IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6859


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

Location:
branches/rel10_ifa/psModules/src
Files:
4 added
3 deleted
24 edited

Legend:

Unmodified
Added
Removed
  • branches/rel10_ifa/psModules/src/astrom/Makefile.am

    r6720 r6859  
    1818        pmConceptsWrite.c \
    1919        pmConceptsStandard.c \
     20        pmFPA_JPEG.c \
    2021        pmFPAview.c \
    2122        pmFPAfile.c
     
    4142        pmConceptsWrite.h \
    4243        pmConceptsStandard.h \
     44        pmFPA_JPEG.h \
    4345        pmFPAview.h \
    4446        pmFPAfile.h
  • branches/rel10_ifa/psModules/src/astrom/pmFPA.c

    r6854 r6859  
    1212* XXX: Should we implement non-linear cell->chip transforms?
    1313*
    14 *  @version $Revision: 1.1.4.7 $ $Name: not supported by cvs2svn $
    15 *  @date $Date: 2006-04-14 03:09:32 $
     14*  @version $Revision: 1.1.4.8 $ $Name: not supported by cvs2svn $
     15*  @date $Date: 2006-04-14 21:43:59 $
    1616*
    1717*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    512512
    513513/*****************************************************************************
     514XXX EAM : I've added the 'exclusive' option.  if true all other chips are de-selected
     515XXX EAM : a negative value is valid and, in combinations with exclusive, de-selects all chips
    514516 *****************************************************************************/
    515 bool pmFPASelectChip(
    516     pmFPA *fpa,
    517     int chipNum)
     517bool pmFPASelectChip(pmFPA *fpa, int chipNum, bool exclusive)
    518518{
    519519    PS_ASSERT_PTR_NON_NULL(fpa, false);
     
    533533            setCellsProcess(tmpChip, true);
    534534        } else {
    535             tmpChip->process = false;
    536             setCellsProcess(tmpChip, false);
    537         }
    538 
    539     }
    540 
    541     return true;
    542 }
    543 
    544 bool pmChipSelectCell(pmChip *chip,
    545                       int cellNum
    546                      )
     535            if (exclusive) {
     536                tmpChip->process = false;
     537                setCellsProcess(tmpChip, false);
     538            }
     539        }
     540
     541    }
     542
     543    return true;
     544}
     545
     546/*****************************************************************************
     547XXX EAM : I've added the 'exclusive' option.  if true all other chips are de-selected
     548XXX EAM : a negative value is valid and, in combinations with exclusive, de-selects all cells
     549XXX this function should probably be re-defined to merge with 'setCellsProcess'
     550 *****************************************************************************/
     551bool pmChipSelectCell(pmChip *chip, int cellNum, bool exclusive)
    547552{
    548553    assert(chip);
     
    558563            continue;
    559564        }
    560         cell->process = (i == cellNum);
    561     }
    562 
     565        if (i == cellNum) {
     566            cell->process = true;
     567        } else {
     568            if (exclusive) {
     569                cell->process = false;
     570            }
     571        }
     572    }
    563573    return true;
    564574}
  • branches/rel10_ifa/psModules/src/astrom/pmFPA.h

    r6854 r6859  
    77*  @author GLG, MHPCC
    88*
    9 *  @version $Revision: 1.1.4.7 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2006-04-14 03:09:32 $
     9*  @version $Revision: 1.1.4.8 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2006-04-14 21:43:59 $
    1111*
    1212*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    244244bool pmFPASelectChip(
    245245    pmFPA *fpa,
    246     int chipNum
     246    int chipNum,
     247    bool exclusive
    247248);
    248249
    249250bool pmChipSelectCell(pmChip *chip,
    250                       int cellNum
     251                      int cellNum,
     252                      bool exclusive
    251253                     );
    252254
  • branches/rel10_ifa/psModules/src/astrom/pmFPAfile.c

    r6850 r6859  
    1111#include "pmFPARead.h"
    1212#include "pmFPAWrite.h"
    13 #include "pmFPAviewObjectsIO.h"
     13#include "pmPeaks.h"
     14#include "pmMoments.h"
     15#include "pmModel.h"
     16#include "pmSource.h"
     17#include "pmSourceIO.h"
     18#include "pmGrowthCurve.h"
     19#include "pmPSF.h"
     20#include "pmPSF_IO.h"
     21#include "pmFPA_JPEG.h"
    1422
    1523static void pmFPAfileFree (pmFPAfile *file)
     
    173181        if (!strcasecmp (type, "IMAGE"))     {
    174182            file->type = PM_FPA_FILE_IMAGE;
     183        }
     184        if (!strcasecmp (type, "PSF"))     {
     185            file->type = PM_FPA_FILE_PSF;
     186        }
     187        if (!strcasecmp (type, "JPEG"))     {
     188            file->type = PM_FPA_FILE_JPEG;
    175189        }
    176190    }
     
    294308    case PM_FPA_FILE_CMP:
    295309    case PM_FPA_FILE_RAW:
     310    case PM_FPA_FILE_PSF:
     311    case PM_FPA_FILE_JPEG:
    296312        psTrace ("pmFPAfile", 5, "not opening %s (type: %d)\n", file->filename, file->type);
    297313        break;
     
    339355        break;
    340356
     357    case PM_FPA_FILE_PSF:
     358        pmFPAviewReadPSFmodel (view, file);
     359        psTrace ("pmFPAfile", 5, "reading %s (type: %d)\n", file->filename, file->type);
     360        break;
     361
     362    case PM_FPA_FILE_JPEG:
     363        break;
     364
    341365    default:
    342366        fprintf (stderr, "warning: type mismatch\n");
     
    378402        break;
    379403
     404    case PM_FPA_FILE_PSF:
     405        pmFPAviewWritePSFmodel (view, file);
     406        psTrace ("pmFPAfile", 5, "wrote PSF %s (fpa: %p)\n", file->filename, file->fpa);
     407        break;
     408
     409    case PM_FPA_FILE_JPEG:
     410        pmFPAviewWriteJPEG (view, file);
     411        psTrace ("pmFPAfile", 5, "wrote PSF %s (fpa: %p)\n", file->filename, file->fpa);
     412        break;
     413
    380414    default:
    381415        fprintf (stderr, "warning: type mismatch\n");
     
    414448    case PM_FPA_FILE_CMP:
    415449    case PM_FPA_FILE_CMF:
     450    case PM_FPA_FILE_PSF:
     451    case PM_FPA_FILE_JPEG:
    416452        break;
    417453
     
    453489    case PM_FPA_FILE_OBJ:
    454490    case PM_FPA_FILE_CMP:
     491    case PM_FPA_FILE_PSF:
     492    case PM_FPA_FILE_JPEG:
    455493        break;
    456494
     
    775813    // load the given filerule (from config->camera) and associate it with the fpa
    776814    // the output file is just a view to the file on config->files
     815    // XXX the filenames placed on config->files should include the seq number
    777816    file = pmFPAfileDefine (config->files, config->camera, fpa, filename);
    778817    if (!file) {
  • branches/rel10_ifa/psModules/src/astrom/pmFPAfile.h

    r6847 r6859  
    77*  @author EAM, IfA
    88*
    9 *  @version $Revision: 1.1.2.11 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2006-04-13 06:17:28 $
     9*  @version $Revision: 1.1.2.12 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2006-04-14 21:43:59 $
    1111*
    1212*  Copyright 2004-2005 Institute for Astronomy, University of Hawaii
     
    3434    PM_FPA_FILE_RAW,
    3535    PM_FPA_FILE_IMAGE,
     36    PM_FPA_FILE_PSF,
     37    PM_FPA_FILE_JPEG,
    3638} pmFPAfileType;
    3739
  • branches/rel10_ifa/psModules/src/objects/Makefile.am

    r6848 r6859  
    2020     pmSourceIO_RAW.c \
    2121     pmPSF.c \
     22     pmPSF_IO.c \
    2223     pmPSFtry.c \
    23      pmGrowthCurve.c \
    24      pmFPAviewReadObjects.c \
    25      pmFPAviewWriteObjects.c
     24     pmGrowthCurve.c
    2625
    2726EXTRA_DIST = \
     
    4443     pmSourceIO.h \
    4544     pmPSF.h \
     45     pmPSF_IO.h \
    4646     pmPSFtry.h \
    47      pmGrowthCurve.h \
    48      pmFPAviewObjectsIO.h
     47     pmGrowthCurve.h
  • branches/rel10_ifa/psModules/src/objects/pmPSF.c

    r6848 r6859  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.4.4.4 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-04-13 06:18:46 $
     8 *  @version $Revision: 1.4.4.5 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-04-14 21:43:59 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    309309    return false;
    310310}
    311 
    312 psMetadata *pmPSFtoMD (psMetadata *metadata, pmPSF *psf)
    313 {
    314 
    315     if (metadata == NULL) {
    316         metadata = psMetadataAlloc ();
    317     }
    318 
    319     char *modelName = pmModelGetType (psf->type);
    320     psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_MODEL_NAME", PS_DATA_STRING, "PSF model name", modelName);
    321 
    322     psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_POISSON_ERRORS", PS_DATA_BOOL, "Poisson errors for fits", psf->poissonErrors);
    323 
    324     int nPar = pmModelParameterCount (psf->type)    ;
    325     psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_MODEL_NPAR", PS_DATA_S32, "PSF model parameter count", nPar);
    326 
    327     for (int i = 0; i < nPar - 4; i++) {
    328         psPolynomial2D *poly = psf->params->data[i];
    329         psPolynomial2DtoMD (metadata, poly, "PSF_PAR%02d", i);
    330     }
    331     psPolynomial4DtoMD (metadata, psf->ApTrend, "APTREND");
    332 
    333     psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_AP_RESID", PS_DATA_F32, "aperture residual", psf->ApResid);
    334     psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_dAP_RESID", PS_DATA_F32, "aperture residual scatter", psf->dApResid);
    335     psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_SKY_BIAS", PS_DATA_F32, "sky bias level", psf->skyBias);
    336 
    337     psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_CHISQ", PS_DATA_F32, "chi-square for fit", psf->chisq);
    338     psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_NSTARS", PS_DATA_S32, "number of stars used to measure PSF", psf->nPSFstars);
    339 
    340     return metadata;
    341 }
    342 
    343 pmPSF *pmPSFfromMD (psMetadata *metadata)
    344 {
    345 
    346     bool status;
    347     char keyword[80];
    348 
    349     char *modelName = psMetadataLookupPtr (&status, metadata, "PSF_MODEL_NAME");
    350     pmModelType type = pmModelSetType (modelName);
    351 
    352     bool poissonErrors = psMetadataLookupPtr (&status, metadata, "PSF_POISSON_ERRORS");
    353     if (!status)
    354         poissonErrors = true;
    355 
    356     pmPSF *psf = pmPSFAlloc (type, poissonErrors);
    357 
    358     int nPar = psMetadataLookupS32 (&status, metadata, "PSF_MODEL_NPAR");
    359     if (nPar != pmModelParameterCount (psf->type))
    360         psAbort ("read PSF" , "mismatch model par count");
    361 
    362     for (int i = 0; i < nPar - 4; i++) {
    363         sprintf (keyword, "PSF_PAR%02d", i);
    364         psMetadata *folder = psMetadataLookupPtr (&status, metadata, keyword);
    365         psPolynomial2D *poly = psPolynomial2DfromMD (folder);
    366         psFree (psf->params->data[i]);
    367         psf->params->data[i] = poly;
    368     }
    369     sprintf (keyword, "APTREND");
    370     psMetadata *folder = psMetadataLookupPtr (&status, metadata, keyword);
    371     psPolynomial4D *poly = psPolynomial4DfromMD (folder);
    372     psFree (psf->ApTrend);
    373     psf->ApTrend = poly;
    374 
    375     psf->ApResid = psMetadataLookupF32 (&status, metadata, "PSF_AP_RESID");
    376     psf->dApResid = psMetadataLookupF32 (&status, metadata, "PSF_dAP_RESID");
    377     psf->skyBias = psMetadataLookupF32 (&status, metadata, "PSF_SKY_BIAS");
    378 
    379     psf->chisq = psMetadataLookupF32 (&status, metadata, "PSF_CHISQ");
    380     psf->nPSFstars = psMetadataLookupS32 (&status, metadata, "PSF_NSTARS");
    381 
    382     psFree (metadata);
    383     return (psf);
    384 }
  • branches/rel10_ifa/psModules/src/objects/pmPSF.h

    r6848 r6859  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.1.22.4 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-04-13 06:18:46 $
     8 *  @version $Revision: 1.1.22.5 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-04-14 21:43:59 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    103103
    104104bool pmPSF_MaskApTrend (pmPSF *psf, pmPSF_ApTrendOptions option);
    105 psMetadata *pmPSFtoMD (psMetadata *metadata, pmPSF *psf);
    106 pmPSF *pmPSFfromMD (psMetadata *metadata);
    107105
    108106# endif
  • branches/rel10_ifa/psModules/src/objects/pmSource.c

    r6556 r6859  
    66 *  @author EAM, IfA: significant modifications.
    77 *
    8  *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-03-09 03:14:23 $
     8 *  @version $Revision: 1.1.2.3 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-04-14 21:43:59 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    5757    tmp->mode = PM_SOURCE_MODE_DEFAULT;
    5858    psMemSetDeallocator(tmp, (psFreeFunc) sourceFree);
     59
     60    tmp->psfMag = 32.0;
     61    tmp->extMag = 32.0;
     62    tmp->errMag = 32.0;
     63    tmp->apMag  = 32.0;
     64    tmp->pixWeight = 0.0;
    5965
    6066    psTrace(__func__, 3, "---- %s() end ----\n", __func__);
  • branches/rel10_ifa/psModules/src/objects/pmSource.h

    r6556 r6859  
    33 *  @author EAM, IfA; GLG, MHPCC
    44 *
    5  *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-03-09 03:14:23 $
     5 *  @version $Revision: 1.1.2.3 $ $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
     
    8585    float errMag;
    8686    float apMag;
     87    float pixWeight;   // model-weighted coverage of valid pixels
    8788    psRegion region;   // area on image covered by selected pixels
    8889}
  • 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
  • branches/rel10_ifa/psModules/src/objects/pmSourceIO.h

    r6712 r6859  
    33 *  @author EAM, IfA; GLG, MHPCC
    44 *
    5  *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-03-28 02:14:56 $
     5 *  @version $Revision: 1.1.2.3 $ $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
     
    3030bool pmPeaksWriteText (psArray *peaks, char *filename);
    3131
     32bool pmFPAviewReadObjects (const pmFPAview *view, pmFPAfile *file);
     33bool pmFPAReadObjects (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file);
     34bool pmChipReadObjects (pmChip *chip, const pmFPAview *view, pmFPAfile *file);
     35bool pmCellReadObjects (pmCell *cell, const pmFPAview *view, pmFPAfile *file);
     36bool pmReadoutReadObjects (pmReadout *readout, const pmFPAview *view, pmFPAfile *file);
     37
     38bool pmFPAviewWriteObjects (const pmFPAview *view, pmFPAfile *file);
     39bool pmFPAWriteObjects (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file);
     40bool pmChipWriteObjects (pmChip *chip, const pmFPAview *view, pmFPAfile *file);
     41bool pmCellWriteObjects (pmCell *cell, const pmFPAview *view, pmFPAfile *file);
     42bool pmReadoutWriteObjects (pmReadout *readout, const pmFPAview *view, pmFPAfile *file);
     43
    3244# endif /* PM_SOURCE_IO_H */
  • branches/rel10_ifa/psModules/src/objects/pmSourceIO_CMF.c

    r6726 r6859  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.1.2.5 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-03-29 20:55:42 $
     5 *  @version $Revision: 1.1.2.6 $ $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
     
    1717#include "pmHDU.h"
    1818#include "pmFPA.h"
     19#include "pmFPAview.h"
     20#include "pmFPAfile.h"
     21
    1922#include "pmPeaks.h"
    2023#include "pmMoments.h"
     
    7679        psMetadataAdd (row, PS_LIST_TAIL, "THETA",   PS_DATA_F32, "", axes.theta);
    7780        psMetadataAdd (row, PS_LIST_TAIL, "DOPHOT",  PS_DATA_U8,  "", type);
    78         psMetadataAdd (row, PS_LIST_TAIL, "DUMMY",   PS_DATA_STRING, "", "123");
     81        psMetadataAdd (row, PS_LIST_TAIL, "WEIGHT",  PS_DATA_U8,  "", PS_MIN (255, PS_MAX(0, 255*source->pixWeight)));
     82        psMetadataAdd (row, PS_LIST_TAIL, "DUMMY",   PS_DATA_STRING, "", "12");
    7983
    8084        psArrayAdd (table, 100, row);
  • branches/rel10_ifa/psModules/src/objects/pmSourceIO_CMP.c

    r6726 r6859  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.1.2.4 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-03-29 20:55:42 $
     5 *  @version $Revision: 1.1.2.5 $ $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
     
    1818#include "pmHDU.h"
    1919#include "pmFPA.h"
     20#include "pmFPAview.h"
     21#include "pmFPAfile.h"
     22
    2023#include "pmPeaks.h"
    2124#include "pmMoments.h"
  • branches/rel10_ifa/psModules/src/objects/pmSourceIO_OBJ.c

    r6565 r6859  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.1.2.3 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-03-09 04:25:03 $
     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
     
    1818#include "pmHDU.h"
    1919#include "pmFPA.h"
     20#include "pmFPAview.h"
     21#include "pmFPAfile.h"
     22
    2023#include "pmPeaks.h"
    2124#include "pmMoments.h"
  • branches/rel10_ifa/psModules/src/objects/pmSourceIO_RAW.c

    r6848 r6859  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.1.2.4 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-04-13 06:18:46 $
     5 *  @version $Revision: 1.1.2.5 $ $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
     
    1818#include "pmHDU.h"
    1919#include "pmFPA.h"
     20#include "pmFPAview.h"
     21#include "pmFPAfile.h"
     22
    2023#include "pmPeaks.h"
    2124#include "pmMoments.h"
     
    9194            fprintf (f, "%9.6f ", dPAR[j]);
    9295        }
    93         fprintf (f, ": %8.4f %2d %#5x %7.3f %7.3f  %7.1f %7.2f %4d %2d\n",
     96        fprintf (f, ": %8.4f %2d %#5x %7.3f %7.3f  %7.1f %7.2f %4.2f %4d %2d\n",
    9497                 source[0].apMag, source[0].type, source[0].mode,
    9598                 log10(model[0].chisq/model[0].nDOF),
     
    97100                 source[0].moments->SN,
    98101                 model[0].radiusTMP,
     102                 source[0].pixWeight,
    99103                 model[0].nDOF,
    100104                 model[0].nIter);
     
    147151            fprintf (f, "%9.6f ", dPAR[j]);
    148152        }
    149         fprintf (f, ": %7.4f  %2d %#5x %7.3f %7.3f  %7.1f %7.2f %4d %2d\n",
     153        fprintf (f, ": %7.4f  %2d %#5x %7.3f %7.3f  %7.1f %7.2f %4.2f %4d %2d\n",
    150154                 source->apMag,
    151155                 source[0].type, source[0].mode,
     
    154158                 source[0].moments->SN,
    155159                 model[0].radiusTMP,
     160                 source[0].pixWeight,
    156161                 model[0].nDOF,
    157162                 model[0].nIter);
  • branches/rel10_ifa/psModules/src/objects/pmSourceIO_SX.c

    r6726 r6859  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.1.2.4 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-03-29 20:55:42 $
     5 *  @version $Revision: 1.1.2.5 $ $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
     
    1818#include "pmHDU.h"
    1919#include "pmFPA.h"
     20#include "pmFPAview.h"
     21#include "pmFPAfile.h"
     22
    2023#include "pmPeaks.h"
    2124#include "pmMoments.h"
  • branches/rel10_ifa/psModules/src/objects/pmSourcePhotometry.c

    r6751 r6859  
    33 *  @author EAM, IfA; GLG, MHPCC
    44 *
    5  *  @version $Revision: 1.1.2.3 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-04-01 02:47:20 $
     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
     
    2525#include "pmSourcePhotometry.h"
    2626
     27# define DO_SKY 0
     28
    2729static float AP_MIN_SN = 0.0;
    2830
     
    105107    status = pmSourcePhotometryModel (&source->extMag, source->modelEXT);
    106108
     109    // measure the weight of included pixels
     110    status = pmSourcePixelWeight (&source->pixWeight, model, source->pixels, source->mask);
     111
    107112    // measure object aperture photometry
    108113    if (SN > AP_MIN_SN) {
     
    169174}
    170175
    171 # define DO_SKY 0
    172176// return source aperture magnitude
    173177bool pmSourcePhotometryAper (float *apMag, pmModel *model, psImage *image, psImage *mask)
     
    202206}
    203207
    204 # if (0)
    205     // XXX split into ap, psf, ext mags?
    206     bool pmSourcePhotometry (float *fitMag, float *apMag, pmModel *model, psImage *image, psImage *mask)
    207 {
    208 
    209     float obsSum = 0;
    210     float fitSum = 0;
    211     float sky = model->params->data.F32[0];
    212 
    213     *fitMag = 99.0;
    214     *obsMag = 99.0;
    215 
    216     // measure fitMag
    217     pmModelFlux modelFluxFunc = pmModelFlux_GetFunction (model->type);
    218     fitSum = modelFluxFunc (model->params);
    219     if (fitSum <= 0)
    220         return false;
    221     if (!isfinite(fitSum))
    222         return false;
    223     *fitMag = -2.5*log10(fitSum);
    224 
    225     // measure apMag
    226     for (int ix = 0; ix < image->numCols; ix++) {
    227         for (int iy = 0; iy < image->numRows; iy++) {
    228             if (mask->data.U8[iy][ix])
    229                 continue;
    230             obsSum += image->data.F32[iy][ix] - sky;
    231         }
    232     }
    233     if (obsSum <= 0)
    234         return false;
    235     *obsMag = -2.5*log10(obsSum);
    236 
     208// return source aperture magnitude
     209bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *image, psImage *mask)
     210{
     211    float modelSum = 0;
     212    float validSum = 0;
     213    float sky = 0;
     214    float value;
     215
     216    int Xo, Yo, dP;
     217    int dX, DX, NX;
     218    int dY, DY, NY;
     219
     220    *pixWeight = 0.0;
     221
     222    if (model == NULL)
     223        return false;
     224
     225    // we only care about the value of the object model, not the local sky
     226    if (DO_SKY) {
     227        sky = model->params->data.F32[0];
     228    } else {
     229        sky = 0;
     230    }
     231
     232    // the model function returns the source flux at a position
     233    pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type);
     234    psVector *coord = psVectorAlloc(2, PS_TYPE_F32);
     235    psVector *params = model->params;
     236
     237    Xo = params->data.F32[2];
     238    Yo = params->data.F32[3];
     239
     240    dX = Xo - image->col0;
     241    dP = image->numCols - dX;
     242    DX = PS_MAX(dX, dP);
     243    NX = image->numCols;
     244
     245    dY = Yo - image->row0;
     246    dP = image->numRows - dY;
     247    DY = PS_MAX(dY, dP);
     248    NY = image->numRows;
     249
     250    // measure modelSum and validSum
     251    // XXX this does not work for sources near the edge: we need to measure for
     252    // a full square region
     253    for (int ix = -DX; ix < DX + 1; ix++) {
     254        int mx = ix + dX;
     255        for (int iy = -DY; iy < DY + 1; iy++) {
     256            int my = iy + dY;
     257
     258            coord->data.F32[0] = (psF32) (ix + Xo);
     259            coord->data.F32[1] = (psF32) (iy + Yo);
     260
     261            // for the full model, add all points
     262            value = modelFunc (NULL, params, coord) - sky;
     263            modelSum += value;
     264
     265            // include count only the unmasked pixels within the image area
     266            if (mx < 0)
     267                continue;
     268            if (my < 0)
     269                continue;
     270            if (mx >= NX)
     271                continue;
     272            if (my >= NY)
     273                continue;
     274            if (mask->data.U8[my][mx])
     275                continue;
     276
     277            validSum += value;
     278        }
     279    }
     280    if (validSum <= 0)
     281        return false;
     282
     283    *pixWeight = validSum / modelSum;
    237284    return (true);
    238285}
    239 # endif
    240286
    241287float pmSourceCrossProduct (pmSource *Mi, pmSource *Mj)
  • branches/rel10_ifa/psModules/src/objects/pmSourcePhotometry.h

    r6751 r6859  
    33 *  @author EAM, IfA; GLG, MHPCC
    44 *
    5  *  @version $Revision: 1.1.2.3 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-04-01 02:47:20 $
     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
     
    4040float pmSourceCrossProduct (pmSource *Mi, pmSource *Mj);
    4141float pmSourceCrossWeight (pmSource *Mi, pmSource *Mj);
     42bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *image, psImage *mask);
    4243
    4344# endif /* PM_SOURCE_PHOTOMETRY_H */
  • branches/rel10_ifa/psModules/src/pslib/psAdditionals.c

    r6725 r6859  
    143143{
    144144    psList *values = psListAlloc(NULL); // The list of values to return
     145    if (string == NULL)
     146        return values;  // NULL string is not an error, just an empty list
     147
    145148    unsigned int length = strlen(string); // The length of the string
    146149    unsigned int numSplitters = strlen(splitters); // Number of characters that might split
     
    176179}
    177180
     181psArray *psStringSplitArray (const char *string, const char *splitters)
     182{
     183
     184    psList *list = psStringSplit (string, splitters);
     185    psArray *array = psListToArray (list);
     186    psFree (list);
     187    return array;
     188}
     189
    178190#ifndef whitespace
    179191#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
  • branches/rel10_ifa/psModules/src/pslib/psAdditionals.h

    r6848 r6859  
    3030                     );
    3131
     32// Split string on given characters
     33psArray *psStringSplitArray(const char *string, // String to split
     34                            const char *splitters // Characters on which to split
     35                           );
     36
    3237// strip whitespace from head and tail of string
    3338int psStringStrip (char *string);
  • branches/rel10_ifa/psModules/src/pslib/psImageUnbin.c

    r6826 r6859  
    179179}
    180180
    181 double psImageClippedStats (psImage *image, psImage *mask, psU8 maskValue, double fmin, double fmax)
     181psStats *psImageClippedStats (psImage *image, psImage *mask, psU8 maskValue, double fmin, double fmax)
    182182{
    183183    double value;
     
    185185    int ny = image->numRows;
    186186
     187    psStats *stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_QUARTILE);
    187188    if (nx*ny <= 0)
    188         return 0.0;
     189        return stats;
    189190
    190191    int Nsubset = PS_MIN (MAX_SAMPLE_PIXELS, nx*ny);
     
    203204        int iy = pixel / nx;
    204205
    205         if (mask->data.U8[iy][ix] & maskValue)
     206        if (mask && mask->data.U8[iy][ix] & maskValue)
    206207            continue;
    207208
     
    226227    value = value / npts;
    227228
     229    stats->robustMedian = value;
     230    stats->robustUQ = values->data.F32[imax];
     231    stats->robustLQ = values->data.F32[imin];
     232
     233    psFree (values);
     234    return stats;
    228235    // XXX correct for selection bias??
    229 
    230     psFree (values);
    231     return value;
    232236}
    233237
  • branches/rel10_ifa/psModules/src/pslib/psImageUnbin.h

    r6826 r6859  
    1111
    1212// my temporary image stats function; seems to be much faster than psLib???
    13 double psImageClippedStats (psImage *image, psImage *mask, psU8 maskValue, double fmin, double fmax);
     13psStats *psImageClippedStats (psImage *image, psImage *mask, psU8 maskValue, double fmin, double fmax);
    1414
    1515// my temporary sort which is based on N.R.; seems to be faster than psLib sort???
  • branches/rel10_ifa/psModules/src/psmodules.h

    r6848 r6859  
    3535#include <pmFPARead.h>
    3636#include <pmFPAWrite.h>
     37#include <pmFPA_JPEG.h>
     38
    3739#include <pmReadout.h>
    3840// #include <pmChipMosaic.h>
     
    6668# include <pmGrowthCurve.h>
    6769# include <pmPSF.h>
     70# include <pmPSF_IO.h>
    6871# include <pmPSFtry.h>
    6972# include <pmModelGroup.h>
    7073# include <pmSourcePhotometry.h>
    71 # include <pmFPAviewObjectsIO.h>
    7274
    7375#endif
Note: See TracChangeset for help on using the changeset viewer.