IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 27, 2022, 4:30:04 PM (4 years ago)
Author:
eugene
Message:

fpcamera now reads the astrometry and loads the refstars

Location:
branches/eam_branches/ipp-20220316/fpcamera/src
Files:
7 edited

Legend:

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

    r42176 r42182  
    1616
    1717void usage(void) {
    18     fprintf (stderr, "USAGE: one of the following\n");
    19     fprintf (stderr, "fpcamera -file filename[,filename,...] -mask maskfile[,maskfile,...] -variance varfile[,varfile,...] -astrom-file (smffile) -ref (dvopath) -OutFileBaseName\n\n");
    20     fprintf (stderr, "fpcamera -list filelist -masklist masklist -varlist varlist -astrom-file (smffile) -ref (dvopath) -OutFileBaseName\n\n");
     18    fprintf (stderr, "USAGE: one of the following:\n\n");
     19    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");
    2121    fprintf (stderr, "where:\n");
    2222    fprintf (stderr, "  FileNameList is a text file containing filenames, one per line\n");
     
    2525    fprintf (stderr, "  OutFileBaseName is the 'root name' for output files\n\n");
    2626    fprintf(stderr, "Optional arguments:\n");
    27     fprintf(stderr, "\t-stats STATS.mdc: Output statistics into STATS.mdc\n");
    28     fprintf(stderr, "\t-chip CHIPNUM: Only process this chip number.\n\n");
     27    fprintf(stderr, "   -stats STATS.mdc: Output statistics into STATS.mdc\n");
     28    fprintf(stderr, "   -chip CHIPNUM: Only process this chip number.\n\n");
     29    fprintf(stderr, "   -D FPCAMERA.CATDIR (catdir): specify the reference catalog.\n\n");
    2930    exit (PS_EXIT_CONFIG_ERROR);
    3031}
  • branches/eam_branches/ipp-20220316/fpcamera/src/fpcameraArguments.c

    r42175 r42182  
    6363
    6464    // 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);
     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);
    7070
    7171    // specify the astrometry calibration
  • branches/eam_branches/ipp-20220316/fpcamera/src/fpcameraDataLoad.c

    r42178 r42182  
    1010
    1111    // select the input data sources
    12     pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "FPCAMERA.INPUT.SMF");
    13     if (!input) ESCAPE (PS_ERR_UNKNOWN, "FPCAMERA.INPUT.SMF not listed in config->files");
     12    pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "FPCAMERA.INPUT.ASTROM");
     13    if (!input) ESCAPE (PS_ERR_UNKNOWN, "FPCAMERA.INPUT.ASTROM not listed in config->files");
    1414
    15     // XXX pass input to fpcameraReadAstrometry?
    16     // XXX change name of function?
     15    // read the astrometry calibration information (from cmf/smf)
    1716    if (!fpcameraReadAstrometry (input, config)) ESCAPE (PS_ERR_UNKNOWN, "Failure to read astrometry calibration");
    1817
  • branches/eam_branches/ipp-20220316/fpcamera/src/fpcameraDataSave.c

    r42178 r42182  
    2323    pmFPAfileActivate (config->files, false, NULL);
    2424    pmFPAfileActivate (config->files, true, "FPCAMERA.OUTPUT");
     25    pmFPAfileActivate (config->files, true, "FPCAMERA.INPUT.ASTROM");
    2526
    2627    view = pmFPAviewAlloc (0);
     
    7475
    7576    // activate all files except FPCAMERA.OUTPUT, and PSPHOT.OUTPUT.CFF
    76     pmFPAfileActivate (config->files, true, NULL);
    77     pmFPAfileActivate (config->files, false, "FPCAMERA.OUTPUT");
     77    // pmFPAfileActivate (config->files, true, NULL);
     78    // pmFPAfileActivate (config->files, false, "FPCAMERA.OUTPUT");
    7879
    7980    psFree (view);
  • branches/eam_branches/ipp-20220316/fpcamera/src/fpcameraLoadRefstars.c

    r42178 r42182  
    1313    psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, FPCAMERA_RECIPE);
    1414
    15     // DVO APIs expect decimal degrees
    16     float RAmin  = DEG_RAD*psMetadataLookupF32(NULL, recipe, "RA_MIN");
    17     float RAmax  = DEG_RAD*psMetadataLookupF32(NULL, recipe, "RA_MAX");
    18     float DECmin = DEG_RAD*psMetadataLookupF32(NULL, recipe, "DEC_MIN");
    19     float DECmax = DEG_RAD*psMetadataLookupF32(NULL, recipe, "DEC_MAX");
     15    // FPA FOV is determined by fpcameraReadAstrometry & save on fpa->analysis
     16    float RAmin  = psMetadataLookupF32(NULL, input->fpa->analysis, "RA_MIN");
     17    float RAmax  = psMetadataLookupF32(NULL, input->fpa->analysis, "RA_MAX");
     18    float DECmin = psMetadataLookupF32(NULL, input->fpa->analysis, "DEC_MIN");
     19    float DECmax = psMetadataLookupF32(NULL, input->fpa->analysis, "DEC_MAX");
    2020
    2121    // extra field fraction to add
     
    3737    DECmax += dDEC * fieldPadding;
    3838
     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
    3942    // grab the FPCAMERA.CATDIR name from the FPCAMERA recipe
    4043    char *catdir_recipe = psMetadataLookupStr(&status, recipe, "FPCAMERA.CATDIR");
     
    4346    // substitute abstract name with concrete name, if present in FPCAMERA.CATDIRS
    4447    psMetadata *catdirs = psMetadataLookupMetadata(&status, config->site, "FPCAMERA.CATDIRS"); // List of cameras
    45     if (!catdirs) ESCAPE(FPCAMERA_ERR_CONFIG, "Unable to find FPCAMERA.CATDIRS in the system configuration.\n");
     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");
    4651
    4752    // the name in the recipe may be one of:
     
    4954    // (B) a reference to the name in the FPCAMERA.CATDIRS folder in site.config
    5055    // (C) a reference to a folder in the FPCAMERA.CATDIRS folder in site.config, containing multiple copy locations
    51     char *catdir_virtual = psMetadataLookupStr(&status, catdirs, catdir_recipe);
    52 
    53     psMetadata *catdir_folder = psMetadataLookupMetadata(&status, catdirs, catdir_recipe);
     56
     57    // can we find a plain string matching catdir_recipe in the catdirs folder?
     58    char *catdir_virtual = catdirs ? psMetadataLookupStr(&status, catdirs, catdir_recipe) : NULL;
     59
     60    // OR, can we find a subfolder in the catdirs folder?
     61    psMetadata *catdir_folder = catdirs ? psMetadataLookupMetadata(&status, catdirs, catdir_recipe) : NULL;
    5462    if (catdir_folder) {
    5563        // randomly choose one of the entries
     
    6977    }
    7078
     79    // if catdir_virtual is NULL, catdir_recipe must be a file name
    7180    char *catdir = (catdir_virtual == NULL) ? catdir_recipe : catdir_virtual;
    7281
    7382    // convert the uri to a real filename (ie, path://foobar)
    7483    psString CATDIR = pmConfigConvertFilename(catdir, config, false, false); // Resolved filename
    75     ESCAPE(FPCAMERA_ERR_CONFIG, "unable to determine filename for CATDIR %s", catdir);
     84    if (!CATDIR) ESCAPE(FPCAMERA_ERR_CONFIG, "unable to determine filename for CATDIR %s", catdir);
    7685
    7786    psLogMsg ("fpcamera", 3, "looking up reference objects in %s\n", CATDIR);
    7887
    7988    char *getstarCommand = psStringCopy(psMetadataLookupStr(NULL, recipe, "DVO.GETSTAR"));
    80     ESCAPE(FPCAMERA_ERR_CONFIG, "unable to find DVO.GETSTAR in recipe");
     89    if (!getstarCommand) ESCAPE(FPCAMERA_ERR_CONFIG, "unable to find DVO.GETSTAR in recipe");
    8190
    8291    char *outformat = psMetadataLookupStr(NULL, recipe, "DVO.GETSTAR.OUTFORMAT");
    83     ESCAPE(FPCAMERA_ERR_CONFIG, "unable to find DVO.GETSTAR.OUTFORMAT in recipe");
     92    if (!outformat) ESCAPE(FPCAMERA_ERR_CONFIG, "unable to find DVO.GETSTAR.OUTFORMAT in recipe");
    8493
    8594    // issue the following command:
     
    166175   
    167176    psMetadataAdd (input->fpa->analysis, PS_LIST_TAIL, "FPCAMERA.REFSTARS", PS_DATA_ARRAY, "reference sources", refstars);
     177    psFree (refstars);
     178
    168179    return true;
    169180}
  • branches/eam_branches/ipp-20220316/fpcamera/src/fpcameraParseCamera.c

    r42178 r42182  
    2323    // the input smf file is a required argument
    2424    pmFPAfileDefineFromArgs (&status, config, "FPCAMERA.INPUT.ASTROM", "INPUT.ASTROM");
    25     if (!status) ESCAPE(FPCAMERA_ERR_CONFIG, "Failed to build FPA from FPCAMERA.INPUT.SMF");
     25    if (!status) ESCAPE(FPCAMERA_ERR_CONFIG, "Failed to build FPA from FPCAMERA.INPUT.ASTROM");
    2626
    2727    // select the current recipe
  • branches/eam_branches/ipp-20220316/fpcamera/src/fpcameraReadAstrometry.c

    r42178 r42182  
    11# include "fpcamera.h"
     2
     3# define ESCAPE(ERROR, MSG) { psError(ERROR, false, MSG); psFree(view); return false; }
    24
    35/* \brief this function loads the astrometry calibration from the input smf file */
     
    57
    68    bool status;
     9    pmChip *chip = NULL;
     10    pmFPAview *view = NULL;
    711
    812    // select the current recipe (just needed for pixel scale)
     13    // XXX this is defined in psastro.config : use that value instead of one defined in fpcamera.config?
    914    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, FPCAMERA_RECIPE);
    10     if (!recipe) {
    11         psError(FPCAMERA_ERR_CONFIG, true, "Can't find FPCAMERA recipe!\n");
    12         return false;
    13     }
     15    if (!recipe) ESCAPE(FPCAMERA_ERR_CONFIG, "Can't find FPCAMERA recipe!");
    1416
    1517    // physical pixel scale in microns per pixel (used in case of non-bilevel astrometry)
    1618    double pixelScale = psMetadataLookupF32 (&status, recipe, "FPCAMERA.PIXEL.SCALE");
    17     if (!status) {
    18         psError(PS_ERR_IO, true, "Failed to lookup pixel scale");
    19         return false;
    20     }
     19    if (!status) ESCAPE(PS_ERR_IO, "Failed to lookup pixel scale");
    2120
    22     pmFPAview *view = pmFPAviewAlloc (0);
     21    // de-activate all files except FPCAMERA.INPUT.ASTROM (where we get the astrometric calibration)
     22    pmFPAfileActivate (config->files, false, NULL);
     23    pmFPAfileActivate (config->files, true, "FPCAMERA.INPUT.ASTROM");
     24
     25    view = pmFPAviewAlloc (0);
     26
     27    // load headers for astrometry calibration
     28    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE(FPCAMERA_ERR_DATA, "failed to load header at FPA level");
     29
     30    // add in chip headers
     31    while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
     32        psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
     33        if (!chip->process) { continue; }
     34        if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE(FPCAMERA_ERR_DATA, "failed to load header at Chip level");
     35    }
     36    psLogMsg ("psastro", 3, "load headers : %f sec\n", psTimerMark ("psastro"));
     37
     38    // reset to loop over all chips:
     39    pmFPAviewReset (view);
    2340
    2441    // check PHU header to see if we are using mosaic-level or per-chip astrometry
     
    3350    }
    3451
    35     pmChip *chip;
     52    // we need the min/max RA & DEC for each of the chips and for the entire FOV
     53    double rMinFPA = +FLT_MAX;
     54    double rMaxFPA = -FLT_MAX;
     55    double dMinFPA = +FLT_MAX;
     56    double dMaxFPA = -FLT_MAX;
     57
    3658    while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
    3759        psTrace ("fpcamera", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
     
    5577            }
    5678        }
     79
     80        // we need the min/max RA & DEC for each of the chips and for the entire FOV
     81        double rMinChip = +FLT_MAX;
     82        double rMaxChip = -FLT_MAX;
     83        double dMinChip = +FLT_MAX;
     84        double dMaxChip = -FLT_MAX;
     85       
     86        // this region defines the data area of the chip
     87        psRegion *region = pmChipPixels (chip);
     88        psPlane ptCH[4];
     89       
     90        // save the 4 corners
     91        ptCH[0].x = region->x0; ptCH[0].y = region->y0;
     92        ptCH[1].x = region->x1; ptCH[1].y = region->y0;
     93        ptCH[2].x = region->x1; ptCH[2].y = region->y1;
     94        ptCH[3].x = region->x0; ptCH[3].y = region->y1;
     95        psFree (region);
     96       
     97        // report and save the current best guess for the chip 0,0 pixel coordinates
     98        for (int i = 0; i < 4; i++) {
     99            psPlane ptFP, ptTP;
     100            psSphere ptSky;
     101
     102            // 4 corners
     103            psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH[i]);
     104            psPlaneTransformApply (&ptTP, input->fpa->toTPA, &ptFP);
     105            psDeproject (&ptSky, &ptTP, input->fpa->toSky);
     106            rMinChip = PS_MIN(rMinChip, DEG_RAD*ptSky.r);
     107            rMaxChip = PS_MAX(rMaxChip, DEG_RAD*ptSky.r);
     108            dMinChip = PS_MIN(dMinChip, DEG_RAD*ptSky.d);
     109            dMaxChip = PS_MAX(dMaxChip, DEG_RAD*ptSky.d);
     110        }
     111        psMetadataAddF32 (chip->analysis, PS_LIST_TAIL, "RA_MIN",  PS_META_REPLACE, "", rMinChip);
     112        psMetadataAddF32 (chip->analysis, PS_LIST_TAIL, "RA_MAX",  PS_META_REPLACE, "", rMaxChip);
     113        psMetadataAddF32 (chip->analysis, PS_LIST_TAIL, "DEC_MIN", PS_META_REPLACE, "", dMinChip);
     114        psMetadataAddF32 (chip->analysis, PS_LIST_TAIL, "DEC_MAX", PS_META_REPLACE, "", dMaxChip);
     115        psLogMsg ("fpcamera", 3, "chip %3d = (%f,%f) - (%f,%f)\n", view->chip, rMinChip, dMinChip, rMaxChip, dMaxChip);
     116
     117        rMinFPA = PS_MIN(rMinFPA, rMinChip);
     118        rMaxFPA = PS_MAX(rMaxFPA, rMaxChip);
     119        dMinFPA = PS_MIN(dMinFPA, dMinChip);
     120        dMaxFPA = PS_MAX(dMaxFPA, dMaxChip);
    57121    }
     122    psMetadataAddF32 (input->fpa->analysis, PS_LIST_TAIL, "RA_MIN",  PS_META_REPLACE, "", rMinFPA);
     123    psMetadataAddF32 (input->fpa->analysis, PS_LIST_TAIL, "RA_MAX",  PS_META_REPLACE, "", rMaxFPA);
     124    psMetadataAddF32 (input->fpa->analysis, PS_LIST_TAIL, "DEC_MIN", PS_META_REPLACE, "", dMinFPA);
     125    psMetadataAddF32 (input->fpa->analysis, PS_LIST_TAIL, "DEC_MAX", PS_META_REPLACE, "", dMaxFPA);
     126
     127    psLogMsg ("fpcamera", 3, "FPA FOV = (%f,%f) - (%f,%f)\n", rMinFPA, dMinFPA, rMaxFPA, dMaxFPA);
    58128    psLogMsg ("fpcamera", 3, "convert wcs terms to internal format : %f sec\n", psTimerMark ("fpcamera"));
    59129
Note: See TracChangeset for help on using the changeset viewer.