TPCCLIB
Loading...
Searching...
No Matches
tpcisotope.h File Reference

Header file for library libtpcisotope. More...

#include "tpcclibConfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>
#include <math.h>
#include "tpcextensions.h"

Go to the source code of this file.

Macros

#define MAX_ATOMIC_NUMBER   118
 Max atomic number, and the size of element_symbol and element_name lists.
#define M_LN2   0.69314718055994530942
 Defined ln(2) for faster computations.
#define MAX_ISOTOPE_LEN   16
 Max string length for PET isotope.

Enumerations

enum  isotope {
  ISOTOPE_UNKNOWN , ISOTOPE_BR_75 , ISOTOPE_BR_76 , ISOTOPE_CU_62 ,
  ISOTOPE_CU_64 , ISOTOPE_FE_52 , ISOTOPE_GA_68 , ISOTOPE_GE_68 ,
  ISOTOPE_NA_22 , ISOTOPE_RB_82 , ISOTOPE_SC_44 , ISOTOPE_TB_152 ,
  ISOTOPE_ZN_62 , ISOTOPE_ZR_89 , ISOTOPE_C_11 , ISOTOPE_F_18 ,
  ISOTOPE_I_124 , ISOTOPE_N_13 , ISOTOPE_O_15 , ISOTOPE_O_14
}
enum  decaycorrection {
  DECAY_UNKNOWN , DECAY_NOTCORRECTED , DECAY_CORRECTED , DECAY_CORRECTED_START ,
  DECAY_CORRECTED_ADMIN
}

Functions

char * elementName (unsigned short int z)
char * elementSymbol (unsigned short int z)
unsigned short int elementIdentify (const char *str)
double isotopeHalflife (int isotope)
double isotopeBranching (int isotope)
char * isotopeName (int isotope)
int isotopeIdentifyHalflife (double halflife)
int isotopeIdentify (const char *isotope)
char * decayDescr (decaycorrection d)
double lambdaFromHalflife (double halflife)
double lambdaFromIsotope (int isotope)
double decayCorrectionFactorFromLambda (double lambda, double starttime, double duration)
double decayCorrectionFactorFromIsotope (int isotope, double starttime, double duration)
double noiseSD4Frame (double y, double t1, double dt, int isotope, double a)

Detailed Description

Header file for library libtpcisotope.

Isotope half-lives and branching fractions are based on the following references, except isotopes Br-75, Br-76, Cu-62, Cu-64, Fe-52, O-14, Rb-82, Zn-62, I-124, which thus should be treated with caution.
References:

  1. Table of Isotopes, Sixth edition, edited by C.M. Lederer, J.M. Hollander, I. Perlman. WILEY, 1967.
  2. Monographie BIPM-5, Table of Radionuclides, Vol. 6, 2011, http://www.bipm.org/en/publications/monographies-ri.html.
Author
Vesa Oikonen

Definition in file tpcisotope.h.

Macro Definition Documentation

◆ M_LN2

#define M_LN2   0.69314718055994530942

Defined ln(2) for faster computations.

Definition at line 37 of file tpcisotope.h.

Referenced by lambdaFromHalflife(), and lambdaFromIsotope().

◆ MAX_ATOMIC_NUMBER

#define MAX_ATOMIC_NUMBER   118

Max atomic number, and the size of element_symbol and element_name lists.

Definition at line 33 of file tpcisotope.h.

Referenced by elementIdentify(), elementName(), and elementSymbol().

◆ MAX_ISOTOPE_LEN

#define MAX_ISOTOPE_LEN   16

Max string length for PET isotope.

Definition at line 41 of file tpcisotope.h.

Referenced by tacGetHeaderIsotope(), tacGetIsotope(), tacReadSIF(), and tacWriteSIF().

Enumeration Type Documentation

◆ decaycorrection

Is data corrected for physical decay or not?

See also
decay.c, decayDescr
Enumerator
DECAY_UNKNOWN 

Not known; usually assumed that data is corrected.

DECAY_NOTCORRECTED 

Data is not corrected for physical decay.

DECAY_CORRECTED 

Data is corrected for physical decay.

DECAY_CORRECTED_START 

Data is corrected for physical decay to scan start time.

DECAY_CORRECTED_ADMIN 

Data is corrected for physical decay to radioligand administration time.

Definition at line 78 of file tpcisotope.h.

78 {
decaycorrection
Definition tpcisotope.h:78
@ DECAY_UNKNOWN
Not known; usually assumed that data is corrected.
Definition tpcisotope.h:79
@ DECAY_CORRECTED_ADMIN
Data is corrected for physical decay to radioligand administration time.
Definition tpcisotope.h:83
@ DECAY_NOTCORRECTED
Data is not corrected for physical decay.
Definition tpcisotope.h:80
@ DECAY_CORRECTED
Data is corrected for physical decay.
Definition tpcisotope.h:81
@ DECAY_CORRECTED_START
Data is corrected for physical decay to scan start time.
Definition tpcisotope.h:82

◆ isotope

enum isotope

isotope_code, same as isotopes position in isotope table (table can not be accessed directly outside the c file).

See also
isotope.c, isotopeName, isotopeIdentify
Enumerator
ISOTOPE_UNKNOWN 

Unknown.

ISOTOPE_BR_75 

Br-75.

ISOTOPE_BR_76 

Br-76.

ISOTOPE_CU_62 

Cu-62.

ISOTOPE_CU_64 

Cu-64.

ISOTOPE_FE_52 

Fe-52.

ISOTOPE_GA_68 

Ga-68.

ISOTOPE_GE_68 

Ge-68.

ISOTOPE_NA_22 

Na-22.

ISOTOPE_RB_82 

Rb-82.

ISOTOPE_SC_44 

Sc-44.

ISOTOPE_TB_152 

Tb-152.

ISOTOPE_ZN_62 

Zn-62.

ISOTOPE_ZR_89 

Zr-89.

ISOTOPE_C_11 

C-11.

ISOTOPE_F_18 

F-18.

ISOTOPE_I_124 

I-124.

ISOTOPE_N_13 

N-13.

ISOTOPE_O_15 

O-15.

ISOTOPE_O_14 

O-14.

Definition at line 50 of file tpcisotope.h.

50 {
71} isotope;
isotope
Definition tpcisotope.h:50
@ ISOTOPE_BR_75
Br-75.
Definition tpcisotope.h:52
@ ISOTOPE_RB_82
Rb-82.
Definition tpcisotope.h:60
@ ISOTOPE_GA_68
Ga-68.
Definition tpcisotope.h:57
@ ISOTOPE_CU_64
Cu-64.
Definition tpcisotope.h:55
@ ISOTOPE_CU_62
Cu-62.
Definition tpcisotope.h:54
@ ISOTOPE_F_18
F-18.
Definition tpcisotope.h:66
@ ISOTOPE_C_11
C-11.
Definition tpcisotope.h:65
@ ISOTOPE_N_13
N-13.
Definition tpcisotope.h:68
@ ISOTOPE_ZR_89
Zr-89.
Definition tpcisotope.h:64
@ ISOTOPE_I_124
I-124.
Definition tpcisotope.h:67
@ ISOTOPE_O_15
O-15.
Definition tpcisotope.h:69
@ ISOTOPE_O_14
O-14.
Definition tpcisotope.h:70
@ ISOTOPE_TB_152
Tb-152.
Definition tpcisotope.h:62
@ ISOTOPE_BR_76
Br-76.
Definition tpcisotope.h:53
@ ISOTOPE_NA_22
Na-22.
Definition tpcisotope.h:59
@ ISOTOPE_ZN_62
Zn-62.
Definition tpcisotope.h:63
@ ISOTOPE_UNKNOWN
Unknown.
Definition tpcisotope.h:51
@ ISOTOPE_GE_68
Ge-68.
Definition tpcisotope.h:58
@ ISOTOPE_FE_52
Fe-52.
Definition tpcisotope.h:56
@ ISOTOPE_SC_44
Sc-44.
Definition tpcisotope.h:61

Function Documentation

◆ decayCorrectionFactorFromIsotope()

double decayCorrectionFactorFromIsotope ( int isotope,
double starttime,
double duration )
extern

Calculate the correction factor for physical decay from measurement time to time zero.

Returns
Factor for decay correction (>1), or NaN if input is invalid.
See also
lambdaFromIsotope, isotopeIdentify, decayCorrectionFactorFromLambda, isotopeName
Author
Vesa Oikonen
Parameters
isotopeisotope_code as enum or the index of isotope in isotope table.
starttimeRadioactivity measurement start time, or middle time, if measurement duration is not known. Unit must be min.
durationRadioactivity measurement duration; if not known, then set to zero, and put measurement middle time for starttime. Unit must be min.

Definition at line 107 of file decay.c.

116 {
117 double lambda=lambdaFromIsotope(isotope); if(isnan(lambda)) return nan("");
118 return decayCorrectionFactorFromLambda(lambda, starttime, duration);
119}
double lambdaFromIsotope(int isotope)
Definition decay.c:63
double decayCorrectionFactorFromLambda(double lambda, double starttime, double duration)
Definition decay.c:79

Referenced by noiseSD4Frame(), and sifWeight().

◆ decayCorrectionFactorFromLambda()

double decayCorrectionFactorFromLambda ( double lambda,
double starttime,
double duration )
extern

Calculate the correction factor for physical decay from measurement time to time zero.

Returns
Factor for decay correction (>1 when lambda>0) or for simulating decay (<1 when lambda<0), or NaN if input is invalid.
See also
lambdaFromIsotope, isotopeIdentify, decayCorrectionFactorFromIsotope
Author
Vesa Oikonen
Parameters
lambdaPositive or negative lambda for the isotope. Note that time unit must be 1/timeunit of the starttime and duration.
starttimeRadioactivity measurement start time, or middle time, if measurement duration is not known.
durationRadioactivity measurement duration; if not known, then set to zero, and put measurement middle time for starttime.

Definition at line 79 of file decay.c.

88 {
89 if(starttime<0.0) return nan("");
90 if(duration<0.0) duration=0.0;
91 if(fabs(lambda)<1.0E-100) return nan("");
92 double cf=exp(lambda*starttime);
93 if(duration>1.0E-10) {
94 double ff=fabs(lambda)*duration/(1.0-exp(-fabs(lambda)*duration));
95 if(lambda<0.0) cf/=ff; else cf*=ff;
96 }
97 return(cf);
98}

Referenced by decayCorrectionFactorFromIsotope(), tacDecayCorrection(), and tacWByFreq().

◆ decayDescr()

char * decayDescr ( decaycorrection d)
extern

Return pointer to string describing the status of decay correction.

See also
isotopeName
Returns
pointer to the name string.
Parameters
dEnum decaycorrection.

Definition at line 32 of file decay.c.

35 {
36 if(d>4) return(decay_correction[0]);
37 return(decay_correction[d]);
38}

Referenced by dcmImgIsotope(), and imgReadDICOM().

◆ elementIdentify()

unsigned short int elementIdentify ( const char * str)
extern

Identify the given string representation of element name or symbol.

See also
elementName, elementSymbol, isotopeIdentify
Returns
Element atomic number Z, or 0 if not identified.
Parameters
strName or symbol of element, for example 'Carbon' or 'C'.

Definition at line 298 of file elements.c.

301 {
302 if(str==NULL || strnlen(str, 5)<1) return(0);
303
304 /* First, search string from the list of element names */
305 for(unsigned short int z=1; z<MAX_ATOMIC_NUMBER; z++)
306 if(strcasecmp(str, element_name[z])==0) return(z);
307
308 /* Then, search string from the list of element symbols */
309 for(unsigned short int z=1; z<MAX_ATOMIC_NUMBER; z++)
310 if(strcasecmp(str, element_symbol[z])==0) return(z);
311
312 /* Not yet successful; then try to find element name as part of the string */
313 for(unsigned short int z=1; z<MAX_ATOMIC_NUMBER; z++)
314 if(strcasestr(str, element_name[z])!=NULL) return(z);
315
316 /* Then try to find two-char element symbol as part of the string */
317 for(unsigned short int z=1; z<MAX_ATOMIC_NUMBER; z++)
318 if(strlen(element_symbol[z])>1 && strstr(str, element_symbol[z])!=NULL) return(z);
319 /* Desperate last step... try to find one-char element symbol as part of the string */
320 for(unsigned short int z=1; z<MAX_ATOMIC_NUMBER; z++)
321 if(strlen(element_symbol[z])==1 && strstr(str, element_symbol[z])!=NULL) return(z);
322
323 return(0);
324}
size_t strnlen(const char *s, size_t n)
Definition stringext.c:566
char * strcasestr(const char *haystack, const char *needle)
Definition stringext.c:155
#define MAX_ATOMIC_NUMBER
Max atomic number, and the size of element_symbol and element_name lists.
Definition tpcisotope.h:33

Referenced by isotopeIdentify().

◆ elementName()

char * elementName ( unsigned short int z)
extern

Return pointer to element name.

See also
elementSymbol, elementIdentify
Returns
pointer to the name string.
Parameters
zAtomic number (Z) of the element.

Definition at line 270 of file elements.c.

273 {
274 if(z>MAX_ATOMIC_NUMBER) return(element_name[0]);
275 return(element_name[z]);
276}

◆ elementSymbol()

char * elementSymbol ( unsigned short int z)
extern

Return pointer to element symbol.

See also
elementName, elementIdentify
Returns
pointer to the symbol string.
Parameters
zAtomic number (Z) of the element.

Definition at line 284 of file elements.c.

287 {
288 if(z>MAX_ATOMIC_NUMBER) return(element_name[0]);
289 return(element_symbol[z]);
290}

◆ isotopeBranching()

double isotopeBranching ( int isotope_code)
extern

Get the branching ratio (fraction) of an isotope spcecified with its isotope_code.

See also
isotopeHalflife, isotopeName, lambdaFromIsotope, decayCorrectionFactorFromIsotope
Returns
branching ratio of the isotope, or NaN if not identified.
Author
Vesa Oikonen
Parameters
isotope_codeisotope_code as enum or the index of isotope in isotope table

Definition at line 81 of file isotope.c.

84 {
85 int n=0;
86
87 while(strlen(tpc_isotope[n].name)>1) n++;
88 if(isotope_code<1 || isotope_code>n-1) return nan("");
89 else if(tpc_isotope[isotope_code].br<1.0E-10) return nan("");
90 else return(tpc_isotope[isotope_code].br);
91}

◆ isotopeHalflife()

double isotopeHalflife ( int isotope_code)
extern

Get the half-life (in minutes) of an isotope specified with its isotope_code.

See also
isotopeBranching, isotopeName, lambdaFromIsotope, decayCorrectionFactorFromIsotope
Returns
halflife of the isotope in minutes, or NaN if not identified.
Author
Vesa Oikonen
Parameters
isotope_codeisotope_code as enum or the index of isotope in isotope table.

Definition at line 62 of file isotope.c.

65 {
66 int n=0;
67
68 while(strlen(tpc_isotope[n].name)>1) n++;
69 if(isotope_code<1 || isotope_code>n-1) return nan("");
70 else return(tpc_isotope[isotope_code].hl);
71}

Referenced by abssWrite(), imgWriteDICOM(), lambdaFromIsotope(), and tacDecayCorrection().

◆ isotopeIdentify()

int isotopeIdentify ( const char * isotope)
extern

Identify the given string representation of isotope, whether it is in format like 'C-11', '11C', '^11^C', or '^11^Carbon'. Even a one-letter symbol like 'C' may be accepted for the most common PET isotopes.

See also
isotopeHalflife, isotopeName, lambdaFromIsotope, decayCorrectionFactorFromIsotope, elementIdentify
Returns
Isotope code, or 0 (enum ISOTOPE_UNKNOWN) if not identified.
Author
Vesa Oikonen
Parameters
isotopeName of isotope to identify.

Definition at line 145 of file isotope.c.

148 {
149 if(isotope==NULL || strnlen(isotope, 5)<1) return ISOTOPE_UNKNOWN;
150
151 unsigned short int i, n=0;
152 while(strlen(tpc_isotope[n].name)>1) n++;
153
154 /* Check, if isotope can be found directly in the table */
155 for(i=0; i<n; i++) {
156 if(strcasecmp(tpc_isotope[i].name, isotope)==0) return(i);
157 }
158
159 /* Ok it was not that easy... try to figure out what it is */
160 char *cptr;
161 int mass_nr=0, ic_mass_nr=0;
162 /* Find the element */
163 unsigned short int z=elementIdentify(isotope);
164 if(z==0) return(ISOTOPE_UNKNOWN);
165 /* Now find the mass number */
166 cptr=strpbrk(isotope, "123456789"); // mass cannot start with zero
167 if(cptr!=NULL) {
168 mass_nr=atoi(cptr);
169 }
170 //printf("fixed isotope: %s-%d\n", elementSymbol(z), mass_nr);
171
172 /* Check if element and mass matches any of the isotopes in our table */
173 for(i=1; i<n; i++) {
174 /* check the element */
175 if(elementIdentify(tpc_isotope[i].name)!=z) continue;
176 /* check the mass, if found */
177 cptr=strchr(tpc_isotope[i].name, '-'); if(cptr==NULL) continue;
178 ic_mass_nr=atoi(cptr+1);
179 if(mass_nr>0 && ic_mass_nr!=mass_nr) continue;
180 /* Match was found! */
181 return(i);
182 }
183
184 return(ISOTOPE_UNKNOWN);
185}
unsigned short int elementIdentify(const char *str)
Definition elements.c:298

Referenced by abssWrite(), dcmImgIsotope(), tacGetIsotope(), tacRead4DM(), and tacReadSIF().

◆ isotopeIdentifyHalflife()

int isotopeIdentifyHalflife ( double halflife)
extern

Identify the isotope based on halflife.

Returns
Isotope code, or 0 (enum ISOTOPE_UNKNOWN) if not identified.
See also
isotopeName, lambdaFromIsotope, decayCorrectionFactorFromIsotope
Author
Vesa Oikonen
Parameters
halflifeHalflife in minutes

Definition at line 121 of file isotope.c.

124 {
125 if(halflife<=0.01) return ISOTOPE_UNKNOWN;
126 int i, n=0;
127 while(strlen(tpc_isotope[n].name)>1) n++;
128 /* Check, if halflife can be found in the table */
129 for(i=1; i<n; i++) {
130 if(fabs(halflife/tpc_isotope[i].hl-1.0)<0.05 ) return i;
131 }
132 return ISOTOPE_UNKNOWN;
133}

Referenced by dcmImgIsotope().

◆ isotopeName()

char * isotopeName ( int isotope_code)
extern

Get the string representation of an isotope specified with its isotope_code.

See also
isotopeBranching, isotopeHalflife, elementName, elementSymbol
Returns
pointer to string representation of the isotope, "unknown" if not identified.
Author
Vesa Oikonen
Parameters
isotope_codeisotope_code as enum or the index of isotope in isotope table.

Definition at line 101 of file isotope.c.

104 {
105 int n=0;
106
107 while(strlen(tpc_isotope[n].name)>1) n++;
108 if(isotope_code<1 || isotope_code>n-1)
109 return tpc_isotope[ISOTOPE_UNKNOWN].name;
110 else
111 return(tpc_isotope[isotope_code].name);
112}

Referenced by dcmImgIsotope(), imgContents(), imgFillOHeader(), imgReadDICOM(), sifWeight(), tacRead4DM(), tacReadSIF(), tacSetIsotope(), tacSetWeights(), and tacWByFreq().

◆ lambdaFromHalflife()

double lambdaFromHalflife ( double halflife)
extern

Calculate lambda based on specified halflife.

Returns
Lambda (=ln(2)/halflife), or NaN if halflife is NaN or <=0.
See also
isotopeIdentifyHalflife, isotopeName, lambdaFromIsotope
Author
Vesa Oikonen
Parameters
halflifeHalflife of the isotope; if halflife is in minutes, then the unit of lambda will be 1/min, if seconds, then lambda will be in units 1/sec, etc.

Definition at line 47 of file decay.c.

51 {
52 if(halflife>0.0) return(M_LN2/halflife); // M_LN2=log(2.0)
53 else return nan("");
54}
#define M_LN2
Defined ln(2) for faster computations.
Definition tpcisotope.h:37

Referenced by tacDecayCorrection().

◆ lambdaFromIsotope()

double lambdaFromIsotope ( int isotope)
extern

Calculate lambda for specified isotope.

Returns
Lambda (=ln(2)/halflife) in units 1/min, or NaN if isotope is not identified.
See also
decayCorrectionFactorFromLambda, isotopeName, isotopeIdentify, decayCorrectionFactorFromIsotope
Author
Vesa Oikonen
Parameters
isotopeisotope_code as enum or the index of isotope in isotope table.

Definition at line 63 of file decay.c.

66 {
67 double hl=isotopeHalflife(isotope); if(isnan(hl) || hl<=0.0) return nan("");
68 return(M_LN2/hl);
69}
double isotopeHalflife(int isotope_code)
Definition isotope.c:62

Referenced by decayCorrectionFactorFromIsotope(), and tacWByFreq().

◆ noiseSD4Frame()

double noiseSD4Frame ( double y,
double t1,
double dt,
int isotope,
double a )
extern

Calculate the standard deviation (SD) of noise for PET radioactivity concentration.

SD of noise can be used in simulations. Reference: Varga & Szabo. J Cereb Blood Flow Metab 2002;22(2):240-244.

See also
isotopeIdentify, drandGaussian, simC3s, simC3p, simRTCM
Returns
Returns the SD, or NaN in case of an error.
Parameters
ySample radioactivity concentration (decay corrected to zero time).
t1Radioactivity measurement (frame) start time in minutes.
dtRadioactivity measurement (frame) duration in minutes.
isotopeIsotope code as enum or index of isotope in isotope table; enter ISOTOPE_UNKNOWN if not to be considered.
aProportionality factor. Note that it should be in relation to the unit of y.

Definition at line 26 of file ranoise.c.

38 {
39 /* Frame start time must be >=0 and frame duration must be >0 */
40 if(isnan(y) || !(t1>=0.0) || !(dt>0.0) || !(a>=0.0)) return(nan(""));
41 /* If concentration is not positive, then its SD is zero */
42 if(!(y>0.0)) return(0.0);
43
44 /* Calculate decay factor (<=1) */
45 double df;
47 df=1.0;
48 } else {
50 if(!(df>0.0 && df<=1.0)) return(nan(""));
51 }
52
53 /* Calculate SD */
54 return(sqrt((a*y)/(dt*df)));
55}
double decayCorrectionFactorFromIsotope(int isotope, double starttime, double duration)
Definition decay.c:107