|
TPCCLIB
|
Working with weights in TAC structure. More...
#include "tpcclibConfig.h"#include "tpcift.h"#include <stdio.h>#include <stdlib.h>#include <math.h>#include <time.h>#include <string.h>#include "tpctac.h"Go to the source code of this file.
Functions | |
| int | tacIsWeighted (TAC *tac) |
| int | tacWCopy (TAC *tac1, TAC *tac2, int i1, int i2) |
| int | tacWMove (TAC *tac, int ow, TPCSTATUS *status) |
| int | tacWByFreq (TAC *tac, isotope isot, TPCSTATUS *status) |
| unsigned int | tacWSampleNr (TAC *tac) |
| int | tacWeightNorm (TAC *tac, TPCSTATUS *status) |
| int | tacWeightModerate (TAC *tac, const double minprop, const int doZeroes, const int doNaNs, TPCSTATUS *status) |
| int | sifWeight (TAC *sif, isotope isot, TPCSTATUS *status) |
| int | tacSetWeights (TAC *tac, weights weightMethod, int weightNr, TPCSTATUS *status) |
Calculate weights for frames in SIF data based on true counts.
Weights are calculated from formula weight=(frame duration)^2 / (trues in a frame) which is applicable to non-decay corrected data. If weights are to be applied to decay-corrected data, provide function with isotope to use formula weight=(frame duration)^2 / (decay corrected trues in a frame) instead.
Reference: Mazoyer BM, Huesman RH, Budinger TF, Knittel BL. Dynamic PET data analysis. J Comput Assist Tomogr 1986; 10:645-653.
Formula is not applicable to initial frames where trues can be zero or even less, but weights for frames with no trues should still be high for fitting purposes; therefore, in those cases, weight is set to the maximum weight that was calculated from the data.
Weights are normalized to have an average of 1.0 for frames that have weight above zero.
| sif | Pointer to SIF data, stored in TAC structure. Weights are added to the structure. Data must have at least two columns (TACs), which are assumed to represent prompts and randoms, to calculate trues as prompts - randoms. Counts in SIF are assumed to be not corrected for physical decay. Frame times are assumed to be in seconds. |
| isot | Isotope code, in case the weights are calculated for decay corrected data. Enter ISOTOPE_UNKNOWN if calculating weights for non-corrected data. SIF should contain isotope, too, but that is not used in this function. |
| status | Pointer to status data; enter NULL if not needed |
Definition at line 363 of file tacw.c.
Referenced by tacSetWeights().
| int tacIsWeighted | ( | TAC * | tac | ) |
Check if TAC contains weights as indicated by the 'weighting' field.
| tac | Pointer to TAC structure. |
Definition at line 24 of file tacw.c.
Referenced by parAllocateWithTAC(), tacDecayCorrection(), tacSampleXRange(), tacSetWeights(), tacWeightModerate(), tacWeightNorm(), tacWMove(), tacWriteCSV(), tacWriteDFT(), tacWritePMOD(), tacWriteSheetIntoXML(), and tacWriteXML().
Set TAC sample weights, based on given weighting scheme.
Weights are normalized to have average weight 1.0, with the sum of weights equals the weightNr or number of frames, whichever is smaller.
| tac | Pointer to TAC structure. Data must be sorted by increasing sample times. |
| weightMethod | Weighting scheme: WEIGHTING_ON_COUNTS, WEIGHTING_ON_F, WEIGHTING_ON_FD, WEIGHTING_OFF. With WEIGHTING_UNKNOWN weightNr (below) is applied to weights and remaining weights are re-normalized. |
| weightNr | Number of samples (frames) to weight; if TAC contains more samples than this, then those are set to have zero weight. Enter a large number to give weight to all available samples. |
| status | Pointer to status data; enter NULL if not needed |
Definition at line 462 of file tacw.c.
Add weight to TAC data based on sample frequency or time frame length.
Weights are scaled so that weight sum = sample number. Any existing weighting is overwritten.
| tac | Pointer to TAC struct where weights will be added. |
| isot | Isotope code, in case the weights are calculated for decay corrected data. Enter ISOTOPE_UNKNOWN if calculating weights for non-corrected data, or when decay correction is ignored. |
| status | Pointer to status data; enter NULL if not needed |
Definition at line 134 of file tacw.c.
Referenced by tacSetWeights().
Copy weights from one TAC structure to another.
| tac1 | Pointer to source TAC structure. |
| tac2 | Pointer to target TAC structure. |
| i1 | Index of the first sample to copy. |
| i2 | Index of the last sample to copy. |
Definition at line 41 of file tacw.c.
Referenced by tacDuplicate(), and tacExtract().
| int tacWeightModerate | ( | TAC * | tac, |
| const double | minprop, | ||
| const int | doZeroes, | ||
| const int | doNaNs, | ||
| TPCSTATUS * | status ) |
Moderate weights so that the min weight is not less than given proportion of the maximum weight.
After moderation, all weights are normalized to have and average of one.
| tac | Pointer to TAC structure (which can contain SIF or TAC data). |
| minprop | The minimum proportion of frame weight to maximum frame weight. Must be less than one. If proportion is lower than this limit, then weight is set to proportion times maximum. Setting minimum proportion to zero or less does not change any weights, but weights are still normalized. By default, zero weights or NaNs are not changed. |
| doZeroes | Set zero weights, too, to the minimum proportion of maximum frame weight. |
| doNaNs | Set NaN weights, too, to the minimum proportion of maximum frame weight. |
| status | Pointer to status data; enter NULL if not needed |
Definition at line 277 of file tacw.c.
Referenced by tacSetWeights().
Scale weights so that average weight is 1.0, and the sum of weights equals the nr of frames.
| tac | Pointer to TAC structure (which can contain SIF or TAC data). |
| status | Pointer to status data; enter NULL if not needed |
Definition at line 237 of file tacw.c.
Referenced by sifWeight(), tacDecayCorrection(), tacSetWeights(), and tacWeightModerate().
Identify column containing weights in TAC structure, and move weights to the correct place.
TAC name starting with string 'weight' is identified as weight column.
Sets tac->weighting to WEIGHTING_ON or WEIGHTING_OFF, depending on whether weight column was found or not.
| tac | Pointer to TAC structure. |
| ow | Overwrite (1) or do not overwrite (0) existing weights. |
| status | Pointer to status data; enter NULL if not needed |
Definition at line 75 of file tacw.c.
Referenced by tacReadCarimasTxt(), tacReadCSV(), tacReadDFT(), and tacReadPMOD().
| unsigned int tacWSampleNr | ( | TAC * | tac | ) |
Get the number of samples in TAC 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 TAC struct. |
Definition at line 219 of file tacw.c.