Changeset 27840 for branches/simtest_nebulous_branches/Ohana/src/relastro
- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 29 edited
- 2 copied
-
. (modified) (1 prop)
-
Ohana (modified) (1 prop)
-
Ohana/src/relastro (modified) (1 prop)
-
Ohana/src/relastro/Makefile (modified) (1 diff)
-
Ohana/src/relastro/doc/notes.txt (modified) (1 diff)
-
Ohana/src/relastro/include/relastro.h (modified) (12 diffs)
-
Ohana/src/relastro/src/ConfigInit.c (modified) (1 diff)
-
Ohana/src/relastro/src/CoordOps.c (copied) (copied from trunk/Ohana/src/relastro/src/CoordOps.c )
-
Ohana/src/relastro/src/FitChip.c (modified) (4 diffs)
-
Ohana/src/relastro/src/FitSimple.c (modified) (1 diff)
-
Ohana/src/relastro/src/FixProblemImages.c (copied) (copied from trunk/Ohana/src/relastro/src/FixProblemImages.c )
-
Ohana/src/relastro/src/GetAstromError.c (modified) (1 diff)
-
Ohana/src/relastro/src/ImageOps.c (modified) (19 diffs)
-
Ohana/src/relastro/src/MosaicOps.c (modified) (10 diffs)
-
Ohana/src/relastro/src/ParFactor.c (modified) (2 diffs)
-
Ohana/src/relastro/src/UpdateChips.c (modified) (2 diffs)
-
Ohana/src/relastro/src/UpdateMeasures.c (modified) (1 diff)
-
Ohana/src/relastro/src/UpdateMosaic.c (modified) (1 diff)
-
Ohana/src/relastro/src/UpdateObjectOffsets.c (modified) (2 diffs)
-
Ohana/src/relastro/src/UpdateObjects.c (modified) (13 diffs)
-
Ohana/src/relastro/src/UpdateSimple.c (modified) (2 diffs)
-
Ohana/src/relastro/src/args.c (modified) (6 diffs)
-
Ohana/src/relastro/src/bcatalog.c (modified) (2 diffs)
-
Ohana/src/relastro/src/fitpoly.c (modified) (6 diffs)
-
Ohana/src/relastro/src/initialize.c (modified) (1 diff)
-
Ohana/src/relastro/src/load_images.c (modified) (1 diff)
-
Ohana/src/relastro/src/mkpolyterm.c (modified) (1 diff)
-
Ohana/src/relastro/src/plotstuff.c (modified) (1 diff)
-
Ohana/src/relastro/src/relastro.c (modified) (4 diffs)
-
Ohana/src/relastro/src/relastro_objects.c (modified) (1 diff)
-
Ohana/src/relastro/src/select_images.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/Ohana
-
Property svn:mergeinfo
set to (toggle deleted branches)
/trunk/Ohana merged eligible /branches/eam_branches/Ohana.20100407 27635-27772 /branches/pap_delete/Ohana 27530-27595
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/simtest_nebulous_branches/Ohana/src/relastro
-
Property svn:mergeinfo
set to (toggle deleted branches)
/trunk/Ohana/src/relastro merged eligible /branches/eam_branches/20091201/Ohana/src/relastro 26295-26885 /branches/eam_branches/Ohana.20100407/src/relastro 27635-27772 /branches/eam_branches/largefiles.20100314/Ohana/src/relastro 27281-27430 /branches/eam_branches/relastro.20100326 27487-27559 /branches/pap_delete/Ohana/src/relastro 27530-27595
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/simtest_nebulous_branches/Ohana/src/relastro/Makefile
r24308 r27840 56 56 $(SRC)/save_catalogs.$(ARCH).o \ 57 57 $(SRC)/write_coords.$(ARCH).o \ 58 $(SRC)/CoordOps.$(ARCH).o \ 59 $(SRC)/FixProblemImages.$(ARCH).o \ 58 60 $(SRC)/relastroVisual.$(ARCH).o 59 61 -
branches/simtest_nebulous_branches/Ohana/src/relastro/doc/notes.txt
r17043 r27840 1 2 2010.03.24 3 4 I have finished only part of the optimizations listed below: I have 5 made the detection->image and image->mosaic lookups use bracket 6 searches. I have NOT converted the image->mosaic lookups to use the 7 parentID, so these matches are still based on time ranges. I have 8 also added a bit of positional constraint to the image match 9 function in 'select_images' (comparing Rmax of the sky regions to 10 Rmin of the images). These have had a huge improvement. Here is 11 the execution time for the SAS data (~450 images) with the old vs 12 the new code on pikake: 13 14 old : 39min 15 new : 7min 16 17 The bulk of the time for the new code is now disk I/O. 18 19 2010.03.23 20 21 I've been working on optimization. I've updated ImageOps to make 22 the measure->image relationship generation use the image IDs along 23 with a bracket search -- this goes much faster as a result. More 24 work is needed: 25 26 * select_images needs to apply astrometry to all image corners: 27 -> cache the image center and radius and use this to narrow down 28 the searches. 29 30 * MosaicOps uses the time to match mosaics. I've added sorting to 31 speed this up, but this should be done based on the image and 32 parent index. 33 34 -> make a tool to create the parent ID for existing DBs. 35 -> make sure addstar is populating the parent IDs 36 -> use the parent IDs to make the link. 37 38 load image data: 0.006347 sec 39 setup sky: 0.091475 sec 40 convert image table: 0.091498 sec 41 select images: 2.925978 sec 42 init images: 2.926957 sec 43 init mosaics: 2.927319 sec 44 load images: 2.933762 sec 45 load catalog data: 9.772259 sec 46 make image bins: 9.780618 sec 47 set up image indexes: 10.196519 sec 48 49 load image data: 0.006746 sec 50 setup sky: 0.091440 sec 51 convert image table: 0.091467 sec 52 select images: 0.374193 sec 53 init images: 0.375355 sec 54 init mosaics: 0.375753 sec 55 load images: 0.382606 sec 56 load catalog data: 7.260094 sec 57 make image bins: 7.268564 sec 58 set up image indexes: 7.687485 sec 59 1 60 2 61 2008.03.01 -
branches/simtest_nebulous_branches/Ohana/src/relastro/include/relastro.h
r24308 r27840 91 91 92 92 int VERBOSE; 93 int VERBOSE2; 93 94 94 95 int RESET; 96 int NLOOP; 95 97 int UPDATE; 96 98 int PLOTSTUFF; … … 104 106 int CHIPORDER; 105 107 108 int UserCatalog; 109 double UserCatalogRA, UserCatalogDEC; 110 106 111 char *PHOTCODE_KEEP_LIST, *PHOTCODE_SKIP_LIST; 107 112 int NphotcodesKeep, NphotcodesSkip; … … 140 145 char *GetPhotnamebyCode PROTO((PhotCodeData *photcodes, int code)); 141 146 void InterpolateGrid PROTO((float *buffer, int Nx, int Ny, Coords *ccd, Coords *gcoords)); 142 int *SelectRefMosaic PROTO((Mosaic **refmosaic, int *Nimage));147 off_t *SelectRefMosaic PROTO((Mosaic **refmosaic, off_t *Nimage)); 143 148 int args PROTO((int argc, char **argv)); 144 149 int bcatalog PROTO((Catalog *subcatalog, Catalog *catalog)); … … 151 156 void dump_grid PROTO((void)); 152 157 int edge_check PROTO((double *x1, double *y1, double *x2, double *y2)); 153 void findImages PROTO((Catalog *catalog, int Ncatalog ));158 void findImages PROTO((Catalog *catalog, int Ncatalog, int MATCHCAT)); 154 159 int findMosaics PROTO((Catalog *catalog, int Ncatalog)); 155 Image *find_images PROTO((FITS_DB *db, GSCRegion *region, int Nregion, int *Nimage, int **LineNum));160 Image *find_images PROTO((FITS_DB *db, GSCRegion *region, off_t Nregion, off_t *Nimage, off_t **LineNum)); 156 161 void set_db (FITS_DB *in); 157 int Shutdown (char *format, ...) ;162 int Shutdown (char *format, ...) OHANA_FORMAT(printf, 1, 2); 158 163 void TrapSignal (int sig); 159 164 void SetProtect (int mode); 160 165 int SetSignals (void); 161 166 162 GSCRegion *find_regions PROTO((Image *image, int Nimage, int *Nregions, GSCRegion *fullregion));167 GSCRegion *find_regions PROTO((Image *image, off_t Nimage, int *Nregions, GSCRegion *fullregion)); 163 168 void freeGridBins PROTO((int Ncatalog)); 164 169 void freeImageBins PROTO((int Ncatalog)); … … 166 171 void free_catalogs PROTO((Catalog *catalog, int Ncatalog)); 167 172 int gcatalog PROTO((Catalog *catalog, int FINAL)); 168 Coords *getCoords PROTO((int meas, int cat));169 float getMcal PROTO(( int meas, int cat));170 float getMgrid PROTO(( int meas, int cat));171 float getMmos PROTO(( int meas, int cat));172 float getMrel PROTO((Catalog *catalog, int meas, int cat));173 GSCRegion *get_regions PROTO((double minRa, double maxRa, double minDec, double maxDec, int *Nregions));174 void getfullregion PROTO((Image *image, int Nimage, GSCRegion *fullregion));175 Image *getimage PROTO(( int N));176 Image *getimages PROTO(( int *N));173 // Coords *getCoords PROTO((off_t meas, int cat)); 174 float getMcal PROTO((off_t meas, int cat)); 175 float getMgrid PROTO((off_t meas, int cat)); 176 float getMmos PROTO((off_t meas, int cat)); 177 float getMrel PROTO((Catalog *catalog, off_t meas, int cat)); 178 GSCRegion *get_regions PROTO((double minRa, double maxRa, double minDec, double maxDec, off_t *Nregions)); 179 void getfullregion PROTO((Image *image, off_t Nimage, GSCRegion *fullregion)); 180 Image *getimage PROTO((off_t N)); 181 Image *getimages PROTO((off_t *N)); 177 182 void global_stats PROTO((Catalog *catalog, int Ncatalog)); 178 183 void initGrid PROTO((int dX, int dY)); 179 184 void initGridBins PROTO((Catalog *catalog, int Ncatalog)); 180 void initImageBins PROTO((Catalog *catalog, int Ncatalog ));181 void initImages PROTO((Image *input, int N));185 void initImageBins PROTO((Catalog *catalog, int Ncatalog, int FULLINIT)); 186 void initImages PROTO((Image *input, off_t N)); 182 187 void initMosaicBins PROTO((Catalog *catalog, int Ncatalog)); 183 void initMosaicGrid PROTO((Image *image, int Nimage));184 void initMosaics PROTO((Image *image, int Nimage));188 void initMosaicGrid PROTO((Image *image, off_t Nimage)); 189 void initMosaics PROTO((Image *image, off_t Nimage)); 185 190 void initMrel PROTO((Catalog *catalog, int Ncatalog)); 186 191 void initialize PROTO((int argc, char **argv)); … … 189 194 Catalog *load_catalogs PROTO((SkyList *skylist, int *Ncatalog, int subselect)); 190 195 SkyList *load_images PROTO((FITS_DB *db, SkyRegion *region)); 191 Image *select_images PROTO((SkyList *skylist, Image *timage, int Ntimage, int **LineNumber, int *Nimage));196 Image *select_images PROTO((SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage)); 192 197 193 198 void check_permissions (char *basefile); … … 198 203 199 204 int main PROTO((int argc, char **argv)); 200 void mark_images PROTO((Image *image, int Nimage, Image *timage, int Ntimage));201 void matchImage PROTO((Catalog *catalog, int meas, int cat));202 void matchMosaics PROTO((Catalog *catalog, int meas, int cat));203 GSCRegion *name_region PROTO((char *name, int *Nregions));205 void mark_images PROTO((Image *image, off_t Nimage, Image *timage, off_t Ntimage)); 206 void matchImage PROTO((Catalog *catalog, off_t meas, int cat, int MATCHCAT)); 207 void matchMosaics PROTO((Catalog *catalog, off_t meas, int cat)); 208 GSCRegion *name_region PROTO((char *name, off_t *Nregions)); 204 209 double opening_angle PROTO((double x1, double y1, double x2, double y2, double x3, double y3)); 205 210 void plot_chisq PROTO((Catalog *catalog, int Ncatalog)); … … 224 229 int setMrelOutput PROTO((Catalog *catalog, int Ncatalog, int mark)); 225 230 void set_ZP PROTO((double ZERO)); 226 int setrefcode PROTO((Image *image, int Nimage));231 int setrefcode PROTO((Image *image, off_t Nimage)); 227 232 void skip_measurements PROTO((Catalog *catalog, int pass)); 228 233 void sortA PROTO((double *X, int N)); … … 250 255 void fit_free (CoordFit *fit); 251 256 void fit_add (CoordFit *fit, double x1, double y1, double x2, double y2, double wt); 252 voidfit_eval (CoordFit *fit);257 int fit_eval (CoordFit *fit); 253 258 void fit_apply (CoordFit *fit, double *x2, double *y2, double x1, double y1); 254 259 double **poly2d_dx (double **poly, int Nx, int Ny); … … 256 261 double **poly2d_copy (double **poly, int Nx, int Ny); 257 262 double poly2d_eval (double **poly, int Nx, int Ny, double x, double y); 258 CoordFit *fit_apply_coords (CoordFit *fit, Coords *coords);263 int fit_apply_coords (CoordFit *fit, Coords *coords); 259 264 int CoordsGetCenter (CoordFit *fit, double tol, double *xo, double *yo); 260 265 CoordFit *CoordsSetCenter (CoordFit *input, double Xo, double Yo); 261 voidFitChip (StarData *raw, StarData *ref, int Nmatch, Coords *coords);266 int FitChip (StarData *raw, StarData *ref, int Nmatch, Coords *coords); 262 267 void FitMosaic (StarData *raw, StarData *ref, int Nmatch, Coords *coords); 263 268 void FitSimple (StarData *raw, StarData *ref, int Nmatch, Coords *coords); … … 268 273 int UpdateMosaic (Catalog *catalog, int Ncatalog); 269 274 int UpdateMeasures (Catalog *catalog, int Ncatalog); 270 void fixImageRaw (Catalog *catalog, int Ncatalog, int im);275 void fixImageRaw (Catalog *catalog, int Ncatalog, off_t im); 271 276 void FlagOutliers(Catalog *catalog); 272 277 int MeasFilterTest(Measure *measure); 273 278 274 279 int sun_ecliptic (double jd, double *lambda, double *beta, double *epsilon); 275 int ParFactor (double *pR, double *pD, double R, double D, time_t T);280 int ParFactor (double *pR, double *pD, double R, double D, double T, double Tmean); 276 281 int FitPM (PMFit *fit, double *X, double *dX, double *Y, double *dY, double *T, int Npts); 277 282 int FitPar (PMFit *fit, double *X, double *dX, double *Y, double *dY, double *pR, double *pD, int Npts); 278 283 int FitPMandPar (PMFit *fit, double *X, double *dX, double *Y, double *dY, double *T, double *pR, double *pD, int Npts); 279 284 280 Mosaic *getMosaicForImage ( int N);281 282 StarData *getImageRef (Catalog *catalog, int Ncatalog, int im, int *Nstars, CoordMode mode);283 StarData *getImageRaw (Catalog *catalog, int Ncatalog, int im, int *Nstars, CoordMode mode);284 285 Mosaic *getmosaics ( int *N);286 void initMosaics (Image *image, int Nimage);287 StarData *getMosaicRaw (Catalog *catalog, int Ncatalog, int mos, int *Nstars);288 StarData *getMosaicRef (Catalog *catalog, int Ncatalog, int mos, int *Nstars);289 Mosaic *getMosaicForImage ( int im);285 Mosaic *getMosaicForImage (off_t N); 286 287 StarData *getImageRef (Catalog *catalog, int Ncatalog, off_t im, off_t *Nstars, CoordMode mode); 288 StarData *getImageRaw (Catalog *catalog, int Ncatalog, off_t im, off_t *Nstars, CoordMode mode); 289 290 Mosaic *getmosaics (off_t *N); 291 void initMosaics (Image *image, off_t Nimage); 292 StarData *getMosaicRaw (Catalog *catalog, int Ncatalog, off_t mos, off_t *Nstars); 293 StarData *getMosaicRef (Catalog *catalog, int Ncatalog, off_t mos, off_t *Nstars); 294 Mosaic *getMosaicForImage (off_t im); 290 295 291 296 double getMeanR (Measure *measure, Average *average, SecFilt *secfilt); … … 297 302 int relastro_objects (void); 298 303 int UpdateObjectOffsets (SkyList *skylist); 304 305 int relastroVisualPlotRawRef(StarData *raw, StarData *ref, double dRmax, int numObj); 306 int relastroVisualPlotScatter(double values[], double thresh, int npts); 307 int relastroVisualPlotOutliers(Catalog *catalog, int offset, int Nmeasure, 308 StatType statsR, StatType statsD, double thresh); 309 310 311 312 int FixProblemImages (SkyList *skylist); 313 int *getCatlist (int *N, off_t im); 314 315 void initCoords (void); 316 void getOffsets (double *dPos, off_t *nPos, off_t N); 317 void saveOffsets (double dPos, off_t nPos, off_t N); 318 void setBadCoords (off_t N); 319 int badCoords (off_t N); 320 Coords *getCoords (off_t N); 321 int saveCoords (Coords *coords, off_t N); 322 void resetImageRaw (Catalog *catalog, int Ncatalog, off_t im); -
branches/simtest_nebulous_branches/Ohana/src/relastro/src/ConfigInit.c
r24308 r27840 60 60 /* update master photcode table if not defined */ 61 61 sprintf (CatdirPhotcodeFile, "%s/Photcodes.dat", CATDIR); 62 if (!LoadPhotcodes (CatdirPhotcodeFile, MasterPhotcodeFile )) {62 if (!LoadPhotcodes (CatdirPhotcodeFile, MasterPhotcodeFile, TRUE)) { 63 63 fprintf (stderr, "error loading photcode table %s or master file %s\n", CatdirPhotcodeFile, MasterPhotcodeFile); 64 64 exit (1); -
branches/simtest_nebulous_branches/Ohana/src/relastro/src/FitChip.c
r24308 r27840 17 17 // XXX save measurements of the fit quality (scatter, chisq) in the image table 18 18 19 voidFitChip (StarData *raw, StarData *ref, int Nmatch, Coords *coords) {19 int FitChip (StarData *raw, StarData *ref, int Nmatch, Coords *coords) { 20 20 21 21 int i, Nscatter, Niter, skip; … … 84 84 default: 85 85 fprintf (stderr, "invalid chip order %d\n", coords[0].Npolyterms); 86 abort ();86 skip = TRUE; 87 87 } 88 88 if (skip) { … … 90 90 fit_free (fit); 91 91 free (values); 92 return ;92 return FALSE; 93 93 } 94 94 95 fprintf (stderr, "scatter limit: %f based on %d detections; using %d of %d for fit\n", dRmax, Nscatter, fit[0].Npts, Nmatch);95 // fprintf (stderr, "scatter limit: %f based on %d detections; using %d of %d for fit\n", dRmax, Nscatter, fit[0].Npts, Nmatch); 96 96 97 97 // measure the fit, update the coords & object coordinates 98 fit_eval (fit); 99 fit_apply_coords (fit, coords); 98 if (!fit_eval (fit)) { 99 fprintf (stderr, "failed to fit new model\n"); 100 return FALSE; 101 } 102 103 if (!fit_apply_coords (fit, coords)) { 104 fprintf (stderr, "failed to fit new model\n"); 105 return FALSE; 106 } 107 100 108 fit_free (fit); 101 109 … … 107 115 108 116 free (values); 109 return ;117 return TRUE; 110 118 } 111 119 -
branches/simtest_nebulous_branches/Ohana/src/relastro/src/FitSimple.c
r16810 r27840 17 17 18 18 // XXX the value needs to be set in a more intelligent way 19 if (dR > 0. 15) continue;19 if (dR > 0.50) continue; 20 20 21 21 fit_add (fit, raw[i].X, raw[i].Y, ref[i].P, ref[i].Q, 1.0); -
branches/simtest_nebulous_branches/Ohana/src/relastro/src/GetAstromError.c
r24308 r27840 8 8 switch (mode) { 9 9 case ERROR_MODE_RA: 10 dPobs = measure[0].dXccd ; // need to redefine this as RAerr10 dPobs = measure[0].dXccd / 100.0; // need to redefine this as RAerr 11 11 break; 12 12 case ERROR_MODE_DEC: 13 dPobs = measure[0].dYccd ; // need to redefine this as RAerr13 dPobs = measure[0].dYccd / 100.0; // need to redefine this as RAerr 14 14 break; 15 15 case ERROR_MODE_POS: 16 dPobs = hypot (measure[0].dXccd, measure[0].dYccd) ; // need to redefine this as RAerr16 dPobs = hypot (measure[0].dXccd, measure[0].dYccd) / 100.0; // need to redefine this as RAerr 17 17 break; 18 18 default: -
branches/simtest_nebulous_branches/Ohana/src/relastro/src/ImageOps.c
r24308 r27840 1 1 # include "relastro.h" 2 #define TESTING 3 2 3 # define USE_IMAGE_ID 1 4 5 static off_t **bin; // link from catalog,measure to image 6 static int **clist; // catalog which supplied measurement on image 7 static off_t **mlist; // measure reference for measurement on image 8 static off_t *Nlist; // number of measurements on image 9 static off_t *NLIST; // allocated number of measurements on image 10 11 static Image *image; // list of available images 12 static off_t Nimage; // number of available images 13 14 static int *Ncatlist; // catalogs associated with each image 15 static int *NCATLIST; // catalogs associated with each image 16 static int **catlist; // catalogs associated with each image 17 18 // if we search by image ID, we sort (imageIDs, imageIdx) by imageIDs to get a sorted 19 // index 20 21 # if USE_IMAGE_ID 22 static off_t *imageIDs; // list of all image IDs 23 static off_t *imageIdx; // list of index for image IDs 24 # else 4 25 static unsigned int *start; 5 26 static unsigned int *stop; 6 static int **bin; 7 8 static int **clist; 9 static int **mlist; 10 static int *Nlist; 11 static int *NLIST; 12 13 static Image *image; 14 static int Nimage; 15 16 Image *getimages (int *N) { 27 # endif 28 29 Image *getimages (off_t *N) { 17 30 *N = Nimage; 18 31 return (image); 19 32 } 20 33 21 Image *getimage ( int N) {34 Image *getimage (off_t N) { 22 35 return (&image[N]); 23 36 } 24 37 25 void initImages (Image *input, int N) { 26 27 int i; 38 int *getCatlist (int *N, off_t im) { 39 40 *N = Ncatlist[im]; 41 return (catlist[im]); 42 } 43 44 void initImages (Image *input, off_t N) { 45 46 off_t i; 28 47 29 48 image = input; 30 49 Nimage = N; 31 50 32 ALLOCATE (start, unsigned, Nimage); 33 ALLOCATE (stop, unsigned, Nimage); 51 # if USE_IMAGE_ID 52 ALLOCATE (imageIDs, off_t, Nimage); 53 ALLOCATE (imageIdx, off_t, Nimage); 54 55 for (i = 0; i < Nimage; i++) { 56 imageIdx[i] = i; 57 imageIDs[i] = image[i].imageID; 58 } 59 llsortpair (imageIDs, imageIdx, Nimage); 60 # else 61 ALLOCATE (start, unsigned, Nimage); 62 ALLOCATE (stop, unsigned, Nimage); 34 63 35 64 for (i = 0; i < Nimage; i++) { … … 37 66 stop[i] = image[i].tzero + MAX(1.01*image[i].trate*image[i].NY, 1); 38 67 } 39 } 40 41 void initImageBins (Catalog *catalog, int Ncatalog) { 42 43 int i, j; 44 45 ALLOCATE (bin, int *, Ncatalog); 68 # endif 69 } 70 71 off_t getImageByID (off_t ID) { 72 73 // we have a pair of vectors (imageIDs, imageIdx) sorted by imageIDs 74 // use bisection to find the specified image ID 75 76 # if USE_IMAGE_ID 77 off_t Nlo, Nhi, N; 78 79 Nlo = 0; Nhi = Nimage; 80 while (Nhi - Nlo > 10) { 81 N = 0.5*(Nlo + Nhi); 82 if (imageIDs[N] < ID) { 83 Nlo = MAX(N, 0); 84 } else { 85 Nhi = MIN(N + 1, Nimage); 86 } 87 } 88 89 for (N = Nlo; N < Nhi; N++) { 90 if (imageIDs[N] == ID) 91 return (imageIdx[N]); 92 } 93 # endif 94 95 return (-1); 96 } 97 98 // these are really image & catalog indexes 99 void initImageBins (Catalog *catalog, int Ncatalog, int FULLINIT) { 100 101 off_t i, j; 102 103 ALLOCATE (bin, off_t *, Ncatalog); 46 104 for (i = 0; i < Ncatalog; i++) { 47 ALLOCATE (bin[i], int, MAX (catalog[i].Nmeasure, 1));105 ALLOCATE (bin[i], off_t, MAX (catalog[i].Nmeasure, 1)); 48 106 for (j = 0; j < catalog[i].Nmeasure; j++) bin[i][j] = -1; 49 107 } 50 108 51 ALLOCATE (Nlist, int,Nimage);52 ALLOCATE (NLIST, int,Nimage);53 ALLOCATE (clist, int *, Nimage);54 ALLOCATE (mlist, int *, Nimage);109 ALLOCATE (Nlist, off_t, Nimage); 110 ALLOCATE (NLIST, off_t, Nimage); 111 ALLOCATE (clist, int *, Nimage); 112 ALLOCATE (mlist, off_t *, Nimage); 55 113 56 114 for (i = 0; i < Nimage; i++) { 57 Nlist[i] = 0;115 Nlist[i] = 0; 58 116 NLIST[i] = 100; 59 117 ALLOCATE (clist[i], int, NLIST[i]); 60 ALLOCATE (mlist[i], int, NLIST[i]); 118 ALLOCATE (mlist[i], off_t, NLIST[i]); 119 } 120 121 if (FULLINIT) { 122 ALLOCATE (Ncatlist, int, Nimage); 123 ALLOCATE (NCATLIST, int, Nimage); 124 ALLOCATE (catlist, int *, Nimage); 125 126 for (i = 0; i < Nimage; i++) { 127 Ncatlist[i] = 0; 128 NCATLIST[i] = 32; 129 ALLOCATE (catlist[i], int, NCATLIST[i]); 130 } 61 131 } 62 132 } … … 64 134 void freeImageBins (int Ncatalog) { 65 135 66 int i;136 off_t i; 67 137 68 138 for (i = 0; i < Ncatalog; i++) { … … 79 149 80 150 /* match measurements to images */ 81 void findImages (Catalog *catalog, int Ncatalog ) {82 83 int i, j;151 void findImages (Catalog *catalog, int Ncatalog, int MATCHCAT) { 152 153 off_t i, j; 84 154 char *name; 85 155 86 156 for (i = 0; i < Ncatalog; i++) { 87 157 for (j = 0; j < catalog[i].Nmeasure; j++) { 88 matchImage (catalog, j, i); 89 } 90 } 91 92 for (i = 0; VERBOSE && (i < Nimage); i++) { 158 // XXX : update to optionally restrict by photcode equiv a la relphot 159 // ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[j].photcode); 160 // if (photcode[0].code != ecode) continue; 161 matchImage (catalog, j, i, MATCHCAT); 162 } 163 } 164 165 for (i = 0; VERBOSE2 && (i < Nimage); i++) { 93 166 name = GetPhotcodeNamebyCode (image[i].photcode); 94 fprintf (stderr, "image % d has %d measures (%s, %s)\n", i,Nlist[i],167 fprintf (stderr, "image %lld has %lld measures (%s, %s)\n", (long long) i, (long long) Nlist[i], 95 168 ohana_sec_to_date(image[i].tzero), name); 96 169 } 97 170 } 98 171 99 /* modify this function to use the measure->imageID field */ 100 void matchImage (Catalog *catalog, int meas, int cat) { 101 102 int i; 172 # if USE_IMAGE_ID 173 // this is the imageID-based match 174 void matchImage (Catalog *catalog, off_t meas, int cat, int MATCHCAT) { 175 176 off_t idx, ID; 177 Measure *measure; 178 int i, found; 179 180 measure = &catalog[cat].measure[meas]; 181 182 ID = measure[0].imageID; 183 idx = getImageByID (ID); 184 if (idx == -1) { 185 if (VERBOSE2) fprintf (stderr, "can't match detection to image?\n"); 186 return; 187 } 188 189 // index for (catalog, measure) -> image 190 bin[cat][meas] = idx; 191 192 // index for image, Nentry -> catalog 193 clist[idx][Nlist[idx]] = cat; 194 195 // index for image, Nentry -> measure 196 mlist[idx][Nlist[idx]] = meas; 197 Nlist[idx] ++; 198 199 if (Nlist[idx] == NLIST[idx]) { 200 NLIST[idx] += 100; 201 REALLOCATE (clist[idx], int, NLIST[idx]); 202 REALLOCATE (mlist[idx], off_t, NLIST[idx]); 203 } 204 205 if (MATCHCAT) { 206 // index for image -> catalog list 207 found = FALSE; 208 for (i = 0; !found && (i < Ncatlist[idx]); i++) { 209 if (catlist[idx][i] == cat) found = TRUE; 210 } 211 if (!found) { 212 catlist[idx][Ncatlist[idx]] = cat; 213 Ncatlist[idx] ++; 214 if (Ncatlist[idx] == NCATLIST[idx]) { 215 NCATLIST[idx] += 32; 216 REALLOCATE (catlist[idx], int, NCATLIST[idx]); 217 } 218 } 219 } 220 221 return; 222 } 223 224 # else 225 // this is the time-based match 226 void matchImage (Catalog *catalog, off_t meas, int cat, int MATCHCAT) { 227 228 off_t i; 103 229 Measure *measure; 104 230 … … 107 233 /* find the image that supplied this measurement */ 108 234 for (i = 0; i < Nimage; i++) { 235 // let's try the very slow method first before adding a bisection search 236 // if (image[i].imageID != measure[0].imageID) continue; 109 237 if (image[0].photcode == -1) continue; 110 238 if (measure[0].photcode != image[i].photcode) continue; … … 124 252 if (Nlist[i] == NLIST[i]) { 125 253 NLIST[i] += 100; 126 REALLOCATE (clist[i], int, NLIST[i]);127 REALLOCATE (mlist[i], int, NLIST[i]);254 REALLOCATE (clist[i], int, NLIST[i]); 255 REALLOCATE (mlist[i], off_t, NLIST[i]); 128 256 } 129 257 return; 130 258 } 131 } 132 133 Coords *getCoords (int meas, int cat) { 134 135 int i; 259 if (VERBOSE2) fprintf (stderr, "can't match detection to image?\n"); 260 return; 261 } 262 # endif 263 264 /* 265 Coords *getCoords (off_t meas, int cat) { 266 267 off_t i; 136 268 137 269 i = bin[cat][meas]; … … 139 271 return (&image[i].coords); 140 272 } 273 */ 141 274 142 275 void plot_images () { 143 276 144 int i, bin;277 off_t i, bin; 145 278 double *xlist, *Mlist, *dlist; 146 279 Graphdata graphdata; … … 188 321 // return StarData values for detections in the specified image, converting coordinates from the 189 322 // chip positions: X,Y -> L,M -> P,Q -> R,D 190 void fixImageRaw (Catalog *catalog, int Ncatalog, int im) {191 192 int i, m, c, n;323 void fixImageRaw (Catalog *catalog, int Ncatalog, off_t im) { 324 325 off_t i, m, c, n, nPos; 193 326 double X, Y, L, M, P, Q, R, D, dR, dD; 327 double dPos; 194 328 195 329 Mosaic *mosaic; 196 330 Coords *moscoords, *imcoords; 197 331 332 // check if this image is bad and should be skipped 333 if (badCoords(im)) return; 334 335 // WRP images need to have an associated mosaic 198 336 moscoords = NULL; 199 mosaic = getMosaicForImage (im); 200 if (mosaic != NULL) { 201 moscoords = &mosaic[0].coords; 337 if (!strcmp(&image[im].coords.ctype[4], "-WRP")) { 338 mosaic = getMosaicForImage (im); 339 if (mosaic == NULL) return; // if we cannot find the associated image, skip it 340 moscoords = &mosaic[0].coords; 202 341 } 203 342 imcoords = &image[im].coords; 343 344 // accumulate the rms position offsets. if this value, or any specific entry, is too 345 // large, we will reset the image to the original coords at the end of the analysis 346 347 dPos = 0.0; 348 nPos = 0; 204 349 205 350 for (i = 0; i < Nlist[im]; i++) { … … 226 371 dD = 3600.0*(catalog[c].average[n].D - D); 227 372 228 if (fabs(catalog[c].measure[m].dR - dR) > 10.0) { 229 // XXXXX running into this still for last megacam exposure: wrong mosaic? 230 // ???? inconsistently hitting this???? 373 // complain if the new location is far from the average location 374 if (fabs(dR) > 2.0) { 231 375 fprintf (stderr, "!"); 232 // abort (); 233 } 234 if (fabs(catalog[c].measure[m].dD - dD) > 10.0) { 376 setBadCoords (im); // report a failure for this image 377 return; 378 } 379 if (fabs(dD) > 2.0) { 235 380 fprintf (stderr, "*"); 236 // abort (); 237 } 381 setBadCoords (im); // report a failure for this image 382 return; 383 } 384 385 // complain if the new location is far from the old location 386 if (fabs(catalog[c].measure[m].dR - dR) > 2.0) { 387 fprintf (stderr, "@"); 388 setBadCoords (im); // report a failure for this image 389 return; 390 } 391 if (fabs(catalog[c].measure[m].dD - dD) > 2.0) { 392 fprintf (stderr, "#"); 393 setBadCoords (im); // report a failure for this image 394 return; 395 } 396 397 dPos += SQ(catalog[c].measure[m].dR - dR) + SQ(catalog[c].measure[m].dD - dD); 398 nPos ++; 238 399 239 400 catalog[c].measure[m].dR = dR; … … 251 412 } 252 413 } 414 415 saveOffsets (dPos, nPos, im); 416 417 return; 418 } 419 420 // return StarData values for detections in the specified image, converting coordinates from the 421 // chip positions: X,Y -> L,M -> P,Q -> R,D 422 void resetImageRaw (Catalog *catalog, int Ncatalog, off_t im) { 423 424 off_t i, m, c, n; 425 double X, Y, L, M, P, Q, R, D, dR, dD; 426 427 Mosaic *mosaic; 428 Coords *moscoords, *imcoords, *oldcoords; 429 430 // check if this image is bad and should be skipped 431 if (!badCoords(im)) { 432 fprintf (stderr, "ERROR: inconsistent result?"); 433 abort(); 434 } 435 436 // replace the current coords with the old coords: 437 oldcoords = getCoords (im); 438 memcpy (&image[im].coords, oldcoords, sizeof(Coords)); 439 440 // WRP images need to have an associated mosaic 441 moscoords = NULL; 442 if (!strcmp(&image[im].coords.ctype[4], "-WRP")) { 443 mosaic = getMosaicForImage (im); 444 if (mosaic == NULL) return; // if we cannot find the associated image, skip it 445 moscoords = &mosaic[0].coords; 446 } 447 imcoords = &image[im].coords; 448 449 for (i = 0; i < Nlist[im]; i++) { 450 m = mlist[im][i]; 451 c = clist[im][i]; 452 453 X = catalog[c].measure[m].Xccd; 454 Y = catalog[c].measure[m].Yccd; 455 n = catalog[c].measure[m].averef; 456 457 dR = dD = 0.0; 458 if (moscoords == NULL) { 459 // this is a Simple image (not a mosaic) 460 // note that for a Simple image, L,M = P,Q 461 XY_to_LM (&L, &M, X, Y, imcoords); 462 LM_to_RD (&R, &D, L, M, imcoords); 463 } else { 464 XY_to_LM (&L, &M, X, Y, imcoords); 465 XY_to_LM (&P, &Q, L, M, moscoords); 466 LM_to_RD (&R, &D, P, Q, moscoords); 467 } 468 469 catalog[c].measure[m].dR = dR; 470 catalog[c].measure[m].dD = dD; 471 472 if (catalog[c].measure[m].dR > +180.0*3600.0) { 473 // average on high end of boundary, move star up 474 R += 360.0; 475 catalog[c].measure[m].dR = 3600.0*(catalog[c].average[n].R - R); 476 } 477 if (catalog[c].measure[m].dR < -180.0*3600.0) { 478 // average on low end of boundary, move star down 479 R -= 360.0; 480 catalog[c].measure[m].dR = 3600.0*(catalog[c].average[n].R - R); 481 } 482 } 483 253 484 return; 254 485 } … … 257 488 // chip positions: X,Y -> L,M -> P,Q -> R,D. This function is used by the image fitting steps, for 258 489 // which the detections have already been filtered when they were loaded (bcatalog) 259 StarData *getImageRaw (Catalog *catalog, int Ncatalog, int im, int *Nstars, CoordMode mode) {260 261 int i, m, c, n;490 StarData *getImageRaw (Catalog *catalog, int Ncatalog, off_t im, off_t *Nstars, CoordMode mode) { 491 492 off_t i, m, c, n; 262 493 263 494 Mosaic *mosaic; … … 265 496 StarData *raw; 266 497 267 ALLOCATE (raw, StarData, Nlist[im]);268 269 498 mosaic = NULL; 270 499 moscoords = NULL; 271 500 if (mode == MODE_MOSAIC) { 272 mosaic = getMosaicForImage (im); 273 if (mosaic == NULL) { 274 fprintf (stderr, "mosaic not found for image %s\n", image[im].name); 275 exit (1); 276 } 277 moscoords = &mosaic[0].coords; 278 } 501 mosaic = getMosaicForImage (im); 502 if (mosaic == NULL) { 503 fprintf (stderr, "mosaic not found for image %s\n", image[im].name); 504 return NULL; 505 } 506 moscoords = &mosaic[0].coords; 507 } 508 509 ALLOCATE (raw, StarData, Nlist[im]); 279 510 280 511 for (i = 0; i < Nlist[im]; i++) { … … 319 550 LM_to_RD (&raw[i].R, &raw[i].D, raw[i].P, raw[i].Q, moscoords); 320 551 break; 321 default:322 fprintf (stderr, "error: invalid mode in getImageRaw");323 abort ();552 default: 553 fprintf (stderr, "error: invalid mode in getImageRaw"); 554 abort (); 324 555 } 325 556 } … … 332 563 // the sky positions: R,D -> P,Q -> L,M -> X,Y 333 564 334 StarData *getImageRef (Catalog *catalog, int Ncatalog, int im, int *Nstars, CoordMode mode) {335 336 int i, m, c, n;565 StarData *getImageRef (Catalog *catalog, int Ncatalog, off_t im, off_t *Nstars, CoordMode mode) { 566 567 off_t i, m, c, n; 337 568 338 569 Mosaic *mosaic; 339 570 Coords *moscoords; 340 571 StarData *ref; 341 342 ALLOCATE (ref, StarData, Nlist[im]);343 572 344 573 mosaic = NULL; … … 348 577 if (mosaic == NULL) { 349 578 fprintf (stderr, "mosaic not found for image %s\n", image[im].name); 350 exit (1);579 return NULL; 351 580 } 352 581 moscoords = &mosaic[0].coords; 353 582 } 583 584 ALLOCATE (ref, StarData, Nlist[im]); 354 585 355 586 for (i = 0; i < Nlist[im]; i++) { … … 371 602 switch (mode) { 372 603 case MODE_SIMPLE: 373 RD_to_LM (&ref[i].P, &ref[i].Q, ref[i].R, ref[i].D, &image[im].coords);374 ref[i].L = ref[i].P;375 ref[i].M = ref[i].Q;376 LM_to_XY (&ref[i].X, &ref[i].Y, ref[i].L, ref[i].M, &image[im].coords);377 break;604 RD_to_LM (&ref[i].P, &ref[i].Q, ref[i].R, ref[i].D, &image[im].coords); 605 ref[i].L = ref[i].P; 606 ref[i].M = ref[i].Q; 607 LM_to_XY (&ref[i].X, &ref[i].Y, ref[i].L, ref[i].M, &image[im].coords); 608 break; 378 609 case MODE_MOSAIC: 379 RD_to_LM (&ref[i].P, &ref[i].Q, ref[i].R, ref[i].D, moscoords);380 LM_to_XY (&ref[i].L, &ref[i].M, ref[i].P, ref[i].Q, moscoords);381 LM_to_XY (&ref[i].X, &ref[i].Y, ref[i].L, ref[i].M, &image[im].coords);382 break;610 RD_to_LM (&ref[i].P, &ref[i].Q, ref[i].R, ref[i].D, moscoords); 611 LM_to_XY (&ref[i].L, &ref[i].M, ref[i].P, ref[i].Q, moscoords); 612 LM_to_XY (&ref[i].X, &ref[i].Y, ref[i].L, ref[i].M, &image[im].coords); 613 break; 383 614 default: 384 615 fprintf (stderr, "invalid case"); … … 399 630 return; 400 631 401 int i, j, k, m, N, Ndel, Nave, Nmax, TOOFEW, Nsecfilt; 632 int Ndel, Nave; 633 off_t i, j, k, m, N, Nmax, TOOFEW, Nsecfilt; 402 634 double Ns, theta, x, y; 403 635 double *R, *D, *dR, *dD; … … 490 722 void FlagOutliers2D (Catalog *catalog) { 491 723 492 int i, j, k, m, N, Ndel, Nave, Nmax, TOOFEW, Nsecfilt; 724 int Ndel, Nave; 725 off_t i, j, k, m, N, Nmax, TOOFEW, Nsecfilt; 493 726 double *index; 494 727 double Ns, theta, x, y; … … 569 802 // recalculate image center, sigma based on closest 50% of points 570 803 for(k = 0; k < N; k++) { 571 int ind = (int) index[k];804 off_t ind = (off_t) index[k]; 572 805 R[k] = catalog[0].measure[ind].dR; 573 806 D[k] = catalog[0].measure[ind].dD; -
branches/simtest_nebulous_branches/Ohana/src/relastro/src/MosaicOps.c
r21508 r27840 2 2 3 3 // array of mosaic definition structures 4 static intNmosaic;4 static off_t Nmosaic; 5 5 static Mosaic *mosaic; 6 6 7 7 // list of all images associated with a mosaic 8 static int *Nmosaic_own_images; // number of images for this mosaic9 static int *Amosaic_own_images; // size of allocated array10 static int **mosaic_own_images; // array of arrays: mosaic -> images8 static off_t *Nmosaic_own_images; // number of images for this mosaic 9 static off_t *Amosaic_own_images; // size of allocated array 10 static off_t **mosaic_own_images; // array of arrays: mosaic -> images 11 11 12 12 // list of mosaic associated with each image 13 static int Nmosaic_for_images; // number of images (for internal checks)14 static int *mosaic_for_images; // array of: image -> mosaic15 16 Mosaic *getmosaics ( int *N) {13 static off_t Nmosaic_for_images; // number of images (for off_ternal checks) 14 static off_t *mosaic_for_images; // array of: image -> mosaic 15 16 Mosaic *getmosaics (off_t *N) { 17 17 *N = Nmosaic; 18 18 return (mosaic); 19 19 } 20 20 21 off_t getMosaicByTimes (unsigned int start, unsigned int stop, unsigned int *startMos, unsigned int *stopMos, off_t *indexMos) { 22 23 // use bisection to find the overlapping mosaic 24 25 off_t Nlo, Nhi, N; 26 27 // find the last mosaic before start 28 Nlo = 0; Nhi = Nmosaic; 29 while (Nhi - Nlo > 10) { 30 N = 0.5*(Nlo + Nhi); 31 if (startMos[N] < start) { 32 Nlo = MAX(N, 0); 33 } else { 34 Nhi = MIN(N + 1, Nmosaic); 35 } 36 } 37 38 // check for the matched mosaic starting from Nlo 39 // we may have to go much beyond Nlo since stop is not sorted 40 // can we use a sorted version of stop to check when we are beyond the valid range?? 41 for (N = Nlo; N < Nmosaic; N++) { 42 if (stop < stopMos[N]) continue; 43 if (start > startMos[N]) continue; 44 if (stop < startMos[N]) return (-1); 45 return (indexMos[N]); 46 } 47 48 return (-1); 49 } 50 51 // sort two times vectors and an index by first time vector 52 void sort_mosaic_times (unsigned int *S, unsigned int *E, off_t *I, off_t N) { 53 54 # define SWAPFUNC(A,B){ unsigned int tmp_t; off_t tmp_i; \ 55 tmp_t = S[A]; S[A] = S[B]; S[B] = tmp_t; \ 56 tmp_t = E[A]; E[A] = E[B]; E[B] = tmp_t; \ 57 tmp_i = I[A]; I[A] = I[B]; I[B] = tmp_i; \ 58 } 59 # define COMPARE(A,B)(S[A] < S[B]) 60 61 OHANA_SORT (N, COMPARE, SWAPFUNC); 62 63 # undef SWAPFUNC 64 # undef COMPARE 65 66 } 67 68 // first, let's continue to use the time to make the match, but use bracketing to make it faster: 69 21 70 // find mosaic frames (unique time periods & photcode name matches mosaic) 22 void initMosaics (Image *image, int Nimage) {23 24 int i, j, found, NMOSAIC;71 void initMosaics (Image *image, off_t Nimage) { 72 73 off_t i, Nmos, NMOSAIC; 25 74 unsigned int start, stop; 75 76 unsigned int *startMos, *stopMos; 77 off_t *indexMos; 26 78 27 79 Nmosaic = 0; … … 29 81 ALLOCATE (mosaic, Mosaic, NMOSAIC); 30 82 31 ALLOCATE (Nmosaic_own_images, int, NMOSAIC); 32 ALLOCATE (Amosaic_own_images, int, NMOSAIC); 33 ALLOCATE (mosaic_own_images, int *, NMOSAIC); 83 ALLOCATE (Nmosaic_own_images, off_t, NMOSAIC); 84 ALLOCATE (Amosaic_own_images, off_t, NMOSAIC); 85 ALLOCATE (mosaic_own_images, off_t *, NMOSAIC); 86 ALLOCATE (startMos, unsigned int, NMOSAIC); 87 ALLOCATE (stopMos, unsigned int, NMOSAIC); 88 ALLOCATE (indexMos, off_t, NMOSAIC); 34 89 35 90 /* find the mosaic images (coords.ctype = DIS); generate list of unique mosaics */ … … 54 109 Nmosaic_own_images[Nmosaic] = 0; 55 110 Amosaic_own_images[Nmosaic] = 10; 56 ALLOCATE (mosaic_own_images[Nmosaic], int, Amosaic_own_images[Nmosaic]); 111 ALLOCATE (mosaic_own_images[Nmosaic], off_t, Amosaic_own_images[Nmosaic]); 112 113 startMos[Nmosaic] = start; 114 stopMos[Nmosaic] = stop; 115 indexMos[Nmosaic] = Nmosaic; 57 116 58 117 Nmosaic ++; … … 60 119 NMOSAIC += 10; 61 120 REALLOCATE (mosaic, Mosaic, NMOSAIC); 62 REALLOCATE (mosaic_own_images, int *, NMOSAIC); 63 REALLOCATE (Nmosaic_own_images, int, NMOSAIC); 64 REALLOCATE (Amosaic_own_images, int, NMOSAIC); 65 } 66 } 67 121 REALLOCATE (mosaic_own_images, off_t *, NMOSAIC); 122 REALLOCATE (Nmosaic_own_images, off_t, NMOSAIC); 123 REALLOCATE (Amosaic_own_images, off_t, NMOSAIC); 124 REALLOCATE (startMos, unsigned int, NMOSAIC); 125 REALLOCATE (stopMos, unsigned int, NMOSAIC); 126 REALLOCATE (indexMos, off_t, NMOSAIC); 127 } 128 } 129 130 // sort the index, start, and stop by the start times: 131 sort_mosaic_times (startMos, stopMos, indexMos, Nmosaic); 132 68 133 // array to store image->mosaic index 69 134 Nmosaic_for_images = Nimage; 70 ALLOCATE (mosaic_for_images, int, Nmosaic_for_images);135 ALLOCATE (mosaic_for_images, off_t, Nmosaic_for_images); 71 136 72 137 /* now assign the WRP images to these mosaics */ … … 80 145 stop = image[i].tzero + MAX(1.01*image[i].trate*image[i].NY, 1); 81 146 82 /* find existing mosaic with this time range */ 83 found = FALSE; 84 for (j = 0; !found && (j < Nmosaic); j++) { 85 if (stop < mosaic[j].start) continue; 86 if (start > mosaic[j].stop) continue; 87 found = TRUE; 88 break; 89 } 90 /* if no matching mosaic exists, skip this image */ 91 if (!found) continue; 147 Nmos = getMosaicByTimes (start, stop, startMos, stopMos, indexMos); 148 if (Nmos == -1) { 149 fprintf (stderr, "cannot match mosaic for %s\n", image[i].name); 150 continue; 151 } 92 152 93 153 // mosaic corresponding to this image 94 mosaic_for_images[i] = j;154 mosaic_for_images[i] = Nmos; 95 155 96 156 // add image to mosaic_own_image list 97 mosaic_own_images[j][Nmosaic_own_images[j]] = i; 98 Nmosaic_own_images[j] ++; 99 if (Nmosaic_own_images[j] == Amosaic_own_images[j]) { 100 Amosaic_own_images[j] += 10; 101 REALLOCATE (mosaic_own_images[j], int, Amosaic_own_images[j]); 102 } 103 assert (Nmosaic_own_images[j] < Amosaic_own_images[j]); 104 } 105 157 mosaic_own_images[Nmos][Nmosaic_own_images[Nmos]] = i; 158 Nmosaic_own_images[Nmos] ++; 159 if (Nmosaic_own_images[Nmos] == Amosaic_own_images[Nmos]) { 160 Amosaic_own_images[Nmos] += 10; 161 REALLOCATE (mosaic_own_images[Nmos], off_t, Amosaic_own_images[Nmos]); 162 } 163 assert (Nmosaic_own_images[Nmos] < Amosaic_own_images[Nmos]); 164 } 165 166 free (startMos); 167 free (stopMos); 168 free (indexMos); 106 169 return; 107 170 } … … 109 172 // return StarData values for detections in the specified image, converting coordinates from the 110 173 // chip positions: X,Y -> L,M -> P,Q -> R,D 111 StarData *getMosaicRaw (Catalog *catalog, int Ncatalog, int mos, int *Nstars) {112 113 int i, j, im, Nraw, Nnew;174 StarData *getMosaicRaw (Catalog *catalog, int Ncatalog, off_t mos, off_t *Nstars) { 175 176 off_t i, j, im, Nraw, Nnew; 114 177 StarData *raw, *new; 115 178 … … 125 188 // this function does the reverse-lookup for the mosaic corresponding to this image 126 189 new = getImageRaw (catalog, Ncatalog, im, &Nnew, MODE_MOSAIC); 190 if (!new) { 191 fprintf (stderr, "inconsistent: missing mosaic for image already associated with a mosaic? (1)\n"); 192 abort(); 193 } 127 194 128 195 // merge new and raw … … 142 209 // return StarData values for averages positions in the specified image, converting coordinates from 143 210 // the sky positions: R,D -> P,Q -> L,M -> X,Y 144 StarData *getMosaicRef (Catalog *catalog, int Ncatalog, int mos, int *Nstars) {145 146 int i, j, im, Nref, Nnew;211 StarData *getMosaicRef (Catalog *catalog, int Ncatalog, off_t mos, off_t *Nstars) { 212 213 off_t i, j, im, Nref, Nnew; 147 214 StarData *ref, *new; 148 215 … … 157 224 // this function does the reverse-lookup for the mosaic corresponding to this image 158 225 new = getImageRef (catalog, Ncatalog, im, &Nnew, MODE_MOSAIC); 226 if (!new) { 227 fprintf (stderr, "inconsistent: missing mosaic for image already associated with a mosaic? (2)\n"); 228 abort(); 229 } 159 230 160 231 // merge new and ref … … 172 243 } 173 244 174 Mosaic *getMosaicForImage ( int im) {175 176 int mos;245 Mosaic *getMosaicForImage (off_t im) { 246 247 off_t mos; 177 248 178 249 if (im < 0) abort(); -
branches/simtest_nebulous_branches/Ohana/src/relastro/src/ParFactor.c
r14590 r27840 42 42 43 43 /* given RA, DEC, Time, calculate the parallax factor */ 44 int ParFactor (double *pR, double *pD, double R, double D, time_t T) {44 int ParFactor (double *pR, double *pD, double R, double D, double T, double Tmean) { 45 45 46 46 double jd; … … 49 49 /* given a time T in UNIX seconds, determine the solar longitude S */ 50 50 51 jd = ohana_sec_to_jd ( T);51 jd = ohana_sec_to_jd (365.25*86400.0*(T + Tmean)); 52 52 sun_ecliptic (jd, &L, &B, &E); 53 53 -
branches/simtest_nebulous_branches/Ohana/src/relastro/src/UpdateChips.c
r17151 r27840 4 4 5 5 /* we can measure new image parameters for each non-mosaic chip independently */ 6 int i, Nimage, Nraw, Nref;6 off_t i, Nimage, Nraw, Nref; 7 7 Image *image; 8 8 StarData *raw, *ref; 9 Coords *oldCoords; 9 10 10 11 image = getimages (&Nimage); … … 17 18 /* convert measure coordinates to raw entries */ 18 19 raw = getImageRaw (catalog, Ncatalog, i, &Nraw, MODE_MOSAIC); 20 if (!raw) continue; 19 21 20 22 /* convert average coordinates to ref entries */ 21 23 ref = getImageRef (catalog, Ncatalog, i, &Nref, MODE_MOSAIC); 24 if (!ref) continue; 22 25 23 26 // note that Nraw & Nref must be equal: if not, we made a programming error in one of these two functions. 24 27 assert (Nraw == Nref); 25 28 29 saveCoords (&image[i].coords, i); 30 26 31 // FitChip does iterative, clipped fitting 27 fprintf (stderr, "image %d : Nstars: %d\n", i, Nraw); 28 FitChip (raw, ref, Nraw, &image[i].coords); 32 // fprintf (stderr, "image %lld : Nstars: %lld\n", (long long) i, (long long) Nraw); 33 if (!FitChip (raw, ref, Nraw, &image[i].coords)) { 34 fprintf (stderr, "reject fit for image %s (%lld) : Nstars: %lld\n", image[i].name, (long long) i, (long long) Nraw); 35 oldCoords = getCoords (i); 36 memcpy (&image[i].coords, oldCoords, sizeof(Coords)); 37 } 29 38 30 39 free (raw); -
branches/simtest_nebulous_branches/Ohana/src/relastro/src/UpdateMeasures.c
r16810 r27840 3 3 int UpdateMeasures (Catalog *catalog, int Ncatalog) { 4 4 5 int i, Nimage;5 off_t i, Nimage; 6 6 Image *image; 7 7 -
branches/simtest_nebulous_branches/Ohana/src/relastro/src/UpdateMosaic.c
r15600 r27840 4 4 5 5 /* we can measure new image parameters for each mosaic independently */ 6 int i, Nmosaic, Nstars;6 off_t i, Nmosaic, Nstars; 7 7 Mosaic *mosaic; 8 8 StarData *raw, *ref; -
branches/simtest_nebulous_branches/Ohana/src/relastro/src/UpdateObjectOffsets.c
r17243 r27840 1 1 # include "relastro.h" 2 3 // We run through each DVO catalog, updating the measures that come from the modified images 4 // We need to watch for failures: 5 // * in UpdateMeasures, in fixImageRaw, we track the cumulative offset for each image 6 // * after all updates are done, we can check for any bad images and reset them to the 7 // original coordinates 2 8 3 9 int UpdateObjectOffsets (SkyList *skylist) { … … 28 34 29 35 // match measurements with images 30 initImageBins (&catalog, 1 );31 findImages (&catalog, 1 );36 initImageBins (&catalog, 1, FALSE); 37 findImages (&catalog, 1, FALSE); 32 38 33 39 // update the detection coordinates using the new image parameters -
branches/simtest_nebulous_branches/Ohana/src/relastro/src/UpdateObjects.c
r24308 r27840 1 1 # include "relastro.h" 2 2 3 static intNmax;3 static off_t Nmax; 4 4 static double *X, *dX; 5 5 static double *Y, *dY; … … 13 13 void initObjectData (Catalog *catalog, int Ncatalog) { 14 14 15 int i, j;15 off_t i, j; 16 16 17 17 Nmax = 0; … … 40 40 int UpdateObjects (Catalog *catalog, int Ncatalog) { 41 41 42 int i, j, k, m, N, Nsecfilt, found, kp; 42 off_t j, k, m; 43 int i, N, Nsecfilt, mode, result, status, XVERB; 43 44 StatType statsR, statsD; 44 45 Coords coords; 45 PMFit fit; 46 time_t To; 47 int mode, Nave, Npm, Npar, Nskip; 48 double Tmin, Tmax; 49 float mag; 50 int mask; 51 PhotCode *code; 52 46 PMFit fitAve, fitPM, fitPAR, fit; 47 time_t T2000; 48 off_t Nave, Npm, Npar, Nskip; 49 off_t NaveSum, NpmSum, NparSum, NskipSum; 50 double Tmin, Tmax, Tmean, Trange; 51 52 memset (&fit, 0, sizeof(fit)); 53 memset (&fitAve, 0, sizeof(fitAve)); 54 memset (&fitPM, 0, sizeof(fitPM)); 55 memset (&fitPAR, 0, sizeof(fitPAR)); 56 53 57 initObjectData (catalog, Ncatalog); 54 58 … … 64 68 strcpy (coords.ctype, "RA---SIN"); 65 69 70 XVERB = FALSE; 71 66 72 // use J2000 as a reference time 67 To = ohana_date_to_sec ("2000/01/01"); 68 Nave = Npar = Npm = 0; 73 T2000 = ohana_date_to_sec ("2000/01/01"); 69 74 70 75 // XXX in the future, use catalog[0].Nsecfilt only? allow catalogs to have variable Nsecfilt? … … 72 77 assert (catalog[0].Nsecfilt == Nsecfilt); 73 78 79 NaveSum = NparSum = NpmSum = NskipSum = 0; 74 80 for (i = 0; i < Ncatalog; i++) { 75 81 76 if (VERBOSE) fprintf (stderr, "astrometrize catalog %d : % d ave, %d meas\n", i, catalog[i].Naverage,catalog[i].Nmeasure);77 78 N skip = 0;82 if (VERBOSE) fprintf (stderr, "astrometrize catalog %d : %lld ave, %lld meas\n", i, (long long) catalog[i].Naverage, (long long) catalog[i].Nmeasure); 83 84 Nave = Npar = Npm = Nskip = 0; 79 85 for (j = 0; j < catalog[i].Naverage; j++) { 80 86 /* calculate the average value of R,D for a single star */ … … 82 88 // skip objects which are known to be problematic 83 89 // XXX include this code or not? 84 # if (0)90 # if (0) 85 91 if (catalog[i].average[j].code & STAR_BAD) { 86 92 Nskip ++; 87 93 continue; 88 94 } 89 # endif95 # endif 90 96 91 97 N = 0; 92 98 m = catalog[i].average[j].measureOffset; 93 99 94 Tmin = Tmax = (catalog[i].measure[m].t - T o) / (86400*365.25);100 Tmin = Tmax = (catalog[i].measure[m].t - T2000) / (86400*365.25); 95 101 mode = FIT_MODE; 96 102 103 // find the basic properties of the detections for this object (Tmin, Tmax, Tmean) 104 Tmean = 0; 97 105 for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) { 98 106 … … 111 119 // exclude measurements by previous outlier detection 112 120 // XXX include this code or not? 113 # if (0)121 # if (0) 114 122 if (catalog[i].measure[m].dbFlags & MEAS_BAD) { 115 123 catalog[i].measure[m].dbFlags |= ID_MEAS_SKIP_ASTROM; 116 124 continue; 117 125 } 118 # endif126 # endif 119 127 120 128 catalog[i].measure[m].dbFlags |= ID_MEAS_USED_OBJ; … … 122 130 R[N] = getMeanR (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]); 123 131 D[N] = getMeanD (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]); 124 T[N] = (catalog[i].measure[m].t - T o) / (86400*365.25) ; // time relative to J2000 in years132 T[N] = (catalog[i].measure[m].t - T2000) / (86400*365.25) ; // time relative to J2000 in years 125 133 126 134 Tmin = MIN(Tmin, T[N]); 127 135 Tmax = MAX(Tmax, T[N]); 128 129 dR[N] = GetAstromError (&catalog[i].measure[m], ERROR_MODE_RA); 130 dD[N] = GetAstromError (&catalog[i].measure[m], ERROR_MODE_DEC); 136 Tmean += T[N]; 137 138 // dX, dY : error in arcsec -- 139 dX[N] = GetAstromError (&catalog[i].measure[m], ERROR_MODE_RA); 140 dY[N] = GetAstromError (&catalog[i].measure[m], ERROR_MODE_DEC); 131 141 dT[N] = catalog[i].measure[m].dt; 142 143 // XXX this is (slightly) inconsistent: dX,dY are the X and Y direction errors in 144 // arcseconds. dR, dD are the errors in those directions in degrees. IF we have 145 // non-circular errors (different values for X and Y), then dR and dD will be 146 // incorrect: they would need to be rotated to take out the position angle 147 dR[k] = dX[k] / 3600.0; 148 dD[k] = dY[k] / 3600.0; 132 149 133 150 N++; … … 141 158 142 159 // XXX add the parallax factor range as a criterion as well 143 if ((Tmax - Tmin) < PM_DT_MIN) mode = FIT_AVERAGE; 160 Trange = Tmax - Tmin; 161 if (Trange < PM_DT_MIN) mode = FIT_AVERAGE; 144 162 if ((mode == FIT_PM_ONLY) && (N < PM_TOOFEW)) mode = FIT_AVERAGE; 145 163 … … 147 165 if (N < SRC_MEAS_TOOFEW) { 148 166 // XXX need to define PHOTOM and ASTROM object flags 167 // XXX reset the average value fields? 149 168 catalog[i].average[j].flags |= ID_STAR_FEW; 169 catalog[i].average[j].ChiSqAve = NAN; 170 catalog[i].average[j].ChiSqPM = NAN; 171 catalog[i].average[j].ChiSqPar = NAN; 150 172 if (N < 2) continue; 151 173 } … … 154 176 coords.crval1 = R[0]; 155 177 coords.crval2 = D[0]; 178 Tmean /= (float) N; 156 179 157 /* project all of the R,D coordinates to a plane centered on this coordinate */ 158 for (k = 0; k < N; k++) { 159 RD_to_XY (&X[k], &Y[k], R[k], D[k], &coords); 160 dX[k] = dR[k]; 161 dY[k] = dD[k]; 162 // fprintf (stderr, "%d %f %f %f %f %f\n", k, T[k], R[k], D[k], X[k], Y[k]); 180 XVERB = FALSE && (catalog[i].measure[m].dM < 0.01) && (N == 6) && (mode == FIT_PM_ONLY); 181 182 // to judge the quality of the PM and PAR fits, we need to fit all three models and compare Chisq 183 184 if ((mode == FIT_PM_ONLY) || (mode == FIT_PM_AND_PAR)) { 185 // project all of the R,D coordinates to a plane centered on this coordinate set 186 // the times to be relative to Tmean (this is required for parallax as well) 187 for (k = 0; k < N; k++) { 188 RD_to_XY (&X[k], &Y[k], R[k], D[k], &coords); 189 T[k] -= Tmean; 190 if (XVERB) { 191 fprintf (stderr, "%lld %f %f %f %f %f +/- %f %f\n", (long long) k, T[k], R[k], D[k], X[k], Y[k], dX[k], dY[k]); 192 } 193 } 194 195 FitPM (&fitPM, X, dX, Y, dY, T, N); 196 if (XVERB) fprintf (stderr, "fitted: %f - %f : %f %f : %f %f : %f vs %f\n", Tmin, Tmax, fitPM.Ro, fitPM.Do, fitPM.uR, fitPM.uD, fitPM.chisq, fitAve.chisq); 197 198 // project Ro, Do back to RA,DEC 199 XY_to_RD (&fitPM.Ro, &fitPM.Do, fitPM.Ro, fitPM.Do, &coords); 200 if (XVERB) fprintf (stderr, "project: %f %f : %f %f : %f\n", fitPM.Ro, fitPM.Do, fitPM.uR, fitPM.uD, fitPM.p); 201 202 fitPM.p = fitPM.dp = 0.0; 203 catalog[i].average[j].flags |= ID_STAR_FIT_PM; 204 Npm ++; 205 } 206 207 if (mode == FIT_PM_AND_PAR) { 208 fprintf (stderr, "parallax fitting is still untested (%s, %d)", __FILE__, __LINE__); 209 exit (2); 210 211 for (k = 0; k < N; k++) { 212 ParFactor (&pX[k], &pY[k], R[k], D[k], T[k], Tmean); 213 } 214 FitPMandPar (&fitPAR, X, dX, Y, dY, T, pX, pY, N); 215 XY_to_RD (&fitPAR.Ro, &fitPAR.Do, fitPAR.Ro, fitPAR.Do, &coords); 216 catalog[i].average[j].flags |= ID_STAR_FIT_PAR; 217 Npar ++; 163 218 } 164 219 165 /* fit the model components as needed */ 166 switch (mode) { 220 // fit the average model 221 if ((mode == FIT_AVERAGE) || (mode == FIT_PM_ONLY) || (mode == FIT_PM_AND_PAR)) { 222 liststats (R, dR, N, &statsR); // WARNING: this function modifies R (do not use after here) 223 liststats (D, dD, N, &statsD); // WARNING: this function modifies D (do not use after here) 224 225 fitAve.Ro = statsR.mean; 226 fitAve.dRo = 3600.0*statsR.sigma; 227 228 fitAve.Do = statsD.mean; 229 fitAve.dDo = 3600.0*statsD.sigma; 230 231 fitAve.chisq = 0.5*(statsR.chisq + statsD.chisq); 232 fitAve.Nfit = N; 233 234 fitAve.uR = fitAve.duR = 0.0; 235 fitAve.uD = fitAve.duD = 0.0; 236 fitAve.p = fitAve.dp = 0.0; 237 catalog[i].average[j].flags |= ID_STAR_FIT_AVE; 238 Nave ++; 239 } 240 241 /* choose the result based on the chisq values */ 242 // XXXX for now, just use the mode as the result: 243 result = mode; 244 245 switch (result) { 167 246 case FIT_AVERAGE: 168 liststats (R, dR, N, &statsR); 169 liststats (D, dD, N, &statsD); 170 171 fit.Ro = statsR.mean; 172 fit.dRo = 3600.0*statsR.sigma; 173 174 fit.Do = statsD.mean; 175 fit.dDo = 3600.0*statsD.sigma; 176 177 fit.chisq = 0.5*(statsR.chisq + statsD.chisq); 178 fit.Nfit = N; 179 180 fit.uR = fit.duR = 0.0; 181 fit.uD = fit.duD = 0.0; 182 fit.p = fit.dp = 0.0; 183 184 Nave ++; 247 catalog[i].average[j].flags |= ID_STAR_USE_AVE; 248 fit = fitAve; 185 249 break; 186 187 250 case FIT_PM_ONLY: 188 FitPM (&fit, X, dX, Y, dY, T, N); 189 // fprintf (stderr, "fitted: %f - %f : %f %f : %f %f : %f\n", Tmin, Tmax, fit.Ro, fit.Do, fit.uR, fit.uD, fit.p); 190 // project Ro, Do back to RA,DEC 191 XY_to_RD (&fit.Ro, &fit.Do, fit.Ro, fit.Do, &coords); 192 // fprintf (stderr, "project: %f %f : %f %f : %f\n", fit.Ro, fit.Do, fit.uR, fit.uD, fit.p); 193 // continue; 194 195 fit.p = fit.dp = 0.0; 196 197 Npm ++; 251 catalog[i].average[j].flags |= ID_STAR_USE_PM; 252 fit = fitPM; 198 253 break; 199 200 case FIT_PAR_ONLY: 201 fprintf (stderr, "programming error at %s, %d", __FILE__, __LINE__); 202 exit (2); 203 204 for (k = 0; k < N; k++) { 205 ParFactor (&pX[k], &pY[k], R[k], D[k], T[k]); 206 } 207 FitPar (&fit, X, dX, Y, dY, pX, pY, N); 208 209 // project Ro, Do back to RA,DEC 210 XY_to_RD (&fit.Ro, &fit.Do, fit.Ro, fit.Do, &coords); 211 212 fit.uR = fit.duR = 0.0; 213 fit.uD = fit.duD = 0.0; 214 215 Npar ++; 254 case FIT_PM_AND_PAR: 255 catalog[i].average[j].flags |= ID_STAR_USE_PAR; 256 fit = fitPAR; 216 257 break; 217 218 case FIT_PM_AND_PAR: 219 fprintf (stderr, "programming error at %s, %d", __FILE__, __LINE__); 220 exit (2); 221 222 for (k = 0; k < N; k++) { 223 ParFactor (&pX[k], &pY[k], R[k], D[k], T[k]); 224 } 225 FitPMandPar (&fit, X, dX, Y, dY, T, pX, pY, N); 226 XY_to_RD (&fit.Ro, &fit.Do, fit.Ro, fit.Do, &coords); 227 Npar ++; 228 break; 229 230 default: 231 fprintf (stderr, "programming error at %s, %d", __FILE__, __LINE__); 232 exit (2); 233 } 234 235 if (0 && (j < 100)) { 236 fprintf (stderr, "%f %f -> %f %f (%f,%f)\n", 237 catalog[i].average[j].R, 238 catalog[i].average[j].D, 239 fit.Ro, fit.Do, 240 3600*(catalog[i].average[j].R - fit.Ro), 241 3600*(catalog[i].average[j].D - fit.Do)); 242 } 258 } 259 260 if (XVERB) fprintf (stderr, "%f %f -> %f %f (%f,%f)\n", 261 catalog[i].average[j].R, 262 catalog[i].average[j].D, 263 fit.Ro, fit.Do, 264 3600*(catalog[i].average[j].R - fit.Ro), 265 3600*(catalog[i].average[j].D - fit.Do)); 243 266 244 267 //make sure that the fit succeeded 245 assert(finite(fit.Ro) && finite(fit.Do) && 246 finite(fit.dRo) && finite(fit.dDo) && 247 finite(fit.uR) && finite(fit.uD) && 248 finite(fit.duR) && finite(fit.duD) && 249 finite(fit.p) && finite(fit.dp)); 268 status = finite(fit.Ro); 269 status &= finite(fit.Do); 270 status &= finite(fit.dRo); 271 status &= finite(fit.dDo); 272 status &= finite(fit.uR); 273 status &= finite(fit.uD); 274 status &= finite(fit.duR); 275 status &= finite(fit.duD); 276 status &= finite(fit.p); 277 status &= finite(fit.dp); 278 if (!status) { 279 Nskip ++; 280 continue; 281 } 250 282 251 283 // the measure fields must be updated before the average fields 252 284 m = catalog[i].average[j].measureOffset; 253 285 for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) { 254 // XXX why was this here?? if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue;255 286 setMeanR (fit.Ro, &catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]); 256 287 setMeanD (fit.Do, &catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]); … … 270 301 catalog[i].average[j].dP = fit.dp; // parallax error in arcsec 271 302 272 catalog[i].average[j].Xp = (fit.Nfit > 1) ? 100.0*log10(fit.chisq) : NAN_S_SHORT; 303 // Xp is supposed to be the position scatter, not the chisq : fix this: 304 // catalog[i].average[j].Xp = (fit.Nfit > 1) ? 100.0*log10(fit.chisq) : NAN_S_SHORT; 305 catalog[i].average[j].ChiSqAve = fitAve.chisq; 306 catalog[i].average[j].ChiSqPM = fitPM.chisq; 307 catalog[i].average[j].ChiSqPar = fitPAR.chisq; 308 catalog[i].average[j].Xp = 0.0; 309 catalog[i].average[j].Tmean = (Tmean * 86400 * 365.26) + T2000; 310 catalog[i].average[j].Trange = (Trange * 86400 * 365.26); 311 catalog[i].average[j].Npos = fit.Nfit; 273 312 } 274 313 275 if (VERBOSE) fprintf (stderr, "catalog %d : %d ave, %d pm, %d par : Nskip % d\n", i, Nave, Npm, Npar, Nskip); 314 NaveSum += Nave; 315 NpmSum += Npm; 316 NparSum += Npar; 317 NskipSum += Nskip; 318 if (VERBOSE) fprintf (stderr, "catalog %lld : %lld ave, %lld pm, %lld par : Nskip %lld\n", (long long) i, (long long) Nave, (long long) Npm, (long long) Npar, (long long) Nskip); 276 319 } 277 320 278 if (VERBOSE) fprintf (stderr, "fitted %d objects (%d ave, %d pm, %d par)\n", Nave + Npm + Npar, Nave, Npm, Npar);321 fprintf (stderr, "fitted %lld objects (%lld ave, %lld pm, %lld par), skipped %lld\n", (long long) (NaveSum + NpmSum + NparSum), (long long) NaveSum, (long long) NpmSum, (long long) NparSum, (long long) NskipSum); 279 322 return (TRUE); 280 323 } … … 282 325 /* fitting proper-motion and parallax: 283 326 284 given a source at position r,d, at a time t, we need to calculate a vector (pr,pd)285 286 let x,y be the coordinate in the linearized frame with y parallel to DEC lines287 288 L,B are the ecliptic longitude and latitude of the object,289 dL and dB are the offsets in the L and B directions290 291 dL = sin(t - topp)292 dB = cos(t - topp)*sin(B)293 294 these need to be rotated to the R,D frame to yield pR,pD. Then, the equation of motion295 for the source in the x,y frame is:296 297 x = Ro + uR * (t - to) + p * pR298 y = Do + uD * (t - to) + p * pD299 300 the unknowns in these equations are Ro, uR, Do, uD, and p301 302 XXX think through the concepts for the pole a bit better. all objects near the pole303 move the same way with the same phase. choose a projection center and define dL,dB relative304 to that center point coordinate system?327 given a source at position r,d, at a time t, we need to calculate a vector (pr,pd) 328 329 let x,y be the coordinate in the linearized frame with y parallel to DEC lines 330 331 L,B are the ecliptic longitude and latitude of the object, 332 dL and dB are the offsets in the L and B directions 333 334 dL = sin(t - topp) 335 dB = cos(t - topp)*sin(B) 336 337 these need to be rotated to the R,D frame to yield pR,pD. Then, the equation of motion 338 for the source in the x,y frame is: 339 340 x = Ro + uR * (t - to) + p * pR 341 y = Do + uD * (t - to) + p * pD 342 343 the unknowns in these equations are Ro, uR, Do, uD, and p 344 345 XXX think through the concepts for the pole a bit better. all objects near the pole 346 move the same way with the same phase. choose a projection center and define dL,dB relative 347 to that center point coordinate system? 305 348 306 349 */ -
branches/simtest_nebulous_branches/Ohana/src/relastro/src/UpdateSimple.c
r15590 r27840 4 4 5 5 /* we can measure new image parameters for each non-mosaic chip independently */ 6 int i, Nimage, Nstars;6 off_t i, Nimage, Nstars; 7 7 Image *image; 8 8 StarData *raw, *ref; … … 18 18 /* convert measure coordinates to raw entries */ 19 19 raw = getImageRaw (catalog, Ncatalog, i, &Nstars, MODE_SIMPLE); 20 if (!raw) continue; 20 21 21 22 /* convert average coordinates to ref entries */ 22 23 ref = getImageRef (catalog, Ncatalog, i, &Nstars, MODE_SIMPLE); 24 if (!ref) continue; 23 25 24 26 FitSimple (raw, ref, Nstars, &image[i].coords); -
branches/simtest_nebulous_branches/Ohana/src/relastro/src/args.c
r24308 r27840 50 50 51 51 if (FIT_TARGET == TARGET_NONE) usage(); 52 53 UserCatalog = FALSE; 54 if ((N = get_argument (argc, argv, "-catalog"))) { 55 remove_argument (N, &argc, argv); 56 UserCatalogRA = atof(argv[N]); 57 remove_argument (N, &argc, argv); 58 UserCatalogDEC = atof(argv[N]); 59 remove_argument (N, &argc, argv); 60 UserCatalog = TRUE; 61 } 52 62 53 63 /* specify portion of the sky : allow default of all sky? */ … … 67 77 remove_argument (N, &argc, argv); 68 78 } else { 69 usage (); 79 if (!UserCatalog) { 80 usage (); 81 } 70 82 } 71 83 … … 111 123 } 112 124 113 VERBOSE = FALSE;125 VERBOSE = VERBOSE2 = FALSE; 114 126 if ((N = get_argument (argc, argv, "-v"))) { 115 127 VERBOSE = TRUE; 128 remove_argument (N, &argc, argv); 129 } 130 if ((N = get_argument (argc, argv, "-vv"))) { 131 VERBOSE = VERBOSE2 = TRUE; 116 132 remove_argument (N, &argc, argv); 117 133 } … … 242 258 } 243 259 260 NLOOP = 4; 261 if ((N = get_argument (argc, argv, "-nloop"))) { 262 remove_argument (N, &argc, argv); 263 NLOOP = atof (argv[N]); 264 remove_argument (N, &argc, argv); 265 } 266 244 267 if (argc != 1) usage (); 245 268 return TRUE; … … 248 271 void usage () { 249 272 fprintf (stderr, "ERROR: USAGE: relastro -region RA RA DEC DEC\n"); 273 fprintf (stderr, " OR: relastro -catalog (ra) (dec)\n"); 250 274 fprintf (stderr, " working options: \n"); 251 275 fprintf (stderr, " -update-objects\n"); … … 263 287 fprintf (stderr, " -statmode (mode)\n"); 264 288 fprintf (stderr, " -reset"); 289 fprintf (stderr, " -nloop (N) : number of image-fit iterations"); 265 290 fprintf (stderr, " -update : apply new fit to database\n"); 266 291 fprintf (stderr, " -params\n"); -
branches/simtest_nebulous_branches/Ohana/src/relastro/src/bcatalog.c
r24308 r27840 3 3 int bcatalog (Catalog *subcatalog, Catalog *catalog) { 4 4 5 int i, j, k, offset, found; 6 int NAVERAGE, NMEASURE, Naverage, Nmeasure, Nm, Nsecfilt; 7 float mag; 8 int mask; 9 PhotCode *code; 5 off_t i, j, offset; 6 off_t NAVERAGE, NMEASURE, Naverage, Nmeasure, Nm; 7 int Nsecfilt; 10 8 11 9 // XXX in the future, use catalog[0].Nsecfilt only? allow catalogs to have variable Nsecfilt? … … 106 104 107 105 if (VERBOSE) { 108 fprintf (stderr, "%d: using %d stars (%d measures) for catalog\n", i, 109 subcatalog[0].Naverage, subcatalog[0].Nmeasure); 106 fprintf (stderr, "%lld: using %lld stars (%lld measures) for catalog\n", (long long) i, (long long) subcatalog[0].Naverage, (long long) subcatalog[0].Nmeasure); 110 107 } 111 108 return (TRUE); -
branches/simtest_nebulous_branches/Ohana/src/relastro/src/fitpoly.c
r17419 r27840 103 103 104 104 /* convert the xsum,ysum,sum terms into vector,matrix and solve */ 105 voidfit_eval (CoordFit *fit) {105 int fit_eval (CoordFit *fit) { 106 106 107 107 int i, j, ix, iy, jx, jy; … … 146 146 // ix, iy, vector[i][0], ix, iy, vector[i][1]); 147 147 } 148 149 dgaussjordan (matrix, vector, fit[0].Nelems, 2); 148 149 if (!dgaussjordan (matrix, vector, fit[0].Nelems, 2)) { 150 return (FALSE); 151 } 150 152 151 153 for (i = 0; i < fit[0].Nelems; i++) { … … 166 168 array_free (matrix, fit[0].Nelems); 167 169 array_free (vector, fit[0].Nelems); 170 return (TRUE); 168 171 } 169 172 … … 271 274 /* this should only apply to the polynomial, not the projection terms */ 272 275 /* compare with psastro supporting code */ 273 CoordFit *fit_apply_coords (CoordFit *fit, Coords *coords) {276 int fit_apply_coords (CoordFit *fit, Coords *coords) { 274 277 275 278 double Xo, Yo, R1, R2; … … 281 284 // L = pc1_1*cd1*(x - cp1) + pc1_2*cd2*(y - cp2) + ... 282 285 283 CoordsGetCenter (fit, 0.001, &Xo, &Yo); 286 if (!CoordsGetCenter (fit, 0.001, &Xo, &Yo)) { 287 fprintf (stderr, "failed to modify model\n"); 288 return (FALSE); 289 } 284 290 coords[0].crpix1 = Xo; 285 291 coords[0].crpix2 = Yo; … … 329 335 /* keep the order and type from initial values */ 330 336 331 // XXX if desired in the future, return modfit (and free above) 332 return (NULL); 333 } 334 337 return (TRUE); 338 } 339 -
branches/simtest_nebulous_branches/Ohana/src/relastro/src/initialize.c
r24308 r27840 5 5 int NPHOTCODES; 6 6 char *codename, *ptr, *list; 7 8 ptr = NULL; 7 9 8 10 ConfigInit (&argc, argv); -
branches/simtest_nebulous_branches/Ohana/src/relastro/src/load_images.c
r12332 r27840 1 1 # include "relastro.h" 2 3 # define MARKTIME(MSG,...) { \ 4 float dtime; \ 5 gettimeofday (&stop, (void *) NULL); \ 6 dtime = DTIME (stop, start); \ 7 fprintf (stderr, MSG, __VA_ARGS__); } 2 8 3 9 SkyList *load_images (FITS_DB *db, SkyRegion *region) { 4 10 5 11 Image *image, *subset; 6 int Nimage, Nsubset; 7 int *LineNumber; 12 off_t Nimage, Nsubset; 13 off_t *LineNumber; 14 struct timeval start, stop; 8 15 9 16 SkyTable *sky = NULL; 10 17 SkyList *skylist = NULL; 11 18 19 gettimeofday (&start, (void *) NULL); 20 12 21 // load the current sky table (layout of all SkyRegions) 13 sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, SKY_DEPTH, VERBOSE);22 sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, TRUE, SKY_DEPTH, VERBOSE); 14 23 SkyTableSetFilenames (sky, CATDIR, "cpt"); 15 24 16 25 // determine the populated SkyRegions overlapping the requested area 17 skylist = SkyListByPatch (sky, -1, region); 26 if (UserCatalog) { 27 skylist = SkyRegionByPoint (sky, -1, UserCatalogRA, UserCatalogDEC); 28 } else { 29 skylist = SkyListByPatch (sky, -1, region); 30 } 31 MARKTIME(" setup sky: %f sec\n", dtime); 18 32 19 33 // convert database table to internal structure 20 34 image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped); 35 MARKTIME(" convert image table: %f sec\n", dtime); 21 36 22 37 // select the images which overlap the selected sky regions 23 38 subset = select_images (skylist, image, Nimage, &LineNumber, &Nsubset); 39 MARKTIME(" select images: %f sec\n", dtime); 24 40 25 41 gfits_vtable_from_ftable (&db[0].ftable, &db[0].vtable, LineNumber, Nsubset); 26 42 27 43 initImages (subset, Nsubset); 44 MARKTIME(" init images: %f sec\n", dtime); 45 28 46 initMosaics (subset, Nsubset); 47 MARKTIME(" init mosaics: %f sec\n", dtime); 29 48 30 49 /* unlock, if we can (else, unlocked below) */ -
branches/simtest_nebulous_branches/Ohana/src/relastro/src/mkpolyterm.c
r16810 r27840 73 73 if (dPos > dPosRef) { 74 74 fprintf (stderr, "*** warning : non-convergence in model conversion (mkpolyterm.c;73) *** \n"); 75 return FALSE; 75 76 } 76 77 array_free (alpha, 2); -
branches/simtest_nebulous_branches/Ohana/src/relastro/src/plotstuff.c
r17203 r27840 125 125 if (PLOTDELAY > 500000) { 126 126 fprintf (stdout, "press return\n"); 127 fscanf (stdin, "%*c");127 if (fscanf (stdin, "%*c") != 0) fprintf (stderr, "\n"); 128 128 } else { 129 129 usleep (PLOTDELAY); -
branches/simtest_nebulous_branches/Ohana/src/relastro/src/relastro.c
r17243 r27840 1 1 # include "relastro.h" 2 3 # define MARKTIME(MSG,...) { \ 4 float dtime; \ 5 gettimeofday (&stop, (void *) NULL); \ 6 dtime = DTIME (stop, start); \ 7 fprintf (stderr, MSG, __VA_ARGS__); } 2 8 3 9 int main (int argc, char **argv) { 4 10 5 int status, Ncatalog;11 int i, status, Ncatalog; 6 12 Catalog *catalog; 7 13 FITS_DB db; 14 struct timeval start, stop; 15 SkyList *skylist = NULL; 8 16 9 SkyList *skylist = NULL;17 gettimeofday (&start, (void *) NULL); 10 18 11 19 /* get configuration info, args */ … … 26 34 if (db.dbstate == LCK_EMPTY) Shutdown ("ERROR: No images in catalog %s (1)", db.filename); 27 35 if (!dvo_image_load (&db, VERBOSE, FALSE)) Shutdown ("can't read image catalog %s", db.filename); 36 MARKTIME("load image data: %f sec\n", dtime); 28 37 29 38 /* load regions and images based on specified sky patch (default depth) */ 30 39 skylist = load_images (&db, &UserPatch); 40 MARKTIME("load images: %f sec\n", dtime); 41 42 initCoords(); 31 43 32 44 /* load catalog data from region files : subselect high-quality measurements */ 33 45 catalog = load_catalogs (skylist, &Ncatalog, TRUE); 46 MARKTIME("load catalog data: %f sec\n", dtime); 34 47 35 48 /* match measurements with images */ 36 initImageBins (catalog, Ncatalog); 37 findImages (catalog, Ncatalog); 49 initImageBins (catalog, Ncatalog, TRUE); 50 MARKTIME("make image bins: %f sec\n", dtime); 51 52 findImages (catalog, Ncatalog, TRUE); 53 MARKTIME("set up image indexes: %f sec\n", dtime); 38 54 39 55 if (PLOTSTUFF) { … … 45 61 switch (FIT_TARGET) { 46 62 case TARGET_SIMPLE: 47 UpdateSimple (catalog, Ncatalog); 63 for (i = 0; i < NLOOP; i++) { 64 UpdateObjects (catalog, Ncatalog); 65 UpdateSimple (catalog, Ncatalog); 66 } 48 67 break; 49 68 50 69 case TARGET_CHIPS: 51 UpdateChips (catalog, Ncatalog); 70 for (i = 0; i < NLOOP; i++) { 71 UpdateObjects (catalog, Ncatalog); 72 UpdateChips (catalog, Ncatalog); 73 MARKTIME("update chips: %f sec\n", dtime); 74 } 52 75 break; 53 76 54 77 case TARGET_MOSAICS: 55 UpdateMosaic (catalog, Ncatalog); 78 for (i = 0; i < NLOOP; i++) { 79 UpdateObjects (catalog, Ncatalog); 80 UpdateMosaic (catalog, Ncatalog); 81 } 56 82 break; 57 83 … … 69 95 UpdateObjectOffsets (skylist); 70 96 97 // iterate over catalogs to make detection coordinates consistant 98 FixProblemImages (skylist); 99 71 100 // save the updated image parameters 72 101 dvo_image_update (&db, VERBOSE); -
branches/simtest_nebulous_branches/Ohana/src/relastro/src/relastro_objects.c
r24308 r27840 11 11 12 12 // load the current sky table (layout of all SkyRegions) 13 sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, SKY_DEPTH, VERBOSE);13 sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, TRUE, SKY_DEPTH, VERBOSE); 14 14 SkyTableSetFilenames (sky, CATDIR, "cpt"); 15 15 16 16 // determine the populated SkyRegions overlapping the requested area (default depth) 17 skylist = SkyListByPatch (sky, -1, &UserPatch); 17 if (UserCatalog) { 18 skylist = SkyRegionByPoint (sky, -1, UserCatalogRA, UserCatalogDEC); 19 } else { 20 skylist = SkyListByPatch (sky, -1, &UserPatch); 21 } 18 22 19 23 // load data from each region file, only use bright stars -
branches/simtest_nebulous_branches/Ohana/src/relastro/src/select_images.c
r21508 r27840 13 13 } SkyRegionCoords; 14 14 15 Image *select_images (SkyList *skylist, Image *timage, int Ntimage, int **LineNumber, int *Nimage) { 15 void dsortindex (double *X, off_t *Y, int N); 16 off_t getRegionStartByRA (double R, double *Rref, off_t Nregions); 17 18 Image *select_images (SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage) { 16 19 17 20 Image *image; 18 int i, j, k, m, found, nimage, NIMAGE; 19 int InRange; 21 off_t i, j, k, m, nStart, iSky, nimage, NIMAGE; 22 off_t *line_number; 23 int InRange, found; 20 24 double Ri[5], Di[5], Xi[5], Yi[5], dx, dy; 21 int *line_number;22 25 Coords tcoords; 23 26 SkyRegionCoords *skycoords; 24 27 28 double *RmaxSky; 29 off_t *index; 30 25 31 if (skylist[0].Nregions < 1) { 26 32 *Nimage = 0; … … 38 44 39 45 ALLOCATE (skycoords, SkyRegionCoords, skylist[0].Nregions); 46 47 ALLOCATE (RmaxSky, double, skylist[0].Nregions); 48 ALLOCATE (index, off_t, skylist[0].Nregions); 40 49 41 50 /* compare with each region file */ … … 56 65 skycoords[i].Yc[4] = skycoords[i].Yc[0]; 57 66 67 RmaxSky[i] = skylist[0].regions[i][0].Rmax; 68 index[i] = i; 69 58 70 dx = 0.02*(skycoords[i].Xc[2] - skycoords[i].Xc[0]); 59 71 dy = 0.02*(skycoords[i].Yc[2] - skycoords[i].Yc[0]); … … 65 77 } 66 78 79 dsortindex (RmaxSky, index, skylist[0].Nregions); 80 67 81 if (VERBOSE) fprintf (stderr, "finding images\n"); 68 82 BuildChipMatch (timage, Ntimage); … … 71 85 NIMAGE = 100; 72 86 ALLOCATE (image, Image, NIMAGE); 73 ALLOCATE (line_number, int, NIMAGE);87 ALLOCATE (line_number, off_t, NIMAGE); 74 88 75 89 // go through the complete list of images, selecting ones which overlap any region … … 100 114 } 101 115 102 if (!FindMosaicForImage (timage, Ntimage, i)) continue; 116 if (!FindMosaicForImage (timage, Ntimage, i)) { 117 fprintf (stderr, "cannot find mosaic for %lld\n", (long long) i); 118 continue; 119 } 103 120 104 121 /* define image corners */ … … 110 127 found = FALSE; 111 128 112 /* transform to ra,dec */ 129 /* transform corners to ra,dec */ 130 double RminImage = 360.0; 113 131 for (j = 0; j < 5; j++) { 114 132 XY_to_RD (&Ri[j], &Di[j], Xi[j], Yi[j], &timage[i].coords); 115 } 133 RminImage = MIN(RminImage, Ri[j]); 134 } 135 136 // RA(nStart) is guaranteed to be < RminImage: 137 nStart = getRegionStartByRA (RminImage, RmaxSky, skylist[0].Nregions); 116 138 117 139 /* compare with each region file */ 118 for (m = 0; (m < skylist[0].Nregions) && !found; m++) { 140 for (iSky = nStart; (iSky < skylist[0].Nregions) && !found; iSky++) { 141 142 m = index[iSky]; 119 143 120 144 /* we make positional comparisons in the projection of catalog */ … … 122 146 tcoords.crval2 = skycoords[m].Dc; 123 147 124 /* transform to ra,dec*/148 /* transform corner coords to X,Y in this catalog system */ 125 149 InRange = TRUE; 126 150 for (j = 0; (j < 5) && InRange; j++) { … … 151 175 } 152 176 if (RESET) { 153 // XXX do we need this in relastro?177 // XXX do we need / want to do this in relastro? 154 178 assignMcal (&image[nimage], (double *) NULL, -1); 155 179 image[nimage].dMcal = NAN; … … 161 185 NIMAGE += 100; 162 186 REALLOCATE (image, Image, NIMAGE); 163 REALLOCATE (line_number, int, NIMAGE);187 REALLOCATE (line_number, off_t, NIMAGE); 164 188 } 165 189 } 166 190 } 167 191 168 if (VERBOSE) fprintf (stderr, "found % d images\n",nimage);192 if (VERBOSE) fprintf (stderr, "found %lld images\n", (long long) nimage); 169 193 170 194 REALLOCATE (image, Image, MAX (nimage, 1)); 171 REALLOCATE (line_number, int, MAX (nimage, 1));195 REALLOCATE (line_number, off_t, MAX (nimage, 1)); 172 196 free (skycoords); 173 197 … … 253 277 } 254 278 279 void dsortindex (double *X, off_t *Y, int N) { 280 281 # define SWAPFUNC(A,B){ double tmpf; off_t tmpi; \ 282 tmpf = X[A]; X[A] = X[B]; X[B] = tmpf; \ 283 tmpi = Y[A]; Y[A] = Y[B]; Y[B] = tmpi; \ 284 } 285 # define COMPARE(A,B)(X[A] < X[B]) 286 287 OHANA_SORT (N, COMPARE, SWAPFUNC); 288 289 # undef SWAPFUNC 290 # undef COMPARE 291 292 } 293 294 off_t getRegionStartByRA (double R, double *Rref, off_t Nregions) { 295 296 // use bisection to find the overlapping mosaic 297 298 off_t Nlo, Nhi, N; 299 300 // find the last mosaic before start 301 Nlo = 0; Nhi = Nregions; 302 while (Nhi - Nlo > 10) { 303 N = 0.5*(Nlo + Nhi); 304 if (Rref[N] < R) { 305 Nlo = MAX(N, 0); 306 } else { 307 Nhi = MIN(N, Nregions); 308 } 309 } 310 return (Nlo); 311 }
Note:
See TracChangeset
for help on using the changeset viewer.
