IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 22, 2007, 2:55:49 PM (19 years ago)
Author:
magnier
Message:

adjusted pmModel.h to allow pmModel to use functions which use pmModel
as an argument.

adjusted the order of the pmPSF.h entries to allow that as an argument
as well

changed pmPSF I/O functions to load/save the psf on the
chip->analysis, not the readout->analysis

fixed the modelRadius function for PGAUSS

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20070817/psModules/src/objects/pmPSF_IO.c

    r14544 r14612  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.20.4.1 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-08-17 21:01:59 $
     8 *  @version $Revision: 1.20.4.2 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-08-23 00:55:49 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4040#include "pmGrowthCurve.h"
    4141#include "pmResiduals.h"
     42#include "pmPSF.h"
    4243#include "pmModel.h"
    43 #include "pmPSF.h"
    4444#include "pmPSF_IO.h"
    4545#include "pmSource.h"
     
    4747#include "pmSourceIO.h"
    4848
    49 bool pmFPAviewCheckDataStatusForPSFmodel (const pmFPAview *view, const pmFPAfile *file)
     49bool pmPSFmodelCheckDataStatusForView (const pmFPAview *view, const pmFPAfile *file)
    5050{
    5151    pmFPA *fpa = file->fpa;
    5252
    5353    if (view->chip == -1) {
    54         bool exists = pmFPACheckDataStatusForPSFmodel (fpa);
     54        bool exists = pmPSFmodelCheckDataStatusForFPA (fpa);
    5555        return exists;
    5656    }
     
    6262
    6363    if (view->cell == -1) {
    64         bool exists = pmChipCheckDataStatusForPSFmodel (chip);
     64        bool exists = pmPSFmodelCheckDataStatusForChip (chip);
    6565        return exists;
    6666    }
     
    6969        return false;
    7070    }
    71     pmCell *cell = chip->cells->data[view->cell];
    72 
    73     if (view->readout == -1) {
    74         bool exists = pmCellCheckDataStatusForPSFmodel (cell);
    75         return exists;
    76     }
    77 
    78     if (view->readout >= cell->readouts->n) {
    79         psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouds->n == %ld", view->readout, cell->readouts->n);
    80         return false;
    81     }
    82     pmReadout *readout = cell->readouts->data[view->readout];
    83 
    84     return pmReadoutCheckDataStatusForPSFmodel (readout);
    85 }
    86 
    87 bool pmFPACheckDataStatusForPSFmodel (const pmFPA *fpa) {
     71    psError(PS_ERR_IO, false, "PSF only valid at the chip level");
     72    return false;
     73}
     74
     75bool pmPSFmodelCheckDataStatusForFPA (const pmFPA *fpa) {
    8876
    8977    for (int i = 0; i < fpa->chips->n; i++) {
    9078        pmChip *chip = fpa->chips->data[i];
    9179        if (!chip) continue;
    92         if (pmChipCheckDataStatusForPSFmodel (chip)) return true;
     80        if (pmPSFmodelCheckDataStatusForChip (chip)) return true;
    9381    }
    9482    return false;
    9583}
    9684
    97 bool pmChipCheckDataStatusForPSFmodel (const pmChip *chip) {
    98 
    99     for (int i = 0; i < chip->cells->n; i++) {
    100         pmCell *cell = chip->cells->data[i];
    101         if (!cell) continue;
    102         if (pmCellCheckDataStatusForPSFmodel (cell)) return true;
    103     }
    104     return false;
    105 }
    106 
    107 bool pmCellCheckDataStatusForPSFmodel (const pmCell *cell) {
    108 
    109     for (int i = 0; i < cell->readouts->n; i++) {
    110         pmReadout *readout = cell->readouts->data[i];
    111         if (!readout) continue;
    112         if (pmReadoutCheckDataStatusForPSFmodel (readout)) return true;
    113     }
    114     return false;
    115 }
    116 
    117 bool pmReadoutCheckDataStatusForPSFmodel (const pmReadout *readout) {
     85bool pmPSFmodelCheckDataStatusForChip (const pmChip *chip) {
    11886
    11987    bool status;
    12088
    12189    // select the psf of interest
    122     pmPSF *psf = psMetadataLookupPtr(&status, readout->analysis, "PSPHOT.PSF");
     90    pmPSF *psf = psMetadataLookupPtr(&status, chip->analysis, "PSPHOT.PSF");
    12391    return psf ? true : false;
    12492}
    12593
    126 bool pmFPAviewWritePSFmodel (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     94bool pmPSFmodelWriteForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    12795{
    12896
     
    13098
    13199    if (view->chip == -1) {
    132         if (!pmFPAWritePSFmodel(fpa, view, file, config)) {
     100        if (!pmPSFmodelWriteFPA(fpa, view, file, config)) {
    133101            psError(PS_ERR_IO, false, "Failed to write PSF for fpa");
    134102            return false;
     
    143111
    144112    if (view->cell == -1) {
    145         if (!pmChipWritePSFmodel (chip, view, file, config)) {
     113        if (!pmPSFmodelWriteChip (chip, view, file, config)) {
    146114            psError(PS_ERR_IO, false, "Failed to write PSF for chip");
    147115            return false;
     
    150118    }
    151119
    152     if (view->cell >= chip->cells->n) {
    153         return false;
    154     }
    155     pmCell *cell = chip->cells->data[view->cell];
    156 
    157     if (view->readout == -1) {
    158         if (!pmCellWritePSFmodel (cell, view, file, config)) {
    159             psError(PS_ERR_IO, false, "Failed to write PSF for cell");
    160             return false;
    161         }
    162         return true;
    163     }
    164 
    165     if (view->readout >= cell->readouts->n) {
    166         return false;
    167     }
    168     pmReadout *readout = cell->readouts->data[view->readout];
    169 
    170     if (!pmReadoutWritePSFmodel (readout, view, file, config)) {
    171         psError(PS_ERR_IO, false, "Failed to write PSF for readout");
    172         return false;
    173     }
    174     return true;
     120    psError(PS_ERR_IO, false, "PSF must be written at the chip level");
     121    return false;
    175122}
    176123
    177124// read in all chip-level PSFmodel files for this FPA
    178 bool pmFPAWritePSFmodel (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     125bool pmPSFmodelWriteFPA (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    179126{
    180127
    181128    for (int i = 0; i < fpa->chips->n; i++) {
    182129        pmChip *chip = fpa->chips->data[i];
    183         if (!pmChipWritePSFmodel (chip, view, file, config)) {
     130        if (!pmPSFmodelWriteChip (chip, view, file, config)) {
    184131            psError(PS_ERR_IO, false, "Failed to write PSF for %dth chip", i);
    185132            return false;
     
    190137
    191138// read in all cell-level PSFmodel files for this chip
    192 bool pmChipWritePSFmodel (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    193 {
    194     for (int i = 0; i < chip->cells->n; i++) {
    195         pmCell *cell = chip->cells->data[i];
    196         if (!pmCellWritePSFmodel (cell, view, file, config)) {
    197             psError(PS_ERR_IO, false, "Failed to write PSF for %dth cell", i);
    198             return false;
    199         }
     139bool pmPSFmodelWriteChip (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     140{
     141    if (!pmPSFmodelWrite (chip->analysis, view, file, config)) {
     142        psError(PS_ERR_IO, false, "Failed to write PSF for chip");
     143        return false;
    200144    }
    201145    return true;
    202146}
    203147
    204 // read in all readout-level PSFmodel files for this cell
    205 bool pmCellWritePSFmodel (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    206 {
    207     for (int i = 0; i < cell->readouts->n; i++) {
    208         pmReadout *readout = cell->readouts->data[i];
    209         if (!pmReadoutWritePSFmodel (readout, view, file, config)) {
    210             psError(PS_ERR_IO, false, "Failed to write PSF for %dth readout", i);
    211             return false;
    212         }
    213     }
    214     return true;
    215 }
    216 
    217 // for each Readout (ie, analysed image), we write out
     148// for a pmPSF supplied on the analysis metadata, we write out
    218149// - image header        : FITS Image NAXIS = 0
    219150// - psf table (+header) : FITS Table
    220151// - psf resid (+header) : FITS Image
    221152// if needed, we also write out a PHU blank header
    222 bool pmReadoutWritePSFmodel (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     153bool pmPSFmodelWrite (psMetadata *analysis, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    223154{
    224155    bool status;
    225156    pmHDU *hdu;
    226157    char *headName, *tableName, *residName;
     158
     159    if (!analysis) return false;
    227160
    228161    // write a PHU? (only if input image is MEF)
     
    300233
    301234    // select the psf of interest
    302     pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
     235    pmPSF *psf = psMetadataLookupPtr (&status, analysis, "PSPHOT.PSF");
    303236    if (!psf) {
    304         psError(PS_ERR_UNKNOWN, true, "missing PSF for this readout");
     237        psError(PS_ERR_UNKNOWN, true, "missing PSF for this analysis metadata");
    305238        psFree (tableName);
    306239        psFree (residName);
     
    324257        for (int i = 0; i < nPar; i++) {
    325258            char name[9];
    326             psPolynomial2D *poly = psf->params_NEW->data[i];
     259            psPolynomial2D *poly = psf->params->data[i];
    327260            if (poly == NULL) continue;
    328261            snprintf (name, 9, "PAR%02d_NX", i);
     
    344277        psArray *psfTable = psArrayAllocEmpty (100);
    345278        for (int i = 0; i < nPar; i++) {
    346             psPolynomial2D *poly = psf->params_NEW->data[i];
     279            psPolynomial2D *poly = psf->params->data[i];
    347280            if (poly == NULL) continue; // skip unset parameters (eg, XPOS)
    348281            for (int ix = 0; ix <= poly->nX; ix++) {
     
    445378
    446379// if this file needs to have a PHU written out, write one
    447 bool pmPSF_WritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) {
     380bool pmPSFmodelWritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) {
    448381
    449382    // not needed if already written
     
    487420}
    488421
    489 bool pmFPAviewReadPSFmodel (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     422bool pmPSFmodelReadForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    490423{
    491424
     
    493426
    494427    if (view->chip == -1) {
    495         return pmFPAReadPSFmodel(fpa, view, file, config);
     428        return pmPSFmodelReadFPA(fpa, view, file, config);
    496429    }
    497430
     
    502435
    503436    if (view->cell == -1) {
    504         return pmChipReadPSFmodel(chip, view, file, config);
    505     }
    506 
    507     if (view->cell >= chip->cells->n) {
    508         psAbort("Programming error: view does not apply to FPA.");
    509     }
    510     pmCell *cell = chip->cells->data[view->cell];
    511 
    512     if (view->readout == -1) {
    513         return pmCellReadPSFmodel(cell, view, file, config);
    514     }
    515 
    516     if (view->readout >= cell->readouts->n) {
    517         psAbort("Programming error: view does not apply to FPA.");
    518     }
    519     pmReadout *readout = cell->readouts->data[view->readout];
    520 
    521     return pmReadoutReadPSFmodel(readout, view, file, config);
     437        return pmPSFmodelReadChip(chip, view, file, config);
     438    }
     439
     440    psError(PS_ERR_IO, false, "PSF must be read at the chip level");
     441    return false;
    522442}
    523443
    524444// read in all chip-level PSFmodel files for this FPA
    525 bool pmFPAReadPSFmodel (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     445bool pmPSFmodelReadFPA (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    526446{
    527447    bool success = true;                // Was everything successful?
    528448    for (int i = 0; i < fpa->chips->n; i++) {
    529449        pmChip *chip = fpa->chips->data[i];
    530         success &= pmChipReadPSFmodel(chip, view, file, config);
     450        success &= pmPSFmodelReadChip(chip, view, file, config);
    531451    }
    532452    return success;
     
    534454
    535455// read in all cell-level PSFmodel files for this chip
    536 bool pmChipReadPSFmodel (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    537 {
    538     bool success = true;                // Was everything successful?
    539     for (int i = 0; i < chip->cells->n; i++) {
    540         pmCell *cell = chip->cells->data[i];
    541         success &= pmCellReadPSFmodel (cell, view, file, config);
    542     }
    543     return success;
    544 }
    545 
    546 // read in all readout-level PSFmodel files for this cell
    547 bool pmCellReadPSFmodel (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    548 {
    549     bool success = true;                // Was everything successful?
    550     for (int i = 0; i < cell->readouts->n; i++) {
    551         pmReadout *readout = cell->readouts->data[i];
    552         success &= pmReadoutReadPSFmodel(readout, view, file, config);
    553     }
    554     return success;
     456bool pmPSFmodelReadChip (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     457{
     458    if (!pmPSFmodelRead (chip->analysis, view, file, config)) {
     459        psError(PS_ERR_IO, false, "Failed to write PSF for chip");
     460        return false;
     461    }
     462    return true;
    555463}
    556464
    557465// for each Readout (ie, analysed image), we write out: header + table with PSF model parameters,
    558466// and header + image for the PSF residual images
    559 bool pmReadoutReadPSFmodel(pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     467bool pmPSFmodelRead (psMetadata *analysis, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    560468{
    561469    bool status;
     
    627535            return false;
    628536        }
    629         psf->params_NEW->data[i] = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXorder, nYorder);
     537        psf->params->data[i] = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXorder, nYorder);
    630538    }
    631539
     
    650558        // XXX sanity check here
    651559
    652         psPolynomial2D *poly = psf->params_NEW->data[iPar];
     560        psPolynomial2D *poly = psf->params->data[iPar];
    653561        if (poly == NULL) {
    654562            psError(PS_ERR_UNKNOWN, true, "values for parameter %d, but missing NX", iPar);
     
    698606    }
    699607
    700     psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.PSF",     PS_DATA_UNKNOWN,  "psphot psf", psf);
     608    psMetadataAdd (analysis, PS_LIST_TAIL, "PSPHOT.PSF",     PS_DATA_UNKNOWN,  "psphot psf", psf);
    701609    psFree (psf);
    702610
     
    708616}
    709617
    710 /************ old support functions, deprecate? **************/
    711 
     618// create a psMetadata representation (human-readable) of a psf model
    712619psMetadata *pmPSFtoMetadata (psMetadata *metadata, pmPSF *psf)
    713620{
     
    724631
    725632    for (int i = 0; i < nPar; i++) {
    726         psPolynomial2D *poly = psf->params_NEW->data[i];
     633        psPolynomial2D *poly = psf->params->data[i];
    727634        if (poly == NULL)
    728635            continue;
     
    742649}
    743650
     651// parse a psMetadata representation (human-readable) of a psf model
    744652pmPSF *pmPSFfromMetadata (psMetadata *metadata)
    745653{
     
    770678            continue;
    771679        psPolynomial2D *poly = psPolynomial2DfromMetadata (folder);
    772         psFree (psf->params_NEW->data[i]);
    773         psf->params_NEW->data[i] = poly;
     680        psFree (psf->params->data[i]);
     681        psf->params->data[i] = poly;
    774682    }
    775683    sprintf (keyword, "APTREND");
     
    789697    return (psf);
    790698}
    791 
    792 // read in all readout-level Objects files for this cell
    793 bool pmReadoutWritePSFmodel_Config (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    794 {
    795     bool status;
    796     char *filename;
    797     char *realname;
    798 
    799     pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
    800 
    801     switch (file->type) {
    802       case PM_FPA_FILE_PSF:
    803         filename = pmFPAfileNameFromRule (file->filerule, file, view);
    804         bool create = file->mode == PM_FPA_MODE_WRITE ? true : false;
    805         realname = pmConfigConvertFilename (filename, config, create);
    806 
    807         psMetadata *psfData = pmPSFtoMetadata (NULL, psf);
    808         psMetadataConfigWrite (psfData, realname);
    809         psFree (psfData);
    810         psFree (realname);
    811         psFree (filename);
    812         return true;
    813 
    814       default:
    815         fprintf (stderr, "warning: type mismatch\n");
    816         break;
    817     }
    818     return false;
    819 }
    820 
    821 // read in all readout-level Objects files for this cell
    822 bool pmReadoutReadPSFmodel_Config (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    823 {
    824 
    825     unsigned int Nfail;
    826     char *filename;
    827     char *realname;
    828 
    829     switch (file->type) {
    830       case PM_FPA_FILE_PSF:
    831         filename = pmFPAfileNameFromRule (file->filerule, file, view);
    832         bool create = file->mode == PM_FPA_MODE_WRITE ? true : false;
    833         realname = pmConfigConvertFilename (filename, config, create);
    834 
    835         psMetadata *psfData = psMetadataConfigRead(NULL, &Nfail, realname, FALSE);
    836         pmPSF *psf = pmPSFfromMetadata (psfData);
    837         psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN, "psphot psf", psf);
    838 
    839         psFree (psf);
    840         psFree (psfData);
    841         psFree (realname);
    842         psFree (filename);
    843 
    844         return true;
    845 
    846       default:
    847         fprintf (stderr, "warning: type mismatch\n");
    848         break;
    849     }
    850     return false;
    851 }
    852 
Note: See TracChangeset for help on using the changeset viewer.