Changeset 36580
- Timestamp:
- Mar 7, 2014, 6:08:39 PM (12 years ago)
- Location:
- trunk/ppBackground/src
- Files:
-
- 8 edited
-
Makefile.am (modified) (3 diffs)
-
ppBackgroundStack.c (modified) (2 diffs)
-
ppBackgroundStack.h (modified) (3 diffs)
-
ppBackgroundStackArguments.c (modified) (2 diffs)
-
ppBackgroundStackCamera.c (modified) (9 diffs)
-
ppBackgroundStackData.c (modified) (2 diffs)
-
ppBackgroundStackLoop.c (modified) (2 diffs)
-
ppBackgroundStackMath.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppBackground/src/Makefile.am
r28281 r36580 1 bin_PROGRAMS = ppBackground 1 bin_PROGRAMS = ppBackground ppBackgroundStack 2 2 3 3 if HAVE_SVNVERSION … … 28 28 ppBackground_LDFLAGS = $(PSLIB_LIBS) $(PSMODULE_LIBS) $(PPSTATS_LIBS) $(PSPHOT_LIBS) $(PPBACKGROUND_LIBS) 29 29 30 ppBackgroundStack_CPPFLAGS = $(ppBackground_CPPFLAGS) 31 ppBackgroundStack_LDFLAGS = $(ppBackground_LDFLAGS) 32 30 33 ppBackground_SOURCES = \ 31 34 ppBackground.c \ … … 38 41 ppBackgroundErrorCodes.c \ 39 42 ppBackgroundExit.c 43 44 ppBackgroundStack_SOURCES = \ 45 ppBackgroundStack.c \ 46 ppBackgroundStackArguments.c \ 47 ppBackgroundStackCamera.c \ 48 ppBackgroundStackData.c \ 49 ppBackgroundStackLoop.c \ 50 ppBackgroundStackMath.c \ 51 ppBackgroundVersion.c \ 52 ppBackgroundErrorCodes.c \ 53 ppBackgroundExit.c 54 40 55 41 56 noinst_HEADERS = \ -
trunk/ppBackground/src/ppBackgroundStack.c
r36579 r36580 18 18 ppBackgroundErrorRegister(); 19 19 20 ppBackground Data *data = ppBackgroundDataInit(&argc, argv);20 ppBackgroundStackData *data = ppBackgroundStackDataInit(&argc, argv); 21 21 if (!data) { 22 22 goto DIE; 23 23 } 24 24 25 if (!ppBackground Arguments(data, argc, argv)) {25 if (!ppBackgroundStackArguments(data, argc, argv)) { 26 26 goto DIE; 27 27 } 28 28 29 if (!ppBackground Camera(data)) {29 if (!ppBackgroundStackCamera(data)) { 30 30 goto DIE; 31 31 } 32 32 33 if (!ppBackground Loop(data)) {33 if (!ppBackgroundStackLoop(data)) { 34 34 goto DIE; 35 35 } … … 39 39 psExit exitValue = ppBackgroundExitCode(PS_EXIT_SUCCESS); // Exit code 40 40 41 if (data && data->stats && data->statsFile) { 42 psString stats = psMetadataConfigFormat(data->stats); // Statistics to output 43 if (!stats || strlen(stats) == 0) { 44 psError(PPBACKGROUND_ERR_IO, false, "Unable to format statistics file"); 45 } else if (fprintf(data->statsFile, "%s", stats) != strlen(stats)) { 46 psError(PPBACKGROUND_ERR_IO, true, "Unable to write statistics file"); 47 } 48 psFree(stats); 49 if (fclose(data->statsFile) == EOF) { 50 psError(PPBACKGROUND_ERR_IO, true, "Unable to close statistics file"); 51 } 52 data->statsFile = NULL; 53 exitValue = ppBackgroundExitCode(exitValue); 54 } 41 /* if (data && data->stats && data->statsFile) { */ 42 /* psString stats = psMetadataConfigFormat(data->stats); // Statistics to output */ 43 /* if (!stats || strlen(stats) == 0) { */ 44 /* psError(PPBACKGROUND_ERR_IO, false, "Unable to format statistics file"); */ 45 /* } else if (fprintf(data->statsFile, "%s", stats) != strlen(stats)) { */ 46 /* psError(PPBACKGROUND_ERR_IO, true, "Unable to write statistics file"); */ 47 /* } */ 48 /* psFree(stats); */ 49 /* if (fclose(data->statsFile) == EOF) { */ 50 /* psError(PPBACKGROUND_ERR_IO, true, "Unable to close statistics file"); */ 51 /* } */ 52 /* data->statsFile = NULL; */ 53 /* exitValue = ppBackgroundExitCode(exitValue); */ 54 /* } */ 55 55 56 56 if (data) { -
trunk/ppBackground/src/ppBackgroundStack.h
r36579 r36580 7 7 #include "ppBackgroundErrorCodes.h" 8 8 9 #define PPBACKGROUND_RECIPE "PPBACKGROUND " // Recipe name9 #define PPBACKGROUND_RECIPE "PPBACKGROUND_STACK" // Recipe name 10 10 11 11 // Data for processing … … 30 30 31 31 /// Initialise data for processing 32 ppBackground Data *ppBackgroundDataInit(int *argc, char *argv[] // Command-line arguments32 ppBackgroundStackData *ppBackgroundStackDataInit(int *argc, char *argv[] // Command-line arguments 33 33 ); 34 34 … … 39 39 40 40 /// Parse camera configurations 41 bool ppBackgroundStackCamera(ppBackground Data *data // Data for processing41 bool ppBackgroundStackCamera(ppBackgroundStackData *data // Data for processing 42 42 ); 43 43 44 44 /// Loop over input data, processing 45 bool ppBackgroundStackLoop(ppBackground Data *data // Data for processing45 bool ppBackgroundStackLoop(ppBackgroundStackData *data // Data for processing 46 46 ); 47 47 48 /// Determine the binning from the recipe if available. 49 psImageBinning *ppBackgroundStackBinningByRecipe(const psImage *image, // Image for which to generate a bg model 50 const pmConfig *config, // Configuration 51 psString recipe_name, 52 psString Xbin_name, 53 psString Ybin_name 54 ); 48 bool ppBackgroundStackModelFitOTASolution(ppBackgroundStackData *data); 49 bool ppBackgroundStackDataModelFit(ppBackgroundStackData *data); 50 bool ppBackgroundStackCalibApply(ppBackgroundStackData *data); 51 bool ppBackgroundStackModelFit(ppBackgroundStackData *data); 55 52 56 57 /// Restore the background to an image58 bool ppBackgroundStackRestore(59 pmChip *chip, // Chip to correct60 const pmChip *background, // Chip with background model61 const pmChip *pattern, // Chip with pattern62 const pmFPAview *view, // View to data63 pmConfig *config, // Configuration64 psImageMaskType maskBad // value to use for bad pixels65 );66 53 67 54 /// Determine exit code -
trunk/ppBackground/src/ppBackgroundStackArguments.c
r36579 r36580 48 48 psMetadataAddStr(arguments, PS_LIST_TAIL, "-image", 0, "Filename of image (required)", NULL); 49 49 psMetadataAddStr(arguments, PS_LIST_TAIL, "-mask", 0, "Filename of mask", NULL); 50 psMetadataAddBool(arguments, PS_LIST_TAIL, "-fitOTAs", 0, "" );51 psMetadataAddStr(arguments, PS_LIST_TAIL, "-OTApath", 0, "" );50 psMetadataAddBool(arguments, PS_LIST_TAIL, "-fitOTAs", 0, "", false); 51 psMetadataAddStr(arguments, PS_LIST_TAIL, "-OTApath", 0, "", NULL); 52 52 53 53 if (argc == 1 || !psArgumentParse(arguments, &argc, argv) || argc != 2) { … … 56 56 57 57 unsigned int numBad = 0; // Number of bad lines 58 data->contents = psMetadataConfigRead(NULL, &numBad,psMetadataLookupStr(NULL, arguments, "-input") );59 if (! inputs|| numBad > 0) {58 data->contents = psMetadataConfigRead(NULL, &numBad,psMetadataLookupStr(NULL, arguments, "-input"),false); 59 if (!(data->contents) || numBad > 0) { 60 60 psError(PPBACKGROUND_ERR_CONFIG, false, "Unable to cleanly read MDC file with inputs."); 61 61 return(false); -
trunk/ppBackground/src/ppBackgroundStackCamera.c
r36579 r36580 31 31 { 32 32 bool status; // Status of file definition 33 33 pmConfig *config = data->config; // Because I'm reusing code. 34 int u,v; 35 // FIX Figure out what stacks we have to deal with. 36 psString stackName = data->stacks->data[0]; 37 fileArguments("IMAGE", stackName, "Input image", data->config); 38 pmFPAfile *stack = pmFPAfileDefineFromArgs(&status, data->config, "PPBACKGROUND.STACK", 39 "IMAGE"); 40 if (!status || !stack) { 41 psError(psErrorCodeLast(), false, "Failed to build file from PPBACKGROUND.STACK"); 42 return false; 43 } 44 45 // Read over the input background models. 34 46 psMetadataIterator *iter = psMetadataIteratorAlloc(data->contents, PS_LIST_HEAD, NULL); // Iterator 35 47 psMetadataItem *item; // Item from iteration 36 int i = 0;48 // int i = 0; 37 49 while ((item = psMetadataGetAndIncrement(iter))) { 38 50 if (item->type != PS_DATA_METADATA) { 39 psError(PPBACKGROUND_ERR_ARGUMENTS, true 51 psError(PPBACKGROUND_ERR_ARGUMENTS, true, 40 52 "Component %s of the input metadata is not of type METADATA", item->name); 41 53 psFree(iter); … … 47 59 psString smfFileName = psMetadataLookupStr(NULL, input, "astrom"); 48 60 49 // FIX Figure out how to calculate the smf name 50 // psString cam_file = pmFPAfileNameFromRule("PSASTRO.OUTPUT"); 51 // pmFPAfile *smfFile = pmFPAfileBindFromArgs(&status, NULL, config); 52 // pmFPAfile *smfFile = pmFPAfileDefineInput(config, 61 // Read the smf file from this item 53 62 fileArguments("astrom",smfFileName,"",config); 54 63 pmFPAfile *smfFile = pmFPAfileDefineFromArgs(&status, config, "PSWARP.ASTROM","astrom"); 55 64 56 65 // Read the SMF data 57 58 66 pmFPAview *view = pmFPAviewAlloc(0); // Pointer into FPA hierarchy 59 67 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { … … 95 103 } 96 104 // read WCS data from the corresponding header 97 pmHDU *hdu = pmFPAviewThisHDU (view, astromFile->fpa);105 pmHDU *hdu = pmFPAviewThisHDU (view, smfFile->fpa); 98 106 if (bilevelAstrometry) { 99 107 if (!pmAstromReadBilevelChip (chip, hdu->header)) { … … 108 116 // we use a default FPA pixel scale of 1.0 109 117 psWarning("Reading WCS astrometry for chip %s.", chipName); 110 if (!pmAstromReadWCS( astromFile->fpa, chip, hdu->header, 1.0)) {118 if (!pmAstromReadWCS(smfFile->fpa, chip, hdu->header, 1.0)) { 111 119 psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for input FPA."); 112 120 psFree(view); … … 116 124 117 125 // FIX Load model data for this chip 118 psString modelFileName = psMetadataLookupStr(NULL, input ->models, chipName);126 psString modelFileName = psMetadataLookupStr(NULL, input, chipName); 119 127 psFits *modelFits = psFitsOpen(modelFileName,"r"); 120 psImage *image = psFitsReadImage(modelFits,NULL,0); 128 int nC, nR; 129 psElemType *type; 130 psRegion region; 131 psFitsImageSize(&nC,&nR,type,modelFits,region); 132 psImage *image = psFitsReadImage(modelFits,region,0); 121 133 psMetadata *header = psFitsReadHeader(NULL,modelFits); 122 134 123 135 // Allocate the data structures for this chip 124 psImage *raim = psImageAlloc(image-> cols,image->rows,PS_TYPE_F32);125 psImage *decim = psImageAlloc(image-> cols,image->rows,PS_TYPE_F32);126 psImage *model = psImageAlloc(image-> cols,image->rows,PS_TYPE_F32);136 psImage *raim = psImageAlloc(image->numCols,image->numRows,PS_TYPE_F32); 137 psImage *decim = psImageAlloc(image->numCols,image->numRows,PS_TYPE_F32); 138 psImage *model = psImageAlloc(image->numCols,image->numRows,PS_TYPE_F32); 127 139 128 140 // Read header and construct original positions … … 142 154 psSphere *sky = psSphereAlloc(); // Sky coordinates 143 155 144 for (v = 0; v < image->n rows; v++) {156 for (v = 0; v < image->numRows; v++) { 145 157 pix->y = (v - yoffset) * ybin; 146 for (u = 0; u < image->n cols; u++) {158 for (u = 0; u < image->numCols; u++) { 147 159 pix->x = (u - xoffset) * xbin; 148 160 psPlaneTransformApply(fp, chip->toFPA, pix); 149 161 psPlaneTransformApply(tp, smfFile->fpa->toTPA, fp); 150 psDeproject(sky, tp, astromFile->fpa->toSky); 151 152 // FIX project sky to stack projection cell grid. 153 if (!data->radians) { 154 sky->r *= 180.0 / M_PI; 155 sky->d *= 180.0 / M_PI; 156 } 157 raim->data.F32[v][u] = sky->r; 158 decim->data.F32[v][u] = sky->d; 162 psDeproject(sky, tp, smfFile->fpa->toSky); 163 164 psProject(tp,sky,stack->fpa->toSky); 165 166 raim->data.F32[v][u] = tp->x; 167 decim->data.F32[v][u] = tp->y; 159 168 model->data.F32[v][u] = 0.0; 160 169 161 170 // Check the bounds so we'll know how large of an area to model in the map 162 if ( sky->r < data->ra_min) { data->ra_min = sky->r; }163 else if ( sky->r > data->ra_max) { data->ra_max = sky->r; }164 if ( sky->d < data->dec_min) { data->dec_min = sky->d; }165 else if ( sky->d > data->dec_max) { data->dec_max = sky->d; }171 if (tp->x < data->ra_min) { data->ra_min = tp->x; } 172 else if (tp->x > data->ra_max) { data->ra_max = tp->x; } 173 if (tp->y < data->dec_min) { data->dec_min = tp->y; } 174 else if (tp->y > data->dec_max) { data->dec_max = tp->y; } 166 175 } 167 176 } … … 187 196 // FIX this should try to find the imagefile. 188 197 if (data->fit_OTAS) { // We are fitting OTAs, so allocate a new image 189 psImage *solution = psImageAlloc(image-> cols,image->rows,PS_TYPE_F32);198 psImage *solution = psImageAlloc(image->numCols,image->numRows,PS_TYPE_F32); 190 199 psMetadataAddPtr(data->OTA_solutions,PS_LIST_TAIL, chipName, PS_DATA_UNKNOWN | PS_META_REPLACE, "OTA solution element", solution); 191 200 } … … 194 203 psStringAppend(&solutionFileName, ".%s.fits",chipName); 195 204 psFits *solutionFits = psFitsOpen(solutionFileName,"r"); 196 psImage *solution = psFitsReadImage(solutionFits,NULL,0); 205 psImage *solution = psFitsReadImage(solutionFits,region,0); 206 psMetadataAddPtr(data->OTA_solutions,PS_LIST_TAIL, chipName, PS_DATA_UNKNOWN | PS_META_REPLACE, "OTA solution element", solution); 197 207 } 198 208 } … … 215 225 } 216 226 227 // Allocate the modelMap for the region we're covering. 228 229 psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); 230 psImageBinning *binning = psImageBinningAlloc(); 231 binning->nXruff = 100; // Number of samples 232 binning->nYruff = 100; 233 binning->nXfine = ceil(data->ra_max - data->ra_min) + 1; // This is the range we're looking at 234 binning->nYfine = ceil(data->dec_max - data->dec_min) + 1; 235 236 data->modelMap = psImageMapNoImageAlloc( binning,stats); 237 217 238 return true; 218 239 } -
trunk/ppBackground/src/ppBackgroundStackData.c
r36579 r36580 36 36 data->smfs = psArrayAlloc(0); 37 37 38 data->OTA_solutions = psMetadataAlloc( 0);39 data->fit OTAs= false;38 data->OTA_solutions = psMetadataAlloc(); 39 data->fit_OTAS = false; 40 40 data->OTApath = NULL; 41 41 … … 49 49 data->outRoot = NULL; 50 50 data->config = NULL; 51 52 data->53 51 54 52 return data; -
trunk/ppBackground/src/ppBackgroundStackLoop.c
r36579 r36580 13 13 ) 14 14 { 15 pmConfig *config = data->config; // Configuration data16 15 // pmConfig *config = data->config; // Configuration data 16 int i; 17 17 // 18 18 // Solve the data into a consistent model. 19 19 { // This block does the initialization 20 20 // If we didn't load the OTA solution from an external source, we need to build one. 21 if (data->fit OTAs) {21 if (data->fit_OTAS) { 22 22 if (!ppBackgroundStackModelFitOTASolution(data)) { 23 23 // Currently can't fail. … … 67 67 // Calculate model for each pixel of output 68 68 // Close output image 69 69 } 70 70 71 71 return(true); -
trunk/ppBackground/src/ppBackgroundStackMath.c
r36579 r36580 27 27 bool ppBackgroundStackModelFitOTASolution(ppBackgroundStackData *data) { 28 28 long i; 29 30 pmFPAview *view = pmFPAviewAllo w(0);29 int u,v; 30 pmFPAview *view = pmFPAviewAlloc(0); 31 31 psMetadataIterator *iter = psMetadataIteratorAlloc(data->OTA_solutions, PS_LIST_HEAD, NULL); // Iterate over all chips. 32 32 psMetadataItem *item; … … 38 38 continue; 39 39 } 40 psString *workingChip = item->name;40 psString workingChip = item->name; 41 41 psImage *solution = item->data.V; 42 42 43 for (v = 0; v < solution->n rows; v++) {44 for (u = 0; u < solution->n cols; u++) {43 for (v = 0; v < solution->numRows; v++) { 44 for (u = 0; u < solution->numCols; u++) { 45 45 psVector *tmp = psVectorAllocEmpty(data->smfs->n,PS_TYPE_F32); 46 46 47 47 for (i = 0; i < data->smfs->n; i++) { 48 48 pmFPAviewReset(view); 49 pmFPAfile *smfFile = data->smfs .data[i];49 pmFPAfile *smfFile = data->smfs->data[i]; 50 50 51 51 pmChip *chip; // Chip from FPA … … 84 84 for (i = 0; i < data->smfs->n; i++) { 85 85 pmFPAviewReset(view); 86 pmFPAfile *smfFile = data->smfs .data[i];86 pmFPAfile *smfFile = data->smfs->data[i]; 87 87 88 88 pmChip *chip; // Chip from FPA … … 95 95 psImage *dec = psMetadataLookupPtr(NULL, chip->concepts, "bkg dec"); 96 96 97 psVector *obs = psVectorAlloc(image->n rows * image->ncols, PS_TYPE_F32);98 psVector *model= psVectorAlloc(image->n rows * image->ncols, PS_TYPE_F32);99 100 for (v = 0; v < image->n rows; v++) {101 for (u = 0; u < image->n cols; u++) {102 obs->data.F32[v * image->n cols + u] = image->data.F32[v][u];103 model->data.F32[v * image->n cols + u] = psImageMapEval(data->modelMap,ra->data.F32[v][u],dec->data.F32[v][u]);97 psVector *obs = psVectorAlloc(image->numRows * image->numCols, PS_TYPE_F32); 98 psVector *model= psVectorAlloc(image->numRows * image->numCols, PS_TYPE_F32); 99 100 for (v = 0; v < image->numRows; v++) { 101 for (u = 0; u < image->numCols; u++) { 102 obs->data.F32[v * image->numCols + u] = image->data.F32[v][u]; 103 model->data.F32[v * image->numCols + u] = psImageMapEval(data->modelMap,ra->data.F32[v][u],dec->data.F32[v][u]); 104 104 } 105 105 } 106 106 107 107 psPolynomial1D *poly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD,1); 108 status = psVectorFitPolynomial1d(poly,NULL,0,model,NULL,obs); 109 psMetadataAddF32(chip->analysis,PS_LIST_TAIL,"bkg offset", PS_META_REPLACE, "background offset for this exposure/ota pair", poly->coeff.F64[0]); 110 psMetadataAddF32(chip->analysis,PS_LIST_TAIL,"bkg scale", PS_META_REPLACE, "background scale for this exposure/ota pair", poly->coeff.F64[1]); 111 112 psFree(tmp); 108 int status = psVectorFitPolynomial1D(poly,NULL,0,model,NULL,obs); 109 if (!status) { 110 psMetadataAddF32(chip->analysis,PS_LIST_TAIL,"bkg offset", PS_META_REPLACE, "background offset for this exposure/ota pair", poly->coeff[0]); 111 psMetadataAddF32(chip->analysis,PS_LIST_TAIL,"bkg scale", PS_META_REPLACE, "background scale for this exposure/ota pair", poly->coeff[1]); 112 } 113 // psFree(tmp); 113 114 } // End OTA loop 114 115 } // End smf/exp loop … … 127 128 128 129 pmFPAview *view = pmFPAviewAlloc(0); 129 stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN);130 // psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN); 130 131 for (i = 0; i < data->smfs->n; i++) { 131 132 pmFPAviewReset(view); 132 pmFPAfile *smfFile = data->smfs .data[i];133 pmFPAfile *smfFile = data->smfs->data[i]; 133 134 134 135 pmChip *chip; // Chip from FPA … … 146 147 psF32 scale = psMetadataLookupF32(NULL,chip->concepts,"bkg scale"); 147 148 148 for (v = 0; v < image->n rows; v++) {149 for (u = 0; u < image->n cols; u++) {149 for (v = 0; v < image->numRows; v++) { 150 for (u = 0; u < image->numCols; u++) { 150 151 model->data.F32[v][u] = scale * image->data.F32[v][u] - offset - camera->data.F32[v][u]; 151 152 } … … 175 176 for (i = 0; i < data->smfs->n; i++) { 176 177 pmFPAviewReset(view); 177 pmFPAfile *smfFile = data->smfs .data[i];178 pmFPAfile *smfFile = data->smfs->data[i]; 178 179 179 180 pmChip *chip; // Chip from FPA … … 182 183 continue; 183 184 } 184 const char *chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME"); // Name of chip185 // const char *chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME"); // Name of chip 185 186 psImage *calib = psMetadataLookupPtr(NULL, chip->concepts, "bkg calibrated data"); 186 187 psImage *ra = psMetadataLookupPtr(NULL, chip->concepts, "bkg ra"); 187 188 psImage *dec = psMetadataLookupPtr(NULL, chip->concepts, "bkg dec"); 188 for (v = 0; v < image->nrows; v++) {189 for (u = 0; u < image->ncols; u++) {189 for (v = 0; v < calib->numRows; v++) { 190 for (u = 0; u < calib->numCols; u++) { 190 191 X->data.F32[j] = ra->data.F32[v][u]; 191 192 Y->data.F32[j] = dec->data.F32[v][u]; … … 197 198 } // End smfs 198 199 199 status = psImageMapClipFit(&fitStatus,data->modelMap,stats, NULL, 0, X, Y, Z, E); 200 bool fitStatus; 201 bool status = psImageMapClipFit(&fitStatus,data->modelMap,stats, NULL, 0, X, Y, Z, E); 202 200 203 psFree(X); 201 204 psFree(Y); … … 204 207 psFree(stats); 205 208 psFree(view); 206 } 209 return(status); 210 }
Note:
See TracChangeset
for help on using the changeset viewer.
