IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 12, 2023, 9:31:00 AM (3 years ago)
Author:
eugene
Message:

add (and use) a function to populate the config with PSCAMERA values for SKYCELLS, if missing; use temporary config to read kernels as well as other things

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppSub/src/ppSubCamera.c

    r42295 r42463  
    180180}
    181181
     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
    182246pmConfig *pmConfigMakeTemp (pmConfig *config) {
    183247    pmConfig *altconfig = pmConfigAlloc();
     
    268332    psAssert(config, "Require configuration");
    269333
     334    pmConfigFixSkycellCamera (config);
     335
    270336    // Input image
    271337    pmFPAfile *input = defineInputFile(&success, config, NULL, "PPSUB.INPUT", "INPUT", PM_FPA_FILE_IMAGE);
     
    334400        return false;
    335401    }
    336     // XXX do we need to copy the PSCAMERA across to src? 
     402    // copy src->format(RULE) PSCAMERA from input->format(RULE)
    337403    ppSubCopyPSCamera (src, input);
    338404    psFree (srcconfig);
     
    504570    checkFileruleFileSave(jpeg3, config);
    505571
     572    // The reference sources may not be from the same origin as the reference image, so
     573    // use another temporary camera.
     574    pmConfig *kernel_config = pmConfigMakeTemp(config);
     575
    506576    // Output subtraction kernel
    507     pmFPAfile *kernel = defineCalcFile(config, output, "PPSUB.OUTPUT.KERNELS", "KERNEL",
    508                                        PM_FPA_FILE_SUBKERNEL);
     577    pmFPAfile *kernel = defineCalcFile(kernel_config, output, "PPSUB.OUTPUT.KERNELS", "KERNEL", PM_FPA_FILE_SUBKERNEL);
    509578    if (!kernel) {
    510579        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to define file PPSUB.OUTPUT.KERNELS");
    511580        return false;
    512581    }
     582
     583    // copy kernel->format(RULE) PSCAMERA from input->format(RULE)
     584    ppSubCopyPSCamera (kernel, input);
     585    psFree (kernel_config);
    513586
    514587    // psPhot input
Note: See TracChangeset for help on using the changeset viewer.