IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 3, 2015, 5:05:24 PM (11 years ago)
Author:
eugene
Message:

merge common code between fitplx and fitplx_irls; move ESCAPE to shell.h

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.astro/fitplx.c

    r38986 r39227  
    11# include "astro.h"
    2 # define J2000 51544.5       /* Modified Julian date at standard epoch J2000 */
    3 
    4 # define ESCAPE(MSG,...) {                      \
    5     gprint (GP_ERR, MSG, __VA_ARGS__);          \
    6     return FALSE; }
    7 
    8 typedef struct {
    9   double *X;
    10   double *Y;
    11   double *t;
    12   double *pX;
    13   double *pY;
    14   double *dX;
    15   double *dY;
    16   int *index;
    17   int Npts;
    18 } PlxFitData;
    19 
    20 typedef struct {
    21   double Ro, dRo;
    22   double Do, dDo;
    23 
    24   double uR, duR;
    25   double uD, duD;
    26 
    27   double p, dp;
    28 
    29   double chisq;
    30   int Nfit;
    31   int getChisq;
    32 } PlxFit;
    33 
    34 int VectorRobustStats (Vector *vector, double *median, double *sigma);
    35 double VectorFractionInterpolate (double *values, float fraction, int Npts);
    36 
    37 int PlxSetMeanEpoch (double *R, double *D, double *T, double *Rmean, double *Dmean, double *Tmean, int *mask, int Ntotal);
    38 int PlxSetEpochPosition (PlxFitData *fitdata, double *R, double *D, double *dR, double *dD, double *T, int *mask, int Ntotal, Coords *coords, double Tmean);
    39 int PlxOutlierClip (PlxFitData *fitdata, int *mask, int Noutlier, float dPsigMax, Vector *dPvec, int VERBOSE);
    40 
    41 int PlxFitDataAlloc (PlxFitData *data, int N);
    42 void PlxFitDataFree (PlxFitData *data);
    43 int PlxBootstrapResample (PlxFitData *src, PlxFitData *tgt);
    44 
    45 int FitPMandPar (PlxFit *fit, double *X, double *dX, double *Y, double *dY, double *T, double *pR, double *pD, int Npts, int VERBOSE);
    46 int sun_ecliptic (double mjd, double *lambda, double *beta, double *epsilon, double *Radius);
    47 int ParFactor (double *pR, double *pD, double RA, double DEC, double Time);
    482
    493int fitplx (int argc, char **argv) {
     
    401355  fit[0].Nfit = Npts;
    402356  return (TRUE);
    403 }
    404 
    405 /* Low precision formulae for the sun, from Astro. Almanac p. C5 (2012) */
    406 int sun_ecliptic (double mjd, double *lambda, double *beta, double *epsilon, double *Radius) {
    407 
    408   double n = mjd - J2000;                          // day number relative to standard epoch
    409   double L = 280.460 + 0.9856474 * n;              // mean solar longitute (corr. for aberration)
    410   double g = (357.528 + 0.9856003 * n)*RAD_DEG;    // Mean anomaly
    411 
    412   *lambda = L + 1.915 * sin(g) + 0.020 * sin(2*g); // solar longitude in degrees
    413   *beta = 0.0;                                     // approx latitude
    414   *epsilon = (23.439 - 0.0000004 * n);             // obliquity of ecliptic in degrees
    415   *Radius = 1.00014 - 0.01671*cos(g) - 0.00014*cos(2*g); // earth-to-sun dist in AU
    416   return TRUE;
    417 }
    418 
    419 /* given RA, DEC, Time, calculate the parallax factor */
    420 // RA,DEC are decimal degrees
    421 // Time is MJD
    422 int ParFactor (double *pR, double *pD, double RA, double DEC, double Time) {
    423 
    424   double lambda, beta, epsilon, Radius;
    425 
    426   // Time must be mjd
    427   sun_ecliptic (Time, &lambda, &beta, &epsilon, &Radius);
    428 
    429   double lambda_rad = lambda*RAD_DEG;
    430   double epsilon_rad = epsilon*RAD_DEG;
    431   double RA_rad = RA*RAD_DEG;
    432   double DEC_rad = DEC*RAD_DEG;
    433 
    434   double x = Radius*cos(lambda_rad);
    435   double y = Radius*cos(epsilon_rad)*sin(lambda_rad);
    436   double z = Radius*sin(epsilon_rad)*sin(lambda_rad);
    437 
    438   *pR = +(y*cos(RA_rad) - x*sin(RA_rad));
    439   *pD = -(y*sin(RA_rad) + x*cos(RA_rad))*sin(DEC_rad) + z*cos(DEC_rad);
    440 
    441   return TRUE;
    442 }
    443 
    444 // allocate arrays but not the container
    445 int PlxFitDataAlloc (PlxFitData *data, int N) {
    446 
    447   data->Npts = N;
    448   ALLOCATE (data->X, double, N);
    449   ALLOCATE (data->Y, double, N);
    450   ALLOCATE (data->dX, double, N);
    451   ALLOCATE (data->dY, double, N);
    452   ALLOCATE (data->t, double, N);
    453   ALLOCATE (data->pX, double, N);
    454   ALLOCATE (data->pY, double, N);
    455   ALLOCATE (data->index, int, N);
    456   return TRUE;
    457 }
    458 
    459 void PlxFitDataFree (PlxFitData *data) {
    460   FREE (data->X);
    461   FREE (data->Y);
    462   FREE (data->dX);
    463   FREE (data->dY);
    464   FREE (data->t);
    465   FREE (data->pX);
    466   FREE (data->pY);
    467   FREE (data->index);
    468357}
    469358
     
    481370    tgt->pX[i] = src->pX[N];
    482371    tgt->pY[i] = src->pY[N];
     372
     373    // *** make this optional?
     374    tgt->Wx[i] = src->Wx[N];
     375    tgt->Wy[i] = src->Wy[N];
    483376  }
    484377  return TRUE;
     
    539432    pYmin = MIN (pYmin, fitdata->pY[Nsubset]);
    540433    pYmax = MAX (pYmax, fitdata->pY[Nsubset]);
     434
     435    fitdata->Wx[Nsubset] = 1.0;
     436    fitdata->Wy[Nsubset] = 1.0;   
    541437    fitdata->index[Nsubset] = i;
    542438    Nsubset++;
Note: See TracChangeset for help on using the changeset viewer.