IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12807


Ignore:
Timestamp:
Apr 11, 2007, 2:01:11 PM (19 years ago)
Author:
eugene
Message:

moved psphot and psastro file defines to ppImageParseCamera, using new
psphotDefineFiles,psastroDefineFiles funcions.

Location:
trunk/ppImage/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppImage/src/ppImage.h

    r10558 r12807  
    77
    88#include <stdio.h>
     9#include <string.h>
     10#include <strings.h>  // for strcasecmp
     11#include <unistd.h>   // for unlink
    912#include "pslib.h"
    1013#include "psmodules.h"
  • trunk/ppImage/src/ppImageAstrom.c

    r11352 r12807  
    1717    // find or define a pmFPAfile PSPHOT.INPUT
    1818    pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PSASTRO.INPUT");
    19     if (!status) {
    20         // psphotReadout requires a pmFPAfile supplied with the name PSASTRO.INPUT
    21         // create a pmFPAfile which points at PSPHOT.OUTPUT
    22         // mode is 'REFERENCE' to prevent double frees of the fpa
    23         pmFPAfile *output = psMetadataLookupPtr (&status, config->files, "PSPHOT.OUTPUT");
    24         input = pmFPAfileDefineInput (config, output->fpa, "PSASTRO.INPUT");
    25         input->mode = PM_FPA_MODE_REFERENCE;
    26 
    27         pmFPAfileDefineOutput (config, input->fpa, "PSASTRO.OUTPUT");
    28     }
     19    PS_ASSERT (input, false);
    2920
    3021    // convert the output sources created by psphot into astrometry objects
    3122    if (!psastroConvertFPA (input->fpa, recipe)) {
    32         psErrorStackPrint(stderr, "error loading input data\n");
    33         exit (1);
     23        psError (PSASTRO_ERR_UNKNOWN, false, "error reading input data\n");
     24        return false;
    3425    }
    3526
    36     // interpret the available initial astrometric information
    37     // apply the initial guess
    38     if (!psastroAstromGuess (config)) {
    39         psErrorStackPrint(stderr, "failed to determine initial astrometry guess\n");
    40         exit (1);
     27    if (!psastroAnalysis (config)) {
     28        psError (PSASTRO_ERR_UNKNOWN, false, "failure in psastro analysis\n");
     29        return false;
    4130    }
    4231
    43     // load the reference stars overlapping the data stars
    44     psArray *refs = psastroLoadRefstars(config);
    45     if (!refs) {
    46         psErrorStackPrint(stderr, "failed to load reference data\n");
    47         exit (1);
    48     }
    49 
    50     if (!psastroChooseRefstars (config, refs)) {
    51         psErrorStackPrint(stderr, "failed to select reference data for chips\n");
    52         exit (1);
    53     }
    54 
    55     // XXX does this check the recipe??
    56     bool chipastro = psMetadataLookupBool (NULL, config->arguments, "PSASTRO.CHIP.MODE");
    57     bool mosastro  = psMetadataLookupBool (NULL, config->arguments, "PSASTRO.MOSAIC.MODE");
    58     if (!chipastro && !mosastro) {
    59         psLogMsg ("psastro", 3, "no astrometry mode selected, assuming chip mode\n");
    60         chipastro= true;
    61     }
    62 
    63     if (chipastro) {
    64       if (!psastroChipAstrom (config, refs)) {
    65             psErrorStackPrint(stderr, "failed to perform single chip astrometry\n");
    66             exit (1);
    67         }
    68     }
    69     if (mosastro) {
    70         if (!psastroMosaicAstrom (config, refs)) {
    71             psErrorStackPrint(stderr, "failed to perform mosaic camera astrometry\n");
    72             exit (1);
    73         }
    74     }
    75 
    76     // XXX should this be left to the ppImageLoop?
    77     psastroDataSave (config);
    78 
    79     psFree (refs);
    8032    return true;
    8133}
  • trunk/ppImage/src/ppImageParseCamera.c

    r12746 r12807  
    55# include "ppImage.h"
    66
    7 // XXX clean up error checks: return NULL, not psAbort
    87ppImageOptions *ppImageParseCamera (pmConfig *config) {
    98
     
    1716    }
    1817
    19 #if 0
    20     // the input image defines the camera, and all recipes and options the follow
    21     pmFPAfile *inputMask = pmFPAfileDefineFromArgs (&status, config, "PPIMAGE.INPUT.MASK", "INPUT.MASK");
    22     if (!status || !inputMask) {
    23         psError(PS_ERR_IO, false, "Failed to build FPA from PPIMAGE.INPUT.MASK");
    24         return NULL;
    25     }
    26 
    27     // the input image defines the camera, and all recipes and options the follow
    28     pmFPAfile *inputWeight = pmFPAfileDefineFromArgs (&status, config, "PPIMAGE.INPUT.WEIGHT", "INPUT.WEIGHT");
    29     if (!status || !inputWeight) {
    30         psError(PS_ERR_IO, false, "Failed to build FPA from PPIMAGE.INPUT.WEIGHT");
    31         return NULL;
    32     }
    33 #endif
     18    // if MASK or WEIGHT was supplied on command line, bind files to 'input'
     19    // the mask and weight will be mosaicked with the image
     20    pmFPAfileBindFromArgs (NULL, input, config, "PPIMAGE.INPUT.MASK",   "MASK");
     21    pmFPAfileBindFromArgs (NULL, input, config, "PPIMAGE.INPUT.WEIGHT", "WEIGHT");
    3422
    3523    // add recipe options supplied on command line
     
    189177        psFree(options);
    190178        return NULL;
     179    }
     180
     181    // For photometry, we operate on the chip-mosaicked image
     182    if (options->doPhotom) {
     183        pmFPAfile *psphotInput = pmFPAfileDefineInput (config, byChip->fpa, "PSPHOT.INPUT");
     184        PS_ASSERT (psphotInput, false);
     185        psphotInput->mode = PM_FPA_MODE_REFERENCE;
     186
     187        // define associated psphot input/output files
     188        if (!psphotDefineFiles (config, psphotInput)) {
     189            psError(PSPHOT_ERR_CONFIG, false, "Trouble defining the additional input/output files for psphot");
     190            return false;
     191        }
     192    }
     193
     194    // For photometry, we operate on the chip-mosaicked image
     195    if (options->doAstromChip || options->doAstromMosaic) {
     196        if (!options->doPhotom) {
     197            psError (PSASTRO_ERR_CONFIG, false, "photometry mode is not selected; it is required for astrometry");
     198            return false;
     199        }
     200
     201        pmFPAfile *psphotOutput = psMetadataLookupPtr (&status, config->files, "PSPHOT.OUTPUT");
     202        PS_ASSERT (psphotOutput, false);
     203
     204        pmFPAfile *psastroInput = pmFPAfileDefineInput (config, psphotOutput->fpa, "PSASTRO.INPUT");
     205        PS_ASSERT (psastroInput, false);
     206        psastroInput->mode = PM_FPA_MODE_REFERENCE;
     207
     208        // define associated psphot input/output files
     209        if (!psastroDefineFiles (config, psastroInput)) {
     210            psError(PSPHOT_ERR_CONFIG, false, "Trouble defining the additional input/output files for psastro");
     211            return false;
     212        }
    191213    }
    192214
     
    265287    }
    266288
    267 #if 0
    268     // Get a look inside all the files.
    269     psMetadataIterator *filesIter = psMetadataIteratorAlloc(config->files, PS_LIST_HEAD, NULL); // Iterator
    270     psMetadataItem *item;               // Item from iteration
    271     fprintf(stderr, "Files:\n");
    272     while ((item = psMetadataGetAndIncrement(filesIter))) {
    273         pmFPAfile *file = item->data.V; // File of interest
    274         fprintf(stderr, "%s: %p %p %p (%p) %p\n", file->name,
    275                 file->src, file->fpa,
    276                 file->camera, file->fpa->camera, file->format);
    277     }
    278     psFree(filesIter);
    279 #endif
     289    if (psTraceGetLevel("ppImage.config") > 0) {
     290        // Get a look inside all the files.
     291        psMetadataIterator *filesIter = psMetadataIteratorAlloc(config->files, PS_LIST_HEAD, NULL); // Iterator
     292        psMetadataItem *item;               // Item from iteration
     293        fprintf(stderr, "Files:\n");
     294        while ((item = psMetadataGetAndIncrement(filesIter))) {
     295            pmFPAfile *file = item->data.V; // File of interest
     296            fprintf(stderr, "%s: %p %p %p (%p) %p\n", file->name,
     297                    file->src, file->fpa,
     298                    file->camera, file->fpa->camera, file->format);
     299        }
     300        psFree(filesIter);
     301    }
    280302
    281303    return (options);
  • trunk/ppImage/src/ppImagePhotom.c

    r11364 r12807  
    55# include "ppImage.h"
    66
    7 // the top portion of this function is equivalent to psphotParseCamera,
    8 // but different in a few important ways. 
    9 // XXX move this section to ppImageParseCamera?
     7// In this function, we perform the psphot analysis routine for the chip-mosaicked images
    108bool ppImagePhotom (pmConfig *config, pmFPAview *view) {
    119
     
    1614    psphotModelGroupInit ();
    1715
    18     // select recipe options supplied on command line
    19     psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
    20 
    2116    // find or define a pmFPAfile PSPHOT.INPUT
    2217    pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT");
    2318    if (!status) {
    24         // psphotReadout requires a pmFPAfile supplied with the name PSPHOT.INPUT
    25         // create a pmFPAfile which points to PPIMAGE.OUTPUT.CHIP (guaranteed to be mosaiced by chip)
    26         // mode is 'REFERENCE' to prevent double frees of the fpa
    27         pmFPAfile *output = psMetadataLookupPtr (&status, config->files, "PPIMAGE.OUTPUT.CHIP");
    28         input = pmFPAfileDefineInput (config, output->fpa, "PSPHOT.INPUT");
    29         input->mode = PM_FPA_MODE_REFERENCE;
    30 
    31         // we set the freeLevel to be FPA so this pmFPAfile may be used as input to psastro
    32         // XXX make this the resonsibility of a ppImageAstrom call?
    33         // XXX test for psastro requests?
    34         // XXX need to make this an INTERNAL file if output is not requested.
    35         bool saveOutput = psMetadataLookupBool (NULL, recipe, "SAVE.OUTPUT");
    36         if (saveOutput) {
    37           pmFPAfile *outfile = pmFPAfileDefineOutput (config, input->fpa, "PSPHOT.OUTPUT");
    38           outfile->freeLevel = PM_FPA_LEVEL_FPA;
    39         }
     19        psError(PSPHOT_ERR_CONFIG, false, "PSPHOT.INPUT I/O file is not defined");
     20        return false;
    4021    }
    4122
    42     // if we have requested PSPHOT.SRC (externally supplied sources), attempt to resolve it
    43     if (psMetadataLookupPtr(NULL, config->arguments, "PSPHOT.SRC")) {
    44         pmFPAfileDefineFromArgs (&status, config, "PSPHOT.SRC", "PSPHOT.SRC");
    45         if (!status) {
    46             psError(PSPHOT_ERR_CONFIG, false, "Failed to find/build PSPHOT.SRC");
    47             return status;
    48         }
    49     }
    50 
    51     // NOTE the difference here from psphotParseCamera: the mask and weight
    52     // images are supplied by ppImage and need not / should not be loaded here.
    53 
    54     // optionally load the PSF Model and/or fixed stars
    55     pmFPAfileBindFromArgs (NULL, input, config, "PSPHOT.PSF", "PSPHOT.PSF");
    56 
    57     // set default recipe values here
    58     // XXX place this in a psphot library function?
    59     psMetadataAddStr (recipe, PS_LIST_TAIL, "FITMODE",         PS_META_NO_REPLACE, "default fitting mode", "NONE");
    60     psMetadataAddStr (recipe, PS_LIST_TAIL, "BREAK_POINT",     PS_META_NO_REPLACE, "default break point",  "NONE");
    61     psMetadataAddF32 (recipe, PS_LIST_TAIL, "ZERO_PT",         PS_META_NO_REPLACE, "default zero point",    25.00);
    62     psMetadataAddS32 (recipe, PS_LIST_TAIL, "BACKGROUND.XBIN", PS_META_NO_REPLACE, "default binning",          64);
    63     psMetadataAddS32 (recipe, PS_LIST_TAIL, "BACKGROUND.YBIN", PS_META_NO_REPLACE, "default binning",          64);
    64 
    65     // determine PHOTCODE from fpa & view, overwrite in recipe
    66     char *photcode = pmConceptsPhotcodeForView (config, input, view);
    67     if (photcode) {
    68         psMetadataAddStr (recipe, PS_LIST_TAIL, "PHOTCODE", PS_META_REPLACE, "photcode from FPA concepts", photcode);
    69         psFree (photcode);
    70     }
    71 
    72     // optionally save the residual image
    73     if (psMetadataLookupBool(NULL, recipe, "SAVE.RESID")) {
    74         if (!pmFPAfileDefineOutput (config, input->fpa, "PSPHOT.RESID")) {
    75             psError(PSPHOT_ERR_CONFIG, false, "Cannot find a rule for PSPHOT.BACKMDL");
    76             return false;
    77         }
    78     }
    79 
    80     int DX = psMetadataLookupS32 (&status, recipe, "BACKGROUND.XBIN");
    81     int DY = psMetadataLookupS32 (&status, recipe, "BACKGROUND.YBIN");
    82 
    83     // these calls construct a new fpa for the I/O handle
    84 
    85     // optionally save the background model (small FITS image)
    86     if (psMetadataLookupBool(NULL, recipe, "SAVE.BACKMDL")) {
    87         if (!pmFPAfileDefineFromFPA (config, input->fpa, DX, DY, "PSPHOT.BACKMDL")) {
    88             psError(PSPHOT_ERR_CONFIG, false, "Cannot find a rule for PSPHOT.BACKMDL");
    89             return false;
    90         }
    91     }
    92     // optionally save the full background image
    93     if (psMetadataLookupBool(NULL, recipe, "SAVE.BACKGND")) {
    94         if (!pmFPAfileDefineFromFPA (config, input->fpa,  1,  1, "PSPHOT.BACKGND")) {
    95             psError(PSPHOT_ERR_CONFIG, false, "Cannot find a rule for PSPHOT.BACKGND");
    96             return false;
    97         }
    98     }
    99     // optionally save the background-subtracted image
    100     if (psMetadataLookupBool(NULL, recipe, "SAVE.BACKSUB")) {
    101         if (!pmFPAfileDefineFromFPA (config, input->fpa,  1,  1, "PSPHOT.BACKSUB")) {
    102             psError(PSPHOT_ERR_CONFIG, false, "Cannot find a rule for PSPHOT.");
    103             return false;
    104         }
    105     }
    106     // optionally save the PSF Model
    107     if (psMetadataLookupBool(NULL, recipe, "SAVE.PSF")) {
    108         if (!pmFPAfileDefineOutput (config, input->fpa, "PSPHOT.PSF.SAVE")) {
    109             psError(PSPHOT_ERR_CONFIG, false, "Cannot find a rule for PSPHOT.PSF.SAVE");
    110             return false;
    111         }
    112     }
    113 
    114     // optionally save output plots
    115     if (psMetadataLookupBool(NULL, recipe, "SAVE.PLOTS")) {
    116         if (!pmFPAfileDefineOutput (config, input->fpa, "SOURCE.PLOT.MOMENTS")) {
    117             psTrace ("psphot", 3, "Cannot find a rule for SOURCE.PLOT.MOMENTS");
    118         }
    119         if (!pmFPAfileDefineOutput (config, input->fpa, "SOURCE.PLOT.PSFMODEL")) {
    120             psTrace ("psphot", 3, "Cannot find a rule for SOURCE.PLOT.PSFMODEL");
    121         }
    122     }
    123 
    124     // XXX not tested (or defined?)
    125     // pmFPAfileConstruct (config->files, format, config->camera, "PSPHOT.PSF_SAMPLE");
    126 
    127     // XXX probably need to deactivate all files and activate the psphot ones explicitly
    128 
    129     // In this section, we iterate over the cells and readout for this chip
    130     // and run the psphot analysis routine here
    131     // XXX worry about this not having unique PHOTCODES...
    132     // view->cell = -1;
    133     // iterate over the cells in the current chip
     23    // iterate over the cells and readout for this chip
    13424    while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
    13525        psLogMsg ("ppImagePhotom", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
     
    14636
    14737    // the PSPHOT.INPUT file is a temporary file used to carry PPIMAGE.OUTPUT.CHIP to psphotReadout
     38    // XXX not sure that this is needed...
    14839    pmFPAfileActivate (config->files, false, "PSPHOT.INPUT");
    14940
    15041    return true;
    15142}
     43
     44// XXX do we need to deactivate all files and activate the psphot ones explicitly?
Note: See TracChangeset for help on using the changeset viewer.