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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.