IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 42183


Ignore:
Timestamp:
Apr 28, 2022, 4:13:55 PM (4 years ago)
Author:
eugene
Message:

fpcamera now reads in the chip image, mask, variance; generates pmSources and loads them on the analysis MD; saves the residual image

Location:
branches/eam_branches/ipp-20220316/fpcamera/src
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20220316/fpcamera/src/Makefile.am

    r42178 r42183  
    1818        fpcameraReadAstrometry.c    \
    1919        fpcameraLoadRefstars.c      \
     20        fpcameraChooseRefstars.c    \
    2021        fpcameraCleanup.c
    2122
  • branches/eam_branches/ipp-20220316/fpcamera/src/fpcamera.c

    r42182 r42183  
    1818    fprintf (stderr, "USAGE: one of the following:\n\n");
    1919    fprintf (stderr, "  fpcamera -file filename[,filename,...] -mask maskfile[,maskfile,...] -variance varfile[,varfile,...] -astrom-file (smffile) OutFileBaseName\n");
    20     fprintf (stderr, "  fpcamera -list filelist -masklist masklist -varlist varlist -astrom-file (smffile) -ref (dvopath) -OutFileBaseName\n\n");
     20    fprintf (stderr, "  fpcamera -list filelist -masklist masklist -varlist varlist -astrom-file (smffile) -OutFileBaseName\n\n");
    2121    fprintf (stderr, "where:\n");
    2222    fprintf (stderr, "  FileNameList is a text file containing filenames, one per line\n");
  • branches/eam_branches/ipp-20220316/fpcamera/src/fpcamera.h

    r42178 r42183  
    4949bool              fpcameraLoadRefstars (pmFPAfile *input, pmConfig *config);
    5050bool              fpcameraReadAstrometry (pmFPAfile *input, pmConfig *config);
     51bool              fpcameraChooseRefstars (pmFPAfile *input, pmFPAfile *astrom, pmFPAview *view);
    5152
    5253// Return version strings.
  • branches/eam_branches/ipp-20220316/fpcamera/src/fpcameraAnalysis.c

    r42178 r42183  
    11# include "fpcamera.h"
    22
    3 # define ESCAPE(ERROR, MSG) { psErrorStackPrint(stderr, MSG); return false; }
     3# define ESCAPE(ERROR, MSG) { psErrorStackPrint(stderr, MSG); psFree (view); return false; }
    44
    55/* \brief this function loops over chips and performs forced photometry for the references */
     
    77
    88    bool status;
     9    pmChip *chip;
     10    pmCell *cell;
     11    pmReadout *readout;
     12    pmFPAview *view = NULL;
    913
    1014    // measure the total elapsed time in fpcameraAnalysis.
     
    1519    if (!recipe) ESCAPE (FPCAMERA_ERR_CONFIG, "Can't find FPCAMERA recipe");
    1620
    17     psLogMsg("fpcamera", 3, "TIMEMARK: fpcameraMosaicAstrom: %f sec\n", psTimerMark ("complete"));
     21    // loop over the input images
     22    pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "FPCAMERA.INPUT");
     23    if (!input) ESCAPE(FPCAMERA_ERR_CONFIG, "Can't find or interpret output file rule FPCAMERA.INPUT!");
     24
     25    // astrometry reference (smf)
     26    pmFPAfile *astrom = psMetadataLookupPtr (NULL, config->files, "FPCAMERA.INPUT.ASTROM");
     27    if (!astrom) ESCAPE(FPCAMERA_ERR_CONFIG, "Can't find or interpret output file rule FPCAMERA.INPUT.ASTROM!");
     28
     29    // only activate input image-type files
     30    pmFPAfileActivate (config->files, false, NULL);
     31    pmFPAfileActivate (config->files, true, "FPCAMERA.INPUT");
     32    pmFPAfileActivate (config->files, true, "FPCAMERA.INPUT.MASK");
     33    pmFPAfileActivate (config->files, true, "FPCAMERA.INPUT.VARIANCE");
     34    pmFPAfileActivate (config->files, true, "FPCAMERA.RESID");
     35    // Note FPCAMERA.RESID is tied to FPCAMERA.INPUT so they must be active in the same block.
     36
     37    view = pmFPAviewAlloc (0);
     38
     39    // load images at FPA level (if appropriate)
     40    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE(FPCAMERA_ERR_DATA, "failed to load images at FPA level");
     41
     42    // load images at chip level (if appropriate)
     43    while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
     44        psTrace ("fpcamera", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
     45        if (!chip->process || !chip->file_exists) { continue; }
     46        if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE(FPCAMERA_ERR_DATA, "failed to load images at Chip level");
     47
     48        // loop over all cells in chip
     49        while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
     50            psLogMsg ("fpcamera", 5, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
     51            if (!cell->process || !cell->file_exists) { continue; }
     52
     53            // loop over all readouts in cell
     54            while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
     55                psLogMsg ("fpcamera", 6, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
     56                if (!readout->data_exists) { continue; }
     57
     58                fpcameraChooseRefstars (input, astrom, view);
     59            }
     60        }
     61        if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE(FPCAMERA_ERR_IO, "failure in IOChecks(AFTER) at Chip");
     62    }
     63    if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE(FPCAMERA_ERR_IO, "failure in IOChecks(AFTER) at FPA");
     64
     65    psFree (view);
     66
     67    psLogMsg("fpcamera", 3, "TIMEMARK: fpcameraAnalysis: %f sec\n", psTimerMark ("analysis"));
    1868    return true;
    1969}
     70
     71// NOTES
     72// chip->process is set (unset) based on command-line -chip selections (in fpcameraArguments)
     73// chip->file_exists is set (in pmFPAFlags.c:pmChipSetFileStatus) by pmFPAfileDefineFromArgs (in pmFPAAddSource...)
  • branches/eam_branches/ipp-20220316/fpcamera/src/fpcameraArguments.c

    r42182 r42183  
    5050    }
    5151
     52    // chip selection is used to limit chips to be processed
     53    if ((N = psArgumentGet (argc, argv, "-save-resid"))) {
     54        psArgumentRemove (N, &argc, argv);
     55        psMetadataAddBool (config->arguments, PS_LIST_TAIL, "SAVE.RESID", PS_META_REPLACE, "", true);
     56    }
     57
    5258    // specify the input images to process
    5359    status = pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT",    "-file",     "-list");
     
    6167    status = pmConfigFileSetsMD (config->arguments, &argc, argv, "VARIANCE", "-variance", "-varlist");
    6268    if (!status) ESCAPE(FPCAMERA_ERR_ARGUMENTS, "Missing -variance (input) or -varlist (input)");
    63 
    64     // specify the reference data source (DVO format or ??)
    65     // N = psArgumentGet (argc, argv, "-ref");
    66     // if (!N) ESCAPE (FPCAMERA_ERR_ARGUMENTS, "Missing -ref (database)");
    67     // psArgumentRemove (N, &argc, argv);
    68     // psMetadataAddStr (config->arguments, PS_LIST_TAIL, "FPCAMERA.CATDIR", PS_META_REPLACE, "", argv[N]);
    69     // psArgumentRemove (N, &argc, argv);
    7069
    7170    // specify the astrometry calibration
  • branches/eam_branches/ipp-20220316/fpcamera/src/fpcameraDataSave.c

    r42182 r42183  
    2424    pmFPAfileActivate (config->files, true, "FPCAMERA.OUTPUT");
    2525    pmFPAfileActivate (config->files, true, "FPCAMERA.INPUT.ASTROM");
     26    // Note: I/O for the image-type files is performed in fpcameraAnalysis
    2627
    2728    view = pmFPAviewAlloc (0);
  • branches/eam_branches/ipp-20220316/fpcamera/src/fpcameraLoadRefstars.c

    r42182 r42183  
    11# include "fpcamera.h"
    2 # define ELIXIR_MODE 1
    32
    43# define ESCAPE(ERROR,...) { p_psError(__FILE__,__LINE__,__func__,ERROR,false,__VA_ARGS__); return false; }
     
    3736    DECmax += dDEC * fieldPadding;
    3837
    39     // XXX: fpcameraArguments.c looks for this explicitly on the command line, but stores it in arguments.
    40     // this could be a recipe value which can also be defined as a command-line option
    41 
    4238    // grab the FPCAMERA.CATDIR name from the FPCAMERA recipe
    4339    char *catdir_recipe = psMetadataLookupStr(&status, recipe, "FPCAMERA.CATDIR");
    4440    if (!catdir_recipe) ESCAPE(FPCAMERA_ERR_CONFIG, "Need a recipe for the catdir!");
    4541
    46     // substitute abstract name with concrete name, if present in FPCAMERA.CATDIRS
    47     psMetadata *catdirs = psMetadataLookupMetadata(&status, config->site, "FPCAMERA.CATDIRS"); // List of cameras
    48 
    49     // XXX it is allowed that FPCAMERA.CATDIRS is not defined in site.config: the value must be a real path
    50     // if (!catdirs) ESCAPE(FPCAMERA_ERR_CONFIG, "Unable to find FPCAMERA.CATDIRS in the system configuration.\n");
     42    // *** substitute abstract name with concrete name, if present in FPCAMERA.CATDIRS ***
    5143
    5244    // the name in the recipe may be one of:
     
    5446    // (B) a reference to the name in the FPCAMERA.CATDIRS folder in site.config
    5547    // (C) a reference to a folder in the FPCAMERA.CATDIRS folder in site.config, containing multiple copy locations
     48
     49    // Folder in site.config containing a list of FPCAMERA.CATDIR entries.
     50    // NOTE: it is allowed that FPCAMERA.CATDIRS not be defined in site.config: then FPCAMERA.CATDIR must be a real path
     51    psMetadata *catdirs = psMetadataLookupMetadata(&status, config->site, "FPCAMERA.CATDIRS"); // List of cameras
    5652
    5753    // can we find a plain string matching catdir_recipe in the catdirs folder?
     
    106102    // supply a known output format (for CATALOG output) so the code below knows what to read
    107103    // XXX I do not think this affects the getstar command (CATFORMAT is used to define the dvo db format)
    108     if (ELIXIR_MODE) {
    109         psStringAppend (&getstarCommand, " -D CATMODE mef -D CATFORMAT elixir");
    110     } else {
    111         psStringAppend (&getstarCommand, " -D CATMODE mef -D CATFORMAT panstarrs");
    112     }
     104    // if (ELIXIR_MODE) {
     105    //     psStringAppend (&getstarCommand, " -D CATMODE mef -D CATFORMAT elixir");
     106    // } else {
     107    //     psStringAppend (&getstarCommand, " -D CATMODE mef -D CATFORMAT panstarrs");
     108    // }
    113109
    114     // check for default name (use .ptolemyrc), or use specified CATDIR
    115     if (strcasecmp(CATDIR, "NONE")) {
    116         psStringAppend (&getstarCommand, " -D CATDIR %s", CATDIR);
    117     }
     110    // Define the full getstar command.  Above, we require CATDIR to be valid and defined at
     111    // this point.  Also add region and output filename.
     112    psStringAppend (&getstarCommand, " -D CATDIR %s", CATDIR);
     113    psStringAppend (&getstarCommand, " -format %s", outformat);
     114    psStringAppend (&getstarCommand, " -region %f %f %f %f -o %s", RAmin, DECmin, RAmax, DECmax, tempFile);
     115
    118116    psFree(CATDIR);
    119 
    120     psStringAppend (&getstarCommand, " -format %s", outformat);
    121 
    122     // add region and output filename
    123     psStringAppend (&getstarCommand, " -region %f %f %f %f -o %s", RAmin, DECmin, RAmax, DECmax, tempFile);
    124     psTrace ("fpcamera", 3, "%s\n", getstarCommand);
    125117
    126118    psLogMsg("fpcamera", PS_LOG_INFO, "getstar command: %s", getstarCommand);
    127119
    128     // XXX use psPipe: catch stderr, stdout, allow for Nsec timeout...
    129     // use fork to add timeout capability
     120    // run getstar, result is saved in the temp file
    130121    status = system (getstarCommand);
    131122    if (status) ESCAPE(FPCAMERA_ERR_REFSTARS, "error loading reference data");
     
    140131
    141132    psArray *refstars = NULL;
    142     if (!strcmp (outformat, "CATALOG")) {
    143       refstars = fpcameraReadGetstarCatalog (fits);
    144     }
    145133    if (!strcmp (outformat, "PS1_DEV_0")) {
    146134      refstars = fpcameraReadGetstar_PS1_DEV_0 (fits);
     
    160148    unlink (tempFile);
    161149
    162 # if (0)
    163 
    164     // dump or plot the available refstars
    165     if (psTraceGetLevel("fpcamera.dump") > 0) {
    166         fpcameraDumpRefstars (refstars, "refstars.dat");
    167     }
    168 
    169     pmAstromVisualPlotRefStars (refstars, recipe);
    170 
    171     if (psTraceGetLevel("fpcamera.plot") > 0) {
    172         fpcameraPlotRefstars (refstars, recipe);
    173     }
    174 # endif
    175    
    176150    psMetadataAdd (input->fpa->analysis, PS_LIST_TAIL, "FPCAMERA.REFSTARS", PS_DATA_ARRAY, "reference sources", refstars);
    177151    psFree (refstars);
     
    180154}
    181155
    182 psArray *fpcameraReadGetstarCatalog (psFits *fits) {
    183 
    184     bool status;
    185 
    186     if (ELIXIR_MODE) {
    187         psFitsMoveExtName (fits, "DVO_AVERAGE_ELIXIR");
    188     } else {
    189         psFitsMoveExtName (fits, "DVO_AVERAGE_PANSTARRS");
    190     }
    191 
    192     long numSources = psFitsTableSize(fits); // Number of sources in table
    193 
    194     // convert the Average table to the pmAstromObj entries
    195     psArray *refstars = psArrayAllocEmpty (numSources);
    196     for (int i = 0; i < numSources; i++) {
    197         pmAstromObj *ref = pmAstromObjAlloc ();
    198 
    199         psMetadata *row = psFitsReadTableRow(fits, i); // Table row
    200 
    201         // DVO tables are stored in degrees
    202         if (ELIXIR_MODE) {
    203             ref->sky->r   = RAD_DEG*psMetadataLookupF32 (&status, row, "RA");
    204             ref->sky->d   = RAD_DEG*psMetadataLookupF32 (&status, row, "DEC");
    205             ref->Mag      = 0.001*psMetadataLookupS32 (&status, row, "MAG");  // ELIXIR uses millimags
    206             ref->Color    = 0.0;
    207         } else {
    208             ref->sky->r   = RAD_DEG*psMetadataLookupF64 (&status, row, "RA");
    209             ref->sky->d   = RAD_DEG*psMetadataLookupF64 (&status, row, "DEC");
    210             ref->Mag      = psMetadataLookupF32 (&status, row, "MAG"); // PANSTARRS uses mags
    211             ref->Color    = 0.0;
    212         }
    213         ref->magCal   = ref->Mag;
    214 
    215         // XXX VERY temporary hack to avoid M31 bulge
    216         if ((fabs(ref->sky->r - 0.186438) < 0.002) && (fabs(ref->sky->d - 0.720270) < 0.002)) {
    217           psFree (ref);
    218           psFree (row);
    219           continue;
    220         }
    221 
    222         psArrayAdd (refstars, 100, ref);
    223         psFree (ref);
    224         psFree (row);
    225     }
    226     return refstars;
    227 }
    228 
     156// method to read PS1_DEV_0 format
     157// Note other options can be found in psastroLoadRefstars.c
    229158psArray *fpcameraReadGetstar_PS1_DEV_0 (psFits *fits) {
    230159
     
    250179            ref->Color = MagC1 - MagC2;
    251180        } else {
    252             // XXX save the color and the slope in the table header?
    253181            ref->Color = 0.0;
    254182        }
     
    269197}
    270198
    271 # undef ESCAPE
    272199
    273 # if (0)
    274 
    275 # define ESCAPE(MSG) { \
    276   psLogMsg ("fpcamera", PS_LOG_INFO, MSG); \
    277   goto escape; }
    278 
    279 char *fpcameraSetMagLimit (float *minMag, float *maxRho, pmConfig *config, const char *source) {
    280 
    281     bool status;
    282     char *photcode;
    283 
    284     // select the current recipe
    285     psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, FPCAMERA_RECIPE);
    286 
    287     // select the input data sources
    288     pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, source);
    289     if (!input) {
    290         psLogMsg ("fpcamera", PS_LOG_DETAIL, "no supplied reference header data");
    291         photcode = psStringCopy ("NONE");
    292         return photcode;
    293     }
    294     assert (input->fpa);
    295 
    296     *maxRho = psMetadataLookupF32(&status, recipe, "DVO.GETSTAR.MAX.RHO");
    297     if (!status) {
    298         psError(FPCAMERA_ERR_CONFIG, false, "DVO.GETSTAR.MAX.RHO missing from recipe");
    299         return NULL;
    300     }
    301 
    302     // select the filter; default to fixed photcode and mag limit otherwise
    303     char *filter = psMetadataLookupStr (&status, input->fpa->concepts, "FPA.FILTERID");
    304     if (!status) ESCAPE ("missing FPA.FILTER in concepts");
    305 
    306     float exptime = psMetadataLookupF32 (&status, input->fpa->concepts, "FPA.EXPOSURE");
    307     if (!status) ESCAPE ("missing FPA.EXPOSURE in concepts");
    308 
    309     // we need to select the PHOTCODE.DATA folder that matches our filter
    310     psMetadataItem *item = psMetadataLookup (recipe, "PHOTCODE.DATA");
    311     if (!item) ESCAPE ("PHOTCODE.DATA folders missing");
    312     if (item->type != PS_DATA_METADATA_MULTI) ESCAPE ("PHOTCODE.DATA not a multi");
    313 
    314     float minInst = psMetadataLookupF32(&status, recipe, "DVO.GETSTAR.MIN.MAG.INST");
    315     if (!status) ESCAPE ("missing DVO.GETSTAR.MIN.MAG.INST");
    316 
    317     // if non zero override the zero point in the PHOTCODE.DATA with this value
    318     float fixedzeropt = psMetadataLookupF32(&status, recipe, "DVO.GETSTAR.FIXED.ZEROPT");
    319 
    320     // PHOTCODE.DATA is a multi of metadata items
    321     psListIterator *iter = psListIteratorAlloc(item->data.list, PS_LIST_HEAD, false);
    322 
    323     psMetadataItem *refItem = NULL;
    324     while ((refItem = psListGetAndIncrement (iter))) {
    325         if (refItem->type != PS_DATA_METADATA) ESCAPE ("PHOTCODE.DATA entry is not a metadata folder");
    326 
    327         char *refFilter = psMetadataLookupStr (&status, refItem->data.md, "FILTER");
    328         if (!status) {
    329             psLogMsg ("fpcamera", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER");
    330             continue;
    331         }
    332 
    333         // does this entry match the current filter?
    334         if (strcmp (refFilter, filter)) continue;
    335 
    336         psLogMsg ("fpcamera", PS_LOG_DETAIL, "PHOTCODE.DATA found for filter %s", filter);
    337 
    338         float zeropt = psMetadataLookupF32 (&status, refItem->data.md, "ZEROPT");
    339         if (!status) {
    340             psLogMsg ("fpcamera", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER");
    341             continue;
    342         }
    343         photcode = psMetadataLookupStr (&status, refItem->data.md, "PHOTCODE");
    344         if (!status) {
    345             psLogMsg ("fpcamera", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER");
    346             continue;
    347         }
    348         if (fixedzeropt != 0.0) {
    349             // override the recipe's zero point with the fixed value (used for stacks)
    350             zeropt = fixedzeropt;
    351         }
    352 
    353         // convert the minInst to a calibrated minimum magnitude
    354         *minMag = minInst + 2.5*log10(exptime) + zeropt;
    355 
    356         psFree (iter);
    357         return photcode;
    358     }
    359     psFree (iter);
    360 
    361   escape:
    362     photcode = psMetadataLookupStr(NULL, recipe, "DVO.GETSTAR.PHOTCODE");
    363     PS_ASSERT (photcode, NULL);
    364 
    365     // give up and use fixed value
    366     *minMag = psMetadataLookupF32(NULL, recipe, "DVO.GETSTAR.MIN.MAG");
    367     return photcode;
    368 }
    369 # endif
  • branches/eam_branches/ipp-20220316/fpcamera/src/fpcameraParseCamera.c

    r42182 r42183  
    3434    output->save = true;
    3535
     36    // optionally save the residual image
     37    if (psMetadataLookupBool(&status, config->arguments, "SAVE.RESID")) {
     38        pmFPAfile *output = pmFPAfileDefineOutputFromFile (config, input, "FPCAMERA.RESID");
     39        if (!output) ESCAPE(FPCAMERA_ERR_CONFIG, "Cannot find a rule for FPCAMERA.RESID");
     40        output->save = true;
     41    }
     42
    3643    // Chip selection: turn on only the chips specified (option is not required)
    3744    char *chipLine = psMetadataLookupStr(&status, config->arguments, "CHIP_SELECTIONS");
Note: See TracChangeset for help on using the changeset viewer.