Changeset 23704 for branches/pap/ppSub/src/ppSubLoop.c
- Timestamp:
- Apr 3, 2009, 11:58:24 AM (17 years ago)
- File:
-
- 1 edited
-
branches/pap/ppSub/src/ppSubLoop.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pap/ppSub/src/ppSubLoop.c
r23688 r23704 21 21 #include "ppSub.h" 22 22 23 bool ppSubLoop(pmConfig *config )23 bool ppSubLoop(pmConfig *config, ppSubData *data) 24 24 { 25 25 psAssert(config, "Require configuration."); … … 28 28 pmConfigRecipesCull(config, "PPSUB,PPSTATS,PSPHOT,MASKS,JPEG"); 29 29 30 ppSubData *data = ppSubDataAlloc(); // Processing data31 30 32 bool mdok; // Status of MD lookup 33 const char *statsName = psMetadataLookupStr(&mdok, config->arguments, "STATS"); // Filename for statistics 34 FILE *statsFile = NULL; // File stream for statistics 35 if (statsName && strlen(statsName) > 0) { 36 psString resolved = pmConfigConvertFilename(statsName, config, true, true); // Resolved filename 37 statsFile = fopen(resolved, "w"); 38 if (!statsFile) { 39 psError(PS_ERR_IO, true, "Unable to open statistics file %s for writing.\n", resolved); 40 psFree(resolved); 31 pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PPSUB.INPUT"); 32 pmFPAfile *reference = psMetadataLookupPtr(NULL, config->files, "PPSUB.REF"); 33 pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PPSUB.OUTPUT"); 34 psAssert(input && reference && output, "Require files"); 35 36 if (!ppSubFilesIterateDown(config, PPSUB_FILES_INPUT | PPSUB_FILES_CONV)) { 37 psError(PPSUB_ERR_IO, false, "Unable to load files."); 38 return false; 39 } 40 41 psTimerStart("PPSUB_MATCH"); 42 43 if (!ppSubSetMasks(config)) { 44 psError(PS_ERR_UNKNOWN, false, "Unable to set masks."); 45 return false; 46 } 47 48 if (!ppSubMatchPSFs(config, data)) { 49 psError(PS_ERR_UNKNOWN, false, "Unable to match PSFs."); 50 return false; 51 } 52 if (data->quality) { 53 // Can't do anything at all 54 return true; 55 } 56 57 // Close input files 58 if (!ppSubFilesIterateUp(config, PPSUB_FILES_INPUT)) { 59 psError(PPSUB_ERR_IO, false, "Unable to close input files."); 60 return false; 61 } 62 63 // Set up subtraction files 64 if (!ppSubFilesIterateDown(config, PPSUB_FILES_SUB)) { 65 psError(PPSUB_ERR_IO, false, "Unable to set up subtraction files."); 66 return false; 67 } 68 69 if (!ppSubDefineOutput("PPSUB.OUTPUT", config, data, view)) { 70 psError(PS_ERR_UNKNOWN, false, "Unable to define output."); 71 return false; 72 } 73 74 if (data->inverse && !ppSubDefineOutput("PPSUB.OUTINV", config, data, view)) { 75 psError(PS_ERR_UNKNOWN, false, "Unable to define inverse."); 76 return false; 77 } 78 79 if (!data->quality && !ppSubMakePSF("PPSUB.OUTPUT", "PPSUB.OUTINV", config, data, view)) { 80 psError(PS_ERR_UNKNOWN, false, "Unable to generate PSF."); 81 return false; 82 } 83 84 // Close convolved files 85 if (!ppSubFilesIterateUp(config, PPSUB_FILES_CONV)) { 86 psError(PPSUB_ERR_IO, false, "Unable to close input files."); 87 return false; 88 } 89 90 if (!ppSubReadoutSubtract("PPSUB.OUTPUT", config, view)) { 91 psError(PS_ERR_UNKNOWN, false, "Unable to subtract images."); 92 return false; 93 } 94 95 // Higher order background subtraction using psphot 96 if (!ppSubBackground("PPSUB.OUTPUT", config, view)) { 97 psError(PS_ERR_UNKNOWN, false, "Unable to subtract background."); 98 return false; 99 } 100 101 if (!data->quality && data->!ppSubReadoutPhotometry("PPSUB.OUTPUT", config, data, view)) { 102 psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry."); 103 return false; 104 } 105 106 if (!ppSubReadoutUpdate("PPSUB.OUTPUT", config, data, view)) { 107 psError(PS_ERR_UNKNOWN, false, "Unable to update."); 108 return false; 109 } 110 111 // Perform statistics on the cell 112 if (statsFile) { 113 pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PPSUB.OUTPUT"); // Output file 114 if (!output) { 115 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find file PPSUB.OUTPUT.\n"); 41 116 goto ERROR; 42 117 } 43 psFree(resolved); 118 psImageMaskType maskValue = pmConfigMaskGet("MASK.VALUE", config); 119 ppStatsFPA(data->stats, output->fpa, view, maskValue, config); 44 120 } 45 121 46 pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PPSUB.INPUT"); 47 if (!input) { 48 psError(PS_ERR_UNEXPECTED_NULL, false, "Can't find input data!\n"); 49 goto ERROR; 50 } 51 52 pmFPAfile *reference = psMetadataLookupPtr(NULL, config->files, "PPSUB.REF"); 53 if (!reference) { 54 psError(PS_ERR_UNEXPECTED_NULL, false, "Can't find reference data!\n"); 55 goto ERROR; 56 } 57 58 pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PPSUB.OUTPUT"); 59 if (!output) { 60 psError(PS_ERR_UNEXPECTED_NULL, false, "Can't find output data!\n"); 61 goto ERROR; 62 } 63 64 pmFPAview *view = pmFPAviewAlloc(0); // Pointer into FPA hierarchy 65 66 // Iterate over the FPA hierarchy 67 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 68 goto ERROR; 69 } 70 71 pmChip *inChip; // Input chip of interest 72 while ((inChip = pmFPAviewNextChip(view, input->fpa, 1)) != NULL) { 73 pmChip *refChip = pmFPAviewThisChip(view, reference->fpa); // Reference chip of interest 74 if ((!inChip->file_exists && refChip->file_exists) || 75 (inChip->file_exists && !refChip->file_exists)) { 76 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "FPA format discrepency between input and reference"); 77 psFree(view); 78 goto ERROR; 122 if (data->inverse) { 123 // Set up inverse subtraction files 124 if (!ppSubFilesIterateDown(config, PPSUB_FILES_INV)) { 125 psError(PPSUB_ERR_IO, false, "Unable to set up inverse files."); 126 return false; 79 127 } 80 128 81 if (!inChip->file_exists) { 82 continue; 129 if (!ppSubReadoutInverse("PPSUB.OUTINV", "PPSUB.OUTPUT", config, view)) { 130 psError(PS_ERR_UNKNOWN, false, "Unable to invert images."); 131 return false; 83 132 } 84 133 85 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 86 goto ERROR; 134 // Close subtraction files and open inverse photometry files 135 if (!ppSubFilesIterateUp(config, PPSUB_FILES_SUB)) { 136 psError(PPSUB_ERR_IO, false, "Unable to close subtraction files."); 137 return false; 87 138 } 88 139 89 pmCell *inCell; // Cell of interest 90 while ((inCell = pmFPAviewNextCell(view, input->fpa, 1)) != NULL) { 91 pmCell *refCell = pmFPAviewThisCell(view, reference->fpa); // Reference cell of interest 92 if ((!inCell->file_exists && refCell->file_exists) || 93 (inCell->file_exists && !refCell->file_exists)) { 94 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 95 "FPA format discrepency between input and reference"); 96 psFree(view); 97 goto ERROR; 98 } 99 if (!inCell->file_exists) { 100 continue; 101 } 102 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 103 goto ERROR; 104 } 105 106 pmReadout *inRO; // Readin of interest 107 while ((inRO = pmFPAviewNextReadout(view, input->fpa, 1))) { 108 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 109 goto ERROR; 110 } 111 pmReadout *refRO = pmFPAviewThisReadout(view, reference->fpa);// Reference readout of interest 112 if (!refRO || (!inRO->data_exists && refRO->data_exists) || 113 (inRO->data_exists && !refRO->data_exists)) { 114 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 115 "FPA format discrepency between input and reference"); 116 psFree(view); 117 goto ERROR; 118 } 119 if (!inRO->data_exists) { 120 continue; 121 } 122 123 // Perform the analysis 124 if (!ppSubReadout(config, data, view)) { 125 psError(PS_ERR_UNKNOWN, false, "Unable to subtract images.\n"); 126 goto ERROR; 127 } 128 129 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 130 goto ERROR; 131 } 132 } 133 134 // Perform statistics on the cell 135 if (statsFile) { 136 pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PPSUB.OUTPUT"); // Output file 137 if (!output) { 138 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find file PPSUB.OUTPUT.\n"); 139 goto ERROR; 140 } 141 psImageMaskType maskValue = pmConfigMaskGet("MASK.VALUE", config); 142 ppStatsFPA(data->stats, output->fpa, view, maskValue, config); 143 } 144 145 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 146 goto ERROR; 147 } 140 if (!data->quality && data->!ppSubReadoutPhotometry("PPSUB.OUTINV", config, data, view)) { 141 psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry."); 142 return false; 148 143 } 149 150 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 151 goto ERROR; 144 } else { 145 // Close subtraction files 146 if (!ppSubFilesIterateUp(config, PPSUB_FILES_SUB)) { 147 psError(PPSUB_ERR_IO, false, "Unable to close subtraction files."); 148 return false; 152 149 } 153 150 } 154 151 155 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 156 goto ERROR; 152 153 if (!ppSubReadoutUpdate("PPSUB.OUTPUT", config, data, view)) { 154 psError(PS_ERR_UNKNOWN, false, "Unable to update."); 155 return false; 157 156 } 158 157 158 159 159 psFree(view); 160 161 // Write out summary statistics162 if (statsFile) {163 psMetadataAddF32(data->stats, PS_LIST_TAIL, "TIME_SUB", 0, "Time for subtraction completion",164 psTimerMark("ppSub"));165 166 const char *statsMDC = psMetadataConfigFormat(data->stats);167 if (!statsMDC || strlen(statsMDC) == 0) {168 psWarning("Unable to generate statistics MDC file.\n");169 } else {170 fprintf(statsFile, "%s", statsMDC);171 }172 psFree((void *)statsMDC);173 fclose(statsFile);174 }175 160 176 161 psString dump_file = psMetadataLookupStr(&mdok, config->arguments, "-dumpconfig"); … … 180 165 } 181 166 182 psFree(data);183 167 return true; 184 168 185 169 ERROR: 186 psFree(data);187 170 return false; 188 171 }
Note:
See TracChangeset
for help on using the changeset viewer.
