IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 23, 2010, 2:36:55 PM (16 years ago)
Author:
eugene
Message:

merge changes from trunk (pauls fixes for loading pre-calculated psfs)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20100621/psModules/src/objects/pmPSF_IO.c

    r27531 r28440  
    174174    PS_ASSERT_PTR_NON_NULL(chip, false);
    175175
    176     if (!pmPSFmodelWrite(chip->analysis, view, file, config)) {
     176    // We need the readout as well, because that has the PSF analysis data (e.g., clumps)
     177    // There is only one, because photometry is done on chip-mosaicked data.
     178    pmFPAview *roView = pmFPAviewAlloc(0); // View to readout
     179    *roView = *view;
     180    roView->cell = 0;
     181    roView->readout = 0;
     182    pmReadout *ro = pmFPAviewThisReadout(roView, chip->parent); // Readout with analysis data
     183    psFree(roView);
     184    PM_ASSERT_READOUT_NON_NULL(ro, false);
     185
     186    if (!pmPSFmodelWrite(chip->analysis, ro->analysis, view, file, config)) {
    177187        psError(psErrorCodeLast(), false, "Failed to write PSF for chip");
    178188        return false;
     
    189199// else
    190200//   - psf table (+header) : FITS Table
    191 bool pmPSFmodelWrite (psMetadata *analysis, const pmFPAview *view,
     201bool pmPSFmodelWrite (const psMetadata *chipAnalysis, const psMetadata *roAnalysis, const pmFPAview *view,
    192202                      pmFPAfile *file, pmConfig *config)
    193203{
     
    198208    char *headName, *tableName, *residName;
    199209
    200     if (!analysis) {
     210    if (!chipAnalysis) {
    201211        psError(PM_ERR_PROG, true, "No analysis metadata for chip.");
     212        return false;
     213    }
     214    if (!roAnalysis) {
     215        psError(PM_ERR_PROG, true, "No analysis metadata for readout.");
    202216        return false;
    203217    }
     
    314328
    315329    // select the psf of interest
    316     pmPSF *psf = psMetadataLookupPtr (&status, analysis, "PSPHOT.PSF");
     330    pmPSF *psf = psMetadataLookupPtr (&status, chipAnalysis, "PSPHOT.PSF");
    317331    if (!psf) {
    318332        psError(PM_ERR_PROG, true, "missing PSF for this analysis metadata");
     
    346360
    347361        // we now save clump parameters for each region : need to save all of those
    348         int nRegions = psMetadataLookupS32 (&status, analysis, "PSF.CLUMP.NREGIONS");
     362        int nRegions = psMetadataLookupS32 (&status, roAnalysis, "PSF.CLUMP.NREGIONS");
    349363        psMetadataAddS32 (header, PS_LIST_TAIL, "PSF_CLN", PS_META_REPLACE, "number of psf clump regions", nRegions);
    350364        for (int i = 0; i < nRegions; i++) {
    351365            char regionName[64];
    352366            snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", i);
    353             psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName);
     367            psMetadata *regionMD = psMetadataLookupPtr (&status, roAnalysis, regionName);
    354368
    355369            psfClump.X  = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X");   assert (status);
     
    492506
    493507        // write the residuals as planes of the image
    494         psArray *images = psArrayAllocEmpty (1);
    495         psArrayAdd (images, 1, psf->residuals->Ro);  // z = 0 is Ro
     508        psArray *images = psArrayAllocEmpty (1);
     509        psArrayAdd (images, 1, psf->residuals->Ro);  // z = 0 is Ro
    496510
    497511        if (psf->residuals->Rx) {
    498512            psArrayAdd (images, 1, psf->residuals->Rx);
    499513            psArrayAdd (images, 1, psf->residuals->Ry);
    500         }
    501 
    502         // note that all N plane are implicitly of the same type, so we convert the mask
    503         if (psf->residuals->mask) {
    504             psImage *mask = psImageCopy (NULL, psf->residuals->mask, psf->residuals->Ro->type.type);
    505             psArrayAdd (images, 1, mask);
    506             psFree (mask);
    507         }
    508 
    509         // psFitsWriteImageCube (file->fits, header, images, residName);
    510         // psFree (images);
    511 
    512         if (!psFitsWriteImageCube (file->fits, header, images, residName)) {
     514        }
     515
     516        // note that all N plane are implicitly of the same type, so we convert the mask
     517        if (psf->residuals->mask) {
     518            psImage *mask = psImageCopy (NULL, psf->residuals->mask, psf->residuals->Ro->type.type);
     519            psArrayAdd (images, 1, mask);
     520            psFree (mask);
     521        }
     522
     523        // psFitsWriteImageCube (file->fits, header, images, residName);
     524        // psFree (images);
     525
     526        if (!psFitsWriteImageCube (file->fits, header, images, residName)) {
    513527            psError(psErrorCodeLast(), false, "Unable to write PSF residuals.");
    514528            psFree(images);
     
    728742    PS_ASSERT_PTR_NON_NULL(file->fpa, false);
    729743
    730     if (!pmPSFmodelRead (chip->analysis, view, file, config)) {
     744    // We need the readout as well, because that has the PSF analysis data (e.g., clumps)
     745    // There may be only one, because photometry is done on chip-mosaicked data.
     746    if (chip->cells->n != 1) {
     747        psError(PM_ERR_PROG, true, "Chip to receive PSF has %ld cells (should be only one)",
     748                chip->cells->n);
     749        return false;
     750    }
     751    pmCell *cell = chip->cells->data[0]; // Cell to receive PSF
     752    pmReadout *ro = NULL;                // Readout to receive PSF
     753    if (cell->readouts->n == 0) {
     754        ro = pmReadoutAlloc(cell);
     755        psFree(ro);                     // Drop reference
     756    } else if (cell->readouts->n != 1) {
     757        psError(PM_ERR_PROG, true, "Cell to receive PSF has %ld readouts (should be only one)",
     758                cell->readouts->n);
     759        return false;
     760    } else {
     761        ro = cell->readouts->data[0];
     762    }
     763    PM_ASSERT_READOUT_NON_NULL(ro, false);
     764    if (!ro->analysis) {
     765        ro->analysis = psMetadataAlloc();
     766    }
     767
     768    if (!pmPSFmodelRead(chip->analysis, ro->analysis, view, file, config)) {
    731769        psError(psErrorCodeLast(), false, "Failed to write PSF for chip");
    732770        return false;
     
    737775// for each Readout (ie, analysed image), we write out: header + table with PSF model parameters,
    738776// and header + image for the PSF residual images
    739 bool pmPSFmodelRead (psMetadata *analysis, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     777bool pmPSFmodelRead (psMetadata *chipAnalysis, psMetadata *roAnalysis, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    740778{
     779    PS_ASSERT_METADATA_NON_NULL(chipAnalysis, false);
     780    PS_ASSERT_METADATA_NON_NULL(roAnalysis, false);
    741781    PS_ASSERT_PTR_NON_NULL(view, false);
    742782    PS_ASSERT_PTR_NON_NULL(file, false);
     
    809849        char regionName[64];
    810850        snprintf (regionName, 64, "PSF.CLUMP.REGION.000");
    811         psMetadataAddS32 (analysis, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", 1);
    812 
    813         psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName);
     851        psMetadataAddS32 (roAnalysis, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", 1);
     852
     853        psMetadata *regionMD = psMetadataLookupPtr (&status, roAnalysis, regionName);
    814854        if (!regionMD) {
    815855            regionMD = psMetadataAlloc();
    816             psMetadataAddMetadata (analysis, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD);
     856            psMetadataAddMetadata (roAnalysis, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD);
    817857            psFree (regionMD);
    818858        }
     
    831871        psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);
    832872    } else {
    833         psMetadataAddS32 (analysis, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", nRegions);
     873        psMetadataAddS32 (roAnalysis, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", nRegions);
    834874
    835875        for (int i = 0; i < nRegions; i++) {
     
    838878            snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", i);
    839879
    840             psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName);
     880            psMetadata *regionMD = psMetadataLookupPtr (&status, roAnalysis, regionName);
    841881            if (!regionMD) {
    842882                regionMD = psMetadataAlloc();
    843                 psMetadataAddMetadata (analysis, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD);
     883                psMetadataAddMetadata (roAnalysis, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD);
    844884                psFree (regionMD);
    845885            }
     
    10191059        }
    10201060
    1021         // note that all N plane are implicitly of the same type, so we convert the mask
    1022         psImage *mask = psImageCopy(NULL, psf->residuals->mask, psf->residuals->Ro->type.type);
    1023         psImageInit (psf->residuals->mask, 0);
    1024         psImageInit (psf->residuals->Rx, 0.0);
    1025         psImageInit (psf->residuals->Ry, 0.0);
    1026         switch (Nz) {
    1027           case 1: // Ro only
    1028             break;
    1029           case 2: // Ro and mask
     1061        // note that all N plane are implicitly of the same type, so we convert the mask
     1062        psImage *mask = psImageCopy(NULL, psf->residuals->mask, psf->residuals->Ro->type.type);
     1063        psImageInit (psf->residuals->mask, 0);
     1064        psImageInit (psf->residuals->Rx, 0.0);
     1065        psImageInit (psf->residuals->Ry, 0.0);
     1066        switch (Nz) {
     1067          case 1: // Ro only
     1068            break;
     1069          case 2: // Ro and mask
    10301070            if (!psFitsReadImageBuffer(mask, file->fits, fullImage, 1)) {
    10311071                psError(psErrorCodeLast(), false, "Unable to read PSF residual image.");
    10321072                return false;
    10331073            }
    1034             psImageCopy (psf->residuals->mask, mask, PM_TYPE_RESID_MASK);
    1035             break;
    1036           case 3: // Ro, Rx and Ry, no mask
     1074            psImageCopy (psf->residuals->mask, mask, PM_TYPE_RESID_MASK);
     1075            break;
     1076          case 3: // Ro, Rx and Ry, no mask
    10371077            if (!psFitsReadImageBuffer(psf->residuals->Rx, file->fits, fullImage, 1)) {
    10381078                psError(psErrorCodeLast(), false, "Unable to read PSF residual image.");
     
    10431083                return false;
    10441084            }
    1045             break;
    1046           case 4: // Ro, Rx, Ry, and mask:
     1085            break;
     1086          case 4: // Ro, Rx, Ry, and mask:
    10471087            if (!psFitsReadImageBuffer(psf->residuals->Rx, file->fits, fullImage, 1)) {
    10481088                psError(psErrorCodeLast(), false, "Unable to read PSF residual image.");
     
    10571097                return false;
    10581098            }
    1059             psImageCopy (psf->residuals->mask, mask, PM_TYPE_RESID_MASK);
    1060             break;
    1061         }
    1062         psFree (mask);
    1063     }
    1064 
    1065     psMetadataAdd (analysis, PS_LIST_TAIL, "PSPHOT.PSF",     PS_DATA_UNKNOWN,  "psphot psf", psf);
     1099            psImageCopy (psf->residuals->mask, mask, PM_TYPE_RESID_MASK);
     1100            break;
     1101        }
     1102        psFree (mask);
     1103    }
     1104
     1105    psMetadataAdd (chipAnalysis, PS_LIST_TAIL, "PSPHOT.PSF",     PS_DATA_UNKNOWN,  "psphot psf", psf);
    10661106    psFree (psf);
    10671107
Note: See TracChangeset for help on using the changeset viewer.