IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6522


Ignore:
Timestamp:
Mar 5, 2006, 2:02:35 PM (20 years ago)
Author:
eugene
Message:

working on file I/O modifications

Location:
trunk/psphot/src
Files:
3 added
6 edited

Legend:

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

    r6481 r6522  
    312312    return false;
    313313}
     314
     315ppImageLoadDepth ppImageCheckDepth (psMetadata *recipe, char *name) {
     316
     317    bool status;
     318
     319    // determine the load depth
     320    const char *depth = psMetadataLookupStr(&status, recipe, name);
     321    if (! status || ! depth || strlen(depth) == 0) {
     322        psLogMsg("psphot", PS_LOG_ERROR, "%s not specified in recipe.", name);
     323        exit(EXIT_FAILURE);
     324    }
     325
     326    if (!strcasecmp(depth, "FPA"))  return (PP_LOAD_FPA);
     327    if (!strcasecmp(depth, "CHIP")) return (PP_LOAD_CHIP);
     328    if (!strcasecmp(depth, "CELL")) return (PP_LOAD_CELL);
     329
     330    psLogMsg(__func__, PS_LOG_ERROR, "%s in recipe is not FPA, CHIP or CELL.", name);
     331    exit(EXIT_FAILURE);
     332
     333    return PP_LOAD_NONE;
     334}
  • trunk/psphot/src/psModulesUtils.h

    r6481 r6522  
    3535} ppFile;
    3636
     37typedef struct {
     38    ppFile *input;
     39    ppFile *resid;
     40    ppFile *background;
     41    ppFile *backSub;
     42    ppFile *output;
     43    ppFile *psfdata;
     44    ppFile *psfsample;
     45} psphotData;
     46
    3747// psModule extra utilities
    3848// bool      pmSourceFitModel_EAM(pmSource *source, pmModel *model, const bool PSF);
  • trunk/psphot/src/psphotArguments.c

    r6481 r6522  
    176176
    177177static void usage (void) {
    178 
    179178    fprintf (stderr, "USAGE: psphot (image) (output)\n");
    180179    exit (2);
  • trunk/psphot/src/psphotImageLoop.c

    r6379 r6522  
    11# include "psphot.h"
    22
    3 bool psphotImageLoop (ppFile *file, ppConfig *config) {
     3bool psphotImageLoop (psphotData *data, ppConfig *config) {
    44
    5     bool status;
    6     ppImageLoadDepth imageLoadDepth;
     5    pmFPA *fpa = data->input->fpa;
    76
    8     // determine the load depth
    9     const char *depth = psMetadataLookupStr(&status, config->recipe, "LOAD.DEPTH");
    10     if (! status || ! depth || strlen(depth) == 0) {
    11         psLogMsg("psphot", PS_LOG_ERROR, "LOAD.DEPTH not specified in recipe.");
    12         exit(EXIT_FAILURE);
    13     }
    14     imageLoadDepth = PP_LOAD_NONE;
    15     if (!strcasecmp(depth, "FPA")) imageLoadDepth = PP_LOAD_FPA;
    16     if (!strcasecmp(depth, "CHIP")) imageLoadDepth = PP_LOAD_CHIP;
    17     if (!strcasecmp(depth, "CELL")) imageLoadDepth = PP_LOAD_CELL;
    18     if (imageLoadDepth == PP_LOAD_NONE) {
    19         psLogMsg(__func__, PS_LOG_ERROR, "LOAD.DEPTH in recipe is not FPA, CHIP or CELL.");
    20         exit(EXIT_FAILURE);
    21     }
     7    psphotDataIO (data, config, -1, -1);
    228
    23     if (imageLoadDepth == PP_LOAD_FPA) {
    24         psTrace(__func__, 1, "Loading pixels for FPA...\n");
    25         ppImageLoadPixels(file, config->database, -1, -1);
    26     }
    27 
    28     for (int i = 0; i < file->fpa->chips->n; i++) {
    29         pmChip *chip = file->fpa->chips->data[i]; // Chip of interest in input image
     9    for (int i = 0; i < fpa->chips->n; i++) {
     10        pmChip *chip = fpa->chips->data[i]; // Chip of interest in input image
    3011
    3112        psLogMsg ("psphot", 4, "Chip %d: %x %x\n", i, chip->exists, chip->process);
    3213        if (! chip->process) { continue; }
    3314
    34         if (imageLoadDepth == PP_LOAD_CHIP) {
    35             psTrace(__func__, 1, "Loading pixels for chip %d...\n", i);
    36             ppImageLoadPixels(file, config->database, i, -1);
    37         }
     15        psphotDataIO (data, config, i, -1);
    3816
    3917        for (int j = 0; j < chip->cells->n; j++) {
     
    4321            if (! cell->process) { continue; }
    4422
    45             if (imageLoadDepth == PP_LOAD_CELL) {
    46                 psTrace(__func__, 1, "Loading pixels for chip %d, cell %d...\n", i, j);
    47                 ppImageLoadPixels(file, config->database, i, j);
    48             }
    49            
     23            psphotDataIO (data, config, i, j);
     24
    5025            // XXX optional mask and weight input image should be loaded here?
    5126            // this sets the weight map and basic mask applying CELL.BAD and CELL.SATURATION
     
    6136                // run a single-model test if desired
    6237                psphotModelTest (readout, config->arguments, config->recipe);
    63                 psphotReadout (readout, config->recipe);
    64                 psphotOutput (readout, config->arguments);
     38
     39                // run the actual photometry analysis
     40                psphotReadout (readout, data, config);
     41
     42                // XXX what do we do if we have multiple readouts?
     43                psphotOutput (readout, data, config);
    6544            }
    6645        }
    6746    }
     47    psphotOutputClose (data);
    6848    return true;
    6949}
  • trunk/psphot/src/psphotOutput.c

    r6495 r6522  
    1414static char *psfSample  = NULL;
    1515
    16 void psphotOutputCleanup () {
    17 
    18     psFree (outputRoot);
    19     psFree (outputName);
    20     psFree (outputMode);
    21     psFree (outputFormat);
    22     psFree (extNumberFormat);
    23     psFree (extNameKey);
    24     psFree (extRoot);
    25     psFree (psfFile);
    26     psFree (psfSample);
    27     return;
     16static psFits *outputFits = NULL;
     17static FILE   *outputFile = NULL;
     18
     19bool psphotDataIO (psphotData *data, ppConfig *config, int chip, int cell) {
     20
     21    // load input data, if depth is appropriate
     22    ppImageLoadDepth loadDepth = ppImageCheckDepth (config->recipe, "LOAD.DEPTH");
     23    if ((chip == -1) && (cell == -1) && (loadDepth == PP_LOAD_FPA)) {
     24        psTrace(__func__, 1, "Loading pixels for FPA...\n");
     25        ppImageLoadPixels(data->input, config->database, -1, -1);
     26    }
     27    if ((chip != -1) && (cell == -1) && (loadDepth == PP_LOAD_CHIP)) {
     28        psTrace(__func__, 1, "Loading pixels for chip %d...\n", i);
     29        ppImageLoadPixels(data->input, config->database, chip, -1);
     30    }
     31    if ((chip != -1) && (cell != -1) && (loadDepth == PP_LOAD_CELL)) {
     32        psTrace(__func__, 1, "Loading pixels for chip %d, cell %d...\n", i, j);
     33        ppImageLoadPixels(data->input, config->database, chip, cell);
     34    }
     35
     36
     37
     38    if (saveDepth == PP_LOAD_FPA) {
     39        psTrace(__func__, 1, "Saving objects for FPA...\n");
     40        psphotOutputOpen (file->fpa->phu);
     41    }
     42
     43    ppImageLoadDepth saveDepth = ppImageCheckDepth (config->recipe, "SAVE.DEPTH");
     44   
     45
    2846}
    2947
     
    4664    extNameKey      = psMetadataLookupStr (&status, config->recipe, "EXTNAME");
    4765    extRoot         = psMetadataLookupStr (&status, config->recipe, "EXTROOT");
     66
     67    headExtname     = psMetadataLookupStr (&status, config->recipe, "HEAD_EXTNAME");
     68    dataExtname     = psMetadataLookupStr (&status, config->recipe, "DATA_EXTNAME");
    4869
    4970    if (extNumberFormat == NULL) {
     
    7697    }
    7798
    78     // for MEF output, we need to open a file up front
     99    // for MEF output, we only allow certain output formats
    79100    if (!strcasecmp (outputMode, "MEF")) {
     101        if (!strcasecmp (outputFormat, "CMF")) goto valid_format;
    80102        psLogMsg ("psphot", PS_LOG_ERROR, "MEF output mode unavailable");
    81103        exit (1);
    82104    }
     105valid_format:
    83106
    84107    // register background image-file names
     
    99122}
    100123
    101 // generate the SPLIT filenames
    102 char *psphotSplitName (psMetadata *header) {
    103 
    104     bool status;
    105 
    106     char *newName = NULL;     // destination for resulting name
    107     char *extNameWord = NULL; // this contains the per-extension word to add
    108     char  extNumberWord[16];  // this will store the string-formatted number
    109 
    110     // extNumberFormat must be set to a valid entry in psphotOutputPrep
    111     sprintf (extNumberWord, extNumberFormat, extNumber);
    112 
    113     // find the extname:
    114     char *extNameVal = psMetadataLookupStr (&status, header, extNameKey);
    115            
    116     extNameWord = extNameVal;
    117     if ((extRoot != NULL) && (extNameVal != NULL)) {
    118         // check that the extNameVal matches the expected root
    119         if (strncmp (extNameVal, extRoot, strlen(extRoot))) {
    120             psLogMsg ("psphotSplitName", PS_LOG_WARN, "header entry does not match expected format");
     124bool psphotOutputOpen (psMetadata *phu){
     125
     126    /* outputFile is used by text-format outputs */
     127
     128    psFree (outputFile);
     129    outputFile = psphotOutputName (phu, outputName);
     130
     131    /* for fits-format output, open outputFits */
     132    if (!strcasecmp (outputFormat, "CMF")) {
     133        if (outputFits != NULL) {
     134            psFitsClose (outputFits);
    121135        }
    122         extNameWord = extNameVal + strlen(extRoot);
    123     }
    124 
    125     if (extNameWord != NULL) {
    126         psStringStrip (extNameWord);
    127     }
    128 
    129     // note : if the user mis-specifies the output name, we will happily overwrite files
    130     newName = psStringCopy (outputName);
    131     newName = psphotNameSubstitute (newName, outputRoot, "%r");
    132     newName = psphotNameSubstitute (newName, extNameWord, "%x");
    133     newName = psphotNameSubstitute (newName, extNumberWord, "%n");
    134 
    135     return newName;
    136 }
    137 
    138 
    139 // given the input string, search for the key, and replace with the replacement
    140 // the input string may be freed if not needed
    141 char *psphotNameSubstitute (char *input, char *replace, char *key) {
    142 
    143     char *p;
    144 
    145     if (key == NULL) return input;
    146     if (strlen(key) == 0) return input;
    147 
    148     p = strstr (input, key);
    149     if (p == NULL) return input;
    150 
    151     // we have input = xxxkeyxxx
    152     // we want output = xxxreplacexxx
    153 
    154     // this is safe since we will subtract strlen(key) elements from input
    155     char *output = psAlloc(strlen(input) + strlen(replace) + 1);
    156     int Nc = p - input;
    157 
    158     // copy the first segement into 'output'
    159     strncpy (output, input, Nc);
    160 
    161     // copy the key replacement to the start of the key
    162 
    163     strcpy (&output[Nc], replace);
    164     Nc += strlen (replace);
    165    
    166     // copy the remainder to the end of the replacement
    167     strcpy (&output[Nc], p + strlen(key));
    168 
    169     psFree (input);
    170     return output;
     136        outputFits = psFitsOpen (outputFile, "w");
     137
     138        if (!strcasecmp (outputMode, "MEF")) {
     139            psFitsWriteHeader (outputFits, phu);
     140        }
     141    }
     142    return true;
     143}
     144
     145bool psphotOutputClose (void) {
     146
     147    if (outputFile != NULL) {
     148        psFitsClose (outputFile);
     149    }
     150    return true;
    171151}
    172152
     
    190170    }
    191171
     172    if (!strcasecmp (outputMode, "MEF")) {
     173        headExt = psphotOutputName (header, headExtname);
     174        dataExt = psphotOutputName (header, dataExtname);
     175    }
     176    if (!strcasecmp (outputMode, "SPLIT")) {
     177        dataExt = psphotOutputName (header, dataExtname);
     178    }
     179
    192180    char *residImage = psMetadataLookupStr (&status, arguments, "RESID_IMAGE");
    193 
    194181    if (psfSample != NULL) psphotSamplePSFs (psf, readout->image, psfSample);
    195182    if (residImage != NULL) psphotSaveImage (header, readout->image, residImage);
     
    225212    }
    226213    if (!strcasecmp (outputFormat, "CMF")) {
    227         pmSourcesWriteCMF (sources, outputFile, header);
     214        pmSourcesWriteCMF (sources, header, headExt, dataExt);
    228215        psFree (outputFile);
    229216        return;
     
    483470        psMetadataAdd (row, PS_LIST_TAIL, "MAG_RAW", PS_DATA_F32, "", source->fitMag + ZERO_POINT);
    484471        psMetadataAdd (row, PS_LIST_TAIL, "MAG_ERR", PS_DATA_F32, "", (int)(1000*dmag));
    485         psMetadataAdd (row, PS_LIST_TAIL, "MAG_GAL", PS_DATA_F32, "", type);
    486         psMetadataAdd (row, PS_LIST_TAIL, "MAG_AP",  PS_DATA_F32, "", lsky);
    487         psMetadataAdd (row, PS_LIST_TAIL, "LOG_SKY", PS_DATA_F32, "", 32.0);
    488         psMetadataAdd (row, PS_LIST_TAIL, "FWHM_X",  PS_DATA_F32, "", source->apMag + ZERO_POINT);
     472        psMetadataAdd (row, PS_LIST_TAIL, "MAG_GAL", PS_DATA_F32, "", 32.0);
     473        psMetadataAdd (row, PS_LIST_TAIL, "MAG_AP",  PS_DATA_F32, "", source->apMag + ZERO_POINT);
     474        psMetadataAdd (row, PS_LIST_TAIL, "LOG_SKY", PS_DATA_F32, "", lsky);
     475        psMetadataAdd (row, PS_LIST_TAIL, "FWHM_X",  PS_DATA_F32, "", type);
    489476        psMetadataAdd (row, PS_LIST_TAIL, "FWHM_Y",  PS_DATA_F32, "", PAR[4]);
    490477        psMetadataAdd (row, PS_LIST_TAIL, "THETA",   PS_DATA_F32, "", PAR[5]);
  • trunk/psphot/src/psphotReadout.c

    r6481 r6522  
    1212    // generate a background model (median, smoothed image)
    1313    skymodel = psphotImageMedian (readout, config);
     14
     15    // optional output of background-subtracted image
     16    psphot
    1417
    1518    // find the peaks in the image
Note: See TracChangeset for help on using the changeset viewer.