IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 27967 for trunk/ppSim


Ignore:
Timestamp:
May 16, 2010, 1:00:37 PM (16 years ago)
Author:
eugene
Message:

updating ppSim to handle cameras with multiple chips (or class_id generally)

Location:
trunk/ppSim/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppSim/src/ppSimSequence.c

    r23259 r27967  
    11# include "ppSimSequence.h"
    22# include <sys/stat.h>
    3 
    4 // XXX Memory leaks in string variables
    53
    64int main (int argc, char **argv) {
     
    135133    psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS);
    136134
    137     psMetadataItem *item = psMetadataLookup (config, "SEQUENCE");
    138     if (item == NULL) {
    139         psLogMsg ("ppSimSequence", PS_LOG_WARN, "missing SEQUENCE description");
    140         exit (PS_EXIT_CONFIG_ERROR);
    141     }
    142 
     135    // global camera option (if not set, we look in each sequence)
     136    if (camera == NULL) {
     137        camera = psMetadataLookupStr (&status, config, "CAMERA");
     138    }
     139
     140    psArray *files = NULL;
    143141    psArray *sequences = NULL;
    144     if (item->type == PS_DATA_METADATA) {
    145         sequences = psArrayAlloc(1);
    146         sequences->data[0] = psMemIncrRefCounter (item->data.V);
    147     } else {
    148         if (item->type != PS_DATA_METADATA_MULTI)  {
    149             psLogMsg ("ppSimSequence", PS_LOG_WARN, "SEQUENCE is not MULTI or METADATA");
    150             exit (1);
    151         }
    152         sequences = psListToArray (item->data.list);
     142
     143    { // find the FILERULE (if it exists) to set the file extension (.fits is default)
     144        psMetadataItem *filerule = psMetadataLookup (config, "FILERULE");
     145        if (filerule == NULL) {
     146            psLogMsg ("ppSimSequence", PS_LOG_INFO, "no FILERULE, assuming .fits ending");
     147            files = psArrayAlloc(1);
     148            files->data[0] = psStringCopy("fits");
     149            goto sequence;
     150        }
     151        if (filerule->type == PS_DATA_METADATA_MULTI) {
     152            psArray *rules = psListToArray (filerule->data.list);
     153            psAssert (rules, "failed to get array from list?");
     154            psAssert (rules->n > 1, "supposed to be multiple entries in the list?");
     155            files = psArrayAllocEmpty(rules->n);
     156            for (int i = 0; i < rules->n; i++) {
     157                psMetadataItem *item = rules->data[i];
     158                if (item->type != PS_DATA_STRING) {
     159                    psLogMsg ("ppSimSequence", PS_LOG_WARN, "invalid FILERULE type");
     160                    exit (PS_EXIT_CONFIG_ERROR);
     161                }
     162                psArrayAdd (files, 16, item->data.str);
     163            }
     164            goto sequence;
     165        }
     166        if (filerule->type == PS_DATA_STRING) {
     167            files = psArrayAlloc(1);
     168            files->data[0] = psStringCopy(filerule->data.str);
     169            goto sequence;
     170        }
     171        psLogMsg ("ppSimSequence", PS_LOG_WARN, "invalid FILERULE type");
     172        exit (PS_EXIT_CONFIG_ERROR);
     173    }
     174
     175sequence:
     176    { // find the set of sequences which define the ppSim data to be produced
     177        psMetadataItem *item = psMetadataLookup (config, "SEQUENCE");
     178        if (item == NULL) {
     179            psLogMsg ("ppSimSequence", PS_LOG_WARN, "missing SEQUENCE description");
     180            exit (PS_EXIT_CONFIG_ERROR);
     181        }
     182
     183        if (item->type == PS_DATA_METADATA) {
     184            sequences = psArrayAlloc(1);
     185            sequences->data[0] = psMemIncrRefCounter (item->data.V);
     186        } else {
     187            if (item->type != PS_DATA_METADATA_MULTI)  {
     188                psLogMsg ("ppSimSequence", PS_LOG_WARN, "SEQUENCE is not MULTI or METADATA");
     189                exit (1);
     190            }
     191            sequences = psListToArray (item->data.list);
     192        }
    153193    }
    154194
     
    172212            camera = psMetadataLookupStr (&status, sequence, "CAMERA");
    173213        }
     214        if (!camera) {
     215            psLogMsg ("ppSimSequence", PS_LOG_WARN, "CAMERA is not defined");
     216            exit (1);
     217        }
    174218
    175219        psString injectCommandReal = NULL;
     
    180224
    181225        if (!strcasecmp (type, "BIAS")) {
    182             ppSimSequenceBias (simfile, inject, sequence, i, rng, path, basename, ppSimCommandReal, injectCommandReal);
     226            ppSimSequenceBias (simfile, inject, sequence, i, rng, path, basename, ppSimCommandReal, injectCommandReal, files);
     227            psFree (injectCommandReal);
     228            psFree (ppSimCommandReal);
    183229            continue;
    184230        }
    185231        if (!strcasecmp (type, "DARK")) {
    186             ppSimSequenceDark (simfile, inject, sequence, i, rng, path, basename, ppSimCommandReal, injectCommandReal);
     232            ppSimSequenceDark (simfile, inject, sequence, i, rng, path, basename, ppSimCommandReal, injectCommandReal, files);
     233            psFree (injectCommandReal);
     234            psFree (ppSimCommandReal);
    187235            continue;
    188236        }
    189237        if (!strcasecmp (type, "FLAT")) {
    190             ppSimSequenceFlat (simfile, inject, sequence, i, rng, path, basename, ppSimCommandReal, injectCommandReal);
     238            ppSimSequenceFlat (simfile, inject, sequence, i, rng, path, basename, ppSimCommandReal, injectCommandReal, files);
     239            psFree (injectCommandReal);
     240            psFree (ppSimCommandReal);
    191241            continue;
    192242        }
    193243        if (!strcasecmp (type, "OBJECT")) {
    194             ppSimSequenceObject (simfile, inject, sequence, i, rng, path, basename, ppSimCommandReal, injectCommandReal);
     244            ppSimSequenceObject (simfile, inject, sequence, i, rng, path, basename, ppSimCommandReal, injectCommandReal, files);
     245            psFree (injectCommandReal);
     246            psFree (ppSimCommandReal);
    195247            continue;
    196248        }
  • trunk/ppSim/src/ppSimSequence.h

    r19315 r27967  
    1212#include <psastro.h>
    1313
    14 bool ppSimSequenceBias   (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand);
    15 bool ppSimSequenceDark   (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand);
    16 bool ppSimSequenceFlat   (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand);
    17 bool ppSimSequenceObject (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand);
     14bool ppSimSequenceBias   (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand, psArray *files);
     15bool ppSimSequenceDark   (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand, psArray *files);
     16bool ppSimSequenceFlat   (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand, psArray *files);
     17bool ppSimSequenceObject (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand, psArray *files);
    1818
    1919#endif
  • trunk/ppSim/src/ppSimSequenceBias.c

    r19315 r27967  
    11# include "ppSimSequence.h"
    22
    3 bool ppSimSequenceBias (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand) {
     3bool ppSimSequenceBias (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand, psArray *files) {
    44
    55    bool status, setLevel, setRange;
     
    1414    int nImage = 0;
    1515    for (int i = 0; i < nImages; i++) {
    16            
     16               
    1717        // define the output filename
    1818        psString filename = NULL;
     
    3030        if (setLevel) psStringAppend (&command, " -biaslevel %f", level);
    3131        if (setRange) psStringAppend (&command, " -biasrange %f", range);
    32      
     32         
    3333        psStringAppend (&command, " %s", filename);
    3434
    3535        fprintf (simfile, "%s\n", command);
    3636        psFree (command);
    37                            
     37                               
    3838        // define the inject command
    3939        // path should be dirname/filename
    40         command = psStringCopy (injectCommand);
    41         psStringAppend (&command, " %s*.fits",    filename);
    42         fprintf (inject, "%s\n", command);
    43         psFree (command);
     40       
     41        // we use the filename above (really the file root) to construct the filenames
     42        for (int i = 0; i < files->n; i++) {
     43            command = psStringCopy (injectCommand);
     44            psStringAppend (&command, " %s.%s", filename, (char *) files->data[i]);
     45            fprintf (inject, "%s\n", command);
     46            psFree (command);
     47        }
     48
    4449        psFree (filename);
    45 
    46         nImage ++;
     50        nImage ++;
    4751    }
    4852    return true;
  • trunk/ppSim/src/ppSimSequenceDark.c

    r19315 r27967  
    11# include "ppSimSequence.h"
    22
    3 bool ppSimSequenceDark (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand) {
     3bool ppSimSequenceDark (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand, psArray *files) {
    44
    55    bool status, setRate;
     
    3939
    4040            psStringAppend (&command, "%s -type DARK", ppSimCommand);
    41      
     41         
    4242            if (setRate) {
    4343                double frnd = psRandomUniform(rng);
     
    5252            fprintf (simfile, "%s\n", command);
    5353            psFree (command);
    54                            
     54                               
    5555            // define the inject command
    5656            // path should be dirname/filename
    57             command = psStringCopy (injectCommand);
    58             psStringAppend (&command, " %s*.fits",    filename);
    59             fprintf (inject, "%s\n", command);
    60             psFree (command);
    61             psFree (filename);
     57       
     58            // we use the filename above (really the file root) to construct the filenames
     59            for (int i = 0; i < files->n; i++) {
     60                command = psStringCopy (injectCommand);
     61                psStringAppend (&command, " %s.%s", filename, (char *) files->data[i]);
     62                fprintf (inject, "%s\n", command);
     63                psFree (command);
     64            }
    6265
    63             nImage ++;
    64         }
     66            psFree (filename);
     67            nImage ++;
     68        }
    6569    }
    6670    return true;
  • trunk/ppSim/src/ppSimSequenceFlat.c

    r19315 r27967  
    11# include "ppSimSequence.h"
    22
    3 bool ppSimSequenceFlat (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand) {
     3bool ppSimSequenceFlat (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand, psArray *files) {
    44
    55    bool status;
     
    2626        // loop over the filters & exposure times
    2727        for (int j = 0; j < nSetup; j++) {
    28            
     28               
    2929            // define the output filename
    3030            psString filename = NULL;
     
    5050            // define the inject command
    5151            // path should be dirname/filename
    52             command = psStringCopy (injectCommand);
    53             psStringAppend (&command, " %s*.fits",    filename);
    54             fprintf (inject, "%s\n", command);
    55             psFree (command);
    56             psFree (filename);
     52       
     53            // we use the filename above (really the file root) to construct the filenames
     54            for (int i = 0; i < files->n; i++) {
     55                command = psStringCopy (injectCommand);
     56                psStringAppend (&command, " %s.%s", filename, (char *) files->data[i]);
     57                fprintf (inject, "%s\n", command);
     58                psFree (command);
     59            }
    5760
    58             nImage ++;
     61            psFree (filename);
     62            nImage ++;
    5963        }
    6064    }
  • trunk/ppSim/src/ppSimSequenceObject.c

    r24099 r27967  
    11# include "ppSimSequence.h"
    22
    3 bool ppSimSequenceObject (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand) {
     3bool ppSimSequenceObject (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand, psArray *files) {
    44
    55    bool status;
     
    3434    // loop over the filters & exposure times
    3535    for (int i = 0; i < filters->n; i++) {
    36            
     36               
    3737        // offset parameters
    3838        float dR = psMetadataLookupF32 (&status, sequence, "OFFSET.RA");
    3939        float dD = psMetadataLookupF32 (&status, sequence, "OFFSET.DEC");
    40  
     40     
    4141        int nR = psMetadataLookupS32 (&status, sequence, "OFFSET.NR");
    4242        int nD = psMetadataLookupS32 (&status, sequence, "OFFSET.ND");
    43  
     43     
    4444        // loop over the offset sequence
    4545        for (int iR = 0; iR < nR; iR++) {
     
    5050                float R = Ro + dR*(iR - 0.5*nR + 0.5) / cos (RAD_DEG*Do) / 3600.0;
    5151                float D = Do + dD*(iD - 0.5*nD + 0.5) / 3600.0;
    52      
     52             
    5353                // dither parameters
    5454                float dr = psMetadataLookupF32 (&status, sequence, "DITHER.RA");
    5555                float dd = psMetadataLookupF32 (&status, sequence, "DITHER.DEC");
    56  
     56         
    5757                int nr = psMetadataLookupS32 (&status, sequence, "DITHER.NR");
    5858                int nd = psMetadataLookupS32 (&status, sequence, "DITHER.ND");
    59  
     59         
    6060                // loop over the dither sequence
    6161                for (int ir = 0; ir < nr; ir++) {
     
    6565                        float ra = R + dr*(ir - 0.5*nr + 0.5) / cos (RAD_DEG*D) / 3600.0;
    6666                        float dec = D + dd*(id - 0.5*nd + 0.5) / 3600.0;
    67          
     67                     
    6868                        // rotation sequence parameters
    6969                        float pos_min   = psMetadataLookupF32 (&status, sequence, "POS_MIN");
     
    7272                        assert (pos_delta > 0.0);
    7373                        assert (pos_max >= pos_min);
    74            
     74                       
    7575                        // loop over rotation sequence
    7676                        for (float pos = pos_min; pos <= pos_max; pos += pos_delta) {
    77              
     77                         
    7878                            // define the output filename
    7979                            psString filename = NULL;
     
    9595                            psStringAppend (&command, " -dec %f", dec);
    9696                            psStringAppend (&command, " -pa %f", pos);
    97                             psStringAppend (&command, " -obs_mode OBJECT.%s", (char *) filters->data[i]);
     97                            psStringAppend (&command, " -obs_mode OBJECT.%s", (char *) filters->data[i]);
    9898
    9999                            double frnd = psRandomUniform(rng);
    100100                            float seeing = IQmin + (IQmax - IQmin)*frnd;
    101              
     101                         
    102102                            psStringAppend (&command, " -seeing %f", seeing);
    103103
     
    106106                            fprintf (simfile, "%s\n", command);
    107107                            psFree (command);
    108                            
     108                                       
    109109                            // define the inject command
    110110                            // path should be dirname/filename
    111                             command = psStringCopy (injectCommand);
    112                             psStringAppend (&command, " %s*.fits",    filename);
    113                             fprintf (inject, "%s\n", command);
    114                             psFree (command);
     111                           
     112                            // we use the filename above (really the file root) to construct the filenames
     113                            for (int i = 0; i < files->n; i++) {
     114                                command = psStringCopy (injectCommand);
     115                                psStringAppend (&command, " %s.%s", filename, (char *) files->data[i]);
     116                                fprintf (inject, "%s\n", command);
     117                                psFree (command);
     118                            }
     119
    115120                            psFree (filename);
    116 
    117121                            nImage ++;
    118122                        }
Note: See TracChangeset for help on using the changeset viewer.