Changeset 42932
- Timestamp:
- Oct 28, 2025, 4:20:30 PM (9 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tags/ipp-ops-20220906/ppSub/src/ppSubCamera.c
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/IPP-308_move_backups_folder/ppSub/src/ppSubCamera.c merged eligible /branches/czw_branch/20160809/ppSub/src/ppSubCamera.c merged eligible /branches/czw_branch/20170908/ppSub/src/ppSubCamera.c merged eligible /branches/eam_branches/ipp-20191011/ppSub/src/ppSubCamera.c merged eligible /branches/eam_branches/ipp-20211108/ppSub/src/ppSubCamera.c merged eligible /branches/eam_branches/ipp-dev-20210817/ppSub/src/ppSubCamera.c merged eligible /tags/ipp-ops-20220705/ppSub/src/ppSubCamera.c merged eligible /tags/ipp-ps1-20210510/ppSub/src/ppSubCamera.c merged eligible /tags/ipp-ps1-20210708/ppSub/src/ppSubCamera.c merged eligible /trunk/ppSub/src/ppSubCamera.c merged eligible /branches/ipp-259_genericise_backups/ppSub/src/ppSubCamera.c 40910-40966
r42096 r42932 119 119 120 120 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. 123 127 static pmFPAfile *defineCalcFile(pmConfig *config, // Configuration 124 128 pmFPAfile *bind, // File to which to bind, or NULL … … 133 137 pmFPAfile *file = pmFPAfileDefineFromRun(&status, NULL, config, filerule); // File to return 134 138 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 } 137 146 } 138 147 file = pmFPAfileBindFromArgs(&status, bind, config, filerule, argname); … … 171 180 } 172 181 182 bool 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 173 246 pmConfig *pmConfigMakeTemp (pmConfig *config) { 174 247 pmConfig *altconfig = pmConfigAlloc(); … … 177 250 altconfig->user = psMemIncrRefCounter(config->user); // inherit from primary camera 178 251 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) 180 255 181 256 psFree (altconfig->files); … … 188 263 altconfig->recipes = psMetadataCopy(NULL, config->recipes); // container for camera-specific recipe values (to be dropped) 189 264 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? 194 268 bool mdok = false; 195 269 psMetadata *cameras = psMetadataLookupMetadata(&mdok, altconfig->system, "CAMERAS"); … … 229 303 psMetadataRemoveKey (rule, "PSCAMERA"); // allow any camera skycell to match 230 304 } 231 # endif 305 psFree (camerasIter); 232 306 233 307 return (altconfig); 308 } 309 310 bool 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; 234 324 } 235 325 … … 241 331 pmConfig *config = data->config; 242 332 psAssert(config, "Require configuration"); 333 334 pmConfigFixSkycellCamera (config); 243 335 244 336 // Input image … … 267 359 } 268 360 361 int did_rewrite = 0; 362 269 363 // Use a temporary config for the reference image, keeping the main user, site, 270 364 // system, files, arguments entries. This allows the reference image to be from a 271 365 // different camera than the input image. NOTE: there is no check that these two 272 366 // 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. 273 369 274 370 pmConfig *refconfig = pmConfigMakeTemp(config); 275 371 276 # if (0)277 // EAM TEST: can we bind the ref to the input to force the right skycell format?278 // Reference image279 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 # else285 372 // Reference image 286 373 pmFPAfile *ref = defineInputFile(&success, refconfig, NULL, "PPSUB.REF", "REF", PM_FPA_FILE_IMAGE); 287 374 if (!success) { 288 375 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 293 389 defineInputFile(&success, refconfig, ref, "PPSUB.REF.MASK", "REF.MASK", PM_FPA_FILE_MASK); 294 390 if (!success) { … … 296 392 return false; 297 393 } 298 394 // Reference variance 299 395 pmFPAfile *refVar = defineInputFile(&success, refconfig, ref, "PPSUB.REF.VARIANCE", "REF.VARIANCE", PM_FPA_FILE_VARIANCE); 300 396 if (!success) { … … 302 398 return false; 303 399 } 400 // copy ref->format(RULE) PSCAMERA from input->format(RULE) 401 ppSubCopyPSCamera (ref, input); 304 402 psFree (refconfig); 305 403 … … 308 406 pmConfig *srcconfig = pmConfigMakeTemp(config); 309 407 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); 311 410 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 { 312 426 psError(psErrorCodeLast(), false, "Failed to build FPA from PPSUB.REF.SOURCES"); 313 427 return false; 314 } 428 } 429 } 430 // copy src->format(RULE) PSCAMERA from input->format(RULE) 431 ppSubCopyPSCamera (src, input); 315 432 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 } 316 439 317 440 // Now that the camera has been determined, we can read the recipe … … 481 604 checkFileruleFileSave(jpeg3, config); 482 605 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 483 616 // 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); 486 618 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 490 636 491 637 // psPhot input 492 638 if (data->photometry || 1) { 493 psphotModelClassInit(); // load implementation-specific models639 psphotModelClassInit(); // load implementation-specific models 494 640 495 641 pmFPAfile *psphot = pmFPAfileDefineFromFPA(config, output->fpa, 1, 1, "PSPHOT.INPUT"); -
Property svn:mergeinfo
set to (toggle deleted branches)
Note:
See TracChangeset
for help on using the changeset viewer.
