IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 21, 2005, 5:33:37 PM (20 years ago)
Author:
eugene
Message:

reorg

File:
1 edited

Legend:

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

    r5560 r5565  
    11# include "psastro.h"
    22# define RENORM 0
    3 
    4 bool testWriteRaw (char *filename, psArray *sources);
    5 
    6 void psastroDumpStars (psArray *sources) {
    7 
    8     for (int i = 0; i < sources->n; i++) {
    9         pmAstromObj *star = sources->data[i];
    10 
    11         fprintf (stderr, "%8.2f %8.2f   %8.2f %8.2f   %8.2f %8.2f   %8.2f %8.2f   %8.2f %8.2f   %10.6f %10.6f   %8.2f %8.2f\n",
    12                  star->pix.x, star->pix.y,
    13                  star->cell.x, star->cell.y,
    14                  star->chip.x, star->chip.y,
    15                  star->FP.x, star->FP.y,
    16                  star->TP.x, star->TP.y,
    17                  star->sky.r*DEG_RAD, star->sky.d*DEG_RAD,
    18                  star->Mag, star->dMag);
    19     }
    20 }
    21 
    22 // sort by mag (descending)
    23 int pmAstromObjSortByMag (const void **a, const void **b)
    24 {
    25     pmAstromObj *A = *(pmAstromObj **)a;
    26     pmAstromObj *B = *(pmAstromObj **)b;
    27 
    28     psF32 diff = A->Mag - B->Mag;
    29     if (diff > FLT_EPSILON) return (-1);
    30     if (diff < FLT_EPSILON) return (+1);
    31     return (0);
    32 }
    333
    344bool psastroSelectBrightStars (pmFPA *fpa, psMetadata *config) {
     
    6232}
    6333
    64 pmFPA *pmFPACopyAstrom (pmFPA *inFPA) {
    65 
    66     pmFPA *fpa = pmFPAAlloc (NULL, NULL);
    67 
    68     // copy FPA astrometry data
    69     fpa->toSky   = psProjectionCopy (inFPA->toSky);
    70     fpa->toTPA   = psPlaneDistortCopy (inFPA->toTPA);
    71     fpa->fromTPA = psPlaneDistortCopy (inFPA->fromTPA);
    72 
    73     psArrayRealloc (fpa->chips, inFPA->chips->n);
    74     for (int i = 0; i < inFPA->chips->n; i++) {
    75         pmChip *inChip = inFPA->chips->data[i];
    76         pmChip *chip = pmChipAlloc (fpa);
    77 
    78         // copy Chip astrometry data
    79         chip->toFPA = psPlaneTransformCopy (inChip->toFPA);
    80         chip->fromFPA = psPlaneTransformCopy (inChip->fromFPA);
    81 
    82         psArrayRealloc (chip->cells, inChip->cells->n);
    83         for (int j = 0; j < inChip->cells->n; j++) {
    84             pmCell *inCell = inChip->cells->data[j];
    85             pmCell *cell = pmCellAlloc (chip);
    86 
    87             // cell.header is a view on inCell.header
    88             cell->header = psMemCopy (inCell->header);
    89 
    90             // copy Cell astrometry data
    91             cell->toChip = psPlaneTransformCopy (inCell->toChip);
    92 
    93             psArrayRealloc (cell->readouts, inCell->readouts->n);
    94             for (int k = 0; k < inCell->readouts->n; k++) {
    95                 pmReadout *inReadout = inCell->readouts->data[k];
    96                 pmReadout *readout = pmReadoutAlloc (cell);
    97 
    98                 // copy Readout data
    99                 *readout = *inReadout;
    100 
    101                 cell->readouts->data[k] = readout;
    102             }
    103             chip->cells->data[j] = cell;
    104         }
    105         fpa->chips->data[i] = chip;
    106     }
    107     return (fpa);
    108 }
    109 
    11034// measure per-chip astrometry terms
    11135bool psastroChipAstrom (pmFPA *fpa, psMetadata *config) {
     
    15377                psastroProjectRefstars (refstars, readout);
    15478
    155                 testWriteRaw ("ref.inp", refstars);
    156                 testWriteRaw ("raw.inp", rawstars);
     79                // testWriteRaw ("ref.inp", refstars);
     80                // testWriteRaw ("raw.inp", rawstars);
    15781
    15882                // fprintf (stderr, "rawstars:\n");
     
    17296                psastroProjectRefstars (refstars, readout);
    17397
    174                 testWriteRaw ("ref.dat", refstars);
    175                 testWriteRaw ("raw.dat", rawstars);
     98                // testWriteRaw ("ref.dat", refstars);
     99                // testWriteRaw ("raw.dat", rawstars);
    176100   
    177101                // use small radius to match stars
     
    284208    return true;
    285209}
    286 
    287 // returns the rotation term, forcing positive parity
    288 double psPlaneTransformGetRotation (psPlaneTransform *map) {
    289 
    290     if (map->x->nX < 1) return 0;
    291     if (map->x->nY < 1) return 0;
    292 
    293     if (map->y->nX < 1) return 0;
    294     if (map->y->nY < 1) return 0;
    295    
    296     double pc1_1 = map->x->coeff[1][0];
    297     double pc1_2 = map->x->coeff[0][1];
    298     double pc2_1 = map->y->coeff[1][0];
    299     double pc2_2 = map->y->coeff[0][1];
    300 
    301     double px = SIGN (pc1_1);
    302     double py = SIGN (pc2_2);
    303 
    304     // both x and y terms imply an angle. take the average
    305     double t1 = -atan2 (px*pc1_2, px*pc1_1);
    306     double t2 = +atan2 (py*pc2_1, py*pc2_2);
    307    
    308     // careful near -pi,+pi boundary...
    309     if (t1 - t2 > M_PI/2) t2 += 2*M_PI;
    310     if (t2 - t1 > M_PI/2) t1 += 2*M_PI;
    311 
    312     double theta = 0.5*(t1 + t2);
    313     while (theta < M_PI) theta += 2*M_PI;
    314     while (theta > M_PI) theta -= 2*M_PI;
    315    
    316     return (theta);
    317 }
    318 
    319 // elixir-style pseudo FITS table (header + ascii list)
    320 bool testWriteRaw (char *filename, psArray *sources) {
    321 
    322     int i;
    323 
    324     // re-open, add data to end of file
    325     FILE *f = fopen (filename, "w");
    326     if (f == NULL) {
    327         psLogMsg ("WriteSourceOBJ", 3, "can't open output file for output %s\n", filename);
    328         return false;
    329     }
    330 
    331     for (i = 0; i < sources->n; i++) {
    332        
    333         pmAstromObj *star = sources->data[i];
    334 
    335         fprintf (f, "%8.2f %8.2f   %8.2f %8.2f   %8.2f %8.2f   %8.2f %8.2f   %8.2f %8.2f   %10.6f %10.6f   %8.2f %8.2f\n",
    336                  star->pix.x, star->pix.y,
    337                  star->cell.x, star->cell.y,
    338                  star->chip.x, star->chip.y,
    339                  star->FP.x, star->FP.y,
    340                  star->TP.x, star->TP.y,
    341                  star->sky.r*DEG_RAD, star->sky.d*DEG_RAD,
    342                  star->Mag, star->dMag);
    343     }
    344     fclose (f);
    345     return true;
    346 }
Note: See TracChangeset for help on using the changeset viewer.