Commit 01b6c03b authored by Vesa Oikonen's avatar Vesa Oikonen
Browse files

tacpeak has new option -swa

parent c382675a
......@@ -33,6 +33,8 @@ static char *info[] = {
" Estimate time when TAC decreases to specified percentage of peak value.",
" -wt",
" Peak time is reported as weighted average of subsequent samples.",
" -swa",
" TAC mean is subtracted from peak value.",
" -stdoptions", // List standard options like --help, -v, etc
" ",
"See also: imgpeak, dftmax, inpstart, tacrange, taccut, tacslope",
......@@ -61,7 +63,8 @@ int main(int argc, char **argv)
int ai, help=0, version=0, verbose=1;
char tacfile[FILENAME_MAX], parfile[FILENAME_MAX];
double decr=nan("");
int timeAsWAvg=0; // 1=report peak time as activity weighted mean
int timeAsWAvg=0; // 1=report peak time as activity weighted mean.
int subtractWAvg=0; // 1=subtract TAC mean from the peak value.
/*
......@@ -79,6 +82,8 @@ int main(int argc, char **argv)
}
} else if(strcasecmp(cptr, "WT")==0) {
timeAsWAvg=1; continue;
} else if(strcasecmp(cptr, "SWA")==0) {
subtractWAvg=1; continue;
}
fprintf(stderr, "Error: invalid option '%s'\n", argv[ai]);
return(1);
......@@ -110,6 +115,7 @@ int main(int argc, char **argv)
if(parfile[0]) printf("parfile := %s\n", parfile);
if(!isnan(decr)) printf("decr_percent := %g\n", decr);
printf("timeAsWAvg := %d\n", timeAsWAvg);
printf("subtractWAvg := %d\n", subtractWAvg);
}
......@@ -205,28 +211,40 @@ int main(int argc, char **argv)
}
/* If requested, search time after peak when TAC drops to specified level */
if(isnan(decr)) continue;
double ylim=(decr/100.0)*ymax;
double x1=tac.x[imax];
double y1=tac.c[ci].y[imax];
double x2, y2; x2=y2=nan("");
for(int i=imax+1; i<tac.sampleNr; i++) {
if(isnan(tac.x[i])) continue;
if(isnan(tac.c[ci].y[i])) continue;
if(tac.c[ci].y[i]>ylim) {x1=tac.x[i]; y1=tac.c[ci].y[i]; continue;}
x2=tac.x[i]; y2=tac.c[ci].y[i];
break;
}
if(isnan(x2) || isnan(y2)) {
fprintf(stderr, "Error: TAC '%s' does not drop to specified level.\n", tac.c[ci].name);
continue;
if(!isnan(decr)) {
double ylim=(decr/100.0)*ymax;
double x1=tac.x[imax];
double y1=tac.c[ci].y[imax];
double x2, y2; x2=y2=nan("");
for(int i=imax+1; i<tac.sampleNr; i++) {
if(isnan(tac.x[i])) continue;
if(isnan(tac.c[ci].y[i])) continue;
if(tac.c[ci].y[i]>ylim) {x1=tac.x[i]; y1=tac.c[ci].y[i]; continue;}
x2=tac.x[i]; y2=tac.c[ci].y[i];
break;
}
if(isnan(x2) || isnan(y2)) {
fprintf(stderr, "Error: TAC '%s' does not drop to specified level.\n", tac.c[ci].name);
} else {
if(verbose>2) {
printf(" prev_sample := (%g, %g)\n", x1, y1);
printf(" next_sample := (%g, %g)\n", x2, y2);
}
if(fabs(y2-y1)>1.0E-20) par.r[ci].p[2]=x1+(ylim-y1)*(x2-x1)/(y2-y1);
else par.r[ci].p[2]=0.5*(x1+x2);
}
}
if(verbose>2) {
printf(" prev_sample := (%g, %g)\n", x1, y1);
printf(" next_sample := (%g, %g)\n", x2, y2);
/* If requested, compute TAC mean and subtract it from the peak value */
if(subtractWAvg) {
double auc=tacAUC(&tac, ci, xmin, xmax, NULL);
if(isnan(auc)) {
fprintf(stderr, "Error: invalid mean of TAC '%s'.\n", tac.c[ci].name);
} else {
double avg=auc/(xmax-xmin);
par.r[ci].p[0]-=avg;
}
}
if(fabs(y2-y1)>1.0E-20) par.r[ci].p[2]=x1+(ylim-y1)*(x2-x1)/(y2-y1);
else par.r[ci].p[2]=0.5*(x1+x2);
} // next TAC
tacFree(&tac);
......
......@@ -82,6 +82,30 @@ if [ ! -f radiowater.sif ] || [ ! -f radiowater.tac ] || [ ! -f radiowaterf.svg
fi
if [ ! -f peak.tac ] || [ ! -f peak.dat ] || [ ! -f correct_peak1.par ] || [ ! -f correct_peak2.par ]; then
printf "\n creating peak.tac \n"
printf "start[minutes] end[kBq/cc] Aorta\n" > peak.tac
printf "0.0 1.0 100.0\n" >> peak.tac
printf "1.0 2.0 80.0\n" >> peak.tac
printf "2.0 3.0 60.0\n" >> peak.tac
printf "3.0 4.0 40.0\n" >> peak.tac
printf "4.0 5.0 20.0\n" >> peak.tac
printf "5.0 10.0 10.0\n" >> peak.tac
printf "10.0 60.0 10.0\n" >> peak.tac
printf "Parameters Peak PeakT\n" > correct_peak1.par
printf "Aorta 85.8333 0.5\n" >> correct_peak1.par
printf "\n making peak.dat \n"
tacformat -mid -f=SIMPLE peak.tac peak.dat
if [ $? -ne 0 ] ; then printf "Failed!\n" ; exit 1 ; fi
printf "Parameters Peak PeakT\n" > correct_peak2.par
printf "Aorta 83.7681 0.5\n" >> correct_peak2.par
fi
printf "\n\n"
printf "=====================================================================\n"
......@@ -224,6 +248,34 @@ if [ $? -ne 0 ] ; then printf "\nFailed!\n" ; exit 1 ; fi
printf "\n passed. \n\n"
printf "=====================================================================\n"
printf "\n\n 3.0.0 \n"
printf " Test case 1: Option -swa. \n"
printf " Test case 2: TAC with frame lengths. \n"
printf " Expected result: Correct TAC peaks are found and subtracted peak value reported. \n\n"
$PROGRAM -swa peak.tac output.par
if [ $? -ne 0 ] ; then printf "\nFailed!\n" ; exit 1 ; fi
printf "\n ok \n"
parmatch -abs=0.001 correct_peak1.par output.par
if [ $? -ne 0 ] ; then printf "\nFailed!\n" ; exit 1 ; fi
printf "\n passed. \n\n"
printf "\n\n 3.0.1 \n"
printf " Test case 1: Option -swa. \n"
printf " Test case 2: TAC without frame lengths. \n"
printf " Expected result: Correct TAC peaks are found and subtracted peak value reported. \n\n"
$PROGRAM -swa peak.dat output.par
if [ $? -ne 0 ] ; then printf "\nFailed!\n" ; exit 1 ; fi
printf "\n ok \n"
parmatch -abs=0.001 correct_peak2.par output.par
if [ $? -ne 0 ] ; then printf "\nFailed!\n" ; exit 1 ; fi
printf "\n passed. \n\n"
printf "=====================================================================\n"
printf " All passed!\n"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment