IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 42932


Ignore:
Timestamp:
Oct 28, 2025, 4:20:30 PM (9 months ago)
Author:
tdeboer
Message:

commiting PS2 camera hack change to tag

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tags/ipp-ops-20220906/ppSub/src/ppSubCamera.c

    r42096 r42932  
    119119
    120120
    121 // Define an output file that will be used in a calculation
    122 // This means it might already be available in the RUN metadata
     121// Define an output file that will be used in a calculation. This means it might already be
     122// available in the RUN metadata
     123
     124// EAM 2022.10.14 : If the file is not found, treat it as if it did not exist in the input
     125// RUN metadata.  Currently, this is only used in this file to select
     126// PPSUB.OUTPUT.KERNELS.
    123127static pmFPAfile *defineCalcFile(pmConfig *config, // Configuration
    124128                                 pmFPAfile *bind,    // File to which to bind, or NULL
     
    133137    pmFPAfile *file = pmFPAfileDefineFromRun(&status, NULL, config, filerule); // File to return
    134138    if (!status) {
    135         psError(psErrorCodeLast(), false, "Failed to load file definition for %s", filerule);
    136         return NULL;
     139      bool requireSubkernel = psMetadataLookupBool(NULL, config->arguments, "-require-subkernel");
     140      if (requireSubkernel) {
     141        psError(psErrorCodeLast(), false, "Failed to load file definition for %s", filerule);
     142        return NULL;
     143      } else {
     144        psWarning("Failed to load file definition for %s, regenerate", filerule);
     145      }
    137146    }
    138147    file = pmFPAfileBindFromArgs(&status, bind, config, filerule, argname);
     
    171180}
    172181
     182bool pmConfigFixSkycellCamera (pmConfig *config) {
     183
     184    // We have some static MDC files used for update for which we are missing PSCAMERA.
     185    // (This was an attempt to address cross-camera diffs, but was only a partial solution)
     186    // Here we need to check for -SKYCELL entries and re-instate the PSCAMERA entries
     187
     188    bool mdok = false;
     189    psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->system, "CAMERAS");
     190    psAssert(cameras, "missing cameras in system config info");
     191   
     192    // iterate over the cameras and find ones with names like _*-SKYCELLS
     193    // psMetadataIterator *camerasIter = psMetadataIteratorAlloc(cameras, PS_LIST_HEAD, "^_.+-SKYCELL$");
     194    psMetadataIterator *camerasIter = psMetadataIteratorAlloc(cameras, PS_LIST_HEAD, NULL);
     195    psAssert(camerasIter, "unable to generate iterator?");
     196
     197    psMetadataItem *camerasItem = NULL; // Item from the metadata
     198    while ((camerasItem = psMetadataGetAndIncrement(camerasIter))) {
     199      psAssert(camerasItem->type == PS_DATA_METADATA, "camerasItem has invalid type");
     200     
     201      char *name = camerasItem->name;
     202      psAssert (name, "NULL name for item");
     203
     204      int nameLen = strlen(name);
     205      if (name[0] != '_') continue;
     206      if (nameLen <= 9) continue;
     207      char *p = &name[nameLen - 8];
     208      if (strcmp(p, "-SKYCELL")) continue;
     209
     210      // we have found a -SKYCELL camera.  does it already have PSCAMERA?
     211
     212      // remove PSCAMERA entries from *-SKYCELL cameras
     213      psMetadata *formats = psMetadataLookupMetadata(&mdok, camerasItem->data.md, "FORMATS"); // List of formats
     214      psAssert (formats, "missing FORMATS in camera.config ");
     215
     216      psMetadata *format = psMetadataLookupMetadata(&mdok, formats, "SKYCELL"); // one true format for skycells
     217      psAssert (format, "missing SKYCELL metaformat for -SKYCELL entry ");
     218
     219      psMetadata *rule = psMetadataLookupMetadata(&mdok, format, "RULE"); // one true format for skycells
     220      psAssert (rule, "missing RULE in SKYCELL metaformat for -SKYCELL entry ");
     221
     222      psString pscamera = psMetadataLookupStr(&mdok, rule, "PSCAMERA"); // one true format for skycells
     223      if (pscamera) continue; // PSCAMERA exists, we are good
     224
     225      // the name of this camera is encoded in the portion of the word skipped above
     226      // name[1] to name[nameLen - 8] : number of bytes to copy is : nameLen - 8 - 1:
     227
     228      // _GPC2-SKYCELL
     229      // 0123456789012
     230      // nameLen = 13
     231      // nameLen - 8 - 1 = 4
     232      char cameraName[64];
     233
     234      int nByte = nameLen - 8 - 1;
     235      psAssert (nByte < 64 - 1, "camera name is too long");
     236     
     237      strncpy (cameraName, &name[1], nByte); cameraName[nByte] = 0;
     238
     239      psMetadataAddStr (rule, PS_LIST_TAIL, "PSCAMERA", PS_META_REPLACE, "", cameraName);
     240    }
     241    psFree (camerasIter);
     242
     243    return true;
     244}
     245
    173246pmConfig *pmConfigMakeTemp (pmConfig *config) {
    174247    pmConfig *altconfig = pmConfigAlloc();
     
    177250    altconfig->user   = psMemIncrRefCounter(config->user);   // inherit from primary camera
    178251    altconfig->site   = psMemIncrRefCounter(config->site);   // inherit from primary camera
    179     altconfig->system = psMemIncrRefCounter(config->system); // inherit from primary camera
     252
     253    psFree (altconfig->system);
     254    altconfig->system = psMetadataCopy(NULL, config->system); // container for camera-specific recipe values (to be dropped)
    180255
    181256    psFree (altconfig->files);
     
    188263    altconfig->recipes = psMetadataCopy(NULL, config->recipes); // container for camera-specific recipe values (to be dropped)
    189264
    190 # if (0)
    191     // XXX ppStack seems to work without removing PSCAMERA
    192     // remove PSCAMERA entries from *-SKYCELL cameras
    193     // XXX make this optional to force matching cameras if desired?
     265    // remove PSCAMERA entries from *-SKYCELL cameras.  This allows skycell images from
     266    // one camera to match those of another camera.  XXX Make this optional to force
     267    // matching cameras if desired?
    194268    bool mdok = false;
    195269    psMetadata *cameras = psMetadataLookupMetadata(&mdok, altconfig->system, "CAMERAS");
     
    229303      psMetadataRemoveKey (rule, "PSCAMERA"); // allow any camera skycell to match
    230304    }
    231 # endif
     305    psFree (camerasIter);
    232306
    233307    return (altconfig);
     308}
     309
     310bool ppSubCopyPSCamera (pmFPAfile *tgt, pmFPAfile *src) {
     311
     312    bool success;
     313    psMetadata *ruleSrc = psMetadataLookupMetadata(&success, src->format, "RULE"); // one true format for skycells
     314    psAssert (ruleSrc, "missing RULE in src->format");
     315
     316    psString pscameraSrc = psMetadataLookupStr(&success, ruleSrc, "PSCAMERA"); // one true format for skycells
     317    psAssert (pscameraSrc, "missing PSCAMERA in src file");
     318
     319    psMetadata *ruleTgt = psMetadataLookupMetadata(&success, tgt->format, "RULE"); // one true format for skycells
     320    psAssert (ruleTgt, "missing RULE in tgt->format");
     321
     322    psMetadataAddStr (ruleTgt, PS_LIST_TAIL, "PSCAMERA", PS_META_REPLACE, "", pscameraSrc);
     323    return true;
    234324}
    235325
     
    241331    pmConfig *config = data->config;
    242332    psAssert(config, "Require configuration");
     333
     334    pmConfigFixSkycellCamera (config);
    243335
    244336    // Input image
     
    267359    }
    268360
     361    int did_rewrite = 0;
     362   
    269363    // Use a temporary config for the reference image, keeping the main user, site,
    270364    // system, files, arguments entries.  This allows the reference image to be from a
    271365    // different camera than the input image.  NOTE: there is no check that these two
    272366    // images match in terms of size, pixel scale, etc. That is up to the user.
     367    // The temporary config structure has PSCAMERA entries removed from the SKYCELL rules
     368    // to allow subtraction between cameras.
    273369   
    274370    pmConfig *refconfig = pmConfigMakeTemp(config);
    275371
    276 # if (0)
    277     // EAM TEST: can we bind the ref to the input to force the right skycell format?
    278     // Reference image
    279     pmFPAfile *ref = defineInputFile(&success, config, input, "PPSUB.REF", "REF", PM_FPA_FILE_IMAGE);
    280     if (!success) {
    281         psError(psErrorCodeLast(), false, "Failed to build FPA from PPSUB.REF");
    282         return false;
    283     }
    284 # else
    285372    // Reference image
    286373    pmFPAfile *ref = defineInputFile(&success, refconfig, NULL, "PPSUB.REF", "REF", PM_FPA_FILE_IMAGE);
    287374    if (!success) {
    288375        psError(psErrorCodeLast(), false, "Failed to build FPA from PPSUB.REF");
    289         return false;
    290     }
    291 # endif
    292 
     376
     377        psErrorClear();
     378        fprintf(stderr,"%s\n", config->cameraName);
     379        psStringSubstitute(&( config->cameraName ),"GPC1","GPC2");
     380        fprintf(stderr,"%s\n", config->cameraName);
     381        did_rewrite = 1;
     382       
     383        ref = defineInputFile(&success, config, NULL, "PPSUB.REF", "REF", PM_FPA_FILE_IMAGE);
     384        if (!success) {
     385          return false;
     386        }
     387    }
     388    // Reference mask
    293389    defineInputFile(&success, refconfig, ref, "PPSUB.REF.MASK", "REF.MASK", PM_FPA_FILE_MASK);
    294390    if (!success) {
     
    296392        return false;
    297393    }
    298 
     394    // Reference variance
    299395    pmFPAfile *refVar = defineInputFile(&success, refconfig, ref, "PPSUB.REF.VARIANCE", "REF.VARIANCE", PM_FPA_FILE_VARIANCE);
    300396    if (!success) {
     
    302398        return false;
    303399    }
     400    // copy ref->format(RULE) PSCAMERA from input->format(RULE)
     401    ppSubCopyPSCamera (ref, input);
    304402    psFree (refconfig);
    305403
     
    308406    pmConfig *srcconfig = pmConfigMakeTemp(config);
    309407
    310     defineInputFile(&success, srcconfig, NULL, "PPSUB.REF.SOURCES", "REF.SOURCES", PM_FPA_FILE_CMF);
     408    // Sources input file (CMF)
     409    pmFPAfile *src = defineInputFile(&success, srcconfig, NULL, "PPSUB.REF.SOURCES", "REF.SOURCES", PM_FPA_FILE_CMF);
    311410    if (!success) {
     411      if (did_rewrite == 1) {
     412        // Sometimes we use the warp sources instead of the stack
     413        psErrorClear();
     414        did_rewrite = 0;
     415       
     416        fprintf(stderr,"%s\n", config->cameraName);
     417        psStringSubstitute(&( config->cameraName ),"GPC2","GPC1");
     418        fprintf(stderr,"%s\n", config->cameraName);
     419        defineInputFile(&success, config, NULL, "PPSUB.REF.SOURCES", "REF.SOURCES", PM_FPA_FILE_CMF);
     420        if (!success) {
     421          psError(psErrorCodeLast(), false, "Failed to build FPA from PPSUB.REF.SOURCES");
     422          return false;
     423        }
     424      }
     425      else {
    312426        psError(psErrorCodeLast(), false, "Failed to build FPA from PPSUB.REF.SOURCES");
    313427        return false;
    314     }
     428      }
     429    }
     430    // copy src->format(RULE) PSCAMERA from input->format(RULE)
     431    ppSubCopyPSCamera (src, input);
    315432    psFree (srcconfig);
     433   
     434    if (did_rewrite == 1) {
     435      fprintf(stderr,"%s\n", config->cameraName);
     436      psStringSubstitute(&( config->cameraName ),"GPC2","GPC1");
     437      fprintf(stderr,"%s\n", config->cameraName);
     438    }
    316439   
    317440    // Now that the camera has been determined, we can read the recipe
     
    481604    checkFileruleFileSave(jpeg3, config);
    482605
     606# if (0)
     607    // XXX NOTE EAM 20240209: This block of code attempts to correct the problem of missing
     608    // PSCAMERA entries, in this case in the output kernel definition.  This seems to work, but
     609    // there was a crash related to running psphot in update mode.  This block is probably not
     610    // responsible for the crash, but is commented out for the moment
     611
     612    // The reference sources may not be from the same origin as the reference image, so
     613    // use another temporary camera.
     614    pmConfig *kernel_config = pmConfigMakeTemp(config);
     615   
    483616    // Output subtraction kernel
    484     pmFPAfile *kernel = defineCalcFile(config, output, "PPSUB.OUTPUT.KERNELS", "KERNEL",
    485                                        PM_FPA_FILE_SUBKERNEL);
     617    pmFPAfile *kernel = defineCalcFile(kernel_config, output, "PPSUB.OUTPUT.KERNELS", "KERNEL", PM_FPA_FILE_SUBKERNEL);
    486618    if (!kernel) {
    487         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to define file PPSUB.OUTPUT.KERNELS");
    488         return false;
    489     }
     619        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to define file PPSUB.OUTPUT.KERNELS");
     620        return false;
     621    }
     622
     623    // copy kernel->format(RULE) PSCAMERA from input->format(RULE)
     624    ppSubCopyPSCamera (kernel, input);
     625    psFree (kernel_config);
     626# else
     627    // XXX NOTE EAM 20240209: This block of code matches the older version used in ipp-ps1-20220906-gentoo
     628
     629    // Output subtraction kernel
     630    pmFPAfile *kernel = defineCalcFile(config, output, "PPSUB.OUTPUT.KERNELS", "KERNEL", PM_FPA_FILE_SUBKERNEL);
     631    if (!kernel) {
     632        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to define file PPSUB.OUTPUT.KERNELS");
     633        return false;
     634    }
     635# endif
    490636
    491637    // psPhot input
    492638    if (data->photometry || 1) {
    493         psphotModelClassInit();        // load implementation-specific models
     639        psphotModelClassInit();        // load implementation-specific models
    494640
    495641        pmFPAfile *psphot = pmFPAfileDefineFromFPA(config, output->fpa, 1, 1, "PSPHOT.INPUT");
Note: See TracChangeset for help on using the changeset viewer.