IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12220


Ignore:
Timestamp:
Mar 4, 2007, 3:45:18 PM (19 years ago)
Author:
eugene
Message:

finishing up the basic code; almost compiles

Location:
branches/dvo-mods-2007-02/Ohana/src/relastro
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • branches/dvo-mods-2007-02/Ohana/src/relastro/Makefile

    r11880 r12220  
    2121
    2222RELASTRO = \
    23 $(SRC)/relastro.$(ARCH).o        \
    24 $(SRC)/initialize.$(ARCH).o      \
    2523$(SRC)/ConfigInit.$(ARCH).o      \
    26 $(SRC)/args.$(ARCH).o            \
    27 $(SRC)/liststats.$(ARCH).o       \
    28 $(SRC)/load_images.$(ARCH).o     \
    29 $(SRC)/name_region.$(ARCH).o     \
    30 $(SRC)/find_images.$(ARCH).o     \
    31 $(SRC)/find_regions.$(ARCH).o    \
    32 $(SRC)/get_regions.$(ARCH).o     \
    33 $(SRC)/load_catalogs.$(ARCH).o   \
    34 $(SRC)/gcatalog.$(ARCH).o        \
    35 $(SRC)/bcatalog.$(ARCH).o        \
    36 $(SRC)/GridOps.v2.$(ARCH).o      \
    37 $(SRC)/StarOps.$(ARCH).o         \
     24$(SRC)/FitChip.$(ARCH).o         \
     25$(SRC)/FitMosaic.$(ARCH).o       \
     26$(SRC)/FitPM.$(ARCH).o           \
     27$(SRC)/FitPMandPar.$(ARCH).o     \
     28$(SRC)/FitSimple.$(ARCH).o       \
    3829$(SRC)/ImageOps.$(ARCH).o        \
    3930$(SRC)/MosaicOps.$(ARCH).o       \
     31$(SRC)/ParFactor.$(ARCH).o       \
     32$(SRC)/SetSignals.$(ARCH).o      \
     33$(SRC)/Shutdown.$(ARCH).o        \
     34$(SRC)/StarOps.$(ARCH).o         \
     35$(SRC)/UpdateChips.$(ARCH).o     \
     36$(SRC)/UpdateMosaic.$(ARCH).o    \
     37$(SRC)/UpdateObjects.$(ARCH).o   \
     38$(SRC)/UpdateSimple.$(ARCH).o    \
     39$(SRC)/args.$(ARCH).o            \
     40$(SRC)/bcatalog.$(ARCH).o        \
     41$(SRC)/dvo_astrom_ops.$(ARCH).o  \
     42$(SRC)/fitpoly.$(ARCH).o         \
    4043$(SRC)/global_stats.$(ARCH).o    \
     44$(SRC)/initialize.$(ARCH).o      \
     45$(SRC)/liststats.$(ARCH).o       \
     46$(SRC)/load_catalogs.$(ARCH).o   \
     47$(SRC)/load_images.$(ARCH).o     \
     48$(SRC)/mkpolyterm.$(ARCH).o      \
    4149$(SRC)/plot_scatter.$(ARCH).o    \
    4250$(SRC)/plotstuff.$(ARCH).o       \
    43 $(SRC)/misc.$(ARCH).o            \
     51$(SRC)/relastro.$(ARCH).o        \
    4452$(SRC)/reload_catalogs.$(ARCH).o \
    45 $(SRC)/image-db.$(ARCH).o \
    46 $(SRC)/free_catalogs.$(ARCH).o   \
    47 $(SRC)/check_permissions.$(ARCH).o   \
     53$(SRC)/setExclusions.$(ARCH).o   \
     54$(SRC)/write_coords.$(ARCH).o
     55
     56DROP = \
    4857$(SRC)/setMrelFinal.$(ARCH).o    \
    49 $(SRC)/write_coords.$(ARCH).o    \
    50 $(SRC)/setExclusions.$(ARCH).o   \
    51 $(SRC)/Shutdown.$(ARCH).o        \
    52 $(SRC)/SetSignals.$(ARCH).o      \
    53 $(SRC)/wcatalog.$(ARCH).o
     58
    5459
    5560$(RELASTRO): $(INC)/relastro.h
  • branches/dvo-mods-2007-02/Ohana/src/relastro/include/relastro.h

    r12206 r12220  
    44# include <signal.h>
    55
     6typedef struct {
     7  double R, D;  /* Sky Coords    - degrees */
     8  double P, Q;  /* Tangent Plane - pixels  */
     9  double L, M;  /* Focal Plane   - pixels  */
     10  double X, Y;  /* Chip Coords   - pixels  */
     11  double Mag, dMag;
     12  int mask;
     13} StarData;
     14
    615// structure to hold coordinate fitting terms
    716typedef struct {
    817    int Npts;
    918    int Nterms;
    10     int Npower;
    1119    int Norder;
     20    int Nsums;
     21    int Nelems;
     22    double **sum;
    1223    double **xsum;
    1324    double **ysum;
    14 
    15     double **vector;
    16     double **matrix;
     25    double **xfit;
     26    double **yfit;
    1727} CoordFit;
    1828
     
    2838  double chisq;
    2939  int Nfit;
    30 } PMfit;
     40} PMFit;
    3141
    3242typedef struct {
     
    6272char   CATFORMAT[16];  /* internal, elixir, loneos, panstarrs */
    6373char   CameraConfig[256];
     74char   SKY_TABLE[256];
     75int    SKY_DEPTH;  /** XXX EAM : depth of catalog tables, fix usage */
    6476
    6577double MAG_LIM;
     
    108120enum {black, white, red, orange, yellow, green, blue, indigo, violet};
    109121
     122int DophotSelect, DophotValue;
     123
    110124int TimeSelect;
    111125time_t TSTART, TSTOP;
    112126
    113 # ifdef GRID_V1
    114 int setGridMeasure (int meas, int cat, double X, double Y);
    115 # endif
    116 
    117 # ifdef GRID_V2
    118 int setGridMeasure (int meas, int cat, double X, double Y, int ccdnum);
    119 # endif
     127int FITTING_MODE;
     128enum {FIT_AVERAGE, FIT_PM_ONLY, FIT_PM_AND_PAR};
     129
     130SkyRegion UserPatch;
     131int UserPatchSelect;
     132
     133int DoUpdateObjects;
     134int DoUpdateSimple;
     135int DoUpdateChips;
     136int DoUpdateMosaics;
    120137
    121138/*** relphot prototypes ***/
     
    126143int          *SelectRefMosaic     PROTO((Mosaic **refmosaic, int *Nimage));
    127144int           args                PROTO((int argc, char **argv));
    128 int           bcatalog            PROTO((Catalog *subcatalog, Catalog *catalog, GSCRegion *fullregion));
     145int           bcatalog            PROTO((Catalog *subcatalog, Catalog *catalog));
    129146void          clean_images        PROTO(());
    130147void          clean_measures      PROTO((Catalog *catalog, int Ncatalog, int final));
     
    171188void          initstats           PROTO((char *mode));
    172189int           liststats           PROTO((double *value, double *dvalue, int N, StatType *stats));
    173 Catalog      *load_catalogs       PROTO((GSCRegion *region, int Nregion, GSCRegion *fullregion));
    174 GSCRegion    *load_images         PROTO((FITS_DB *db, char *seed, int *nregion, GSCRegion *fullregion));
     190Catalog      *load_catalogs       PROTO((SkyList *skylist, int *Ncatalog));
     191SkyList      *load_images         PROTO((FITS_DB *db, char *regionName, SkyRegion *region, int RegionSelect));
     192Image        *select_images       PROTO((SkyList *skylist, Image *timage, int Ntimage, int **LineNumber, int *Nimage));
    175193
    176194void check_permissions (char *basefile);
     
    195213void          plot_star_coords    PROTO((Catalog *catalog, int Ncatalog));
    196214void          plot_stars          PROTO((Catalog *catalog, int Ncatalog));
    197 void          reload_catalogs     PROTO((GSCRegion *region, int Nregion, GSCRegion *fullregion));
     215void          reload_catalogs     PROTO((SkyList *skylist));
    198216int           setExclusions       PROTO((Catalog *catalog, int Ncatalog));
    199217void          setMcal             PROTO((Catalog *catalog, int Poor));
     
    226244void          wimages             PROTO(());
    227245void          write_coords        PROTO((Header *header, Coords *coords));
     246
     247
     248double **array_init (int Nx, int Ny);
     249void array_free (double **array, int Nx);
     250CoordFit *fit_init (int order);
     251void fit_free (CoordFit *fit);
     252void fit_add (CoordFit *fit, double x1, double y1, double x2, double y2, double wt);
     253void fit_eval (CoordFit *fit);
     254double **poly2d_dx (double **poly, int Nx, int Ny);
     255double **poly2d_dy (double **poly, int Nx, int Ny);
     256double **poly2d_copy (double **poly, int Nx, int Ny);
     257double poly2d_eval (double **poly, int Nx, int Ny, double x, double y);
     258void fit_apply_coords (CoordFit *fit, Coords *coords);
     259int CoordsGetCenter (CoordFit *fit, double tol, double *xo, double *yo);
     260CoordFit *CoordsSetCenter (CoordFit *input, double Xo, double Yo);
     261void FitChip (StarData *raw, StarData *ref, int Nmatch, Coords *coords);
     262void FitMosaic (StarData *raw, StarData *ref, int Nmatch, Coords *coords);
     263void FitSimple (StarData *raw, StarData *ref, int Nmatch, Coords *coords);
     264void initObjectData (Catalog *catalog, int Ncatalog);
     265int UpdateObjects (Catalog *catalog, int Ncatalog);
     266int UpdateSimple (Catalog *catalog, int Ncatalog);
     267int UpdateChips (Catalog *catalog, int Ncatalog);
     268int UpdateMosaic (Catalog *catalog, int Ncatalog);
     269int sun_ecliptic (double jd, double *lambda, double *beta, double *epsilon);
     270int ParFactor (double *pR, double *pD, double R, double D, time_t T);
     271int FitPM (PMFit *fit, double *X, double *dX, double *Y, double *dY, time_t *T, int Npts);
     272int FitPMandPar (PMFit *fit, double *X, double *dX, double *Y, double *dY, time_t *T, double *pR, double *pD, int Npts);
     273
     274Coords *getMosaicForImage (int N);
     275
     276StarData *getImageRef (Catalog *catalog, int Ncatalog, int im, int *Nstars, int isMosaic);
     277StarData *getImageRaw (Catalog *catalog, int Ncatalog, int im, int *Nstars, int isMosaic);
     278
     279double getMeanR (Measure *measure, Average *average, SecFilt *secfilt);
     280double getMeanD (Measure *measure, Average *average, SecFilt *secfilt);
  • branches/dvo-mods-2007-02/Ohana/src/relastro/src/FitMosaic.c

    r12205 r12220  
    44
    55  int i;
     6  CoordFit *fit;
    67
    7   fit_init (coords[0].Npolyterms);
     8  fit = fit_init (coords[0].Npolyterms);
    89  for (i = 0; i < Nmatch; i++) {
    910    if (raw[i].mask) continue;
    10     fit_add (raw[i].L, raw[i].M, ref[i].P, ref[i].Q);
     11    fit_add (fit, raw[i].L, raw[i].M, ref[i].P, ref[i].Q, 1.0);
    1112  }
    12   fit_eval ();
    13   fit_apply_coords (coords);
     13  fit_eval (fit);
     14  fit_apply_coords (fit, coords);
     15  fit_free (fit);
    1416  /* FitChip and FitSimple update the coords in different ways? maybe not... */
    1517}
  • branches/dvo-mods-2007-02/Ohana/src/relastro/src/FitPM.c

    r12068 r12220  
    22
    33/* do we want an init function which does the alloc and a clear function to free? */
    4 int FitPM (PMFit *fit, double *X, double *dX, double *Y, double *dY, double *T, int Npts) {
     4int FitPM (PMFit *fit, double *X, double *dX, double *Y, double *dY, time_t *T, int Npts) {
     5
     6  int i;
    57
    68  double **A, **B;
     9  double wx, wy, Wx, Wy, Tx, Ty, Tx2, Ty2, Xs, Ys, XT, YT;
    710
    811  /* do I need to do this as 2 2x2 matrix equations? */
    9   ALLOCATE (A, double *, 4);
    10   ALLOCATE (B, double *, 4);
    11   for (i = 0; i < 4; i++) {
    12     ALLOCATE (A[i], double, 4);
    13     ALLOCATE (B[i], double, 1);
    14     bzero (A[i], 4*sizeof(double));
    15     bzero (B[i], 1*sizeof(double));
    16   }
     12  A = array_init (4, 4);
     13  B = array_init (4, 1);
    1714
     15  Wx = Wy = Tx = Ty = Tx2 = Ty2 = Xs = Ys = XT = YT = 0.0;
    1816  for (i = 0; i < Npts; i++) {
    1917    /* handle case where dX or dY = 0.0 */
     
    5654  dgaussj (A, 4, B, 1);
    5755
    58   fit[0].Ro = B[0];
    59   fit[0].uR = B[1];
    60   fit[0].Do = B[2];
    61   fit[0].uD = B[3];
     56  fit[0].Ro = B[0][0];
     57  fit[0].uR = B[1][0];
     58  fit[0].Do = B[2][0];
     59  fit[0].uD = B[3][0];
    6260  fit[0].p  = 0.0;
    6361 
     
    6866  fit[0].dp  = 0.0;
    6967 
    70   for (i = 0; i < 4; i++) {
    71     free (A[i]);
    72     free (B[i]);
    73   }
    74   free (A);
    75   free (B);
     68  array_free (A, 4);
     69  array_free (B, 4);
    7670
    7771  return (TRUE);
  • branches/dvo-mods-2007-02/Ohana/src/relastro/src/FitPMandPar.c

    r12068 r12220  
    22
    33/* do we want an init function which does the alloc and a clear function to free? */
    4 int FitPM (PMFit *fit, double *X, double *dX, double *Y, double *dY, double *T, double *pR, double *pD, int Npts) {
     4int FitPMandPar (PMFit *fit, double *X, double *dX, double *Y, double *dY, time_t *T, double *pR, double *pD, int Npts) {
     5
     6  int i;
    57
    68  double **A, **B;
     9  double wx, wy, Wx, Wy, Tx, Ty, Tx2, Ty2, Xs, Ys, XT, YT;
     10  double PR, PD, PRT, PDT, PRX, PDY, PR2, PD2;
    711
    8   ALLOCATE (A, double *, 5);
    9   ALLOCATE (B, double *, 5);
    10   for (i = 0; i < 5; i++) {
    11     ALLOCATE (A[i], double, 5);
    12     ALLOCATE (B[i], double, 1);
    13     bzero (A[i], 5*sizeof(double));
    14     bzero (B[i], 1*sizeof(double));
    15   }
     12  A = array_init (5, 5);
     13  B = array_init (5, 1);
    1614
     15  PR = PD = PRT = PDT = PRX = PDY = PR2 = PD2 = 0.0;
     16  Wx = Wy = Tx = Ty = Tx2 = Ty2 = Xs = Ys = XT = YT = 0.0;
    1717  for (i = 0; i < Npts; i++) {
    1818    /* handle case where dX or dY = 0.0 */
     
    7878  dgaussj (A, 5, B, 1);
    7979
    80   fit[0].Ro = B[0];
    81   fit[0].uR = B[1];
    82   fit[0].Do = B[2];
    83   fit[0].uD = B[3];
    84   fit[0].p  = B[4];
     80  fit[0].Ro = B[0][0];
     81  fit[0].uR = B[1][0];
     82  fit[0].Do = B[2][0];
     83  fit[0].uD = B[3][0];
     84  fit[0].p  = B[4][0];
    8585 
    8686  fit[0].dRo = sqrt(A[0][0]);
     
    9090  fit[0].dp  = sqrt(A[4][4]);
    9191 
    92   for (i = 0; i < 5; i++) {
    93     free (A[i]);
    94     free (B[i]);
    95   }
    96   free (A);
    97   free (B);
     92  array_free (A, 5);
     93  array_free (B, 5);
    9894
    9995  /* get the chisq from the matrix values */
  • branches/dvo-mods-2007-02/Ohana/src/relastro/src/FitSimple.c

    r12205 r12220  
    44
    55  int i;
     6  CoordFit *fit;
    67
    7   fit_init (coords[0].Npolyterms);
     8  fit = fit_init (coords[0].Npolyterms);
    89  for (i = 0; i < Nmatch; i++) {
    910    if (raw[i].mask) continue;
    10     fit_add (raw[i].X, raw[i].Y, ref[i].L, ref[i].M);
     11    fit_add (fit, raw[i].X, raw[i].Y, ref[i].L, ref[i].M, 1.0);
    1112  }
    12   fit_eval ();
    13   fit_apply_coords (coords);
     13  fit_eval (fit);
     14  fit_apply_coords (fit, coords);
     15  fit_free (fit);
    1416}
    1517
  • branches/dvo-mods-2007-02/Ohana/src/relastro/src/ImageOps.c

    r12205 r12220  
    9494void matchImage (Catalog *catalog, int meas, int cat) {
    9595
    96   int i, ave, ccdnum;
    97   double ra, dec, X, Y;
    98   char *pname, *filter, *p, base[256];
     96  int i;
    9997  Measure *measure;
    10098 
     
    178176}
    179177
    180 StarData *getImageRaw (int im, int *Nstars, int isMosaic) {
    181 
     178/* XXX re-write to use image->nstars if that is possible */
     179StarData *getImageRaw (Catalog *catalog, int Ncatalog, int im, int *Nstars, int isMosaic) {
     180
     181  int i, m, c;
     182
     183  Coords *mosaic;
    182184  StarData *raw;
    183185 
    184186  ALLOCATE (raw, StarData, Nlist[im]);
    185187
     188  mosaic = NULL;
    186189  if (isMosaic) {
    187190    mosaic = getMosaicForImage (im);
     
    202205    XY_to_LM (&raw[i].L, &raw[i].M, raw[i].X, raw[i].Y, &image[im].coords);
    203206    if (isMosaic) {
    204       XY_to_LM (&raw[i].P, &raw[i].Q, raw[i].L, raw[i].M, &mosaic);
    205       LM_to_RD (&raw[i].R, &raw[i].D, raw[i].P, raw[i].Q, &mosaic);
     207      XY_to_LM (&raw[i].P, &raw[i].Q, raw[i].L, raw[i].M, mosaic);
     208      LM_to_RD (&raw[i].R, &raw[i].D, raw[i].P, raw[i].Q, mosaic);
    206209    } else {
    207210      raw[i].P = raw[i].L;
     
    215218}
    216219
    217 StarData *getImageRef (int im, int *Nstars, int isMosaic) {
    218 
     220StarData *getImageRef (Catalog *catalog, int Ncatalog, int im, int *Nstars, int isMosaic) {
     221
     222  int i, m, c, n;
     223
     224  Coords *mosaic;
    219225  StarData *ref;
    220226 
    221227  ALLOCATE (ref, StarData, Nlist[im]);
    222228
     229  mosaic = NULL;
    223230  if (isMosaic) {
    224231    mosaic = getMosaicForImage (im);
     
    237244    RD_to_LM (&ref[i].P, &ref[i].Q, ref[i].R, ref[i].D, &image[im].coords);
    238245    if (isMosaic) {
    239       LM_to_XY (&ref[i].M, &ref[i].L, ref[i].P, ref[i].Q, &mosaic);
    240       LM_to_XY (&ref[i].X, &ref[i].Y, ref[i].L, ref[i].M, &mosaic);
     246      LM_to_XY (&ref[i].M, &ref[i].L, ref[i].P, ref[i].Q, mosaic);
     247      LM_to_XY (&ref[i].X, &ref[i].Y, ref[i].L, ref[i].M, mosaic);
    241248    } else {
    242249      ref[i].L = ref[i].P;
  • branches/dvo-mods-2007-02/Ohana/src/relastro/src/ParFactor.c

    r12068 r12220  
    2828int sun_ecliptic (double jd, double *lambda, double *beta, double *epsilon) {
    2929
    30   double n, L, g, lambda,epsilon,alpha,delta,x,y,z;
     30  double n, L, g;
     31
     32# define J2000 2451545.       /* Julian date at standard epoch */
    3133
    3234  n = jd - J2000;
     
    4345
    4446  double jd;
    45   double L, B;
     47  double L, B, E, e, s, r, d;
    4648
    4749  /* given a time T in UNIX seconds, determine the solar longitude S */
  • branches/dvo-mods-2007-02/Ohana/src/relastro/src/StarOps.c

    r12048 r12220  
    2828  if (catalog[cat].average[ave].code & STAR_BAD) return (NO_MAG); 
    2929 
    30   value = PhotPrimary ? catalog[cat].average[ave].M : catalog[cat].secfilt[PhotNsec*ave+PhotSec].M;
     30  value = catalog[cat].secfilt[PhotNsec*ave+PhotSec].M;
    3131  return (value);
    3232}
     
    6565      liststats (list, dlist, N, &stats);
    6666
    67       if (PhotPrimary) {
    68         catalog[i].average[j].M = stats.mean;
    69         catalog[i].average[j].dM = stats.sigma;
    70         catalog[i].average[j].Xm = (stats.Nmeas > 1) ? 100.0*log10(stats.chisq) : NO_MAG;
    71       } else {
    72         catalog[i].secfilt[PhotNsec*j+PhotSec].M  = stats.mean;
    73         catalog[i].secfilt[PhotNsec*j+PhotSec].dM = stats.sigma;
    74         catalog[i].secfilt[PhotNsec*j+PhotSec].Xm = (stats.Nmeas > 1) ? 100.0*log10(stats.chisq) : NO_MAG;
    75       }     
     67      catalog[i].secfilt[PhotNsec*j+PhotSec].M  = stats.mean;
     68      catalog[i].secfilt[PhotNsec*j+PhotSec].dM = stats.sigma;
     69      catalog[i].secfilt[PhotNsec*j+PhotSec].Xm = (stats.Nmeas > 1) ? 100.0*log10(stats.chisq) : NO_MAG;
    7670    }
    7771  }
     
    121115
    122116      /* use sigma or error in dM for output? */
    123       if (PhotPrimary) {
    124         catalog[i].average[j].M = stats.mean;
    125         catalog[i].average[j].dM = MAX (stats.sigma, stats.error);
    126         catalog[i].average[j].Xm = (stats.Nmeas > 1) ? 100.0*log10(stats.chisq) : NO_MAG;
    127       } else {
    128         catalog[i].secfilt[PhotNsec*j+PhotSec].M  = stats.mean;
    129         catalog[i].secfilt[PhotNsec*j+PhotSec].dM = MAX (stats.error, stats.sigma);
    130         catalog[i].secfilt[PhotNsec*j+PhotSec].Xm = (stats.Nmeas > 1) ? 100.0*log10(stats.chisq) : NO_MAG;
    131       }     
     117      catalog[i].secfilt[PhotNsec*j+PhotSec].M  = stats.mean;
     118      catalog[i].secfilt[PhotNsec*j+PhotSec].dM = MAX (stats.error, stats.sigma);
     119      catalog[i].secfilt[PhotNsec*j+PhotSec].Xm = (stats.Nmeas > 1) ? 100.0*log10(stats.chisq) : NO_MAG;
    132120    }
    133121  }
     
    183171    for (j = 0; j < catalog[i].Naverage; j++) {
    184172      if (catalog[i].average[j].code & STAR_BAD) continue;
    185       Xm = PhotPrimary ? catalog[i].average[j].Xm : catalog[i].secfilt[PhotNsec*j+PhotSec].Xm;
     173      Xm = catalog[i].secfilt[PhotNsec*j+PhotSec].Xm;
    186174      if (Xm == -1) continue;
    187175      Chisq = pow (10.0, 0.01*Xm);
    188176      xlist[Ntot] = Chisq;
    189       slist[Ntot] = PhotPrimary ? catalog[i].average[j].dM : catalog[i].secfilt[PhotNsec*j+PhotSec].dM;
     177      slist[Ntot] = catalog[i].secfilt[PhotNsec*j+PhotSec].dM;
    190178      dlist[Ntot] = 1;
    191179      Ntot ++;
     
    203191  for (i = 0; i < Ncatalog; i++) {
    204192    for (j = 0; j < catalog[i].Naverage; j++) {
    205       dM = PhotPrimary ? catalog[i].average[j].dM : catalog[i].secfilt[PhotNsec*j+PhotSec].dM;
    206       Xm = PhotPrimary ? catalog[i].average[j].Xm    : catalog[i].secfilt[PhotNsec*j+PhotSec].Xm;
     193      dM = catalog[i].secfilt[PhotNsec*j+PhotSec].dM;
     194      Xm = catalog[i].secfilt[PhotNsec*j+PhotSec].Xm;
    207195      Chisq = pow (10.0, 0.01*Xm);
    208196      mark = (dM > MaxScatter) || (Xm == NO_MAG) || (Chisq > MaxChisq);
     
    387375      if (catalog[i].average[j].code & STAR_BAD) continue; 
    388376
    389       Xm = PhotPrimary ? catalog[i].average[j].Xm : catalog[i].secfilt[PhotNsec*j+PhotSec].Xm;
     377      Xm = catalog[i].secfilt[PhotNsec*j+PhotSec].Xm;
    390378      if (Xm == NO_MAG) continue;
    391379      list[n] = pow (10.0, 0.01*Xm);
     
    423411      if (catalog[i].average[j].code & STAR_BAD) continue; 
    424412
    425       dM = PhotPrimary ? catalog[i].average[j].dM : catalog[i].secfilt[PhotNsec*j+PhotSec].dM;
     413      dM = catalog[i].secfilt[PhotNsec*j+PhotSec].dM;
    426414      list[n] = dM;
    427415      dlist[n] = 1;
     
    452440    for (j = 0; j < catalog[i].Naverage; j++) {
    453441      if (catalog[i].average[j].code & STAR_BAD) continue; 
    454       dMrel = PhotPrimary ? catalog[i].average[j].dM : catalog[i].secfilt[PhotNsec*j+PhotSec].dM;
     442      dMrel = catalog[i].secfilt[PhotNsec*j+PhotSec].dM;
    455443      bin = dMrel / 0.00025;
    456444      bin = MAX (0, MIN (NBIN-1, bin));
     
    483471    for (j = 0; j < catalog[i].Naverage; j++) {
    484472      if (catalog[i].average[j].code & STAR_BAD) continue;
    485       xlist[N] = PhotPrimary ? catalog[i].average[j].M : catalog[i].secfilt[PhotNsec*j+PhotSec].M;
    486       value    = PhotPrimary ? catalog[i].average[j].Xm   : catalog[i].secfilt[PhotNsec*j+PhotSec].Xm;
     473      xlist[N] = catalog[i].secfilt[PhotNsec*j+PhotSec].M;
     474      value    = catalog[i].secfilt[PhotNsec*j+PhotSec].Xm;
    487475      if (value == NO_MAG) continue;
    488476      ylist[N] = 0.01*value;
  • branches/dvo-mods-2007-02/Ohana/src/relastro/src/UpdateChips.c

    r12205 r12220  
    11# include "relastro.h"
    22
    3 int UpdateChips () {
     3int UpdateChips (Catalog *catalog, int Ncatalog) {
    44
    55  /* we can measure new image parameters for each non-mosaic chip independently */
    6 
     6  int i, Nimage, Nstars;
    77  Image *image;
    8   int Nimage;
     8  StarData *raw, *ref;
    99
    1010  image = getimages (&Nimage);
     
    1818
    1919    /* convert measure coordinates to raw entries */
    20     raw = getImageRaw (&image[i], &Nstars, TRUE);
     20    raw = getImageRaw (catalog, Ncatalog, i, &Nstars, TRUE);
    2121
    2222    /* convert average coordinates to ref entries */
    23     ref = getImageRef (&image[i], &Nstars, TRUE);
     23    ref = getImageRef (catalog, Ncatalog, i, &Nstars, TRUE);
    2424
    2525    /* XXX grab this code from mosastro */
  • branches/dvo-mods-2007-02/Ohana/src/relastro/src/UpdateMosaic.c

    r12205 r12220  
    11# include "relastro.h"
    22
    3 int UpdateMosaic () {
     3int UpdateMosaic (Catalog *catalog, int Ncatalog) {
    44
    55  /* we can measure new image parameters for each mosaic independently */
    6 
     6  int i, Nimage, Nstars;
    77  Image *image;
    8   int Nimage;
     8  StarData *raw, *ref;
    99
    1010  image = getimages (&Nimage);
     
    1818
    1919    /* convert measure coordinates to raw entries */
    20     raw = getImageRaw (&image[i], &Nstars, TRUE);
     20    raw = getImageRaw (catalog, Ncatalog, i, &Nstars, TRUE);
    2121
    2222    /* convert average coordinates to ref entries */
    23     ref = getImageRef (&image[i], &Nstars, TRUE);
     23    ref = getImageRef (catalog, Ncatalog, i, &Nstars, TRUE);
    2424
    2525    /* XXX grab this code from mosastro */
  • branches/dvo-mods-2007-02/Ohana/src/relastro/src/UpdateObjects.c

    r12068 r12220  
    66static double *R, *dR;
    77static double *D, *dD;
     8static double *pX;
     9static double *pY;
    810static time_t *T;
    911static double *dT;
     
    2527  ALLOCATE (X, double, MAX (1, Nmax));
    2628  ALLOCATE (Y, double, MAX (1, Nmax));
    27   ALLOCATE (pR, double, MAX (1, Nmax));
    28   ALLOCATE (pD, double, MAX (1, Nmax));
    2929
    3030  ALLOCATE (dR, double, MAX (1, Nmax));
     
    3333  ALLOCATE (dX, double, MAX (1, Nmax));
    3434  ALLOCATE (dY, double, MAX (1, Nmax));
     35
     36  ALLOCATE (pX, double, MAX (1, Nmax));
     37  ALLOCATE (pY, double, MAX (1, Nmax));
    3538
    3639
     
    3841
    3942  int i, j, k, m, N;
    40   float chisq;
    4143  StatType statsR, statsD;
    4244  Coords coords;
     
    8890     
    8991      /* project all of the R,D coordinates to a plane centered on this coordinate */
    90       /* calculate pR[i], pD[i] for each point */
    9192      for (k = 0; k < N; k++) {
    9293          RD_to_XY (&X[k], &Y[k], R[k], D[k], &coords);
     
    100101
    101102          fit.Ro = statsR.mean;
    102           fit.dR = statsR.sigma;
     103          fit.dRo = statsR.sigma;
    103104
    104105          fit.Do = statsD.mean;
    105           fit.dD = statsD.sigma;
     106          fit.dDo = statsD.sigma;
    106107
    107108          fit.chisq = 0.5*(statsR.chisq + statsD.chisq);
     
    117118            ParFactor (&pX[k], &pY[k], R[k], D[k], T[k]);
    118119          }
    119           FitPMandPar (&fit, X, dX, Y, dY, T, pR, pD, N);
     120          FitPMandPar (&fit, X, dX, Y, dY, T, pX, pY, N);
    120121          break;
    121122        default:
     
    137138      catalog[i].average[j].dP  = fit.dp;
    138139
    139       catalog[i].average[j].Xp  = (fit.Npts > 1) ? 100.0*log10(fit.chisq) : NO_MAG;
     140      catalog[i].average[j].Xp  = (fit.Nfit > 1) ? 100.0*log10(fit.chisq) : NO_MAG;
    140141    }
    141142  }
  • branches/dvo-mods-2007-02/Ohana/src/relastro/src/UpdateSimple.c

    r12205 r12220  
    11# include "relastro.h"
    22
    3 int UpdateSimple () {
     3int UpdateSimple (Catalog *catalog, int Ncatalog) {
    44
    55  /* we can measure new image parameters for each non-mosaic chip independently */
    6 
     6  int i, Nimage, Nstars;
    77  Image *image;
    8   int Nimage;
     8  StarData *raw, *ref;
    99
    1010  image = getimages (&Nimage);
     
    1919
    2020    /* convert measure coordinates to raw entries */
    21     raw = getImageRaw (&image[i], &Nstars, FALSE);
     21    raw = getImageRaw (catalog, Ncatalog, i, &Nstars, FALSE);
    2222
    2323    /* convert average coordinates to ref entries */
    24     ref = getImageRef (&image[i], &Nstars, FALSE);
     24    ref = getImageRef (catalog, Ncatalog, i, &Nstars, FALSE);
    2525
    2626    /* XXX grab this code from mosastro */
  • branches/dvo-mods-2007-02/Ohana/src/relastro/src/args.c

    r12048 r12220  
    174174
    175175  /* possible operations */
    176   UpdateObjects = FALSE;
     176  DoUpdateObjects = FALSE;
    177177  if ((N = get_argument (argc, argv, "-update-objects"))) {
    178178    remove_argument (N, &argc, argv);
    179     UpdateObjects = TRUE;
    180   }
    181   UpdateImages = FALSE;
    182   if ((N = get_argument (argc, argv, "-update-images"))) {
    183     remove_argument (N, &argc, argv);
    184     UpdateImages = TRUE;
     179    DoUpdateObjects = TRUE;
     180  }
     181  DoUpdateSimple = FALSE;
     182  if ((N = get_argument (argc, argv, "-update-simple"))) {
     183    remove_argument (N, &argc, argv);
     184    DoUpdateSimple = TRUE;
     185  }
     186  DoUpdateChips = FALSE;
     187  if ((N = get_argument (argc, argv, "-update-chips"))) {
     188    remove_argument (N, &argc, argv);
     189    DoUpdateChips = TRUE;
     190  }
     191  DoUpdateMosaics = FALSE;
     192  if ((N = get_argument (argc, argv, "-update-mosaics"))) {
     193    remove_argument (N, &argc, argv);
     194    DoUpdateMosaics = TRUE;
     195  }
     196
     197  DophotSelect = FALSE;
     198  if ((N = get_argument (argc, argv, "-dophot"))) {
     199    remove_argument (N, &argc, argv);
     200    DophotValue = atof (argv[N]);
     201    remove_argument (N, &argc, argv);
     202    DophotSelect = TRUE;
    185203  }
    186204
  • branches/dvo-mods-2007-02/Ohana/src/relastro/src/bcatalog.c

    r12048 r12220  
    1919    if (catalog[0].average[i].Nm < 2) continue;
    2020
    21     /* XXX this limitation is absurd
    22     if (catalog[0].average[i].R < fullregion[0].RA[0]) continue;
    23     if (catalog[0].average[i].R > fullregion[0].RA[1]) continue;
    24     if (catalog[0].average[i].D < fullregion[0].DEC[0]) continue;
    25     if (catalog[0].average[i].D > fullregion[0].DEC[1]) continue;
    26     */
    27 
    2821    /* start with all stars good */
    2922    subcatalog[0].average[Naverage] = catalog[0].average[i];
     
    3427
    3528    if (RESET) {
    36       float *p;
    37       p = (PhotPrimary) ? &subcatalog[0].average[Naverage].M : &subcatalog[0].secfilt[PhotNsec*Naverage+PhotSec].M;
    38       *p = NO_MAG;
    39       p = (PhotPrimary) ? &subcatalog[0].average[Naverage].dM : &subcatalog[0].secfilt[PhotNsec*Naverage+PhotSec].dM;
    40       *p = NO_MAG;
     29      // XXX reset the ra,dec coords?
    4130      subcatalog[0].average[Naverage].code &= ~ID_STAR_FEW;
    4231      subcatalog[0].average[Naverage].code &= ~ID_STAR_POOR;
     
    5948
    6049      /* select measurements by quality */
    61       if (catalog[0].measure[offset].dophot != 1) continue;
     50      if (DophotSelect && (catalog[0].measure[offset].dophot != DophotValue)) continue;
    6251
    6352      /* select measurements by mag limit */
     
    6655
    6756      /* select measurements by measurement error */
    68       if (catalog[0].measure[offset].dM > SIGMA_LIM) continue;
     57      if ((SIGMA_LIM > 0) && (catalog[0].measure[offset].dM > SIGMA_LIM)) continue;
    6958
    7059      /* select measurements by mag limit */
     
    111100  subcatalog[0].Nsecfilt = catalog[0].Nsecfilt;
    112101
     102  // XXX really do this or not???
    113103  if (catalog[0].Naverage > 0) free (catalog[0].average);
    114104  if (catalog[0].Nmeasure > 0) free (catalog[0].measure);
  • branches/dvo-mods-2007-02/Ohana/src/relastro/src/fitpoly.c

    r12219 r12220  
    1212*/
    1313
     14double **array_init (int Nx, int Ny) {
     15
     16  int i;
     17  double **array;
     18
     19  ALLOCATE (array, double *, Nx);
     20  for (i = 0; i < Nx; i++) {
     21    ALLOCATE (array[i], double, Ny);
     22    memset (array[i], 0, Ny*sizeof(double));
     23  }   
     24  return (array);
     25}
     26
     27void array_free (double **array, int Nx) {
     28
     29  int i;
     30
     31  for (i = 0; i < Nx; i++) {
     32    free (array[i]);
     33  }   
     34  free (array);
     35}
     36
    1437// XXX define a fit structure and drop the file static variables?
    1538CoordFit *fit_init (int order) {
    1639
    17   int i;
     40  CoordFit *fit;
    1841
    1942  ALLOCATE (fit, CoordFit, 1);
     
    2952  // xsum[i][j] holds \sum (x2 wt x1^i y1^j)
    3053  // ysum[i][j] holds \sum (y2 wt x1^i y1^j)
    31   ALLOCATE (fit[0].xsum, double *, fit[0].Nterms);
    32   ALLOCATE (fit[0].ysum, double *, fit[0].Nterms);
    33   for (i = 0; i < fit[0].Nterms; i++) {
    34     ALLOCATE (fit[0].xsum[i], double, fit[0].Nterms);
    35     ALLOCATE (fit[0].ysum[i], double, fit[0].Nterms);
    36     bzero (fit[0].xsum[i], fit[0].Nterms*sizeof(double));
    37     bzero (fit[0].ysum[i], fit[0].Nterms*sizeof(double));
    38   }     
     54  fit[0].xsum = array_init (fit[0].Nterms, fit[0].Nterms);
     55  fit[0].ysum = array_init (fit[0].Nterms, fit[0].Nterms);
     56
     57  // xfit[i][j] holds x2 coeff for x1^i y1^j
     58  // yfit[i][j] holds y2 coeff for x1^i y1^j
     59  fit[0].xfit = array_init (fit[0].Nterms, fit[0].Nterms);
     60  fit[0].yfit = array_init (fit[0].Nterms, fit[0].Nterms);
    3961
    4062  // sum[i][j] holds \sum (wt x1^i y1^j)
    41   ALLOCATE (fit[0].sum, double *, fit[0].Nsums);
    42   for (i = 0; i < fit[0].Nsums; i++) {
    43     ALLOCATE (fit[0].sum[i], double, fit[0].Nsums);
    44     bzero (fit[0].sum[i], fit[0].Nsums*sizeof(double));
    45   }
    46 
    47   // matrix, vector hold the final linear system
    48   ALLOCATE (fit[0].matrix, double *, fit[0].Nelems);
    49   ALLOCATE (fit[0].vector, double *, fit[0].Nelems);
    50   for (i = 0; i < fit[0].Nelems; i++) {
    51     ALLOCATE (fit[0].matrix[i], double, fit[0].Nelems);
    52     ALLOCATE (fit[0].vector[i], double, fit[0].Nelems);
    53     bzero (fit[0].matrix[i], fit[0].Nelems*sizeof(double));
    54     bzero (fit[0].vector[i], 2*sizeof(double));
    55   }
     63  fit[0].sum = array_init (fit[0].Nsums, fit[0].Nsums);
     64
    5665  return (fit);
    5766}
    5867
     68void fit_free (CoordFit *fit) {
     69
     70  array_free (fit[0].xfit, fit[0].Nterms);
     71  array_free (fit[0].yfit, fit[0].Nterms);
     72
     73  array_free (fit[0].sum, fit[0].Nsums);
     74  array_free (fit[0].xsum, fit[0].Nterms);
     75  array_free (fit[0].ysum, fit[0].Nterms);
     76 
     77  free (fit);
     78}
     79 
    5980// XXX use implicit masks as below or explicit masks (with function to set?)
    6081// XXX eg, add a global mask to this file and
     
    84105void fit_eval (CoordFit *fit) {
    85106
    86   int i, j, n, m, M, N;
     107  int i, j, ix, iy, jx, jy;
     108  double **matrix, **vector;
    87109
    88110  if (fit[0].Npts == 0) {
    89111    fprintf (stderr, "warning: no valid pts\n");
    90112  }
     113
     114  // matrix, vector hold the final linear system
     115  matrix = array_init (fit[0].Nelems, fit[0].Nelems);
     116  vector = array_init (fit[0].Nelems, 2);
    91117
    92118  /* remap the xsum,ysum terms into the vector */
     
    94120    ix = i % fit[0].Nterms;
    95121    iy = i / fit[0].Nterms;
    96     vector[i][0] = xsum[ix][iy];
    97     vector[i][1] = ysum[ix][iy];
     122    vector[i][0] = fit[0].xsum[ix][iy];
     123    vector[i][1] = fit[0].ysum[ix][iy];
    98124
    99125    for (j = 0; j < fit[0].Nelems; j++) {
    100126      jx = j % fit[0].Nterms;
    101127      jy = j / fit[0].Nterms;
    102       matrix[i][j] = sum[ix+jx][iy+jy];
    103     }
    104   }
    105 
    106   dgaussj (matrix, NPARS, vector, 2);
     128      matrix[i][j] = fit[0].sum[ix+jx][iy+jy];
     129    }
     130  }
     131
     132  dgaussj (matrix, fit[0].Nelems, vector, 2);
    107133
    108134  for (i = 0; i < fit[0].Nelems; i++) {
     
    112138             ix, iy, vector[i][0], ix, iy, vector[i][1]);
    113139  }     
     140
     141  /* remap the vector terms into xfit,yfit */
     142  for (i = 0; i < fit[0].Nelems; i++) {
     143    ix = i % fit[0].Nterms;
     144    iy = i / fit[0].Nterms;
     145    fit[0].xfit[ix][iy] = vector[i][0];
     146    fit[0].yfit[ix][iy] = vector[i][1];
     147  }
     148
     149  array_free (matrix, fit[0].Nelems);
     150  array_free (vector, fit[0].Nelems);
     151}
     152
     153// Nx, Ny is the number of terms in x and in y
     154double **poly2d_dx (double **poly, int Nx, int Ny) {
     155
     156  int i, j, Nxout, Nyout;
     157  double **dpoly;
     158
     159  Nxout = Nx - 1;
     160  Nyout = Ny;
     161
     162  // poly[i][j] holds coeff for x1^i y1^j
     163  dpoly = array_init (Nxout, Nyout);
     164
     165  for (i = 0; i < Nxout; i++) {
     166    for (j = 0; j < Nyout; j++) {
     167      dpoly[i][j] = poly[i+1][j] * (i+1);
     168    }
     169  }
     170  return dpoly;
     171}
     172
     173// Nx, Ny is the number of terms in x and in y
     174double **poly2d_dy (double **poly, int Nx, int Ny) {
     175
     176  int i, j, Nxout, Nyout;
     177  double **dpoly;
     178
     179  Nxout = Nx;
     180  Nyout = Ny - 1;
     181
     182  // poly[i][j] holds coeff for x1^i y1^j
     183  dpoly = array_init (Nxout, Nyout);
     184
     185  for (i = 0; i < Nxout; i++) {
     186    for (j = 0; j < Nyout; j++) {
     187      dpoly[i][j] = poly[i][j+1] * (j+1);
     188    }
     189  }
     190  return dpoly;
     191}
     192
     193// Nx, Ny is the number of terms in x and in y
     194double **poly2d_copy (double **poly, int Nx, int Ny) {
     195
     196  int i, j;
     197  double **out;
     198
     199  // poly[i][j] holds coeff for x1^i y1^j
     200  out = array_init (Nx, Ny);
     201
     202  for (i = 0; i < Nx; i++) {
     203    for (j = 0; j < Ny; j++) {
     204      out[i][j] = poly[i][j+1];
     205    }
     206  }
     207  return out;
     208}
     209
     210double poly2d_eval (double **poly, int Nx, int Ny, double x, double y) {
     211
     212  int i, j;
     213  double xsum, ysum, sum;
     214
     215  sum = 0;
     216  xsum = ysum = 1.0;
     217
     218  for (i = 0; i < Nx; i++) {
     219    ysum = xsum;
     220    for (j = 0; j < Ny; j++) {
     221      sum += poly[i][j] * ysum;
     222      ysum *= y;
     223    }
     224    xsum *= x;
     225  }
     226  return (sum);
    114227}
    115228
     
    119232void fit_apply_coords (CoordFit *fit, Coords *coords) {
    120233
    121   int i, j, Np, Nv, N;
    122234  double c11, c12;
    123235  double c21, c22;
    124   double R;
     236  double Xo, Yo, R;
     237  CoordFit *modfit;
    125238
    126239  /* I have L,M = fit(X,Y). set corresponding terms for coords */
     
    129242  // L = pc1_1*cd1*(x - cp1) + pc1_2*cd2*(y - cp2) + ...
    130243
    131   coords[0].crpix1,crpix2 = CoordsGetCenter (fit);
    132   modfit = CoordsSetCenter (fit, xo, yo);
    133 
    134   // set crpix1,2
    135   fit_to_coordterms (coords, modfit, 0, 0);
     244  CoordsGetCenter (fit, 0.001, &Xo, &Yo);
     245  coords[0].crpix1 = Xo;
     246  coords[0].crpix2 = Yo;
     247 
     248  // resulting fit should have zero constant terms
     249  modfit = CoordsSetCenter (fit, Xo, Yo);
    136250
    137251  // set pc1_1, pc1_2, pc2_1, pc2_2 (cd1,cd2 = 1.0)
    138   fit_to_coordterms (coords, modfit, 0, 1);
    139   fit_to_coordterms (coords, modfit, 1, 0);
     252  coords[0].pc1_1 = modfit[0].xfit[1][0];
     253  coords[0].pc1_2 = modfit[0].xfit[0][1];
     254  coords[0].pc2_1 = modfit[0].yfit[1][0];
     255  coords[0].pc2_2 = modfit[0].yfit[0][1];
    140256
    141257  // set the polyterm elements
    142   fit_to_coordterms (coords, modfit, 0, 2);
    143   fit_to_coordterms (coords, modfit, 1, 1);
    144   fit_to_coordterms (coords, modfit, 2, 0);
    145 
    146   fit_to_coordterms (coords, modfit, 0, 3);
    147   fit_to_coordterms (coords, modfit, 1, 2);
    148   fit_to_coordterms (coords, modfit, 2, 1);
    149   fit_to_coordterms (coords, modfit, 3, 0);
     258  coords[0].polyterms[0][0] = modfit[0].xfit[2][0];
     259  coords[0].polyterms[1][0] = modfit[0].xfit[1][1];
     260  coords[0].polyterms[2][0] = modfit[0].xfit[0][2];
     261
     262  coords[0].polyterms[0][1] = modfit[0].yfit[2][0];
     263  coords[0].polyterms[1][1] = modfit[0].yfit[1][1];
     264  coords[0].polyterms[2][1] = modfit[0].yfit[0][2];
     265
     266  // I need to validate Norder
     267  coords[0].polyterms[3][0] = modfit[0].xfit[3][0];
     268  coords[0].polyterms[4][0] = modfit[0].xfit[2][1];
     269  coords[0].polyterms[5][0] = modfit[0].xfit[1][2];
     270  coords[0].polyterms[6][0] = modfit[0].xfit[0][3];
     271
     272  coords[0].polyterms[3][1] = modfit[0].yfit[3][0];
     273  coords[0].polyterms[4][1] = modfit[0].yfit[2][1];
     274  coords[0].polyterms[5][1] = modfit[0].yfit[1][2];
     275  coords[0].polyterms[6][1] = modfit[0].yfit[0][3];
    150276
    151277  /* we do not modify crval1,2: these are kept at the default values */
     
    164290  coords[0].pc2_2  = c22*R;
    165291
     292  fit_free (modfit);
    166293  /* keep the order and type from initial values */
    167294}
    168295
    169 void fit_free (CoordFit *fit) {
    170 
    171   int i;
    172 
    173   for (i = 0; i < fit[0].Nterms; i++) {
    174     free (fit[0].xsum[i]);
    175     free (fit[0].ysum[i]);
    176   }     
    177   free (fit[0].xsum);
    178   free (fit[0].ysum);
    179 
    180   for (i = 0; i < fit[0].Nsums; i++) {
    181     free (fit[0].sum[i]);
    182   }
    183   free (fit[0].sum);
    184 
    185   for (i = 0; i < fit[0].Nelems; i++) {
    186     free (fit[0].matrix[i]);
    187     free (fit[0].vector[i]);
    188   }
    189   free (fit[0].matrix);
    190   free (fit[0].vector);
    191 
    192   free (fit);
    193 }
    194  
  • branches/dvo-mods-2007-02/Ohana/src/relastro/src/mkpolyterm.c

    r12219 r12220  
    1 # include "mosastro.h"
     1# include "relastro.h"
    22
    3 fit_to_coordterms (Coords *coords, CoordFit *fit, int nx, int ny) {
     3double factorial (int N) {
    44
    5   int nsum;
     5  int i;
     6  double F;
    67
    7   nsum = nx + ny;
    8 
    9   switch (nsum) {
    10     case 0:
    11       xterm = &coords[0].crpix1;
    12       yterm = &coords[0].crpix2;
    13       return;
    14     case 1:
    15       if (ny == 0) {
    16         xterm = &coords[0].pc1_1;
    17         yterm = &coords[0].pc2_1;
    18       } else {
    19         xterm = &coords[0].pc1_2;
    20         yterm = &coords[0].pc2_2;
    21       }
    22       return;
    23     case 2:
    24       xterm = &coords[0].polyterm[ny][0];
    25       yterm = &coords[0].polyterm[ny][1];
    26       return;
    27     case 3:
    28       xterm = &coords[0].polyterm[ny+3][0];
    29       yterm = &coords[0].polyterm[ny+3][1];
    30       return;
    31     default:
    32       fprintf (stderr, "programming error %s:%d\n", __func__, __line__);
    33       exit (2);
     8  F = 1;
     9  for (i = N; i > 1; i--) {
     10    F *= i;
    3411  }
    35   fprintf (stderr, "programming error %s:%d\n", __func__, __line__);
    36   exit (2);
     12  return F;
    3713}
    3814
    39 
    40 // XXXX use a separate structure for the map (x2,y2 = f,g(x1,y1)) ?
    41 
    42 CoordsGetCenter () {
     15// XXX use a separate structure for the map (x2,y2 = f,g(x1,y1)) ?
    4316
    4417// given a 2D transformation -- L(x,y),M(x,y) -- find the coordinates x,y
    4518// for which L,M = 0,0. tol is the allowed error on x,y.
    46 psPlane *psPlaneTransformGetCenter (psPlaneTransform *trans, double tol)
    47 {
     19int CoordsGetCenter (CoordFit *fit, double tol, double *xo, double *yo) {
    4820
    49     // crpix1,2 = X,Y(crval1,2)
    50     // start with linear solution for Xo,Yo:
    51     double R  = (trans->x->coeff[1][0]*trans->y->coeff[0][1] - trans->x->coeff[0][1]*trans->y->coeff[1][0]);
    52     double Xo = (trans->y->coeff[0][0]*trans->x->coeff[0][1] - trans->x->coeff[0][0]*trans->y->coeff[0][1])/R;
    53     double Yo = (trans->x->coeff[0][0]*trans->y->coeff[1][0] - trans->y->coeff[0][0]*trans->x->coeff[1][0])/R;
     21  int i, Nx, Ny;
     22  double R, Xo, Yo, dPos;
     23  double **XdX, **XdY, **YdX, **YdY, **alpha, **beta;
     24  double **xfit, **yfit;
    5425
    55     // iterate to actual solution: requires small non-linear terms
    56     if (trans->x->nX > 1) {
    57         psPolynomial2D *XdX = psPolynomial2D_dX(NULL, trans->x);
    58         psPolynomial2D *XdY = psPolynomial2D_dY(NULL, trans->x);
     26  xfit = fit[0].xfit;
     27  yfit = fit[0].yfit;
    5928
    60         psPolynomial2D *YdX = psPolynomial2D_dX(NULL, trans->y);
    61         psPolynomial2D *YdY = psPolynomial2D_dY(NULL, trans->y);
     29  // solve for Xo,Yo where L,M(Xo,Yo) = 0,0
     30  // start with linear solution for Xo,Yo:
     31  R  = (xfit[1][0]*yfit[0][1] - xfit[0][1]*yfit[1][0]);
     32  Xo = (yfit[0][0]*xfit[0][1] - xfit[0][0]*yfit[0][1])/R;
     33  Yo = (xfit[0][0]*yfit[1][0] - yfit[0][0]*xfit[1][0])/R;
    6234
    63         psImage *Alpha = psImageAlloc (2, 2, PS_DATA_F32);
    64         psVector *Beta = psVectorAlloc (2, PS_DATA_F32);
     35  Nx = fit[0].Nterms;
     36  Ny = fit[0].Nterms;
    6537
    66         /* this loop uses the Newton-Raphson method to solve for Xo,Yo
    67         * it needs the high order terms to be small
    68         * Xo,Yo are in pixels;
    69         */
    70         double dPos = tol + 1;
    71         for (int i = 0; (dPos > tol) && (i < 20); i++) {
    72             // NOTE: order for Alpha is: [y][x]
    73             Alpha->data.F32[0][0] = psPolynomial2DEval (XdX, Xo, Yo);
    74             Alpha->data.F32[1][0] = psPolynomial2DEval (XdY, Xo, Yo);
    75             Alpha->data.F32[0][1] = psPolynomial2DEval (YdX, Xo, Yo);
    76             Alpha->data.F32[1][1] = psPolynomial2DEval (YdY, Xo, Yo);
     38  // iterate to actual solution: requires small non-linear terms
     39  if (fit[0].Norder > 1) {
     40    XdX = poly2d_dx (xfit, Nx, Ny);
     41    XdY = poly2d_dy (xfit, Nx, Ny);
     42    YdX = poly2d_dx (yfit, Nx, Ny);
     43    YdY = poly2d_dy (yfit, Nx, Ny);
    7744
    78             Beta->data.F32[0] = psPolynomial2DEval (trans->x, Xo, Yo);
    79             Beta->data.F32[1] = psPolynomial2DEval (trans->y, Xo, Yo);
     45    alpha = array_init (2, 2);
     46    beta  = array_init (2, 1);
    8047
    81             psMatrixGJSolveF32 (Alpha, Beta);
     48    /* this loop uses the Newton-Raphson method to solve for Xo,Yo
     49     * it needs the high order terms to be small
     50     * Xo,Yo are in pixels;
     51     */
     52    dPos = tol + 1;
     53    for (i = 0; (dPos > tol) && (i < 20); i++) {
     54      // NOTE: order for alpha is: [y][x]
     55      alpha[0][0] = poly2d_eval (XdX, Nx-1, Ny,   Xo, Yo);
     56      alpha[1][0] = poly2d_eval (XdY, Nx,   Ny-1, Xo, Yo);
     57      alpha[0][1] = poly2d_eval (YdX, Nx-1, Ny,   Xo, Yo);
     58      alpha[1][1] = poly2d_eval (YdY, Nx,   Ny-1, Xo, Yo);
    8259
    83             Xo -= Beta->data.F32[0];
    84             Yo -= Beta->data.F32[1];
    85             dPos = hypot(Beta->data.F32[0], Beta->data.F32[1]);
    86         }
    87         psFree (Alpha);
    88         psFree (Beta);
    89         psFree (XdX);
    90         psFree (XdY);
    91         psFree (YdX);
    92         psFree (YdY);
     60      beta[0][0] = poly2d_eval (xfit, Nx, Ny, Xo, Yo);
     61      beta[1][0] = poly2d_eval (yfit, Nx, Ny, Xo, Yo);
     62
     63      dgaussj (alpha, 2, beta, 1);
     64
     65      Xo -= beta[0][0];
     66      Yo -= beta[1][0];
     67      dPos = hypot(beta[0][0], beta[1][0]);
    9368    }
    94     psPlane *center = psPlaneAlloc ();
    95     center->x = Xo;
    96     center->y = Yo;
    97 
    98     return center;
     69    array_free (alpha, 2);
     70    array_free (beta, 2);
     71    array_free (XdX, Nx - 1);
     72    array_free (XdY, Nx);
     73    array_free (YdX, Nx - 1);
     74    array_free (YdY, Nx);
     75  }
     76  *xo = Xo;
     77  *yo = Yo;
     78  return TRUE;
    9979}
    10080
    10181// convert a transformation L(x,y) to L'(x-xo,y-yo)
    102 psPlaneTransform *psPlaneTransformSetCenter (psPlaneTransform *output, psPlaneTransform *input, double Xo, double Yo)
    103 {
     82CoordFit *CoordsSetCenter (CoordFit *input, double Xo, double Yo) {
    10483
    105     // validate fit order
     84  int i, j, Nx, Ny;
     85  double **xPx, **yPx, **xPy, **yPy, **tmp;
    10686
    107     if (output == NULL) {
    108         output = psPlaneTransformAlloc(input->x->nX, input->x->nY);
     87  CoordFit *output;
     88  output = fit_init (input->Norder);
     89
     90  /* given two equivalent polynomial representations L(x,y) = \sum_i \sum_j A_{i,j} x^i y^j
     91   * we can transform L(x,y) into L'(x-xo,y-yo) by taking the derivatives of both sides and
     92   * noting that the constant term in each is the coefficient in the case of L(x,y) and is the
     93   * value of L'(-xo,-yo) in the second case.
     94   */
     95
     96  Nx = input->Nterms;
     97  Ny = input->Nterms;
     98
     99  xPx = poly2d_copy (input->xfit, Nx, Ny);
     100  yPx = poly2d_copy (input->yfit, Nx, Ny);
     101
     102  for (i = 0; i <= input->Nterms; i++) {
     103    xPy = poly2d_copy (xPx, Nx, Ny);
     104    yPy = poly2d_copy (yPx, Nx, Ny);
     105    for (j = 0; j <= input->Nterms; j++) {
     106      output->xfit[i][j] = poly2d_eval (xPy, Nx, Ny, Xo, Yo) / factorial(i) / factorial(j);
     107      output->yfit[i][j] = poly2d_eval (yPy, Nx, Ny, Xo, Yo) / factorial(i) / factorial(j);
     108
     109      // take the next derivative wrt y, catch output (is NULL on last pass)
     110      if (Ny > 0) {
     111        tmp = poly2d_dy(xPy, Nx, Ny);
     112        array_free (xPy, Nx);
     113        xPy = tmp;
     114
     115        tmp = poly2d_dy(yPy, Nx, Ny);
     116        array_free (yPy, Nx);
     117        yPy = tmp;
     118      } else {
     119        array_free (xPy, Nx);
     120        array_free (yPy, Nx);
     121      }
     122
     123      Ny --;
    109124    }
    110 
    111     /* given two equivalent polynomial representations L(x,y) = \sum_i \sum_j A_{i,j} x^i y^j
    112      * we can transform L(x,y) into L'(x-xo,y-yo) by taking the derivatives of both sides and
    113      * noting that the constant term in each is the coefficient in the case of L(x,y) and is the
    114      * value of L'(-xo,-yo) in the second case.
    115      */
    116 
    117     psPolynomial2D *tmp;
    118 
    119     psPolynomial2D *xPx = psPolynomial2DCopy (NULL, input->x);
    120     psPolynomial2D *yPx = psPolynomial2DCopy (NULL, input->y);
    121 
    122     for (int i = 0; i <= input->x->nX; i++) {
    123         psPolynomial2D *xPy = psPolynomial2DCopy (NULL, xPx);
    124         psPolynomial2D *yPy = psPolynomial2DCopy (NULL, yPx);
    125         for (int j = 0; j <= input->x->nY; j++) {
    126             output->x->mask[i][j] = input->x->mask[i][j];
    127             output->y->mask[i][j] = input->y->mask[i][j];
    128             output->x->coeff[i][j] = (output->x->mask[i][j]) ? 0 : psPolynomial2DEval (xPy, Xo, Yo) / tgamma(i+1) / tgamma(j+1);
    129             output->y->coeff[i][j] = (output->y->mask[i][j]) ? 0 : psPolynomial2DEval (yPy, Xo, Yo) / tgamma(i+1) / tgamma(j+1);
    130 
    131             // take the next derivative wrt y, catch output (is NULL on last pass)
    132             tmp = psPolynomial2D_dY(NULL, xPy);
    133             psFree (xPy);
    134             xPy = tmp;
    135             tmp = psPolynomial2D_dY(NULL, yPy);
    136             psFree (yPy);
    137             yPy = tmp;
    138         }
    139         // take the next derivative wrt x, catch output (is NULL on last pass)
    140         tmp = psPolynomial2D_dX(NULL, xPx);
    141         psFree (xPx);
    142         xPx = tmp;
    143         tmp = psPolynomial2D_dX(NULL, yPx);
    144         psFree (yPx);
    145         yPx = tmp;
     125    Ny = input->Nterms;
     126    // take the next derivative wrt x, catch output (is NULL on last pass)
     127    if (Nx > 0) {
     128      tmp = poly2d_dx(xPx, Nx, Ny);
     129      array_free (xPx, Nx);
     130      xPx = tmp;
     131      tmp = poly2d_dx(yPx, Nx, Ny);
     132      array_free (yPx, Nx);
     133      yPx = tmp;
     134      Nx --;
     135    } else {
     136      array_free (xPx, Nx);
     137      array_free (yPx, Nx);
    146138    }
    147     return output;
    148 }
    149 
    150 int mkpolyterm (int n, int m) {
    151  
    152   int i, nt, N;
    153  
    154   N = 0;
    155   nt = n + m;
    156   for (i = 2; i < nt; i++) {
    157     N += i + 1;
    158139  }
    159   N += m;
    160   return (N);
     140  return output;
    161141}
    162142
    163143/*
    164   coords uses an odd, rigid sequence for the coefficients:
     144  Coords uses a rigid sequence for the coefficients:
    165145
    166146  x^0 y^0 : crpix1,2 (but note this is applied before higher order terms)
  • branches/dvo-mods-2007-02/Ohana/src/relastro/src/plot_scatter.c

    r12048 r12220  
    3232        if ((Mgrid = getMgrid (m, i)) == NO_MAG) continue;
    3333
    34         Mrel = PhotPrimary ? catalog[i].average[j].M : catalog[i].secfilt[PhotNsec*j+PhotSec].M;
     34        Mrel = catalog[i].secfilt[PhotNsec*j+PhotSec].M;
    3535        xlist[N] = Mrel;
    3636        ylist[N] = PhotSys  (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*PhotNsec]) - Mcal - Mmos - Mgrid - Mrel;
  • branches/dvo-mods-2007-02/Ohana/src/relastro/src/plotstuff.c

    r12048 r12220  
    4949  if (Xgraph[N] == 0) return;
    5050
    51   KiiPS (Xgraph[N], TRUE, KAPA_NEWPLOT, filename);
     51  KiiPS (Xgraph[N], TRUE, KAPA_PS_NEWPLOT, filename, "default");
    5252  return;
    5353}
  • branches/dvo-mods-2007-02/Ohana/src/relastro/src/relastro.c

    r12068 r12220  
    33int main (int argc, char **argv) {
    44
    5   int i, status, Ncatalog;
     5  int status, Ncatalog;
    66  Catalog *catalog;
    77  FITS_DB db;
     
    4343
    4444  /* major modes */
    45   if (UpdateObjects) {
     45  if (DoUpdateObjects) {
    4646    UpdateObjects (catalog, Ncatalog);
    4747  }
    48   if (UpdateSimple) {
    49     UpdateSimple ();
     48  if (DoUpdateSimple) {
     49    UpdateSimple (catalog, Ncatalog);
    5050  }
    51   if (UpdateChips) {
    52     UpdateChips ();
     51  if (DoUpdateChips) {
     52    UpdateChips (catalog, Ncatalog);
    5353  }
    54   if (UpdateMosaics) {
    55     UpdateMosaics ();
     54  if (DoUpdateMosaics) {
     55    UpdateMosaic (catalog, Ncatalog);
    5656  }
    5757
Note: See TracChangeset for help on using the changeset viewer.