Changeset 12220
- Timestamp:
- Mar 4, 2007, 3:45:18 PM (19 years ago)
- Location:
- branches/dvo-mods-2007-02/Ohana/src/relastro
- Files:
-
- 20 edited
-
Makefile (modified) (1 diff)
-
include/relastro.h (modified) (8 diffs)
-
src/FitMosaic.c (modified) (1 diff)
-
src/FitPM.c (modified) (3 diffs)
-
src/FitPMandPar.c (modified) (3 diffs)
-
src/FitSimple.c (modified) (1 diff)
-
src/ImageOps.c (modified) (5 diffs)
-
src/ParFactor.c (modified) (2 diffs)
-
src/StarOps.c (modified) (9 diffs)
-
src/UpdateChips.c (modified) (2 diffs)
-
src/UpdateMosaic.c (modified) (2 diffs)
-
src/UpdateObjects.c (modified) (8 diffs)
-
src/UpdateSimple.c (modified) (2 diffs)
-
src/args.c (modified) (1 diff)
-
src/bcatalog.c (modified) (5 diffs)
-
src/fitpoly.c (modified) (8 diffs)
-
src/mkpolyterm.c (modified) (1 diff)
-
src/plot_scatter.c (modified) (1 diff)
-
src/plotstuff.c (modified) (1 diff)
-
src/relastro.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/dvo-mods-2007-02/Ohana/src/relastro/Makefile
r11880 r12220 21 21 22 22 RELASTRO = \ 23 $(SRC)/relastro.$(ARCH).o \24 $(SRC)/initialize.$(ARCH).o \25 23 $(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 \ 38 29 $(SRC)/ImageOps.$(ARCH).o \ 39 30 $(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 \ 40 43 $(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 \ 41 49 $(SRC)/plot_scatter.$(ARCH).o \ 42 50 $(SRC)/plotstuff.$(ARCH).o \ 43 $(SRC)/ misc.$(ARCH).o\51 $(SRC)/relastro.$(ARCH).o \ 44 52 $(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 56 DROP = \ 48 57 $(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 54 59 55 60 $(RELASTRO): $(INC)/relastro.h -
branches/dvo-mods-2007-02/Ohana/src/relastro/include/relastro.h
r12206 r12220 4 4 # include <signal.h> 5 5 6 typedef 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 6 15 // structure to hold coordinate fitting terms 7 16 typedef struct { 8 17 int Npts; 9 18 int Nterms; 10 int Npower;11 19 int Norder; 20 int Nsums; 21 int Nelems; 22 double **sum; 12 23 double **xsum; 13 24 double **ysum; 14 15 double **vector; 16 double **matrix; 25 double **xfit; 26 double **yfit; 17 27 } CoordFit; 18 28 … … 28 38 double chisq; 29 39 int Nfit; 30 } PM fit;40 } PMFit; 31 41 32 42 typedef struct { … … 62 72 char CATFORMAT[16]; /* internal, elixir, loneos, panstarrs */ 63 73 char CameraConfig[256]; 74 char SKY_TABLE[256]; 75 int SKY_DEPTH; /** XXX EAM : depth of catalog tables, fix usage */ 64 76 65 77 double MAG_LIM; … … 108 120 enum {black, white, red, orange, yellow, green, blue, indigo, violet}; 109 121 122 int DophotSelect, DophotValue; 123 110 124 int TimeSelect; 111 125 time_t TSTART, TSTOP; 112 126 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 127 int FITTING_MODE; 128 enum {FIT_AVERAGE, FIT_PM_ONLY, FIT_PM_AND_PAR}; 129 130 SkyRegion UserPatch; 131 int UserPatchSelect; 132 133 int DoUpdateObjects; 134 int DoUpdateSimple; 135 int DoUpdateChips; 136 int DoUpdateMosaics; 120 137 121 138 /*** relphot prototypes ***/ … … 126 143 int *SelectRefMosaic PROTO((Mosaic **refmosaic, int *Nimage)); 127 144 int args PROTO((int argc, char **argv)); 128 int bcatalog PROTO((Catalog *subcatalog, Catalog *catalog , GSCRegion *fullregion));145 int bcatalog PROTO((Catalog *subcatalog, Catalog *catalog)); 129 146 void clean_images PROTO(()); 130 147 void clean_measures PROTO((Catalog *catalog, int Ncatalog, int final)); … … 171 188 void initstats PROTO((char *mode)); 172 189 int 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)); 190 Catalog *load_catalogs PROTO((SkyList *skylist, int *Ncatalog)); 191 SkyList *load_images PROTO((FITS_DB *db, char *regionName, SkyRegion *region, int RegionSelect)); 192 Image *select_images PROTO((SkyList *skylist, Image *timage, int Ntimage, int **LineNumber, int *Nimage)); 175 193 176 194 void check_permissions (char *basefile); … … 195 213 void plot_star_coords PROTO((Catalog *catalog, int Ncatalog)); 196 214 void plot_stars PROTO((Catalog *catalog, int Ncatalog)); 197 void reload_catalogs PROTO(( GSCRegion *region, int Nregion, GSCRegion *fullregion));215 void reload_catalogs PROTO((SkyList *skylist)); 198 216 int setExclusions PROTO((Catalog *catalog, int Ncatalog)); 199 217 void setMcal PROTO((Catalog *catalog, int Poor)); … … 226 244 void wimages PROTO(()); 227 245 void write_coords PROTO((Header *header, Coords *coords)); 246 247 248 double **array_init (int Nx, int Ny); 249 void array_free (double **array, int Nx); 250 CoordFit *fit_init (int order); 251 void fit_free (CoordFit *fit); 252 void fit_add (CoordFit *fit, double x1, double y1, double x2, double y2, double wt); 253 void fit_eval (CoordFit *fit); 254 double **poly2d_dx (double **poly, int Nx, int Ny); 255 double **poly2d_dy (double **poly, int Nx, int Ny); 256 double **poly2d_copy (double **poly, int Nx, int Ny); 257 double poly2d_eval (double **poly, int Nx, int Ny, double x, double y); 258 void fit_apply_coords (CoordFit *fit, Coords *coords); 259 int CoordsGetCenter (CoordFit *fit, double tol, double *xo, double *yo); 260 CoordFit *CoordsSetCenter (CoordFit *input, double Xo, double Yo); 261 void FitChip (StarData *raw, StarData *ref, int Nmatch, Coords *coords); 262 void FitMosaic (StarData *raw, StarData *ref, int Nmatch, Coords *coords); 263 void FitSimple (StarData *raw, StarData *ref, int Nmatch, Coords *coords); 264 void initObjectData (Catalog *catalog, int Ncatalog); 265 int UpdateObjects (Catalog *catalog, int Ncatalog); 266 int UpdateSimple (Catalog *catalog, int Ncatalog); 267 int UpdateChips (Catalog *catalog, int Ncatalog); 268 int UpdateMosaic (Catalog *catalog, int Ncatalog); 269 int sun_ecliptic (double jd, double *lambda, double *beta, double *epsilon); 270 int ParFactor (double *pR, double *pD, double R, double D, time_t T); 271 int FitPM (PMFit *fit, double *X, double *dX, double *Y, double *dY, time_t *T, int Npts); 272 int FitPMandPar (PMFit *fit, double *X, double *dX, double *Y, double *dY, time_t *T, double *pR, double *pD, int Npts); 273 274 Coords *getMosaicForImage (int N); 275 276 StarData *getImageRef (Catalog *catalog, int Ncatalog, int im, int *Nstars, int isMosaic); 277 StarData *getImageRaw (Catalog *catalog, int Ncatalog, int im, int *Nstars, int isMosaic); 278 279 double getMeanR (Measure *measure, Average *average, SecFilt *secfilt); 280 double getMeanD (Measure *measure, Average *average, SecFilt *secfilt); -
branches/dvo-mods-2007-02/Ohana/src/relastro/src/FitMosaic.c
r12205 r12220 4 4 5 5 int i; 6 CoordFit *fit; 6 7 7 fit _init (coords[0].Npolyterms);8 fit = fit_init (coords[0].Npolyterms); 8 9 for (i = 0; i < Nmatch; i++) { 9 10 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); 11 12 } 12 fit_eval (); 13 fit_apply_coords (coords); 13 fit_eval (fit); 14 fit_apply_coords (fit, coords); 15 fit_free (fit); 14 16 /* FitChip and FitSimple update the coords in different ways? maybe not... */ 15 17 } -
branches/dvo-mods-2007-02/Ohana/src/relastro/src/FitPM.c
r12068 r12220 2 2 3 3 /* 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) { 4 int FitPM (PMFit *fit, double *X, double *dX, double *Y, double *dY, time_t *T, int Npts) { 5 6 int i; 5 7 6 8 double **A, **B; 9 double wx, wy, Wx, Wy, Tx, Ty, Tx2, Ty2, Xs, Ys, XT, YT; 7 10 8 11 /* 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); 17 14 15 Wx = Wy = Tx = Ty = Tx2 = Ty2 = Xs = Ys = XT = YT = 0.0; 18 16 for (i = 0; i < Npts; i++) { 19 17 /* handle case where dX or dY = 0.0 */ … … 56 54 dgaussj (A, 4, B, 1); 57 55 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]; 62 60 fit[0].p = 0.0; 63 61 … … 68 66 fit[0].dp = 0.0; 69 67 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); 76 70 77 71 return (TRUE); -
branches/dvo-mods-2007-02/Ohana/src/relastro/src/FitPMandPar.c
r12068 r12220 2 2 3 3 /* 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) { 4 int FitPMandPar (PMFit *fit, double *X, double *dX, double *Y, double *dY, time_t *T, double *pR, double *pD, int Npts) { 5 6 int i; 5 7 6 8 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; 7 11 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); 16 14 15 PR = PD = PRT = PDT = PRX = PDY = PR2 = PD2 = 0.0; 16 Wx = Wy = Tx = Ty = Tx2 = Ty2 = Xs = Ys = XT = YT = 0.0; 17 17 for (i = 0; i < Npts; i++) { 18 18 /* handle case where dX or dY = 0.0 */ … … 78 78 dgaussj (A, 5, B, 1); 79 79 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]; 85 85 86 86 fit[0].dRo = sqrt(A[0][0]); … … 90 90 fit[0].dp = sqrt(A[4][4]); 91 91 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); 98 94 99 95 /* get the chisq from the matrix values */ -
branches/dvo-mods-2007-02/Ohana/src/relastro/src/FitSimple.c
r12205 r12220 4 4 5 5 int i; 6 CoordFit *fit; 6 7 7 fit _init (coords[0].Npolyterms);8 fit = fit_init (coords[0].Npolyterms); 8 9 for (i = 0; i < Nmatch; i++) { 9 10 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); 11 12 } 12 fit_eval (); 13 fit_apply_coords (coords); 13 fit_eval (fit); 14 fit_apply_coords (fit, coords); 15 fit_free (fit); 14 16 } 15 17 -
branches/dvo-mods-2007-02/Ohana/src/relastro/src/ImageOps.c
r12205 r12220 94 94 void matchImage (Catalog *catalog, int meas, int cat) { 95 95 96 int i, ave, ccdnum; 97 double ra, dec, X, Y; 98 char *pname, *filter, *p, base[256]; 96 int i; 99 97 Measure *measure; 100 98 … … 178 176 } 179 177 180 StarData *getImageRaw (int im, int *Nstars, int isMosaic) { 181 178 /* XXX re-write to use image->nstars if that is possible */ 179 StarData *getImageRaw (Catalog *catalog, int Ncatalog, int im, int *Nstars, int isMosaic) { 180 181 int i, m, c; 182 183 Coords *mosaic; 182 184 StarData *raw; 183 185 184 186 ALLOCATE (raw, StarData, Nlist[im]); 185 187 188 mosaic = NULL; 186 189 if (isMosaic) { 187 190 mosaic = getMosaicForImage (im); … … 202 205 XY_to_LM (&raw[i].L, &raw[i].M, raw[i].X, raw[i].Y, &image[im].coords); 203 206 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); 206 209 } else { 207 210 raw[i].P = raw[i].L; … … 215 218 } 216 219 217 StarData *getImageRef (int im, int *Nstars, int isMosaic) { 218 220 StarData *getImageRef (Catalog *catalog, int Ncatalog, int im, int *Nstars, int isMosaic) { 221 222 int i, m, c, n; 223 224 Coords *mosaic; 219 225 StarData *ref; 220 226 221 227 ALLOCATE (ref, StarData, Nlist[im]); 222 228 229 mosaic = NULL; 223 230 if (isMosaic) { 224 231 mosaic = getMosaicForImage (im); … … 237 244 RD_to_LM (&ref[i].P, &ref[i].Q, ref[i].R, ref[i].D, &image[im].coords); 238 245 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); 241 248 } else { 242 249 ref[i].L = ref[i].P; -
branches/dvo-mods-2007-02/Ohana/src/relastro/src/ParFactor.c
r12068 r12220 28 28 int sun_ecliptic (double jd, double *lambda, double *beta, double *epsilon) { 29 29 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 */ 31 33 32 34 n = jd - J2000; … … 43 45 44 46 double jd; 45 double L, B ;47 double L, B, E, e, s, r, d; 46 48 47 49 /* 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 28 28 if (catalog[cat].average[ave].code & STAR_BAD) return (NO_MAG); 29 29 30 value = PhotPrimary ? catalog[cat].average[ave].M :catalog[cat].secfilt[PhotNsec*ave+PhotSec].M;30 value = catalog[cat].secfilt[PhotNsec*ave+PhotSec].M; 31 31 return (value); 32 32 } … … 65 65 liststats (list, dlist, N, &stats); 66 66 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; 76 70 } 77 71 } … … 121 115 122 116 /* 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; 132 120 } 133 121 } … … 183 171 for (j = 0; j < catalog[i].Naverage; j++) { 184 172 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; 186 174 if (Xm == -1) continue; 187 175 Chisq = pow (10.0, 0.01*Xm); 188 176 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; 190 178 dlist[Ntot] = 1; 191 179 Ntot ++; … … 203 191 for (i = 0; i < Ncatalog; i++) { 204 192 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; 207 195 Chisq = pow (10.0, 0.01*Xm); 208 196 mark = (dM > MaxScatter) || (Xm == NO_MAG) || (Chisq > MaxChisq); … … 387 375 if (catalog[i].average[j].code & STAR_BAD) continue; 388 376 389 Xm = PhotPrimary ? catalog[i].average[j].Xm :catalog[i].secfilt[PhotNsec*j+PhotSec].Xm;377 Xm = catalog[i].secfilt[PhotNsec*j+PhotSec].Xm; 390 378 if (Xm == NO_MAG) continue; 391 379 list[n] = pow (10.0, 0.01*Xm); … … 423 411 if (catalog[i].average[j].code & STAR_BAD) continue; 424 412 425 dM = PhotPrimary ? catalog[i].average[j].dM :catalog[i].secfilt[PhotNsec*j+PhotSec].dM;413 dM = catalog[i].secfilt[PhotNsec*j+PhotSec].dM; 426 414 list[n] = dM; 427 415 dlist[n] = 1; … … 452 440 for (j = 0; j < catalog[i].Naverage; j++) { 453 441 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; 455 443 bin = dMrel / 0.00025; 456 444 bin = MAX (0, MIN (NBIN-1, bin)); … … 483 471 for (j = 0; j < catalog[i].Naverage; j++) { 484 472 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; 487 475 if (value == NO_MAG) continue; 488 476 ylist[N] = 0.01*value; -
branches/dvo-mods-2007-02/Ohana/src/relastro/src/UpdateChips.c
r12205 r12220 1 1 # include "relastro.h" 2 2 3 int UpdateChips ( ) {3 int UpdateChips (Catalog *catalog, int Ncatalog) { 4 4 5 5 /* we can measure new image parameters for each non-mosaic chip independently */ 6 6 int i, Nimage, Nstars; 7 7 Image *image; 8 int Nimage;8 StarData *raw, *ref; 9 9 10 10 image = getimages (&Nimage); … … 18 18 19 19 /* convert measure coordinates to raw entries */ 20 raw = getImageRaw ( &image[i], &Nstars, TRUE);20 raw = getImageRaw (catalog, Ncatalog, i, &Nstars, TRUE); 21 21 22 22 /* convert average coordinates to ref entries */ 23 ref = getImageRef ( &image[i], &Nstars, TRUE);23 ref = getImageRef (catalog, Ncatalog, i, &Nstars, TRUE); 24 24 25 25 /* XXX grab this code from mosastro */ -
branches/dvo-mods-2007-02/Ohana/src/relastro/src/UpdateMosaic.c
r12205 r12220 1 1 # include "relastro.h" 2 2 3 int UpdateMosaic ( ) {3 int UpdateMosaic (Catalog *catalog, int Ncatalog) { 4 4 5 5 /* we can measure new image parameters for each mosaic independently */ 6 6 int i, Nimage, Nstars; 7 7 Image *image; 8 int Nimage;8 StarData *raw, *ref; 9 9 10 10 image = getimages (&Nimage); … … 18 18 19 19 /* convert measure coordinates to raw entries */ 20 raw = getImageRaw ( &image[i], &Nstars, TRUE);20 raw = getImageRaw (catalog, Ncatalog, i, &Nstars, TRUE); 21 21 22 22 /* convert average coordinates to ref entries */ 23 ref = getImageRef ( &image[i], &Nstars, TRUE);23 ref = getImageRef (catalog, Ncatalog, i, &Nstars, TRUE); 24 24 25 25 /* XXX grab this code from mosastro */ -
branches/dvo-mods-2007-02/Ohana/src/relastro/src/UpdateObjects.c
r12068 r12220 6 6 static double *R, *dR; 7 7 static double *D, *dD; 8 static double *pX; 9 static double *pY; 8 10 static time_t *T; 9 11 static double *dT; … … 25 27 ALLOCATE (X, double, MAX (1, Nmax)); 26 28 ALLOCATE (Y, double, MAX (1, Nmax)); 27 ALLOCATE (pR, double, MAX (1, Nmax));28 ALLOCATE (pD, double, MAX (1, Nmax));29 29 30 30 ALLOCATE (dR, double, MAX (1, Nmax)); … … 33 33 ALLOCATE (dX, double, MAX (1, Nmax)); 34 34 ALLOCATE (dY, double, MAX (1, Nmax)); 35 36 ALLOCATE (pX, double, MAX (1, Nmax)); 37 ALLOCATE (pY, double, MAX (1, Nmax)); 35 38 } 36 39 … … 38 41 39 42 int i, j, k, m, N; 40 float chisq;41 43 StatType statsR, statsD; 42 44 Coords coords; … … 88 90 89 91 /* project all of the R,D coordinates to a plane centered on this coordinate */ 90 /* calculate pR[i], pD[i] for each point */91 92 for (k = 0; k < N; k++) { 92 93 RD_to_XY (&X[k], &Y[k], R[k], D[k], &coords); … … 100 101 101 102 fit.Ro = statsR.mean; 102 fit.dR = statsR.sigma;103 fit.dRo = statsR.sigma; 103 104 104 105 fit.Do = statsD.mean; 105 fit.dD = statsD.sigma;106 fit.dDo = statsD.sigma; 106 107 107 108 fit.chisq = 0.5*(statsR.chisq + statsD.chisq); … … 117 118 ParFactor (&pX[k], &pY[k], R[k], D[k], T[k]); 118 119 } 119 FitPMandPar (&fit, X, dX, Y, dY, T, p R, pD, N);120 FitPMandPar (&fit, X, dX, Y, dY, T, pX, pY, N); 120 121 break; 121 122 default: … … 137 138 catalog[i].average[j].dP = fit.dp; 138 139 139 catalog[i].average[j].Xp = (fit.N pts> 1) ? 100.0*log10(fit.chisq) : NO_MAG;140 catalog[i].average[j].Xp = (fit.Nfit > 1) ? 100.0*log10(fit.chisq) : NO_MAG; 140 141 } 141 142 } -
branches/dvo-mods-2007-02/Ohana/src/relastro/src/UpdateSimple.c
r12205 r12220 1 1 # include "relastro.h" 2 2 3 int UpdateSimple ( ) {3 int UpdateSimple (Catalog *catalog, int Ncatalog) { 4 4 5 5 /* we can measure new image parameters for each non-mosaic chip independently */ 6 6 int i, Nimage, Nstars; 7 7 Image *image; 8 int Nimage;8 StarData *raw, *ref; 9 9 10 10 image = getimages (&Nimage); … … 19 19 20 20 /* convert measure coordinates to raw entries */ 21 raw = getImageRaw ( &image[i], &Nstars, FALSE);21 raw = getImageRaw (catalog, Ncatalog, i, &Nstars, FALSE); 22 22 23 23 /* convert average coordinates to ref entries */ 24 ref = getImageRef ( &image[i], &Nstars, FALSE);24 ref = getImageRef (catalog, Ncatalog, i, &Nstars, FALSE); 25 25 26 26 /* XXX grab this code from mosastro */ -
branches/dvo-mods-2007-02/Ohana/src/relastro/src/args.c
r12048 r12220 174 174 175 175 /* possible operations */ 176 UpdateObjects = FALSE;176 DoUpdateObjects = FALSE; 177 177 if ((N = get_argument (argc, argv, "-update-objects"))) { 178 178 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; 185 203 } 186 204 -
branches/dvo-mods-2007-02/Ohana/src/relastro/src/bcatalog.c
r12048 r12220 19 19 if (catalog[0].average[i].Nm < 2) continue; 20 20 21 /* XXX this limitation is absurd22 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 28 21 /* start with all stars good */ 29 22 subcatalog[0].average[Naverage] = catalog[0].average[i]; … … 34 27 35 28 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? 41 30 subcatalog[0].average[Naverage].code &= ~ID_STAR_FEW; 42 31 subcatalog[0].average[Naverage].code &= ~ID_STAR_POOR; … … 59 48 60 49 /* select measurements by quality */ 61 if ( catalog[0].measure[offset].dophot != 1) continue;50 if (DophotSelect && (catalog[0].measure[offset].dophot != DophotValue)) continue; 62 51 63 52 /* select measurements by mag limit */ … … 66 55 67 56 /* 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; 69 58 70 59 /* select measurements by mag limit */ … … 111 100 subcatalog[0].Nsecfilt = catalog[0].Nsecfilt; 112 101 102 // XXX really do this or not??? 113 103 if (catalog[0].Naverage > 0) free (catalog[0].average); 114 104 if (catalog[0].Nmeasure > 0) free (catalog[0].measure); -
branches/dvo-mods-2007-02/Ohana/src/relastro/src/fitpoly.c
r12219 r12220 12 12 */ 13 13 14 double **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 27 void 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 14 37 // XXX define a fit structure and drop the file static variables? 15 38 CoordFit *fit_init (int order) { 16 39 17 int i;40 CoordFit *fit; 18 41 19 42 ALLOCATE (fit, CoordFit, 1); … … 29 52 // xsum[i][j] holds \sum (x2 wt x1^i y1^j) 30 53 // 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); 39 61 40 62 // 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 56 65 return (fit); 57 66 } 58 67 68 void 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 59 80 // XXX use implicit masks as below or explicit masks (with function to set?) 60 81 // XXX eg, add a global mask to this file and … … 84 105 void fit_eval (CoordFit *fit) { 85 106 86 int i, j, n, m, M, N; 107 int i, j, ix, iy, jx, jy; 108 double **matrix, **vector; 87 109 88 110 if (fit[0].Npts == 0) { 89 111 fprintf (stderr, "warning: no valid pts\n"); 90 112 } 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); 91 117 92 118 /* remap the xsum,ysum terms into the vector */ … … 94 120 ix = i % fit[0].Nterms; 95 121 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]; 98 124 99 125 for (j = 0; j < fit[0].Nelems; j++) { 100 126 jx = j % fit[0].Nterms; 101 127 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); 107 133 108 134 for (i = 0; i < fit[0].Nelems; i++) { … … 112 138 ix, iy, vector[i][0], ix, iy, vector[i][1]); 113 139 } 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 154 double **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 174 double **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 194 double **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 210 double 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); 114 227 } 115 228 … … 119 232 void fit_apply_coords (CoordFit *fit, Coords *coords) { 120 233 121 int i, j, Np, Nv, N;122 234 double c11, c12; 123 235 double c21, c22; 124 double R; 236 double Xo, Yo, R; 237 CoordFit *modfit; 125 238 126 239 /* I have L,M = fit(X,Y). set corresponding terms for coords */ … … 129 242 // L = pc1_1*cd1*(x - cp1) + pc1_2*cd2*(y - cp2) + ... 130 243 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); 136 250 137 251 // 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]; 140 256 141 257 // 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]; 150 276 151 277 /* we do not modify crval1,2: these are kept at the default values */ … … 164 290 coords[0].pc2_2 = c22*R; 165 291 292 fit_free (modfit); 166 293 /* keep the order and type from initial values */ 167 294 } 168 295 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" 2 2 3 fit_to_coordterms (Coords *coords, CoordFit *fit, int nx, int ny) {3 double factorial (int N) { 4 4 5 int nsum; 5 int i; 6 double F; 6 7 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; 34 11 } 35 fprintf (stderr, "programming error %s:%d\n", __func__, __line__); 36 exit (2); 12 return F; 37 13 } 38 14 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)) ? 43 16 44 17 // given a 2D transformation -- L(x,y),M(x,y) -- find the coordinates x,y 45 18 // for which L,M = 0,0. tol is the allowed error on x,y. 46 psPlane *psPlaneTransformGetCenter (psPlaneTransform *trans, double tol) 47 { 19 int CoordsGetCenter (CoordFit *fit, double tol, double *xo, double *yo) { 48 20 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; 54 25 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; 59 28 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; 62 34 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; 65 37 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); 77 44 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); 80 47 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); 82 59 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]); 93 68 } 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; 99 79 } 100 80 101 81 // convert a transformation L(x,y) to L'(x-xo,y-yo) 102 psPlaneTransform *psPlaneTransformSetCenter (psPlaneTransform *output, psPlaneTransform *input, double Xo, double Yo) 103 { 82 CoordFit *CoordsSetCenter (CoordFit *input, double Xo, double Yo) { 104 83 105 // validate fit order 84 int i, j, Nx, Ny; 85 double **xPx, **yPx, **xPy, **yPy, **tmp; 106 86 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 --; 109 124 } 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); 146 138 } 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;158 139 } 159 N += m; 160 return (N); 140 return output; 161 141 } 162 142 163 143 /* 164 coords uses an odd,rigid sequence for the coefficients:144 Coords uses a rigid sequence for the coefficients: 165 145 166 146 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 32 32 if ((Mgrid = getMgrid (m, i)) == NO_MAG) continue; 33 33 34 Mrel = PhotPrimary ? catalog[i].average[j].M :catalog[i].secfilt[PhotNsec*j+PhotSec].M;34 Mrel = catalog[i].secfilt[PhotNsec*j+PhotSec].M; 35 35 xlist[N] = Mrel; 36 36 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 49 49 if (Xgraph[N] == 0) return; 50 50 51 KiiPS (Xgraph[N], TRUE, KAPA_ NEWPLOT, filename);51 KiiPS (Xgraph[N], TRUE, KAPA_PS_NEWPLOT, filename, "default"); 52 52 return; 53 53 } -
branches/dvo-mods-2007-02/Ohana/src/relastro/src/relastro.c
r12068 r12220 3 3 int main (int argc, char **argv) { 4 4 5 int i,status, Ncatalog;5 int status, Ncatalog; 6 6 Catalog *catalog; 7 7 FITS_DB db; … … 43 43 44 44 /* major modes */ 45 if ( UpdateObjects) {45 if (DoUpdateObjects) { 46 46 UpdateObjects (catalog, Ncatalog); 47 47 } 48 if ( UpdateSimple) {49 UpdateSimple ( );48 if (DoUpdateSimple) { 49 UpdateSimple (catalog, Ncatalog); 50 50 } 51 if ( UpdateChips) {52 UpdateChips ( );51 if (DoUpdateChips) { 52 UpdateChips (catalog, Ncatalog); 53 53 } 54 if ( UpdateMosaics) {55 UpdateMosaic s ();54 if (DoUpdateMosaics) { 55 UpdateMosaic (catalog, Ncatalog); 56 56 } 57 57
Note:
See TracChangeset
for help on using the changeset viewer.
