IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 14, 2006, 11:43:59 AM (20 years ago)
Author:
magnier
Message:

added JPEG and PSF I/O methods to pmFPAfile, added pmSourcePixelWeights

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/rel10_ifa/psModules/src/objects/pmSourceIO.c

    r6712 r6859  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.1.2.3 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-03-28 02:14:56 $
     5 *  @version $Revision: 1.1.2.4 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-04-14 21:43:59 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1414#include <string.h>
    1515#include "pslib.h"
     16#include "psAdditionals.h"
    1617#include "pmHDU.h"
    1718#include "pmFPA.h"
     19#include "pmFPAview.h"
     20#include "pmFPAfile.h"
     21
    1822#include "pmPeaks.h"
    1923#include "pmMoments.h"
     
    5357}
    5458
     59// Given a FITS file pointer, read the table of object data
     60bool pmFPAviewWriteObjects (const pmFPAview *view, pmFPAfile *file)
     61{
     62
     63    pmFPA *fpa = file->fpa;
     64
     65    if (view->chip == -1) {
     66        pmFPAWriteObjects (fpa, view, file);
     67        return true;
     68    }
     69
     70    if (view->chip >= fpa->chips->n) {
     71        return false;
     72    }
     73    pmChip *chip = fpa->chips->data[view->chip];
     74
     75    if (view->cell == -1) {
     76        pmChipWriteObjects (chip, view, file);
     77        return true;
     78    }
     79
     80    if (view->cell >= chip->cells->n) {
     81        return false;
     82    }
     83    pmCell *cell = chip->cells->data[view->cell];
     84
     85    if (view->readout == -1) {
     86        pmCellWriteObjects (cell, view, file);
     87        return true;
     88    }
     89
     90    if (view->readout >= cell->readouts->n) {
     91        return false;
     92    }
     93    pmReadout *readout = cell->readouts->data[view->readout];
     94
     95    pmReadoutWriteObjects (readout, view, file);
     96    return true;
     97}
     98
     99// read in all chip-level Objects files for this FPA
     100bool pmFPAWriteObjects (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file)
     101{
     102
     103    for (int i = 0; i < fpa->chips->n; i++) {
     104
     105        pmChip *chip = fpa->chips->data[i];
     106        pmChipWriteObjects (chip, view, file);
     107    }
     108    return true;
     109}
     110
     111// read in all cell-level Objects files for this chip
     112bool pmChipWriteObjects (pmChip *chip, const pmFPAview *view, pmFPAfile *file)
     113{
     114
     115    for (int i = 0; i < chip->cells->n; i++) {
     116
     117        pmCell *cell = chip->cells->data[i];
     118        pmCellWriteObjects (cell, view, file);
     119    }
     120    return true;
     121}
     122
     123// read in all readout-level Objects files for this cell
     124bool pmCellWriteObjects (pmCell *cell, const pmFPAview *view, pmFPAfile *file)
     125{
     126
     127    for (int i = 0; i < cell->readouts->n; i++) {
     128
     129        pmReadout *readout = cell->readouts->data[i];
     130        pmReadoutWriteObjects (readout, view, file);
     131    }
     132    return true;
     133}
     134
     135// read in all readout-level Objects files for this cell
     136bool pmReadoutWriteObjects (pmReadout *readout, const pmFPAview *view, pmFPAfile *file)
     137{
     138
     139    bool status;
     140    char *filename;
     141    char *dataname;
     142    char *headname;
     143    pmHDU *hdu;
     144    pmHDU *phu;
     145    psMetadata *updates;
     146    psMetadata *outhead;
     147
     148    psArray *sources = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.SOURCES");
     149
     150    switch (file->type) {
     151    case PM_FPA_FILE_RAW:
     152        filename = pmFPAfileNameFromRule (file->filerule, file, view);
     153        pmSourcesWriteRAW (sources, filename);
     154        psFree (filename);
     155        break;
     156
     157    case PM_FPA_FILE_OBJ:
     158        filename = pmFPAfileNameFromRule (file->filerule, file, view);
     159        pmSourcesWriteOBJ (sources, filename);
     160        psFree (filename);
     161        break;
     162
     163    case PM_FPA_FILE_SX:
     164        filename = pmFPAfileNameFromRule (file->filerule, file, view);
     165        pmSourcesWriteSX (sources, filename);
     166        psFree (filename);
     167        break;
     168
     169    case PM_FPA_FILE_CMP:
     170        // a SPLIT format : only one header and object table per file
     171        hdu = pmFPAviewThisHDU (view, file->fpa);
     172        filename = pmFPAfileNameFromRule (file->filerule, file, view);
     173
     174        // copy the header to an output header, add the output header data
     175        outhead = psMetadataCopy (NULL, hdu->header);
     176
     177        // check/fix first line (must be SIMPLE = F)
     178        psMetadataItem *item = psMetadataGet (outhead, PS_LIST_HEAD);
     179        if (strcmp (item->name, "SIMPLE") && strcmp (item->name, "XTENSION")) {
     180            psErrorStackPrint(stderr, "invalid header: first line is neither SIMPLE nor XTENSION\n");
     181            exit(EXIT_FAILURE);
     182        }
     183        if (!strcmp (item->name, "XTENSION")) {
     184            psMetadataRemoveIndex (outhead, PS_LIST_HEAD);
     185        }
     186        psMetadataAddBool (outhead, PS_LIST_HEAD, "SIMPLE", PS_META_REPLACE, "CMP file, not simple", false);
     187
     188        // copy over the entries saved in the
     189        updates = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.HEADER");
     190        psMetadataCopy (outhead, updates);
     191
     192        pmSourcesWriteCMP (sources, filename, outhead);
     193        psFree (outhead);
     194        psFree (filename);
     195        break;
     196
     197    case PM_FPA_FILE_CMF:
     198        // write a PHU?
     199        // write a header?
     200        // write the data
     201
     202        // get the current header
     203        hdu = pmFPAviewThisHDU (view, file->fpa);
     204
     205        // if file does not yet have a PHU, write it to disk
     206        if (file->phu == NULL) {
     207            // get the corresponding phu
     208            phu = pmFPAviewThisPHU (view, file->fpa);
     209
     210            // CMF always has extensions
     211            outhead = psMetadataCopy (NULL, phu->header);
     212            psMetadataAdd (outhead, PS_LIST_TAIL, "EXTEND", PS_DATA_BOOL | PS_META_REPLACE, "this file has extensions", true);
     213            psFitsWriteHeaderNotImage (file->fits, outhead);
     214            file->phu = phu->header;
     215            psTrace ("pmFPAfile", 5, "wrote phu %s (type: %d)\n", file->filename, file->type);
     216            psFree (outhead);
     217        }
     218
     219        // this this header block is new, write it to disk,
     220        if (hdu->header != file->header) {
     221            // determine name for header extension
     222            headname = pmFPAfileNameFromRule (file->extxtra, file, view);
     223            outhead = psMetadataCopy (NULL, hdu->header);
     224            psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTNAME", PS_META_REPLACE, "extension name", headname);
     225            psFitsWriteHeaderNotImage (file->fits, outhead);
     226            psTrace ("pmFPAfile", 5, "wrote ext head %s (type: %d)\n", file->filename, file->type);
     227            file->header = hdu->header;
     228            psFree (outhead);
     229            psFree (headname);
     230        }
     231
     232        // write this table to disk
     233        dataname = pmFPAfileNameFromRule (file->extrule, file, view);
     234        updates = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.HEADER");
     235        pmSourcesWriteCMF (file->fits, sources, updates, dataname);
     236        psTrace ("pmFPAfile", 5, "wrote ext data %s (type: %d)\n", file->filename, file->type);
     237        psFree (dataname);
     238        break;
     239
     240    default:
     241        fprintf (stderr, "warning: type mismatch\n");
     242        break;
     243    }
     244    return true;
     245}
     246// a MEF CMF file has: PHU, CELL-HEAD, TABLE, CELL-HEAD, TABLE, TABLE, TABLE...
     247
     248// Given a FITS file pointer, read the table of object data
     249bool pmFPAviewReadObjects (const pmFPAview *view, pmFPAfile *file)
     250{
     251    pmFPA *fpa = file->fpa;
     252
     253    if (view->chip == -1) {
     254        pmFPAReadObjects (fpa, view, file);
     255        return true;
     256    }
     257
     258    if (view->chip >= fpa->chips->n) {
     259        return false;
     260    }
     261    pmChip *chip = fpa->chips->data[view->chip];
     262
     263    if (view->cell == -1) {
     264        pmChipReadObjects (chip, view, file);
     265        return true;
     266    }
     267
     268    if (view->cell >= chip->cells->n) {
     269        return false;
     270    }
     271    pmCell *cell = chip->cells->data[view->cell];
     272
     273    if (view->readout == -1) {
     274        pmCellReadObjects (cell, view, file);
     275        return true;
     276    }
     277
     278    if (view->readout >= cell->readouts->n) {
     279        return false;
     280    }
     281    pmReadout *readout = cell->readouts->data[view->readout];
     282
     283    pmReadoutReadObjects (readout, view, file);
     284    return true;
     285}
     286
     287// read in all chip-level Objects files for this FPA
     288bool pmFPAReadObjects (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file)
     289{
     290
     291    for (int i = 0; i < fpa->chips->n; i++) {
     292
     293        pmChip *chip = fpa->chips->data[i];
     294        pmChipReadObjects (chip, view, file);
     295    }
     296    return true;
     297}
     298
     299// read in all cell-level Objects files for this chip
     300bool pmChipReadObjects (pmChip *chip, const pmFPAview *view, pmFPAfile *file)
     301{
     302
     303    for (int i = 0; i < chip->cells->n; i++) {
     304
     305        pmCell *cell = chip->cells->data[i];
     306        pmCellReadObjects (cell, view, file);
     307    }
     308    return true;
     309}
     310
     311// read in all readout-level Objects files for this cell
     312bool pmCellReadObjects (pmCell *cell, const pmFPAview *view, pmFPAfile *file)
     313{
     314
     315    for (int i = 0; i < cell->readouts->n; i++) {
     316
     317        pmReadout *readout = cell->readouts->data[i];
     318        pmReadoutReadObjects (readout, view, file);
     319    }
     320    return true;
     321}
     322
     323// read in all readout-level Objects files for this cell
     324bool pmReadoutReadObjects (pmReadout *readout, const pmFPAview *view, pmFPAfile *file)
     325{
     326
     327    bool status;
     328    psArray *sources;
     329    pmHDU *hdu;
     330
     331    switch (file->type) {
     332    case PM_FPA_FILE_OBJ:
     333        fprintf (stderr, "warning: OBJ is not supported as an input object format\n");
     334        break;
     335
     336    case PM_FPA_FILE_SX:
     337        fprintf (stderr, "warning: SX is not supported as an input object format\n");
     338        break;
     339
     340    case PM_FPA_FILE_CMP:
     341        // a SPLIT format : only one header and object table per file
     342
     343        // read in header, if not yet loaded
     344        hdu = pmFPAviewThisHDU (view, file->fpa);
     345
     346        char *filename = pmFPAfileNameFromRule (file->filerule, file, view);
     347        file->fits = psFitsOpen (filename, "r");
     348        hdu->header = psFitsReadHeader (NULL, file->fits);
     349        psFitsClose (file->fits);
     350        sources  = pmSourcesReadCMP (filename, hdu->header);
     351        psFree (filename);
     352        break;
     353
     354    case PM_FPA_FILE_CMF:
     355        // read in header, if not yet loaded
     356        hdu = pmFPAviewThisHDU (view, file->fpa);
     357        if (hdu->header == NULL) {
     358            char *headname = pmFPAfileNameFromRule (file->extxtra, file, view);
     359            psFitsMoveExtName (file->fits, headname);
     360            hdu->header = psFitsReadHeader (NULL, file->fits);
     361            psFree (headname);
     362        }
     363
     364        char *dataname = pmFPAfileNameFromRule (file->extrule, file, view);
     365        psFitsMoveExtName (file->fits, dataname);
     366        sources  = pmSourcesReadCMF (file->fits, hdu->header);
     367        psFree (dataname);
     368        break;
     369
     370    default:
     371        fprintf (stderr, "warning: type mismatch\n");
     372        break;
     373    }
     374    status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY, "psphot sources", sources);
     375    return true;
     376}
     377
     378
Note: See TracChangeset for help on using the changeset viewer.