- Timestamp:
- Apr 28, 2022, 4:13:55 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.
