IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13773


Ignore:
Timestamp:
Jun 12, 2007, 5:27:11 PM (19 years ago)
Author:
Paul Price
Message:

Read/write concepts when reading/writing objects --- this way the
correct values should be placed in the header.

Adding a hack to add important (required for DVO addstar) header
values to the PHU when a MEF is written with all the objects from
multiple chips that were in their own files (e.g., GPC, SIMMOSAIC).
This uses the BLANK.HEADERS metadata within the camera configuration
file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/pmSourceIO.c

    r13670 r13773  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.42 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-06-06 02:23:33 $
     5 *  @version $Revision: 1.43 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-06-13 03:27:11 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4040#include "pmSourceIO.h"
    4141
     42
     43#define BLANK_HEADERS "BLANK.HEADERS"   // Name of metadata in camera configuration containing header names
     44                                        // for putting values into a blank PHU
     45
    4246// translations between psphot object types and dophot object types
    4347int pmSourceGetDophotType (pmSource *source)
     
    164168    *thisView = *view;
    165169
     170    if (!pmConceptsWriteFPA(fpa, PM_CONCEPT_SOURCE_HEADER, true, NULL)) {
     171        psError(PS_ERR_IO, false, "Unable to write concepts for fpa");
     172        psFree(thisView);
     173        return false;
     174    }
    166175    for (int i = 0; i < fpa->chips->n; i++) {
    167176        pmChip *chip = fpa->chips->data[i];
    168         thisView->chip = i;
     177        thisView->chip = i;
    169178        if (!pmChipWriteObjects (chip, thisView, file, config)) {
    170179            psError(PS_ERR_IO, false, "Failed to write %dth chip", i);
    171             psFree (thisView);
     180            psFree (thisView);
    172181            return false;
    173182        }
     
    183192    *thisView = *view;
    184193
     194    if (!pmConceptsWriteChip(chip, PM_CONCEPT_SOURCE_HEADER, true, true, NULL)) {
     195        psError(PS_ERR_IO, false, "Unable to write concepts for chip");
     196        psFree(thisView);
     197        return false;
     198    }
    185199    for (int i = 0; i < chip->cells->n; i++) {
    186 
    187200        pmCell *cell = chip->cells->data[i];
    188         thisView->cell = i;
     201        thisView->cell = i;
    189202        if (!pmCellWriteObjects (cell, thisView, file, config)) {
    190203            psError(PS_ERR_IO, false, "Failed to write %dth cell", i);
    191             psFree (thisView);
     204            psFree (thisView);
    192205            return false;
    193206        }
     
    203216    *thisView = *view;
    204217
     218    if (!pmConceptsWriteCell(cell, PM_CONCEPT_SOURCE_HEADER, true, NULL)) {
     219        psError(PS_ERR_IO, false, "Unable to write concepts for cell");
     220        psFree(thisView);
     221        return false;
     222    }
    205223    for (int i = 0; i < cell->readouts->n; i++) {
    206 
    207224        pmReadout *readout = cell->readouts->data[i];
    208         thisView->readout = i;
     225        thisView->readout = i;
    209226        if (!pmReadoutWriteObjects (readout, thisView, file, config)) {
    210227            psError(PS_ERR_IO, false, "Failed to write %dth readout", i);
    211             psFree (thisView);
     228            psFree (thisView);
    212229            return false;
    213230        }
     
    309326                    psMetadataAddStr(outhead, PS_LIST_TAIL, fpaNameHdr, PS_META_REPLACE, "FPA name", fpaName);
    310327                }
     328
     329                // We need to get some FPA-level concepts in there
     330                // This is a hack, not very pretty.  But then, so is writing the FPA in this manner without
     331                // using the pmFPAMosaic functions....
     332
     333                psMetadata *headers = psMetadataLookupMetadata(NULL, file->fpa->camera,
     334                                                               BLANK_HEADERS); // Header names
     335                if (!headers) {
     336                    psError(PS_ERR_UNEXPECTED_NULL, false,
     337                            "Unable to find %s metadata within camera configuration", BLANK_HEADERS);
     338                    psFree(outhead);
     339                    return false;
     340                }
     341
     342                {
     343                    const char *mjdName = psMetadataLookupStr(NULL, headers, "FPA.TIME"); // Header name
     344                    if (!mjdName || strlen(mjdName) == 0) {
     345                        psError(PS_ERR_UNEXPECTED_NULL, false,
     346                                "Unable to find FPA.TIME in %s within camera configuration.", BLANK_HEADERS);
     347                        psFree(outhead);
     348                        return false;
     349                    }
     350                    psTime *time = psMetadataLookupTime(NULL, file->fpa->concepts,
     351                                                        "FPA.TIME"); // Time of observation
     352                    double mjd = psTimeToMJD(time); // The MJD of observation
     353                    psMetadataAddF64(outhead, PS_LIST_TAIL, mjdName, PS_META_REPLACE,
     354                                     "Time of observation", mjd);
     355                }
     356
     357                {
     358                    const char *expName = psMetadataLookupStr(NULL, headers, "FPA.EXPOSURE"); // Header name
     359                    if (!expName || strlen(expName) == 0) {
     360                        psError(PS_ERR_UNEXPECTED_NULL, false,
     361                                "Unable to find FPA.EXPOSURE in %s within camera configuration.",
     362                                BLANK_HEADERS);
     363                        psFree(outhead);
     364                        return false;
     365                    }
     366                    float exptime = psMetadataLookupF32(NULL, file->fpa->concepts,
     367                                                        "FPA.EXPOSURE"); // Exposure time
     368                    psMetadataAddF32(outhead, PS_LIST_TAIL, expName, PS_META_REPLACE,
     369                                     "Exposure time (sec)", exptime);
     370                }
     371
     372                {
     373                    const char *amName = psMetadataLookupStr(NULL, headers, "FPA.AIRMASS"); // Header name
     374                    if (!amName || strlen(amName) == 0) {
     375                        psError(PS_ERR_UNEXPECTED_NULL, false,
     376                                "Unable to find FPA.AIRMASS in %s within camera configuration.",
     377                                BLANK_HEADERS);
     378                        psFree(outhead);
     379                        return false;
     380                    }
     381                    float airmass = psMetadataLookupF32(NULL, file->fpa->concepts, "FPA.AIRMASS"); // Airmass
     382                    psMetadataAddF32(outhead, PS_LIST_TAIL, amName, PS_META_REPLACE,
     383                                     "Observation airmass", airmass);
     384                }
     385
    311386            }
    312387
     
    324399        }
    325400
    326         // define the EXTNAME values for the different data segments:
    327         {
    328             // lookup the EXTNAME values used for table data and image header segments
    329             char *rule = NULL;
    330 
    331             // Menu of EXTNAME rules
    332             psMetadata *menu = psMetadataLookupMetadata(&status, file->camera, "EXTNAME.RULES");
    333             if (!menu) {
    334                 psError(PS_ERR_UNKNOWN, true, "missing EXTNAME.RULES in camera.config");
    335                 return false;
    336             }
    337 
    338             // EXTNAME for image header
    339             rule = psMetadataLookupStr(&status, menu, "CMF.HEAD");
    340             if (!rule) {
    341                 psError(PS_ERR_UNKNOWN, true, "missing entry for CMF.HEAD in EXTNAME.RULES in camera.config");
    342                 return false;
    343             }
    344             headname = pmFPAfileNameFromRule (rule, file, view);
    345 
    346             // EXTNAME for table data
    347             rule = psMetadataLookupStr(&status, menu, "CMF.DATA");
    348             if (!rule) {
    349                 psError(PS_ERR_UNKNOWN, true, "missing entry for CMF.DATA in EXTNAME.RULES in camera.config");
    350                 return false;
    351             }
    352             dataname = pmFPAfileNameFromRule (rule, file, view);
    353         }
    354 
    355         // write out the IMAGE header segment
    356         {
    357             // this header block is new, write it to disk
    358             if (hdu->header != file->header) {
    359                 // add EXTNAME, EXTHEAD, EXTTYPE to header
    360                 psMetadataAddStr (hdu->header, PS_LIST_TAIL, "EXTDATA", PS_META_REPLACE, "name of table extension", dataname);
    361                 psMetadataAddStr (hdu->header, PS_LIST_TAIL, "EXTTYPE", PS_META_REPLACE, "extension type", "IMAGE");
    362                 if (!file->phu) {
    363                     // this hdu->header acts as the PHU: set EXTEND to be true
    364                     psMetadataAddBool (hdu->header, PS_LIST_TAIL, "EXTEND", PS_META_REPLACE, "this file has extensions", true);
    365                 }
    366 
    367                 // save psphot and psastro metadata in the image and table headers
    368                 updates = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.HEADER");
    369                 if (updates) {
    370                     psMetadataCopy (hdu->header, updates);
    371                 }
    372                 updates = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.HEADER");
    373                 if (updates) {
    374                     psMetadataCopy (hdu->header, updates);
    375                 }
    376 
    377                 psFitsWriteBlank (file->fits, hdu->header, headname);
    378                 psTrace ("pmFPAfile", 5, "wrote ext head %s (type: %d)\n", file->filename, file->type);
    379                 file->header = hdu->header;
    380             }
    381         }
    382 
    383         // write out the TABLE data segment
    384         {
    385             // create a header to hold the output data
    386             outhead = psMetadataAlloc ();
    387 
    388             // determine the output table format
    389             psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "PSPHOT");
    390             if (!status) {
    391                 psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data");
    392                 return false;
    393             }
    394             exttype = psMemIncrRefCounter (psMetadataLookupStr(&status, recipe, "OUTPUT.FORMAT"));
    395             if (!exttype) {
    396                 exttype = psStringCopy ("SMPDATA");
    397             }
    398 
    399             // write the links to the image header
    400             psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTHEAD", PS_META_REPLACE, "name of image extension w/", headname);
    401             psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTTYPE", PS_META_REPLACE, "extension type", exttype);
    402             psFree (exttype);
    403 
    404             // XXX these are case-sensitive since the EXTYPE is case-sensitive
    405             status = false;
    406             if (!strcmp (exttype, "SMPDATA")) {
    407                 status = pmSourcesWrite_SMPDATA (file->fits, sources, file->header, outhead, dataname);
    408             }
    409             if (!strcmp (exttype, "PS1_DEV_0")) {
    410                 status = pmSourcesWrite_PS1_DEV_0 (file->fits, sources, file->header, outhead, dataname);
    411             }
    412 
    413             if (!status) {
    414                 psError(PS_ERR_IO, false, "writing CMF data to %s with format %s\n", file->filename, exttype);
    415                 psFree (headname);
    416                 psFree (dataname);
    417                 psFree (outhead);
    418                 return false;
    419             }
    420         }
     401        // define the EXTNAME values for the different data segments:
     402        {
     403            // lookup the EXTNAME values used for table data and image header segments
     404            char *rule = NULL;
     405
     406            // Menu of EXTNAME rules
     407            psMetadata *menu = psMetadataLookupMetadata(&status, file->camera, "EXTNAME.RULES");
     408            if (!menu) {
     409                psError(PS_ERR_UNKNOWN, true, "missing EXTNAME.RULES in camera.config");
     410                return false;
     411            }
     412
     413            // EXTNAME for image header
     414            rule = psMetadataLookupStr(&status, menu, "CMF.HEAD");
     415            if (!rule) {
     416                psError(PS_ERR_UNKNOWN, true, "missing entry for CMF.HEAD in EXTNAME.RULES in camera.config");
     417                return false;
     418            }
     419            headname = pmFPAfileNameFromRule (rule, file, view);
     420
     421            // EXTNAME for table data
     422            rule = psMetadataLookupStr(&status, menu, "CMF.DATA");
     423            if (!rule) {
     424                psError(PS_ERR_UNKNOWN, true, "missing entry for CMF.DATA in EXTNAME.RULES in camera.config");
     425                return false;
     426            }
     427            dataname = pmFPAfileNameFromRule (rule, file, view);
     428        }
     429
     430        // write out the IMAGE header segment
     431        {
     432            // this header block is new, write it to disk
     433            if (hdu->header != file->header) {
     434                // add EXTNAME, EXTHEAD, EXTTYPE to header
     435                psMetadataAddStr (hdu->header, PS_LIST_TAIL, "EXTDATA", PS_META_REPLACE, "name of table extension", dataname);
     436                psMetadataAddStr (hdu->header, PS_LIST_TAIL, "EXTTYPE", PS_META_REPLACE, "extension type", "IMAGE");
     437                if (!file->phu) {
     438                    // this hdu->header acts as the PHU: set EXTEND to be true
     439                    psMetadataAddBool (hdu->header, PS_LIST_TAIL, "EXTEND", PS_META_REPLACE, "this file has extensions", true);
     440                }
     441
     442                // save psphot and psastro metadata in the image and table headers
     443                updates = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.HEADER");
     444                if (updates) {
     445                    psMetadataCopy (hdu->header, updates);
     446                }
     447                updates = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.HEADER");
     448                if (updates) {
     449                    psMetadataCopy (hdu->header, updates);
     450                }
     451
     452                psFitsWriteBlank (file->fits, hdu->header, headname);
     453                psTrace ("pmFPAfile", 5, "wrote ext head %s (type: %d)\n", file->filename, file->type);
     454                file->header = hdu->header;
     455            }
     456        }
     457
     458        // write out the TABLE data segment
     459        {
     460            // create a header to hold the output data
     461            outhead = psMetadataAlloc ();
     462
     463            // determine the output table format
     464            psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "PSPHOT");
     465            if (!status) {
     466                psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data");
     467                return false;
     468            }
     469            exttype = psMemIncrRefCounter (psMetadataLookupStr(&status, recipe, "OUTPUT.FORMAT"));
     470            if (!exttype) {
     471                exttype = psStringCopy ("SMPDATA");
     472            }
     473
     474            // write the links to the image header
     475            psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTHEAD", PS_META_REPLACE, "name of image extension w/", headname);
     476            psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTTYPE", PS_META_REPLACE, "extension type", exttype);
     477            psFree (exttype);
     478
     479            // XXX these are case-sensitive since the EXTYPE is case-sensitive
     480            status = false;
     481            if (!strcmp (exttype, "SMPDATA")) {
     482                status = pmSourcesWrite_SMPDATA (file->fits, sources, file->header, outhead, dataname);
     483            }
     484            if (!strcmp (exttype, "PS1_DEV_0")) {
     485                status = pmSourcesWrite_PS1_DEV_0 (file->fits, sources, file->header, outhead, dataname);
     486            }
     487
     488            if (!status) {
     489                psError(PS_ERR_IO, false, "writing CMF data to %s with format %s\n", file->filename, exttype);
     490                psFree (headname);
     491                psFree (dataname);
     492                psFree (outhead);
     493                return false;
     494            }
     495        }
    421496
    422497        psTrace ("pmFPAfile", 5, "wrote ext data %s (type: %d)\n", file->filename, file->type);
     
    483558    for (int i = 0; i < fpa->chips->n; i++) {
    484559        pmChip *chip = fpa->chips->data[i];
    485         thisView->chip = i;
     560        thisView->chip = i;
    486561        pmChipReadObjects (chip, thisView, file, config);
    487562    }
    488563    psFree (thisView);
     564
     565    if (!pmConceptsReadFPA(fpa, PM_CONCEPT_SOURCE_HEADER, true, NULL)) {
     566        psError(PS_ERR_IO, false, "Failed to read concepts for fpa.\n");
     567        return false;
     568    }
     569
    489570    return true;
    490571}
     
    499580    for (int i = 0; i < chip->cells->n; i++) {
    500581        pmCell *cell = chip->cells->data[i];
    501         thisView->cell = i;
     582        thisView->cell = i;
    502583        pmCellReadObjects (cell, thisView, file, config);
    503584        if (!cell->data_exists) continue;
     
    505586    }
    506587    psFree (thisView);
     588
     589    if (!pmConceptsReadChip(chip, PM_CONCEPT_SOURCE_HEADER, true, true, NULL)) {
     590        psError(PS_ERR_IO, false, "Failed to read concepts for chip.\n");
     591        return false;
     592    }
     593
    507594    return true;
    508595}
     
    524611    for (int i = 0; i < cell->readouts->n; i++) {
    525612        pmReadout *readout = cell->readouts->data[i];
    526         thisView->readout = i;
     613        thisView->readout = i;
    527614        pmReadoutReadObjects (readout, thisView, file, config);
    528615        if (!readout->data_exists) {
     
    539626    }
    540627    psFree (thisView);
     628
     629    if (!pmConceptsReadCell(cell, PM_CONCEPT_SOURCE_HEADER, true, NULL)) {
     630        //psError(PS_ERR_UNKNOWN, false, "Failed to read concepts for cell");
     631        //return false;
     632        psWarning("Difficulty reading concepts for cell; attempting to proceed.");
     633    }
     634
    541635    return true;
    542636}
Note: See TracChangeset for help on using the changeset viewer.