IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 11, 2005, 5:43:47 AM (21 years ago)
Author:
eugene
Message:

adding mask & noise images

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/setup.c

    r4189 r4215  
    11# include "psphot.h"
    22
    3 bool setup (psImage **image, psImage **mask, psImage **noise, psMetadata **header, psMetadata **config)
     3psImageData *setup (psMetadata *config)
    44{
    5     int       Nfail;
    6     psFits   *file = NULL;              // FITS pointer to input image
    75    psRegion  region = {0,0,0,0};       // a region representing the entire array
    86
    97    psTimerStart ("psphot");
    108
    11     char *input = pmConfigLookupSTR (&status, *config, *header, "INPUT");
    12     file = psFitsAlloc (input);
     9    char *input = psMetadataLookupSTR (&status, config, "INPUT");
     10    psFits *file = psFitsAlloc (input);
    1311
    14     *header = psMetadataAlloc ();
    15     psMetadataAdd (*header, PS_LIST_HEAD, "COMMENT", PS_META_MULTI, "folder for comment", NULL);
    16     psMetadataAdd (*header, PS_LIST_HEAD, "HISTORY", PS_META_MULTI, "folder for history", NULL);
    17     *header = psFitsReadHeader (*header, file);
    18     *image  = psFitsReadImage  (*image,  file, region, 0);
     12    psImageData *imdata = psAlloc(sizeof(psImageData));
     13    psMetadata *header = psMetadataAlloc ();
     14    psMetadataAdd (header, PS_LIST_HEAD, "COMMENT", PS_META_MULTI, "folder for comment", NULL);
     15    psMetadataAdd (header, PS_LIST_HEAD, "HISTORY", PS_META_MULTI, "folder for history", NULL);
     16    header = psFitsReadHeader (header, file);
     17    psImage *image = psFitsReadImage (NULL, file, region, 0);
    1918    psFree (file);
    2019
    2120    // grab these values from the approrpiate location (image header if necessary)
    2221    bool  status   = false;
    23     float RDNOISE  = pmConfigLookupF32 (&status, *config, *header, "RDNOISE");
    24     float GAIN     = pmConfigLookupF32 (&status, *config, *header, "GAIN");
    25     psMetadataAdd (*config, PS_LIST_TAIL, "RDNOISE", PS_META_F32 | PS_META_REPLACE, "read noise value used", RDNOISE);
    26     psMetadataAdd (*config, PS_LIST_TAIL, "GAIN",    PS_META_F32 | PS_META_REPLACE, "gain value used", GAIN);
     22    float RDNOISE  = pmConfigLookupF32 (&status, config, header, "RDNOISE");
     23    float GAIN     = pmConfigLookupF32 (&status, config, header, "GAIN");
     24    psMetadataAdd (config, PS_LIST_TAIL, "RDNOISE", PS_META_F32 | PS_META_REPLACE, "read noise value used", RDNOISE);
     25    psMetadataAdd (config, PS_LIST_TAIL, "GAIN",    PS_META_F32 | PS_META_REPLACE, "gain value used", GAIN);
    2726
    28     // load the noise image if it exists, otherwise build from input
    29     char *noiseName = pmConfigLookupSTR (&status, *config, *header, "NOISE");
     27    imdata->image = image;
     28    imdata->header = header;
     29
     30    // load the noise image if it is supplied, otherwise build from input
     31    char *noiseName = psMetadataLookupSTR (&status, config, "NOISE");
    3032    if (status == true) {
    3133      file = psFitsAlloc (noiseName);
    32       *noise  = psFitsReadImage  (*noise, file, region, 0);
     34      imdata->noise = psFitsReadImage  (NULL, file, region, 0);
    3335      psFree (file);
    3436    } else {
    35       *value = psScalar (1.0 / GAIN);
    36       *noise = BinaryOp (NULL, *image, '/', value);
     37      psScalar *value = psScalarAlloc (1.0 / GAIN, PS_TYPE_F64);
     38      imdata->noise = BinaryOp (NULL, imdata->image, '/', value);
    3739      psFree (value);
    3840
    39       *value = psScalar (PS_SQR(RDNOISE/GAIN));
    40       *noise = BinaryOp (*noise, *noise, '+', value);
     41      psScalar *value = psScalarAlloc (PS_SQR(RDNOISE/GAIN), PS_TYPE_F64);
     42      imdata->noise = BinaryOp (imdata->noise, imdata->noise, '+', value);
    4143      psFree (value);
    4244    }
    4345
    44     char *maskName = pmConfigLookupSTR (&status, *config, *header, "MASK");
     46    char *maskName = psMetadataLookupSTR (&status, config, "MASK");
    4547    if (status == true) {
    4648      file = psFitsAlloc (maskName);
    47       *mask  = psFitsReadImage  (*mask, file, region, 0);
     49      imdata->mask  = psFitsReadImage  (NULL, file, region, 0);
     50      // check if U8 & force?
    4851      psFree (file);
    4952    } else {
    50       *mask = psImageAlloc (image->numCols, image->numRows, PS_TYPE_U8);
     53      imdata->mask = psImageAlloc (image->numCols, image->numRows, PS_TYPE_U8);
    5154    }
     55
     56    float XBORDER  = psMetadataLookupF32 (&status, config, "XBORDER");
     57    float YBORDER  = psMetadataLookupF32 (&status, config, "YBORDER");
     58    psRegion *keep = psRegionAlloc (XBORDER, -XBORDER, YBORDER, -YBORDER);
     59    keep           = psRegionForImage (keep, image, keep);
     60    psImageKeepRegion (imdata->mask, keep, 0x01);
    5261
    5362    psLogMsg ("psphot", 3, "load data: %f sec\n", psTimerMark ("psphot"));
Note: See TracChangeset for help on using the changeset viewer.