IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 34487


Ignore:
Timestamp:
Sep 27, 2012, 6:30:59 PM (14 years ago)
Author:
watersc1
Message:

Fixed problem that was causing pswarp to exit with non-zero status (pmPFAfileIOChecks does something to the config that results in PSPHOT.DETECTIONS being added to the metadata twice. Removed offending region without change in output). Cleaned up some other debug information and removed unused bits of code.

Location:
branches/czw_branch/20120906/pswarp/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20120906/pswarp/src/pswarpLoop.c

    r34471 r34487  
    458458    bool status;
    459459    bool mdok;                          // Status of MD lookup
    460 
    461460    const char *skyCamera = psMetadataLookupStr(NULL, config->arguments,
    462461                                                "SKYCELL.CAMERA");  // Name of camera for skycell
     
    505504    }
    506505    psFree (view);
    507 
    508506    // Turn all skycell files on to generate them, and then turn them off for the loop over the input images
    509507    // the input, which is in a different format.
     
    519517        pswarpFileActivation(config, skycellFiles, false);
    520518    }
    521 
    522519    // Read the input astrometry
    523520    // XXX rather than use the activations here, this should just explicitly loop over the desired filerule
    524521    {
    525         pmFPAfileActivate(config->files, true, "PSWARP.ASTROM");
     522
     523      pmFPAfileActivate(config->files, true, "PSWARP.ASTROM");
    526524
    527525        pmChip *chip;
     
    531529            goto DONE;
    532530        }
     531
    533532        while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
    534           psTrace ("pswarp", 4, "AChip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
     533#if 0
     534          // This needs to be removed because otherwise it throws an error of duplicate PSPHOT.DETECTIONS.
    535535            if (!chip->process || !chip->file_exists) { continue; }
    536536            if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
     
    538538                goto DONE;
    539539            }
     540#endif
    540541            pmCell *cell;
    541542            while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
    542                 psTrace ("pswarp", 4, "ACell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
     543              psTrace ("pswarp", 4, "ACell %d: %x %x %d\n", view->cell, cell->file_exists, cell->process,psErrorCodeLast());
    543544                if (!cell->process || !cell->file_exists) { continue; }
    544545                if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE) ||
     
    558559        }
    559560        psFree(view);
    560 
    561561        pswarpFileActivation(config, detectorFiles, true);
    562562        pmFPAfileActivate(config->files, false, "PSWARP.ASTROM");
    563563    }
    564 
    565 /*     // Turn on the source output --- we need to get rid of these so that we can measure the PSF */
    566 /*     pmFPAfileActivate(config->files, true, "PSWARP.OUTPUT.SOURCES"); */
    567564
    568565    // Don't care about the skycell anymore --- we've read it, and that's all we need to do.
     
    574571    pmHDU *phu = pmFPAviewThisPHU(view, astrom->fpa);
    575572
    576     pmAstromWCS *WCSF = pmAstromWCSfromHeader(phu->header);
    577    
    578     fprintf(stderr,"WCSF: %g %g : %g %g : %g %g : %g %g %g %g : %g %g\n",
    579             WCSF->crval1,WCSF->crval2,
    580             WCSF->crpix1,WCSF->crpix2,
    581             WCSF->cdelt1,WCSF->cdelt2,
    582             WCSF->trans->x->coeff[1][0],
    583             WCSF->trans->x->coeff[0][1],
    584             WCSF->trans->y->coeff[1][0],
    585             WCSF->trans->y->coeff[0][1],
    586             -1.0,-1.0);
    587 /* #define CORRECT_INPUT_WCS 1 */
    588 /* #if CORRECT_INPUT_WCS */
    589 /*      // Correct the input WCS */
    590 /*      pmAstromWCS *WCS = pmAstromWCSfromHeader(phu->header); */
    591 
    592 /*      double cd1f = 1.0 * 400; */
    593 /*      double cd2f = 1.0 * 400; */
    594 /*      fprintf(stderr,"WCS: %g %g : %g %g : %g %g : %g %g %g %g : %g %g\n", */
    595 /*              WCS->crval1,WCS->crval2, */
    596 /*              WCS->crpix1,WCS->crpix2, */
    597 /*              WCS->cdelt1,WCS->cdelt2, */
    598 /*              WCS->trans->x->coeff[1][0], */
    599 /*              WCS->trans->x->coeff[0][1], */
    600 /*              WCS->trans->y->coeff[1][0], */
    601 /*              WCS->trans->y->coeff[0][1], */
    602 /*              cd1f,cd2f); */
    603 
    604 /*      WCS->crpix1 = WCS->crpix1 / cd1f; */
    605 /*      WCS->crpix2 = WCS->crpix2 / cd2f; */
    606 
    607 /*      WCS->cdelt1 *= cd1f; */
    608 /*      WCS->cdelt2 *= cd2f; */
    609 
    610 /*      // WCS->trans->x->nX/nY */
    611 /*      for (int q = 0; q < WCS->trans->x->nX; q++) { */
    612 /*        for (int r = 0; r < WCS->trans->x->nY; r++) { */
    613 /*          WCS->trans->x->coeff[q][r] *= cd1f; */
    614 /*        } */
    615 /*      } */
    616 /*      for (int q = 0; q < WCS->trans->y->nX; q++) { */
    617 /*        for (int r = 0; r < WCS->trans->y->nY; r++) { */
    618 /*          WCS->trans->y->coeff[q][r] *= cd2f; */
    619 /*        } */
    620 /*      } */
    621 /*      fprintf(stderr,"WCS: %g %g : %g %g : %g %g : %g %g %g %g : %g %g\n", */
    622 /*              WCS->crval1,WCS->crval2, */
    623 /*              WCS->crpix1,WCS->crpix2, */
    624 /*              WCS->cdelt1,WCS->cdelt2, */
    625 /*              WCS->trans->x->coeff[1][0], */
    626 /*              WCS->trans->x->coeff[0][1], */
    627 /*              WCS->trans->y->coeff[1][0], */
    628 /*              WCS->trans->y->coeff[0][1], */
    629 /*              cd1f,cd2f); */
    630 /*      pmAstromWCStoHeader (phu->header,WCS); */
    631 /*      // End WCS work. */
    632 /* #endif */
    633 
    634 
    635    
     573    //    pmAstromWCS *WCSF = pmAstromWCSfromHeader(phu->header);
    636574   
    637575    if (phu) {
     
    649587        }
    650588    }
    651 
    652 
    653589
    654590    psList *cells = psListAlloc(NULL);  // List of cells, for concepts averaging
     
    676612        double cd1f = 1.0 * 400;
    677613        double cd2f = 1.0 * 400;
    678         fprintf(stderr,"WCSC: %g %g : %g %g : %g %g : %g %g %g %g : %g %g\n",
    679                 WCS->crval1,WCS->crval2,
    680                 WCS->crpix1,WCS->crpix2,
    681                 WCS->cdelt1,WCS->cdelt2,
    682                 WCS->trans->x->coeff[1][0],
    683                 WCS->trans->x->coeff[0][1],
    684                 WCS->trans->y->coeff[1][0],
    685                 WCS->trans->y->coeff[0][1],
    686                 cd1f,cd2f);
    687 
    688614
    689615        WCS->cdelt1 *= cd1f;
     
    695621        for (int q = 0; q <= WCS->trans->x->nX; q++) {
    696622          for (int r = 0; r <= WCS->trans->x->nY; r++) {
    697             fprintf(stderr,"%d %d %g\n",q,r,WCS->trans->x->coeff[q][r]);
    698623            WCS->trans->x->coeff[q][r] *= pow(cd1f,q) * pow(cd2f,r);
    699             fprintf(stderr,"%d %d %g\n",q,r,WCS->trans->x->coeff[q][r]);
    700624          }
    701625        }
    702626        for (int q = 0; q <= WCS->trans->y->nX; q++) {
    703627          for (int r = 0; r <= WCS->trans->y->nY; r++) {
    704             fprintf(stderr,"%d %d %g\n",q,r,WCS->trans->y->coeff[q][r]);
    705628            WCS->trans->y->coeff[q][r] *= pow(cd1f,q) * pow(cd2f,r);
    706             fprintf(stderr,"%d %d %g\n",q,r,WCS->trans->y->coeff[q][r]);
    707629          }
    708630        }
    709         fprintf(stderr,"WCSO: %g %g : %g %g : %g %g : %g %g %g %g : %g %g\n",
    710                 WCS->crval1,WCS->crval2,
    711                 WCS->crpix1,WCS->crpix2,
    712                 WCS->cdelt1,WCS->cdelt2,
    713                 WCS->trans->x->coeff[1][0],
    714                 WCS->trans->x->coeff[0][1],
    715                 WCS->trans->y->coeff[1][0],
    716                 WCS->trans->y->coeff[0][1],
    717                 cd1f,cd2f);
    718 
    719         fprintf(stderr,"Size: %d %d %d %d\n",WCS->trans->x->nX,WCS->trans->x->nY,WCS->trans->y->nX,WCS->trans->y->nY);
    720631        pmAstromWCStoHeader (hdu->header,WCS);
    721632       
     
    761672                }
    762673
    763                 // Copy the detections from the astrometry carrier to the input, so they can be accessed by
    764                 // pswarpTransformReadout
    765 /*                 pmReadout *astromRO = pmFPAviewThisReadout(view, astrom->fpa); // Readout for astrometry */
    766 /*                 pmDetections *detections = psMetadataLookupPtr(&mdok, astromRO->analysis, "PSPHOT.DETECTIONS"); // Sources from astrometry */
    767 /*                 if (detections) { */
    768 /*                     psMetadataAddPtr(readout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_DATA_ARRAY | PS_META_REPLACE, "Sources from input astrometry", detections); */
    769 /*                 } */
    770                
    771674                for (int x = 0; x < readout->image->numCols; x++) {
    772675                  for (int y = 0; y < readout->image->numRows; y++) {
     
    778681               
    779682                psMetadataAddS32(config->arguments,PS_LIST_TAIL, "INTERPOLATION.MODE", PS_META_REPLACE, "", 8);
    780 
    781683                fprintf(stderr,"Transforming Readout!\n");
    782684
     
    784686                pswarpTransformReadout(output, readout, config);
    785687                psMetadataAddBool(config->arguments,PS_LIST_TAIL, "BACKGROUND_WARPING", PS_META_REPLACE, "", false);
    786                
    787688                if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
    788689                    psError(psErrorCodeLast(), false, "Unable to write files.");
     
    800701        }
    801702    }
    802 
     703    fprintf(stderr,"End readout transformations!\n");
    803704    if (!output->data_exists) {
    804705        psWarning("No overlap between input and skycell.");
    805 /*         if (stats) { */
    806 /*             psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE, */
    807 /*                              "No overlap between input and skycell", PSWARP_ERR_NO_OVERLAP); */
    808 /*         } */
    809706        psphotFilesActivate(config, false);
    810707        psFree(cells);
     
    812709        goto DONE;
    813710    }
    814    
    815711    pmCell *outCell = output->parent;   ///< Output cell
    816712    pmChip *outChip = outCell->parent;  ///< Output chip
     
    823719        goto DONE;
    824720    }
    825 /*     bool doStats = psMetadataLookupBool(&mdok,recipe,"MASK.STATS"); */
    826 /*     if (doStats) { */
    827 /*       if (!pswarpMaskStats(output, stats, config)) { */
    828 /*      psError(psErrorCodeLast(), false, "Unable to calculate mask stats."); */
    829 /*      psFree(cells); */
    830 /*      psFree(view); */
    831 /*      goto DONE; */
    832 /*       } */
    833 /*     } */
    834 /*     // Set covariance matrix for output */
    835 /*     { */
    836 /*         psList *covariances = psMetadataLookupPtr(&mdok, output->analysis, */
    837 /*                                                   PSWARP_ANALYSIS_COVARIANCES); // Covariance matrices */
    838 /*         psAssert(covariances, "Should be there"); */
    839 /*         psArray *covars = psListToArray(covariances); // Array of covariance matrices */
    840 /*         psKernel *covar = psImageCovarianceAverage(covars); */
    841 /*         psFree(covars); */
    842 /*         psMetadataRemoveKey(output->analysis, PSWARP_ANALYSIS_COVARIANCES); */
    843 
    844 /*         // Correct covariance matrix scale for the mean (square root of the) Jacobian */
    845 /*         double jacobian = psMetadataLookupF64(NULL, output->analysis, PSWARP_ANALYSIS_JACOBIAN); // Jacobian */
    846 /*         int goodPixels = psMetadataLookupS32(NULL, output->analysis, PSWARP_ANALYSIS_GOODPIX);   // Good pixels */
    847 /*         jacobian /= goodPixels; */
    848 /*         output->covariance = psImageCovarianceScale(covar, jacobian); */
    849 /*         psFree(covar); */
    850 
    851 /*         if (output->variance) { */
    852 /*             psImageCovarianceTransfer(output->variance, output->covariance); */
    853 /*         } */
    854 /*     } */
    855 
    856 /*     if (!pmConceptsAverageCells(outCell, cells, NULL, NULL, false)) { */
    857 /*         psError(psErrorCodeLast(), false, "Unable to average cell concepts."); */
    858 /*         psFree(stats); */
    859 /*         psFree(cells); */
    860 /*         psFree(view); */
    861 /*         goto DONE; */
    862 /*     } */
    863 /*     psFree(cells); */
    864721
    865722    psRegion *trimsec = psMetadataLookupPtr(NULL, outCell->concepts, "CELL.TRIMSEC"); ///< Trim section
     
    872729        goto DONE;
    873730    }
    874 
    875     // Update ZP from the astrometry
    876 /*     { */
    877 /*         psMetadataItem *item = psMetadataLookup(outFPA->concepts, "FPA.ZP"); */
    878 /*         item->data.F32 = psMetadataLookupF32(NULL, astrom->fpa->concepts, "FPA.ZP"); */
    879 /*     } */
    880731
    881732    pmHDU *hdu = outFPA->hdu;           ///< HDU for the output warped image
     
    895746        hdu->header = psMetadataCopy(hdu->header, skyHDU->header);
    896747    }
    897 
    898748    pswarpVersionHeader(hdu->header);
    899749   
     
    903753        goto DONE;
    904754    }
    905 
    906755    if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
    907756        psError(psErrorCodeLast(), false, "Unable to write files.");
    908757        goto DONE;
    909758    }
    910 
    911759    // Done with the detector side of things
    912760    pswarpFileActivation(config, detectorFiles, false);
    913761    pswarpFileActivation(config, independentFiles, false);
    914 
    915 
    916     // We need a new PSF model for the warped frame.  It would be good to generate this analytically, but
    917     // that's going to be tricky.  We have a list of sources, so we use those to redetermine the PSF model.
    918 
    919 /*     if (psMetadataLookupBool(&mdok, recipe, "PSF")) { */
    920 /*         pswarpFileActivation(config, photFiles, true); */
    921 /*         if (!pswarpIOChecksBefore(config)) { */
    922 /*             psError(psErrorCodeLast(), false, "Unable to read files."); */
    923 /*             goto DONE; */
    924 /*         } */
    925 
    926 /*         // supply the readout and fpa of interest to psphot */
    927 /*         pmFPAfile *photFile = psMetadataLookupPtr(NULL, config->files, "PSPHOT.INPUT"); */
    928 /*         pmFPACopy(photFile->fpa, outFPA); */
    929 
    930 /*         pmFPAview *view = pmFPAviewAlloc(0); ///< View into skycell */
    931 /*         view->chip = view->cell = view->readout = 0; */
    932 
    933 /*         // grab the sources of interest from the storage location (pmFPAfile PSPHOT.INPUT.CMF) */
    934 /*         psArray *sources = psphotLoadPSFSources (config, view); */
    935 /*         if (!sources) { */
    936 /*             psError(psErrorCodeLast(), false, "No sources supplied to measure PSF"); */
    937 /*             goto DONE; */
    938 /*         } */
    939 
    940 /*         pmModelClassSetLimits(PM_MODEL_LIMITS_STRICT); */
    941 
    942 /*         // measure the PSF using these sources */
    943 /*         if (!psphotReadoutFindPSF(config, view, "PSPHOT.INPUT", sources)) { */
    944 /*             // This is likely a data quality issue */
    945 /*             // XXX Split into multiple cases using error codes? */
    946 /*             psErrorStackPrint(stderr, "Unable to determine PSF"); */
    947 /*             psWarning("Unable to determine PSF --- suspect bad data quality."); */
    948 /*             if (stats && psMetadataLookupS32(NULL, stats, "QUALITY") == 0) { */
    949 /*                 psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE, */
    950 /*                                  "Unable to determine PSF", psErrorCodeLast()); */
    951 /*             } */
    952 /*             psErrorClear(); */
    953 /*             psphotFilesActivate(config, false); */
    954 /*         } */
    955 
    956 /*         // Ensure seeing is carried over */
    957 /*         pmChip *photChip = pmFPAviewThisChip(view, photFile->fpa);                 // Chip with seeing */
    958 /*         psMetadataItem *item = psMetadataLookup(outChip->concepts, "CHIP.SEEING"); // Concept with seeing */
    959 /*         item->data.F32 = psMetadataLookupF32(NULL, photChip->concepts, "CHIP.SEEING"); */
    960 
    961 /* // XXX EAM : put this in a visualization function */
    962 /* #if (TESTING) */
    963 /*         { */
    964 /*             #define PSF_SIZE 20         ///< Half-size of PSF */
    965 /*             #define PSF_FLUX 10000      ///< Central flux for PSF */
    966 /*             pmChip *photChip = pmFPAviewThisChip(view, photFile->fpa); */
    967 /*             pmPSF *psf = psMetadataLookupPtr(NULL, photChip->analysis, "PSPHOT.PSF"); */
    968 /*             psImage *image = psImageAlloc(2 * PSF_SIZE + 1, 2 * PSF_SIZE + 1, PS_TYPE_F32); */
    969 /*             psImageInit(image, 0); */
    970 /*             pmModel *model = pmModelFromPSFforXY(psf, PSF_SIZE, PSF_SIZE, PSF_FLUX); */
    971 /*             pmModelAdd(image, NULL, model, PM_MODEL_OP_FULL, 0); */
    972 /*             psFree(model); */
    973 /*             psFits *fits = psFitsOpen("psf.fits", "w"); */
    974 /*             psFitsWriteImage(fits, NULL, image, 0, NULL); */
    975 /*             psFitsClose(fits); */
    976 /*             psFree(image); */
    977 /*         } */
    978 /* #endif */
    979 
    980 /*         psFree(view); */
    981 /*     } */
    982 
    983 /*     // Perform statistics on the output image */
    984 /*     if (stats) { */
    985 /*         if (!ppStatsFPA(stats, output->parent->parent->parent, view, maskValue, config)) { */
    986 /*             psWarning("Unable to perform statistics on warped image."); */
    987 /*         } */
    988 /*     } */
    989762   
    990763
     
    1002775    psFree(headerName);
    1003776    psFree(view);
    1004 
    1005777 DONE:
    1006778
  • branches/czw_branch/20120906/pswarp/src/pswarpTransformReadout.c

    r34471 r34487  
    202202
    203203    if (goodPixels > 0 && psMetadataLookupBool(&mdok, recipe, "SOURCES")) {
     204      if (!psMetadataLookupBool(NULL,config->arguments,"BACKGROUND_WARPING")) {
    204205        if (!pswarpTransformSources(output, input, config)) {
    205             psError(psErrorCodeLast(), false, "Unable to interpolate image.");
    206             return false;
     206          psError(psErrorCodeLast(), false, "Unable to interpolate image.");
     207          return false;
    207208        }
     209      }
    208210    }
    209211
Note: See TracChangeset for help on using the changeset viewer.