IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 37562


Ignore:
Timestamp:
Nov 6, 2014, 8:17:04 PM (12 years ago)
Author:
eugene
Message:

add frame correction

Location:
branches/eam_branches/ipp-20140904/Ohana/src/relastro
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20140904/Ohana/src/relastro/include/relastro.h

    r37545 r37562  
    575575FrameCorrectionType *FrameCorrectionInit (double scale);
    576576void FrameCorrectionFree (FrameCorrectionType *frame);
     577
    577578int FrameCorrection (Catalog *catalog, int Ncatalog);
    578 int FrameCorrectionFit (Catalog *catalog, int Ncatalog, SHterms *dR, SHterms *dD);
     579int FrameCorrectionFitSH (Catalog *catalog, int Ncatalog, SHterms *dR, SHterms *dD);
    579580int FrameCorrectionFromSH (FrameCorrectionType *frame, SHterms *dR, SHterms *dD);
     581
     582int FrameCorrectionFitLocal (Catalog *catalog, int Ncatalog, AstromOffsetMap *map, Coords *coords);
     583int FrameCorrectionApply (Catalog *catalog, int Ncatalog, FrameCorrectionType *frame, AstromOffsetMap *map, Coords *coords, int POLE);
  • branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/FrameCorrection.c

    r37545 r37562  
    7575  // go from ICRF object to the catalog entry. 
    7676
    77   // Lmax in recipe
    78   int Lmax = 20;
    79 
    80   // dR and dD will carry the fit coefficients in RA and DEC
    81   SHterms *dRc = SHtermsInit (Lmax);
    82   SHterms *dDc = SHtermsInit (Lmax);
    83 
    84   FrameCorrectionFit (catalog, Ncatalog, dRc, dDc);
    85 
    86   double pltscale = 0.5; // degrees per pixel
    87   FrameCorrectionType *frame = FrameCorrectionInit (pltscale);
     77  // we can have 2 kinds of corrections:
     78  // 'frame' is a map in spherical coords of the corrections based on spherical harmonics
     79  // 'map' is a correction based on a local projection to a linear coordinate system.  I
     80  // am going to use this for the pole, but also for SAS for testing.
     81  // We need to be sure only one of the two is applied. For the pole, the boundary is a
     82  // fixed line of DEC; for the SAS, the boundary is the projection 'image'
     83
     84  Coords coords;
     85  AstromOffsetMap *map = NULL;
     86  FrameCorrectionType *frame = NULL;
     87
     88# define LOCAL_FRAME 1
     89# define SH_FRAME 0
     90
     91  int POLE = FALSE;
     92
     93  if (LOCAL_FRAME) {
     94    // for the local frame correction, we are going to convert R,D into
     95    // X,Y linear coordinates in an 'image' centered on the field center.
     96    // we can then use an AstromOffsetMap structure to carry the correction values
     97
     98    // what parameters define a local frame correction?
     99    // * Ro, Do -- map/projection center
     100    // * scale  -- degrees / pixel
     101    // * Nx, Ny -- size of map in pixels
     102    // * Rmin,Rmax,Dmin,Dmax
     103
     104    // example parameters for SAS: 320 - 340, -10 - +10
     105    double Ro = 330.0;
     106    double Do =   0.0;
     107
     108    // double Ro =  0.0;
     109    // double Do = 90.0;
     110    // POLE = TRUE;
     111
     112    double scale = 2.0; // degrees per patch
     113    int Nx = 10;
     114    int Ny = 10;
     115   
     116    map = AstromOffsetMapInit (Nx, Ny);
     117    map->dX = 1.0; // scale from projection (in arcsec) to correction patches
     118    map->dY = 1.0;
     119 
     120    InitCoords (&coords, "DEC--SIN");
     121    coords.cdelt1 = coords.cdelt2 = scale;
     122    coords.crval1 = Ro; // SAS center
     123    coords.crval2 = Do;
     124    coords.crpix1 = 0.5*Nx; // middle of projection is middle of map
     125    coords.crpix2 = 0.5*Ny; // middle of projection is middle of map
     126
     127    FrameCorrectionFitLocal (catalog, Ncatalog, map, &coords);
     128  }
     129
     130  if (SH_FRAME) {
     131    // Lmax in recipe
     132    int Lmax = 20;
     133
     134    // dR and dD will carry the fit coefficients in RA and DEC
     135    SHterms *dRc = SHtermsInit (Lmax);
     136    SHterms *dDc = SHtermsInit (Lmax);
     137
     138    FrameCorrectionFitSH (catalog, Ncatalog, dRc, dDc);
     139
     140    double pltscale = 0.5; // degrees per pixel
     141    frame = FrameCorrectionInit (pltscale);
    88142 
    89   FrameCorrectionFromSH (frame, dRc, dDc);
    90 
    91   // XXX write out an image to represent the correction
     143    FrameCorrectionFromSH (frame, dRc, dDc);
     144
     145    // XXX write out an image to represent the correction
     146
     147    SHtermsFree (dRc);
     148    SHtermsFree (dDc);
     149  }
    92150
    93151  // Now apply the correction to all of the average.R,D values
    94 
    95   int i, j;
    96   for (i = 0; i < Ncatalog; i++) {
    97     for (j = 0; j < catalog[i].Naverage; j++) {
    98      
    99       double R = catalog[i].average[j].R;
    100       double D = catalog[i].average[j].D;
    101 
    102       // special handling for the polar regions...
    103 
    104       int iD = (D + 89.0) / frame->scale;
    105       int iR = R / frame->dR[iD];
    106 
    107       double dR = frame->Roff[iD][iR];
    108       double dD = frame->Doff[iD][iR];
    109 
    110       catalog[i].average[j].R -= dR;
    111       catalog[i].average[j].D -= dD;
    112     }
    113   }
     152  FrameCorrectionApply (catalog, Ncatalog, frame, map, &coords, POLE);
     153
    114154  FrameCorrectionFree(frame);
    115   return TRUE;
    116 }
    117 
    118 
    119 int FrameCorrectionFit (Catalog *catalog, int Ncatalog, SHterms *dRc, SHterms *dDc) {
     155  AstromOffsetMapFree (map);
     156
     157  return TRUE;
     158}
     159
     160int FrameCorrectionFitSH (Catalog *catalog, int Ncatalog, SHterms *dRc, SHterms *dDc) {
    120161
    121162  myAssert (dRc->lmax == dDc->lmax, "dR and dD must match\n");
     
    196237  return TRUE;
    197238}
     239
     240int FrameCorrectionFitLocal (Catalog *catalog, int Ncatalog, AstromOffsetMap *map, Coords *coords) {
     241
     242  double Xave, Yave, Xmeas, Ymeas;
     243  float *X, *Y, *dX, *dY;
     244
     245  int Npts = 0;
     246  int NPTS = 100;
     247
     248  ALLOCATE (X, float, NPTS);
     249  ALLOCATE (Y, float, NPTS);
     250  ALLOCATE (dX, float, NPTS);
     251  ALLOCATE (dY, float, NPTS);
     252
     253  int Nicrf = ICRFmax();
     254
     255  int i;
     256  for (i = 0; i < Nicrf; i++) {
     257
     258    int cat, meas, ave;
     259    ICRFdata (i, &cat, &meas, &ave);
     260
     261    Average *average = &catalog[cat].average[ave];
     262    Measure *measure = &catalog[cat].measure[meas]; // MeasureTiny?
     263
     264    // this local correction is defined for (Rmin < R < Rmax, Dmin < D < Dmax)
     265    int status = RD_to_XY (&Xave, &Yave, average->R, average->D, coords);
     266    if (!status) continue;
     267    if (Xave < 0.0) continue;
     268    if (Xave > map->Nx) continue;
     269    if (Yave < 0.0) continue;
     270    if (Yave > map->Ny) continue;
     271
     272    RD_to_XY (&Xmeas, &Ymeas, measure->R, measure->D, coords);
     273
     274    // record these in arcsec or degree?
     275    // correct for cos(D) or not?
     276    X[Npts] = Xave;
     277    Y[Npts] = Yave;
     278    dX[Npts] = Xave - Xmeas;
     279    dY[Npts] = Yave - Ymeas;
     280    Npts ++;
     281    if (Npts == NPTS) {
     282      NPTS += 100;
     283      REALLOCATE (X, float, NPTS);
     284      REALLOCATE (Y, float, NPTS);
     285      REALLOCATE (dX, float, NPTS);
     286      REALLOCATE (dY, float, NPTS);
     287    }
     288  }   
     289
     290  AstromOffsetMapFit (map, X, Y, dX, Npts, TRUE);
     291  AstromOffsetMapFit (map, X, Y, dY, Npts, FALSE);
     292
     293  return TRUE;
     294}
     295
     296int FrameCorrectionApply (Catalog *catalog, int Ncatalog, FrameCorrectionType *frame, AstromOffsetMap *map, Coords *coords, int POLE) {
     297
     298  double Xave, Yave;
     299
     300  int i, j;
     301  for (i = 0; i < Ncatalog; i++) {
     302    for (j = 0; j < catalog[i].Naverage; j++) {
     303     
     304      Average *average = &catalog[i].average[j];
     305
     306      double R = average->R;
     307      double D = average->D;
     308
     309      myAssert (coords, "no local frame coords defined");
     310
     311      // this local correction is defined for (Rmin < R < Rmax, Dmin < D < Dmax)
     312      int useLocal = RD_to_XY (&Xave, &Yave, average->R, average->D, coords);
     313      if (POLE) {
     314        useLocal = (average->D > 85.0);
     315      } else {
     316        useLocal = (useLocal && (Xave > 0.0));
     317        useLocal = (useLocal && (Xave < map->Nx));
     318        useLocal = (useLocal && (Yave > 0.0));
     319        useLocal = (useLocal && (Yave < map->Ny));
     320      }
     321
     322      if (useLocal) {
     323        myAssert (map, "no local frame map defined");
     324        double dX = AstromOffsetMapValue (map, Xave, Yave, TRUE);
     325        double dY = AstromOffsetMapValue (map, Xave, Yave, FALSE);
     326        double Xmeas = Xave - dX;
     327        double Ymeas = Yave - dY;
     328        XY_to_RD (&average->R, &average->D, Xmeas, Ymeas, coords);
     329      } else {
     330        myAssert (frame, "no frame correction defined");
     331
     332        int iD = (D + 89.0) / frame->scale;
     333        int iR = R / frame->dR[iD];
     334
     335        double dR = frame->Roff[iD][iR];
     336        double dD = frame->Doff[iD][iR];
     337        average->R -= dR;
     338        average->D -= dD;
     339      }
     340    }
     341  }
     342  return TRUE;
     343}
     344
  • branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/UpdateChips.c

    r37545 r37562  
    322322    }
    323323
     324    // apply the modified R,D back to the measures
     325    setImageRaw (threadinfo->catalog, threadinfo->Ncatalog, i, raw, Nraw, MODE_MOSAIC);
     326
    324327    saveCenter (image, &threadinfo->Ro[i], &threadinfo->Do[i], i);
    325328    threadinfo->mode[i] = 3;
Note: See TracChangeset for help on using the changeset viewer.