Changeset 42183 for branches/eam_branches/ipp-20220316
- Timestamp:
- Apr 28, 2022, 4:13:55 PM (4 years ago)
- Location:
- branches/eam_branches/ipp-20220316/fpcamera/src
- Files:
-
- 1 added
- 8 edited
-
Makefile.am (modified) (1 diff)
-
fpcamera.c (modified) (1 diff)
-
fpcamera.h (modified) (1 diff)
-
fpcameraAnalysis.c (modified) (3 diffs)
-
fpcameraArguments.c (modified) (2 diffs)
-
fpcameraChooseRefstars.c (added)
-
fpcameraDataSave.c (modified) (1 diff)
-
fpcameraLoadRefstars.c (modified) (9 diffs)
-
fpcameraParseCamera.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20220316/fpcamera/src/Makefile.am
r42178 r42183 18 18 fpcameraReadAstrometry.c \ 19 19 fpcameraLoadRefstars.c \ 20 fpcameraChooseRefstars.c \ 20 21 fpcameraCleanup.c 21 22 -
branches/eam_branches/ipp-20220316/fpcamera/src/fpcamera.c
r42182 r42183 18 18 fprintf (stderr, "USAGE: one of the following:\n\n"); 19 19 fprintf (stderr, " fpcamera -file filename[,filename,...] -mask maskfile[,maskfile,...] -variance varfile[,varfile,...] -astrom-file (smffile) OutFileBaseName\n"); 20 fprintf (stderr, " fpcamera -list filelist -masklist masklist -varlist varlist -astrom-file (smffile) - ref (dvopath) -OutFileBaseName\n\n");20 fprintf (stderr, " fpcamera -list filelist -masklist masklist -varlist varlist -astrom-file (smffile) -OutFileBaseName\n\n"); 21 21 fprintf (stderr, "where:\n"); 22 22 fprintf (stderr, " FileNameList is a text file containing filenames, one per line\n"); -
branches/eam_branches/ipp-20220316/fpcamera/src/fpcamera.h
r42178 r42183 49 49 bool fpcameraLoadRefstars (pmFPAfile *input, pmConfig *config); 50 50 bool fpcameraReadAstrometry (pmFPAfile *input, pmConfig *config); 51 bool fpcameraChooseRefstars (pmFPAfile *input, pmFPAfile *astrom, pmFPAview *view); 51 52 52 53 // Return version strings. -
branches/eam_branches/ipp-20220316/fpcamera/src/fpcameraAnalysis.c
r42178 r42183 1 1 # include "fpcamera.h" 2 2 3 # define ESCAPE(ERROR, MSG) { psErrorStackPrint(stderr, MSG); return false; }3 # define ESCAPE(ERROR, MSG) { psErrorStackPrint(stderr, MSG); psFree (view); return false; } 4 4 5 5 /* \brief this function loops over chips and performs forced photometry for the references */ … … 7 7 8 8 bool status; 9 pmChip *chip; 10 pmCell *cell; 11 pmReadout *readout; 12 pmFPAview *view = NULL; 9 13 10 14 // measure the total elapsed time in fpcameraAnalysis. … … 15 19 if (!recipe) ESCAPE (FPCAMERA_ERR_CONFIG, "Can't find FPCAMERA recipe"); 16 20 17 psLogMsg("fpcamera", 3, "TIMEMARK: fpcameraMosaicAstrom: %f sec\n", psTimerMark ("complete")); 21 // loop over the input images 22 pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "FPCAMERA.INPUT"); 23 if (!input) ESCAPE(FPCAMERA_ERR_CONFIG, "Can't find or interpret output file rule FPCAMERA.INPUT!"); 24 25 // astrometry reference (smf) 26 pmFPAfile *astrom = psMetadataLookupPtr (NULL, config->files, "FPCAMERA.INPUT.ASTROM"); 27 if (!astrom) ESCAPE(FPCAMERA_ERR_CONFIG, "Can't find or interpret output file rule FPCAMERA.INPUT.ASTROM!"); 28 29 // only activate input image-type files 30 pmFPAfileActivate (config->files, false, NULL); 31 pmFPAfileActivate (config->files, true, "FPCAMERA.INPUT"); 32 pmFPAfileActivate (config->files, true, "FPCAMERA.INPUT.MASK"); 33 pmFPAfileActivate (config->files, true, "FPCAMERA.INPUT.VARIANCE"); 34 pmFPAfileActivate (config->files, true, "FPCAMERA.RESID"); 35 // Note FPCAMERA.RESID is tied to FPCAMERA.INPUT so they must be active in the same block. 36 37 view = pmFPAviewAlloc (0); 38 39 // load images at FPA level (if appropriate) 40 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE(FPCAMERA_ERR_DATA, "failed to load images at FPA level"); 41 42 // load images at chip level (if appropriate) 43 while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) { 44 psTrace ("fpcamera", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 45 if (!chip->process || !chip->file_exists) { continue; } 46 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE(FPCAMERA_ERR_DATA, "failed to load images at Chip level"); 47 48 // loop over all cells in chip 49 while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) { 50 psLogMsg ("fpcamera", 5, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 51 if (!cell->process || !cell->file_exists) { continue; } 52 53 // loop over all readouts in cell 54 while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) { 55 psLogMsg ("fpcamera", 6, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 56 if (!readout->data_exists) { continue; } 57 58 fpcameraChooseRefstars (input, astrom, view); 59 } 60 } 61 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE(FPCAMERA_ERR_IO, "failure in IOChecks(AFTER) at Chip"); 62 } 63 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE(FPCAMERA_ERR_IO, "failure in IOChecks(AFTER) at FPA"); 64 65 psFree (view); 66 67 psLogMsg("fpcamera", 3, "TIMEMARK: fpcameraAnalysis: %f sec\n", psTimerMark ("analysis")); 18 68 return true; 19 69 } 70 71 // NOTES 72 // chip->process is set (unset) based on command-line -chip selections (in fpcameraArguments) 73 // chip->file_exists is set (in pmFPAFlags.c:pmChipSetFileStatus) by pmFPAfileDefineFromArgs (in pmFPAAddSource...) -
branches/eam_branches/ipp-20220316/fpcamera/src/fpcameraArguments.c
r42182 r42183 50 50 } 51 51 52 // chip selection is used to limit chips to be processed 53 if ((N = psArgumentGet (argc, argv, "-save-resid"))) { 54 psArgumentRemove (N, &argc, argv); 55 psMetadataAddBool (config->arguments, PS_LIST_TAIL, "SAVE.RESID", PS_META_REPLACE, "", true); 56 } 57 52 58 // specify the input images to process 53 59 status = pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list"); … … 61 67 status = pmConfigFileSetsMD (config->arguments, &argc, argv, "VARIANCE", "-variance", "-varlist"); 62 68 if (!status) ESCAPE(FPCAMERA_ERR_ARGUMENTS, "Missing -variance (input) or -varlist (input)"); 63 64 // specify the reference data source (DVO format or ??)65 // N = psArgumentGet (argc, argv, "-ref");66 // if (!N) ESCAPE (FPCAMERA_ERR_ARGUMENTS, "Missing -ref (database)");67 // psArgumentRemove (N, &argc, argv);68 // psMetadataAddStr (config->arguments, PS_LIST_TAIL, "FPCAMERA.CATDIR", PS_META_REPLACE, "", argv[N]);69 // psArgumentRemove (N, &argc, argv);70 69 71 70 // specify the astrometry calibration -
branches/eam_branches/ipp-20220316/fpcamera/src/fpcameraDataSave.c
r42182 r42183 24 24 pmFPAfileActivate (config->files, true, "FPCAMERA.OUTPUT"); 25 25 pmFPAfileActivate (config->files, true, "FPCAMERA.INPUT.ASTROM"); 26 // Note: I/O for the image-type files is performed in fpcameraAnalysis 26 27 27 28 view = pmFPAviewAlloc (0); -
branches/eam_branches/ipp-20220316/fpcamera/src/fpcameraLoadRefstars.c
r42182 r42183 1 1 # include "fpcamera.h" 2 # define ELIXIR_MODE 13 2 4 3 # define ESCAPE(ERROR,...) { p_psError(__FILE__,__LINE__,__func__,ERROR,false,__VA_ARGS__); return false; } … … 37 36 DECmax += dDEC * fieldPadding; 38 37 39 // XXX: fpcameraArguments.c looks for this explicitly on the command line, but stores it in arguments.40 // this could be a recipe value which can also be defined as a command-line option41 42 38 // grab the FPCAMERA.CATDIR name from the FPCAMERA recipe 43 39 char *catdir_recipe = psMetadataLookupStr(&status, recipe, "FPCAMERA.CATDIR"); 44 40 if (!catdir_recipe) ESCAPE(FPCAMERA_ERR_CONFIG, "Need a recipe for the catdir!"); 45 41 46 // substitute abstract name with concrete name, if present in FPCAMERA.CATDIRS 47 psMetadata *catdirs = psMetadataLookupMetadata(&status, config->site, "FPCAMERA.CATDIRS"); // List of cameras 48 49 // XXX it is allowed that FPCAMERA.CATDIRS is not defined in site.config: the value must be a real path 50 // if (!catdirs) ESCAPE(FPCAMERA_ERR_CONFIG, "Unable to find FPCAMERA.CATDIRS in the system configuration.\n"); 42 // *** substitute abstract name with concrete name, if present in FPCAMERA.CATDIRS *** 51 43 52 44 // the name in the recipe may be one of: … … 54 46 // (B) a reference to the name in the FPCAMERA.CATDIRS folder in site.config 55 47 // (C) a reference to a folder in the FPCAMERA.CATDIRS folder in site.config, containing multiple copy locations 48 49 // Folder in site.config containing a list of FPCAMERA.CATDIR entries. 50 // NOTE: it is allowed that FPCAMERA.CATDIRS not be defined in site.config: then FPCAMERA.CATDIR must be a real path 51 psMetadata *catdirs = psMetadataLookupMetadata(&status, config->site, "FPCAMERA.CATDIRS"); // List of cameras 56 52 57 53 // can we find a plain string matching catdir_recipe in the catdirs folder? … … 106 102 // supply a known output format (for CATALOG output) so the code below knows what to read 107 103 // XXX I do not think this affects the getstar command (CATFORMAT is used to define the dvo db format) 108 if (ELIXIR_MODE) {109 psStringAppend (&getstarCommand, " -D CATMODE mef -D CATFORMAT elixir");110 } else {111 psStringAppend (&getstarCommand, " -D CATMODE mef -D CATFORMAT panstarrs");112 }104 // if (ELIXIR_MODE) { 105 // psStringAppend (&getstarCommand, " -D CATMODE mef -D CATFORMAT elixir"); 106 // } else { 107 // psStringAppend (&getstarCommand, " -D CATMODE mef -D CATFORMAT panstarrs"); 108 // } 113 109 114 // check for default name (use .ptolemyrc), or use specified CATDIR 115 if (strcasecmp(CATDIR, "NONE")) { 116 psStringAppend (&getstarCommand, " -D CATDIR %s", CATDIR); 117 } 110 // Define the full getstar command. Above, we require CATDIR to be valid and defined at 111 // this point. Also add region and output filename. 112 psStringAppend (&getstarCommand, " -D CATDIR %s", CATDIR); 113 psStringAppend (&getstarCommand, " -format %s", outformat); 114 psStringAppend (&getstarCommand, " -region %f %f %f %f -o %s", RAmin, DECmin, RAmax, DECmax, tempFile); 115 118 116 psFree(CATDIR); 119 120 psStringAppend (&getstarCommand, " -format %s", outformat);121 122 // add region and output filename123 psStringAppend (&getstarCommand, " -region %f %f %f %f -o %s", RAmin, DECmin, RAmax, DECmax, tempFile);124 psTrace ("fpcamera", 3, "%s\n", getstarCommand);125 117 126 118 psLogMsg("fpcamera", PS_LOG_INFO, "getstar command: %s", getstarCommand); 127 119 128 // XXX use psPipe: catch stderr, stdout, allow for Nsec timeout... 129 // use fork to add timeout capability 120 // run getstar, result is saved in the temp file 130 121 status = system (getstarCommand); 131 122 if (status) ESCAPE(FPCAMERA_ERR_REFSTARS, "error loading reference data"); … … 140 131 141 132 psArray *refstars = NULL; 142 if (!strcmp (outformat, "CATALOG")) {143 refstars = fpcameraReadGetstarCatalog (fits);144 }145 133 if (!strcmp (outformat, "PS1_DEV_0")) { 146 134 refstars = fpcameraReadGetstar_PS1_DEV_0 (fits); … … 160 148 unlink (tempFile); 161 149 162 # if (0)163 164 // dump or plot the available refstars165 if (psTraceGetLevel("fpcamera.dump") > 0) {166 fpcameraDumpRefstars (refstars, "refstars.dat");167 }168 169 pmAstromVisualPlotRefStars (refstars, recipe);170 171 if (psTraceGetLevel("fpcamera.plot") > 0) {172 fpcameraPlotRefstars (refstars, recipe);173 }174 # endif175 176 150 psMetadataAdd (input->fpa->analysis, PS_LIST_TAIL, "FPCAMERA.REFSTARS", PS_DATA_ARRAY, "reference sources", refstars); 177 151 psFree (refstars); … … 180 154 } 181 155 182 psArray *fpcameraReadGetstarCatalog (psFits *fits) { 183 184 bool status; 185 186 if (ELIXIR_MODE) { 187 psFitsMoveExtName (fits, "DVO_AVERAGE_ELIXIR"); 188 } else { 189 psFitsMoveExtName (fits, "DVO_AVERAGE_PANSTARRS"); 190 } 191 192 long numSources = psFitsTableSize(fits); // Number of sources in table 193 194 // convert the Average table to the pmAstromObj entries 195 psArray *refstars = psArrayAllocEmpty (numSources); 196 for (int i = 0; i < numSources; i++) { 197 pmAstromObj *ref = pmAstromObjAlloc (); 198 199 psMetadata *row = psFitsReadTableRow(fits, i); // Table row 200 201 // DVO tables are stored in degrees 202 if (ELIXIR_MODE) { 203 ref->sky->r = RAD_DEG*psMetadataLookupF32 (&status, row, "RA"); 204 ref->sky->d = RAD_DEG*psMetadataLookupF32 (&status, row, "DEC"); 205 ref->Mag = 0.001*psMetadataLookupS32 (&status, row, "MAG"); // ELIXIR uses millimags 206 ref->Color = 0.0; 207 } else { 208 ref->sky->r = RAD_DEG*psMetadataLookupF64 (&status, row, "RA"); 209 ref->sky->d = RAD_DEG*psMetadataLookupF64 (&status, row, "DEC"); 210 ref->Mag = psMetadataLookupF32 (&status, row, "MAG"); // PANSTARRS uses mags 211 ref->Color = 0.0; 212 } 213 ref->magCal = ref->Mag; 214 215 // XXX VERY temporary hack to avoid M31 bulge 216 if ((fabs(ref->sky->r - 0.186438) < 0.002) && (fabs(ref->sky->d - 0.720270) < 0.002)) { 217 psFree (ref); 218 psFree (row); 219 continue; 220 } 221 222 psArrayAdd (refstars, 100, ref); 223 psFree (ref); 224 psFree (row); 225 } 226 return refstars; 227 } 228 156 // method to read PS1_DEV_0 format 157 // Note other options can be found in psastroLoadRefstars.c 229 158 psArray *fpcameraReadGetstar_PS1_DEV_0 (psFits *fits) { 230 159 … … 250 179 ref->Color = MagC1 - MagC2; 251 180 } else { 252 // XXX save the color and the slope in the table header?253 181 ref->Color = 0.0; 254 182 } … … 269 197 } 270 198 271 # undef ESCAPE272 199 273 # if (0)274 275 # define ESCAPE(MSG) { \276 psLogMsg ("fpcamera", PS_LOG_INFO, MSG); \277 goto escape; }278 279 char *fpcameraSetMagLimit (float *minMag, float *maxRho, pmConfig *config, const char *source) {280 281 bool status;282 char *photcode;283 284 // select the current recipe285 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, FPCAMERA_RECIPE);286 287 // select the input data sources288 pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, source);289 if (!input) {290 psLogMsg ("fpcamera", PS_LOG_DETAIL, "no supplied reference header data");291 photcode = psStringCopy ("NONE");292 return photcode;293 }294 assert (input->fpa);295 296 *maxRho = psMetadataLookupF32(&status, recipe, "DVO.GETSTAR.MAX.RHO");297 if (!status) {298 psError(FPCAMERA_ERR_CONFIG, false, "DVO.GETSTAR.MAX.RHO missing from recipe");299 return NULL;300 }301 302 // select the filter; default to fixed photcode and mag limit otherwise303 char *filter = psMetadataLookupStr (&status, input->fpa->concepts, "FPA.FILTERID");304 if (!status) ESCAPE ("missing FPA.FILTER in concepts");305 306 float exptime = psMetadataLookupF32 (&status, input->fpa->concepts, "FPA.EXPOSURE");307 if (!status) ESCAPE ("missing FPA.EXPOSURE in concepts");308 309 // we need to select the PHOTCODE.DATA folder that matches our filter310 psMetadataItem *item = psMetadataLookup (recipe, "PHOTCODE.DATA");311 if (!item) ESCAPE ("PHOTCODE.DATA folders missing");312 if (item->type != PS_DATA_METADATA_MULTI) ESCAPE ("PHOTCODE.DATA not a multi");313 314 float minInst = psMetadataLookupF32(&status, recipe, "DVO.GETSTAR.MIN.MAG.INST");315 if (!status) ESCAPE ("missing DVO.GETSTAR.MIN.MAG.INST");316 317 // if non zero override the zero point in the PHOTCODE.DATA with this value318 float fixedzeropt = psMetadataLookupF32(&status, recipe, "DVO.GETSTAR.FIXED.ZEROPT");319 320 // PHOTCODE.DATA is a multi of metadata items321 psListIterator *iter = psListIteratorAlloc(item->data.list, PS_LIST_HEAD, false);322 323 psMetadataItem *refItem = NULL;324 while ((refItem = psListGetAndIncrement (iter))) {325 if (refItem->type != PS_DATA_METADATA) ESCAPE ("PHOTCODE.DATA entry is not a metadata folder");326 327 char *refFilter = psMetadataLookupStr (&status, refItem->data.md, "FILTER");328 if (!status) {329 psLogMsg ("fpcamera", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER");330 continue;331 }332 333 // does this entry match the current filter?334 if (strcmp (refFilter, filter)) continue;335 336 psLogMsg ("fpcamera", PS_LOG_DETAIL, "PHOTCODE.DATA found for filter %s", filter);337 338 float zeropt = psMetadataLookupF32 (&status, refItem->data.md, "ZEROPT");339 if (!status) {340 psLogMsg ("fpcamera", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER");341 continue;342 }343 photcode = psMetadataLookupStr (&status, refItem->data.md, "PHOTCODE");344 if (!status) {345 psLogMsg ("fpcamera", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER");346 continue;347 }348 if (fixedzeropt != 0.0) {349 // override the recipe's zero point with the fixed value (used for stacks)350 zeropt = fixedzeropt;351 }352 353 // convert the minInst to a calibrated minimum magnitude354 *minMag = minInst + 2.5*log10(exptime) + zeropt;355 356 psFree (iter);357 return photcode;358 }359 psFree (iter);360 361 escape:362 photcode = psMetadataLookupStr(NULL, recipe, "DVO.GETSTAR.PHOTCODE");363 PS_ASSERT (photcode, NULL);364 365 // give up and use fixed value366 *minMag = psMetadataLookupF32(NULL, recipe, "DVO.GETSTAR.MIN.MAG");367 return photcode;368 }369 # endif -
branches/eam_branches/ipp-20220316/fpcamera/src/fpcameraParseCamera.c
r42182 r42183 34 34 output->save = true; 35 35 36 // optionally save the residual image 37 if (psMetadataLookupBool(&status, config->arguments, "SAVE.RESID")) { 38 pmFPAfile *output = pmFPAfileDefineOutputFromFile (config, input, "FPCAMERA.RESID"); 39 if (!output) ESCAPE(FPCAMERA_ERR_CONFIG, "Cannot find a rule for FPCAMERA.RESID"); 40 output->save = true; 41 } 42 36 43 // Chip selection: turn on only the chips specified (option is not required) 37 44 char *chipLine = psMetadataLookupStr(&status, config->arguments, "CHIP_SELECTIONS");
Note:
See TracChangeset
for help on using the changeset viewer.
