Changeset 9952 for trunk/ppImage/src/ppImageDetrendFringe.c
- Timestamp:
- Nov 13, 2006, 12:26:09 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ppImage/src/ppImageDetrendFringe.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppImage/src/ppImageDetrendFringe.c
r9857 r9952 5 5 #include "ppImageDetrendFringe.h" 6 6 7 bool ppImageDetrendFringeMeasure(pmFringeStats **science, // (Ptr to) science fringe measurements 8 psArray *references, // Array of reference fringe measurements 9 const pmReadout *readout, // Readout to measure 7 bool ppImageDetrendFringeMeasure(pmReadout *readout, // Readout to measure 8 pmCell *fringe, // Fringe cell (each readout is a different component) 10 9 const ppImageOptions *options // Options 11 10 ) 12 11 { 13 assert(science); 14 PS_ASSERT_ARRAY_NON_NULL(references, false); 12 PS_ASSERT_PTR_NON_NULL(readout, false); 13 PS_ASSERT_PTR_NON_NULL(fringe, false); 14 PS_ASSERT_PTR_NON_NULL(options, false); 15 16 // Reference fringe measurements 17 psArray *references = psMemIncrRefCounter(psMetadataLookupPtr(NULL, fringe->analysis, 18 "FRINGE.MEASUREMENTS")); 19 if (!references) { 20 references = pmFringesParse(fringe); // Reference fringes 21 if (!references) { 22 psError(PS_ERR_IO, false, "Unable to find fringe references.\n"); 23 return false; 24 } 25 psMetadataAdd(fringe->analysis, PS_LIST_TAIL, "FRINGE.MEASUREMENTS", PS_DATA_UNKNOWN, 26 "Fringe measurements", references); 27 } 15 28 16 29 pmFringeStats *reference = references->data[0]; // Take the first as representative 17 30 pmFringeRegions *regions = reference->regions; // Regions to measure 18 pmFringeStats * fringe= pmFringeStatsMeasure(regions, readout, options->maskValue); // Fringe stats31 pmFringeStats *measurements = pmFringeStatsMeasure(regions, readout, options->maskValue); // Fringe stats 19 32 20 33 // Normalise measurements by the exposure time … … 23 36 if (!mdok || !isfinite(expTime)) { 24 37 psError(PS_ERR_UNKNOWN, false, "CELL.EXPOSURE is not set for --- can't normalise fringes\n"); 25 psFree( fringe);38 psFree(measurements); 26 39 return false; 27 40 } … … 30 43 expTime = 1.0; 31 44 } 32 psBinaryOp( fringe->f, fringe->f, "*", psScalarAlloc(1.0 / expTime, PS_TYPE_F32));33 psBinaryOp( fringe->df, fringe->df, "*", psScalarAlloc(1.0 / expTime, PS_TYPE_F32));45 psBinaryOp(measurements->f, measurements->f, "*", psScalarAlloc(1.0 / expTime, PS_TYPE_F32)); 46 psBinaryOp(measurements->df, measurements->df, "*", psScalarAlloc(1.0 / expTime, PS_TYPE_F32)); 34 47 35 if (!*science) { 36 // Only a single readout 37 *science = fringe; 38 } else { 48 // Science fringe measurements 49 pmFringeStats *previous = psMetadataLookupPtr(NULL, readout->parent->analysis, "FRINGE.MEASUREMENTS"); 50 if (previous) { 39 51 // Multiple readouts: concatenate 40 52 psArray *concatenate = psArrayAlloc(2); // Array to hold fringes 41 53 42 54 // Concatenate science measurements 43 concatenate->data[0] = *science;44 concatenate->data[1] = fringe;45 pmFringeStats * sciNew = pmFringeStatsConcatenate(concatenate, NULL, NULL); // New measurements46 psFree( *science);47 *science = sciNew;55 concatenate->data[0] = previous; 56 concatenate->data[1] = measurements; 57 pmFringeStats *new = pmFringeStatsConcatenate(concatenate, NULL, NULL); // New measurements 58 psFree(measurements); 59 measurements = new; 48 60 49 // Concatenate reference measurements 61 // Concatenate reference measurements (duplication, so the science and reference line up) 50 62 for (int i = 0; i < references->n; i++) { 51 63 concatenate->data[0] = concatenate->data[1] = references->data[i]; … … 54 66 references->data[i] = refNew; 55 67 } 56 57 68 concatenate->data[0] = concatenate->data[1] = NULL; 58 69 psFree(concatenate); 59 70 } 71 72 psMetadataAdd(readout->parent->analysis, PS_LIST_TAIL, "FRINGE.MEASUREMENTS", 73 PS_DATA_UNKNOWN | PS_META_REPLACE, "Fringe measurements", measurements); 74 psFree(measurements); 75 76 psFree(references); 60 77 61 78 return true; … … 63 80 64 81 82 // Pull the fringes out of the cell analysis FRINGE.MEASUREMENTS for a chip 83 static psArray *getFringes(const pmChip *chip // Chip of interest 84 ) 85 { 86 psArray *cells = chip->cells; // Component cells 87 psArray *fringes = psArrayAlloc(cells->n); // Fringes, to return 88 for (int i = 0; i < cells->n; i++) { 89 pmCell *cell = cells->data[i]; // Cell of interest 90 fringes->data[i] = psMemIncrRefCounter(psMetadataLookupPtr(NULL, cell->analysis, 91 "FRINGE.MEASUREMENTS")); 92 } 93 94 return fringes; 95 } 96 65 97 66 98 // Solve the fringe system: we have science fringe measurements for each cell, and an array of reference 67 99 // fringe measurements for each cell. Need to concatenate these together first, and then solve. 68 pmFringeScale *ppImageDetrendFringeSolve(psArray *science, // Science fringe measurements (per cell) 69 psArray *references, // Array of array of fringe measurements70 const ppImageOptions *options // Options100 bool ppImageDetrendFringeSolve(pmChip *scienceChip, // Chip with science 101 const pmChip *refChip, // Chip with reference fringes 102 const ppImageOptions *options // Options 71 103 ) 72 104 { 105 PS_ASSERT_PTR_NON_NULL(scienceChip, NULL); 106 PS_ASSERT_PTR_NON_NULL(refChip, NULL); 107 PS_ASSERT_PTR_NON_NULL(options, NULL); 108 109 psArray *science = getFringes(scienceChip); // Fringe measurements on science chip 73 110 pmFringeStats *scienceCat = pmFringeStatsConcatenate(science, NULL, NULL); // Science fringes 111 psFree(science); 74 112 75 113 // Need to transform the array of cells each with an array of fringes --> array of fringes for the chip as 76 114 // a whole 115 psArray *references = getFringes(refChip); // Fringe measurements on reference chip 77 116 int numRefs = ((psArray*)references->data[0])->n; // Number of reference fringes 78 117 psArray *referencesCat = psArrayAlloc(numRefs); // Reference fringes … … 86 125 psFree(refs); 87 126 } 127 psFree(references); 88 128 89 129 // Now we can solve … … 92 132 options->fringeIter, options->fringeKeep); 93 133 134 psMetadataAdd(scienceChip->analysis, PS_LIST_TAIL, "FRINGE.SOLUTION", PS_DATA_UNKNOWN, 135 "Fringe solution", solution); 136 psFree(solution); 94 137 psFree(scienceCat); 95 138 psFree(referencesCat); 96 139 97 return solution;140 return true; 98 141 } 99 142 100 143 101 144 psImage *ppImageDetrendFringeGenerate(pmCell *science, // Science cell 102 pmCell *fringes, // Fringe cell, one readout per fringe component 103 const pmFringeScale *solution // Fringe solution to apply 145 pmCell *fringes // Fringe cell, one readout per fringe component 104 146 ) 105 147 { 106 148 PS_ASSERT_PTR_NON_NULL(science, false); 107 PS_ASSERT_PTR_NON_NULL(solution, false); 149 PS_ASSERT_PTR_NON_NULL(fringes, false); 150 151 pmFringeScale *solution = psMetadataLookupPtr(NULL, science->parent->analysis, "FRINGE.SOLUTION"); 108 152 assert(fringes->readouts->n == solution->nFringeFrames); 109 153
Note:
See TracChangeset
for help on using the changeset viewer.
