IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 30, 2006, 12:15:03 PM (20 years ago)
Author:
eugene
Message:

first complete working version (chip only)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psastro/src/psastroChipAstrom.c

    r6176 r7014  
    11# include "psastro.h"
    22
    3 // measure per-chip astrometry terms
    4 // this function requires a chip from a well-formed pmFPA
    5 // with PSASTRO.OBJECTS on the readouts
    6 bool psastroChipAstrom (pmChip *chip, psMetadata *config) {
     3bool psastroChipAstrom (pmConfig *config, psArray *refs) {
    74
    85    bool status;
    9     psArray *match;
    10     pmAstromStats stats;
     6    pmChip *chip = NULL;
     7    pmCell *cell = NULL;
     8    pmReadout *readout = NULL;
    119
    12     // cells->n > 1 is not well-defined
    13     if (chip->cells->n > 1) {
    14         psLogMsg ("pmSourcesReadCMP", 3, "undefined behavior for nCells > 1");
    15         return false;
     10    // select the current recipe
     11    psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, "PSASTRO");
     12    if (!recipe) {
     13        psErrorStackPrint(stderr, "Can't find PSASTRO recipe!\n");
     14        exit(EXIT_FAILURE);
    1615    }
    17     pmCell *cell = chip->cells->data[0];
    1816
    19     // readouts->n > 1 is not well-defined
    20     if (cell->readouts->n > 1) {
    21         psLogMsg ("pmSourcesReadCMP", 3, "undefined behavior for nReadouts > 1");
    22         return false;
     17    // select the input data sources
     18    pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT");
     19    if (!input) {
     20        psErrorStackPrint(stderr, "Can't find input data!\n");
     21        exit(EXIT_FAILURE);
    2322    }
    24     pmReadout *readout = cell->readouts->data[0];
    25     psMetadata *header = pmReadoutGetHeader (readout);
    2623
    27     // load the corresponding reference data (DVO command)
    28     // XXX EAM : this needs to be improved, perhaps moved to a higher level
    29     psArray *refstars = psastroLoadReference (header, config);
     24    double plateScale = psMetadataLookupF32 (&status, recipe, "PSASTRO.PLATE.SCALE");
     25    if (!status) plateScale = 1.0;
    3026
    31     // we require PASTRO.OBJECTS (pmAstromObj) on the analysis for this readout
    32     psArray *rawstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.OBJECTS");
     27    pmFPAview *view = pmFPAviewAlloc (0);
     28    pmFPA *fpa = input->fpa;
    3329
    34     // project the rawstars to the current best guess astrometry
    35     psastroProjectRawstars (rawstars, readout);
     30    while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) {
     31        psTrace (__func__, 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
     32        if (!chip->process || !chip->file_exists) { continue; }
     33       
     34        while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
     35            psTrace (__func__, 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
     36            if (!cell->process || !cell->file_exists) { continue; }
    3637
    37     // use the header & config info to project refstars onto the focal plane
    38     psastroProjectRefstars (refstars, readout);
     38            // process each of the readouts
     39            while ((readout = pmFPAviewNextReadout (view, fpa, 1)) != NULL) {
     40                if (! readout->data_exists) { continue; }
    3941
    40     // testWriteRaw ("ref.inp", refstars);
    41     // testWriteRaw ("raw.inp", rawstars);
     42                // select the raw objects for this readout
     43                psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.OBJECTS");
     44                if (rawstars == NULL) { continue; }
    4245
    43     // fprintf (stderr, "rawstars:\n");
    44     // psastroDumpStars (rawstars);
    45     // fprintf (stderr, "refstars:\n");
    46     // psastroDumpStars (refstars);
     46                // the refstars is a subset within range of this chip
     47                psArray *refstars = psArrayAlloc (100);
    4748
    48     // find initial offset / rotation
    49     stats = pmAstromGridMatch (rawstars, refstars, config);
     49                // select the reference objects within range of this readout
     50                // project the reference objects to this chip
     51                for (int i = 0; i < refs->n; i++) {
     52                    pmAstromObj *ref = refs->data[i];
     53       
     54                    p_psProject (ref->TP, ref->sky, fpa->projection);
     55                    psPlaneDistortApply (ref->FP, fpa->fromTangentPlane, ref->TP, 0.0, 0.0);
     56                    psPlaneTransformApply (ref->chip, chip->fromFPA, ref->FP);
    5057
    51     // adjust the chip.toFPA terms only
    52     pmAstromGridApply (chip->toFPA, stats);
    53     chip->fromFPA = p_psPlaneTransformLinearInvert (chip->toFPA);
     58                    // XXX what is the X,Y range of the selected chip?
     59                    // XXX for the moment, force these to be good for Megacam
     60                    if (ref->chip->x < -500) continue;
     61                    if (ref->chip->x > 2500) continue;
     62                    if (ref->chip->y < -500) continue;
     63                    if (ref->chip->y > 5000) continue;
     64                   
     65                    psArrayAdd (refstars, 100, ref);
     66                }
     67                psastroOneChip (fpa, chip, refstars, rawstars, recipe);
     68                psFree (refstars);
    5469
    55     // use fit result to re-project rawstars
    56     psastroProjectRawstars (rawstars, readout);
    57     psastroProjectRefstars (refstars, readout);
    58 
    59     // testWriteRaw ("ref.dat", refstars);
    60     // testWriteRaw ("raw.dat", rawstars);
    61    
    62     // use small radius to match stars
    63     match = pmAstromRadiusMatch (rawstars, refstars, config);
    64 
    65     // improved fit for astrometric terms
    66     pmAstromMatchFit (chip->toFPA, rawstars, refstars, match, config);
    67     chip->fromFPA = p_psPlaneTransformLinearInvert (chip->toFPA);
    68 
    69     // per-chip astrometry has been updated
    70     pmAstromWriteWCS (chip->toFPA, fpa->toSky, header);
    71 
     70                // read WCS data from the corresponding header
     71                pmHDU *hdu = pmFPAviewThisHDU (view, fpa);
     72                pmAstromWriteWCS (chip->toFPA, fpa->toSky, hdu->header, plateScale);
     73            }
     74        }
     75    }
     76    psFree (view);
    7277    return true;
    7378}
     79
     80/* coordinate frame hierachy
     81   pixels (on a given readout)
     82   cell
     83   chip
     84   FP (focal plane)
     85   TP (tangent plane)
     86   sky (ra, dec)
     87*/
Note: See TracChangeset for help on using the changeset viewer.