Changeset 23298
- Timestamp:
- Mar 12, 2009, 12:16:20 PM (17 years ago)
- Location:
- trunk/ppSub/src
- Files:
-
- 2 edited
-
ppSubArguments.c (modified) (5 diffs)
-
ppSubCamera.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppSub/src/ppSubArguments.c
r23242 r23298 29 29 { 30 30 fprintf(stderr, "\nPan-STARRS PSF-matched image subtraction\n\n"); 31 fprintf(stderr, "Usage: %s INPUT.fits REFERENCE.fitsOUTPUT_ROOT \n"31 fprintf(stderr, "Usage: %s OUTPUT_ROOT \n" 32 32 "\t[-psf REFERENCE.psf.fits]\n\n" 33 33 "This subtracts the convolved REFERENCE from the INPUT, by default.\n", … … 202 202 203 203 psMetadata *arguments = config->arguments; // Command-line arguments 204 psMetadataAddStr(arguments, PS_LIST_TAIL, "-inimage", 0, "Input image", NULL); 204 205 psMetadataAddStr(arguments, PS_LIST_TAIL, "-inmask", 0, "Input mask image", NULL); 205 206 psMetadataAddStr(arguments, PS_LIST_TAIL, "-invariance", 0, "Input variance image", NULL); 206 207 psMetadataAddStr(arguments, PS_LIST_TAIL, "-insources", 0, "Input source list", NULL); 208 psMetadataAddStr(arguments, PS_LIST_TAIL, "-refimage", 0, "Reference image", NULL); 207 209 psMetadataAddStr(arguments, PS_LIST_TAIL, "-refmask", 0, "Reference mask image", NULL); 208 210 psMetadataAddStr(arguments, PS_LIST_TAIL, "-refvariance", 0, "Reference variance image", NULL); 209 211 psMetadataAddStr(arguments, PS_LIST_TAIL, "-refsources", 0, "Reference source list", NULL); 212 psMetadataAddStr(arguments, PS_LIST_TAIL, "-kernel", 0, "Precalculated kernel to apply", NULL); 210 213 psMetadataAddStr(arguments, PS_LIST_TAIL, "-stats", 0, "Statistics file", NULL); 211 214 psMetadataAddF32(arguments, PS_LIST_TAIL, "-region", 0, "Size of iso-kernel region", NAN); … … 253 256 psMetadataAddBool(arguments, PS_LIST_TAIL, "-visual", 0, "Show diagnostic plots", NULL); 254 257 255 if (argc == 1 || !psArgumentParse(arguments, &argc, argv) || argc != 4) {258 if (argc == 1 || !psArgumentParse(arguments, &argc, argv) || argc != 2) { 256 259 usage(argv[0], arguments, config); 257 260 } 258 261 259 fileList("INPUT", argv[1], "Name of the input image", config);260 fileList("REF", argv[2], "Name of the reference image", config);261 262 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "Name of the output image", argv[3]); 262 263 264 265 const char *inImage = psMetadataLookupStr(NULL, arguments, "-inimage"); // Name of input image 266 if (inImage && strlen(inImage) > 0) { 267 fileList("INPUT", inImage, "Name of the input image", config); 268 } 263 269 const char *inMask = psMetadataLookupStr(NULL, arguments, "-inmask"); // Name of input mask 264 270 if (inMask && strlen(inMask) > 0) { … … 274 280 } 275 281 282 const char *refImage = psMetadataLookupStr(NULL, arguments, "-refimage"); // Name of reference image 283 if (refImage && strlen(refImage) > 0) { 284 fileList("INPUT", refImage, "Name of the reference image", config); 285 } 276 286 const char *refMask = psMetadataLookupStr(NULL, arguments, "-refmask"); // Name of reference mask 277 287 if (refMask && strlen(refMask) > 0) { … … 285 295 if (refSources && strlen(refSources) > 0) { 286 296 fileList("REF.SOURCES", refSources, "Name of the reference source list", config); 297 } 298 299 const char *kernel = psMetadataLookupStr(NULL, arguments, "-kernel"); // Name of kernel 300 if (kernel && strlen(kernel) > 0) { 301 fileList("KERNEL", kernel, "Name of the kernel to apply", config); 287 302 } 288 303 -
trunk/ppSub/src/ppSubCamera.c
r23235 r23298 22 22 #include "ppSub.h" 23 23 24 // Define an input file 25 static pmFPAfile *defineInputFile(pmConfig *config,// Configuration 26 pmFPAfile *bind, // File to which to bind, or NULL 27 char *filerule, // Name of file rule 28 char *argname, // Argument name 29 pmFPAfileType fileType // Type of file 30 ) 31 { 32 bool status; 33 34 // look for the file on the RUN metadata 35 pmFPAfile *file = pmFPAfileDefineFromRun(&status, config, filerule); // File to return 36 if (!status) { 37 psError(PS_ERR_UNKNOWN, false, "Failed to load file definition for %s", filerule); 38 return NULL; 39 } 40 if (!file) { 41 // look for the file on the argument list 42 if (bind) { 43 file = pmFPAfileBindFromArgs(&status, bind, config, filerule, argname); 44 } else { 45 file = pmFPAfileDefineFromArgs(&status, config, filerule, argname); 46 } 47 if (!status) { 48 psError(PS_ERR_UNKNOWN, false, "Failed to load file definition for %s", filerule); 49 return false; 50 } 51 } 52 53 if (!file) { 54 return NULL; 55 } 56 57 if (file->type != fileType) { 58 psError(PS_ERR_UNKNOWN, true, "%s is not of type %s", filerule, pmFPAfileStringFromType(fileType)); 59 return NULL; 60 } 61 62 return file; 63 } 64 65 // Define an output file 66 static pmFPAfile *defineOutputFile(pmConfig *config, // Configuration 67 pmFPAfile *template, // File to use as basis for definition 68 char *filerule, // Name of file rule 69 pmFPAfileType fileType // Type of file 70 ) 71 { 72 73 pmFPAfile *file = pmFPAfileDefineFromFile(config, template, 1, 1, filerule); 74 if (!file) { 75 psError(PS_ERR_IO, false, _("Unable to generate output file from %s"), filerule); 76 return NULL; 77 } 78 if (file->type != fileType) { 79 psError(PS_ERR_IO, true, "%s is not of type %s", filerule, pmFPAfileStringFromType(fileType)); 80 return NULL; 81 } 82 83 return file; 84 } 85 86 87 // Define an output file that will be used in a calculation 88 // This means it might already be available in the RUN metadata 89 static pmFPAfile *defineCalcFile(pmConfig *config, // Configuration 90 pmFPAfile *bind, // File to which to bind, or NULL 91 char *filerule, // Name of file rule 92 pmFPAfileType fileType // Type of file 93 ) 94 { 95 bool status; 96 97 // look for the file on the RUN metadata 98 pmFPAfile *file = pmFPAfileDefineFromRun(&status, config, filerule); // File to return 99 if (!status) { 100 psError(PS_ERR_UNKNOWN, false, "Failed to load file definition for %s", filerule); 101 return NULL; 102 } 103 if (file) { 104 // It's an input 105 file->save = false; 106 } 107 108 // define new version of file 109 if (!file) { 110 pmFPAfileDefineOutput(config, bind ? bind->fpa : NULL, filerule); 111 if (!status) { 112 psError(PS_ERR_UNKNOWN, false, "Failed to load file definition for %s", filerule); 113 return false; 114 } 115 if (file) { 116 // It's an output 117 file->save = true; 118 } 119 } 120 121 if (!file) { 122 return NULL; 123 } 124 125 if (file->type != fileType) { 126 psError(PS_ERR_UNKNOWN, true, "%s is not of type %s", filerule, pmFPAfileStringFromType(fileType)); 127 return NULL; 128 } 129 130 return file; 131 } 132 133 24 134 bool ppSubCamera(pmConfig *config) 25 135 { 26 bool status = false; // result from pmFPAfileDefine operations136 psAssert(config, "Require configuration"); 27 137 28 138 // Input image 29 pmFPAfile *input = pmFPAfileDefineFromArgs(&status, config, "PPSUB.INPUT", "INPUT");30 if (! status || !input) {139 pmFPAfile *input = defineInputFile(config, NULL, "PPSUB.INPUT", "INPUT", PM_FPA_FILE_IMAGE); 140 if (!input) { 31 141 psError(PS_ERR_IO, false, "Failed to build FPA from PPSUB.INPUT"); 32 142 return false; 33 143 } 34 if (input->type != PM_FPA_FILE_IMAGE) { 35 psError(PS_ERR_IO, true, "PPSUB.INPUT is not of type IMAGE"); 36 return false; 37 } 38 39 // Input mask 40 pmFPAfile *inputMask = pmFPAfileBindFromArgs(&status, input, config, "PPSUB.INPUT.MASK", "INPUT.MASK"); 41 if (!status) { 42 psError(PS_ERR_UNKNOWN, false, "Failed to load file definition PPSUB.INPUT.MASK"); 43 return NULL; 44 } 45 if (inputMask && inputMask->type != PM_FPA_FILE_MASK) { 46 psError(PS_ERR_IO, true, "PPSUB.INPUT.MASK is not of type MASK"); 47 return false; 48 } 49 50 // Input variance map 51 pmFPAfile *inputVariance = pmFPAfileBindFromArgs(&status, input, config, "PPSUB.INPUT.VARIANCE", "INPUT.VARIANCE"); 52 if (!status) { 53 psError(PS_ERR_UNKNOWN, false, "Failed to load file definition PPSUB.INPUT.VARIANCE"); 54 return NULL; 55 } 56 if (inputVariance && inputVariance->type != PM_FPA_FILE_VARIANCE) { 57 psError(PS_ERR_IO, true, "PPSUB.INPUT.VARIANCE is not of type VARIANCE"); 58 return false; 59 } 60 61 // Input source list 62 pmFPAfile *inputSources = pmFPAfileBindFromArgs(&status, input, config, "PPSUB.INPUT.SOURCES", "INPUT.SOURCES"); 63 if (!status) { 64 psError(PS_ERR_UNKNOWN, false, "Failed to load file definition PPSUB.INPUT.SOURCES"); 65 return NULL; 66 } 67 if (inputSources && inputSources->type != PM_FPA_FILE_CMF) { 68 psError(PS_ERR_IO, true, "PPSUB.INPUT.SOURCES is not of type CMF"); 69 return false; 70 } 144 defineInputFile(config, input, "PPSUB.INPUT.MASK", "INPUT.MASK", PM_FPA_FILE_MASK); 145 pmFPAfile *inVar = defineInputFile(config, input, "PPSUB.INPUT.VARIANCE", "INPUT.VARIANCE", 146 PM_FPA_FILE_VARIANCE); 147 defineInputFile(config, input, "PPSUB.INPUT.SOURCES", "INPUT.SOURCES", PM_FPA_FILE_CMF); 71 148 72 149 // Reference image 73 status = false; 74 pmFPAfile *ref = pmFPAfileDefineFromArgs(&status, config, "PPSUB.REF", "REF"); 150 pmFPAfile *ref = defineInputFile(config, NULL, "PPSUB.REF", "REF", PM_FPA_FILE_IMAGE); 75 151 if (!ref) { 76 152 psError(PS_ERR_IO, false, "Failed to build FPA from PPSUB.REF"); 77 153 return false; 78 154 } 79 if (ref->type != PM_FPA_FILE_IMAGE) { 80 psError(PS_ERR_IO, true, "PPSUB.REF is not of type IMAGE"); 81 return false; 82 } 83 84 // Reference mask 85 pmFPAfile *refMask = pmFPAfileBindFromArgs(&status, ref, config, "PPSUB.REF.MASK", "REF.MASK"); 86 if (!status) { 87 psError(PS_ERR_UNKNOWN, false, "Failed to load file definition PPSUB.REF.MASK"); 88 return NULL; 89 } 90 if (refMask && refMask->type != PM_FPA_FILE_MASK) { 91 psError(PS_ERR_IO, true, "PPSUB.REF.MASK is not of type MASK"); 92 return false; 93 } 94 95 // Reference variance map 96 pmFPAfile *refVariance = pmFPAfileBindFromArgs(&status, ref, config, "PPSUB.REF.VARIANCE", "REF.VARIANCE"); 97 if (!status) { 98 psError(PS_ERR_UNKNOWN, false, "Failed to load file definition PPSUB.REF.VARIANCE"); 99 return NULL; 100 } 101 if (refVariance && refVariance->type != PM_FPA_FILE_VARIANCE) { 102 psError(PS_ERR_IO, true, "PPSUB.REF.VARIANCE is not of type VARIANCE"); 103 return false; 104 } 105 106 // Reference source list 107 pmFPAfile *refSources = pmFPAfileBindFromArgs(&status, ref, config, "PPSUB.REF.SOURCES", "REF.SOURCES"); 108 if (!status) { 109 psError(PS_ERR_UNKNOWN, false, "Failed to load file definition PPSUB.REF.SOURCES"); 110 return NULL; 111 } 112 if (refSources && refSources->type != PM_FPA_FILE_CMF) { 113 psError(PS_ERR_IO, true, "PPSUB.REF.SOURCES is not of type CMF"); 114 return false; 115 } 155 defineInputFile(config, ref, "PPSUB.REF.MASK", "REF.MASK", PM_FPA_FILE_MASK); 156 pmFPAfile *refVar = defineInputFile(config, ref, "PPSUB.REF.VARIANCE", "REF.VARIANCE", 157 PM_FPA_FILE_VARIANCE); 158 defineInputFile(config, ref, "PPSUB.REF.SOURCES", "REF.SOURCES", PM_FPA_FILE_CMF); 159 116 160 117 161 // Output image 118 pmFPAfile *output = pmFPAfileDefineFromFile(config, input, 1, 1, "PPSUB.OUTPUT"); 119 if (!output) { 120 psError(PS_ERR_IO, false, _("Unable to generate output file from PPSUB.OUTPUT")); 121 return false; 122 } 123 if (output->type != PM_FPA_FILE_IMAGE) { 124 psError(PS_ERR_IO, true, "PPSUB.OUTPUT is not of type IMAGE"); 162 pmFPAfile *output = defineOutputFile(config, input, "PPSUB.OUTPUT", PM_FPA_FILE_IMAGE); 163 pmFPAfile *outMask = defineOutputFile(config, output, "PPSUB.OUTPUT.MASK", PM_FPA_FILE_MASK); 164 if (!output || !outMask) { 165 psError(PS_ERR_UNKNOWN, false, "Unable to define output files"); 125 166 return false; 126 167 } 127 168 output->save = true; 128 129 // Output mask130 pmFPAfile *outMask = pmFPAfileDefineOutput(config, output->fpa, "PPSUB.OUTPUT.MASK");131 if (!outMask) {132 psError(PS_ERR_IO, false, _("Unable to generate output file from PPSUB.OUTPUT.MASK"));133 return false;134 }135 if (outMask->type != PM_FPA_FILE_MASK) {136 psError(PS_ERR_IO, true, "PPSUB.OUTPUT.MASK is not of type MASK");137 return false;138 }139 169 outMask->save = true; 140 141 // Output variance 142 if (inputVariance && refVariance) { 143 pmFPAfile *outVariance = pmFPAfileDefineOutput(config, output->fpa, "PPSUB.OUTPUT.VARIANCE"); 144 if (!outVariance) { 145 psError(PS_ERR_IO, false, _("Unable to generate output file from PPSUB.OUTPUT.VARIANCE")); 146 return false; 147 } 148 if (outVariance->type != PM_FPA_FILE_VARIANCE) { 149 psError(PS_ERR_IO, true, "PPSUB.OUTPUT.VARIANCE is not of type VARIANCE"); 150 return false; 151 } 152 outVariance->save = true; 153 } 170 pmFPAfile *outVar = NULL; 171 if (inVar && refVar) { 172 outVar = defineOutputFile(config, output, "PPSUB.OUTPUT.VARIANCE", PM_FPA_FILE_VARIANCE); 173 if (!outVar) { 174 psError(PS_ERR_UNKNOWN, false, "Unable to define output files"); 175 return false; 176 } 177 outVar->save = true; 178 } 179 154 180 155 181 // Convolved input image 156 pmFPAfile *inConv = pmFPAfileDefineFromFile(config, input, 1, 1, "PPSUB.INPUT.CONV"); 157 if (!inConv) { 158 psError(PS_ERR_IO, false, _("Unable to generate output file for PPSUB.INPUT.CONV")); 159 return false; 160 } 161 if (output->type != PM_FPA_FILE_IMAGE) { 162 psError(PS_ERR_IO, true, "PPSUB.INPUT.CONV is not of type IMAGE"); 163 return false; 164 } 165 // XXX should be based on recipe : inConv->save = true; 166 167 // Convolved input mask 168 pmFPAfile *inConvMask = pmFPAfileDefineOutput(config, inConv->fpa, "PPSUB.INPUT.CONV.MASK"); 169 if (!inConvMask) { 170 psError(PS_ERR_IO, false, _("Unable to generate output file from PPSUB.INPUT.CONV.MASK")); 171 return false; 172 } 173 if (inConvMask->type != PM_FPA_FILE_MASK) { 174 psError(PS_ERR_IO, true, "PPSUB.INPUT.CONV.MASK is not of type MASK"); 175 return false; 176 } 177 // XXX should be based on recipe : inConvMask->save = true; 178 179 // Convolved input variance 180 if (inputVariance) { 181 pmFPAfile *inConvVariance = pmFPAfileDefineOutput(config, inConv->fpa, "PPSUB.INPUT.CONV.VARIANCE"); 182 if (!inConvVariance) { 183 psError(PS_ERR_IO, false, _("Unable to generate output file from PPSUB.OUTPUT.VARIANCE")); 184 return false; 185 } 186 if (inConvVariance->type != PM_FPA_FILE_VARIANCE) { 187 psError(PS_ERR_IO, true, "PPSUB.INPUT.CONV.VARIANCE is not of type VARIANCE"); 188 return false; 189 } 190 // XXX should be based on recipe : inConvVariance->save = true; 182 defineOutputFile(config, input, "PPSUB.INPUT.CONV", PM_FPA_FILE_IMAGE); 183 defineOutputFile(config, input, "PPSUB.INPUT.CONV.MASK", PM_FPA_FILE_MASK); 184 if (inVar) { 185 defineOutputFile(config, input, "PPSUB.INPUT.CONV.VARIANCE", PM_FPA_FILE_VARIANCE); 191 186 } 192 187 193 188 // Convolved ref image 194 pmFPAfile *refConv = pmFPAfileDefineFromFile(config, ref, 1, 1, "PPSUB.REF.CONV"); 195 if (!refConv) { 196 psError(PS_ERR_IO, false, _("Unable to generate output file for PPSUB.REF.CONV")); 197 return false; 198 } 199 if (output->type != PM_FPA_FILE_IMAGE) { 200 psError(PS_ERR_IO, true, "PPSUB.REF.CONV is not of type IMAGE"); 201 return false; 202 } 203 // XXX should be based on recipe : refConv->save = true; 204 205 // Convolved ref mask 206 pmFPAfile *refConvMask = pmFPAfileDefineOutput(config, refConv->fpa, "PPSUB.REF.CONV.MASK"); 207 if (!refConvMask) { 208 psError(PS_ERR_IO, false, _("Unable to generate output file from PPSUB.REF.CONV.MASK")); 209 return false; 210 } 211 if (refConvMask->type != PM_FPA_FILE_MASK) { 212 psError(PS_ERR_IO, true, "PPSUB.REF.CONV.MASK is not of type MASK"); 213 return false; 214 } 215 // XXX should be based on recipe : refConvMask->save = true; 216 217 // Convolved ref variance 218 if (refVariance) { 219 pmFPAfile *refConvVariance = pmFPAfileDefineOutput(config, refConv->fpa, "PPSUB.REF.CONV.VARIANCE"); 220 if (!refConvVariance) { 221 psError(PS_ERR_IO, false, _("Unable to generate output file from PPSUB.OUTPUT.VARIANCE")); 222 return false; 223 } 224 if (refConvVariance->type != PM_FPA_FILE_VARIANCE) { 225 psError(PS_ERR_IO, true, "PPSUB.REF.CONV.VARIANCE is not of type VARIANCE"); 226 return false; 227 } 228 // XXX should be based on recipe : refConvVariance->save = true; 229 } 189 defineOutputFile(config, input, "PPSUB.REF.CONV", PM_FPA_FILE_IMAGE); 190 defineOutputFile(config, input, "PPSUB.REF.CONV.MASK", PM_FPA_FILE_MASK); 191 if (refVar) { 192 defineOutputFile(config, input, "PPSUB.REF.CONV.VARIANCE", PM_FPA_FILE_VARIANCE); 193 } 194 230 195 231 196 // Output JPEGs … … 252 217 253 218 // Output subtraction kernel 254 pmFPAfile *outKernels = pmFPAfileDefineOutput(config, output->fpa, "PPSUB.OUTPUT.KERNELS"); 255 if (!outKernels) { 256 psError(PS_ERR_IO, false, _("Unable to generate output file from PPSUB.OUTPUT.KERNELS")); 257 return false; 258 } 259 if (outKernels->type != PM_FPA_FILE_SUBKERNEL) { 260 psError(PS_ERR_IO, true, "PPSUB.OUTPUT.KERNELS is not of type SUBKERNEL"); 261 return false; 262 } 263 outKernels->save = true; 219 pmFPAfile *kernel = defineCalcFile(config, output, "PPSUB.OUTPUT.KERNELS", PM_FPA_FILE_SUBKERNEL); 264 220 265 221
Note:
See TracChangeset
for help on using the changeset viewer.
