IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 15, 2009, 4:56:07 PM (17 years ago)
Author:
eugene
Message:

add psastroExtract (first working version)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/eam_branch_20090312/psastro/src/psastroExtractAnalysis.c

    r23322 r23335  
    2020
    2121# define TEST_OUTPUT 1
    22 static pmFits *outStars = NULL;
     22
     23psImage *psastroExtractStar (psImage *input, float x, float y, float dX, float dY);
    2324
    2425/**
     
    3233    pmReadout *readout = NULL;
    3334    float zeropt, exptime;
     35    char extname[81];
    3436
    3537    // select the current recipe
     
    4042    }
    4143
     44    // force this recipe value to be false (would cause an error in psastroChooseRefstars -- no rawstars!)
     45    psMetadataAddBool (recipe, PS_LIST_TAIL, "PSASTRO.MATCH.LUMFUNC", PS_META_REPLACE, "do not match luminosity functions", false);
     46
    4247    psLogMsg ("psastro", PS_LOG_INFO, "extracting bright-star subrasters");
     48
     49    // load the reference stars overlapping the data stars
     50    psArray *refs = psastroLoadRefstars(config, "PSASTRO.EXTRACT.ASTROM");
     51    if (!refs) {
     52        psError (PSASTRO_ERR_UNKNOWN, false, "failed to load reference data\n");
     53        return false;
     54    }
     55    if (refs->n == 0) {
     56        psError(PSASTRO_ERR_REFSTARS, true, "no reference stars found");
     57        psFree(refs);
     58        return false;
     59    }
     60
     61    if (!psastroChooseRefstars (config, refs, "PSASTRO.EXTRACT.ASTROM")) {
     62        psError (PSASTRO_ERR_UNKNOWN, false, "failed to select reference data for chips\n");
     63        psFree(refs);
     64        return false;
     65    }
     66    psFree(refs);
    4367
    4468    double EXTRACT_MAX_MAG = psMetadataLookupF32 (&status, recipe, "EXTRACT_MAX_MAG");
     
    4670    // we have two input pmFPAfiles: PSASTRO.EXTRACT.INPUT and PSASTRO.EXTRACT.ASTROM.  both are in chip-mosaic or fpa format
    4771    // 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;
    4880
    4981    // select the input data sources
     
    5385        return false;
    5486    }
    55     pmFPA *fpa = input->fpa;
    56 
    57     // select the input data sources
    58     pmFPAfile *astrom = psMetadataLookupPtr (NULL, config->files, "PSASTRO.EXTRACT.ASTROM");
    59     if (!input) {
    60         psError(PSASTRO_ERR_CONFIG, true, "Can't find input data");
    61         return false;
    62     }
    6387
    6488    // only load data from INPUT
     
    77101    EXTRACT_MAX_MAG += MagOffset;
    78102
     103    int nExt = 0;
     104
    79105    // 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");
    80112    if (!outStars) {
    81       char *filename = psMetadataLookupStr (&stats, config->arguments, "OUTPUT");
    82       if (!filename) {
    83         psLogMsg ("psastro", PS_LOG_INFO, "output filename not supplieda");
    84         return false;
    85       }
    86       outStars = psFitsOpen (filename, "w");
    87       if (!outStars) {
    88         psError(PS_ERR_IO, false, "error opening file %s\n", filename);
    89         return false;
    90       }
    91       // call: psFitsWriteImage (fits, NULL, subraster, 0, "extname.NN");
    92     }
     113      psError(PS_ERR_IO, false, "error opening file %s\n", filename);
     114      return false;
     115    }
     116
     117    pmFPAview *view = pmFPAviewAlloc (0);
    93118
    94119    // open/load files as needed
     
    109134          char *chipname = psMetadataLookupStr (&status, chip->concepts, "CHIP.NAME");
    110135          psStringAppend (&filename, "bright.%s.dat", chipname);
    111           FILE *f = fopen (filename, "w");
     136          f = fopen (filename, "w");
    112137          if (!f) {
    113138            psWarning ("cannot create test output file %s\n", filename);
     
    132157                for (int i = 0; i < refstars->n; i++) {
    133158                    pmAstromObj *ref = refstars->data[i];
    134                     if (ref->Mag > REFSTAR_MASK_MAX_MAG) continue;
     159                    if (ref->Mag > EXTRACT_MAX_MAG) continue;
    135160
    136161                    if (TEST_OUTPUT) {
     
    138163                    }
    139164
    140                     // XXX for now, assume cell binning is 1x1 relative to chip
    141                     psImage *subraster = psastroExtractStar (input->image, ref->chip->x, ref->chip->y, DX, DY);
     165                    pmReadout *inReadout = pmFPAviewThisReadout (view, input->fpa);
     166                    psImage *subraster = psastroExtractStar (inReadout->image, ref->chip->x, ref->chip->y, 100.0, 100.0);
     167                    if (!subraster) continue;
     168                   
     169                    snprintf (extname, 80, "extname.%05d", nExt);
     170                    psFitsWriteImage (outStars, NULL, subraster, 0, extname);
     171                    nExt ++;
     172                   
     173                    psFree (subraster);
    142174                }
    143                 if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_AFTER)) ESCAPE;
     175                if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
    144176            }
    145             if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_AFTER)) ESCAPE;
     177            if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
    146178        }
    147179        if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
    148180
     181        fclose (f);
    149182    }
    150183    if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
    151184
    152     // need to close the output fits file on some basis..
    153     fclose (f);
    154 
     185    psFitsClose (outStars);
    155186    psFree (view);
    156187    return true;
    157188}
    158189
     190psImage *psastroExtractStar (psImage *input, float x, float y, float dX, float dY) {
     191
     192  // skip if no pixels are on the image
     193  // skip if center is not on the image
     194  // if bounds fall off image, paste into a full-size image.
     195
     196  if (x < 0) return NULL;
     197  if (y < 0) return NULL;
     198  if (x >= input->numCols) return NULL;
     199  if (y >= input->numRows) return NULL;
     200
     201  psRegion fullRegion = psRegionSet (x - dX, x + dX, y - dY, y + dY);
     202  psRegion realRegion = psRegionForImage (input, fullRegion);
     203  psImage *subset = psImageSubset (input, realRegion);
     204
     205  // if ((subset->numCols < dX) || (subset->numRows < dY)) {
     206  //   psImage *fullsize = psImageAlloc (dX, dY, PS_TYPE_F32);
     207  //   // fill in the fullsize image with the values from the subset
     208  //   // I must already have done this elsewhere...
     209  // }
     210  return subset;
     211}
Note: See TracChangeset for help on using the changeset viewer.