IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 29, 2010, 3:55:49 PM (16 years ago)
Author:
eugene
Message:

update merges from trunk

Location:
branches/eam_branches/20100225
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20100225

  • branches/eam_branches/20100225/psModules/src/objects/pmPSF_IO.c

    r27263 r27517  
    2828#include "pmConfig.h"
    2929#include "pmDetrendDB.h"
     30#include "pmErrorCodes.h"
    3031
    3132#include "pmHDU.h"
     
    122123    if (view->chip == -1) {
    123124        if (!pmPSFmodelWriteFPA(fpa, view, file, config)) {
    124             psError(PS_ERR_IO, false, "Failed to write PSF for fpa");
     125            psError(psErrorCodeLast(), false, "Failed to write PSF for fpa");
    125126            return false;
    126127        }
     
    135136    if (view->cell == -1) {
    136137        if (!pmPSFmodelWriteChip (chip, view, file, config)) {
    137             psError(PS_ERR_IO, false, "Failed to write PSF for chip");
     138            psError(psErrorCodeLast(), false, "Failed to write PSF for chip");
    138139            return false;
    139140        }
     
    141142    }
    142143
    143     psError(PS_ERR_IO, false, "PSF must be written at the chip level");
     144    psError(PM_ERR_CONFIG, true, "PSF must be written at the chip level");
    144145    return false;
    145146}
     
    158159        thisView->chip = i;
    159160        if (!pmPSFmodelWriteChip (chip, thisView, file, config)) {
    160             psError(PS_ERR_IO, false, "Failed to write PSF for %dth chip", i);
     161            psError(psErrorCodeLast(), false, "Failed to write PSF for %dth chip", i);
    161162            psFree(thisView);
    162163            return false;
     
    173174    PS_ASSERT_PTR_NON_NULL(chip, false);
    174175
    175     if (!pmPSFmodelWrite (chip->analysis, view, file, config)) {
    176         psError(PS_ERR_IO, false, "Failed to write PSF for chip");
     176    if (!pmPSFmodelWrite(chip->analysis, view, file, config)) {
     177        psError(psErrorCodeLast(), false, "Failed to write PSF for chip");
    177178        return false;
    178179    }
     
    197198    char *headName, *tableName, *residName;
    198199
    199     if (!analysis) return false;
     200    if (!analysis) {
     201        psError(PM_ERR_PROG, true, "No analysis metadata for chip.");
     202        return false;
     203    }
    200204
    201205    // select the current recipe
    202206    psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, "PSPHOT");
    203207    if (!recipe) {
    204         psError(PS_ERR_UNKNOWN, false, "missing recipe %s", "PSPHOT");
     208        psError(PM_ERR_CONFIG, false, "missing recipe %s", "PSPHOT");
    205209        return false;
    206210    }
     
    213217    // get the current header
    214218    pmFPA *fpa = pmFPAfileSuitableFPA(file, view, config, false); // Suitable FPA for writing
     219    if (!fpa) {
     220        psError(psErrorCodeLast(), false, "Unable to get FPA for writing.");
     221        return false;
     222    }
    215223    pmHDU *hdu = psMemIncrRefCounter(pmFPAviewThisHDU(view, fpa));
    216224    psFree(fpa);
    217225    if (!hdu) {
    218         psError(PS_ERR_UNKNOWN, false, "Unable to find HDU");
     226        psError(PM_ERR_CONFIG, false, "Unable to find HDU");
    219227        return false;
    220228    }
     
    234242        psMetadata *menu = psMetadataLookupMetadata(&status, file->camera, "EXTNAME.RULES");
    235243        if (!menu) {
    236             psError(PS_ERR_UNKNOWN, true, "missing EXTNAME.RULES in camera.config");
     244            psError(PM_ERR_CONFIG, true, "missing EXTNAME.RULES in camera.config");
    237245            psFree(hdu);
    238246            return false;
     
    242250        rule = psMetadataLookupStr(&status, menu, "PSF.HEAD");
    243251        if (!rule) {
    244             psError(PS_ERR_UNKNOWN, false, "missing entry for PSF.HEAD in EXTNAME.RULES in camera.config");
     252            psError(PM_ERR_CONFIG, false, "missing entry for PSF.HEAD in EXTNAME.RULES in camera.config");
    245253            psFree(hdu);
    246254            return false;
     
    251259        rule = psMetadataLookupStr(&status, menu, "PSF.TABLE");
    252260        if (!rule) {
    253             psError(PS_ERR_UNKNOWN, false, "missing entry for PSF.TABLE in EXTNAME.RULES in camera.config");
     261            psError(PM_ERR_CONFIG, false, "missing entry for PSF.TABLE in EXTNAME.RULES in camera.config");
    254262            psFree (headName);
    255263            psFree(hdu);
     
    261269        rule = psMetadataLookupStr(&status, menu, "PSF.RESID");
    262270        if (!rule) {
    263             psError(PS_ERR_UNKNOWN, false, "missing entry for PSF.RESID in EXTNAME.RULES in camera.config");
     271            psError(PM_ERR_CONFIG, false, "missing entry for PSF.RESID in EXTNAME.RULES in camera.config");
    264272            psFree (headName);
    265273            psFree (tableName);
     
    294302        }
    295303
    296         psFitsWriteBlank (file->fits, hdu->header, headName);
     304        if (!psFitsWriteBlank(file->fits, hdu->header, headName)) {
     305            psError(psErrorCodeLast(), false, "Unable to write PSF PHU.");
     306            psFree(hdu);
     307            return false;
     308        }
    297309        psTrace ("pmFPAfile", 5, "wrote ext head %s (type: %d)\n", file->filename, file->type);
    298310        file->header = hdu->header;
     
    304316    pmPSF *psf = psMetadataLookupPtr (&status, analysis, "PSPHOT.PSF");
    305317    if (!psf) {
    306         psError(PS_ERR_UNKNOWN, true, "missing PSF for this analysis metadata");
     318        psError(PM_ERR_PROG, true, "missing PSF for this analysis metadata");
    307319        psFree (tableName);
    308320        psFree (residName);
     
    322334        psMetadataAddBool (header, PS_LIST_TAIL, "ERR_PAR",  0, "Use Poisson errors in fits?", psf->poissonErrorsParams);
    323335
    324         int nPar = pmModelClassParameterCount (psf->type)    ;
     336        int nPar = pmModelClassParameterCount (psf->type);
    325337        psMetadataAdd (header, PS_LIST_TAIL, "PSF_NPAR", PS_DATA_S32, "PSF model parameter count", nPar);
    326338
     
    436448        // write an empty FITS segment if we have no PSF information
    437449        if (psfTable->n == 0) {
    438             // XXX this is probably an error (if we have a PSF, how do we have no data?)
    439             psFitsWriteBlank (file->fits, header, tableName);
     450            psError(PM_ERR_PROG, true, "No PSF data to write.");
     451            psFree(tableName);
     452            psFree(residName);
     453            psFree(psfTable);
     454            psFree(header);
     455            return false;
    440456        } else {
    441457            psTrace ("pmFPAfile", 5, "writing psf data %s\n", tableName);
    442             if (!psFitsWriteTable (file->fits, header, psfTable, tableName)) {
    443                 psError(PS_ERR_IO, false, "writing psf table data %s\n", tableName);
     458            if (!psFitsWriteTable(file->fits, header, psfTable, tableName)) {
     459                psError(psErrorCodeLast(), false, "Error writing psf table data %s\n", tableName);
    444460                psFree (tableName);
    445461                psFree (residName);
     
    459475        if (psf->residuals == NULL) {
    460476            // set some header keywords to make it clear there are no residuals?
    461             psFitsWriteBlank (file->fits, header, residName);
     477            if (!psFitsWriteBlank(file->fits, header, residName)) {
     478                psError(psErrorCodeLast(), false, "Unable to write blank PSF residual image.");
     479                psFree(residName);
     480                psFree(header);
     481                return false;
     482            }
    462483            psFree (residName);
    463484            psFree (header);
     
    486507        }
    487508
    488         psFitsWriteImageCube (file->fits, header, images, residName);
    489         psFree (images);
     509        // psFitsWriteImageCube (file->fits, header, images, residName);
     510        // psFree (images);
     511
     512        if (!psFitsWriteImageCube (file->fits, header, images, residName)) {
     513            psError(psErrorCodeLast(), false, "Unable to write PSF residuals.");
     514            psFree(images);
     515            psFree(residName);
     516            psFree(header);
     517            return false;
     518        }
     519        psFree (images);
    490520        psFree (residName);
    491521        psFree (header);
     
    498528        if (0) {
    499529            // set some header keywords to make it clear there are no residuals?
    500             psFitsWriteBlank (file->fits, header, residName);
     530            if (!psFitsWriteBlank (file->fits, header, residName)) {
     531                psError(psErrorCodeLast(), false, "Unable to write blank PSF residuals.");
     532                psFree(residName);
     533                psFree(header);
     534                return false;
     535            }
    501536            psFree (residName);
    502537            psFree (header);
     
    504539        }
    505540
    506         int DX = 65;
    507         int DY = 65;
    508 
    509         psImage *psfMosaic = psImageAlloc (DX, DY, PS_TYPE_F32);
    510         psImageInit (psfMosaic, 0.0);
    511 
    512         pmModel *modelRef = pmModelAlloc(psf->type);
    513 
    514         // use the center of the center pixel of the image
    515         float xc = 0.5*psf->fieldNx;
    516         float yc = 0.5*psf->fieldNy;
    517 
    518         // assign the x and y coords to the image center
    519         // create an object with center intensity of 1000
    520         modelRef->params->data.F32[PM_PAR_SKY] = 0;
    521         modelRef->params->data.F32[PM_PAR_I0] = 1.000;
    522         modelRef->params->data.F32[PM_PAR_XPOS] = xc;
    523         modelRef->params->data.F32[PM_PAR_YPOS] = yc;
    524 
    525         // create modelPSF from this model
    526         pmModel *model = pmModelFromPSF (modelRef, psf);
    527         if (model) {
    528             // place the reference object in the image center
    529             pmModelAddWithOffset (psfMosaic, NULL, model, PM_MODEL_OP_FULL | PM_MODEL_OP_CENTER, 0, 0.0, 0.0);
    530             psFree (model);
    531        
    532             if (false) {
    533                 // this call creates an extension with NAXIS3 = 3
    534                 psArray *images = psArrayAllocEmpty (3);
    535                 psArrayAdd (images, 1, psfMosaic);
    536                 // psArrayAdd (images, 1, psfModel);
    537                 // psArrayAdd (images, 1, psfModel);
    538 
    539                 psFitsWriteImageCube (file->fits, header, images, "PSF_MODEL");
    540                 psFree (images);
    541             } else {
    542                 // this call creates an extension with NAXIS3 = 1
    543                 // XXX need to replace PSF_MODEL with rule-based name like residName
    544                 psFitsWriteImage(file->fits, header, psfMosaic, 0, "PSF_MODEL");
    545             }
    546         }
     541        int DX = 65;
     542        int DY = 65;
     543
     544        psImage *psfMosaic = psImageAlloc (DX, DY, PS_TYPE_F32);
     545        psImageInit (psfMosaic, 0.0);
     546
     547        pmModel *modelRef = pmModelAlloc(psf->type);
     548
     549        // use the center of the center pixel of the image
     550        float xc = 0.5*psf->fieldNx;
     551        float yc = 0.5*psf->fieldNy;
     552
     553        // assign the x and y coords to the image center
     554        // create an object with center intensity of 1000
     555        modelRef->params->data.F32[PM_PAR_SKY] = 0;
     556        modelRef->params->data.F32[PM_PAR_I0] = 1.000;
     557        modelRef->params->data.F32[PM_PAR_XPOS] = xc;
     558        modelRef->params->data.F32[PM_PAR_YPOS] = yc;
     559
     560        // create modelPSF from this model
     561        pmModel *model = pmModelFromPSF (modelRef, psf);
     562        if (model) {
     563            // place the reference object in the image center
     564            pmModelAddWithOffset (psfMosaic, NULL, model, PM_MODEL_OP_FULL | PM_MODEL_OP_CENTER, 0, 0.0, 0.0);
     565            psFree (model);
     566
     567            if (false) {
     568                // this call creates an extension with NAXIS3 = 3
     569                psArray *images = psArrayAllocEmpty (3);
     570                psArrayAdd (images, 1, psfMosaic);
     571                // psArrayAdd (images, 1, psfModel);
     572                // psArrayAdd (images, 1, psfModel);
     573
     574                if (!psFitsWriteImageCube (file->fits, header, images, "PSF_MODEL")) {
     575                    psError(psErrorCodeLast(), false, "Unable to write PSF representation.");
     576                    psFree(images);
     577                    psFree(psfMosaic);
     578                    psFree(modelRef);
     579                    psFree(header);
     580                    return false;
     581                }
     582                psFree (images);
     583            } else {
     584                // this call creates an extension with NAXIS3 = 1
     585                // XXX need to replace PSF_MODEL with rule-based name like residName
     586                if (!psFitsWriteImage(file->fits, header, psfMosaic, 0, "PSF_MODEL")) {
     587                    psError(psErrorCodeLast(), false, "Unable to write PSF representation.");
     588                    psFree(psfMosaic);
     589                    psFree(modelRef);
     590                    psFree(header);
     591                    return false;
     592                }
     593            }
     594        }
    547595
    548596        psFree (psfMosaic);
     
    597645    // find the FPA phu
    598646    pmFPA *fpa = pmFPAfileSuitableFPA(file, view, config, false); // Suitable FPA for writing
     647    if (!fpa) {
     648        psError(psErrorCodeLast(), false, "Unable to build FPA to write.");
     649        return false;
     650    }
    599651    pmHDU *phu = psMemIncrRefCounter(pmFPAviewThisPHU(view, fpa));
    600652    psFree(fpa);
     
    607659        psMetadataCopy (outhead, phu->header);
    608660    } else {
    609         pmConfigConformHeader (outhead, file->format);
     661        if (!pmConfigConformHeader (outhead, file->format)) {
     662            psError(psErrorCodeLast(), false, "Unable to conform header of PSF PHU.");
     663            psFree(phu);
     664            return false;
     665        }
    610666    }
    611667    psFree(phu);
    612668
    613669    psMetadataAddBool (outhead, PS_LIST_TAIL, "EXTEND", PS_META_REPLACE, "this file has extensions", true);
    614     psFitsWriteBlank (file->fits, outhead, "");
     670    if (!psFitsWriteBlank (file->fits, outhead, "")) {
     671        psError(psErrorCodeLast(), false, "Unable to write PHU for PSF.");
     672        psFree(outhead);
     673        return false;
     674    }
    615675    file->wrote_phu = true;
    616676
     
    642702    }
    643703
    644     psError(PS_ERR_IO, false, "PSF must be read at the chip level");
     704    psError(PM_ERR_CONFIG, true, "PSF must be read at the chip level");
    645705    return false;
    646706}
     
    669729
    670730    if (!pmPSFmodelRead (chip->analysis, view, file, config)) {
    671         psError(PS_ERR_IO, false, "Failed to write PSF for chip");
     731        psError(psErrorCodeLast(), false, "Failed to write PSF for chip");
    672732        return false;
    673733    }
     
    692752    psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, "PSPHOT");
    693753    if (!recipe) {
    694         psError(PS_ERR_UNKNOWN, false, "missing recipe %s", "PSPHOT");
     754        psError(PM_ERR_CONFIG, false, "missing recipe %s", "PSPHOT");
    695755        return false;
    696756    }
     
    699759    psMetadata *menu = psMetadataLookupMetadata(&status, file->camera, "EXTNAME.RULES");
    700760    if (!menu) {
    701         psError(PS_ERR_UNKNOWN, true, "missing EXTNAME.RULES in camera.config");
     761        psError(PM_ERR_CONFIG, true, "missing EXTNAME.RULES in camera.config");
    702762        return false;
    703763    }
     
    705765    rule = psMetadataLookupStr(&status, menu, "PSF.TABLE");
    706766    if (!rule) {
    707         psError(PS_ERR_UNKNOWN, true, "missing entry for PSF.TABLE in EXTNAME.RULES in camera.config");
     767        psError(PM_ERR_CONFIG, true, "missing entry for PSF.TABLE in EXTNAME.RULES in camera.config");
    708768        return false;
    709769    }
     
    712772    rule = psMetadataLookupStr(&status, menu, "PSF.RESID");
    713773    if (!rule) {
    714         psError(PS_ERR_UNKNOWN, true, "missing entry for PSF.RESID in EXTNAME.RULES in camera.config");
     774        psError(PM_ERR_CONFIG, true, "missing entry for PSF.RESID in EXTNAME.RULES in camera.config");
    715775        return false;
    716776    }
     
    720780    // advance to the table data extension
    721781    // since we have read the IMAGE header, the TABLE header should exist
    722     if (!psFitsMoveExtName (file->fits, tableName)) {
    723         psAbort("cannot find data extension %s in %s", tableName, file->filename);
     782    if (!psFitsMoveExtName(file->fits, tableName)) {
     783        psError(psErrorCodeLast(), false, "cannot find data extension %s in %s", tableName, file->filename);
     784        return false;
    724785    }
    725786
    726787    // load the PSF model table header
    727788    header = psFitsReadHeader (NULL, file->fits);
    728     if (!header) psAbort("cannot read table header");
     789    if (!header) {
     790        psError(psErrorCodeLast(), false, "Cannot read PSF table header.");
     791        return false;
     792    }
    729793
    730794    pmPSFOptions *options = pmPSFOptionsAlloc();
     
    838902        char *modeName = psMetadataLookupStr (&status, header, name);
    839903        if (!status) {
    840             psError(PS_ERR_UNKNOWN, true, "inconsistent PSF header: NX & NY defined for PAR %d, but not MD", i);
     904            psError(PM_ERR_PROG, true, "inconsistent PSF header: NX & NY defined for PAR %d, but not MD", i);
    841905            return false;
    842906        }
     
    872936    // read the raw table data
    873937    psArray *table = psFitsReadTable (file->fits);
     938    if (!table) {
     939        psError(psErrorCodeLast(), false, "Unable to read PSF table.");
     940        psFree(header);
     941        return false;
     942    }
    874943
    875944    // fill in the matching psf->params entries
     
    916985    // since we have read the IMAGE header, the TABLE header should exist
    917986    if (!psFitsMoveExtName (file->fits, imageName)) {
    918         psAbort("cannot find data extension %s in %s", imageName, file->filename);
     987        psError(psErrorCodeLast(), false, "Cannot find PSF data extension %s in %s",
     988                imageName, file->filename);
     989        return false;
    919990    }
    920991
    921992    header = psFitsReadHeader (NULL, file->fits);
     993    if (!header) {
     994        psError(psErrorCodeLast(), false, "Unable to read PSF header.");
     995        return false;
     996    }
    922997    int Naxis = psMetadataLookupS32 (&status, header, "NAXIS");
    923998    if (Naxis != 0) {
     
    9391014
    9401015        psRegion fullImage = {0, 0, 0, 0};
    941         psFitsReadImageBuffer(psf->residuals->Ro, file->fits, fullImage, 0); // Desired pixels
     1016        if (!psFitsReadImageBuffer(psf->residuals->Ro, file->fits, fullImage, 0)) {
     1017            psError(psErrorCodeLast(), false, "Unable to read PSF residual image.");
     1018            return false;
     1019        }
    9421020
    9431021        // note that all N plane are implicitly of the same type, so we convert the mask
     
    9541032            break;
    9551033          case 3: // Ro, Rx and Ry, no mask
    956             psFitsReadImageBuffer(psf->residuals->Rx, file->fits, fullImage, 1); // Desired pixels
    957             psFitsReadImageBuffer(psf->residuals->Ry, file->fits, fullImage, 2); // Desired pixels
     1034            if (!psFitsReadImageBuffer(psf->residuals->Rx, file->fits, fullImage, 1)) {
     1035                psError(psErrorCodeLast(), false, "Unable to read PSF residual image.");
     1036                return false;
     1037            }
     1038            if (!psFitsReadImageBuffer(psf->residuals->Ry, file->fits, fullImage, 2)) {
     1039                psError(psErrorCodeLast(), false, "Unable to read PSF residual image.");
     1040                return false;
     1041            }
    9581042            break;
    9591043          case 4: // Ro, Rx, Ry, and mask:
Note: See TracChangeset for help on using the changeset viewer.