IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23220


Ignore:
Timestamp:
Mar 8, 2009, 2:54:56 PM (17 years ago)
Author:
eugene
Message:

finally got the ring cell sized essentially right based on Tamas description

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/eam_branch_20090303/Ohana/src/addstar/src/sky_tessalation.c

    r23138 r23220  
    240240  // integer number of dec zones between -90 and +90
    241241
    242   nDEC = 180.0 / CELLSIZE;
    243   dDEC = 180.0 / nDEC;
     242  // in fact, we place a single image on each pole, so the real range of dec is 180.0 - CELLSIZE:
     243
     244  nDEC = (180.0 - CELLSIZE) / CELLSIZE;
     245  dDEC = (180.0 - CELLSIZE) / nDEC;
     246  nDEC += 2;
     247
     248  // a test
     249  // for (dec = 0.0 + 0.5*dDEC; dec < +90.0; dec += dDEC) {
    244250
    245251  // generate the a collection of rectangles for each ring
    246   for (dec = -90.0 + 0.5*dDEC; dec < +90.0; dec += dDEC) {
     252  for (dec = -90.0; dec < +90.0 + 0.5*dDEC; dec += dDEC) {
    247253
    248254    ring = sky_rectangle_ring (dec, dDEC, &Nring);
     255    if (!ring) continue;
    249256
    250257    // subdivide each image (Nx x Ny subcells)
     
    529536SkyRectangle *sky_rectangle_ring (float dec, float dDEC, int *nring) {
    530537
    531   int i, nRA, NX, NY;
    532   float dRA, decLower;
     538  int i, NX, NY, nRA;
    533539  SkyRectangle *ring;
     540  float theta, dRA;
    534541
    535542  // 'dec' is a guess at the center of the cell; in fact, we need to choose decLower and
     
    537544
    538545  // we can determine the 'lower' bound (bound closest to the equator):
    539   decLower = (dec > 0.0) ? dec - 0.5*dDEC : dec + 0.5*dDEC;
    540 
    541   // Subdivide the 'lower' bound into an integer number of segments:
    542   nRA = cos(dec*RAD_DEG) * 360.0 / CELLSIZE; // CELLSIZE is a projection size
    543   dRA = 360.0 / nRA;                         // dRA is a size in RA degrees
     546  float decLower = (dec > 0.0) ? dec - 0.5*dDEC : dec + 0.5*dDEC;
     547
     548  // solve for actual cellsize (\theta):  tan(\delta_{n+1} - \theta/2) = tan(\delta_n + \theta/2)cos(\alpha_n / 2)
     549  float decUpper = (dec > 0.0) ? dec + dDEC : dec - dDEC;
     550
     551  if (fabs(dec) + 0.5*dDEC > 90.0) {
     552    // onPole = TRUE;
     553    theta = dDEC;
     554    nRA = 1;
     555    dRA = theta / cos(decLower*RAD_DEG); // make a square at the pole
     556  } else {
     557    // onPole = FALSE;
     558    // Subdivide the 'lower' bound into an integer number of segments:
     559    nRA = cos(RAD_DEG*decLower) * 360.0 / CELLSIZE; // CELLSIZE is a projection size
     560    dRA = 360.0 / nRA;                         // dRA is a size in RA degrees == \alpha_n
     561
     562    // tan(decUpper - theta/2) = tan(dec + theta/2) cos(dRA / 2);
     563
     564    // we solve this equation for theta (fairly ugly: expand the tangents into sin/cos, expand the
     565    // sum-of-angle sine and cosine, multiply through, convert via half-angle formulae and write
     566    // as a quadratic expression in sine(theta/2)
     567 
     568    float sd1 = sin(RAD_DEG*decUpper);
     569    float cd1 = cos(RAD_DEG*decUpper);
     570    float sd2 = sin(RAD_DEG*dec);
     571    float cd2 = cos(RAD_DEG*dec);
     572    float   k = cos(RAD_DEG*dRA/2.0);
     573
     574    float c1 =  (sd1*cd2 + sd2*cd1)*(1.0 - k);
     575    float c2 =  (sd1*cd2 - sd2*cd1)*(1.0 + k);
     576    float c3 = -(sd1*sd2 + cd1*cd2)*(1.0 + k);
     577
     578    float A = SQ(c3) + SQ(c2);
     579    float B = 2*c1*c3;
     580    float C = SQ(c1) - SQ(c2);
     581
     582    float arg = SQ(B) - 4.0*A*C;
     583
     584    float root;
     585
     586    if (dec >= 0.0) {
     587      root = (-B + sqrt (arg)) / (2.0*A);
     588      theta = +DEG_RAD*asin(root);
     589    } else {
     590      root = (-B - sqrt (arg)) / (2.0*A);
     591      theta = -DEG_RAD*asin(root);
     592    }
     593
     594    // the negative solution yields a negative cellsize
     595    // float root2 = (-B - sqrt (arg)) / (2.0*A);
     596    // float theta2 = DEG_RAD*asin(root2);
     597
     598    // test lines:
     599    // float r1 = tan(RAD_DEG*(decUpper - 0.5*theta1));
     600    // float r2 = tan(RAD_DEG*(dec + 0.5*theta1));
     601    // fprintf (stdout, "%f %f  %f  %f  %f %f  %f %f  %f %f %f\n", dec, decUpper, dRA, arg, root1, root2, theta1, theta2, r1, r2, k*r2);
     602  }
     603  fprintf (stdout, "%f %f  %f x %f (%d)\n", dec, decUpper, dRA, theta, nRA);
    544604
    545605  // I think we need to return the value of dec for the next ring, but I am not sure...
     
    559619 
    560620    // range values are in projected degrees
    561     NX = cos(dec*RAD_DEG) * dRA  * 3600.0 / SCALE;
    562     NY =                    dDEC * 3600.0 / SCALE;
     621    NX = cos(decLower*RAD_DEG) * dRA   * 3600.0 / SCALE;
     622    NY =                         theta * 3600.0 / SCALE;
    563623
    564624    // crpix1,crpix2 is the projection center
     
    576636
    577637
    578     fprintf (stderr, "%f %f  : %f %f\n",
    579             ring[i].coords.crval1, ring[i].coords.crval2,
    580             ring[i].coords.crpix1, ring[i].coords.crpix2);
     638    // fprintf (stderr, "%f %f  : %f %f\n",
     639    // ring[i].coords.crval1, ring[i].coords.crval2,
     640    // ring[i].coords.crpix1, ring[i].coords.crpix2);
    581641  }
    582642
Note: See TracChangeset for help on using the changeset viewer.