Changeset 35527
- Timestamp:
- May 7, 2013, 12:01:01 PM (13 years ago)
- Location:
- branches/eam_branches/ipp-20130419/pswarp/src
- Files:
-
- 1 added
- 8 edited
-
Makefile.am (modified) (1 diff)
-
pswarp.h (modified) (1 diff)
-
pswarpArguments.c (modified) (1 diff)
-
pswarpDefineLayout.c (modified) (7 diffs)
-
pswarpLoop.c (modified) (5 diffs)
-
pswarpParseCamera.c (modified) (4 diffs)
-
pswarpTransformTile.c (modified) (3 diffs)
-
pswarpUpdateMetadata.c (added)
-
pswarpUpdateStatistics.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20130419/pswarp/src/Makefile.am
r35521 r35527 51 51 pswarpTransformSources.c \ 52 52 pswarpTransformTile.c \ 53 pswarpUpdateStatistics.c \ 53 pswarpUpdateStatistics.c \ 54 pswarpUpdateMetadata.c \ 54 55 pswarpVersion.c \ 55 56 pswarpFiles.c -
branches/eam_branches/ipp-20130419/pswarp/src/pswarp.h
r35521 r35527 201 201 bool pswarpMakePSF (pmConfig *config, pmFPAfile *output, psMetadata *stats); 202 202 bool pswarpUpdateStatistics (pmFPA *output, psMetadata *stats, pmFPA *input, pmFPA *astrom, pmConfig *config); 203 bool pswarpUpdateMetadata (pmFPA *output, pmFPA *input, pmFPA *astrom, pmConfig *config); 204 205 // XXX functions in pswarpParseCamera 206 207 bool AddStringAsArray (psMetadata *md, char *string, char *name); 208 209 pmFPAfile *pswarpDefineInputFile(pmConfig *config,// Configuration 210 pmFPAfile *bind, // File to which to bind, or NULL 211 char *filerule, // Name of file rule 212 char *argname, // Argument name 213 pmFPAfileType fileType // Type of file 214 ); 215 216 bool pswarpParseSingleInput (pmConfig *config); 217 bool pswarpParseMultiInput (pmConfig *config, psMetadata *fileListMD); -
branches/eam_branches/ipp-20130419/pswarp/src/pswarpArguments.c
r35421 r35527 83 83 pswarpSetThreads(); 84 84 85 pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list"); 86 pmConfigFileSetsMD (config->arguments, &argc, argv, "MASK", "-mask", "-masklist"); 87 pmConfigFileSetsMD (config->arguments, &argc, argv, "VARIANCE", "-variance", "-variancelist"); 88 pmConfigFileSetsMD (config->arguments, &argc, argv, "BACKGROUND", "-background", "-bkglist"); 85 // there are three mutually exclusive ways of providing the input 86 // 1) supply -file (filename) [-mask .. -variance ..] on the command line 87 // 2) supply -input (input.mdc) on the command line 88 // 3) load inputs from RUN config info 89 90 // below, we check first for -file then for -input. failure to find either implies use of 91 // the configuration metadata file. 92 93 bool singleInput = pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list"); 94 if (singleInput) { 95 if (psArgumentGet(argc, argv, "-input")) { 96 psErrorStackPrint(stderr, "error in arguments : -input and -file / -list are mutually exclusive"); 97 exit(PS_EXIT_CONFIG_ERROR); 98 } 99 pmConfigFileSetsMD (config->arguments, &argc, argv, "MASK", "-mask", "-masklist"); 100 pmConfigFileSetsMD (config->arguments, &argc, argv, "VARIANCE", "-variance", "-variancelist"); 101 pmConfigFileSetsMD (config->arguments, &argc, argv, "BACKGROUND", "-background", "-bkglist"); 102 } else { 103 // find the input data file (an mdc file) 104 if ((N = psArgumentGet(argc, argv, "-input"))) { 105 if (argc <= N+1) { 106 psErrorStackPrint(stderr, "Expected to see 1 more argument; saw %d", argc - 1); 107 exit(PS_EXIT_CONFIG_ERROR); 108 } 109 psArgumentRemove(N, &argc, argv); 110 111 unsigned int numBad = 0; // Number of bad lines 112 psMetadata *inputs = psMetadataConfigRead(NULL, &numBad, argv[N], false); // Input file info 113 if (!inputs || numBad > 0) { 114 psErrorStackPrint(stderr, "Unable to cleanly read MDC file with inputs."); 115 exit(PS_EXIT_CONFIG_ERROR); 116 } 117 psMetadataAddMetadata(config->arguments, PS_LIST_TAIL, "INPUTS", 0, "Metadata with input details", inputs); 118 psFree(inputs); 119 120 psArgumentRemove(N, &argc, argv); 121 } 122 } 123 if (argc != 3) { 124 usage(); 125 } 126 if (psErrorCodeLast() != PS_ERR_NONE) { 127 psErrorStackPrint(stderr, "error in arguments"); 128 exit(PS_EXIT_CONFIG_ERROR); 129 } 89 130 90 if (argc != 3) {91 usage();92 }93 94 95 131 psArray *array; 96 132 -
branches/eam_branches/ipp-20130419/pswarp/src/pswarpDefineLayout.c
r35512 r35527 14 14 bool pswarpDefineLayout (pmConfig *config) { 15 15 16 // place input astrometry transformations in 'input' 17 pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PSWARP.INPUT"); 18 if (!input) { 19 psError(PSWARP_ERR_CONFIG, false, "Can't find input data!\n"); 20 return false; 21 } 22 // input astrometry may be embedded in 'input' or supplied separately 23 pmFPAfile *astrom = psMetadataLookupPtr(NULL, config->files, "PSWARP.ASTROM"); 24 if (!astrom) { 25 astrom = input; 26 } 27 if (!pswarpLoadAstrometry (input, astrom, config)) { 28 psError(PSWARP_ERR_CONFIG, false, "problem loading input astrometry\n"); 29 return false; 30 } 31 32 pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PSWARP.OUTPUT"); 16 bool status = false; 17 18 pmFPAfile *output = psMetadataLookupPtr(&status, config->files, "PSWARP.OUTPUT"); 33 19 if (!output) { 34 20 psError(PSWARP_ERR_CONFIG, false, "Can't find output data!\n"); … … 36 22 } 37 23 // select the input data sources 38 pmFPAfile *skycell = psMetadataLookupPtr ( NULL, config->files, "PSWARP.SKYCELL");24 pmFPAfile *skycell = psMetadataLookupPtr (&status, config->files, "PSWARP.SKYCELL"); 39 25 if (!skycell) { 40 26 psError(PSWARP_ERR_CONFIG, false, "Can't find skycell data!\n"); … … 46 32 } 47 33 48 // given the input data, determine which output elements should be generated 49 // and generate the appropriate images 50 51 // find the R,D center for the skycell, use for common projection 52 psProjection *frame = pswarpLocalFrame (skycell->fpa); 53 54 // generate Lmin,max, Mmin,max for both datasets 55 pswarpBounds *srcBounds = pswarpMakeBounds (input->fpa, frame); 56 pswarpBounds *tgtBounds = pswarpMakeBounds (skycell->fpa, frame); 57 58 // find the output (tgt) chips which overlap the input (src) chips 59 pswarpFindOverlap (input->fpa, output->fpa, srcBounds, tgtBounds); 34 // chips are not processed unless we have determined they overlap the inputs 35 pmFPAExcludeChips (output->fpa); 36 37 int nInputs = psMetadataLookupS32(&status, config->arguments, "NUM_INPUTS"); 38 if (!status) { 39 psError(PSWARP_ERR_DATA, true, "number of inputs is not defined (programming error)"); 40 return false; 41 } 42 43 for (int i = 0; i < nInputs; i++) { 44 // place input astrometry transformations in 'input' 45 pmFPAfile *input = pmFPAfileSelectSingle(config->files, "PSWARP.INPUT", i); 46 if (!input) { 47 psError(PSWARP_ERR_CONFIG, false, "Can't find input data!\n"); 48 return false; 49 } 50 51 // input astrometry may be embedded in 'input' or supplied separately 52 pmFPAfile *astrom = pmFPAfileSelectSingle(config->files, "PSWARP.ASTROM", i); 53 if (!astrom) { 54 astrom = input; 55 } 56 if (!pswarpLoadAstrometry (input, astrom, config)) { 57 psError(PSWARP_ERR_CONFIG, false, "problem loading input astrometry\n"); 58 return false; 59 } 60 61 // given the input data, determine which output elements should be generated 62 // and generate the appropriate images 63 64 // find the R,D center for the skycell, use for common projection 65 psProjection *frame = pswarpLocalFrame (skycell->fpa); 66 67 // generate Lmin,max, Mmin,max for both datasets 68 pswarpBounds *srcBounds = pswarpMakeBounds (input->fpa, frame); 69 pswarpBounds *tgtBounds = pswarpMakeBounds (skycell->fpa, frame); 70 71 // find the output (tgt) chips which overlap the input (src) chips 72 pswarpFindOverlap (input->fpa, output->fpa, srcBounds, tgtBounds); 73 psFree (srcBounds); 74 psFree (tgtBounds); 75 } 60 76 61 77 // The loop below generates the output pixels. XXX Should this be deferred until we … … 86 102 return false; 87 103 } 88 int numCols = psMetadataLookupS32( NULL, hdu->header, "NAXIS1"); ///< Number of columns89 int numRows = psMetadataLookupS32( NULL, hdu->header, "NAXIS2"); ///< Number of rows104 int numCols = psMetadataLookupS32(&status, hdu->header, "NAXIS1"); ///< Number of columns 105 int numRows = psMetadataLookupS32(&status, hdu->header, "NAXIS2"); ///< Number of rows 90 106 if ((numCols == 0) || (numRows == 0)) { 91 107 psError(PSWARP_ERR_DATA, false, "skycell has invalid dimensions %d x %d", numCols, numRows); … … 97 113 pmReadout *readout = pmReadoutAlloc(cell); ///< output readout 98 114 readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32); 115 99 116 psImageInit(readout->image, NAN); 100 117 psFree(readout); // Drop reference … … 129 146 # include "pswarpFileNames.h" 130 147 148 static int Nout = 0; 149 131 150 // XX function for tests 132 151 bool pswarpDumpOutput (pmConfig *config) { … … 144 163 pmFPAfileActivate(config->files, true, "PSWARP.OUTPUT"); 145 164 165 pmFPAview *view = pmFPAviewAlloc(0); 166 146 167 pmChip *chip; 147 pmFPAview *view = pmFPAviewAlloc(0);148 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {149 psError(psErrorCodeLast(), false, "Unable to read files.");150 goto DONE;151 }152 168 while ((chip = pmFPAviewNextChip (view, output->fpa, 1)) != NULL) { 153 169 psTrace ("pswarp", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 154 170 if (!chip->process || !chip->file_exists) { continue; } 155 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 156 psError(psErrorCodeLast(), false, "Unable to read files."); 157 goto DONE; 158 } 171 159 172 pmCell *cell; 160 173 while ((cell = pmFPAviewNextCell (view, output->fpa, 1)) != NULL) { 161 174 psTrace ("pswarp", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 162 175 if (!cell->process || !cell->file_exists) { continue; } 163 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE) || 164 !pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { 165 psError(psErrorCodeLast(), false, "Unable to read files."); 166 goto DONE; 176 177 // process each of the readouts 178 pmReadout *readout; 179 while ((readout = pmFPAviewNextReadout(view, output->fpa, 1)) != NULL) { 180 if (!readout->data_exists) { 181 continue; 182 } 183 184 char name[64]; 185 snprintf (name, 64, "dumpwarp.%02d.fits", Nout); 186 Nout ++; 187 188 psphotSaveImage (NULL, readout->image, name); 167 189 } 168 190 } -
branches/eam_branches/ipp-20130419/pswarp/src/pswarpLoop.c
r35522 r35527 36 36 37 37 // select the input data sources 38 pmFPAfile *input = psMetadataLookupPtr(&status, config->files, "PSWARP.INPUT");39 if (!input) {40 psError(PSWARP_ERR_CONFIG, true, "Can't find input data!\n");41 return false;42 }43 44 // use the external astrometry source if supplied45 pmFPAfile *astrom = psMetadataLookupPtr(&status, config->files, "PSWARP.ASTROM");46 if (!astrom) {47 astrom = input;48 }49 50 if (astrom->camera != input->camera) {51 psError(PSWARP_ERR_DATA, true, "Input camera and astrometry camera do not match.");52 return false;53 }54 55 // select the input data sources56 38 pmFPAfile *output = psMetadataLookupPtr(&status, config->files, "PSWARP.OUTPUT"); 57 39 if (!output) { … … 67 49 } 68 50 69 // ensure everyone is off except what we need below 70 pswarpFileActivation(config, detectorFiles, false); 71 pswarpFileActivation(config, photFiles, false); 72 pswarpFileActivation(config, independentFiles, false); 73 pswarpFileActivation(config, skycellFiles, false); 51 pmFPAview *view = pmFPAviewAlloc(0); 52 53 int nInputs = psMetadataLookupS32(&status, config->arguments, "NUM_INPUTS"); 54 if (!status) { 55 psError(PSWARP_ERR_DATA, true, "number of inputs is not defined (programming error)"); 56 return false; 57 } 58 59 // loop over this section once per input group 60 for (int i = 0; i < nInputs; i++) { 61 // select the input data sources 62 pmFPAfile *input = pmFPAfileSelectSingle(config->files, "PSWARP.INPUT", i); 63 if (!input) { 64 psError(PSWARP_ERR_CONFIG, true, "Can't find input data!\n"); 65 return false; 66 } 67 68 fprintf (stderr, "loading file %s\n", input->filename); 69 70 // use the external astrometry source if supplied 71 pmFPAfile *astrom = pmFPAfileSelectSingle(config->files, "PSWARP.ASTROM", i); 72 if (!astrom) { 73 astrom = input; 74 } 75 76 if (astrom->camera != input->camera) { 77 psError(PSWARP_ERR_DATA, true, "Input camera and astrometry camera do not match."); 78 return false; 79 } 80 81 // ensure everyone is off except what we need below 82 pswarpFileActivation(config, detectorFiles, false); 83 pswarpFileActivation(config, photFiles, false); 84 pswarpFileActivation(config, independentFiles, false); 85 pswarpFileActivation(config, skycellFiles, false); 74 86 75 // the loops below load the input data 76 pswarpFileActivation(config, detectorFiles, true); 77 78 // need to read in these (but only if CMF, right?) 79 pmFPAfileActivate(config->files, true, "PSWARP.ASTROM"); 80 81 // pswarpFileActivation(config, independentFiles, true); 82 83 pmFPAview *view = pmFPAviewAlloc(0); 84 85 // files associated with the science image 86 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 87 psError(psErrorCodeLast(), false, "Unable to read files."); 88 goto FAIL; 89 } 90 91 // *** main transformation block 92 // *** this section loops over the input chips/cells and reads them one at a time 93 // *** the output chips/cells are filled where appropriate, but not yet written to disk 94 pmChip *chip; 95 while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) { 96 psTrace ("pswarp", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 97 if (!chip->process || !chip->file_exists) { continue; } 98 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 99 psError(psErrorCodeLast(), false, "Unable to read files."); 100 goto FAIL; 101 } 102 103 pmCell *cell; 104 while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) { 105 psTrace ("pswarp", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 106 if (!cell->process || !cell->file_exists) { continue; } 107 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 108 psError(psErrorCodeLast(), false, "Unable to read files."); 109 goto FAIL; 110 } 111 112 // process each of the readouts 113 pmReadout *readout; 114 while ((readout = pmFPAviewNextReadout(view, input->fpa, 1)) != NULL) { 115 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 116 psError(psErrorCodeLast(), false, "Unable to read files."); 117 goto FAIL; 118 } 119 if (!readout->data_exists) { 120 continue; 121 } 122 123 // Copy the detections from the astrometry carrier to the input, so they can be accessed by 124 // pswarpTransformReadout 125 if (astrom != input) { 126 pmReadout *astromRO = pmFPAviewThisReadout(view, astrom->fpa); // Readout for astrometry 127 pmDetections *detections = psMetadataLookupPtr(&status, astromRO->analysis, "PSPHOT.DETECTIONS"); // Sources from astrometry 128 if (detections) { 129 psMetadataAddPtr(readout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_DATA_ARRAY, "Sources from input astrometry", detections); 130 } 87 // the loops below load the input data 88 pswarpFileActivation(config, detectorFiles, true); 89 90 // need to read in these (but only if CMF, right?) 91 pmFPAfileActivate(config->files, true, "PSWARP.ASTROM"); 92 93 // pswarpFileActivation(config, independentFiles, true); 94 95 pmFPAviewReset (view); 96 97 // files associated with the science image 98 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 99 psError(psErrorCodeLast(), false, "Unable to read files."); 100 goto FAIL; 101 } 102 103 // *** main transformation block 104 // *** this section loops over the input chips/cells and reads them one at a time 105 // *** the output chips/cells are filled where appropriate, but not yet written to disk 106 pmChip *chip; 107 while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) { 108 psTrace ("pswarp", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 109 if (!chip->process || !chip->file_exists) { continue; } 110 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 111 psError(psErrorCodeLast(), false, "Unable to read files."); 112 goto FAIL; 113 } 114 115 pmCell *cell; 116 while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) { 117 psTrace ("pswarp", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 118 if (!cell->process || !cell->file_exists) { continue; } 119 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 120 psError(psErrorCodeLast(), false, "Unable to read files."); 121 goto FAIL; 131 122 } 132 123 133 pswarpTransformToTarget(output->fpa, readout, config); 124 // process each of the readouts 125 pmReadout *readout; 126 while ((readout = pmFPAviewNextReadout(view, input->fpa, 1)) != NULL) { 127 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 128 psError(psErrorCodeLast(), false, "Unable to read files."); 129 goto FAIL; 130 } 131 if (!readout->data_exists) { 132 continue; 133 } 134 135 // Copy the detections from the astrometry carrier to the input, so they can be accessed by 136 // pswarpTransformReadout 137 if (astrom != input) { 138 pmReadout *astromRO = pmFPAviewThisReadout(view, astrom->fpa); // Readout for astrometry 139 pmDetections *detections = psMetadataLookupPtr(&status, astromRO->analysis, "PSPHOT.DETECTIONS"); // Sources from astrometry 140 if (detections) { 141 psMetadataAddPtr(readout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_DATA_ARRAY, "Sources from input astrometry", detections); 142 } 143 } 144 145 // psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "SET.VALUE", PS_META_REPLACE, "test", (i + 1)*1.0); 146 pswarpTransformToTarget(output->fpa, readout, config); 134 147 135 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 136 psError(psErrorCodeLast(), false, "Unable to write files."); 137 goto FAIL; 138 } 139 } 140 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 141 psError(psErrorCodeLast(), false, "Unable to write files."); 142 goto FAIL; 143 } 144 } 145 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 146 psError(psErrorCodeLast(), false, "Unable to write files."); 147 goto FAIL; 148 } 149 } 150 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 151 psError(psErrorCodeLast(), false, "Unable to write files."); 152 goto FAIL; 153 } 154 155 // Done with the detector side of things 156 pswarpFileActivation(config, detectorFiles, false); 157 pswarpFileActivation(config, independentFiles, false); 158 159 if (!pswarpUpdateStatistics (output->fpa, stats, input->fpa, astrom->fpa, config)) { 160 psError(psErrorCodeLast(), false, "problem generating statistics."); 161 goto FAIL; 148 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 149 psError(psErrorCodeLast(), false, "Unable to write files."); 150 goto FAIL; 151 } 152 } 153 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 154 psError(psErrorCodeLast(), false, "Unable to write files."); 155 goto FAIL; 156 } 157 } 158 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 159 psError(psErrorCodeLast(), false, "Unable to write files."); 160 goto FAIL; 161 } 162 } 163 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 164 psError(psErrorCodeLast(), false, "Unable to write files."); 165 goto FAIL; 166 } 167 168 // Done with the detector side of things 169 pswarpFileActivation(config, detectorFiles, false); 170 pswarpFileActivation(config, independentFiles, false); 171 172 if (!pswarpUpdateStatistics (output->fpa, stats, input->fpa, astrom->fpa, config)) { 173 psError(psErrorCodeLast(), false, "problem generating statistics."); 174 goto FAIL; 175 } 176 if (!pswarpUpdateMetadata (output->fpa, input->fpa, astrom->fpa, config)) { 177 psError(psErrorCodeLast(), false, "problem generating statistics."); 178 goto FAIL; 179 } 162 180 } 163 181 … … 166 184 goto FAIL; 167 185 } 186 187 // XXX 188 // pswarpDumpOutput (config); 189 // exit (0); 168 190 169 191 psFree(view); … … 174 196 return false; 175 197 } 198 199 // static int Nout = 0; 176 200 177 201 // once the output fpa elements have been built, loop over the fpa and generate stats … … 195 219 while ((readout = pmFPAviewNextReadout(view, output, 1)) != NULL) { 196 220 pswarpTransformReadout (readout, input, config); 221 // char name[64]; 222 // snprintf (name, 64, "dumpwarp.%02d.fits", Nout); 223 // Nout ++; 224 // 225 // psphotSaveImage (NULL, readout->image, name); 197 226 } 198 227 } -
branches/eam_branches/ipp-20130419/pswarp/src/pswarpParseCamera.c
r35521 r35527 13 13 #include "pswarp.h" 14 14 15 // Define an input file 16 static pmFPAfile *defineInputFile(pmConfig *config,// Configuration 17 pmFPAfile *bind, // File to which to bind, or NULL 18 char *filerule, // Name of file rule 19 char *argname, // Argument name 20 pmFPAfileType fileType // Type of file 21 ) 22 { 23 bool status; 24 25 pmFPAfile *file = NULL; 26 // look for the file on the argument list 27 if (bind) { 28 file = pmFPAfileBindFromArgs(&status, bind, config, filerule, argname); 29 } else { 30 file = pmFPAfileDefineFromArgs(&status, config, filerule, argname); 31 } 32 if (!status) { 33 psError(psErrorCodeLast(), false, "Failed to load file definition for %s", filerule); 34 return false; 35 } 36 if (!file) { 37 // look for the file on the RUN metadata 38 file = pmFPAfileDefineFromRun(&status, bind, config, filerule); // File to return 39 if (!status) { 40 psError(psErrorCodeLast(), false, "Failed to load file definition for %s", filerule); 41 return NULL; 42 } 43 } 44 45 if (!file) { 46 return NULL; 47 } 48 49 if (file->type != fileType) { 50 psError(PSWARP_ERR_CONFIG, true, "%s is not of type %s", filerule, pmFPAfileStringFromType(fileType)); 51 return NULL; 52 } 53 54 return file; 55 } 15 static bool foundAstrom = false; 16 static bool foundVariance = false; 17 static bool foundBackground = false; 56 18 57 19 bool pswarpParseCamera(pmConfig *config) 58 20 { 59 21 psAssert(config, "Require configuration"); 60 bool mdok; // Status of MD lookup 22 bool status; // Status of MD lookup 23 24 // *** parse the input information (either from -file or from -input) 25 26 // if INPUTS exists, we have a metadata file to provide input, variance, mask, etc 27 psMetadata *inputFile = psMetadataLookupPtr(&status, config->arguments, "INPUTS"); 28 if (inputFile) { 29 if (!pswarpParseMultiInput (config, inputFile)) { 30 psError(PSWARP_ERR_CONFIG, false, "failed to parse multi-input file"); 31 return false; 32 } 33 } else { 34 if (!pswarpParseSingleInput (config)) { 35 psError(PSWARP_ERR_CONFIG, false, "failed to parse multi-input file"); 36 return false; 37 } 38 } 39 40 // *** parse the output information (output target, output astrometry [skycell]) 41 42 // The input skycell is a required argument: it defines the output image 43 pmConfig *skyConfig = NULL; 44 pmFPAfile *skycell = NULL; 45 46 skycell = pmFPAfileDefineNewConfig(&status, &skyConfig, config, "PSWARP.SKYCELL", "SKYCELL"); 47 if (!status || !skycell) { 48 psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.SKYCELL"); 49 return false; 50 } 51 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "SKYCELL.CAMERA", 0, "Name of camera for skycell", skyConfig->cameraName); 52 psFree(skyConfig); 53 54 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSWARP_RECIPE); 55 if (!recipe) { 56 psError(PSWARP_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE); 57 return false; 58 } 59 60 // The output skycell 61 pmFPAfile *output = pmFPAfileDefineOutputForFormat(config, NULL, "PSWARP.OUTPUT", skycell->cameraName, skycell->formatName); 62 if (!output) { 63 psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.OUTPUT"); 64 return false; 65 } 66 output->save = true; 67 68 pmFPAfile *outMask = pmFPAfileDefineOutputForFormat(config, output->fpa, "PSWARP.OUTPUT.MASK", skycell->cameraName, skycell->formatName); 69 if (!outMask) { 70 psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.OUTPUT.MASK"); 71 return false; 72 } 73 outMask->save = true; 74 75 // only create an output variance in we supply an input variance 76 if (foundVariance) { 77 pmFPAfile *outVariance = pmFPAfileDefineOutputForFormat(config, output->fpa, "PSWARP.OUTPUT.VARIANCE", skycell->cameraName, skycell->formatName); 78 if (!outVariance) { 79 psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.OUTPUT.VARIANCE"); 80 return false; 81 } 82 outVariance->save = true; 83 } 84 85 // XXX we assume input sources come from the input astrom description, but this need not be true (we could define an input sources file) 86 if (foundAstrom && psMetadataLookupBool(&status, recipe, "SOURCES")) { 87 pmFPAfile *outSources = pmFPAfileDefineOutputForFormat(config, output->fpa, "PSWARP.OUTPUT.SOURCES", skycell->cameraName, skycell->formatName); 88 if (!outSources) { 89 psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.OUTPUT.SOURCES"); 90 return false; 91 } 92 outSources->save = true; 93 } 94 95 // only create an output background if an input background is supplied 96 if (foundBackground && psMetadataLookupBool(&status, recipe, "BACKGROUND.MODEL")) { 97 pmFPAfile *outBackground = pmFPAfileDefineSkycell(config, NULL, "PSWARP.OUTPUT.BKGMODEL"); 98 outBackground->xBin = psMetadataLookupS32(&status, recipe, "BKG.XGRID"); 99 outBackground->yBin = psMetadataLookupS32(&status, recipe, "BKG.YGRID"); 100 101 if (!outBackground) { 102 psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.OUTPUT.BKGMODEL"); 103 return false; 104 } 105 outBackground->save = true; 106 } 107 108 if (psMetadataLookupBool(&status, recipe, "PSF")) { 109 // This file, PSPHOT.INPUT, is just used as a carrier; output files (eg, PSPHOT.RESID) are defined by psphotDefineFiles 110 pmFPAfile *psphotInput = pmFPAfileDefineOutputForFormat(config, NULL, "PSPHOT.INPUT", skycell->cameraName, skycell->formatName); 111 if (!psphotInput) { 112 psError(psErrorCodeLast(), false, _("Unable to generate output file from PSPHOT.INPUT")); 113 return false; 114 } 115 psphotInput->src = psMemIncrRefCounter(output->fpa); 116 117 // specify the number of psphot input images (psphotReadout loops over all input images) 118 psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "number of inputs", 1); 119 120 // the input sources (read from the input astrometry file) are transformed (in pswarpLoop) to the readout->analysis 121 // entries of the output file PSWARP.OUTPUT.SOURCES, associated with the main output pmFPAfile PSWARP.OUTPUT 122 123 // the PSPHOT.INPUT.CMF is used to supply those sources to psphot (specifically psphotLoadPSFSources). 124 125 // pmFPAfile *psphotInSources = pmFPAfileDefineSkycell(config, output->fpa, "PSPHOT.INPUT.CMF"); 126 pmFPAfile *psphotInSources = pmFPAfileDefineOutputForFormat(config, output->fpa, "PSPHOT.INPUT.CMF", skycell->cameraName, skycell->formatName); 127 if (!psphotInSources) { 128 psError(psErrorCodeLast(), false, _("Unable to generate output file from PSPHOT.INPUT.CMF")); 129 return false; 130 } 131 132 // Ensure psphot defines an output file for the PSF. 133 psMetadata *psphotRecipe = psMetadataLookupPtr(NULL, config->recipes, PSPHOT_RECIPE); // Recipe 134 if (!psphotRecipe) { 135 psError(PSWARP_ERR_CONFIG, false, "Unable to find %s recipe.", PSPHOT_RECIPE); 136 return false; 137 } 138 psMetadataAddBool(psphotRecipe, PS_LIST_TAIL, "SAVE.PSF", PS_META_REPLACE, "Save PSF?", true); 139 140 // Define associated psphot input/output files 141 if (!psphotDefineFiles(config, psphotInput)) { 142 psError(PSWARP_ERR_CONFIG, false, 143 "Unable to define the additional input/output files for psphot"); 144 return false; 145 } 146 147 // Turn off writing the sources we find as part of deriving the PSF --- they might clobber the ones we 148 // get from transforming the input coordinates. 149 pmFPAfile *psphotSources = psMetadataLookupPtr(NULL, config->files, "PSPHOT.OUTPUT"); 150 assert(psphotSources); 151 psphotSources->save = false; 152 } 153 154 psTrace("pswarp", 1, "Done with pswarpParseCamera...\n"); 155 return true; 156 } 157 158 bool pswarpParseSingleInput (pmConfig *config) { 61 159 62 160 // The input image(s) is required: it defines the camera 63 pmFPAfile *input = defineInputFile(config, NULL, "PSWARP.INPUT", "INPUT", PM_FPA_FILE_IMAGE);161 pmFPAfile *input = pswarpDefineInputFile(config, NULL, "PSWARP.INPUT", "INPUT", PM_FPA_FILE_IMAGE); 64 162 if (!input) { 65 163 psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.INPUT"); … … 77 175 } 78 176 } 79 if (astrom && (astrom->type != PM_FPA_FILE_CMF) && (astrom->type != PM_FPA_FILE_WCS)) { 80 psLogMsg("pswarp", PS_LOG_INFO, "%s is neither CMF nor WCS", "PSWARP.ASTROM"); 177 if (astrom) { 178 if ((astrom->type != PM_FPA_FILE_CMF) && (astrom->type != PM_FPA_FILE_WCS)) { 179 psLogMsg("pswarp", PS_LOG_INFO, "%s is neither CMF nor WCS", "PSWARP.ASTROM"); 180 // XXX raise an error here?? 181 } else { 182 foundAstrom = true; 183 } 81 184 } 82 185 psLogMsg("pswarp", PS_LOG_INFO, "Astrometry source: %s", astrom ? "supplied" : "header"); 83 186 84 187 // Define the input mask file(s) 85 pmFPAfile *inMask = defineInputFile(config, input, "PSWARP.MASK", "MASK", PM_FPA_FILE_MASK);188 pmFPAfile *inMask = pswarpDefineInputFile(config, input, "PSWARP.MASK", "MASK", PM_FPA_FILE_MASK); 86 189 if (!inMask) { 87 190 psLogMsg("pswarp", PS_LOG_INFO, "No mask supplied"); … … 89 192 90 193 // Define the input variance file(s) 91 pmFPAfile *inVariance = defineInputFile(config, input, "PSWARP.VARIANCE", "VARIANCE", 92 PM_FPA_FILE_VARIANCE); 93 if (!inVariance) { 194 pmFPAfile *inVariance = pswarpDefineInputFile(config, input, "PSWARP.VARIANCE", "VARIANCE", PM_FPA_FILE_VARIANCE); 195 if (inVariance) { 196 foundVariance = true; 197 } else { 94 198 psLogMsg("pswarp", PS_LOG_INFO, "No variance supplied"); 95 199 } 96 200 97 pmFPAfile *inBackground = defineInputFile(config, NULL, "PSWARP.BKGMODEL", "BACKGROUND", 98 PM_FPA_FILE_IMAGE); 99 if (!inBackground) { 201 pmFPAfile *inBackground = pswarpDefineInputFile(config, NULL, "PSWARP.BKGMODEL", "BACKGROUND", PM_FPA_FILE_IMAGE); 202 if (inBackground) { 203 foundBackground = true; 204 } else { 100 205 psLogMsg("pswarp", PS_LOG_INFO, "No background models supplied"); 101 206 } 102 103 // The input skycell is a required argument: it defines the output image104 pmConfig *skyConfig = NULL;105 pmFPAfile *skycell = NULL;106 107 # define USE_PSWARP_DEFINE_SKYCELL 0108 # if (USE_PSWARP_DEFINE_SKYCELL)109 // XXX this function is no longer needed; drop110 status = pswarpDefineSkycell(&skycell, &skyConfig, config, "PSWARP.SKYCELL", "SKYCELL");111 # else112 skycell = pmFPAfileDefineNewConfig(&status, &skyConfig, config, "PSWARP.SKYCELL", "SKYCELL");113 # endif114 115 if (!status || !skycell) {116 psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.SKYCELL");117 return false;118 }119 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "SKYCELL.CAMERA", 0, "Name of camera for skycell", skyConfig->cameraName);120 psFree(skyConfig);121 122 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSWARP_RECIPE);123 if (!recipe) {124 psError(PSWARP_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE);125 return false;126 }127 128 // The output skycell129 // XXX The output needs to be in a more generic format, not just skycell.130 // I need to understand how badly things depend on SKYCELL being a special format131 // (is it just pswarp, or is it everything downstream as well??)132 // XXX for a test, generate a generic output (based on output target astrometry)133 // XXX pmFPAfile *output = pmFPAfileDefineSkycell(config, NULL, "PSWARP.OUTPUT");134 pmFPAfile *output = pmFPAfileDefineOutputForFormat(config, NULL, "PSWARP.OUTPUT", skycell->cameraName, skycell->formatName);135 if (!output) {136 psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.OUTPUT");137 return false;138 }139 output->save = true;140 141 // pmFPAfile *outMask = pmFPAfileDefineSkycell(config, output->fpa, "PSWARP.OUTPUT.MASK");142 pmFPAfile *outMask = pmFPAfileDefineOutputForFormat(config, output->fpa, "PSWARP.OUTPUT.MASK", skycell->cameraName, skycell->formatName);143 if (!outMask) {144 psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.OUTPUT.MASK");145 return false;146 }147 outMask->save = true;148 149 if (inVariance) {150 // pmFPAfile *outVariance = pmFPAfileDefineSkycell(config, output->fpa, "PSWARP.OUTPUT.VARIANCE");151 pmFPAfile *outVariance = pmFPAfileDefineOutputForFormat(config, output->fpa, "PSWARP.OUTPUT.VARIANCE", skycell->cameraName, skycell->formatName);152 if (!outVariance) {153 psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.OUTPUT.VARIANCE");154 return false;155 }156 outVariance->save = true;157 }158 159 if (astrom && psMetadataLookupBool(&mdok, recipe, "SOURCES")) {160 // pmFPAfile *outSources = pmFPAfileDefineSkycell(config, output->fpa, "PSWARP.OUTPUT.SOURCES");161 pmFPAfile *outSources = pmFPAfileDefineOutputForFormat(config, output->fpa, "PSWARP.OUTPUT.SOURCES", skycell->cameraName, skycell->formatName);162 if (!outSources) {163 psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.OUTPUT.SOURCES");164 return false;165 }166 outSources->save = true;167 }168 169 if (inBackground && psMetadataLookupBool(&mdok, recipe, "BACKGROUND.MODEL")) {170 pmFPAfile *outBackground = pmFPAfileDefineSkycell(config, NULL, "PSWARP.OUTPUT.BKGMODEL");171 outBackground->xBin = psMetadataLookupS32(&mdok, recipe, "BKG.XGRID");172 outBackground->yBin = psMetadataLookupS32(&mdok, recipe, "BKG.YGRID");173 174 if (!outBackground) {175 psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.OUTPUT.BKGMODEL");176 return false;177 }178 outBackground->save = true;179 }180 181 if (psMetadataLookupBool(&mdok, recipe, "PSF")) {182 // This file, PSPHOT.INPUT, is just used as a carrier; output files (eg, PSPHOT.RESID) are defined by183 // psphotDefineFiles184 // XXX old : pmFPAfile *psphotInput = pmFPAfileDefineSkycell(config, NULL, "PSPHOT.INPUT");185 pmFPAfile *psphotInput = pmFPAfileDefineOutputForFormat(config, NULL, "PSPHOT.INPUT", skycell->cameraName, skycell->formatName);186 if (!psphotInput) {187 psError(psErrorCodeLast(), false, _("Unable to generate output file from PSPHOT.INPUT"));188 return false;189 }190 psphotInput->src = psMemIncrRefCounter(output->fpa);191 192 // specify the number of psphot input images (psphotReadout loops over all input images)193 psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "number of inputs", 1);194 195 // the input sources (read from the input astrometry file) are transformed (in pswarpLoop) to the readout->analysis196 // entries of the output file PSWARP.OUTPUT.SOURCES, associated with the main output pmFPAfile PSWARP.OUTPUT197 198 // the PSPHOT.INPUT.CMF is used to supply those sources to psphot (specifically psphotLoadPSFSources).199 200 // pmFPAfile *psphotInSources = pmFPAfileDefineSkycell(config, output->fpa, "PSPHOT.INPUT.CMF");201 pmFPAfile *psphotInSources = pmFPAfileDefineOutputForFormat(config, output->fpa, "PSPHOT.INPUT.CMF", skycell->cameraName, skycell->formatName);202 if (!psphotInSources) {203 psError(psErrorCodeLast(), false, _("Unable to generate output file from PSPHOT.INPUT.CMF"));204 return false;205 }206 207 // Ensure psphot defines an output file for the PSF.208 psMetadata *psphotRecipe = psMetadataLookupPtr(NULL, config->recipes, PSPHOT_RECIPE); // Recipe209 if (!psphotRecipe) {210 psError(PSWARP_ERR_CONFIG, false, "Unable to find %s recipe.", PSPHOT_RECIPE);211 return false;212 }213 psMetadataAddBool(psphotRecipe, PS_LIST_TAIL, "SAVE.PSF", PS_META_REPLACE, "Save PSF?", true);214 215 // Define associated psphot input/output files216 if (!psphotDefineFiles(config, psphotInput)) {217 psError(PSWARP_ERR_CONFIG, false,218 "Unable to define the additional input/output files for psphot");219 return false;220 }221 222 // Turn off writing the sources we find as part of deriving the PSF --- they might clobber the ones we223 // get from transforming the input coordinates.224 pmFPAfile *psphotSources = psMetadataLookupPtr(NULL, config->files, "PSPHOT.OUTPUT");225 assert(psphotSources);226 psphotSources->save = false;227 }228 207 229 208 // Chip selection: turn on only the chips specified 230 char *chipLine = psMetadataLookupStr(& mdok, config->arguments, "CHIP_SELECTIONS");231 if ( mdok) {209 char *chipLine = psMetadataLookupStr(&status, config->arguments, "CHIP_SELECTIONS"); 210 if (status) { 232 211 psArray *chips = psStringSplitArray (chipLine, ",", false); 233 212 if (chips->n > 0) { … … 244 223 } 245 224 246 ps Trace("pswarp", 1, "Done with pswarpParseCamera...\n");225 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "NUM_INPUTS", PS_META_REPLACE, "input file sets", 1); 247 226 return true; 248 227 } 228 229 // read input file information from a metadata file 230 // XXX for now, in the multi-input format, we disable PSF, BACKGROUND, and CHIP_SELECTIONS 231 bool pswarpParseMultiInput (pmConfig *config, psMetadata *fileListMD) { 232 233 // the multi-input file consists of a set of metadata blocks, each with entries 234 // for INPUT and (possibly) ASTROM, MASK, VARIANCE, ??? 235 236 bool status = false; 237 238 for (int i = 0; i < fileListMD->list->n; i++) { 239 psMetadataItem *item = psMetadataGet(fileListMD, i); 240 if (item->type != PS_DATA_METADATA) { 241 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Component %s of the input metadata is not of type METADATA", item->name); 242 return false; 243 } 244 245 // next input metadata block of interest 246 psMetadata *fileBlockMD = item->data.md; 247 248 psString inputName = psMetadataLookupStr(&status, fileBlockMD, "INPUT"); // Name of image 249 if (!inputName || !strlen(inputName)) { 250 psError(PS_ERR_UNKNOWN, false, "input file not found in metadata block %d (%s)", i, item->name); 251 return false; 252 } 253 AddStringAsArray (config->arguments, inputName, "FILENAMES"); 254 255 pmFPAfile *input = pswarpDefineInputFile (config, NULL, "PSWARP.INPUT", "FILENAMES", PM_FPA_FILE_IMAGE); 256 if (!input) { 257 psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.INPUT"); 258 return false; 259 } 260 261 psString astromName = psMetadataLookupStr(&status, fileBlockMD, "ASTROM"); // Name of astrom file 262 if (astromName && strlen(astromName)) { 263 AddStringAsArray (config->arguments, astromName, "FILENAMES"); 264 265 pmFPAfile *astrom = pmFPAfileDefineFromArgs (&status, config, "PSWARP.ASTROM", "FILENAMES"); 266 if (!status) { 267 psLogMsg("pswarp", PS_LOG_INFO, "Failed to load file definition for %s", "PSWARP.ASTROM"); 268 } 269 if (astrom) { 270 if ((astrom->type != PM_FPA_FILE_CMF) && (astrom->type != PM_FPA_FILE_WCS)) { 271 psLogMsg("pswarp", PS_LOG_INFO, "%s is neither CMF nor WCS", "PSWARP.ASTROM"); 272 } else { 273 foundAstrom = true; 274 } 275 } 276 psLogMsg("pswarp", PS_LOG_INFO, "Astrometry source: %s", astrom ? "supplied" : "header"); 277 } 278 279 pmFPAfile *mask = NULL; 280 psString maskName = psMetadataLookupStr(&status, fileBlockMD, "MASK"); // Name of mask 281 if (maskName && strlen(maskName)) { 282 AddStringAsArray (config->arguments, maskName, "FILENAMES"); 283 284 mask = pswarpDefineInputFile (config, input, "PSWARP.MASK", "FILENAMES", PM_FPA_FILE_MASK); 285 } 286 if (!mask) { 287 psLogMsg("pswarp", PS_LOG_INFO, "No mask supplied"); 288 } 289 290 pmFPAfile *variance = NULL; 291 psString varianceName = psMetadataLookupStr(&status, fileBlockMD, "VARIANCE"); // Name of variance 292 if (varianceName && strlen(varianceName)) { 293 AddStringAsArray (config->arguments, varianceName, "FILENAMES"); 294 295 variance = pswarpDefineInputFile (config, input, "PSWARP.VARIANCE", "FILENAMES", PM_FPA_FILE_VARIANCE); 296 } 297 if (variance) { 298 foundVariance = true; 299 } else { 300 psLogMsg("pswarp", PS_LOG_INFO, "No variance supplied"); 301 } 302 } 303 304 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "NUM_INPUTS", PS_META_REPLACE, "input file sets", fileListMD->list->n); 305 return true; 306 } 307 308 // Define an input file based on name in config->arguments or config RUN block 309 pmFPAfile *pswarpDefineInputFile(pmConfig *config,// Configuration 310 pmFPAfile *bind, // File to which to bind, or NULL 311 char *filerule, // Name of file rule 312 char *argname, // Argument name 313 pmFPAfileType fileType // Type of file 314 ) 315 { 316 bool status; 317 318 pmFPAfile *file = NULL; 319 // look for the file on the argument list 320 if (bind) { 321 file = pmFPAfileBindFromArgs(&status, bind, config, filerule, argname); 322 } else { 323 file = pmFPAfileDefineFromArgs(&status, config, filerule, argname); 324 } 325 if (!status) { 326 psError(psErrorCodeLast(), false, "Failed to load file definition for %s", filerule); 327 return false; 328 } 329 if (!file) { 330 // look for the file on the RUN metadata 331 file = pmFPAfileDefineFromRun(&status, bind, config, filerule); // File to return 332 if (!status) { 333 psError(psErrorCodeLast(), false, "Failed to load file definition for %s", filerule); 334 return NULL; 335 } 336 } 337 338 if (!file) { 339 return NULL; 340 } 341 342 if (file->type != fileType) { 343 psError(PSWARP_ERR_CONFIG, true, "%s is not of type %s", filerule, pmFPAfileStringFromType(fileType)); 344 return NULL; 345 } 346 347 return file; 348 } 349 350 bool AddStringAsArray (psMetadata *md, char *string, char *name) { 351 352 psArray *dummy = psArrayAlloc(1); // Dummy array of filenames for this FPA 353 dummy->data[0] = psStringCopy(string); 354 355 psMetadataAddArray(md, PS_LIST_TAIL, name, PS_META_REPLACE, "string added as array", dummy); 356 psFree(dummy); 357 return true; 358 } 359 -
branches/eam_branches/ipp-20130419/pswarp/src/pswarpTransformTile.c
r34800 r35527 89 89 90 90 for (int y = yMin; y < yMax; y++) { 91 92 int yOut = y - outRow0; ///< Position on output image 93 91 94 for (int x = xMin; x < xMax; x++) { 92 95 // Only transform those pixels requested … … 94 97 continue; 95 98 } 99 100 int xOut = x - outCol0; 101 102 // XXX the existing image may already have valid data -- probably should keep 103 // the best, but for the moment, just keep the pixel which is not NAN 104 if (isfinite(outImageData[yOut][xOut])) continue; 105 96 106 // pswarpMapApply converts the output coordinate (x,y) to the input coordinate. 97 107 // both are in the parent frames of the input and output images. … … 127 137 } 128 138 129 int xOut = x - outCol0, yOut = y - outRow0; ///< Position on output image130 131 139 if (outImageData) { 132 outImageData[yOut][xOut] = imageValue * jacobian; 140 // XXX TEST outImageData[yOut][xOut] = value; 141 outImageData[yOut][xOut] = imageValue * jacobian; 133 142 } 134 143 if (outVarData) { -
branches/eam_branches/ipp-20130419/pswarp/src/pswarpUpdateStatistics.c
r35524 r35527 15 15 // for each readout 16 16 bool pswarpUpdateStatistics (pmFPA *output, psMetadata *fpaStats, pmFPA *input, pmFPA *astrom, pmConfig *config) { 17 18 if (!fpaStats) { 19 psLogMsg("pswarp", PS_LOG_INFO, "stats not requested, skipping"); 20 return true; 21 } 17 22 18 23 // load the recipe … … 95 100 } 96 101 97 // Set covariance matrix for output98 // XXX is this the right place for the covariance calculation?99 # if (0)100 psList *covariances = psMetadataLookupPtr(&mdok, output->analysis, PSWARP_ANALYSIS_COVARIANCES); // Covariance matrices101 psAssert(covariances, "Should be there");102 psArray *covars = psListToArray(covariances); // Array of covariance matrices103 psKernel *covar = psImageCovarianceAverage(covars);104 psFree(covars);105 psMetadataRemoveKey(output->analysis, PSWARP_ANALYSIS_COVARIANCES);106 107 // Correct covariance matrix scale for the mean (square root of the) Jacobian108 double jacobian = psMetadataLookupF64(NULL, output->analysis, PSWARP_ANALYSIS_JACOBIAN); // Jacobian109 int goodPixels = psMetadataLookupS32(NULL, output->analysis, PSWARP_ANALYSIS_GOODPIX); // Good pixels110 jacobian /= goodPixels;111 output->covariance = psImageCovarianceScale(covar, jacobian);112 psFree(covar);113 114 if (output->variance) {115 psImageCovarianceTransfer(output->variance, output->covariance);116 }117 # endif118 119 {120 // Add MD5 information for readout121 psString headerName = NULL; ///< Header name for MD5122 psVector *md5 = psImageMD5(readout->image); ///< md5 hash123 psString md5string = psMD5toString(md5); ///< String124 125 pmHDU *hdu = pmHDUFromReadout(readout);126 psStringAppend(&headerName, "MD5_%s_%s_%d", chipName, cellName, view->readout);127 psMetadataAddStr(hdu->header, PS_LIST_TAIL, headerName, PS_META_REPLACE, "Image MD5", md5string);128 psFree(md5);129 psFree(md5string);130 psFree(headerName);131 }132 102 psFree (readoutName); 133 103 } 134 135 psList *inputCells = psMetadataLookupPtr (NULL, cell->analysis, "INPUT.CELLS");136 if (!pmConceptsAverageCells(cell, inputCells, NULL, NULL, false)) {137 psError(psErrorCodeLast(), false, "Unable to average cell concepts.");138 psFree(view);139 return false;140 }141 142 // XXX Is this too ad-hoc?143 psRegion *trimsec = psMetadataLookupPtr(NULL, cell->concepts, "CELL.TRIMSEC"); ///< Trim section144 trimsec->x0 = trimsec->x1 = trimsec->y0 = trimsec->y1 = 0; ///< All pixels145 146 104 } 147 105 } 148 106 149 107 // Perform statistics on the output image (ppStatsFPA loops down the hierarchy) 150 if (fpaStats) { 151 pmFPAviewReset (view); 152 if (!ppStatsFPA(fpaStats, output, view, maskValue, config)) { 108 pmFPAviewReset (view); 109 if (!ppStatsFPA(fpaStats, output, view, maskValue, config)) { 153 110 psWarning("Unable to perform statistics on warped image."); 154 }155 111 } 156 112 psFree(view); 157 158 if (!psMetadataCopy(output->concepts, input->concepts)) {159 psError(psErrorCodeLast(), false, "Unable to copy FPA concepts from input to output.");160 return false;161 }162 113 163 114 if (Nreadout == 0) { … … 168 119 } 169 120 170 // Update ZP from the astrometry171 {172 psMetadataItem *item = psMetadataLookup(output->concepts, "FPA.ZP");173 item->data.F32 = psMetadataLookupF32(NULL, astrom->concepts, "FPA.ZP");174 }175 176 // need to update the chip and fpa level astrometry appropriately, see177 // code in psastro178 179 # if (0)180 if (!pmAstromWriteWCS(hdu->header, outFPA, outChip, WCS_NONLIN_TOL)) {181 psError(psErrorCodeLast(), false, "Unable to generate WCS header.");182 return false;183 }184 # endif185 186 121 return true; 187 122 }
Note:
See TracChangeset
for help on using the changeset viewer.
