IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 13, 2024, 8:15:12 AM (3 years ago)
Author:
eugene
Message:

for cross-camera forced photometry, we need to remove the PSCAMERA entry from the input sources

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20230313/psphot/src/psphotDefineFiles.c

    r36375 r42582  
    11# include "psphotInternal.h"
     2pmConfig *pmConfigMakeTemp (pmConfig *config);
    23
    34bool psphotINpsphotStack = false;
     
    143144    }
    144145
     146    // Use a temporary config for the source files, keeping the main user, site,
     147    // system, files, arguments entries.  This allows the sources to be from a
     148    // different camera than the input image.  NOTE: there is no check that these two
     149    // images match in terms of size, pixel scale, etc. That is up to the user.
     150    // The temporary config structure has PSCAMERA entries removed from the SKYCELL rules
     151    // to allow forced photometry between cameras.
     152   
     153    pmConfig *srcconfig = pmConfigMakeTemp(config);
     154
    145155    if (psMetadataLookupPtr(NULL, config->arguments, "SRC")) {
    146         if (!pmFPAfileDefineFromArgs (&status, config, "PSPHOT.INPUT.CMF", "SRC")) {
     156        if (!pmFPAfileDefineFromArgs (&status, srcconfig, "PSPHOT.INPUT.CMF", "SRC")) {
    147157            psError(PSPHOT_ERR_CONFIG, false, "Failed to find/build PSPHOT.INPUT.CMF");
    148158            return status;
     
    151161
    152162    if (psMetadataLookupPtr(NULL, config->arguments, "FORCE")) {
    153         if (!pmFPAfileDefineFromArgs (&status, config, "PSPHOT.INPUT.CFF", "FORCE")) {
     163        if (!pmFPAfileDefineFromArgs (&status, srcconfig, "PSPHOT.INPUT.CFF", "FORCE")) {
    154164            psError(PSPHOT_ERR_CONFIG, false, "Failed to find/build PSPHOT.INPUT.CFF");
    155165            return status;
     
    160170        // XXX cannot use pmFPAfileDefineFromArgs: this is explicitly a FITS-based I/O function
    161171        // supply the attach the
    162         if (!psphotLoadSRCTEXT(input->fpa, config)) {
     172        if (!psphotLoadSRCTEXT(input->fpa, srcconfig)) {
    163173            psError(PSPHOT_ERR_CONFIG, false, "Failed to load PSPHOT.INPUT.TEXT");
    164174            return status;
     
    167177
    168178    if (psMetadataLookupPtr(NULL, config->arguments, "PSPHOT.PSF")) {
    169         pmFPAfileBindFromArgs(&status, input, config, "PSPHOT.PSF.LOAD", "PSPHOT.PSF");
     179        pmFPAfileBindFromArgs(&status, input, srcconfig, "PSPHOT.PSF.LOAD", "PSPHOT.PSF");
    170180        if (!status) {
    171181            psError(PSPHOT_ERR_CONFIG, false, "Failed to find/build PSPHOT.PSF.LOAD");
     
    173183        }
    174184    }
     185
     186    psFree (srcconfig);
    175187
    176188    // XXX add in example PSF image thumbnails
     
    214226    return rule;
    215227}
     228
     229pmConfig *pmConfigMakeTemp (pmConfig *config) {
     230    pmConfig *altconfig = pmConfigAlloc();
     231
     232    // these are NULL on pmConfigAlloc
     233    altconfig->user   = psMemIncrRefCounter(config->user);   // inherit from primary camera
     234    altconfig->site   = psMemIncrRefCounter(config->site);   // inherit from primary camera
     235
     236    psFree (altconfig->system);
     237    altconfig->system = psMetadataCopy(NULL, config->system); // container for camera-specific recipe values (to be dropped)
     238
     239    psFree (altconfig->files);
     240    altconfig->files  = psMemIncrRefCounter(config->files); // inherit from primary camera
     241
     242    psFree (altconfig->arguments);
     243    altconfig->arguments = psMemIncrRefCounter(config->arguments); // inherit from primary camera
     244
     245    psFree (altconfig->recipes);
     246    altconfig->recipes = psMetadataCopy(NULL, config->recipes); // container for camera-specific recipe values (to be dropped)
     247
     248    // remove PSCAMERA entries from *-SKYCELL cameras.  This allows skycell images from
     249    // one camera to match those of another camera.  XXX Make this optional to force
     250    // matching cameras if desired?
     251    bool mdok = false;
     252    psMetadata *cameras = psMetadataLookupMetadata(&mdok, altconfig->system, "CAMERAS");
     253    psAssert(cameras, "missing cameras in system config info");
     254   
     255    // iterate over the cameras and find ones with names like _*-SKYCELLS
     256    // psMetadataIterator *camerasIter = psMetadataIteratorAlloc(cameras, PS_LIST_HEAD, "^_.+-SKYCELL$");
     257    psMetadataIterator *camerasIter = psMetadataIteratorAlloc(cameras, PS_LIST_HEAD, NULL);
     258    psAssert(camerasIter, "unable to generate iterator?");
     259
     260    psMetadataItem *camerasItem = NULL; // Item from the metadata
     261    while ((camerasItem = psMetadataGetAndIncrement(camerasIter))) {
     262      psAssert(camerasItem->type == PS_DATA_METADATA, "camerasItem has invalid type");
     263     
     264      char *name = camerasItem->name;
     265      psAssert (name, "NULL name for item");
     266
     267      int nameLen = strlen(name);
     268      if (name[0] != '_') continue;
     269      if (nameLen <= 9) continue;
     270      char *p = &name[nameLen - 8];
     271      if (strcmp(p, "-SKYCELL")) continue;
     272
     273      // remove PSCAMERA entries from *-SKYCELL cameras
     274      psMetadata *formats = psMetadataLookupMetadata(&mdok, camerasItem->data.md, "FORMATS"); // List of formats
     275      psAssert (formats, "missing FORMATS in camera.config ");
     276
     277      psMetadata *format = psMetadataLookupMetadata(&mdok, formats, "SKYCELL"); // one true format for skycells
     278      psAssert (format, "missing SKYCELL metaformat for -SKYCELL entry ");
     279
     280      psMetadata *rule = psMetadataLookupMetadata(&mdok, format, "RULE"); // one true format for skycells
     281      psAssert (rule, "missing RULE in SKYCELL metaformat for -SKYCELL entry ");
     282
     283      psString pscamera = psMetadataLookupStr(&mdok, rule, "PSCAMERA"); // one true format for skycells
     284      if (!pscamera) continue; // already removed, or never supplied
     285
     286      psMetadataRemoveKey (rule, "PSCAMERA"); // allow any camera skycell to match
     287    }
     288    psFree (camerasIter);
     289
     290    return (altconfig);
     291}
     292
Note: See TracChangeset for help on using the changeset viewer.