TPCCLIB
|
Header file for libtpcmodext. More...
#include "tpcclibConfig.h"
#include "libtpcmisc.h"
#include "libtpcmodel.h"
#include "libtpcsvg.h"
#include "libtpccurveio.h"
#include "libtpcimgio.h"
#include "libtpcimgp.h"
Go to the source code of this file.
Functions | |
int | bf_srtm (double *t, double *cr, int n, int bfNr, double t3min, double t3max, DFT *bf) |
int | bfRadiowater (DFT *input, DFT *tissue, DFT *bf, int bfNr, double k2min, double k2max, char *status, int verbose) |
int | bfIrr2TCM (DFT *input, DFT *tissue, DFT *bf, int bfNr, double thetamin, double thetamax, char *status, int verbose) |
int | dftReadinput (DFT *input, DFT *tissue, char *filename, int *filetype, double *ti1, double *ti2, int verifypeak, char *status, int verbose) |
int | dftReadReference (DFT *tissue, char *filename, int *filetype, int *ref_index, char *status, int verbose) |
int | dftReadModelingData (char *tissuefile, char *inputfile1, char *inputfile2, char *inputfile3, double *fitdur, int *fitframeNr, DFT *tis, DFT *inp, FILE *loginfo, int verbose, char *status) |
int | dftRobustMinMaxTAC (DFT *dft, int tacindex, double *minx, double *maxx, double *miny, double *maxy, int *mini, int *maxi, int *mins, int *maxs, int verbose) |
int | dftVerifyPeak (DFT *dft, int index, int verbose, char *status) |
int | imgReadModelingData (char *petfile, char *siffile, char *inputfile1, char *inputfile2, char *inputfile3, double *fitdur, int *fitframeNr, IMG *img, DFT *inp, DFT *iinp, int verifypeak, FILE *loginfo, int verbose, char *status) |
int | extrapolate_monoexp (DFT *dft, double *fittime, int *min_nr, int max_nr, double mintime, double extr_to, DFT *ext, FILE *loginfo, char *status) |
int | dftAutointerpolate (DFT *dft, DFT *dft2, double endtime, int verbose) |
int | dftDoubleFrames (DFT *dft, DFT *dft2) |
int | dftDivideFrames (DFT *dft, int voi_index, int add_nr, DFT *dft2, int verbose) |
int | dft_end_line (DFT *dft, double *fittime, int *min_nr, int max_nr, double mintime, int check_impr, FIT *fit, FILE *loginfo, char *status) |
int | dft_ln (DFT *dft1, DFT *dft2) |
int | fittime_from_dft (DFT *dft, double *startTime, double *endTime, int *first, int *last, int verbose) |
int | fittime_from_img (IMG *img, double *fittime, int verbose) |
int | check_times_dft_vs_img (IMG *img, DFT *dft, int verbose) |
int | check_times_dft_vs_dft (DFT *dft1, DFT *dft2, int verbose) |
int | copy_times_from_img_to_dft (IMG *img, DFT *dft, int verbose) |
int | getActualSamplenr (DFT *dft, int ri) |
double | dftEndtime (DFT *dft) |
double | imgEndtime (IMG *img) |
int | dftMatchTimeunits (DFT *dft1, DFT *dft2, int *tunit2, int verbose) |
int | img_patlak (DFT *input, IMG *dyn_img, int start, int end, linefit_range fit_range, float thrs, IMG *ki_img, IMG *ic_img, IMG *nr_img, char *status, int verbose) |
int | img_logan (DFT *input, IMG *dyn_img, int start, int end, linefit_range fit_range, float thrs, double k2, IMG *vt_img, IMG *ic_img, IMG *nr_img, char *status, int verbose) |
int | img_k1_using_ki (DFT *input, IMG *dyn_img, int frame_nr, IMG *ki_img, IMG *k1_img, IMG *k2k3_img, char *status, int verbose) |
int | dftInterpolateCheckStart (DFT *input, DFT *output, char *status, int verbose) |
int | dftInterpolateCheckEnd (DFT *input, DFT *output, char *status, int verbose) |
int | dftInterpolate (DFT *input, DFT *tissue, DFT *output, char *status, int verbose) |
int | dftInterpolateInto (DFT *inp, DFT *tis, char *status, int verbose) |
int | dftTimeIntegral (DFT *dft, double t1, double t2, DFT *idft, int calc_mode, char *status, int verbose) |
int | dftDerivative (DFT *dft, DFT *deriv, char *status) |
int | dftDerivative_old (DFT *dft, DFT *deriv, char *status) |
int | dftInterpolateForIMG (DFT *input, IMG *img, int frame_nr, DFT *output, double *ti1, double *ti2, int verbose, char *status) |
int | imgTimeIntegral (IMG *img, float t1, float t2, IMG *iimg, int calc_mode, char *status, int verbose) |
int | dftAllocateWithIMG (DFT *dft, int tacNr, IMG *img) |
int | sif2dft (SIF *sif, DFT *dft) |
int | sifAllocateWithIMG (SIF *sif, IMG *img, int doCounts, int verbose) |
int | mrl_between_tacs (double *y1, double *y2, int n) |
int | noiseSD4Simulation (double y, double t1, double dt, double hl, double a, double *sd, char *status, int verbose) |
int | noiseSD4SimulationFromDFT (DFT *dft, int index, double pc, double *sd, char *status, int verbose) |
int | plot_svg (DFT *dft, RES *res, int first, int last, char *main_title, char *x_title, char *y_title, int color_scale, char *fname, int verbose) |
int | plotdata (DFT *dft, RES *res, int first, int last, char *mtitle, char *xtitle, char *ytitle, char *fname) |
int | plotdata_as_dft (DFT *dft, char *fname) |
int | plot_fit_svg (DFT *dft1, DFT *dft2, char *main_title, char *fname, int verbose) |
int | plot_fitrange_svg (DFT *dft1, DFT *dft2, char *main_title, double x1, double x2, double y1, double y2, char *fname, int verbose) |
int | cunit_check_dft_vs_img (DFT *dft, IMG *img, char *errmsg, int verbose) |
int | dftWeightByFreq (DFT *dft) |
int | imgSetWeights (IMG *img, int wmet, int verbose) |
int | dftWSampleNr (DFT *tac) |
int | clusterTACs (IMG *dimg, IMG *cimg, int nr, DFT *tac, int verbose) |
Header file for libtpcmodext.
Definition in file libtpcmodext.h.
int bf_srtm | ( | double * | t, |
double * | cr, | ||
int | n, | ||
int | bfNr, | ||
double | t3min, | ||
double | t3max, | ||
DFT * | bf ) |
Calculates set of basis functions for SRTM.
t | PET frame mid times. |
cr | Non-decay corrected Cr(t). |
n | Nr of PET frames. |
bfNr | Nr of basis functions to calculate. |
t3min | theta3 min. |
t3max | theta3 max. |
bf | data for basis functions is allocated and filled here. |
Definition at line 16 of file bf_model.c.
int bfIrr2TCM | ( | DFT * | input, |
DFT * | tissue, | ||
DFT * | bf, | ||
int | bfNr, | ||
double | thetamin, | ||
double | thetamax, | ||
char * | status, | ||
int | verbose ) |
Calculates set of basis functions for irreversible 2TCM.
input | Arterial PTAC (not modified). |
tissue | PET TTAC (not modified, just to get frame times). |
bf | Place for basis functions (initiated DFT struct, allocated and filled here). |
bfNr | Nr of basis functions to calculate. |
thetamin | Minimum of theta=k2+k3 (sec-1 or min-1, corresponding to TAC time units). |
thetamax | Maximum of theta=k2+k3 (sec-1 or min-1, corresponding to TAC time units). |
status | Pointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 217 of file bf_model.c.
int bfRadiowater | ( | DFT * | input, |
DFT * | tissue, | ||
DFT * | bf, | ||
int | bfNr, | ||
double | k2min, | ||
double | k2max, | ||
char * | status, | ||
int | verbose ) |
Calculates set of basis functions for generic radiowater model.
input | Arterial blood input TAC (not modified). |
tissue | PET TACs (not modified, just to get frame times). |
bf | Place for basis functions (initiated DFT struct, allocated and filled here). |
bfNr | Nr of basis functions to calculate. |
k2min | Minimum of k2 (sec-1 or min-1, corresponding to TAC time units). |
k2max | Maximum of k2 (sec-1 or min-1, corresponding to TAC time units). |
status | Pointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 77 of file bf_model.c.
Check whether sample times are the same (or very close to) in two DFT structs. Data sets are not edited. If DFT structs contain different sample number, then only common nr of samples are compared.
dft1 | Pointer to first DFT data; times can be both seconds or minutes, if unit is correctly set. |
dft2 | Pointer to second DFT data; times can be both seconds or minutes, if unit is correctly set; sample nr may be different than in dft1. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 169 of file fittime.c.
Referenced by dftInterpolate(), dftInterpolateForIMG(), and dftInterpolateInto().
Check whether DFT sample times are the same (or very close to) as the frame times in IMG. This would suggest that DFT data originates from the same or similar PET scan. Specified data sets are not edited. If frame nr is different, then only the common frames are compared.
img | Pointer to IMG data; times must be in sec as usual. |
dft | Pointer to DFT data; times can be both seconds or minutes, if unit is correctly set; sample nr may be different than in IMG. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 109 of file fittime.c.
Referenced by img_logan(), and img_patlak().
Allocates memory and calculates the values for average TACs for clusters.
dimg | Dynamic image |
cimg | Cluster image |
nr | Highest cluster ID |
tac | Pointer to initiated but empty DFT data |
verbose | Verbose level; if zero, then only warnings are printed into stderr |
Definition at line 15 of file cluster_tac.c.
Copies frame times (especially start and end times, but also mid times) from an IMG data into DFT data, and sets DFT 'header' to indicate that frame start and end times are present.
img | Pointer to IMG data; times must be in sec as usual. |
dft | Pointer to DFT data; times can be both seconds or minutes, if unit is correctly set; sample nr may be smaller than in IMG. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 246 of file fittime.c.
Referenced by dftInterpolateForIMG(), img_logan(), and img_patlak().
Check that calibration units in IMG (PET image) and DFT (input TAC) are the same, and if not, then try to convert DFT calibration unit to IMG unit. If input unit is unknown, then assume it is the same as the PET unit.
dft | Pointer to DFT. |
img | Pointer to IMG. |
errmsg | Char pointer to string (at least of length 128) where possible error description or warning is copied; set to NULL if not necessary. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 18 of file units_check.c.
Referenced by imgReadModelingData().
int dft_end_line | ( | DFT * | dft, |
double * | fittime, | ||
int * | min_nr, | ||
int | max_nr, | ||
double | mintime, | ||
int | check_impr, | ||
FIT * | fit, | ||
FILE * | loginfo, | ||
char * | status ) |
Fits line to the end-part of TACs. By default, the included data points are determined based on maximum adjusted R^2 from at least three points; regression to the larger number of points is used in case difference in adjusted R^2 values is not larger than 0.0001.
dft | Pointer to original TAC data |
fittime | By default, the search for the best line fit is started from the last sample towards the first sample; set fit time to -1 to use this default. However, if the end phase is unreliable or very noisy, you may want to set fittime to include only certain time range from the beginning. Function will write here the fittime that was actually used. |
min_nr | The minimum number of samples used in searching the best fit; at least 2, but 3 is recommended. If data is very noisy, then this number may need to be increased. Function will write here the nr of samples that was actually used. This can be used as an alternative to mintime or in addition to it. |
max_nr | The maximum number of samples used in searching the best fit; must be higher than min_nr, or set to -1 to not to limit the number. |
mintime | Minimum time range used in searching the best fit. If data is very noisy, then this may need to be set, otherwise setting mintime to -1 will use the default. This can be used as an alternative to min_nr or in addition to it. |
check_impr | Linear fitting can be applied to all data subsets in the fit time range (check_impr=0), or fitting is stopped when increasing n does not improve the adjusted R^2 (check_impr=1); the latter mode is for compatibility with WinNonlin. |
fit | Pointer to data for fitted parameters. Struct must be initiated. Any existing data is deleted. Additionally, adjusted R^2 is written as 3rd (non-documented) parameter. |
loginfo | Give file pointer (for example stdout) where log information is printed; NULL if not needed. |
status | Pointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed. |
Definition at line 514 of file extrapolate.c.
Natural logarithm (ln) transformation for TAC concentrations.
dft1 | Pointer to original TAC data. |
dft2 | Pointer to allocated memory for ln transformed TAC data; enter NULL, if original data is to be overwritten by ln transformed values. |
Definition at line 677 of file extrapolate.c.
Allocate memory for DFT based on information in IMG.
dft | Pointer to initiated DFT struct which will be allocated here. |
tacNr | Nr of TACs to be allocated in DFT; if zero, then TACs for all IMG pixels is allocated, but it may lead to out of memory error. |
img | Pointer to IMG struct from where necessary information is read. |
Definition at line 296 of file misc_model.c.
Referenced by imgMaskPixelTACs().
Interpolates TACs to automatically determined sample times with smaller intervals in the beginning. Only data in y arrays are interpolated; data in y2 and y3 are not used.
dft | Data to be interpolated is read from this structure. |
dft2 | Interpolated data is written in this struct; must be initiated; any previous content is deleted. |
endtime | The length of interpolated/extrapolated data. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 243 of file extrapolate.c.
Calculate simple derivatives from regional PET TACs. This must not be used for any quantitative purpose.
dft | DFT struct containing the regional tissue TACs |
deriv | Allocated DFT struct for derivatives |
status | Pointer to allocated string where the status or error message is written; set to NULL if not needed |
Definition at line 635 of file dftint.c.
Calculate simple derivatives from regional PET TACs. Old version. Requires that frame start and end times are known.
dft | DFT struct containing the regional tissue TACs |
deriv | Allocated DFT struct for derivatives |
status | Pointer to allocated string where the status or error message is written; set to NULL if not needed |
Definition at line 591 of file dftint.c.
Interpolates TACs to automatically determined sample times with smaller intervals in the beginning. Only data in y arrays are interpolated; data in y2 and y3 are not used.
dft | Data to be interpolated into more time frames is read from this struct. |
voi_index | Region index [0..voiNr-1] that is interpolated; <0 means all VOIs. |
add_nr | Nr of extra time frames that are created from each original frame; valid numers are 1-100; 1 doubles the frame number. |
dft2 | Interpolated data is written in this struct; must be initiated, may be allocated but do not need to be; any previous content is deleted. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 406 of file extrapolate.c.
Doubles the TAC sample number by making each sample/frame into two by linear interpolation. Only data in y arrays are interpolated; data in y2 and y3 are not used.
dft | Data to be interpolated is read from this structure. |
dft2 | Interpolated data is written in this struct; must be initiated; any previous content is deleted. |
Definition at line 343 of file extrapolate.c.
double dftEndtime | ( | DFT * | dft | ) |
Get TAC end time. Sample times are assumed to be sorted to increasing order.
dft | Pointer to DFT TAC structure. |
Definition at line 315 of file fittime.c.
Referenced by imgReadModelingData().
Interpolate (and integrate) TAC data to sample times that are given with another TAC data. PET frame lengths are taken into account if available in tissue DFT struct.
Input frame lengths are taken into account if the framing is same as with tissue data.
input | Data which is interpolated; make sure that time unit is the same as in tissue data; time range is checked to cover the tissue data |
tissue | Data to which (sample times) the interpolation is done |
output | Pointer to initiated DFT into which interpolated values and integrals will be written |
status | Pointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout |
Definition at line 162 of file dftint.c.
Referenced by dftReadinput().
Verify that data to-be-interpolated does not need too much extrapolation in the end, and that samples are not too sparse.
Time units in DFTs can be different, if specified.
input | Data that will be verified for reliable interpolation |
output | Data containing sample times for interpolated data |
status | Pointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout |
Definition at line 82 of file dftint.c.
Referenced by dftInterpolate(), dftInterpolateForIMG(), and dftInterpolateInto().
Verify that data to-be-interpolated does not need too much extrapolation in the beginning.
input | Data that will be verified for reliable interpolation |
output | Data containing sample times for interpolated data |
status | Pointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout |
Definition at line 17 of file dftint.c.
Referenced by dftInterpolate(), dftInterpolateForIMG(), and dftInterpolateInto().
int dftInterpolateForIMG | ( | DFT * | input, |
IMG * | img, | ||
int | frame_nr, | ||
DFT * | output, | ||
double * | ti1, | ||
double * | ti2, | ||
int | verbose, | ||
char * | status ) |
Interpolate (and integrate) TAC data to sample times that are given with IMG data. Input frame lengths are taken into account if they are available in DFT or if the framing is the same as in IMG data.
input | Data which is interpolated. |
img | Data to which (sample times) the interpolation is done. |
frame_nr | Number of IMG frames that are needed; can be set to 0 if all frames can be included. |
output | Pointer to initiated DFT into which interpolated values and integrals will be written at input sample times and units. |
ti1 | First time of input data before interpolation (in input time units); use this to check that required time range was measured; NULL if not needed. |
ti2 | Last time of input data before interpolation (in input time units); use this to check that required time range was measured; NULL if not needed. |
verbose | Verbose level; set to zero to not to print any comments. |
status | Pointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed. |
Definition at line 17 of file misc_model.c.
Referenced by imgReadModelingData().
Interpolate (and integrate) TAC data to sample times that are given with another TAC data. New TAC is written into existing TAC data. PET frame lengths are taken into account if available in tissue DFT struct. Input frame lengths are taken into account if the framing is same as with tissue data.
inp | Data which is interpolated; make sure that time unit is the same as in tissue data; time range is checked to cover the tissue data |
tis | Data into which the interpolation is done |
status | Pointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout |
Definition at line 281 of file dftint.c.
Referenced by dftReadModelingData(), dftReadReference(), and imgReadModelingData().
Make sure that time units in two DFT structs are the same, converting units when necessary, optionally saving original units so that units can be converted back to what they were using dftTimeunitConversion().
dft1 | Pointer to DFT struct 1. |
dft2 | Pointer to DFT struct 2; sample time units are changed to match the data in dft1. |
tunit2 | Pointer for original time unit in DFT 2; enter NULL if not needed. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 358 of file fittime.c.
Referenced by dftInterpolateCheckEnd(), and dftInterpolateCheckStart().
int dftReadinput | ( | DFT * | input, |
DFT * | tissue, | ||
char * | filename, | ||
int * | filetype, | ||
double * | ti1, | ||
double * | ti2, | ||
int | verifypeak, | ||
char * | status, | ||
int | verbose ) |
Read DFT format input TAC data to match the time frames in the specified tissue DFT file. Instead of input filename, a reference region name can be given: then all the matching tacs (based on roi names) are moved from the roi data to the input data, with the best match as first tac. Input data is interpolated (if necessary) and also integrated to y2[]. Input time and concentration units are tried to be converted to be the same as in tissue data.
input | Input data, previous contents are cleared. |
tissue | PET data containing frames and possible input regions. |
filename | Input data filename, or region name in PET data. |
filetype | Type of input, as found out here; 1 and 2 =tac, 3=fit, 5=region name; enter NULL, if not needed. |
ti1 | First time of input data before interpolation (in tissue time units); use this to check that required time range was measured; NULL if not needed. |
ti2 | Last time of input data before interpolation (in tissue time units); use this to check that required time range was measured; NULL if not needed. |
verifypeak | Set to <>0 to verify that input TAC does not start too late and has decent peak to provide reliable AUC0-T. |
status | Pointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 25 of file dftinput.c.
int dftReadModelingData | ( | char * | tissuefile, |
char * | inputfile1, | ||
char * | inputfile2, | ||
char * | inputfile3, | ||
double * | fitdur, | ||
int * | fitframeNr, | ||
DFT * | tis, | ||
DFT * | inp, | ||
FILE * | loginfo, | ||
int | verbose, | ||
char * | status ) |
Read tissue and input data for modeling. Time units are converted to min and input calibration units to units of tissue data. Input data is NOT interpolated to tissue times. If input data extends much further than fit duration, the last part is removed to save computation time in simulations. Input data is verified not to end too early, and not to start too late.
tissuefile | Tissue data filename; one time sample is sufficient here. |
inputfile1 | 1st input data filename. |
inputfile2 | 2nd input data filename (or NULL if only not needed). |
inputfile3 | 3rd input data filename (or NULL if only not needed). |
fitdur | Fit duration (in minutes); shortened if longer than tissue data. |
fitframeNr | Nr of time frames (samples) in tissue data that are inside fitdur will be written here. |
tis | Pointer to initiated DFT into which tissue data will be written. |
inp | Pointer to initiated DFT into which input data (plasma and/or blood) will be written. |
loginfo | Give file pointer (for example stdout) where log information is printed; NULL if not needed; warnings will be printed in stderr anyway. |
verbose | Verbose level; if zero, then only warnings are printed into stderr. |
status | Pointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed. |
Definition at line 342 of file dftinput.c.
int dftReadReference | ( | DFT * | tissue, |
char * | filename, | ||
int * | filetype, | ||
int * | ref_index, | ||
char * | status, | ||
int | verbose ) |
Read DFT format reference region TAC data and add it into DFT already containing other tissue TACs, if reference region TAC(s) are be given in a separate file. Alternatively the reference region name can be given, which will then be selected from existing tissue TACs. Reference TACs are marked in DFT with sw=2 (best name match) or sw=1; if reference region file contains several TACs then the one which contains name 'mean' or 'avg' or has shortest total name length is given value sw=2. When necessary, reference data is interpolated and units converted to match the existing tissue DFT. Reference TAC is also integrated into y2[].
tissue | PET data containing existing tissue TACs, possibly also ref regions. |
filename | Reference TAC filename, or region name in previous data. |
filetype | Type of input, as found out here; 1 and 2 =tac, 3=fit, 5=region name; enter NULL, if not needed. |
ref_index | Index of the best reference region; enter NULL if not needed. |
status | Pointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 204 of file dftinput.c.
int dftRobustMinMaxTAC | ( | DFT * | dft, |
int | tacindex, | ||
double * | minx, | ||
double * | maxx, | ||
double * | miny, | ||
double * | maxy, | ||
int * | mini, | ||
int * | maxi, | ||
int * | mins, | ||
int * | maxs, | ||
int | verbose ) |
Robust search of the min and max values of DFT TAC data. Data may contain NaN's, and individual outliers are not taken as min or max.
dft | Pointer to the DFT TAC data to search. |
tacindex | Index of the only TAC which is searched for min and max; <0 if all. |
minx | Pointer to X at TAC min; set to NULL if not needed. |
maxx | Pointer to X at TAC max; set to NULL if not needed. |
miny | Pointer to min Y; set to NULL if not needed. |
maxy | Pointer to max Y; set to NULL if not needed. |
mini | Index of min TAC; set to NULL if not needed. |
maxi | Index of max TAC; set to NULL if not needed. |
mins | Index of min sample; set to NULL if not needed. |
maxs | Index of max sample; set to NULL if not needed. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 608 of file dftinput.c.
int dftTimeIntegral | ( | DFT * | dft, |
double | t1, | ||
double | t2, | ||
DFT * | idft, | ||
int | calc_mode, | ||
char * | status, | ||
int | verbose ) |
Integration of regional TAC data from time1 to time2, i.e. AUC(t1,t2).
You may want to test the time range before applying this routine, because this function accepts relatively large extrapolation large.
dft | Regional TAC data in DFT struct. Number of samples must be at least one. If only one sample, then the integration time range must match with the possible frame start and times. Frames do not have to be continuous in time. |
t1 | Time where to start integration (same unit as in TACs) |
t2 | Time to stop integration (same unit as in TACs); must be higher than t1, except that t1=t2 is acceptable when calc_mode=average |
idft | Pointer to initiated but empty AUC DFT data (output) |
calc_mode | Calculate integral or average: 0=integral, 1=average |
status | Pointer to a string (allocated for at least 128 chars) where error message or other execution status will be written; enter NULL, if not needed |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout |
Definition at line 382 of file dftint.c.
int dftVerifyPeak | ( | DFT * | dft, |
int | index, | ||
int | verbose, | ||
char * | status ) |
Verify that specified (input) TAC contains peak and that it does not start too late to get reliable estimate of AUC.
dft | Pointer to TAC data which is verified. |
index | Index of TAC to be verified; <0 in case all are (separately) verified. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
status | Pointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed. |
Definition at line 747 of file dftinput.c.
Referenced by dftFixPeak(), dftReadinput(), and imgReadModelingData().
int dftWeightByFreq | ( | DFT * | dft | ) |
Add weights based on sample frequency or frame length.
Existing weights are overwritten.
dft | Samples/frames must be sorted by sample time, but duplicate samples are allowed |
Definition at line 20 of file weight_model.c.
int dftWSampleNr | ( | DFT * | tac | ) |
Get the number of samples in DFT that have weight > 0. Missing (NaN) sample values are included as long as weight is not missing. If weights are not set, then nr of all samples is returned.
tac | Pointer to the DFT struct. |
Definition at line 147 of file weight_model.c.
int extrapolate_monoexp | ( | DFT * | dft, |
double * | fittime, | ||
int * | min_nr, | ||
int | max_nr, | ||
double | mintime, | ||
double | extr_to, | ||
DFT * | ext, | ||
FILE * | loginfo, | ||
char * | status ) |
Extrapolation of exponentially decreasing tail of PET radiotracer plasma curves. This is accomplished by fitting line to the end-part of the plot of the natural logarithm of tracer concentration against time. By default, the included data points are determined based on maximum adjusted R^2 from at least three points; fit to the larger number of points is used in case difference in adjusted R^2 values is not larger than 0.0001. This function is used and tested with program extrapol.
dft | Pointer to original TAC data. |
fittime | By default, the search for the best line fit is started from the last sample towards the first sample; set fit time to -1 to use this default. However, if the end phase is unreliable or very noisy, you may want to set fittime to include only certain time range from the beginning. Function will write here the fittime that was actually used. |
min_nr | The minimum number of samples used in searching the best fit; at least 2, but 3 is recommended. If data is very noisy, then this number may need to be increased. Function will write here the nr of samples that was actually used. This can be used as an alternative to mintime or in addition to it. |
max_nr | The maximum number of samples used in searching the best fit; must be higher than min_nr, or set to -1 to not to limit the number. |
mintime | Minimum time range used in searching the best fit. If data is very noisy, then this may need to be set, otherwise setting mintime to -1 will use the default. This can be used as an alternative to min_nr or in addition to it. |
extr_to | Last extrapolated sample time in same time units than in the data. |
ext | Pointer to data for extrapolated TACs. Struct must be initiated. Any existing data is deleted. |
loginfo | Give file pointer (for example stdout) where log information is printed; NULL if not needed. |
status | Pointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed. |
Definition at line 22 of file extrapolate.c.
int fittime_from_dft | ( | DFT * | dft, |
double * | startTime, | ||
double * | endTime, | ||
int * | first, | ||
int * | last, | ||
int | verbose ) |
Reset user-defined fit time range to comply with DFT data.
dft | Pointer to DFT containing (regional tissue) data; times can be in minutes or seconds, as long as units are defined. |
startTime | Pointer containing originally the requested fit start time (min). This is changed to contain the time of the first included frame. Unit must be minutes. Initially, set to <0 to start from the beginning of the data. |
endTime | Pointer containing originally the requested fit end time (min). This is changed to contain the time of the last included frame. Unit must be minutes. Initially, set to <0 or to a very large value to reach to the end of data. |
first | Function writes the index of the first included sample (frame) here. |
last | Function writes the index of the last included sample (frame) here. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 16 of file fittime.c.
Referenced by dftReadModelingData(), and imgReadModelingData().
int fittime_from_img | ( | IMG * | img, |
double * | fittime, | ||
int | verbose ) |
Get the IMG frame end time of the last frame that is inside (mid time before) the specified maximum fittime.
img | Pointer to IMG |
fittime | Pointer containing originally the fit time maximum, after this the last included IMG frame end time. Unit must be seconds. Initially, set to <0 or to a very large value to include all frames. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 74 of file fittime.c.
Referenced by imgReadModelingData().
int getActualSamplenr | ( | DFT * | dft, |
int | ri ) |
Returns the actual TAC sample number, not including NaNs, samples with negative x, duplicate samples, or samples with zero weights (if data is weighted).
dft | Pointer to TAC data in DFT struct; must be sorted by increasing x. |
ri | Region index [0..voiNr-1]. |
Definition at line 288 of file fittime.c.
int img_k1_using_ki | ( | DFT * | input, |
IMG * | dyn_img, | ||
int | frame_nr, | ||
IMG * | ki_img, | ||
IMG * | k1_img, | ||
IMG * | k2k3_img, | ||
char * | status, | ||
int | verbose ) |
Computing pixel-by-pixel the K1 for irreversible PET tracers using previously determined Ki (K1*k3/(k2+k3) and bilinear regression.
input | Pointer to the TAC data to be used as model input. Sample times in minutes. Curve is interpolated to PET frame times, if necessary |
dyn_img | Pointer to dynamic PET image data. Image and input data must be in the same calibration units |
frame_nr | Nr of frames that will be included in the fit [3-frame_nr] |
ki_img | Pointer to previously calculated Ki image |
k1_img | Pointer to initiated IMG structure where K1 values will be placed |
k2k3_img | Pointer to initiated IMG structure where (k2+k3) values will be placed; enter NULL, if not needed |
status | Pointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout |
Definition at line 16 of file img_k1.c.
int img_logan | ( | DFT * | input, |
IMG * | dyn_img, | ||
int | start, | ||
int | end, | ||
linefit_range | fit_range, | ||
float | thrs, | ||
double | k2, | ||
IMG * | vt_img, | ||
IMG * | ic_img, | ||
IMG * | nr_img, | ||
char * | status, | ||
int | verbose ) |
Computing pixel-by-pixel the graphical analysis for reversible PET tracers (Logan plot).
input | Pointer to the TAC data to be used as model input. Sample times in minutes. Curve is interpolated to PET frame times, if necessary. |
dyn_img | Pointer to dynamic PET image data. Image and input data must be in the same calibration units. |
start | The range of frames where line is fitted, given as the frame start here and next the end index, i.e. [0..frame_nr-1]. |
end | The range of frames where line is fitted, given as the frame start above and here the end index, i.e. [0..frame_nr-1]. |
fit_range | Use the whole range or based on data leave out points from the beginning; PRESET or EXCLUDE_BEGIN. |
thrs | Threshold as fraction of input AUC. |
k2 | Reference region k2; set to <=0 if not needed. |
vt_img | Pointer to initiated IMG structure where Vt (or DVR) values will be placed. |
ic_img | Pointer to initiated IMG structure where plot y axis intercept values times -1 will be placed; enter NULL, if not needed. |
nr_img | Pointer to initiated IMG structure where the number of plot data points actually used in the fit is written; enter NULL, when not needed. |
status | Pointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 228 of file img_mtga.c.
int img_patlak | ( | DFT * | input, |
IMG * | dyn_img, | ||
int | start, | ||
int | end, | ||
linefit_range | fit_range, | ||
float | thrs, | ||
IMG * | ki_img, | ||
IMG * | ic_img, | ||
IMG * | nr_img, | ||
char * | status, | ||
int | verbose ) |
Computing pixel-by-pixel the graphical analysis for irreversible PET tracers (Gjedde-Patlak plot).
input | Pointer to the TAC data to be used as model input. Sample times in minutes. Curve is interpolated to PET frame times, if necessary. |
dyn_img | Pointer to dynamic PET image data. Image and input data must be in the same calibration units. |
start | The range of frames where line is fitted, given as the frame start here and next the end index, i.e. [0..frame_nr-1]. |
end | The range of frames where line is fitted, given as the frame start above and here the end index, i.e. [0..frame_nr-1]. |
fit_range | Use the whole range or based on data leave out points from the beginning; PRESET or EXCLUDE_BEGIN. |
thrs | Threshold as fraction of input AUC. |
ki_img | Pointer to initiated IMG structure where Ki values will be placed. |
ic_img | Pointer to initiated IMG structure where plot y axis intercept values will be placed; enter NULL, if not needed. |
nr_img | Pointer to initiated IMG structure where the number of plot data points actually used in the fit is written; enter NULL, when not needed. |
status | Pointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 17 of file img_mtga.c.
double imgEndtime | ( | IMG * | img | ) |
Get IMG end time. Frame times are assumed to be sorted to increasing order.
img | Pointer to IMG structure. |
Definition at line 339 of file fittime.c.
Referenced by imgReadModelingData().
int imgReadModelingData | ( | char * | petfile, |
char * | siffile, | ||
char * | inputfile1, | ||
char * | inputfile2, | ||
char * | inputfile3, | ||
double * | fitdur, | ||
int * | fitframeNr, | ||
IMG * | img, | ||
DFT * | inp, | ||
DFT * | iinp, | ||
int | verifypeak, | ||
FILE * | loginfo, | ||
int | verbose, | ||
char * | status ) |
Read PET image and input TAC for modelling.
Input calibration units are converted to units of tissue data. Input data is optionally interpolated to tissue times. If input data extends much further than fit duration, the last part is removed to save computation time in simulations. Input data is optionally verified not to end too early, and not to start too late.
petfile | PET dynamic image filename; one time frame is sufficient here. |
siffile | Optional SIF. SIF is automatically read with NIfTI and Analyze formats, if found in the same folder and files are consistently named. SIF filename needs to be specified here only if that is not the case, or if other image formats do not contain information on frame times or tracer isotope, or if weights from SIF are needed. Enter NULL if not needed. |
inputfile1 | 1st input data filename. |
inputfile2 | 2nd input data filename (or NULL if only not needed). |
inputfile3 | 3rd input data filename (or NULL if only not needed). |
fitdur | Fit duration (in minutes); shortened if longer than PET data; enter <=0 to use all data in image; input is verified to not be much shorter than fitdur. |
fitframeNr | Nr of time frames (samples) in PET data that are inside fitdur will be written here; pointer MUST be provided. |
img | Pointer to initiated IMG structure into which PET data will be written. |
inp | Pointer to initiated DFT into which input data (plasma, blood, and/or reference tissue TAC) will be written without interpolation; enter NULL if not needed. Times will be in seconds, like in image. |
iinp | Pointer to initiated DFT into which input data (plasma, blood, and/or reference tissue TAC) will be written, interpolated to PET frames; enter NULL if not needed. Times will be in seconds, like in image. |
verifypeak | Set to <>0 to verify that input TAC does not start too late and has decent peak to provide reliable AUC0-T. |
loginfo | Give file pointer (for example stdout) where log information is printed; NULL if not needed; warnings will be printed in stderr anyway. |
verbose | Verbose level; if zero, then only warnings are printed into stderr. |
status | Pointer to a string (allocated for at least 256 chars) where error message or other execution status will be written; enter NULL, if not needed. |
Definition at line 24 of file imginput.c.
int imgSetWeights | ( | IMG * | img, |
int | wmet, | ||
int | verbose ) |
Add weights based on average voxel values and frame lengths, just frame lengths, or set all weights to 1 (no weighting).
Existing weights are overwritten. Decay correction is not considered in calculation of weights.
img | Pointer to IMG struct; image data is used to calculate relational frame weights, which are also written into IMG struct. |
wmet | Weighting method: 0=based on mean voxel values times frame lengths; 1=based on frame lengths, 2=set weights to 1 (no weighting). |
verbose | Verbose level; if zero, then only warnings are printed into stderr |
Definition at line 85 of file weight_model.c.
int imgTimeIntegral | ( | IMG * | img, |
float | t1, | ||
float | t2, | ||
IMG * | iimg, | ||
int | calc_mode, | ||
char * | status, | ||
int | verbose ) |
Integration of dynamic image from time1 to time2, storing integrals in iimg, which is allocated here. Frames do not have to be continuous in time. Time unit in integral is sec. Raw data (sinogram) must be divided by frame durations before calling this. You may want to test the time range before applying this routine, because this function accepts relatively large extrapolation.
img | IMG data; preferably dynamic, if static, then the specified time range must match with the frame time. |
t1 | Time where to start integration (sec). |
t2 | Time to stop integration (sec); must be higher than t1. |
iimg | Pointer to initiated but empty AUC IMG data. |
calc_mode | Calculate integral or average: 0=integral, 1=average. |
status | Pointer to a string (allocated for at least 128 chars) where error message or other execution status will be written; enter NULL, if not needed. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 147 of file misc_model.c.
int mrl_between_tacs | ( | double * | y1, |
double * | y2, | ||
int | n ) |
Return the maximum run length between given n length arrays of data
y1 | Array of data1; may contain NaNs |
y2 | Array of data2; may contain NaNs |
n | Nr of samples in array 1 and 2 |
Definition at line 13 of file mrl.c.
int noiseSD4Simulation | ( | double | y, |
double | t1, | ||
double | dt, | ||
double | hl, | ||
double | a, | ||
double * | sd, | ||
char * | status, | ||
int | verbose ) |
Calculate SD for PET radioactivity concentration data to be used to simulate noise.
Note that SD is dependent on the time units.
Reference: Varga & Szabo. J Cereb Blood Flow Metab 2002;22(2):240-244.
y | Sample radioactivity concentration (decay corrected to zero time) |
t1 | Radioactivity measurement (frame) start time (in same units as the halflife) |
dt | Radioactivity measurement (frame) duration (in same units as the halflife) |
hl | Isotope halflife (in same units as the sample time); enter 0 if not to be considered |
a | Proportionality factor. Note that it is inside square root. |
sd | Pointer in which SD is written |
status | Pointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout |
Definition at line 21 of file noise.c.
Referenced by noiseSD4SimulationFromDFT().
int noiseSD4SimulationFromDFT | ( | DFT * | dft, |
int | index, | ||
double | pc, | ||
double * | sd, | ||
char * | status, | ||
int | verbose ) |
Calculate SD for noise simulation from TAC data.
Sample times will be converted to minutes if necessary.
Reference: Varga & Szabo. J Cereb Blood Flow Metab 2002;22(2):240-244.
dft | Pointer to TAC data in DFT struct, based on which the SD for each frame is calculated. Contents are not changed. Struct must contain correct values for the isotope, time unit, and frame times (start and end). Status of decay correction is used, and if not known, then data is assumed to be decay corrected. |
index | TAC index [0..voiNr-1] which is used to calculate the SD in case DFT contains more than one TAC. Non-effective if DFT contains only one TAC. Set to <0 if mean of all TACs is to be used. |
pc | Proportionality factor |
sd | Pointer to allocated array in which SD is written |
status | Pointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout |
Definition at line 79 of file noise.c.
Writes plots of original and fitted TACs in SVG 1.1 format. Data must not contain NaNs.
dft1 | Measured data points. |
dft2 | Fitted data points. Times can be different but unit must be the same. |
main_title | String for plot main title, or "". |
fname | SVG filename; existing file is backed up. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 216 of file plotfit.c.
int plot_fitrange_svg | ( | DFT * | dft1, |
DFT * | dft2, | ||
char * | main_title, | ||
double | x1, | ||
double | x2, | ||
double | y1, | ||
double | y2, | ||
char * | fname, | ||
int | verbose ) |
Writes specified range of plots of original and fitted TACs in SVG 1.1 format.
dft1 | Measured data points |
dft2 | Fitted data points. Times can be different but unit must be the same. |
main_title | String for plot main title, or NULL |
x1 | Start time; NaN if determined from data |
x2 | End time; NaN if determined from data |
y1 | Minimum y value; NaN if determined from data |
y2 | Maximum y value; NaN if determined from data |
fname | SVG filename; existing file is backed up |
verbose | Verbose level; set to zero to not to print any comments |
Definition at line 16 of file plotfit.c.
int plot_svg | ( | DFT * | dft, |
RES * | res, | ||
int | first, | ||
int | last, | ||
char * | main_title, | ||
char * | x_title, | ||
char * | y_title, | ||
int | color_scale, | ||
char * | fname, | ||
int | verbose ) |
Writes graphical analysis plots in SVG 1.1 format. Assumes that line slope and ic are in res->parameter[0] and [1].
dft | Plot points: X in y2, Y in y3. |
res | Results containing parameters of line. |
first | First sample (starting from 0) used in linear fit. |
last | last sample (starting from 0) used in linear fit. |
main_title | String for plot main title, or NULL. |
x_title | String for X axis title, or NULL. |
y_title | String for Y axis title, or NULL. |
color_scale | Colour-scale: 0=colour, 2=black-and-white. |
fname | File name for SVG; existing file is renamed as *.bak. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 17 of file plotdata.c.
int plotdata | ( | DFT * | dft, |
RES * | res, | ||
int | first, | ||
int | last, | ||
char * | mtitle, | ||
char * | xtitle, | ||
char * | ytitle, | ||
char * | fname ) |
Write plot and line fit data in XHTML 1.1. Strict table format. Assumes that line slope and ic are in res->parameter[0] and [1].
dft | Plot points: X in y2, Y in y3. |
res | Results containing parameters of line. |
first | First sample (starting from 0) used in linear fit. |
last | last sample (starting from 0) used in linear fit. |
mtitle | String for plot main title, or NULL. |
xtitle | String for X axis title, or NULL. |
ytitle | String for Y axis title, or NULL. |
fname | Filename for plot data; existing file is renamed as *%. If extension is .dft, plot data (excluding lines) is written in DFT format with x values as separate columns before corresponding y values. |
Definition at line 217 of file plotdata.c.
int plotdata_as_dft | ( | DFT * | dft, |
char * | fname ) |
Write plot data in DFT format with x values as separate columns before corresponding y values.
dft | Plot points: X in y2, Y in y3. |
fname | File name for plot data. |
Definition at line 412 of file plotdata.c.
Referenced by plotdata().
sif | Pointer to SIF struct containing data to be converted. |
dft | Pointer to initiated but empty DFT struct. |
Definition at line 350 of file misc_model.c.
Allocate memory for SIF based on information in IMG.
Frame times are set, 'counts' are optionally set to mean of voxel values times frame lengths, scaled to 0-1E7. Weights are not calculated.
sif | Pointer to initiated SIF struct which will be allocated here. |
img | Pointer to IMG struct from where necessary information is read. |
doCounts | Set (1) or do not set (0) counts, based on sum of all image voxel values and frame lengths. |
verbose | Verbose level; if zero, then only warnings are printed into stderr. |
Definition at line 418 of file misc_model.c.
Referenced by imgSetWeights().