Changeset 5862
- Timestamp:
- Dec 30, 2005, 6:32:45 PM (20 years ago)
- Location:
- trunk/ppMerge/src
- Files:
-
- 1 added
- 8 edited
-
ppMerge.c (modified) (4 diffs)
-
ppMerge.h (modified) (4 diffs)
-
ppMergeCell.c (modified) (2 diffs)
-
ppMergeConfig.c (modified) (2 diffs)
-
ppMergeLoop.c (modified) (5 diffs)
-
ppMergeOptions.c (modified) (3 diffs)
-
ppMergeOutput.c (added)
-
ppMergeParseCamera.c (modified) (6 diffs)
-
ppMergeParseDetrend.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppMerge/src/ppMerge.c
r5860 r5862 1 # include "pp Image.h"1 # include "ppMerge.h" 2 2 3 3 int main (int argc, char **argv) { … … 6 6 ppConfig config; 7 7 ppOptions options; 8 8 9 9 10 psTimerStart("merge"); … … 15 16 // Get camera configuration from header if not already defined 16 17 // Construct camera in preparation for reading 17 ppMergeParseCamera (&data, &config , argv);18 ppMergeParseCamera (&data, &config); 18 19 19 20 // Set various tasks (define optional operations) … … 27 28 28 29 // output options 29 // ppImageOutput (&data, &options, &config);30 ppMergeOutput (&data, &options, &config); 30 31 31 32 exit (0); 32 33 } 34 35 int speedTest (void) 36 { 37 # define NTEST 10000000 38 psStats *testData, *stats; 39 stats = psStatsAlloc (PS_STAT_ROBUST_MEAN); 40 psList *testList = psListAlloc (NULL); 41 psArray *testArray = psArrayAlloc (NTEST); 42 43 psTimerStart("merge"); 44 for (int i = 0; i < NTEST; i++) { 45 testArray->data[i] = stats; 46 } 47 fprintf (stderr, "added %d objects to array: %f usec / obj\n", NTEST, 1e6*psTimerMark ("merge")/NTEST); 48 49 psTimerStart("merge"); 50 for (int i = 0; i < NTEST; i++) { 51 psListAdd (testList, PS_LIST_TAIL, stats); 52 } 53 fprintf (stderr, "added %d objects to list: %f usec / obj\n", NTEST, 1e6*psTimerMark ("merge")/NTEST); 54 55 psTimerStart("merge"); 56 for (int i = 0; i < NTEST; i++) { 57 testData = testArray->data[i]; 58 } 59 fprintf (stderr, "pulled %d objects from array: %f usec / obj\n", NTEST, 1e6*psTimerMark ("merge")/NTEST); 60 61 psTimerStart("merge"); 62 psListElem *tmpInput = (psListElem *) testList->head; 63 while (tmpInput != NULL) { 64 testData = tmpInput->data; 65 tmpInput = tmpInput->next; 66 } 67 fprintf (stderr, "pulled %d objects from list: %f usec / obj\n", NTEST, 1e6*psTimerMark ("merge")/NTEST); 68 69 exit (0); 70 } -
trunk/ppMerge/src/ppMerge.h
r5860 r5862 1 #include <stdio.h> 2 #include <strings.h> 1 # include <stdio.h> 2 # include <strings.h> 3 # include <glob.h> 3 4 4 # include "pslib.h"5 # include "pslib.h" 5 6 6 # include "psAdditionals.h"7 # include "psAdditionals.h" 7 8 8 # include "pmAstrometry.h"9 # include "pmReadout.h"10 # include "pmConfig.h"11 # include "pmFPAConstruct.h"12 # include "pmFPARead.h"13 # include "pmFPAConceptsGet.h"14 # include "pmFPAWrite.h"9 # include "pmAstrometry.h" 10 # include "pmReadout.h" 11 # include "pmConfig.h" 12 # include "pmFPAConstruct.h" 13 # include "pmFPARead.h" 14 # include "pmFPAConceptsGet.h" 15 # include "pmFPAWrite.h" 15 16 16 #include "pmFlatField.h" 17 #include "pmMaskBadPixels.h" 18 #include "pmNonLinear.h" 19 #include "pmSubtractBias.h" 20 #include "pmChipMosaic.h" 21 //#include "pmFPAMorph.h" 17 # include "pmReadoutCombine.h" 22 18 23 # define RECIPE "PHASE2"// Name of the recipe to use19 # define RECIPE "MERGE" // Name of the recipe to use 24 20 21 // XXX : same as in ppImage 25 22 typedef enum { 26 23 PP_LOAD_NONE, … … 30 27 } ppImageLoadDepth; 31 28 29 // XXX : same as in ppImage 32 30 typedef struct { 33 31 psMetadata *site; … … 48 46 49 47 typedef struct { 50 psArray *data; 48 psArray *input; 49 ppFPA *output; 51 50 ppFPA *process; 52 51 ppFPA *mask; … … 55 54 typedef struct { 56 55 ppImageLoadDepth imageLoadDepth; 57 58 psStats *mergeStats; // Statistics for overscan 59 void *overscanFit; // Overscan fit (polynomial or spline) 60 pmFit overscanFitType; // Fit type for overscan 61 pmOverscanAxis overscanMode; // Axis for overscan 62 63 bool doNonLin; // Non-linearity correction 64 psDataType nonLinearType; 65 psMetadataItem *nonLinearData; 66 void *nonLinearSource; 56 bool doMask; // apply a pixel mask before stacking 57 pmCombineParams *combineParams; 58 bool applyZeroScale; 59 double gain; 60 double readnoise; 67 61 } ppOptions; 68 62 69 typedef struct { 70 pmCell *input; 71 pmCell *mask; 72 pmCell *bias; 73 pmCell *dark; 74 pmCell *flat; 75 } ppDetrend; 63 bool ppMergeConfig (ppConfig *config, int argc, char **argv); 64 bool ppMergeLoop (ppData *data, ppOptions *options, ppConfig *config); 65 bool ppMergeOptions (ppData *data, ppOptions *options, ppConfig *config); 66 bool ppMergeOutput (ppData *data, ppOptions *options, ppConfig *config); 67 bool ppMergeParseCamera (ppData *data, ppConfig *config); 68 bool ppMergeParseDetrend (ppData *data, ppOptions *options, ppConfig *config); 76 69 77 bool ppImageConfig (ppConfig *config, int argc, char **argv); 78 bool ppImageLoadPixels (ppFPA *input, ppFPA *process, psDB *db, int nChip, int nCell); 79 bool ppImageLoop (ppData *data, ppOptions *options, ppConfig *config); 80 bool ppImageOptions (ppData *data, ppOptions *options, ppConfig *config); 81 bool ppImageParseCamera (ppData *data, ppConfig *config, char **argv); 82 bool ppImageParseDetrend (ppData *data, ppOptions *options, ppConfig *config); 70 bool ppMergeCell (pmCell *output, pmCell *mask, psArray *cellList, ppOptions *options, ppConfig *config); 83 71 84 bool ppReadoutWeights (pmReadout *readout); 85 86 bool ppDetrendCell (ppDetrend *detrend, ppOptions *options, ppConfig *config); 87 88 bool ppDetrendMask (pmCell *cell, pmReadout *input, pmReadout *mask); 89 bool ppDetrendNonLinear (pmCell *cell, pmReadout *input, ppOptions *options); 90 bool ppDetrendNonLinearLookup (pmReadout *input, psMetadataItem *dataItem); 91 bool ppDetrendNonLinearPolynomial (pmReadout *input, psMetadataItem *dataItem); 92 bool ppDetrendBias (pmCell *inputCell, pmReadout *inputReadout, pmReadout *pedestal, ppOptions *options); 93 pmReadout* ppDetrendPedestal (pmReadout *pedestal, pmCell *input, pmReadout *bias, pmReadout *dark, float darkTime, ppOptions *options); 72 // XXX : these functions are identical to the ppImage equivalents 94 73 pmReadout* ppDetrendSelectFirst (pmCell *cell, char *name, bool doThis); 95 96 74 bool ppFPAOpen (ppFPA *fpa, psMetadata *camera, char *name, bool doThis); 75 bool ppMergeLoadPixels (ppFPA *input, ppFPA *process, psDB *db, int nChip, int nCell); -
trunk/ppMerge/src/ppMergeCell.c
r5860 r5862 1 1 # include "ppMerge.h" 2 3 // mask, bias, dark, flat are defined per Cell4 // pedestal is constructed for each readout, which may have different exposure times5 2 6 3 pmReadout *ppDetrendSelectFirst (pmCell *cell, char *name, bool doThis) { … … 19 16 } 20 17 21 bool ppMergeCell (p sArray *cellList, pmCell *maskCell, ppOptions *options, ppConfig *config) {18 bool ppMergeCell (pmCell *outputCell, pmCell *maskCell, psArray *cellList, ppOptions *options, ppConfig *config) { 22 19 23 20 pmCell *sample = cellList->data[0]; 24 pmReadout *mask = ppDetrendSelectFirst (maskCell, "mask", options->doMask); 21 // pmReadout *mask = ppDetrendSelectFirst (maskCell, "mask", options->doMask); 22 23 // list to carry readouts for processing 24 psArray *inputs = psArrayAlloc (cellList->n); 25 inputs->n = 0; 26 27 psVector *combineZero = psVectorAlloc (128, PS_TYPE_F32); 28 combineZero->n = 0; 29 30 psVector *combineScale = psVectorAlloc (128, PS_TYPE_F32); 31 combineScale->n = 0; 32 33 int nVal = 0; 25 34 26 35 // push all readouts from each image onto the list 27 36 // not clear that this is the right process -- how to merge readouts? 28 37 // are all readouts from this cell equivalent? (ie, across images?) 29 // XXX need to set / carry the zero,scale values 30 31 readouts = psListAlloc (); 32 38 // XXX need to set the zero,scale values correctly for each readout 33 39 for (int i = 0; i < cellList->n; i++) { 34 40 pmCell *cell = cellList->data[i]; 35 41 for (int j = 0; j < cell->readouts->n; j++) { 36 psListAdd (cell->readouts->data[j], PS_LIST_TAIL); 42 psArrayAdd (inputs, 16, cell->readouts->data[j]); 43 44 combineZero->data.F32[nVal] = 0.0; 45 combineScale->data.F32[nVal] = 1.0; 46 psVectorExtend (combineZero, 100, 1); 47 psVectorExtend (combineScale, 100, 1); 48 nVal ++; 37 49 } 38 50 } 39 51 40 // XXX : need to consider the output41 42 psImage *output = pmReadoutCombine (NULL, readouts, params,...);52 // XXX : need to assign these correctly 53 float combineGain = 1.0; 54 float combineNoise = 0.0; 43 55 56 // XXX somehow need to transfer the input cell concepts to the 57 // the output cell. this is weak: are the concepts fixed 58 // or not for a collection of images... 59 outputCell->concepts = sample->concepts; 60 61 // XXX where is the output readouts array allocated? 62 pmReadout *outputReadout = pmReadoutAlloc (outputCell); 63 outputReadout->image = pmReadoutCombine (NULL, inputs, 64 combineZero, 65 combineScale, 66 options->combineParams, 67 options->applyZeroScale, 68 combineGain, combineNoise); 44 69 return true; 45 70 } 71 72 73 // XXX a psList does not make sense here: we are using the fixed length psVectors 74 // to carry bzero and bscale, a psArray should be used for the images -
trunk/ppMerge/src/ppMergeConfig.c
r5860 r5862 1 # include "pp Image.h"1 # include "ppMerge.h" 2 2 3 3 bool ppMergeConfig (ppConfig *config, int argc, char **argv) { … … 20 20 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "-zero", 0, "Name of the mask image", 0); 21 21 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "-scale", 0, "Chip number to process (if positive)", 1); 22 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "-chip", 0, "Chip number to process (if positive)",-1); 22 23 23 24 if (! psArgumentParse(config->arguments, &argc, argv) || argc != 2) { 24 25 printf("\nPan-STARRS Phase 2 processing\n\n"); 25 printf("Usage: %s INPUT.fitsOUTPUT.fits\n\n", argv[0]);26 printf("Usage: %s OUTPUT.fits\n\n", argv[0]); 26 27 psArgumentHelp(config->arguments); 27 28 psFree(config->arguments); -
trunk/ppMerge/src/ppMergeLoop.c
r5860 r5862 3 3 bool ppMergeLoop (ppData *data, ppOptions *options, ppConfig *config) { 4 4 5 ppDetrend detrend;6 7 p pFPA *sampleFPA = data->input->data[0];5 char name[128]; 6 ppFPA *sample = data->input->data[0]; 7 pmFPA *sampleFPA = sample->fpa; 8 8 9 9 psArray *cellList = psArrayAlloc (data->input->n); … … 20 20 // iterate over all chips, using sampleFPA as reference 21 21 for (int i = 0; i < sampleFPA->chips->n; i++) { 22 pmChip *maskChip = data->mask->fpa->chips->data[i]; // Chip of interest in input image 23 pmChip *outputChip = data->output->fpa->chips->data[i]; // Chip of interest in input image 22 24 pmChip *sampleChip = sampleFPA->chips->data[i]; // Chip of interest in input image 23 pmChip *maskChip = data->mask->fpa->chips->data[i]; // Chip of interest in input image24 25 if (! sampleChip->valid) { continue; } 25 26 … … 35 36 // iterate over all cells, using sampleChip as reference 36 37 for (int j = 0; j < sampleChip->cells->n; j++) { 38 pmCell *maskCell = maskChip->cells->data[j]; 39 pmCell *outputCell = outputChip->cells->data[j]; 37 40 pmCell *sampleCell = sampleChip->cells->data[j]; 38 pmCell *maskCell = maskChip->cells->data[j];39 41 if (! sampleCell->valid) { continue; } 40 42 … … 50 52 // build an array of the cells of interest 51 53 for (int k = 0; k < cellList->n; k++) { 52 pmFPA *thisFPA = data->input->data[k]; 54 ppFPA *thisFrame = data->input->data[k]; 55 pmFPA *thisFPA = thisFrame->fpa; 53 56 pmChip *thisChip = thisFPA->chips->data[i]; 54 57 cellList->data[k] = thisChip->cells->data[j]; … … 56 59 57 60 // run the merge function 58 ppMergeCell (cellList, maskCell, options, config); 61 ppMergeCell (outputCell, maskCell, cellList, options, config); 62 63 sprintf (name, "test.%d.%d.fits", i, j); 64 psFits *fits = psFitsOpen (name, "w"); 65 pmReadout *readout = outputCell->readouts->data[0]; 66 psFitsWriteImage (fits, NULL, readout->image, 0); 67 psFitsClose (fits); 68 69 # if (0) 70 if (sampleCell->hdu) { 71 outputCell->hdu = sampleCell->hdu; 72 outputCell->hdu->images = psArrayAlloc (1); 73 outputCell->hdu->images->data[0] = outputCell->readouts->data[0]; 74 } 75 # endif 59 76 } 77 # if (0) 78 if (sampleChip->hdu) { 79 outputChip->hdu = sampleChip->hdu; 80 outputChip->hdu->images = psArrayAlloc (1); 81 // outputChip->hdu->images->data[0] = outputChip->readouts->data[0]; 82 } 83 # endif 60 84 } 61 85 return true; -
trunk/ppMerge/src/ppMergeOptions.c
r5860 r5862 1 # include "pp Image.h"1 # include "ppMerge.h" 2 2 3 3 // XXX EAM : optionally choose the mask image based on the detrend database … … 26 26 } 27 27 28 // how do we calculate the merge stack? 29 options->mergeStats = NULL; 30 psString stat = psMetadataLookupStr(NULL, config->recipe, "MERGE.STAT"); 31 if (! strcasecmp(stat, "MEAN")) { 32 options->mergeStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN); 33 } else if (! strcasecmp(stat, "MEDIAN")) { 34 options->mergeStats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN); 35 } else { 36 psErrorStackPrint(stderr, "MERGE.STAT (%s) is not one of MEAN, MEDIAN: assuming MEAN\n", stat); 37 options->mergeStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN); 38 } 39 40 // mask - recipe options 28 // global pixel mask 29 options->doMask = false; 41 30 if (psMetadataLookupBool(NULL, config->recipe, "MASK")) { 42 31 data->mask->filename = psMetadataLookupStr(NULL, config->arguments, "-mask"); … … 49 38 } 50 39 40 // how do we calculate the merge stack? 41 psStatsOptions mergeStats = 0; 42 psString stat = psMetadataLookupStr(NULL, config->recipe, "MERGE.STAT"); 43 if (! strcasecmp(stat, "MEAN")) { 44 mergeStats = PS_STAT_SAMPLE_MEAN; 45 } else if (! strcasecmp(stat, "MEDIAN")) { 46 mergeStats = PS_STAT_SAMPLE_MEDIAN; 47 } else { 48 psAbort ("merge", "MERGE.STAT (%s) is not one of MEAN, MEDIAN\n", stat); 49 } 50 options->combineParams = pmCombineParamsAlloc (mergeStats); 51 52 // other merge stack options 53 options->applyZeroScale = psMetadataLookupBool(NULL, config->recipe, "MERGE.RESCALE"); 54 55 int nKeep = psMetadataLookupS32(&status, config->recipe, "MERGE.NKEEP"); 56 if (status && nKeep > 0) { 57 options->combineParams->nKeep = nKeep; 58 } 59 60 float fracHigh = psMetadataLookupF32(&status, config->recipe, "MERGE.FRAC.HIGH"); 61 if (status) { 62 options->combineParams->fracHigh = fracHigh; 63 } 64 65 float fracLow = psMetadataLookupF32(&status, config->recipe, "MERGE.FRAC.LOW"); 66 if (status) { 67 options->combineParams->fracLow = fracLow; 68 } 69 70 // XXX need to set the masking value somehow... 71 72 // gain and readnoise come from camera parameters and depend on chip/cell 73 // XXX drop these from the options structure? 74 options->gain = 1.0; 75 options->readnoise = 0.0; 76 51 77 return true; 52 78 } -
trunk/ppMerge/src/ppMergeParseCamera.c
r5860 r5862 38 38 ppFPA *fpa = ppFPA_Alloc (); 39 39 fpa->filename = psStringCopy (globList.gl_pathv[i]); 40 psArrayAdd (input, 100, fpa); 40 41 } 41 psArrayAdd (input, 100, fpa);42 42 } 43 43 … … 56 56 } 57 57 while (fgets (line, 1024, f) != NULL) { 58 nItems = fscanf (f, "%s %lf %lf", filename, &zero, &scale);59 fpa = ppFPA_Alloc ();58 nItems = sscanf (line, "%s %lf %lf", filename, &zero, &scale); 59 ppFPA *fpa = ppFPA_Alloc (); 60 60 switch (nItems) { 61 61 case 0: … … 65 65 fpa->zero = zero; 66 66 fpa->scale = scale; 67 // NOTE: continues to case 1 below 67 fpa->filename = psStringCopy (filename); 68 psArrayAdd (input, 100, fpa); 69 break; 68 70 case 1: 69 71 fpa->filename = psStringCopy (filename); … … 85 87 86 88 // Open the input images, test that they are the same camera 87 psLogMsg(" phase2", PS_LOG_INFO, "Opening input images\n");89 psLogMsg("merge", PS_LOG_INFO, "Opening input images\n"); 88 90 for (int i = 0; i < input->n; i++) { 89 91 90 92 ppFPA *fpa = input->data[i]; 93 94 psLogMsg("merge", PS_LOG_INFO, "Trying %s...\n", fpa->filename); 91 95 92 96 fpa->fits = psFitsOpen(fpa->filename, "r"); // File handle for FITS file … … 130 134 131 135 // data->process acts as a process mask for the full FPA 132 data->process = pmFPAConstruct(config->camera); 136 data->process = ppFPA_Alloc (); 137 data->process->fpa = pmFPAConstruct(config->camera); 133 138 134 139 // see if we have selected a specific chip … … 144 149 // data->mask carries a pixel mask for pixels to be ignored 145 150 // the name and contents of the mask are determined in ppMergeOptions 146 data->mask = pmFPAConstruct(config->camera); 151 data->mask = ppFPA_Alloc (); 152 data->mask->fpa = pmFPAConstruct(config->camera); 153 154 // data->output will store the output file 155 // currently, we keep the complete output file and write it at the end 156 data->output = ppFPA_Alloc (); 157 data->output->fpa = pmFPAConstruct(config->camera); 158 data->output->filename = psMetadataLookupPtr (NULL, config->arguments, "-output"); 159 if (! *data->output->filename) { 160 psAbort ("merge", "output file not specified"); 161 } 147 162 148 163 return true; -
trunk/ppMerge/src/ppMergeParseDetrend.c
r5860 r5862 1 # include "pp Image.h"1 # include "ppMerge.h" 2 2 3 3 // open all needed detrend files
Note:
See TracChangeset
for help on using the changeset viewer.
