Changeset 5976
- Timestamp:
- Jan 13, 2006, 5:14:07 PM (20 years ago)
- Location:
- trunk/ppImage/src
- Files:
-
- 10 edited
-
Makefile.am (modified) (1 diff)
-
ppImage.c (modified) (2 diffs)
-
ppImage.h (modified) (2 diffs)
-
ppImageConfig.c (modified) (3 diffs)
-
ppImageDetrendNonLinear.c (modified) (5 diffs)
-
ppImageLoadPixels.c (modified) (1 diff)
-
ppImageLoop.c (modified) (3 diffs)
-
ppImageOptions.c (modified) (4 diffs)
-
ppImageParseCamera.c (modified) (3 diffs)
-
ppImageParseDetrend.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppImage/src/Makefile.am
r5910 r5976 9 9 ppDetrendNonLinear.c \ 10 10 ppDetrendPedestal.c \ 11 ppFile.c \ 11 12 ppImage.c \ 12 13 ppImageConfig.c \ -
trunk/ppImage/src/ppImage.c
r5860 r5976 1 # include "ppImage.h"1 #include "ppImage.h" 2 2 3 int main (int argc, char **argv) { 3 int main(int argc, char **argv) 4 { 4 5 5 6 ppData data; … … 7 8 ppOptions options; 8 9 9 psTimerStart( "phase2");10 psTimerStart(TIMERNAME); 10 11 11 12 // Parse the configuration and arguments 12 ppImageConfig (&config, argc, argv);13 ppImageConfig(&config, argc, argv); 13 14 14 15 // Open the input image, output image, output mask 15 16 // Get camera configuration from header if not already defined 16 17 // Construct camera in preparation for reading 17 ppImageParseCamera (&data, &config);18 ppImageParseCamera(&data, &config); 18 19 19 20 // Set various tasks (define optional operations) 20 ppImageOptions (&data, &options, &config);21 ppImageOptions(&data, &options, &config); 21 22 22 23 // open detrend images, load headers, optionally load pixels 23 ppImageParseDetrend (&data, &options, &config);24 ppImageParseDetrend(&data, &options, &config); 24 25 25 26 // Image Arithmetic Loop 26 ppImageLoop (&data, &options, &config);27 ppImageLoop(&data, &options, &config); 27 28 28 29 // output options 29 // ppImageOutput (&data, &options, &config);30 // ppImageOutput(&data, &options, &config); 30 31 31 exit (0);32 exit(EXIT_SUCCESS); 32 33 } -
trunk/ppImage/src/ppImage.h
r5860 r5976 1 #ifndef PP_IMAGE_H 2 #define PP_IMAGE_H 3 1 4 #include <stdio.h> 2 5 #include <strings.h> … … 22 25 23 26 #define RECIPE "PHASE2" // Name of the recipe to use 27 #define TIMERNAME "ppImage" // Name of timer 24 28 29 // How much of the FPA to load at a time 25 30 typedef enum { 26 PP_LOAD_NONE, 27 PP_LOAD_FPA, 28 PP_LOAD_CHIP, 29 PP_LOAD_CELL, 31 PP_LOAD_NONE, // Don't load anything 32 PP_LOAD_FPA, // Load the entire FPA at once 33 PP_LOAD_CHIP, // Load by chip 34 PP_LOAD_CELL, // Load by cell 30 35 } ppImageLoadDepth; 31 36 37 // Configuration data 32 38 typedef struct { 33 psMetadata *site; 34 psMetadata *camera; 35 psMetadata *recipe; 36 psMetadata *arguments; 37 psDB *database; 39 psMetadata *site; // The site configuration 40 psMetadata *camera; // The camera configuration 41 psMetadata *recipe; // The recipe (i.e., specific setups) 42 psMetadata *arguments; // The command-line arguments 43 psDB *database; // Database handle 38 44 } ppConfig; 39 45 46 // Options 40 47 typedef struct { 41 bool doMask; // Mask bad pixles42 bool doBias; // Bias subtraction43 bool doDark; // Dark subtraction44 bool doFlat; // Flat-field normalisation45 bool doFringe; // Fringe subtraction46 bool doSource; // Source identification and photometry47 bool doAstrom; // Astrometry48 bool doMask; // Mask bad pixels 49 bool doBias; // Bias subtraction 50 bool doDark; // Dark subtraction 51 bool doFlat; // Flat-field normalisation 52 bool doFringe; // Fringe subtraction 53 bool doSource; // Source identification and photometry 54 bool doAstrom; // Astrometry 48 55 49 bool doOverscan; // Overscan subtraction50 int overscanBins; // Number of pixels per bin for overscan51 psStats *overscanStats; // Statistics for overscan52 void *overscanFit; // Overscan fit (polynomial or spline)53 pmFit overscanFitType; // Fit type for overscan54 pmOverscanAxis overscanMode; // Axis for overscan56 bool doOverscan; // Overscan subtraction 57 int overscanBins; // Number of pixels per bin for overscan 58 psStats *overscanStats; // Statistics for overscan 59 void *overscanFit; // Overscan fit (polynomial or spline) 60 pmFit overscanFitType; // Fit type for overscan 61 pmOverscanAxis overscanMode; // Axis for overscan 55 62 56 bool doNonLin; // Non-linearity correction63 bool doNonLin; // Non-linearity correction 57 64 psDataType nonLinearType; 58 65 psMetadataItem *nonLinearData; 59 66 void *nonLinearSource; 60 67 61 ppImageLoadDepth imageLoadDepth; 68 ppImageLoadDepth imageLoadDepth; // How much of the FPA to load at once 62 69 } ppOptions; 63 70 71 // A file to process 64 72 typedef struct { 65 char *filename; 66 p mFPA *fpa;67 ps Fits *fits;68 p sMetadata *header;69 } ppF PA;73 char *filename; // File name 74 psFits *fits; // The FITS file handle 75 psMetadata *phu; // The FITS header 76 pmFPA *fpa; // The FPA, with pixels and extensions 77 } ppFile; 70 78 79 // The data to be processed 71 80 typedef struct { 72 ppFPA *input; 73 ppFPA *mask; 74 ppFPA *bias; 75 ppFPA *dark; 76 ppFPA *flat; 77 ppFPA *fringe; 78 ppFPA *process; 81 ppFile *input; // The input, to be operated upon 82 ppFile *mask; // The bad pixel mask image 83 ppFile *bias; // The bias correction image 84 ppFile *dark; // The dark correction image 85 ppFile *flat; // The flat-field correction image 86 ppFile *fringe; // The fringe correction image 87 #if 0 88 ppFile *process; // A dummy file pointing out what needs to be processed 89 #endif 79 90 } ppData; 80 91 92 // Cells to be used in the detrend 81 93 typedef struct { 82 pmCell *input; 83 pmCell *mask; 84 pmCell *bias; 85 pmCell *dark; 86 pmCell *flat; 94 pmCell *input; // The input cell, to be operated upon 95 pmCell *mask; // The bad pixel mask 96 pmCell *bias; // The bias correction 97 pmCell *dark; // The dark correction 98 pmCell *flat; // The flat-field correction 87 99 } ppDetrend; 88 100 89 bool ppImageConfig (ppConfig *config, int argc, char **argv);90 bool ppImageLoadPixels (ppFPA *input, ppFPA *process, psDB *db, int nChip, int nCell);91 bool ppImageLoop (ppData *data, ppOptions *options, ppConfig *config);92 bool ppImageOptions (ppData *data, ppOptions *options, ppConfig *config);93 bool ppImageParseCamera (ppData *data, ppConfig *config);94 bool ppImageParseDetrend (ppData *data, ppOptions *options, ppConfig *config);95 101 96 bool ppReadoutWeights (pmReadout *readout); 102 // Allocators 103 ppFile *ppFileAlloc(void); 97 104 98 bool ppDetrendCell (ppDetrend *detrend, ppOptions *options, ppConfig *config);99 105 100 bool ppDetrendMask (pmCell *cell, pmReadout *input, pmReadout *mask);101 bool ppDetrendNonLinear (pmCell *cell, pmReadout *input, ppOptions *options);102 bool ppDetrendNonLinearLookup (pmReadout *input, psMetadataItem *dataItem);103 bool ppDetrendNonLinearPolynomial (pmReadout *input, psMetadataItem *dataItem);104 bool ppDetrendBias (pmCell *inputCell, pmReadout *inputReadout, pmReadout *pedestal, ppOptions *options);105 pmReadout* ppDetrendPedestal (pmReadout *pedestal, pmCell *input, pmReadout *bias, pmReadout *dark, float darkTime, ppOptions *options);106 pmReadout* ppDetrendSelectFirst (pmCell *cell, char *name, bool doThis);107 106 108 bool ppFPAOpen (ppFPA *fpa, psMetadata *camera, char *name, bool doThis); 107 // Parse the site configuration (and camera and recipe if specified); read the command-line arguments 108 bool ppImageConfig(ppConfig *config, // The configuration(output) 109 int argc, char **argv // Command-line arguments 110 ); 111 112 // Determine what type of camera, and initialise 113 bool ppImageParseCamera(ppData *data, // The data to be processed 114 ppConfig *config // Configuration 115 ); 116 117 // Determine the procession options 118 bool ppImageOptions(ppData *data, // The data to be processed 119 ppOptions *options, // Processing options 120 ppConfig *config // Configuration 121 ); 122 123 124 // Loop over the 125 bool ppImageLoop(ppData *data, ppOptions *options, ppConfig *config); 126 127 // Load the pixels for the given file 128 bool ppImageLoadPixels(ppFile *input, // File for which to load the pixels 129 psDB *db, // Database handle (for reading concepts) 130 int nChip, // Chip number to load 131 int nCell // Cell number to load 132 ); 133 134 bool ppImageParseDetrend(ppData *data, ppOptions *options, ppConfig *config); 135 136 bool ppReadoutWeights(pmReadout *readout); 137 138 bool ppDetrendCell(ppDetrend *detrend, ppOptions *options, ppConfig *config); 139 140 bool ppDetrendMask(pmCell *cell, pmReadout *input, pmReadout *mask); 141 bool ppDetrendNonLinear(pmCell *cell, pmReadout *input, ppOptions *options); 142 bool ppDetrendNonLinearLookup(pmReadout *input, psMetadataItem *dataItem); 143 bool ppDetrendNonLinearPolynomial(pmReadout *input, psMetadataItem *dataItem); 144 bool ppDetrendBias(pmCell *inputCell, pmReadout *inputReadout, pmReadout *pedestal, ppOptions *options); 145 pmReadout* ppDetrendPedestal(pmReadout *pedestal, pmCell *input, pmReadout *bias, pmReadout *dark, float darkTime, ppOptions *options); 146 pmReadout* ppDetrendSelectFirst(pmCell *cell, char *name, bool doThis); 147 148 #if 0 149 bool ppFileOpen(ppFile *fpa, psMetadata *camera, char *name, bool doThis); 150 #endif 151 152 153 #endif // Pau. -
trunk/ppImage/src/ppImageConfig.c
r5858 r5976 1 # include "ppImage.h"1 #include "ppImage.h" 2 2 3 bool ppImageConfig (ppConfig *config, int argc, char **argv) { 3 bool ppImageConfig(ppConfig *config, int argc, char **argv) 4 { 5 // Initialise the configuration 6 config->site = NULL; // Site configuration 7 config->camera = NULL; // Camera configuration 8 config->recipe = NULL; // Recipe configuration 9 config->arguments = NULL; // The command-line arguments 10 config->database = NULL; // Database handle 4 11 5 // Parse the configurations 6 config->site = NULL; // Site configuration 7 config->camera = NULL; // Camera configuration 8 config->recipe = NULL; // Recipe configuration 9 10 // XXX - this should be split into a function to parse argc,argv 11 // and a second to read the config files. 12 // XXX - this should be split into a function to parse argc,argv 13 // and a second to read the config files. 12 14 // all argc,argv should be interpretted before work is done. 13 15 if (! pmConfigRead(&config->site, &config->camera, &config->recipe, &argc, argv, RECIPE)) { … … 23 25 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-flat", 0, "Name of the flat-field image", ""); 24 26 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-mask", 0, "Name of the mask image", ""); 27 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-fringe", 0, "Name of the fringe image", ""); 25 28 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "-chip", 0, "Chip number to process (if positive)", -1); 26 29 … … 33 36 } 34 37 35 // add the input and output imagesto the arguments list36 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "-input", 0, "Name of the input image", argv[1]);37 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "-output", 0, "Name of the output image", argv[2]);38 // Add the input and output images (which remain on the command-line) to the arguments list 39 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-input", 0, "Name of the input image", argv[1]); 40 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-output", 0, "Name of the output image", argv[2]); 38 41 39 // define Database handle, if used 42 // Define database handle, if used 43 #if 0 40 44 config->database = pmConfigDB(config->site); 45 #endif 46 41 47 return true; 42 } 48 } -
trunk/ppImage/src/ppImageDetrendNonLinear.c
r5858 r5976 6 6 psVector *coeff = dataItem->data.V; // The coefficient vector 7 7 if (coeff->type.type != PS_TYPE_F64) { 8 psVector *temp = psVectorCopy(NULL, coeff, PS_TYPE_F64); // F64 version9 psFree (coeff);10 coeff = temp;8 psVector *temp = psVectorCopy(NULL, coeff, PS_TYPE_F64); // F64 version 9 psFree (coeff); 10 coeff = temp; 11 11 } 12 12 psPolynomial1D *correction = psPolynomial1DAlloc(coeff->n - 1, PS_POLYNOMIAL_ORD); … … 17 17 psFree(correction); 18 18 return true; 19 } 19 } 20 20 21 21 bool ppDetrendNonLinearLookup (pmReadout *input, psMetadataItem *dataItem) { … … 25 25 psLookupTable *table = psLookupTableAlloc(name, "%f %f", 0); 26 26 if (psLookupTableRead(table) <= 0) { 27 psErrorStackPrint(stderr, "Unable to read non-linearity correction file "28 "%s --- ignored\n", name);29 return false;30 } 27 psErrorStackPrint(stderr, "Unable to read non-linearity correction file " 28 "%s --- ignored\n", name); 29 return false; 30 } 31 31 #ifdef PRODUCTION 32 32 pmNonLinearityLookup(input, table); … … 38 38 psFree(table); 39 39 return true; 40 } 40 } 41 41 42 42 bool ppDetrendNonLinear (pmCell *cell, pmReadout *input, ppOptions *options) { … … 46 46 switch (options->nonLinearType) { 47 47 case PS_DATA_VECTOR: 48 ppDetrendNonLinearPolynomial (input, options->nonLinearData);49 return true;48 ppDetrendNonLinearPolynomial (input, options->nonLinearData); 49 return true; 50 50 51 51 case PS_DATA_STRING: 52 ppDetrendNonLinearLookup (input, options->nonLinearData);53 return true;52 ppDetrendNonLinearLookup (input, options->nonLinearData); 53 return true; 54 54 55 55 case PS_DATA_METADATA: 56 // XXX this is somewhat confusing : let's wrap in a function when i understand it 57 concept = pmCellGetConcept(cell, options->nonLinearSource); 58 if (! concept) { 59 psLogMsg("phase2", PS_LOG_WARN, "Unable to find value of concept %s " 60 "for non-linearity correction --- ignored.\n", options->nonLinearSource); 61 return false; 62 } 63 if (concept->type != PS_DATA_STRING) { 64 psLogMsg("phase2", PS_LOG_WARN, "Type for concept %s isn't STRING, as" 65 " expected for non-linearity correction --- ignored.\n", 66 concept); 67 return false; 68 } 56 // XXX EAM: this is somewhat confusing : let's wrap in a function when i understand it 69 57 70 // Get the value of the concept 71 psString conceptValue = concept->data.V; 72 psMetadata *folder = (psMetadata *)options->nonLinearData->data.V; 73 psMetadataItem *optionItem = psMetadataLookup(folder, conceptValue); 74 if (!optionItem) { 75 psLogMsg("phase2", PS_LOG_WARN, "Unable to find %s in NONLIN.DATA" 76 " --- ignored.\n", conceptValue); 77 return false; 78 } 58 // Go looking for the value in the hierarchy 59 concept = psMetadataLookup(cell->concepts, options->nonLinearSource); 60 if (! concept) { 61 pmChip *chip = cell->parent;// Parent chip 62 concept = psMetadataLookup(chip->concepts, options->nonLinearSource); 63 if (! concept) { 64 pmFPA *fpa = chip->parent; // Parent FPA 65 concept = psMetadataLookup(fpa->concepts, options->nonLinearSource); 66 if (! concept) { 67 psLogMsg("phase2", PS_LOG_WARN, "Unable to find value of concept %s " 68 "for non-linearity correction --- ignored.\n", options->nonLinearSource); 69 return false; 70 } 71 } 72 } 79 73 80 switch (optionItem->type) { 81 case PS_DATA_VECTOR: 82 ppDetrendNonLinearPolynomial (input, optionItem); 83 return true; 84 case PS_DATA_STRING: 85 ppDetrendNonLinearLookup (input, optionItem); 86 return true; 87 default: 88 psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction " 89 "desired but unable to interpret NONLIN.DATA for %s" 90 " --- ignored\n", conceptValue); 91 return false; 92 } 74 if (concept->type != PS_DATA_STRING) { 75 psLogMsg("phase2", PS_LOG_WARN, "Type for concept %s isn't STRING, as" 76 " expected for non-linearity correction --- ignored.\n", 77 concept); 78 return false; 79 } 80 81 // Get the value of the concept 82 psString conceptValue = concept->data.V; 83 psMetadata *folder = (psMetadata *)options->nonLinearData->data.V; 84 psMetadataItem *optionItem = psMetadataLookup(folder, conceptValue); 85 if (!optionItem) { 86 psLogMsg("phase2", PS_LOG_WARN, "Unable to find %s in NONLIN.DATA" 87 " --- ignored.\n", conceptValue); 88 return false; 89 } 90 91 switch (optionItem->type) { 92 case PS_DATA_VECTOR: 93 ppDetrendNonLinearPolynomial (input, optionItem); 94 return true; 95 case PS_DATA_STRING: 96 ppDetrendNonLinearLookup (input, optionItem); 97 return true; 98 default: 99 psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction " 100 "desired but unable to interpret NONLIN.DATA for %s" 101 " --- ignored\n", conceptValue); 102 return false; 103 } 93 104 default: 94 psAbort("phase2", "Invalid options->nonLinearType");105 psAbort("phase2", "Invalid options->nonLinearType"); 95 106 } 96 107 return true; -
trunk/ppImage/src/ppImageLoadPixels.c
r5858 r5976 1 # include "ppImage.h" 1 // XXX PAP: Need to look this over some more 2 2 3 bool ppImageLoadPixels (ppFPA *input, ppFPA *process, psDB *db, int nChip, int nCell) { 3 #include "ppImage.h" 4 4 5 // an input chip is valid if: 6 // (((nChip == i) || (nChip == -1)) && process.valid) 5 bool ppImageLoadPixels(ppFile *input, psDB *db, int chipNum, int cellNum) 6 { 7 // an input chip is valid for processing if: 8 // (((chipNum == i) || (chipNum == -1)) && chip.process) 7 9 8 // if we have not opened the file, skip it10 // If we have not opened the file, skip it 9 11 if (input->fits == NULL) { 10 return false;12 return false; 11 13 } 12 14 13 fprintf (stderr, "loading %d,%d for %s\n", nChip, nCell, input->filename);15 psTrace(__func__, 1, "Loading %d,%d for %s\n", chipNum, cellNum, input->filename); 14 16 15 // set input:valid flags according to process and nChip/nCell17 // set input:valid flags according to process and chipNum/cellNum 16 18 for (int i = 0; i < input->fpa->chips->n; i++) { 17 pmChip *pChip = process->fpa->chips->data[i]; 18 pmChip *iChip = input->fpa->chips->data[i];19 pmChip *chip = input->fpa->chips->data[i]; // Chip in input image 20 chip->process = (! chip->exists && ((chipNum == i) || (chipNum == -1))); 19 21 20 iChip->valid = pChip->valid; 21 iChip->valid &= (nChip == i) || (nChip == -1); 22 23 for (int j = 0; j < iChip->cells->n; j++) { 24 25 pmCell *pCell = pChip->cells->data[j]; 26 pmCell *iCell = iChip->cells->data[j]; 27 28 iCell->valid = pCell->valid; 29 iCell->valid &= iChip->valid; 30 iCell->valid &= (nCell == i) || (nCell == -1); 31 } 22 for (int j = 0; j < chip->cells->n; j++) { 23 pmCell *cell = chip->cells->data[j]; // Cell in input image 24 cell->process &= chip->process; 25 cell->process = (! cell->exists && ((cellNum == i) || (cellNum == -1))); 26 } 32 27 } 33 28 34 29 // Read in the input pixels 35 if (! pmFPARead(input->fpa, input->fits, input-> header, db)) {30 if (! pmFPARead(input->fpa, input->fits, input->phu, db)) { 36 31 psErrorStackPrint(stderr, "Unable to populate camera from input FITS file\n"); 37 32 exit(EXIT_FAILURE); 38 33 } 39 34 35 #if 0 36 // XXX PAP: Not sure this is required any more. 37 40 38 // reset input:valid flags to true 41 39 for (int i = 0; i < input->fpa->chips->n; i++) { 42 40 43 pmChip *iChip = input->fpa->chips->data[i];44 iChip->valid= true;45 for (int j = 0; j < iChip->cells->n; j++) {41 pmChip *chip = input->fpa->chips->data[i]; 42 chip->process = true; 43 for (int j = 0; j < chip->cells->n; j++) { 46 44 47 pmCell *iCell = iChip->cells->data[j];48 iCell->valid =true;49 }45 pmCell *cell = chip->cells->data[j]; 46 cell->process = true; 47 } 50 48 } 49 #endif 51 50 52 51 return true; -
trunk/ppImage/src/ppImageLoop.c
r5858 r5976 1 1 # include "ppImage.h" 2 2 3 bool ppImageLoop (ppData *data, ppOptions *options, ppConfig *config) {4 3 bool ppImageLoop(ppData *data, ppOptions *options, ppConfig *config) 4 { 5 5 ppDetrend detrend; 6 6 7 7 if (options->imageLoadDepth == PP_LOAD_FPA) { 8 ppImageLoadPixels (data->input, data->process, config->database, -1, -1); 9 ppImageLoadPixels (data->bias, data->process, config->database, -1, -1); 10 ppImageLoadPixels (data->dark, data->process, config->database, -1, -1); 11 ppImageLoadPixels (data->mask, data->process, config->database, -1, -1); 12 ppImageLoadPixels (data->flat, data->process, config->database, -1, -1); 8 psTrace(__func__, 1, "Loading pixels for FPA...\n"); 9 ppImageLoadPixels(data->input, config->database, -1, -1); 10 ppImageLoadPixels(data->bias, config->database, -1, -1); 11 ppImageLoadPixels(data->dark, config->database, -1, -1); 12 ppImageLoadPixels(data->mask, config->database, -1, -1); 13 ppImageLoadPixels(data->flat, config->database, -1, -1); 13 14 } 15 14 16 for (int i = 0; i < data->input->fpa->chips->n; i++) { 15 17 pmChip *inputChip = data->input->fpa->chips->data[i]; // Chip of interest in input image … … 19 21 pmChip *flatChip = data->flat->fpa->chips->data[i]; // Chip of interest in flat image 20 22 21 if (! inputChip->valid) { continue; } 23 printf("Chip %d: %x %x\n", i, inputChip->exists, inputChip->process); 24 if (! inputChip->process) { continue; } 22 25 23 if (options->imageLoadDepth == PP_LOAD_CHIP) { 24 ppImageLoadPixels (data->input, data->process, config->database, i, -1); 25 ppImageLoadPixels (data->bias, data->process, config->database, i, -1); 26 ppImageLoadPixels (data->dark, data->process, config->database, i, -1); 27 ppImageLoadPixels (data->mask, data->process, config->database, i, -1); 28 ppImageLoadPixels (data->flat, data->process, config->database, i, -1); 29 } 26 if (options->imageLoadDepth == PP_LOAD_CHIP) { 27 psTrace(__func__, 1, "Loading pixels for chip %d...\n", i); 28 ppImageLoadPixels(data->input, config->database, i, -1); 29 ppImageLoadPixels(data->bias, config->database, i, -1); 30 ppImageLoadPixels(data->dark, config->database, i, -1); 31 ppImageLoadPixels(data->mask, config->database, i, -1); 32 ppImageLoadPixels(data->flat, config->database, i, -1); 33 } 34 30 35 for (int j = 0; j < inputChip->cells->n; j++) { 31 36 detrend.input = inputChip->cells->data[j]; // Cell of interest in input image … … 35 40 detrend.flat = flatChip->cells->data[j]; // Cell of interest in flat image 36 41 37 if (! detrend.input->valid) { continue; } 42 printf ("\tCell %d: %x %x\n", j, detrend.input->exists, detrend.input->process); 43 if (! detrend.input->process) { continue; } 38 44 39 if (options->imageLoadDepth == PP_LOAD_CELL) { 40 ppImageLoadPixels (data->input, data->process, config->database, i, j); 41 ppImageLoadPixels (data->bias, data->process, config->database, i, j); 42 ppImageLoadPixels (data->dark, data->process, config->database, i, j); 43 ppImageLoadPixels (data->mask, data->process, config->database, i, j); 44 ppImageLoadPixels (data->flat, data->process, config->database, i, j); 45 } 46 ppDetrendCell (&detrend, options, config); 47 } 45 if (options->imageLoadDepth == PP_LOAD_CELL) { 46 psTrace(__func__, 1, "Loading pixels for chip %d, cell %d...\n", i, j); 47 ppImageLoadPixels(data->input, config->database, i, j); 48 ppImageLoadPixels(data->bias, config->database, i, j); 49 ppImageLoadPixels(data->dark, config->database, i, j); 50 ppImageLoadPixels(data->mask, config->database, i, j); 51 ppImageLoadPixels(data->flat, config->database, i, j); 52 } 53 54 ppDetrendCell (&detrend, options, config); 55 } 48 56 } 49 57 return true; -
trunk/ppImage/src/ppImageOptions.c
r5858 r5976 1 # include "ppImage.h"1 #include "ppImage.h" 2 2 3 3 // XXX EAM : this needs signficant work to choose the detrend images based on the detrend database 4 4 5 bool ppImageOptions (ppData *data, ppOptions *options, ppConfig *config) { 5 bool ppImageOptions(ppData *data, ppOptions *options, ppConfig *config) 6 { 6 7 7 bool status; 8 9 // default initial values 10 options->doMask = false; // Mask bad pixels 11 options->doNonLin = false; // Non-linearity correction 12 options->doBias = false; // Bias subtraction 13 options->doDark = false; // Dark subtraction 14 options->doOverscan = false; // Overscan subtraction 15 options->doFlat = false; // Flat-field normalisation 16 options->doFringe = false; // Fringe subtraction 17 options->doSource = false; // Source identification and photometry 18 options->doAstrom = false; // Astrometry 19 options->overscanBins = 1; // Number of pixels per bin for overscan 8 // Flags for various activities 9 options->doMask = false; // Mask bad pixels 10 options->doNonLin = false; // Non-linearity correction 11 options->doBias = false; // Bias subtraction 12 options->doDark = false; // Dark subtraction 13 options->doOverscan = false; // Overscan subtraction 14 options->doFlat = false; // Flat-field normalisation 15 options->doFringe = false; // Fringe subtraction 16 options->doSource = false; // Source identification and photometry 17 options->doAstrom = false; // Astrometry 18 // Overscan options 19 options->overscanBins = 1; // Number of pixels per bin for overscan 20 20 options->overscanStats = NULL; // Statistics for overscan 21 options->overscanFit = NULL; // Overscan fit (polynomial or spline)21 options->overscanFit = NULL; // Overscan fit (polynomial or spline) 22 22 options->overscanFitType = PM_FIT_NONE; // Fit type for overscan 23 23 options->overscanMode = PM_OVERSCAN_NONE; // Axis for overscan 24 // Non-linearity options 25 options->nonLinearType = 0; // Type of non-linearity data (vector, string or metadata) 26 options->nonLinearData = NULL; // The non-linearity data 27 options->nonLinearSource = NULL; // If the non-linearity data is a menu, this provides the key 28 // Various others 29 options->imageLoadDepth = PP_LOAD_NONE; // No load depth specified yet 24 30 25 options->doNonLin = false; 26 options->nonLinearType = false; 27 options->nonLinearData = NULL; 28 options->nonLinearSource = NULL; 29 30 options->imageLoadDepth = PP_LOAD_NONE; 31 char *depth = psMetadataLookupPtr(NULL, config->recipe, "LOAD.DEPTH"); 32 if (depth == NULL) { 33 psAbort ("phase2", "load depth not specified"); 31 bool mdStatus = false; // Result of MD lookup 32 const char *depth = psMetadataLookupStr(&mdStatus, config->recipe, "LOAD.DEPTH"); 33 if (! mdStatus || ! depth || strlen(depth) == 0) { 34 psLogMsg("ppImage", PS_LOG_ERROR, "LOAD.DEPTH not specified in recipe."); 35 exit(EXIT_FAILURE); 34 36 } 35 37 if (!strcasecmp(depth, "FPA")) { 36 options->imageLoadDepth = PP_LOAD_FPA; 37 } 38 if (!strcasecmp(depth, "CHIP")) { 39 options->imageLoadDepth = PP_LOAD_CHIP; 40 } 41 if (!strcasecmp(depth, "CELL")) { 42 options->imageLoadDepth = PP_LOAD_CELL; 43 } 44 if (options->imageLoadDepth == PP_LOAD_NONE) { 45 psAbort ("phase2", "load depth not specified"); 38 options->imageLoadDepth = PP_LOAD_FPA; 39 } else if (!strcasecmp(depth, "CHIP")) { 40 options->imageLoadDepth = PP_LOAD_CHIP; 41 } else if (!strcasecmp(depth, "CELL")) { 42 options->imageLoadDepth = PP_LOAD_CELL; 43 } else { 44 psLogMsg(__func__, PS_LOG_ERROR, "LOAD.DEPTH in recipe is not FPA, CHIP or CELL."); 45 exit(EXIT_FAILURE); 46 46 } 47 47 48 // mask -recipe options48 // Mask recipe options 49 49 if (psMetadataLookupBool(NULL, config->recipe, "MASK")) { 50 data->mask->filename = psMetadataLookupStr(NULL, config->arguments, "-mask");51 if ( strlen(data->mask->filename) > 0) {50 data->mask->filename = psMetadataLookupStr(NULL, config->arguments, "-mask"); 51 if (data->mask->filename && strlen(data->mask->filename) > 0) { 52 52 options->doMask = true; 53 53 } else { 54 psLogMsg( "phase2", PS_LOG_WARN, "Masking is desired, but no mask was supplied"55 " --- no masking will be performed.\n");54 psLogMsg(__func__, PS_LOG_WARN, "Masking is desired, but no mask was supplied" 55 " --- no masking will be performed.\n"); 56 56 } 57 57 } 58 58 59 // non-linear -recipe options59 // Non-linearity recipe options 60 60 if (psMetadataLookupBool(NULL, config->recipe, "NONLIN")) { 61 psMetadataItem *dataItem = psMetadataLookup(config->recipe, "NONLIN.DATA"); 62 if (! dataItem) { 63 psAbort("phase2", "Non-linearity correction desired, but unable to " 64 "find NONLIN.DATA in recipe"); 65 } 61 psMetadataItem *dataItem = psMetadataLookup(config->recipe, "NONLIN.DATA"); 62 if (! dataItem) { 63 psLogMsg(__func__, PS_LOG_ERROR, "Non-linearity correction desired, but unable to " 64 "find NONLIN.DATA in recipe."); 65 exit(EXIT_FAILURE); 66 } 66 67 67 68 options->doNonLin = true; 68 options->nonLinearType = dataItem->type;69 options->nonLinearData = dataItem;69 options->nonLinearType = dataItem->type; 70 options->nonLinearData = dataItem; 70 71 71 switch (dataItem->type) { 72 case PS_DATA_VECTOR: 73 case PS_DATA_STRING: 74 break; 72 switch (dataItem->type) { 73 // No immediate action required 74 case PS_DATA_VECTOR: 75 case PS_DATA_STRING: 76 break; 75 77 76 case PS_DATA_METADATA: 77 // This is a menu 78 options->nonLinearSource = psMetadataLookupStr(&status, config->recipe, "NONLIN.SOURCE"); 79 if (! status || ! options->nonLinearSource) { 80 psAbort("phase2", "Non-linearity correction desired, but unable to " 81 "find NONLIN.SOURCE in recipe"); 82 } 83 break; 84 85 default: 86 psAbort("phase2", "Non-linearity correction desired, but " 87 "NONLIN.DATA is of invalid type."); 88 } 89 78 // This is a menu; we need the key 79 case PS_DATA_METADATA: 80 { 81 bool status; 82 options->nonLinearSource = psMetadataLookupStr(&status, config->recipe, "NONLIN.SOURCE"); 83 if (! status || ! options->nonLinearSource) { 84 psLogMsg(__func__, PS_LOG_ERROR, "Non-linearity correction desired, but unable to " 85 "find NONLIN.SOURCE in recipe"); 86 exit(EXIT_FAILURE); 87 } 88 } 89 break; 90 default: 91 psLogMsg(__func__, PS_LOG_ERROR, "Non-linearity correction desired, but " 92 "NONLIN.DATA is of invalid type."); 93 exit(EXIT_FAILURE); 94 } 90 95 } 91 96 92 // bias -recipe options97 // Bias recipe options 93 98 if (psMetadataLookupBool(NULL, config->recipe, "BIAS")) { 94 data->bias->filename = psMetadataLookupStr(NULL, config->arguments, "-bias");95 if ( strlen(data->bias->filename) > 0) {99 data->bias->filename = psMetadataLookupStr(NULL, config->arguments, "-bias"); 100 if (data->bias->filename && strlen(data->bias->filename) > 0) { 96 101 options->doBias = true; 97 102 } else { 98 psLogMsg( "phase2", PS_LOG_WARN, "Bias subtraction is desired, but no bias was supplied --- "103 psLogMsg(__func__, PS_LOG_WARN, "Bias subtraction is desired, but no bias was supplied --- " 99 104 "no bias subtraction will be performed.\n"); 100 105 } 101 106 } 102 107 103 // dark -recipe options108 // Dark recipe options 104 109 if (psMetadataLookupBool(NULL, config->recipe, "DARK")) { 105 data->dark->filename = psMetadataLookupStr(NULL, config->arguments, "-dark");106 if ( strlen(data->dark->filename) > 0) {110 data->dark->filename = psMetadataLookupStr(NULL, config->arguments, "-dark"); 111 if (data->dark->filename && strlen(data->dark->filename) > 0) { 107 112 options->doDark = true; 108 113 } else { 109 psLogMsg( "phase2", PS_LOG_WARN, "Dark subtraction is desired, but no dark was supplied --- "114 psLogMsg(__func__, PS_LOG_WARN, "Dark subtraction is desired, but no dark was supplied --- " 110 115 "no dark subtraction will be performed.\n"); 111 116 } 112 117 } 113 118 114 // overscan - recipe options 119 // XXX PAP: The overscan stuff needs to be updated following the reworked API 120 121 // Overscan recipe options 115 122 // XXX EAM : we should abort on invalid options. default options? 116 123 if (psMetadataLookupBool(NULL, config->recipe, "OVERSCAN")) { 117 // XXX EAM : does 'overscanMode = NONE' mean doOverscan = false?124 // XXX EAM : does 'overscanMode = NONE' mean doOverscan = false? 118 125 options->doOverscan = true; 119 126 psString mode = psMetadataLookupStr(NULL, config->recipe, "OVERSCAN.MODE"); … … 123 130 options->overscanMode = PM_OVERSCAN_ALL; 124 131 } else if (strcasecmp(mode, "NONE")) { 125 psLogMsg( "phase2", PS_LOG_WARN, "OVERSCAN.MODE (%s) is not one of NONE, INDIVIDUAL, or ALL:"132 psLogMsg(__func__, PS_LOG_WARN, "OVERSCAN.MODE (%s) is not one of NONE, INDIVIDUAL, or ALL:" 126 133 " assuming NONE.\n", mode); 127 134 } … … 135 142 options->overscanFitType = PM_FIT_SPLINE; 136 143 // int order = psMetadataLookupS32(NULL, config->recipe, "OVERSCAN.ORDER"); // Order of polynomial fit 137 // XXX : not in psLib yet : options->overscanFit = psSpline1DAlloc();144 // XXX : not in psLib yet : options->overscanFit = psSpline1DAlloc(); 138 145 } else if (strcasecmp(fit, "NONE")) { 139 psLogMsg( "phase2", PS_LOG_WARN, "OVERSCAN.FIT (%s) is not one of NONE, POLYNOMIAL, or SPLINE:"146 psLogMsg(__func__, PS_LOG_WARN, "OVERSCAN.FIT (%s) is not one of NONE, POLYNOMIAL, or SPLINE:" 140 147 " assuming NONE.\n", fit); 141 148 } … … 158 165 // flat-field - recipe options 159 166 if (psMetadataLookupBool(NULL, config->recipe, "FLAT")) { 160 data->flat->filename = psMetadataLookupStr(NULL, config->arguments, "-flat");167 data->flat->filename = psMetadataLookupStr(NULL, config->arguments, "-flat"); 161 168 if (strlen(data->flat->filename) > 0) { 162 169 options->doFlat = true; 163 170 } else { 164 psLogMsg( "phase2", PS_LOG_WARN, "Flat-fielding is desired, but no flat was supplied --- "171 psLogMsg(__func__, PS_LOG_WARN, "Flat-fielding is desired, but no flat was supplied --- " 165 172 "no flat-fielding will be performed.\n"); 166 173 } -
trunk/ppImage/src/ppImageParseCamera.c
r5860 r5976 1 # include "ppImage.h"1 #include "ppImage.h" 2 2 3 static void ppFPA_Free (ppFPA *fpa) { 4 return; 5 } 3 bool ppImageParseCamera(ppData *data, ppConfig *config) 4 { 5 // Initialise the containers where the files will go 6 data->input = ppFileAlloc(); 7 data->mask = ppFileAlloc(); 8 data->bias = ppFileAlloc(); 9 data->dark = ppFileAlloc(); 10 data->flat = ppFileAlloc(); 11 data->fringe = ppFileAlloc(); 12 #if 0 13 data->process = ppFileAlloc(); 14 #endif 6 15 7 ppFPA *ppFPA_Alloc (void) { 8 9 ppFPA *fpa = psAlloc (sizeof(ppFPA)); 10 psMemSetDeallocator(fpa, (psFreeFunc) ppFPA_Free); 11 12 fpa->filename = NULL; 13 fpa->fpa = NULL; 14 fpa->fits = NULL; 15 fpa->header = NULL; 16 17 return fpa; 18 } 19 20 bool ppImageParseCamera (ppData *data, ppConfig *config) { 21 22 bool status; 23 24 data->input = ppFPA_Alloc (); 25 data->mask = ppFPA_Alloc (); 26 data->bias = ppFPA_Alloc (); 27 data->dark = ppFPA_Alloc (); 28 data->flat = ppFPA_Alloc (); 29 data->fringe = ppFPA_Alloc (); 30 data->process = ppFPA_Alloc (); 31 32 data->input->filename = psMetadataLookupPtr (NULL, config->arguments, "-input"); 16 data->input->filename = psMemIncrRefCounter(psMetadataLookupStr(NULL, config->arguments, "-input")); 33 17 34 18 // Open the input image 35 psLogMsg("p hase2", PS_LOG_INFO, "Opening input image: %s\n", data->input->filename);19 psLogMsg("ppImage", PS_LOG_INFO, "Opening input image: %s\n", data->input->filename); 36 20 data->input->fits = psFitsOpen(data->input->filename, "r"); // File handle for FITS file 37 21 if (! data->input->fits) { 22 // There's no point in continuing if we can't open the input 38 23 psErrorStackPrint(stderr, "Can't open input image: %s\n", data->input->filename); 39 24 exit(EXIT_FAILURE); 40 25 } 41 data->input-> header= psFitsReadHeader(NULL, data->input->fits); // FITS header26 data->input->phu = psFitsReadHeader(NULL, data->input->fits); // FITS header 42 27 43 28 // Get camera configuration from header if not already defined 44 29 if (! config->camera) { 45 config->camera = pmConfigCameraFromHeader(config->site, data->input-> header);30 config->camera = pmConfigCameraFromHeader(config->site, data->input->phu); 46 31 if (! config->camera) { 32 // There's no point in continuing if we can't recognise what we've got 47 33 psErrorStackPrint(stderr, "Can't find camera configuration!\n"); 48 34 exit(EXIT_FAILURE); 49 35 } 50 } else if (! pmConfigValidateCamera(config->camera, data->input->header)) { 51 psError(PS_ERR_IO, true, "%s does not seem to be from the camera.\n", data->input->filename); 36 } else if (! pmConfigValidateCamera(config->camera, data->input->phu)) { 37 // There's no point in continuing if what we've got doesn't match what we've been told 38 psError(PS_ERR_IO, true, "%s does not seem to be from the specified camera.\n", 39 data->input->filename); 52 40 exit(EXIT_FAILURE); 53 41 } 54 42 55 // determine the correct recipe to use43 // Determine the correct recipe to use 56 44 if (! config->recipe && !(config->recipe = pmConfigRecipeFromCamera(config->camera, RECIPE))) { 45 // There's no point in continuing if we can't work out what recipe to use 57 46 psErrorStackPrint(stderr, "Can't find recipe configuration!\n"); 58 47 exit(EXIT_FAILURE); 59 48 } 60 49 61 // Construct camera in preparation for reading50 // Construct cameras in preparation for reading 62 51 data->input->fpa = pmFPAConstruct(config->camera); 63 52 data->mask->fpa = pmFPAConstruct(config->camera); … … 66 55 data->flat->fpa = pmFPAConstruct(config->camera); 67 56 data->fringe->fpa = pmFPAConstruct(config->camera); 57 #if 0 68 58 data->process->fpa = pmFPAConstruct(config->camera); 59 #endif 69 60 70 61 // XXX EAM : extend this to allow an array of selected chips by name 71 62 // Chip selection: if we are using a single chip, select it for each FPA 72 // data->process acts as a process mask for the full FPA 73 int chipNum = psMetadataLookupS32(&status, config->arguments, "-chip"); // Chip number to work on 63 int chipNum = psMetadataLookupS32(NULL, config->arguments, "-chip"); // Chip number to work on 74 64 if (chipNum >= 0) { 75 if (! pmFPASelectChip(data-> process->fpa, chipNum)) {65 if (! pmFPASelectChip(data->input->fpa, chipNum)) { 76 66 psErrorStackPrint(stderr, "Chip number %d doesn't exist in camera.\n", chipNum); 77 67 exit(EXIT_FAILURE); 78 68 } 79 psLogMsg("p hase2", PS_LOG_INFO, "Operating only on chip %d\n", chipNum);69 psLogMsg("ppImage", PS_LOG_INFO, "Operating only on chip %d\n", chipNum); 80 70 } 81 71 return true; … … 84 74 // XXX EAM : I dropped the pre-open of the output files; replace with a stats test of output permissions 85 75 86 // XXX : for split data (data spread across multiple files), this step is only operating on a component 76 // XXX : for split data (data spread across multiple files), this step is only operating on a component 87 77 // of the FPA. the other components should be set to 'invalid' in this case? -
trunk/ppImage/src/ppImageParseDetrend.c
r5858 r5976 8 8 // XXX : add fringe frame 9 9 10 bool ppF PAOpen (ppFPA *fpa, psMetadata *camera, char *name, bool doThis) {10 bool ppFileOpen(ppFile *file, psMetadata *camera, char *name, bool doThis) { 11 11 12 12 if (!doThis) { 13 return false;13 return false; 14 14 } 15 15 16 psLogMsg("phase2", PS_LOG_INFO, "Opening %s image: %s\n", name, fpa->filename); 17 fpa->fits = psFitsOpen(fpa->filename, "r"); // File handle 18 fpa->header = psFitsReadHeader(NULL, fpa->fits); // primary header 19 if (! pmConfigValidateCamera(camera, fpa->header)) { 20 psError(PS_ERR_IO, true, "%s (%s) does not seem to be from the correct camera.\n", name, fpa->filename); 21 exit(EXIT_FAILURE); 16 psLogMsg("phase2", PS_LOG_INFO, "Opening %s image: %s\n", name, file->filename); 17 file->fits = psFitsOpen(file->filename, "r"); // File handle 18 file->phu = psFitsReadHeader(NULL, file->fits); // primary header 19 if (! pmConfigValidateCamera(camera, file->phu)) { 20 psError(PS_ERR_IO, true, "%s (%s) does not seem to be from the correct camera.\n", name, 21 file->filename); 22 exit(EXIT_FAILURE); 22 23 } 23 24 return true; … … 26 27 bool ppImageParseDetrend (ppData *data, ppOptions *options, ppConfig *config) { 27 28 28 ppF PAOpen(data->mask, config->camera, "mask", options->doMask);29 ppF PAOpen(data->bias, config->camera, "bias", options->doBias);30 ppF PAOpen(data->dark, config->camera, "dark", options->doDark);31 ppF PAOpen(data->flat, config->camera, "flat", options->doFlat);29 ppFileOpen(data->mask, config->camera, "mask", options->doMask); 30 ppFileOpen(data->bias, config->camera, "bias", options->doBias); 31 ppFileOpen(data->dark, config->camera, "dark", options->doDark); 32 ppFileOpen(data->flat, config->camera, "flat", options->doFlat); 32 33 return true; 33 34 }
Note:
See TracChangeset
for help on using the changeset viewer.
