Changeset 23740 for trunk/ppSub/src/ppSubLoop.c
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/pap merged: 23690,23704,23711,23719,23723,23730-23735
- Property svn:mergeinfo changed
-
trunk/ppSub
- Property svn:mergeinfo changed
/branches/pap/ppSub merged: 23704,23711,23719,23723,23730,23732-23734
- Property svn:mergeinfo changed
-
trunk/ppSub/src
- Property svn:ignore
-
old new 10 10 stamp-h1 11 11 ppSubKernel 12 ppSubErrorCodes.h 13 ppSubErrorCodes.c
-
- Property svn:ignore
-
trunk/ppSub/src/ppSubLoop.c
r23688 r23740 17 17 #include <pslib.h> 18 18 #include <psmodules.h> 19 #include <ppStats.h>20 19 21 20 #include "ppSub.h" 22 21 23 bool ppSubLoop(pmConfig *config )22 bool ppSubLoop(pmConfig *config, ppSubData *data) 24 23 { 25 24 psAssert(config, "Require configuration."); … … 28 27 pmConfigRecipesCull(config, "PPSUB,PPSTATS,PSPHOT,MASKS,JPEG"); 29 28 30 ppSubData *data = ppSubDataAlloc(); // Processing data31 29 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); 41 goto ERROR; 42 } 43 psFree(resolved); 30 pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PPSUB.INPUT"); 31 pmFPAfile *reference = psMetadataLookupPtr(NULL, config->files, "PPSUB.REF"); 32 pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PPSUB.OUTPUT"); 33 psAssert(input && reference && output, "Require files"); 34 35 if (!ppSubFilesIterateDown(config, PPSUB_FILES_INPUT | PPSUB_FILES_CONV)) { 36 psError(PPSUB_ERR_IO, false, "Unable to load files."); 37 return false; 44 38 } 45 39 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; 40 psTimerStart("PPSUB_MATCH"); 41 42 if (!ppSubSetMasks(config)) { 43 psError(PS_ERR_UNKNOWN, false, "Unable to set masks."); 44 return false; 50 45 } 51 46 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; 47 if (!ppSubMatchPSFs(config, data)) { 48 psError(PS_ERR_UNKNOWN, false, "Unable to match PSFs."); 49 return false; 50 } 51 if (data->quality) { 52 // Can't do anything at all 53 return true; 56 54 } 57 55 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; 56 psMetadataAddF32(data->stats, PS_LIST_TAIL, "TIME_MATCH", 0, "Time to match PSFs", 57 psTimerClear("PPSUB_MATCH")); 58 59 // Close input files 60 if (!ppSubFilesIterateUp(config, PPSUB_FILES_INPUT)) { 61 psError(PPSUB_ERR_IO, false, "Unable to close input files."); 62 return false; 62 63 } 63 64 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; 65 // Set up subtraction files 66 if (!ppSubFilesIterateDown(config, PPSUB_FILES_SUB)) { 67 psError(PPSUB_ERR_IO, false, "Unable to set up subtraction files."); 68 return false; 69 69 } 70 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; 71 if (!ppSubDefineOutput("PPSUB.OUTPUT", config)) { 72 psError(PS_ERR_UNKNOWN, false, "Unable to define output."); 73 return false; 74 } 75 76 if (!data->quality && !ppSubMakePSF(config, data)) { 77 psError(PS_ERR_UNKNOWN, false, "Unable to generate PSF."); 78 return false; 79 } 80 81 if (!ppSubReadoutSubtract(config)) { 82 psError(PS_ERR_UNKNOWN, false, "Unable to subtract images."); 83 return false; 84 } 85 86 // Close convolved files 87 if (!ppSubFilesIterateUp(config, PPSUB_FILES_PSF | PPSUB_FILES_CONV)) { 88 psError(PPSUB_ERR_IO, false, "Unable to close input files."); 89 return false; 90 } 91 92 // Higher order background subtraction using psphot 93 if (!ppSubBackground(config)) { 94 psError(PS_ERR_UNKNOWN, false, "Unable to subtract background."); 95 return false; 96 } 97 98 if (!ppSubFilesIterateDown(config, PPSUB_FILES_PHOT_SUB)) { 99 psError(PPSUB_ERR_IO, false, "Unable to set up photometry files."); 100 return false; 101 } 102 103 if (!data->quality && !ppSubReadoutPhotometry("PPSUB.OUTPUT", config, data)) { 104 psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry."); 105 return false; 106 } 107 108 if (!ppSubFilesIterateUp(config, PPSUB_FILES_PHOT_SUB)) { 109 psError(PPSUB_ERR_IO, false, "Unable to set up photometry files."); 110 return false; 111 } 112 113 // Perform statistics on the cell 114 if (!ppSubReadoutStats(config, data)) { 115 psError(PS_ERR_UNKNOWN, false, "Unable to collect statistics"); 116 return false; 117 } 118 119 if (!ppSubReadoutJpeg(config)) { 120 psError(PS_ERR_UNKNOWN, false, "Unable to update."); 121 return false; 122 } 123 124 if (data->inverse) { 125 // Set up inverse subtraction files 126 if (!ppSubFilesIterateDown(config, PPSUB_FILES_INV)) { 127 psError(PPSUB_ERR_IO, false, "Unable to set up inverse files."); 128 return false; 79 129 } 80 130 81 if (!inChip->file_exists) { 82 continue; 131 if (data->inverse && !ppSubDefineOutput("PPSUB.INVERSE", config)) { 132 psError(PS_ERR_UNKNOWN, false, "Unable to define inverse."); 133 return false; 83 134 } 84 135 85 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 86 goto ERROR; 136 if (!ppSubReadoutInverse(config)) { 137 psError(PS_ERR_UNKNOWN, false, "Unable to invert images."); 138 return false; 87 139 } 88 140 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 } 141 // Close subtraction files and open inverse photometry files 142 if (!ppSubFilesIterateUp(config, PPSUB_FILES_SUB)) { 143 psError(PPSUB_ERR_IO, false, "Unable to close subtraction files."); 144 return false; 148 145 } 149 146 150 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 151 goto ERROR; 147 if (!ppSubFilesIterateDown(config, PPSUB_FILES_PHOT_INV)) { 148 psError(PPSUB_ERR_IO, false, "Unable to set up inverse files."); 149 return false; 150 } 151 152 if (!data->quality && !ppSubReadoutPhotometry("PPSUB.INVERSE", config, data)) { 153 psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry."); 154 return false; 155 } 156 157 // Close inverse subtraction files 158 if (!ppSubFilesIterateUp(config, PPSUB_FILES_INV | PPSUB_FILES_PHOT_INV)) { 159 psError(PPSUB_ERR_IO, false, "Unable to close subtraction files."); 160 return false; 161 } 162 } else { 163 // Close subtraction files 164 if (!ppSubFilesIterateUp(config, PPSUB_FILES_SUB)) { 165 psError(PPSUB_ERR_IO, false, "Unable to close subtraction files."); 166 return false; 152 167 } 153 168 } 154 169 155 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 156 goto ERROR; 157 } 158 159 psFree(view); 160 161 // Write out summary statistics 162 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 176 psString dump_file = psMetadataLookupStr(&mdok, config->arguments, "-dumpconfig"); 170 psString dump_file = psMetadataLookupStr(NULL, config->arguments, "-dumpconfig"); 177 171 if (dump_file) { 178 172 pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PPSUB.INPUT"); // Input file … … 180 174 } 181 175 182 psFree(data);183 176 return true; 184 185 ERROR:186 psFree(data);187 return false;188 177 }
Note:
See TracChangeset
for help on using the changeset viewer.
