Skip to content

Commit

Permalink
smurf: Rewrite RTS values for reverse scans to be increasing in time
Browse files Browse the repository at this point in the history
- The GSL interpolator requires monotonically increasing values for the X dimension
  so the first reordered RTS timestamp is set to the time of the first original timestamp
  and subsequent timestamps are incremented by the original difference between successive values
  • Loading branch information
Matt Sherwood committed Jan 21, 2014
1 parent 5ec6580 commit 72ed7e1
Showing 1 changed file with 15 additions and 39 deletions.
54 changes: 15 additions & 39 deletions applications/smurf/libsc2fts/fts2_validatemirrorpositions.c
Expand Up @@ -40,6 +40,11 @@
* Reverse data also with mirror position array in case of opposite scan direction.
* 2013-11-25 (MS)
* Also treat RTS timing values.
* 2014-01-21 (MS)
* Rewrite RTS values for reverse scans to be increasing in time
* - The GSL interpolator requires monotonically increasing values for the X dimension
* so the first reordered RTS timestamp is set to the time of the first original timestamp
* and subsequent timestamps are incremented by the original difference between successive values
* Copyright:
* Copyright (C) 2010 Science and Technology Facilities Council.
Expand Down Expand Up @@ -116,9 +121,7 @@ void fts2_validatemirrorpositions(double* positions, double* times, int count, i
double EPSILON = s/2;

int i,j,x,y = 0;
double positive = 0.0;
double negative = 0.0;
double direction = 0.0;
int scanDir = 0; /* Mirror scan direction forward==1, reverse==-1 */

double * copyData; /* Array of pointers to DATA/VARIANCE/QUALITY */
size_t nWidth = 0;
Expand All @@ -127,24 +130,12 @@ void fts2_validatemirrorpositions(double* positions, double* times, int count, i
size_t nPixels = 0;
int bolIndex = 0;


/* Determine scan direction */
/* Mirror scans are supposed to be unidirectional (monotonically increasing or decreasing)
but can have slow starts or trailing ends where there is little to no significant change.
Determine the majority direction of this scan: positive or negative.
*/
for(i=0; i<count-1; i++) {
if(positions[i] < positions[i+1])
positive += (positions[i+1] - positions[i]);
else if(positions[i] > positions[i+1])
negative += (positions[i] - positions[i+1]);
}
direction = positive - negative;
smf_fits_getI(inData->hdr, "SCANDIR", &scanDir, status);

/* Invert negative scan */
double* invertedP = NULL; /* Inverted positions */
double* invertedT = NULL; /* Inverted times */
if(direction < 0) {
if(scanDir < 0) {
/* Copy input data into output data for inversion */
nWidth = inData->dims[0];
nHeight = inData->dims[1];
Expand All @@ -155,16 +146,20 @@ void fts2_validatemirrorpositions(double* positions, double* times, int count, i
invertedP = (double*) astCalloc(count, sizeof(*invertedP));
invertedT = (double*) astCalloc(count, sizeof(*invertedT));
for(i=0,j=count-1; i < count; i++,j--) {
/* Do a simple reversal on the positions */
invertedP[i] = positions[j];
invertedT[i] = times[j];
/* Set the first inverted time to the first original time of the reverse scan */
if(i==0) invertedT[i] = times[j];
/* Set subsequent inverted times to be equal to the previous value plus the original difference to the next value */
invertedT[i] = invertedT[i-1] + (times[j+1] - times[j]);
for(x = 0; x < nWidth; x++) {
for(y = 0; y < nHeight; y++) {
bolIndex = x + y * nWidth;
copyData[i*nPixels+bolIndex] = *((double*) inData->pntr[0] + j*nPixels+bolIndex);
}
}
}
// Copy inverted values back to positions and times
/* Copy inverted values back to positions and times */
for(i=0; i < count; i++) {
positions[i] = invertedP[i];
times[i] = invertedT[i];
Expand All @@ -177,15 +172,6 @@ void fts2_validatemirrorpositions(double* positions, double* times, int count, i
}
}

/*
// CREATE SHIFTED MIRROR POSITIONS
double* shifted = (double*) astCalloc(count, sizeof(double));
for(i = 1; i < count; i++) {
shifted[i] = positions[i - 1];
}
shifted[0] = positions[count - 1];
*/

/* COMPUTE DELTA MIRROR POSITIONS */
double* delta = (double*) astCalloc(count, sizeof(double));
for(i = 0; i < count-1; i++) {
Expand All @@ -208,20 +194,10 @@ void fts2_validatemirrorpositions(double* positions, double* times, int count, i
}
}

/*
// CHECK TO SEE IF THE POSITIONS HAVE REPEATING VALUES IN BETWEEN
for(i = *ni + 1; i < *nf; i++) {
if(abs(delta[i]) <= EPSILON) {
*status = SAI__ERROR;
errRep(FUNC_NAME, "Repeating mirror position values found!", status);
}
}
*/

/* CLEANUP: */
if(delta) {astFree(delta); delta = NULL;}
/*if(shifted) {astFree(shifted); shifted = NULL;}*/
if(direction < 0) {
if(scanDir < 0) {
if(invertedP) {
astFree(invertedP);
invertedP = NULL;
Expand Down

0 comments on commit 72ed7e1

Please sign in to comment.