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