UCL / UCL/STIR

Patlak \int_0_t Cp(t) wrongly computed in PatlakPlot.cxx

Open
#703 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
160
Forks
113
Avg merge
12d 15h
Merged PRs (30d)
1

Description

The following piece of code computes the Concentration of plasma in blood and its integral for the time frames used for the Patlak plot fit:

https://github.com/UCL/STIR/blob/7b4c27470ad175a80f29e9aabe945b6831a4f159/src/modelling_buildblock/PatlakPlot.cxx#L154-L167

It does so by integrating the IF over the time frame, and adds it to patlak_array[2][sample_num].

The integral part, it does by taking this same value, and multiplying by the frame duration and adding it to patlak_array[1][sample_num].

However, I think this last one is missing a big part. This being a Patlak plot, the first frame input will not be at t=0, but much later, lets call it t1. However, this code does not start integrating Cp(t) until t1. For an input where all time dynamic time frames are used (i.e. starting frame := 1 in the parameter file) and a starting frame that starts at t1, the first for loop in the code above simply does not run. sum_value=0 by the time the second loop starts, and thus the integral of Cp(t) is only ever computed from t1. But, as far as I know, we need the full integral of Cp(t), starting from zero.

I can verify numerically this is happening too, for a particular IF and a time frame length of 210, this is what the values of patlak_array are (after decay un-correction):


Cp(t)
1126.32 998.855 895.152 808.298 734.225 670.127 614.032 564.431 520.19 480.454 444.478 411.792 381.927 354.533 329.34 
int_Cp(t)
236527 441117 619456 775659 912891 1.03366e+06 1.14002e+06 1.23363e+06 1.3159e+06 1.38803e+06 1.45103e+06 1.50579e+06 1.55308e+06 1.59359e+06 1.62792e+06 

236527/210=1126.32

@KrisThielemans I'd appreciate a second pair of eyes to verify I'm not mad.

Should the integral not be from t=0? Or is this quite wrong?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked section of src/modelling_buildblock/PatlakPlot.cxx at lines 154-167, tracing how the two loops populate patlak_array[1] and patlak_array[2]. Reproduce the reported frame-duration values and compare the accumulated integral with the intended Patlak definition; done means the calculation is correct for a starting frame at t1 and the relevant tests or numerical checks pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.