IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23591


Ignore:
Timestamp:
Mar 29, 2009, 3:26:40 PM (17 years ago)
Author:
eugene
Message:

updates to generate ghost extractions (cleanup star extractions)

Location:
trunk/psastro/src
Files:
4 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/psastro/src/Makefile.am

    r23412 r23591  
    4747        psastroExtractDataLoad.c      \
    4848        psastroExtractAnalysis.c      \
     49        psastroExtractStar.c      \
     50        psastroExtractStars.c      \
     51        psastroExtractGhosts.c      \
     52        psastroExtractFindChip.c      \
    4953        psastroCleanup.c
    5054
  • trunk/psastro/src/psastro.h

    r23494 r23591  
    127127bool              psastroMetadataStats (pmConfig *config);
    128128
    129 bool psastroZeroPoint (pmConfig *config);
    130 bool psastroZeroPointReadout(pmReadout *readout, float zeropt, float exptime);
    131 bool psastroZeroPointFromRecipe (float *zeropt, float *exptime, pmFPA *fpa, psMetadata *recipe);
     129bool              psastroZeroPoint (pmConfig *config);
     130bool              psastroZeroPointReadout(pmReadout *readout, float zeropt, float exptime);
     131bool              psastroZeroPointFromRecipe (float *zeropt, float *exptime, pmFPA *fpa, psMetadata *recipe);
    132132
    133133// psastroExtract functions
    134 bool psastroExtractAnalysis (pmConfig *config);
    135 psImage *psastroExtractStar (psImage *input, float x, float y, float dX, float dY);
    136 bool psastroExtractParseCamera (pmConfig *config);
    137 bool psastroExtractDataLoad (pmConfig *config);
    138 pmConfig *psastroExtractArguments (int argc, char **argv);
     134bool              psastroExtractAnalysis (pmConfig *config);
     135bool              psastroExtractStars (pmConfig *config);
     136bool              psastroExtractGhosts (pmConfig *config);
     137pmChip           *psastroExtractFindChip (float *xChip, float *yChip, pmFPA *fpa, float xFPA, float yFPA);
     138bool              psastroExtractChipBounds (pmFPA *fpa);
     139
     140psImage          *psastroExtractStar (psImage *input, float x, float y, float dX, float dY);
     141bool              psastroExtractParseCamera (pmConfig *config);
     142bool              psastroExtractDataLoad (pmConfig *config);
     143pmConfig         *psastroExtractArguments (int argc, char **argv);
    139144
    140145///@}
  • trunk/psastro/src/psastroExtractAnalysis.c

    r23584 r23591  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     8 *  @version $Revision: 1.7 $
    99 *  @date $Date: 2009-02-07 02:03:34 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
     
    1212
    1313# include "psastroInternal.h"
    14 
    15 # define ESCAPE(MSG) {                                                  \
    16         psError(PS_ERR_UNKNOWN, false, "I/O failure in psastroMaskUpdate: %s", MSG); \
    17         psFree (view);                                                  \
    18         return false;                                                   \
    19     }
    20 
    21 # define TEST_OUTPUT 0
    22 
    23 psImage *psastroExtractStar (psImage *input, float x, float y, float dX, float dY);
    2414
    2515/**
     
    2919
    3020    bool status;
    31     pmChip *chip = NULL;
    32     pmCell *cell = NULL;
    33     pmReadout *readout = NULL;
    34     float zeropt, exptime;
    35     char extname[81];
    3621
    3722    // select the current recipe
     
    4530    psMetadataAddBool (recipe, PS_LIST_TAIL, "PSASTRO.MATCH.LUMFUNC", PS_META_REPLACE, "do not match luminosity functions", false);
    4631
    47     psLogMsg ("psastro", PS_LOG_INFO, "extracting bright-star subrasters");
     32    psLogMsg ("psastro", PS_LOG_INFO, "loading reference stars");
    4833
    4934    // load the reference stars overlapping the data stars
     
    6651    psFree(refs);
    6752
    68     double EXTRACT_MAX_MAG = psMetadataLookupF32 (&status, recipe, "EXTRACT_MAX_MAG");
    69 
    70     // we have two input pmFPAfiles: PSASTRO.EXTRACT.INPUT and PSASTRO.EXTRACT.ASTROM.  both are in chip-mosaic or fpa format
    71     // we have already loaded the headers from PSASTRO.EXTRACT.ASTROM and determined the astrometry terms
    72 
    73     // select the input astrometry data (also carries the refstars)
    74     pmFPAfile *astrom = psMetadataLookupPtr (NULL, config->files, "PSASTRO.EXTRACT.ASTROM");
    75     if (!astrom) {
    76         psError(PSASTRO_ERR_CONFIG, true, "Can't find input data");
    77         return false;
    78     }
    79     pmFPA *fpa = astrom->fpa;
    80 
    81     // select the input data sources
    82     pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSASTRO.EXTRACT.INPUT");
    83     if (!input) {
    84         psError(PSASTRO_ERR_CONFIG, true, "Can't find input data");
    85         return false;
    86     }
    87 
    88     // only load data from INPUT
    89     pmFPAfileActivate(config->files, false, NULL);
    90     pmFPAfileActivate(config->files, true, "PSASTRO.EXTRACT.INPUT");
    91 
    92     // really error-out here?  or just skip?
    93     if (!psastroZeroPointFromRecipe (&zeropt, &exptime, fpa, recipe)) {
    94         psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
    95         return false;
    96     }
    97 
    98     // recipe values are given in instrumental magnitudes
    99     // use the zero point and exposure time to convert to apparent mags: M_ap = M_inst + C_0 + 2.5*log(exptime)
    100     float MagOffset = zeropt + 2.5*log10(exptime);
    101     EXTRACT_MAX_MAG += MagOffset;
    102 
    103     int nExt = 0;
    104 
    105     // open the output file handle: we are just saving a series of extensions to this file
    106     char *filename = psMetadataLookupStr (&status, config->arguments, "OUTPUT");
    107     if (!filename) {
    108         psLogMsg ("psastro", PS_LOG_INFO, "output filename not supplieda");
    109         return false;
    110     }
    111     psFits *outStars = psFitsOpen (filename, "w");
    112     if (!outStars) {
    113         psError(PS_ERR_IO, false, "error opening file %s\n", filename);
    114         return false;
    115     }
    116 
    117     pmFPAview *view = pmFPAviewAlloc (0);
    118 
    119     // generate a (very) basic header:
    120     psMetadata *phu = psMetadataAlloc ();
    121     // select the filter; default to fixed photcode and mag limit otherwise
    122     char *filter = psMetadataLookupStr (&status, fpa->concepts, "FPA.FILTERID");
    123     if (!status) ESCAPE("missing FPA.FILTER in concepts");
    124 
    125     psMetadataAddStr (phu, PS_LIST_TAIL, "FILTER",  0, "filter", filter);
    126     psMetadataAddF32 (phu, PS_LIST_TAIL, "EXPTIME", 0, "exptime", exptime);
    127     psMetadataAddF32 (phu, PS_LIST_TAIL, "ZEROPT",  0, "zeropt", zeropt);
    128     psFitsWriteBlank (outStars, phu, NULL);
    129     psFree (phu);
    130 
    131     // open/load files as needed
    132     if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE("failed on FPA BEFORE");
    133 
    134     // this loop selects the matched stars for all chips
    135     while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) {
    136         psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
    137         if (!chip->process || !chip->file_exists) { continue; }
    138         if (!chip->fromFPA) { continue; }
    139 
    140         if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE("failed on Chip BEFORE");
    141 
    142         // text output file for testing
    143         FILE *f = NULL;
    144         if (TEST_OUTPUT) {
    145             char *filename = NULL;
    146             char *chipname = psMetadataLookupStr (&status, chip->concepts, "CHIP.NAME");
    147             psStringAppend (&filename, "bright.%s.dat", chipname);
    148             f = fopen (filename, "w");
    149             if (!f) {
    150                 psWarning ("cannot create test output file %s\n", filename);
    151                 continue;
    152             }
    153             psFree (filename);
    154         }
    155 
    156         while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
    157             psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
    158             if (!cell->process || !cell->file_exists) { continue; }
    159 
    160             // process each of the readouts
    161             while ((readout = pmFPAviewNextReadout (view, fpa, 1)) != NULL) {
    162                 if (! readout->data_exists) { continue; }
    163 
    164                 // select the raw objects for this readout (loaded in psastroExtract.c)
    165                 psArray *refstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.REFSTARS");
    166                 if (refstars == NULL) { continue; }
    167 
    168                 // identify the bright stars of interest
    169                 for (int i = 0; i < refstars->n; i++) {
    170                     pmAstromObj *ref = refstars->data[i];
    171                     if (ref->Mag > EXTRACT_MAX_MAG) continue;
    172 
    173                     if (TEST_OUTPUT) {
    174                         fprintf (f, "stars %f %f  %f %f   %f\n", ref->chip->x, ref->chip->y, ref->FP->x, ref->FP->y, ref->Mag);
    175                     }
    176 
    177                     pmReadout *inReadout = pmFPAviewThisReadout (view, input->fpa);
    178                     psImage *subraster = psastroExtractStar (inReadout->image, ref->chip->x, ref->chip->y, 200.0, 200.0);
    179                     if (!subraster) continue;
    180                    
    181                     // generate a (very) basic header:
    182                     psMetadata *header = psMetadataAlloc ();
    183                     psMetadataAddF32 (header, PS_LIST_TAIL, "CHIP_X",  0, "chip coordinate",        ref->chip->x);
    184                     psMetadataAddF32 (header, PS_LIST_TAIL, "CHIP_Y",  0, "chip coordinate",        ref->chip->y);
    185                     psMetadataAddF32 (header, PS_LIST_TAIL, "FPA_X",   0, "focal-plane coordinate", ref->FP->x);
    186                     psMetadataAddF32 (header, PS_LIST_TAIL, "FPA_Y",   0, "focal-plane coordinate", ref->FP->y);
    187                     psMetadataAddF32 (header, PS_LIST_TAIL, "MAG",     0, "magnitude",              ref->Mag);
    188 
    189                     snprintf (extname, 80, "extname.%05d", nExt);
    190                     psFitsWriteImage (outStars, header, subraster, 0, extname);
    191                     nExt ++;
    192                    
    193                     psFree (header);
    194                     psFree (subraster);
    195                 }
    196                 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE("failed on Readout AFTER");;
    197             }
    198             if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE("failed on Cell AFTER");;
    199         }
    200         if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE("failed on Chip AFTER");;
    201 
    202         if (f) fclose (f);
    203     }
    204     if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE("failed on FPA AFTER");;
    205 
    206     psFitsClose (outStars);
    207     psFree (view);
     53    psastroExtractStars (config);
     54    psastroExtractGhosts (config);
    20855    return true;
    20956}
    210 
    211 psImage *psastroExtractStar (psImage *input, float x, float y, float dX, float dY) {
    212 
    213     // skip if no pixels are on the image
    214     // skip if center is not on the image
    215     // if bounds fall off image, paste into a full-size image.
    216 
    217     if (x < 0) return NULL;
    218     if (y < 0) return NULL;
    219     if (x >= input->numCols) return NULL;
    220     if (y >= input->numRows) return NULL;
    221 
    222     int xo = x; // index of center pixel (eg, 6.00 to 6.99 -> 6)
    223     int yo = y;
    224 
    225     // build an output image of size 2dX + 1, 2dY + 1
    226     // psRegion fullRegion = psRegionSet (xo - dX, x + dX + 1, y - dY, y + dY + 1);
    227     // psRegion realRegion = psRegionForImage (input, fullRegion);
    228     // psImage *subset = psImageSubset (input, realRegion);
    229 
    230     psImage *subset = psImageAlloc (2*dX+1, 2*dY+1, PS_TYPE_F32);
    231     psImageInit (subset, 0.0);
    232 
    233     // fill in the subset image with the values from the subset
    234     // I must already have done this elsewhere...
    235 
    236     for (int iy = yo - dY; iy < yo + dY + 1; iy++) {
    237         for (int ix = xo - dX; ix < xo + dX + 1; ix++) {
    238 
    239             if (ix < input->col0) continue;
    240             if (iy < input->row0) continue;
    241             if (ix >= input->numCols) continue;
    242             if (iy >= input->numRows) continue;
    243        
    244             int jx = ix + dX - xo; // runs from 0 to 2dX
    245             int jy = iy + dY - yo;
    246             subset->data.F32[jy][jx] = input->data.F32[iy][ix];
    247         }
    248     }
    249     return subset;
    250 }
  • trunk/psastro/src/psastroExtractArguments.c

    r23412 r23591  
    1313# include "psastroStandAlone.h"
    1414
    15 static char *usage = "USAGE: psastroExtract [-outroot root] -astrom (cmffiles)";
     15static char *usage = "USAGE: psastroExtract -file (input) -astrom (cmffiles) -outroot (outroot) [-chip]";
    1616
    1717pmConfig *psastroExtractArguments (int argc, char **argv) {
Note: See TracChangeset for help on using the changeset viewer.