- Timestamp:
- May 7, 2013, 12:01:01 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.
