Changeset 33652
- Timestamp:
- Apr 1, 2012, 3:00:19 PM (14 years ago)
- Location:
- trunk/Ohana/src/relastro
- Files:
-
- 30 edited
- 5 copied
-
Makefile (modified) (4 diffs)
-
doc/parallel.txt (copied) (copied from branches/eam_branches/ipp-20111122/Ohana/src/relastro/doc/parallel.txt )
-
doc/plx_factor.pro (copied) (copied from branches/eam_branches/ipp-20111122/Ohana/src/relastro/doc/plx_factor.pro )
-
include/relastro.h (modified) (15 diffs)
-
src/BrightCatalog.c (copied) (copied from branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/BrightCatalog.c )
-
src/ConfigInit.c (modified) (2 diffs)
-
src/FitChip.c (modified) (10 diffs)
-
src/FixProblemImages.c (modified) (2 diffs)
-
src/GetAstromError.c (modified) (2 diffs)
-
src/ImageOps.c (modified) (31 diffs)
-
src/ParFactor.c (modified) (5 diffs)
-
src/StarMaps.c (modified) (2 diffs)
-
src/UpdateChips.c (modified) (7 diffs)
-
src/UpdateMeasures.c (modified) (1 diff)
-
src/UpdateObjectOffsets.c (modified) (4 diffs)
-
src/UpdateObjects.c (modified) (9 diffs)
-
src/args.c (modified) (11 diffs)
-
src/bcatalog.c (modified) (14 diffs)
-
src/dvo_astrom_ops.c (modified) (5 diffs)
-
src/fitpoly.c (modified) (1 diff)
-
src/high_speed_catalogs.c (modified) (4 diffs)
-
src/high_speed_objects.c (modified) (11 diffs)
-
src/high_speed_utils.c (modified) (8 diffs)
-
src/initialize.c (modified) (3 diffs)
-
src/load_catalogs.c (modified) (4 diffs)
-
src/load_images.c (modified) (5 diffs)
-
src/relastro.c (modified) (1 diff)
-
src/relastro_client.c (copied) (copied from branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/relastro_client.c )
-
src/relastro_images.c (copied) (copied from branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/relastro_images.c )
-
src/relastro_merge_source.c (modified) (4 diffs)
-
src/relastro_objects.c (modified) (5 diffs)
-
src/resort_catalog.c (modified) (1 diff)
-
src/save_catalogs.c (modified) (1 diff)
-
src/select_images.c (modified) (8 diffs)
-
src/testparallax.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/relastro/Makefile
r32346 r33652 1 default: relastro 1 default: relastro relastro_client 2 2 help: 3 3 @echo "make options: relastro (default)" … … 18 18 19 19 relastro: $(BIN)/relastro.$(ARCH) 20 install: $(DESTBIN)/relastro 20 relastro_client: $(BIN)/relastro_client.$(ARCH) 21 22 install: $(DESTBIN)/relastro $(DESTBIN)/relastro_client $(DESTBIN)/testparallax 21 23 22 24 RELASTRO = \ … … 53 55 $(SRC)/select_images.$(ARCH).o \ 54 56 $(SRC)/relastro.$(ARCH).o \ 57 $(SRC)/relastro_images.$(ARCH).o \ 55 58 $(SRC)/relastro_objects.$(ARCH).o \ 56 59 $(SRC)/save_catalogs.$(ARCH).o \ 57 $(SRC)/write_coords.$(ARCH).o \58 60 $(SRC)/CoordOps.$(ARCH).o \ 59 61 $(SRC)/FixProblemImages.$(ARCH).o \ … … 64 66 $(SRC)/relastro_merge_source.$(ARCH).o \ 65 67 $(SRC)/resort_catalog.$(ARCH).o \ 68 $(SRC)/BrightCatalog.$(ARCH).o \ 66 69 $(SRC)/relastroVisual.$(ARCH).o 67 70 68 $(RELASTRO): $(INC)/relastro.h $(KAPA_INCS) 69 $(BIN)/relastro.$(ARCH): $(RELASTRO) $(KAPA_LIBS) 71 #$(SRC)/write_coords.$(ARCH).o \ 72 73 $(RELASTRO): $(INC)/relastro.h 74 $(BIN)/relastro.$(ARCH): $(RELASTRO) 75 76 RELASTRO_CLIENT = \ 77 $(SRC)/ConfigInit.$(ARCH).o \ 78 $(SRC)/FitPM.$(ARCH).o \ 79 $(SRC)/FitPar.$(ARCH).o \ 80 $(SRC)/FitPMandPar.$(ARCH).o \ 81 $(SRC)/FitSimple.$(ARCH).o \ 82 $(SRC)/ImageOps.$(ARCH).o \ 83 $(SRC)/MosaicOps.$(ARCH).o \ 84 $(SRC)/ParFactor.$(ARCH).o \ 85 $(SRC)/SetSignals.$(ARCH).o \ 86 $(SRC)/Shutdown.$(ARCH).o \ 87 $(SRC)/UpdateObjects.$(ARCH).o \ 88 $(SRC)/UpdateObjectOffsets.$(ARCH).o \ 89 $(SRC)/UpdateMeasures.$(ARCH).o \ 90 $(SRC)/GetAstromError.$(ARCH).o \ 91 $(SRC)/args.$(ARCH).o \ 92 $(SRC)/bcatalog.$(ARCH).o \ 93 $(SRC)/dvo_astrom_ops.$(ARCH).o \ 94 $(SRC)/fitpoly.$(ARCH).o \ 95 $(SRC)/initialize.$(ARCH).o \ 96 $(SRC)/liststats.$(ARCH).o \ 97 $(SRC)/load_catalogs.$(ARCH).o \ 98 $(SRC)/load_images.$(ARCH).o \ 99 $(SRC)/mkpolyterm.$(ARCH).o \ 100 $(SRC)/select_images.$(ARCH).o \ 101 $(SRC)/relastro_client.$(ARCH).o \ 102 $(SRC)/relastro_objects.$(ARCH).o \ 103 $(SRC)/save_catalogs.$(ARCH).o \ 104 $(SRC)/CoordOps.$(ARCH).o \ 105 $(SRC)/high_speed_catalogs.$(ARCH).o \ 106 $(SRC)/high_speed_objects.$(ARCH).o \ 107 $(SRC)/high_speed_utils.$(ARCH).o \ 108 $(SRC)/relastro_merge_source.$(ARCH).o \ 109 $(SRC)/resort_catalog.$(ARCH).o \ 110 $(SRC)/plot_scatter.$(ARCH).o \ 111 $(SRC)/plotstuff.$(ARCH).o \ 112 $(SRC)/relastroVisual.$(ARCH).o \ 113 $(SRC)/BrightCatalog.$(ARCH).o 114 115 #$(SRC)/FitChip.$(ARCH).o \ 116 #$(SRC)/FitMosaic.$(ARCH).o \ 117 #$(SRC)/UpdateChips.$(ARCH).o \ 118 #$(SRC)/UpdateMosaic.$(ARCH).o \ 119 #$(SRC)/UpdateSimple.$(ARCH).o \ 120 #$(SRC)/write_coords.$(ARCH).o \ 121 #$(SRC)/FixProblemImages.$(ARCH).o \ 122 #$(SRC)/StarMaps.$(ARCH).o \ 123 124 $(RELASTRO_CLIENT): $(INC)/relastro.h 125 $(BIN)/relastro_client.$(ARCH): $(RELASTRO_CLIENT) 126 127 testparallax: $(BIN)/testparallax.$(ARCH) 128 129 TESTPAR = \ 130 $(SRC)/FitPMandPar.$(ARCH).o \ 131 $(SRC)/ParFactor.$(ARCH).o \ 132 $(SRC)/fitpoly.$(ARCH).o \ 133 $(SRC)/mkpolyterm.$(ARCH).o \ 134 $(SRC)/testparallax.$(ARCH).o 135 136 $(TESTPAR): $(INC)/relastro.h 137 $(BIN)/testparallax.$(ARCH): $(TESTPAR) -
trunk/Ohana/src/relastro/include/relastro.h
r32740 r33652 4 4 # include <signal.h> 5 5 # include <assert.h> 6 # include <pthread.h> 7 8 // choose off_t or int depending on full-scale relphot analysis resources 9 // # define IDX_T off_t 10 # define IDX_T int 6 11 7 12 typedef enum { … … 15 20 typedef enum {FIT_NONE, FIT_AVERAGE, FIT_PM_ONLY, FIT_PAR_ONLY, FIT_PM_AND_PAR} FitMode; 16 21 17 typedef enum {TARGET_NONE, TARGET_OBJECTS, TARGET_SIMPLE, TARGET_CHIPS, TARGET_MOSAICS, TARGET_HIGH_SPEED, TARGET_MERGE_SOURCE} FitTarget; 22 typedef enum {TARGET_NONE, TARGET_SIMPLE, TARGET_CHIPS, TARGET_MOSAICS, TARGET_HIGH_SPEED, TARGET_MERGE_SOURCE, TARGET_UPDATE_OBJECTS, TARGET_UPDATE_OFFSETS, TARGET_LOAD_OBJECTS} FitTarget; 23 24 typedef enum { 25 MARK_MEAS_DEFAULT = 0x0000, 26 MARK_TOO_FEW_MEAS = 0x0001, 27 MARK_NAN_POS_ERROR = 0x0002, 28 MARK_NAN_MAG_ERROR = 0x0004, 29 MARK_BIG_MAG_ERROR = 0x0008, 30 MARK_BIG_OFFSET = 0x0010, 31 } MeasurementMask; 32 33 typedef struct { 34 Average *average; // array of (minimal) average data 35 MeasureTiny *measure; // array of (minimal) measure data 36 SecFilt *secfilt; // array of secfilt data (matched to average by Nsecfilt) 37 off_t Naverage; 38 off_t Nmeasure; 39 } BrightCatalog; 40 41 typedef struct { 42 Catalog *catalog; // array of catalogs generated 43 int NCATALOG; // number of catalogs allocated 44 int Ncatalog; // number of catalogs generated 45 int Nsecfilt; // number of catalogs generated 46 off_t *NAVERAGE; // allocated Averages per catalog 47 off_t *NMEASURE; // allocated Measures per catalog 48 int *index; // lookup table catID -> catalog[i] 49 int *catIDs; // lookup table catID <- catalog[i] 50 int maxID; // max catID value to date 51 } CatalogSplitter; 18 52 19 53 typedef struct { … … 86 120 87 121 /* global variables set in parameter file */ 88 char ImageCat[256]; 89 char GSCFILE[256]; 90 char CATDIR[256]; 122 # define MAX_PATH_LENGTH 1024 123 char ImageCat[MAX_PATH_LENGTH]; 124 char GSCFILE[MAX_PATH_LENGTH]; 125 char CATDIR[MAX_PATH_LENGTH]; 91 126 char *HIGH_SPEED_DIR; 92 127 char CATMODE[16]; /* raw, mef, split, mysql */ 93 128 char CATFORMAT[16]; /* internal, elixir, loneos, panstarrs */ 94 char SKY_TABLE[ 256];129 char SKY_TABLE[MAX_PATH_LENGTH]; 95 130 int SKY_DEPTH; /** XXX EAM : depth of catalog tables, fix usage */ 131 132 int HOST_ID; 133 char *HOSTDIR; 134 char *BCATALOG; 96 135 97 136 unsigned int OBJ_ID_SRC; … … 110 149 double RADIUS; // match radius for high-speed objects 111 150 151 int PARALLEL; 152 int PARALLEL_MANUAL; 153 int PARALLEL_SERIAL; 154 155 int PARALLEL_OUTPUT; 156 112 157 int VERBOSE; 113 158 int VERBOSE2; … … 115 160 int RESET; 116 161 int NLOOP; 162 int NTHREADS; 117 163 int UPDATE; 118 164 int PLOTSTUFF; … … 123 169 int PM_TOOFEW; 124 170 double PM_DT_MIN; 171 double PAR_FACTOR_MIN; 125 172 int PLOTDELAY; 126 173 int CHIPORDER; … … 128 175 int MaxDensityUse; 129 176 double MaxDensityValue; 130 131 int UserCatalog;132 double UserCatalogRA, UserCatalogDEC;133 177 134 178 char *PHOTCODE_KEEP_LIST, *PHOTCODE_SKIP_LIST; … … 142 186 SkyRegionSelection SELECTION; 143 187 144 int AreaSelect; 145 double AreaXmin, AreaXmax, AreaYmin, AreaYmax; 146 147 int ImagSelect, ImagMin, ImagMax; 188 int ImagSelect; 189 double ImagMin, ImagMax; 148 190 149 191 double PlotMmin, PlotMmax, PlotdMmin, PlotdMmax; 150 192 151 int DophotSelect, DophotValue;152 193 int PhotFlagSelect, PhotFlagPoor, PhotFlagBad; 153 194 … … 181 222 char *GetPhotnamebyCode PROTO((PhotCodeData *photcodes, int code)); 182 223 void InterpolateGrid PROTO((float *buffer, int Nx, int Ny, Coords *ccd, Coords *gcoords)); 183 off_t *SelectRefMosaic PROTO((Mosaic **refmosaic, off_t *Nimage));224 off_t *SelectRefMosaic PROTO((Mosaic **refmosaic, off_t *Nimage)); 184 225 int args PROTO((int argc, char **argv)); 226 int args_client PROTO((int argc, char **argv)); 185 227 int bcatalog PROTO((Catalog *subcatalog, Catalog *catalog)); 186 228 void clean_images PROTO((void)); … … 226 268 void initMrel PROTO((Catalog *catalog, int Ncatalog)); 227 269 void initialize PROTO((int argc, char **argv)); 270 void initialize_client PROTO((int argc, char **argv)); 228 271 void initstats PROTO((char *mode)); 229 272 int liststats PROTO((double *value, double *dvalue, int N, StatType *stats)); 230 Catalog *load_catalogs PROTO((SkyList *skylist, int *Ncatalog, int subselect ));231 SkyList *load_images PROTO((FITS_DB *db, SkyRegion *region));273 Catalog *load_catalogs PROTO((SkyList *skylist, int *Ncatalog, int subselect, int hostID, char *hostpath)); 274 int load_images PROTO((FITS_DB *db, SkyList *skylist)); 232 275 Image *select_images PROTO((SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage)); 233 276 … … 314 357 void FlagOutliers(Catalog *catalog); 315 358 int MeasFilterTest(Measure *measure, int applySigmaLim); 359 int MeasFilterTestTiny(MeasureTiny *measure, int applySigmaLim); 316 360 317 361 int sun_ecliptic (double jd, double *lambda, double *beta, double *epsilon, double *Radius); … … 333 377 Mosaic *getMosaicForImage (off_t im); 334 378 335 double getMeanR (Measure *measure, Average *average, SecFilt *secfilt); 336 double getMeanD (Measure *measure, Average *average, SecFilt *secfilt); 337 int setMeanR (double ra_fit, Measure *measure, Average *average, SecFilt *secfilt); 338 int setMeanD (double dec_fit, Measure *measure, Average *average, SecFilt *secfilt); 379 double getMeanR (MeasureTiny *measure, Average *average, SecFilt *secfilt); 380 double getMeanD (MeasureTiny *measure, Average *average, SecFilt *secfilt); 381 int setMeanR (double ra_fit, MeasureTiny *measure, Average *average, SecFilt *secfilt); 382 int setMeanD (double dec_fit, MeasureTiny *measure, Average *average, SecFilt *secfilt); 383 int setMeanR_Big (double ra_fit, Measure *measure, Average *average, SecFilt *secfilt); 384 int setMeanD_Big (double dec_fit, Measure *measure, Average *average, SecFilt *secfilt); 339 385 340 386 float GetAstromError (Measure *measure, int mode); 341 int relastro_objects (void); 342 int UpdateObjectOffsets (SkyList *skylist); 387 float GetAstromErrorTiny (MeasureTiny *measure, int mode); 388 int relastro_objects (SkyList *skylist, int hostID, char *hostpath); 389 int relastro_images (SkyList *skylist); 390 int UpdateObjectOffsets (SkyList *skylist, int hostID, char *hostpath); 343 391 344 392 int relastroVisualPlotChipFit(StarData *raw, StarData *ref, double dRmax, int numObj); … … 361 409 void resetImageRaw (Catalog *catalog, int Ncatalog, off_t im); 362 410 363 int high_speed_catalogs ( );411 int high_speed_catalogs (SkyTable *sky, SkyList *skylist, int hostID, char *hostpath); 364 412 int high_speed_objects (SkyRegion *region, Catalog *catalog); 365 413 int MeasMatchesPhotcode(Measure *measure, PhotCode **photcodeSet, int Nset); … … 369 417 int createStarMapPoints(); 370 418 int checkStarMap(int N); 419 int createStarMap (Catalog *catalog, int Ncatalog); 371 420 372 421 int GetScatterRawRef(float *dLsig, float *dMsig, float *dRsig, int *nKeep, StarData *raw, StarData *ref, int Nstars, float SigmaLimit); 373 int LimitDensityCatalog (Catalog *subcatalog, Catalog *catalog); 422 int LimitDensityCatalog_ByNmeasure (Catalog *subcatalog, Catalog *catalog); 423 int LimitDensityCatalog_RandomSample (Catalog *subcatalog, Catalog *catalog); 374 424 375 425 int initializeConstraints(); … … 378 428 void setupAreaSelection(SkyRegion *region); 379 429 380 int relastro_merge_source ( );430 int relastro_merge_source (SkyTable *sky); 381 431 void resort_catalog (Catalog *catalog); 432 433 BrightCatalog *BrightCatalogLoad(char *filename); 434 int BrightCatalogSave(char *filename, BrightCatalog *catalog); 435 BrightCatalog *BrightCatalogMerge (Catalog *catalog, int Ncatalog); 436 CatalogSplitter *BrightCatalogSplitInit (int Nsecfilt); 437 int BrightCatalogSplit (CatalogSplitter *catalogs, BrightCatalog *bcatalog); 438 int BrightCatalogSplitFree (CatalogSplitter *catalogs); 439 440 PhotCode **ParsePhotcodeList (char *rawlist, int *nphotcodes, int needAve); -
trunk/Ohana/src/relastro/src/ConfigInit.c
r31635 r33652 26 26 if (!ScanConfig (config, "RELASTRO_IMFIT_SYS_SIGMA_LIM", "%lf", 0, &IMFIT_SYS_SIGMA_LIM)) IMFIT_SYS_SIGMA_LIM = 0.01; 27 27 28 // XXX these are used in relphot to identify poor stars / images -- define29 // an equivalent concept here?30 // GetConfig (config, "STAR_SCATTER", "%lf", 0, &STAR_SCATTER);31 // GetConfig (config, "IMAGE_SCATTER", "%lf", 0, &IMAGE_SCATTER);32 // GetConfig (config, "IMAGE_OFFSET", "%lf", 0, &IMAGE_OFFSET);33 // GetConfig (config, "STAR_CHISQ", "%lf", 0, &STAR_CHISQ);34 35 28 GetConfig (config, "PM_DT_MIN", "%lf", 0, &PM_DT_MIN); 36 29 GetConfig (config, "PM_TOOFEW", "%d", 0, &PM_TOOFEW); 37 30 GetConfig (config, "POS_TOOFEW", "%d", 0, &POS_TOOFEW); 31 32 GetConfig (config, "PAR_FACTOR_MIN", "%lf", 0, &PAR_FACTOR_MIN); 38 33 39 34 GetConfig (config, "RELASTRO_MAP_NX", "%d", 0, &NX_MAP); … … 42 37 GetConfig (config, "ADDSTAR_RADIUS", "%lf", 0, &ADDSTAR_RADIUS); 43 38 39 // force CATDIR to be absolute (so parallel mode will work) 40 GetConfig (config, "CATDIR", "%s", 0, CATDIR); 41 char *tmpcatdir = abspath (CATDIR, MAX_PATH_LENGTH); 42 strcpy (CATDIR, tmpcatdir); 43 free (tmpcatdir); 44 44 45 GetConfig (config, "GSCFILE", "%s", 0, GSCFILE); 45 GetConfig (config, "CATDIR", "%s", 0, CATDIR);46 46 ScanConfig(config, "CATMODE", "%s", 0, CATMODE); 47 47 ScanConfig(config, "CATFORMAT", "%s", 0, CATFORMAT); -
trunk/Ohana/src/relastro/src/FitChip.c
r30616 r33652 4 4 int FitChip (StarData *raw, StarData *ref, int Nmatch, Image *image) { 5 5 6 int i, NstatFull, Nstat, Niter , skip;6 int i, NstatFull, Nstat, Niter; 7 7 float dLsig, dMsig, dRsig; 8 8 float dLsigFull, dMsigFull, dRsigFull; … … 27 27 if (raw[i].mask) continue; 28 28 if (isnan(raw[i].dMag)) { 29 raw[i].mask |= 0x0004;29 raw[i].mask |= MARK_NAN_MAG_ERROR; 30 30 continue; 31 31 } 32 32 if (raw[i].dMag > SIGMA_LIM) { 33 raw[i].mask |= 0x0008;33 raw[i].mask |= MARK_BIG_MAG_ERROR; 34 34 continue; 35 35 } // is this redundant with ImageOps.c:915? … … 39 39 dR = hypot (dL, dM); 40 40 if (dR > dRmax) { 41 raw[i].mask |= 0x0010;41 raw[i].mask |= MARK_BIG_OFFSET; 42 42 continue; 43 43 } … … 52 52 // fit the requested order polynomial 53 53 if (CHIPORDER > 0) { 54 image[0].coords.Npolyterms = CHIPORDER; 55 } 54 int Ndof_min = 3; 55 int order_max = 0.5*(sqrt(4*Nmatch - 4*Ndof_min + 1) - 3); 56 int order_use = MIN (CHIPORDER, order_max); 57 if (order_use < 1) { 58 if (VERBOSE2) fprintf (stderr, "insufficient measurements (%d) for linear fit\n", Nmatch); 59 image[0].flags |= ID_IMAGE_ASTROM_FEW; 60 return FALSE; 61 } 62 image[0].coords.Npolyterms = order_use; 63 } 64 56 65 if (fit) fit_free (fit); 57 66 fit = fit_init (image[0].coords.Npolyterms); … … 63 72 } 64 73 74 # if (0) 65 75 // check if the fit has enough data points for the polynomial order 66 76 skip = FALSE; … … 86 96 return FALSE; 87 97 } 98 # endif 88 99 89 100 // measure the fit, update the coords & object coordinates … … 91 102 fprintf (stderr, "failed to fit new model\n"); 92 103 image[0].flags |= ID_IMAGE_ASTROM_FAIL; 104 if (fit) fit_free (fit); 93 105 return FALSE; 94 106 } … … 97 109 fprintf (stderr, "failed to fit new model\n"); 98 110 image[0].flags |= ID_IMAGE_ASTROM_FAIL; 111 if (fit) fit_free (fit); 99 112 return FALSE; 100 113 } … … 114 127 for (i = 0; i < Nmatch; i++) { 115 128 if (!raw[i].mask) continue; 116 if (raw[i].mask & 0x01) nMask1 ++;117 if (raw[i].mask & 0x02) nMask2 ++;118 if (raw[i].mask & 0x04) nMask3 ++;119 if (raw[i].mask & 0x08) nMask4 ++;120 if (raw[i].mask & 0x10) nMask5 ++;129 if (raw[i].mask & MARK_TOO_FEW_MEAS ) nMask1 ++; 130 if (raw[i].mask & MARK_NAN_POS_ERROR) nMask2 ++; 131 if (raw[i].mask & MARK_NAN_MAG_ERROR) nMask3 ++; 132 if (raw[i].mask & MARK_BIG_MAG_ERROR) nMask4 ++; 133 if (raw[i].mask & MARK_BIG_OFFSET ) nMask5 ++; 121 134 } 122 135 123 136 GetScatterRawRef(&dLsigFull, &dMsigFull, &dRsigFull, &NstatFull, raw, ref, Nmatch, SIGMA_LIM); 124 GetScatterRawRef(&dLsig, &dMsig, &dRsig, &Nstat,raw, ref, Nmatch, IMFIT_SYS_SIGMA_LIM);137 GetScatterRawRef(&dLsig, &dMsig, &dRsig, &Nstat, raw, ref, Nmatch, IMFIT_SYS_SIGMA_LIM); 125 138 126 139 int Nm = 0; … … 133 146 image[0].nLinkAstrom = (Nm / Ns); 134 147 135 if (VERBOSE ) fprintf (stderr, "fit sigma: %f (%f, %f) : full: %f (%f, %f), scatter limit: %f (%d full, %d bright, %d fit, %d all) (%d %d %d %d %d)\n", dRsig, dLsig, dMsig, dRsigFull, dLsigFull, dMsigFull, dRmax, NstatFull, Nstat, fit[0].Npts, Nmatch, nMask1, nMask2, nMask3, nMask4, nMask5);148 if (VERBOSE2) fprintf (stderr, "fit sigma: %f (%f, %f) : full: %f (%f, %f), scatter limit: %f (%d full, %d bright, %d fit, %d all) (%d %d %d %d %d)\n", dRsig, dLsig, dMsig, dRsigFull, dLsigFull, dMsigFull, dRmax, NstatFull, Nstat, fit[0].Npts, Nmatch, nMask1, nMask2, nMask3, nMask4, nMask5); 136 149 137 150 image[0].dXpixSys = dLsig; -
trunk/Ohana/src/relastro/src/FixProblemImages.c
r32346 r33652 5 5 6 6 int FixProblemImages (SkyList *skylist) { 7 8 fprintf (stderr, "this function is currently not used : check on change from measure -> measureT in load_catalogs\n"); 9 abort(); 7 10 8 11 int Nbad; … … 64 67 } 65 68 66 catalog = load_catalogs (&sublist, &Ncat, FALSE); 69 // XXX use a different function here 70 // catalog = load_catalogs (&sublist, &Ncat, FALSE); 67 71 assert (Ncat == Ncatlist); 68 72 -
trunk/Ohana/src/relastro/src/GetAstromError.c
r30616 r33652 1 1 # include "relastro.h" 2 2 # define WEIGHTED_ERRORS 1 3 4 float GetAstromErrorTiny (MeasureTiny *measure, int mode) { 5 6 PhotCode *code; 7 float dPobs, dPsys, dPtotal, dM, AS, MS, dX, dY; 8 9 if (!WEIGHTED_ERRORS) { 10 // if we don't understand the errors at all, this at least lets us get things roughly 11 // right: 12 return 0.1; 13 } 14 15 switch (mode) { 16 case ERROR_MODE_RA: 17 dPobs = FromShortPixels(measure[0].dXccd); // dXccd is a value in pixels 18 break; 19 case ERROR_MODE_DEC: 20 dPobs = FromShortPixels(measure[0].dYccd); // dYccd is a value in pixels 21 break; 22 case ERROR_MODE_POS: 23 dX = FromShortPixels(measure[0].dXccd); // dXccd is a value in pixels 24 dY = FromShortPixels(measure[0].dYccd); // dYccd is a value in pixels 25 dPobs = hypot (dX, dY); 26 break; 27 default: 28 abort(); 29 } 30 31 code = GetPhotcodebyCode (measure[0].photcode); 32 33 // do not raise an exception, just send back the result 34 if (isnan(code[0].astromErrSys)) return NAN; 35 36 AS = code[0].astromErrScale; 37 MS = code[0].astromErrMagScale; 38 dPsys = code[0].astromErrSys; 39 dM = measure[0].dM; 40 dPtotal = sqrt(SQ(dPsys) + SQ(AS*dPobs) + SQ(MS*dM)); 41 42 dPtotal = MAX (dPtotal, MIN_ERROR); 43 return (dPtotal); 44 } 3 45 4 46 float GetAstromError (Measure *measure, int mode) { … … 30 72 31 73 code = GetPhotcodebyCode (measure[0].photcode); 74 75 // do not raise an exception, just send back the result 76 if (isnan(code[0].astromErrSys)) return NAN; 77 32 78 AS = code[0].astromErrScale; 33 79 MS = code[0].astromErrMagScale; -
trunk/Ohana/src/relastro/src/ImageOps.c
r32695 r33652 3 3 # define USE_IMAGE_ID 1 4 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 5 // we have an array of images: image[ImageIndex] (ImageIndex : 0 < Nimage) 11 6 static Image *image; // list of available images 12 7 static off_t Nimage; // number of available images 8 9 // if we read only a subset of the rows from the Image FITS, LineNumber tells us to which row 10 // each image belongs 13 11 static off_t *LineNumber; // match of subset to full image table 14 12 15 static int *Ncatlist; // catalogs associated with each image 16 static int *NCATLIST; // catalogs associated with each image 13 static off_t *N_onImage; // number of measurements on image 14 static off_t *N_ONIMAGE; // allocated number of measurements on image 15 16 static int *Ncatlist; // catalogs associated with each image 17 static int *NCATLIST; // catalogs associated with each image 17 18 static int **catlist; // catalogs associated with each image 19 20 static IDX_T **MeasureToImage; // link from catalog,measure to image 21 static IDX_T **ImageToCatalog; // catalog which supplied measurement on image 22 static IDX_T **ImageToMeasure; // measure reference for measurement on image 18 23 19 24 // if we search by image ID, we sort (imageIDs, imageIdx) by imageIDs to get a sorted … … 28 33 # endif 29 34 35 // MeasureToImage was 'bin' 36 // ImageToCatalog was 'clist' 37 // ImageToMeasure was 'mlist' 38 39 // N_onImage was 'Nlist' 40 // N_ONIMAGE was 'NLIST' 41 30 42 Image *getimages (off_t *N, off_t **line_number) { 31 43 … … 105 117 off_t i, j; 106 118 107 ALLOCATE ( bin, off_t*, Ncatalog);119 ALLOCATE (MeasureToImage, IDX_T *, Ncatalog); 108 120 for (i = 0; i < Ncatalog; i++) { 109 ALLOCATE ( bin[i], off_t, MAX (catalog[i].Nmeasure, 1));110 for (j = 0; j < catalog[i].Nmeasure; j++) bin[i][j] = -1;111 } 112 113 ALLOCATE (N list, off_t, Nimage);114 ALLOCATE (N LIST, off_t, Nimage);115 ALLOCATE ( clist, int*, Nimage);116 ALLOCATE ( mlist, off_t*, Nimage);121 ALLOCATE (MeasureToImage[i], IDX_T, MAX (catalog[i].Nmeasure, 1)); 122 for (j = 0; j < catalog[i].Nmeasure; j++) MeasureToImage[i][j] = -1; 123 } 124 125 ALLOCATE (N_onImage, off_t, Nimage); 126 ALLOCATE (N_ONIMAGE, off_t, Nimage); 127 ALLOCATE (ImageToCatalog, IDX_T *, Nimage); 128 ALLOCATE (ImageToMeasure, IDX_T *, Nimage); 117 129 118 130 for (i = 0; i < Nimage; i++) { 119 N list[i] = 0;120 N LIST[i] = 100;121 clist[i] = NULL; // we allocate these iff they are needed in matchImage122 mlist[i] = NULL; // we allocate these iff they are needed in matchImage131 N_onImage[i] = 0; 132 N_ONIMAGE[i] = 30; 133 ImageToCatalog[i] = NULL; // we allocate these iff they are needed in matchImage 134 ImageToMeasure[i] = NULL; // we allocate these iff they are needed in matchImage 123 135 } 124 136 … … 141 153 142 154 for (i = 0; i < Ncatalog; i++) { 143 free ( bin[i]);144 } 145 free ( bin);155 free (MeasureToImage[i]); 156 } 157 free (MeasureToImage); 146 158 for (i = 0; i < Nimage; i++) { 147 if ( clist[i]) { free (clist[i]); }148 if ( mlist[i]) { free (mlist[i]); }149 } 150 free ( clist);151 free ( mlist);152 free (N list);153 free (N LIST);159 if (ImageToCatalog[i]) { free (ImageToCatalog[i]); } 160 if (ImageToMeasure[i]) { free (ImageToMeasure[i]); } 161 } 162 free (ImageToCatalog); 163 free (ImageToMeasure); 164 free (N_onImage); 165 free (N_ONIMAGE); 154 166 } 155 167 … … 169 181 } 170 182 171 for (i = 0; VERBOSE2 && (i < Nimage); i++) { 172 name = GetPhotcodeNamebyCode (image[i].photcode); 173 fprintf (stderr, "image "OFF_T_FMT" has "OFF_T_FMT" measures (%s, %s)\n", i, Nlist[i], 174 ohana_sec_to_date(image[i].tzero), name); 175 } 183 // watch for chips with few stars 184 int Nfew = 0; 185 int Nbad = 0; 186 for (i = 0; i < Nimage; i++) { 187 // ignore the PHU entries 188 if (!strcmp(&image[i].coords.ctype[4], "-DIS")) continue; 189 if (VERBOSE2 || (MATCHCAT && (N_onImage[i] < 20))) { 190 name = GetPhotcodeNamebyCode (image[i].photcode); 191 fprintf (stderr, "image "OFF_T_FMT" (%d, %s) has "OFF_T_FMT" of %d measures (%s, %s)", i, image[i].imageID, image[i].name, N_onImage[i], image[i].nstar, 192 ohana_sec_to_date(image[i].tzero), name); 193 if (N_onImage[i] < 20) { 194 fprintf (stderr, "*"); 195 Nfew ++; 196 } 197 if (N_onImage[i] < 15) { 198 fprintf (stderr, "*** warning ***"); 199 Nbad ++; 200 } 201 fprintf (stderr, "\n"); 202 } 203 } 204 fprintf (stderr, OFF_T_FMT" total images, %d with < 20 measurements, %d with < 15\n", Nimage, Nfew, Nbad); 176 205 } 177 206 … … 181 210 182 211 off_t idx, ID; 183 Measure *measure;212 MeasureTiny *measure; 184 213 int i, found; 185 214 186 measure = &catalog[cat].measure [meas];215 measure = &catalog[cat].measureT[meas]; 187 216 188 217 ID = measure[0].imageID; … … 194 223 195 224 // index for (catalog, measure) -> image 196 bin[cat][meas] = idx;225 MeasureToImage[cat][meas] = idx; 197 226 198 227 // if we need to allocate an image index table, do so here 199 if (! clist[idx]) {200 ALLOCATE ( clist[idx], int, NLIST[idx]);201 } 202 if (! mlist[idx]) {203 ALLOCATE ( mlist[idx], off_t, NLIST[idx]);228 if (!ImageToCatalog[idx]) { 229 ALLOCATE (ImageToCatalog[idx], IDX_T, N_ONIMAGE[idx]); 230 } 231 if (!ImageToMeasure[idx]) { 232 ALLOCATE (ImageToMeasure[idx], IDX_T, N_ONIMAGE[idx]); 204 233 } 205 234 206 235 // index for image, Nentry -> catalog 207 clist[idx][Nlist[idx]] = cat;236 ImageToCatalog[idx][N_onImage[idx]] = cat; 208 237 209 238 // index for image, Nentry -> measure 210 mlist[idx][Nlist[idx]] = meas;211 N list[idx] ++;212 213 if (N list[idx] == NLIST[idx]) {214 N LIST[idx] += 100;215 REALLOCATE ( clist[idx], int, NLIST[idx]);216 REALLOCATE ( mlist[idx], off_t, NLIST[idx]);239 ImageToMeasure[idx][N_onImage[idx]] = meas; 240 N_onImage[idx] ++; 241 242 if (N_onImage[idx] == N_ONIMAGE[idx]) { 243 N_ONIMAGE[idx] += 30; 244 REALLOCATE (ImageToCatalog[idx], IDX_T, N_ONIMAGE[idx]); 245 REALLOCATE (ImageToMeasure[idx], IDX_T, N_ONIMAGE[idx]); 217 246 } 218 247 … … 241 270 242 271 off_t i; 243 Measure *measure;244 245 measure = &catalog[cat].measure [meas];272 MeasureTiny *measure; 273 274 measure = &catalog[cat].measureT[meas]; 246 275 247 276 /* find the image that supplied this measurement */ … … 255 284 256 285 // index for (catalog, measure) -> image 257 bin[cat][meas] = i;286 MeasureToImage[cat][meas] = i; 258 287 259 288 // index for image, Nentry -> catalog 260 clist[i][Nlist[i]] = cat;289 ImageToCatalog[i][N_onImage[i]] = cat; 261 290 262 291 // index for image, Nentry -> measure 263 mlist[i][Nlist[i]] = meas;264 N list[i] ++;265 266 if (N list[i] == NLIST[i]) {267 N LIST[i] += 100;268 REALLOCATE ( clist[i], int, NLIST[i]);269 REALLOCATE ( mlist[i], off_t, NLIST[i]);292 ImageToMeasure[i][N_onImage[i]] = meas; 293 N_onImage[i] ++; 294 295 if (N_onImage[i] == N_ONIMAGE[i]) { 296 N_ONIMAGE[i] += 30; 297 REALLOCATE (ImageToCatalog[i], IDX_T, N_ONIMAGE[i]); 298 REALLOCATE (ImageToMeasure[i], IDX_T, N_ONIMAGE[i]); 270 299 } 271 300 return; … … 281 310 off_t i; 282 311 283 i = bin[cat][meas];312 i = MeasureToImage[cat][meas]; 284 313 if (i == -1) return (NULL); 285 314 return (&image[i].coords); … … 333 362 } 334 363 335 void dump_measures (Average *average, Measure *measure) {364 void dump_measures (Average *average, Measure *measure) { 336 365 337 366 off_t j, off; … … 402 431 } 403 432 404 for (i = 0; i < Nlist[im]; i++) { 405 m = mlist[im][i]; 406 c = clist[im][i]; 407 408 X = catalog[c].measure[m].Xccd; 409 Y = catalog[c].measure[m].Yccd; 410 n = catalog[c].measure[m].averef; 433 int NoffRAave = 0; int NoffRAori = 0; 434 int NoffDECave = 0; int NoffDECori = 0; 435 436 for (i = 0; i < N_onImage[im]; i++) { 437 m = ImageToMeasure[im][i]; 438 c = ImageToCatalog[im][i]; 439 440 Measure *measure = &catalog[c].measure[m]; 441 442 X = measure[0].Xccd; 443 Y = measure[0].Yccd; 444 n = measure[0].averef; 411 445 412 446 if (moscoords == NULL) { … … 428 462 // NOTE: This should never happen, or our StarMap tests are not working 429 463 if (fabs(dR) > 3.0*ADDSTAR_RADIUS) { 430 fprintf (stderr, "measurement is far from average location (R): %f %f (%f %f)\n", catalog[c].average[n].R, catalog[c].average[n].D, dR, dD); 431 dump_measures (&catalog[c].average[n], catalog[c].measure); 464 NoffRAave ++; 465 if (VERBOSE2) { 466 fprintf (stderr, "measurement is far from average location (R): %f %f (%f %f)\n", catalog[c].average[n].R, catalog[c].average[n].D, dR, dD); 467 dump_measures (&catalog[c].average[n], catalog[c].measure); 468 } 432 469 // abort (); 433 470 } 434 471 if (fabs(dD) > 3.0*ADDSTAR_RADIUS) { 435 fprintf (stderr, "measurement is far from average location (D): %f %f (%f %f)\n", catalog[c].average[n].R, catalog[c].average[n].D, dR, dD); 436 dump_measures (&catalog[c].average[n], catalog[c].measure); 472 NoffDECave ++; 473 if (VERBOSE2) { 474 fprintf (stderr, "measurement is far from average location (D): %f %f (%f %f)\n", catalog[c].average[n].R, catalog[c].average[n].D, dR, dD); 475 dump_measures (&catalog[c].average[n], catalog[c].measure); 476 } 437 477 // abort (); 438 478 } 439 479 440 480 // complain if the new location is far from the old location 441 if (fabs(catalog[c].measure[m].dR - dR) > DPOS_MAX_ASEC) { 442 fprintf (stderr, "measurement is far from original location (R): %f %f (%f %f)\n", catalog[c].average[n].R, catalog[c].average[n].D, dR, dD); 443 dump_measures (&catalog[c].average[n], catalog[c].measure); 481 if (fabs(catalog[c].measureT[m].dR - dR) > DPOS_MAX_ASEC) { 482 NoffRAori ++; 483 if (VERBOSE2) { 484 fprintf (stderr, "measurement is far from original location (R): %f %f (%f %f)\n", catalog[c].average[n].R, catalog[c].average[n].D, dR, dD); 485 dump_measures (&catalog[c].average[n], catalog[c].measure); 486 } 444 487 // abort(); 445 488 } 446 if (fabs(catalog[c].measure[m].dD - dD) > DPOS_MAX_ASEC) { 447 fprintf (stderr, "measurement is far from original location (D): %f %f (%f %f)\n", catalog[c].average[n].R, catalog[c].average[n].D, dR, dD); 448 dump_measures (&catalog[c].average[n], catalog[c].measure); 449 // abort(); 450 } 451 452 dPos += SQ(catalog[c].measure[m].dR - dR) + SQ(catalog[c].measure[m].dD - dD); 489 if (fabs(measure[0].dD - dD) > DPOS_MAX_ASEC) { 490 NoffDECori ++; 491 if (VERBOSE2) { 492 fprintf (stderr, "measurement is far from original location (D): %f %f (%f %f)\n", catalog[c].average[n].R, catalog[c].average[n].D, dR, dD); 493 dump_measures (&catalog[c].average[n], catalog[c].measure); 494 } // abort(); 495 } 496 497 dPos += SQ(measure[0].dR - dR) + SQ(measure[0].dD - dD); 453 498 nPos ++; 454 499 455 catalog[c].measure[m].dR = dR;456 catalog[c].measure[m].dD = dD;500 measure[0].dR = dR; 501 measure[0].dD = dD; 457 502 458 if ( catalog[c].measure[m].dR > +180.0*3600.0) {503 if (measure[0].dR > +180.0*3600.0) { 459 504 // average on high end of boundary, move star up 460 505 R += 360.0; 461 catalog[c].measure[m].dR = 3600.0*(catalog[c].average[n].R - R);462 } 463 if ( catalog[c].measure[m].dR < -180.0*3600.0) {506 measure[0].dR = 3600.0*(catalog[c].average[n].R - R); 507 } 508 if (measure[0].dR < -180.0*3600.0) { 464 509 // average on low end of boundary, move star down 465 510 R -= 360.0; 466 catalog[c].measure[m].dR = 3600.0*(catalog[c].average[n].R - R);511 measure[0].dR = 3600.0*(catalog[c].average[n].R - R); 467 512 } 468 513 469 514 // set the systematic error for this image: 470 catalog[c].measure[m].dRsys = ToShortPixels(dPosSys); 471 } 472 515 measure[0].dRsys = ToShortPixels(dPosSys); 516 } 517 518 int Noff = NoffRAave + NoffDECave + NoffRAori + NoffDECori; 519 if (VERBOSE && (Noff > 0)) fprintf (stderr, "Noff ave RA %d, Noff ave DEC %d, Noff ori RA %d, Noff ori DEC %d\n", NoffRAave, NoffDECave, NoffRAori, NoffDECori); 473 520 saveOffsets (dPos, nPos, im); 474 521 … … 487 534 Mosaic *mosaic; 488 535 Coords *moscoords, *imcoords, *oldcoords; 536 537 fprintf (stderr, "fix resetImageRaw wrt MeasureTiny\n"); 538 abort(); 489 539 490 540 // check if this image is bad and should be skipped … … 507 557 imcoords = &image[im].coords; 508 558 509 for (i = 0; i < Nlist[im]; i++) { 510 m = mlist[im][i]; 511 c = clist[im][i]; 512 513 X = catalog[c].measure[m].Xccd; 514 Y = catalog[c].measure[m].Yccd; 515 n = catalog[c].measure[m].averef; 559 for (i = 0; i < N_onImage[im]; i++) { 560 m = ImageToMeasure[im][i]; 561 c = ImageToCatalog[im][i]; 562 563 // XXX unclear if this should use Measure or MeasureTiny; it is only called by FixProblemImages, which has not been updated 564 Measure *measure = &catalog[c].measure[m]; 565 566 X = measure[0].Xccd; 567 Y = measure[0].Yccd; 568 n = measure[0].averef; 516 569 517 570 dR = dD = 0.0; … … 527 580 } 528 581 529 catalog[c].measure[m].dR = dR;530 catalog[c].measure[m].dD = dD;531 532 if ( catalog[c].measure[m].dR > +180.0*3600.0) {582 measure[0].dR = dR; 583 measure[0].dD = dD; 584 585 if (measure[0].dR > +180.0*3600.0) { 533 586 // average on high end of boundary, move star up 534 587 R += 360.0; 535 catalog[c].measure[m].dR = 3600.0*(catalog[c].average[n].R - R);536 } 537 if ( catalog[c].measure[m].dR < -180.0*3600.0) {588 measure[0].dR = 3600.0*(catalog[c].average[n].R - R); 589 } 590 if (measure[0].dR < -180.0*3600.0) { 538 591 // average on low end of boundary, move star down 539 592 R -= 360.0; 540 catalog[c].measure[m].dR = 3600.0*(catalog[c].average[n].R - R);593 measure[0].dR = 3600.0*(catalog[c].average[n].R - R); 541 594 } 542 595 } … … 567 620 } 568 621 569 ALLOCATE (raw, StarData, Nlist[im]); 570 571 for (i = 0; i < Nlist[im]; i++) { 572 m = mlist[im][i]; 573 c = clist[im][i]; 622 ALLOCATE (raw, StarData, N_onImage[im]); 623 624 for (i = 0; i < N_onImage[im]; i++) { 625 m = ImageToMeasure[im][i]; 626 c = ImageToCatalog[im][i]; 627 628 MeasureTiny *measure = &catalog[c].measureT[m]; 574 629 575 630 /* apply the current image transformation or use the current value of R+dR, D+dD? */ 576 raw[i].X = catalog[c].measure[m].Xccd;577 raw[i].Y = catalog[c].measure[m].Yccd;578 579 raw[i].Mag = catalog[c].measure[m].M;580 raw[i].dMag = catalog[c].measure[m].dM;581 raw[i].dPos = GetAstromError (&catalog[c].measure[m], ERROR_MODE_POS);582 583 n = catalog[c].measure[m].averef;631 raw[i].X = measure[0].Xccd; 632 raw[i].Y = measure[0].Yccd; 633 634 raw[i].Mag = measure[0].M; 635 raw[i].dMag = measure[0].dM; 636 raw[i].dPos = GetAstromErrorTiny (&measure[0], ERROR_MODE_POS); 637 638 n = measure[0].averef; 584 639 585 640 // an object with only one detection provides no information about the image calibration 586 641 // XXX this is already taken care of in bcatalog 587 raw[i].mask = 0x0000;642 raw[i].mask = MARK_MEAS_DEFAULT; 588 643 if (catalog[c].average[n].Nmeasure <= SRC_MEAS_TOOFEW) { 589 raw[i].mask |= 0x0001;590 } 591 if (!finite( catalog[c].measure[m].dR) || !finite(catalog[c].measure[m].dD)) {592 raw[i].mask |= 0x0002;644 raw[i].mask |= MARK_TOO_FEW_MEAS; 645 } 646 if (!finite(measure[0].dR) || !finite(measure[0].dD)) { 647 raw[i].mask |= MARK_NAN_POS_ERROR; 593 648 } 594 649 raw[i].Nmeas = catalog[c].average[n].Nmeasure; // record so we can check how well connected an image is … … 613 668 } 614 669 615 *Nstars = N list[im];670 *Nstars = N_onImage[im]; 616 671 return (raw); 617 672 } … … 639 694 } 640 695 641 ALLOCATE (ref, StarData, Nlist[im]); 642 643 for (i = 0; i < Nlist[im]; i++) { 644 m = mlist[im][i]; 645 c = clist[im][i]; 646 n = catalog[c].measure[m].averef; 696 ALLOCATE (ref, StarData, N_onImage[im]); 697 698 for (i = 0; i < N_onImage[im]; i++) { 699 m = ImageToMeasure[im][i]; 700 c = ImageToCatalog[im][i]; 701 702 MeasureTiny *measure = &catalog[c].measureT[m]; 703 n = measure[0].averef; 647 704 648 705 /* apply the current image transformation or use the current value of R+dR, D+dD? */ … … 650 707 ref[i].D = catalog[c].average[n].D; 651 708 652 ref[i].Mag = catalog[c].measure[m].M;653 ref[i].dMag = catalog[c].measure[m].dM;654 ref[i].dPos = GetAstromError (&catalog[c].measure[m], ERROR_MODE_POS);709 ref[i].Mag = measure[0].M; 710 ref[i].dMag = measure[0].dM; 711 ref[i].dPos = GetAstromErrorTiny (&measure[0], ERROR_MODE_POS); 655 712 656 713 ref[i].mask = FALSE; … … 675 732 } 676 733 677 *Nstars = N list[im];734 *Nstars = N_onImage[im]; 678 735 return (ref); 679 736 } … … 682 739 void FlagOutliers2D(Catalog *catalog); 683 740 741 // operates on Full values (not tiny) 684 742 void FlagOutliers (Catalog *catalog) { 685 // XXX FlagOutliers is just using FlagOutliers2D 743 744 // XXX FlagOutliers is now just using FlagOutliers2D 686 745 FlagOutliers2D(catalog); 687 746 return; … … 696 755 assert(catalog[0].Nsecfilt == Nsecfilt); 697 756 698 if (VERBOSE ) fprintf (stderr, "marking poor measures\n");757 if (VERBOSE2) fprintf (stderr, "marking poor measures\n"); 699 758 Nmax = 0; 700 759 for (i = 0; i < catalog[0].Naverage; i++) { … … 716 775 for (j = 0; j < catalog[0].Naverage; j++) { 717 776 777 // pointer to this set of measurements 778 m = catalog[0].average[j].measureOffset; 779 Measure *measure = &catalog[0].measure[m]; 780 718 781 /* accumulate list of valid measurements */ 719 m = catalog[0].average[j].measureOffset;720 782 N = 0; 721 for (k = 0; k < catalog[0].average[j].Nmeasure; k++, m++) { 722 783 for (k = 0; k < catalog[0].average[j].Nmeasure; k++) { 723 784 // skip measurements based on user selected criteria 724 if (!MeasFilterTest(& catalog[0].measure[m], FALSE)) continue;725 R[N] = catalog[0].measure[m].dR;726 D[N] = catalog[0].measure[m].dD;727 dR[N] = GetAstromError ( &catalog[0].measure[m], ERROR_MODE_RA);728 dD[N] = GetAstromError ( &catalog[0].measure[m], ERROR_MODE_DEC);785 if (!MeasFilterTest(&measure[k], FALSE)) continue; 786 R[N] = measure[k].dR; 787 D[N] = measure[k].dD; 788 dR[N] = GetAstromError (&measure[k], ERROR_MODE_RA); 789 dD[N] = GetAstromError (&measure[k], ERROR_MODE_DEC); 729 790 if (isnan(R[N]) || isnan(D[N])) continue; 730 791 N++; … … 741 802 742 803 /* compare per-object distance to this standard deviation, and flag outliers*/ 743 m = catalog[0].average[j].measureOffset;744 804 N = 0; 745 for (k = 0; k < catalog[0].average[j].Nmeasure; k++ , m++) {805 for (k = 0; k < catalog[0].average[j].Nmeasure; k++) { 746 806 //reset flag on each invocation 747 catalog[0].measure[m].dbFlags &= ~ID_MEAS_POOR_ASTROM;807 measure[k].dbFlags &= ~ID_MEAS_POOR_ASTROM; 748 808 749 809 // skip measurements based on user selected criteria 750 if (!MeasFilterTest(& catalog[0].measure[m], FALSE)) continue;810 if (!MeasFilterTest(&measure[k], FALSE)) continue; 751 811 752 x = catalog[0].measure[m].dR - statsR.median;753 y = catalog[0].measure[m].dD - statsD.median;812 x = measure[k].dR - statsR.median; 813 y = measure[k].dD - statsD.median; 754 814 theta = atan2(y,x); 755 815 if ((x*x + y*y) > (SQR(statsR.sigma * Ns * cos(theta)) + 756 816 SQR(statsD.sigma * Ns * sin(theta)))) { 757 catalog[0].measure[m].dbFlags |= ID_MEAS_POOR_ASTROM;817 measure[k].dbFlags |= ID_MEAS_POOR_ASTROM; 758 818 Ndel++; 759 819 } … … 787 847 assert(catalog[0].Nsecfilt == Nsecfilt); 788 848 789 if (VERBOSE ) fprintf (stderr, "marking poor measures\n");849 if (VERBOSE2) fprintf (stderr, "marking poor measures\n"); 790 850 Nmax = 0; 791 851 for (i = 0; i < catalog[0].Naverage; i++) { … … 809 869 for (j = 0; j < catalog[0].Naverage; j++) { 810 870 871 // pointer to this set of measurements 872 m = catalog[0].average[j].measureOffset; 873 Measure *measure = &catalog[0].measure[m]; 874 811 875 /* accumulate list of valid measurements */ 812 m = catalog[0].average[j].measureOffset;813 876 N = 0; 814 815 for (k = 0; k < catalog[0].average[j].Nmeasure; k++, m++) { 816 817 //reset flag on each invocation 818 catalog[0].measure[m].dbFlags &= ~ID_MEAS_POOR_ASTROM; 877 for (k = 0; k < catalog[0].average[j].Nmeasure; k++) { 878 879 // reset flag on each invocation 880 measure[k].dbFlags &= ~ID_MEAS_POOR_ASTROM; 819 881 820 882 // skip measurements based on user selected criteria 821 if (!MeasFilterTest(& catalog[0].measure[m], FALSE)) continue;822 R[N] = catalog[0].measure[m].dR;823 D[N] = catalog[0].measure[m].dD;824 dR[N] = GetAstromError( &catalog[0].measure[m], ERROR_MODE_RA);825 dD[N] = GetAstromError( &catalog[0].measure[m], ERROR_MODE_DEC);883 if (!MeasFilterTest(&measure[k], FALSE)) continue; 884 R[N] = measure[k].dR; 885 D[N] = measure[k].dD; 886 dR[N] = GetAstromError(&measure[k], ERROR_MODE_RA); 887 dD[N] = GetAstromError(&measure[k], ERROR_MODE_DEC); 826 888 if (isnan(R[N]) || isnan(D[N])) continue; 827 889 N++; … … 837 899 838 900 /* calculate deviations of all points*/ 839 m = catalog[0].average[j].measureOffset;840 901 N = 0; 841 for (k = 0; k < catalog[0].average[j].Nmeasure; k++ , m++) {842 // skip bad measurements843 if (!MeasFilterTest(& catalog[0].measure[m], FALSE)) continue;844 x = catalog[0].measure[m].dR - statsR.median;845 y = catalog[0].measure[m].dD - statsD.median;902 for (k = 0; k < catalog[0].average[j].Nmeasure; k++) { 903 // skip bad measurements 904 if (!MeasFilterTest(&measure[k], FALSE)) continue; 905 x = measure[k].dR - statsR.median; 906 y = measure[k].dD - statsD.median; 846 907 theta = atan2(y,x); 847 908 d2[N] = (x*x + y*y) / (SQR(statsR.sigma * Ns * cos(theta)) + 848 909 SQR(statsD.sigma * Ns * sin(theta))); 849 index[N] = m;910 index[N] = k; 850 911 N++; 851 912 } … … 856 917 857 918 // recalculate image center, sigma based on closest 50% of points 858 for (k = 0; k < N; k++) {919 for (k = 0; k < N; k++) { 859 920 off_t ind = (off_t) index[k]; 860 R[k] = catalog[0].measure[ind].dR;861 D[k] = catalog[0].measure[ind].dD;862 dR[k] = GetAstromError( &catalog[0].measure[ind], ERROR_MODE_RA);863 dD[k] = GetAstromError( &catalog[0].measure[ind], ERROR_MODE_DEC);921 R[k] = measure[ind].dR; 922 D[k] = measure[ind].dD; 923 dR[k] = GetAstromError(&measure[ind], ERROR_MODE_RA); 924 dD[k] = GetAstromError(&measure[ind], ERROR_MODE_DEC); 864 925 } 865 926 liststats (R, dR, N, &statsR); … … 869 930 870 931 // use these new statistics to flag outliers 871 m = catalog[0].average[j].measureOffset;872 932 N = 0; 873 for (k = 0; k < catalog[0].average[j].Nmeasure; k++ , m++) {933 for (k = 0; k < catalog[0].average[j].Nmeasure; k++) { 874 934 //skip bad measurements 875 if (!MeasFilterTest(& catalog[0].measure[m], FALSE)) continue;876 x = catalog[0].measure[m].dR - statsR.median;877 y = catalog[0].measure[m].dD - statsD.median;935 if (!MeasFilterTest(&measure[k], FALSE)) continue; 936 x = measure[k].dR - statsR.median; 937 y = measure[k].dD - statsD.median; 878 938 theta = atan2(y,x); 879 939 d2[N] = (x*x + y*y) / (SQR(statsR.sigma * Ns * cos(theta)) + 880 940 SQR(statsD.sigma * Ns * sin(theta))); 881 941 if ((d2[N]) > 1) { 882 catalog[0].measure[m].dbFlags |= ID_MEAS_POOR_ASTROM;942 measure[k].dbFlags |= ID_MEAS_POOR_ASTROM; 883 943 Ndel ++; 884 944 } 885 945 N++; 886 946 Nave++; 887 } // done rejecting outliers947 } // done rejecting outliers 888 948 889 949 // examine results 890 950 // relastroVisualPlotOutliers(catalog, catalog[0].average[j].measureOffset, catalog[0].average[j].Nmeasure, statsR, statsD, Ns); 891 951 892 } // done looping over objects952 } // done looping over objects 893 953 894 954 if (VERBOSE) fprintf (stderr, "%d measures marked poor, %d total\n", Ndel, Nave); … … 901 961 } 902 962 903 963 /** Determine whether a measurement should be included in the analysis, based on supplied filter criteria */ 964 // we only optionally apply the sigma limit: for object averages, this should not be used (should it?) 965 int MeasFilterTestTiny(MeasureTiny *measure, int applySigmaLim) { 966 int found, k; 967 long mask; 968 PhotCode *code; 969 float mag; 970 971 if (!finite(measure[0].dR) || !finite(measure[0].dD)) return FALSE; 972 if (!finite(measure[0].M)) return FALSE; //XXX is this necessary for all relastro tasks? 973 if (!finite(measure[0].dM)) return FALSE; //XXX is this necessary for all relastro tasks? 974 975 /* select measurements by photcode, or equiv photcode, if specified */ 976 if (NphotcodesKeep > 0) { 977 found = FALSE; 978 for (k = 0; (k < NphotcodesKeep) && !found; k++) { 979 if (photcodesKeep[k][0].code == measure[0].photcode) found = TRUE; 980 if (photcodesKeep[k][0].code == GetPhotcodeEquivCodebyCode(measure[0].photcode)) found = TRUE; 981 } 982 if (!found) return FALSE; 983 } 984 985 if (NphotcodesSkip > 0) { 986 found = FALSE; 987 for (k = 0; (k < NphotcodesSkip) && !found; k++) { 988 if (photcodesSkip[k][0].code == measure[0].photcode) found = TRUE; 989 if (photcodesSkip[k][0].code == GetPhotcodeEquivCodebyCode(measure[0].photcode)) found = TRUE; 990 } 991 if (found) return FALSE; 992 } 993 994 /* select measurements by time */ 995 if (TimeSelect) { 996 if (measure[0].t < TSTART) return FALSE; 997 if (measure[0].t > TSTOP) return FALSE; 998 } 999 1000 /* select measurements by quality */ 1001 if (PhotFlagSelect) { 1002 if (PhotFlagBad) { 1003 mask = PhotFlagBad; 1004 } else { 1005 code = GetPhotcodebyCode (measure[0].photcode); 1006 mask = code[0].astromBadMask; 1007 } 1008 if (mask & measure[0].photFlags) return FALSE; 1009 } 1010 1011 /* select measurements by measurement error */ 1012 if (applySigmaLim && (SIGMA_LIM > 0) && (measure[0].dM > SIGMA_LIM)) { 1013 return FALSE; 1014 } 1015 1016 /* select measurements by mag limit */ 1017 if (ImagSelect) { 1018 mag = PhotInstTiny (measure); 1019 if (mag < ImagMin || mag > ImagMax) return FALSE; 1020 } 1021 1022 return TRUE; 1023 } 904 1024 905 1025 /** Determine whether a measurement should be included in the analysis, based on supplied filter criteria */ -
trunk/Ohana/src/relastro/src/ParFactor.c
r32740 r33652 1 1 # include "relastro.h" 2 # define J2000 2451545. /* Julian date at standard epoch */ 2 3 3 4 # if (0) … … 31 32 double n, L, g; 32 33 33 # define J2000 2451545. /* Julian date at standard epoch */34 34 35 35 n = jd - J2000; … … 46 46 int sun_ecliptic (double jd, double *lambda, double *beta, double *epsilon, double *Radius) { 47 47 48 # define J2000 2451545. /* Julian date at standard epoch */49 50 48 double n = jd - J2000; // day number 51 49 double L = 280.460 + 0.9856474 * n; // mean solar longitute (corr. for aberration) … … 60 58 61 59 /* given RA, DEC, Time, calculate the parallax factor */ 60 // Time is relative to Tmean, Tmean is years relative to J2000 62 61 int ParFactor (double *pR, double *pD, double RA, double DEC, double Time, double Tmean) { 63 62 … … 66 65 /* given a time T in UNIX seconds, determine the solar longitude S */ 67 66 68 jd = ohana_sec_to_jd (365.25*86400.0*(Time + Tmean)); 67 // jd = ohana_sec_to_jd (365.25*86400.0*(Time + Tmean)); 68 jd = 365.25*(Time + Tmean) + J2000; 69 // fprintf (stderr, "Time: %f, jd: %f\n", Time, jd); 70 69 71 sun_ecliptic (jd, &lambda, &beta, &epsilon, &Radius); 70 72 -
trunk/Ohana/src/relastro/src/StarMaps.c
r32346 r33652 68 68 for (i = 0; i < catalog[0].Nmeasure; i++) { 69 69 70 N = getImageByID(catalog[0].measure[i].imageID); 70 MeasureTiny *measure = &catalog[0].measureT[i]; 71 72 N = getImageByID(measure[0].imageID); 71 73 if (N < 0) continue; 72 74 73 xbin = catalog[0].measure[i].Xccd / starmap[N].Nx;74 ybin = catalog[0].measure[i].Yccd / starmap[N].Ny;75 xbin = measure[0].Xccd / starmap[N].Nx; 76 ybin = measure[0].Yccd / starmap[N].Ny; 75 77 76 78 xbin = MAX(0, MIN(NX_MAP-1, xbin)); … … 82 84 83 85 return (TRUE); 86 } 87 88 int createStarMap (Catalog *catalog, int Ncatalog) { 89 90 int i; 91 92 initStarMaps(); 93 94 for (i = 0; i < Ncatalog; i++) { 95 // check coverage per chip (operates on (Average, MeasureTiny, Secfilt) 96 updateStarMaps (&catalog[i]); 97 } 98 99 createStarMapPoints(); 100 return TRUE; 84 101 } 85 102 -
trunk/Ohana/src/relastro/src/UpdateChips.c
r32346 r33652 1 1 # include "relastro.h" 2 2 3 int plotChipFits (double *Ro, double *Do, char *mode, int Nimage); 3 4 int saveCenter (Image *image, double *Ro, double *Do, int im); 4 5 off_t getNextImageForThread (); 6 int UpdateChips_threaded (Catalog *catalog, int Ncatalog); 7 void *UpdateChips_worker (void *data); 8 9 enum {THREAD_RUN, THREAD_DONE}; 10 11 typedef struct { 12 int entry; 13 int state; 14 double *Ro; 15 double *Do; 16 char *mode; 17 off_t Nskip; 18 off_t Nmosaic; 19 off_t NnewFit; 20 off_t NoldFit; 21 Catalog *catalog; 22 int Ncatalog; 23 } ThreadInfo; 24 25 static Image *image = NULL; 26 static off_t Nimage = 0; 27 static off_t nextImage = 0; 28 29 // update astrometry of all chips relative to the average positions 30 // if NTHREADS is non-zero, call the threaded version of this function 5 31 int UpdateChips (Catalog *catalog, int Ncatalog) { 6 32 7 int Nskip, Nmosaic, NnewFit, NoldFit;33 off_t Nskip, Nmosaic, NnewFit, NoldFit; 8 34 9 35 /* we can measure new image parameters for each non-mosaic chip independently */ 10 off_t i, Nimage, Nraw, Nref, nFitAstr; 11 Image *image; 36 off_t i, Nraw, Nref, nFitAstr; 12 37 StarData *raw, *ref; 13 38 Coords *oldCoords; … … 16 41 char *mode; 17 42 43 if (NTHREADS) { 44 UpdateChips_threaded (catalog, Ncatalog); 45 return TRUE; 46 } 47 18 48 Nskip = Nmosaic = NnewFit = NoldFit = 0; 19 49 … … 25 55 ALLOCATE (mode, char, Nimage); 26 56 57 // XXX for faster processing in the future, this can be easily run in parallel 58 // each chip is fitted independently, so we could do N at once in parallel 27 59 for (i = 0; i < Nimage; i++) { 60 61 // XXX looks like everything below is thread safe : we can unroll this into a set of 62 // helper functions that grab the next available chip.... 28 63 29 64 /* skip all except WRP images */ … … 47 82 Nskip ++; 48 83 mode[i] = 0; 84 free (raw); 49 85 continue; 50 86 } … … 62 98 // fprintf (stderr, "image "OFF_T_FMT" : Nstars: "OFF_T_FMT"\n", i, Nraw); 63 99 if (!FitChip (raw, ref, Nraw, &image[i])) { 64 if (VERBOSE) fprintf (stderr, "reject fit for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT" \n", image[i].name, i, Nraw);100 if (VERBOSE) fprintf (stderr, "reject fit for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT" of %d\n", image[i].name, i, Nraw, image[i].nstar); 65 101 66 102 // restore status quo ante … … 105 141 106 142 plotChipFits (Ro, Do, mode, Nimage); 107 108 fprintf (stderr, "UpdateChips: %d fitted, %d keep old, %d skipped, %d mosaic (skipped)\n", NnewFit, NoldFit, Nskip, Nmosaic); 143 free (Ro); 144 free (Do); 145 free (mode); 146 147 fprintf (stderr, "UpdateChips: %d fitted, %d keep old, %d skipped, %d mosaic (skipped)\n", 148 (int) NnewFit, (int) NoldFit, (int) Nskip, (int) Nmosaic); 109 149 return (TRUE); 110 150 } 111 151 152 int UpdateChips_threaded (Catalog *catalog, int Ncatalog) { 153 154 int i; 155 off_t Nskip, Nmosaic, NnewFit, NoldFit; 156 double *Ro, *Do; 157 char *mode; 158 159 image = getimages (&Nimage, NULL); 160 nextImage = 0; 161 162 // save fit results for summary plot 163 ALLOCATE (Ro, double, Nimage); 164 ALLOCATE (Do, double, Nimage); 165 ALLOCATE (mode, char, Nimage); 166 167 pthread_attr_t attr; 168 pthread_attr_init (&attr); 169 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); 170 171 pthread_t *threads; 172 ALLOCATE (threads, pthread_t, NTHREADS); 173 174 ThreadInfo *threadinfo; 175 ALLOCATE (threadinfo, ThreadInfo, NTHREADS); 176 177 // launch N worker threads 178 for (i = 0; i < NTHREADS; i++) { 179 threadinfo[i].entry = i; 180 threadinfo[i].state = THREAD_RUN; 181 threadinfo[i].Ro = Ro; 182 threadinfo[i].Do = Do; 183 threadinfo[i].mode = mode; 184 threadinfo[i].Nskip = 0; 185 threadinfo[i].Nmosaic = 0; 186 threadinfo[i].NnewFit = 0; 187 threadinfo[i].NoldFit = 0; 188 threadinfo[i].catalog = catalog; 189 threadinfo[i].Ncatalog = Ncatalog; 190 pthread_create (&threads[i], NULL, UpdateChips_worker, &threadinfo[i]); 191 } 192 pthread_attr_destroy (&attr); 193 194 // wait until all threads have finished 195 while (1) { 196 int allDone = TRUE; 197 for (i = 0; i < NTHREADS; i++) { 198 if (threadinfo[i].state == THREAD_RUN) allDone = FALSE; 199 } 200 if (allDone) { 201 break; 202 } 203 usleep (500000); 204 } 205 206 // all threads are done, free the threads array and grab the info 207 free (threads); 208 209 plotChipFits (Ro, Do, mode, Nimage); 210 free (Ro); 211 free (Do); 212 free (mode); 213 214 // report stats & summary from the threads 215 Nskip = Nmosaic = NnewFit = NoldFit = 0; 216 for (i = 0; i < NTHREADS; i++) { 217 fprintf (stderr, "UpdateChips thread %d : %d fitted, %d keep old, %d skipped, %d mosaic (skipped)\n", 218 i, (int) threadinfo[i].NnewFit, (int) threadinfo[i].NoldFit, (int) threadinfo[i].Nskip, (int) threadinfo[i].Nmosaic); 219 220 NnewFit += threadinfo[i].NnewFit; 221 NoldFit += threadinfo[i].NoldFit; 222 Nskip += threadinfo[i].Nskip; 223 Nmosaic += threadinfo[i].Nmosaic; 224 } 225 free (threadinfo); 226 227 fprintf (stderr, "UpdateChips: %d fitted, %d keep old, %d skipped, %d mosaic (skipped)\n", 228 (int) NnewFit, (int) NoldFit, (int) Nskip, (int) Nmosaic); 229 return (TRUE); 230 } 231 232 void *UpdateChips_worker (void *data) { 233 234 /* we can measure new image parameters for each non-mosaic chip independently */ 235 off_t Nraw, Nref, nFitAstr; 236 StarData *raw, *ref; 237 Coords *oldCoords; 238 float dXpixSys, dYpixSys; 239 240 ThreadInfo *threadinfo = data; 241 242 while (1) { 243 244 off_t i = getNextImageForThread(); 245 if (i == -1) { 246 threadinfo->state = THREAD_DONE; 247 return NULL; 248 } 249 250 /* skip all except WRP images */ 251 if (strcmp(&image[i].coords.ctype[4], "-WRP")) { 252 threadinfo->Nmosaic ++; 253 threadinfo->mode[i] = 0; 254 continue; 255 } 256 257 /* convert measure coordinates to raw entries */ 258 raw = getImageRaw (threadinfo->catalog, threadinfo->Ncatalog, i, &Nraw, MODE_MOSAIC); 259 if (!raw) { 260 threadinfo->Nskip ++; 261 threadinfo->mode[i] = 0; 262 continue; 263 } 264 265 /* convert average coordinates to ref entries */ 266 ref = getImageRef (threadinfo->catalog, threadinfo->Ncatalog, i, &Nref, MODE_MOSAIC); 267 if (!ref) { 268 threadinfo->Nskip ++; 269 threadinfo->mode[i] = 0; 270 free (raw); 271 continue; 272 } 273 274 // note that Nraw & Nref must be equal: if not, we made a programming error in one of these two functions. 275 assert (Nraw == Nref); 276 277 // save these in case of failure 278 saveCoords (&image[i].coords, i); 279 dXpixSys = image[i].dXpixSys; 280 dYpixSys = image[i].dYpixSys; 281 nFitAstr = image[i].nFitAstrom; 282 283 // FitChip does iterative, clipped fitting 284 // fprintf (stderr, "image "OFF_T_FMT" : Nstars: "OFF_T_FMT"\n", i, Nraw); 285 if (!FitChip (raw, ref, Nraw, &image[i])) { 286 if (VERBOSE) fprintf (stderr, "reject fit for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT" of %d\n", image[i].name, i, Nraw, image[i].nstar); 287 288 // restore status quo ante 289 oldCoords = getCoords (i); 290 memcpy (&image[i].coords, oldCoords, sizeof(Coords)); 291 image[i].dXpixSys = dXpixSys; 292 image[i].dYpixSys = dYpixSys; 293 image[i].nFitAstrom = nFitAstr; 294 295 saveCenter (image, &threadinfo->Ro[i], &threadinfo->Do[i], i); 296 threadinfo->mode[i] = 1; 297 threadinfo->NoldFit ++; 298 free (raw); 299 free (ref); 300 continue; 301 } 302 303 if (!checkStarMap (i)) { 304 if (VERBOSE) fprintf (stderr, "fit diverges too much for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT"\n", image[i].name, i, Nraw); 305 // restore status quo ante 306 oldCoords = getCoords (i); 307 memcpy (&image[i].coords, oldCoords, sizeof(Coords)); 308 image[i].dXpixSys = dXpixSys; 309 image[i].dYpixSys = dYpixSys; 310 image[i].nFitAstrom = nFitAstr; 311 312 saveCenter (image, &threadinfo->Ro[i], &threadinfo->Do[i], i); 313 threadinfo->mode[i] = 2; 314 image[i].flags |= ID_IMAGE_ASTROM_POOR; 315 threadinfo->NoldFit ++; 316 free (raw); 317 free (ref); 318 continue; 319 } 320 321 saveCenter (image, &threadinfo->Ro[i], &threadinfo->Do[i], i); 322 threadinfo->mode[i] = 3; 323 threadinfo->NnewFit ++; 324 free (raw); 325 free (ref); 326 } 327 328 // we should never reach here... 329 return NULL; 330 } 331 332 // mutex to lock UpdateChips_worker operations 333 static pthread_mutex_t UpdateChips_mutex = PTHREAD_MUTEX_INITIALIZER; 334 335 // we have an array of chips (image, Nimage). we need to hand out images one at a time to 336 // the worker threads as they need 337 off_t getNextImageForThread () { 338 339 pthread_mutex_lock (&UpdateChips_mutex); 340 if (nextImage >= Nimage) { 341 pthread_mutex_unlock (&UpdateChips_mutex); 342 return (-1); 343 } 344 off_t thisImage = nextImage; 345 nextImage ++; 346 347 pthread_mutex_unlock (&UpdateChips_mutex); 348 return (thisImage); 349 } 350 351 // This function uses the mosaic array in MosaicOps.c to associate PHU + CHIP this is 352 // thread safe : the lookup (getMosaicForImage) is selecting an element of a previously 353 // allocated and assigned static array. This function does NOT use the thread-unsafe (and 354 // somewhat slower) functions in libdvo/src/mosaic_astrom.c to associate CHIP and PHU 112 355 int saveCenter (Image *image, double *Ro, double *Do, int im) { 113 356 … … 136 379 // note that for a Simple image, L,M = P,Q 137 380 XY_to_LM (&L, &M, X, Y, imcoords); 138 LM_to_RD (&R, &D, L, M, imcoords); 381 LM_to_RD (&R, &D, L, M, imcoords); // because of the block above, ctype is not -WRP 139 382 } else { 140 383 XY_to_LM (&L, &M, X, Y, imcoords); 141 384 XY_to_LM (&P, &Q, L, M, moscoords); 142 LM_to_RD (&R, &D, P, Q, moscoords); 143 } 144 145 double Rmid; 146 if (UserCatalog) { 147 Rmid = UserCatalogRA; 148 } else { 149 Rmid = 0.5*(UserPatch.Rmin + UserPatch.Rmax); 150 } 385 LM_to_RD (&R, &D, P, Q, moscoords); // moscoords.ctype is -DIS 386 } 387 388 double Rmid = 0.5*(UserPatch.Rmin + UserPatch.Rmax); 151 389 152 390 R = ohana_normalize_angle_to_midpoint (R, Rmid); -
trunk/Ohana/src/relastro/src/UpdateMeasures.c
r32346 r33652 1 1 # include "relastro.h" 2 2 3 // this function operates on Measure, not MeasureTiny 3 4 int UpdateMeasures (Catalog *catalog, int Ncatalog) { 4 5 -
trunk/Ohana/src/relastro/src/UpdateObjectOffsets.c
r30616 r33652 7 7 // original coordinates 8 8 9 int UpdateObjectOffsets (SkyList *skylist) { 9 int UpdateObjectOffsets_parallel (SkyList *sky); 10 11 int UpdateObjectOffsets (SkyList *skylist, int hostID, char *hostpath) { 10 12 11 13 int i; 12 14 Catalog catalog; 13 15 16 // XXX need to decide how to determine PARALLEL mode... 17 if (PARALLEL && !hostID) { 18 UpdateObjectOffsets_parallel (skylist); 19 return TRUE; 20 } 21 14 22 // load data from each region file, only use bright stars 15 23 for (i = 0; i < skylist[0].Nregions; i++) { 16 24 25 // does this host ID match the desired location for the table? 26 if (!HostTableTestHost(skylist[0].regions[i], hostID)) continue; 27 28 // define the catalog file name 29 char hostfile[1024]; 30 snprintf (hostfile, 1024, "%s/%s.cpt", hostpath, skylist[0].regions[i]->name); 31 catalog.filename = hostID ? hostfile : skylist[0].filename[i]; 32 17 33 // set up the basic catalog info 18 catalog.filename = skylist[0].filename[i];19 34 catalog.catformat = dvo_catalog_catformat (CATFORMAT); // set the default catformat from config data 20 35 catalog.catmode = dvo_catalog_catmode (CATMODE); // set the default catmode from config data … … 22 37 catalog.Nsecfilt = GetPhotcodeNsecfilt (); 23 38 24 if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE , "w")) {39 if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE2, "w")) { 25 40 fprintf (stderr, "ERROR: failure reading catalog %s\n", catalog.filename); 26 41 exit (1); 27 42 } 28 43 if (!catalog.Naves_disk) { 29 if (VERBOSE ) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);44 if (VERBOSE2) fprintf (stderr, "no data in %s, skipping\n", catalog.filename); 30 45 dvo_catalog_unlock (&catalog); 31 46 dvo_catalog_free (&catalog); 32 47 continue; 33 48 } 49 50 // set the values in MeasureTiny needed by UpdateObjects 51 populate_tiny_values(&catalog, DVO_TV_MEASURE); 34 52 35 53 // match measurements with images … … 40 58 UpdateMeasures (&catalog, 1); 41 59 60 // uses MeasureTiny values, but will also update Measure values when populated 42 61 UpdateObjects (&catalog, 1); 43 62 … … 50 69 return (TRUE); 51 70 } 71 72 // CATDIR is supplied globally 73 # define DEBUG 1 74 int UpdateObjectOffsets_parallel (SkyList *sky) { 75 76 // launch the setphot_client jobs to the parallel hosts 77 78 // load the list of hosts 79 HostTable *table = HostTableLoad (CATDIR, sky->hosts); 80 if (!table) { 81 fprintf (stderr, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR); 82 exit (1); 83 } 84 85 int i; 86 for (i = 0; i < table->Nhosts; i++) { 87 88 // ensure that the paths are absolute path names 89 char *tmppath = abspath (table->hosts[i].pathname, MAX_PATH_LENGTH); 90 free (table->hosts[i].pathname); 91 table->hosts[i].pathname = tmppath; 92 93 // options / arguments that can affect relastro_client -load: 94 // VERBOSE, VERBOSE2 95 // RESET (-reset) 96 // TimeSelect -time 97 // (note that psfQual is applied rigidly at 0.85, as is the galaxy test) 98 // ImagSelect, ImagMin, ImagMax 99 // MaxDensityUse, MaxDensityValue 100 101 char command[1024]; 102 snprintf (command, 1024, "relastro_client -update-offsets -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -statmode %s -minerror %f", 103 table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, STATMODE, MIN_ERROR); 104 105 char tmpline[1024]; 106 if (FIT_MODE == FIT_PM_ONLY) { snprintf (tmpline, 1024, "%s -pm", command); strcpy (command, tmpline); } 107 if (FIT_MODE == FIT_PAR_ONLY) { snprintf (tmpline, 1024, "%s -par", command); strcpy (command, tmpline); } 108 if (FIT_MODE == FIT_PM_AND_PAR) { snprintf (tmpline, 1024, "%s -pmpar", command); strcpy (command, tmpline); } 109 110 if (VERBOSE) { snprintf (tmpline, 1024, "%s -v", command); strcpy (command, tmpline); } 111 if (VERBOSE2) { snprintf (tmpline, 1024, "%s -vv", command); strcpy (command, tmpline); } 112 if (RESET) { snprintf (tmpline, 1024, "%s -reset", command); strcpy (command, tmpline); } 113 if (ImagSelect) { snprintf (tmpline, 1024, "%s -instmag %f %f", command, ImagMin, ImagMax); strcpy (command, tmpline); } 114 if (MaxDensityUse) { snprintf (tmpline, 1024, "%s -max-density %f", command, MaxDensityValue); strcpy (command, tmpline); } 115 116 if (USE_BASIC_CHECK) { snprintf (tmpline, 1024, "%s -basic-image-search", command); strcpy (command, tmpline); } 117 if (FlagOutlier) { snprintf (tmpline, 1024, "%s -clip %d", command, CLIP_THRESH); strcpy (command, tmpline); } 118 119 if (PHOTCODE_KEEP_LIST) { snprintf (tmpline, 1024, "%s +photcode %s", command, PHOTCODE_KEEP_LIST); strcpy (command, tmpline); } 120 if (PHOTCODE_SKIP_LIST) { snprintf (tmpline, 1024, "%s -photcode %s", command, PHOTCODE_SKIP_LIST); strcpy (command, tmpline); } 121 if (PhotFlagSelect) { snprintf (tmpline, 1024, "%s +photflags", command); strcpy (command, tmpline); } 122 if (PhotFlagBad) { snprintf (tmpline, 1024, "%s +photflagbad %d", command, PhotFlagBad); strcpy (command, tmpline); } 123 if (PhotFlagPoor) { snprintf (tmpline, 1024, "%s +photflagpoor %d", command, PhotFlagPoor); strcpy (command, tmpline); } 124 // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values 125 126 if (TimeSelect) { 127 char *tstart = ohana_sec_to_date (TSTART); 128 char *tstop = ohana_sec_to_date (TSTOP); 129 snprintf (tmpline, 1024, "%s -time %s %s", command, tstart, tstop); 130 free (tstart); 131 free (tstop); 132 strcpy (command, tmpline); 133 } 134 fprintf (stderr, "command: %s\n", command); 135 136 if (PARALLEL_MANUAL) continue; 137 138 if (PARALLEL_SERIAL) { 139 int status = system (command); 140 if (status) { 141 fprintf (stderr, "ERROR running relastro_client\n"); 142 exit (2); 143 } 144 } else { 145 // launch the job on the remote machine (no handshake) 146 int errorInfo = 0; 147 int pid = rconnect ("ssh", table->hosts[i].hostname, command, table->hosts[i].stdio, &errorInfo, FALSE); 148 if (!pid) { 149 if (DEBUG) fprintf (stderr, "failure to start %s (error %d)\n", table->hosts[i].hostname, errorInfo); 150 exit (1); 151 } 152 table->hosts[i].pid = pid; // save for future reference 153 } 154 } 155 156 if (PARALLEL_MANUAL) { 157 fprintf (stderr, "run the relastro_client commands above. when these are done, hit return\n"); 158 getchar(); 159 } 160 if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) { 161 HostTableWaitJobsGetIO (table, __FILE__, __LINE__, VERBOSE); 162 } 163 164 return TRUE; 165 } -
trunk/Ohana/src/relastro/src/UpdateObjects.c
r32695 r33652 38 38 } 39 39 40 // This function operates on both Measure and MeasureTiny. In the big stages, this should 41 // be called with just MeasureTiny set and Measure == NULL 40 42 int UpdateObjects (Catalog *catalog, int Ncatalog) { 41 43 … … 72 74 T2000 = ohana_date_to_sec ("2000/01/01"); 73 75 // XXX in the future, use catalog[0].Nsecfilt only? allow catalogs to have variable Nsecfilt? 76 74 77 Nsecfilt = GetPhotcodeNsecfilt (); 75 assert (catalog[0].Nsecfilt == Nsecfilt); 78 if (Ncatalog) { 79 assert (catalog[0].Nsecfilt == Nsecfilt); 80 } 76 81 77 82 NaveSum = NparSum = NpmSum = NskipSum = 0; 78 83 for (i = 0; i < Ncatalog; i++) { 79 84 80 if (VERBOSE ) fprintf (stderr, "astrometrize catalog %d : "OFF_T_FMT" ave, "OFF_T_FMT" meas\n", i, catalog[i].Naverage, catalog[i].Nmeasure);85 if (VERBOSE2) fprintf (stderr, "astrometrize catalog %d : "OFF_T_FMT" ave, "OFF_T_FMT" meas\n", i, catalog[i].Naverage, catalog[i].Nmeasure); 81 86 82 87 Nave = Npar = Npm = Nskip = 0; … … 86 91 XVERB = FALSE; 87 92 88 // skip objects which are known to be problematic89 // XXX include this code or not?90 # if (0)91 if (catalog[i].average[j].code & STAR_BAD) {92 Nskip ++;93 continue;94 }95 # endif96 97 93 if (catalog[i].average[j].Nmeasure == 0) { 98 94 continue; … … 101 97 N = 0; 102 98 m = catalog[i].average[j].measureOffset; 103 Tmin = Tmax = (catalog[i].measure[m].t - T2000) / (86400*365.25); 99 MeasureTiny *measure = &catalog[i].measureT[m]; 100 Measure *measureBig = catalog[i].measure ? &catalog[i].measure[m] : NULL; 101 // when we update the output measure values, we need to do it here 102 104 103 mode = FIT_MODE; 105 104 106 105 // find the basic properties of the detections for this object (Tmin, Tmax, Tmean) 107 Tmean = 0;108 for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) { 109 110 //does the measurement pass the supplied filtering constraints?111 if (!MeasFilterTest(&catalog[i].measure[m], FALSE)) {112 catalog[i].measure[m].dbFlags &= ~ID_MEAS_USED_OBJ;106 for (k = 0; k < catalog[i].average[j].Nmeasure; k++) { 107 108 // does the measurement pass the supplied filtering constraints? 109 if (!MeasFilterTestTiny(&measure[k], FALSE)) { 110 measure[k].dbFlags &= ~ID_MEAS_USED_OBJ; 111 if (measureBig) { measureBig[k].dbFlags &= ~ID_MEAS_USED_OBJ; } 113 112 continue; 114 113 } 115 114 116 115 //outlier rejection 117 if (FlagOutlier && (catalog[i].measure[m].dbFlags & ID_MEAS_POOR_ASTROM)) { 118 catalog[i].measure[m].dbFlags &= ~ID_MEAS_USED_OBJ; 116 if (FlagOutlier && (measure[k].dbFlags & ID_MEAS_POOR_ASTROM)) { 117 measure[k].dbFlags &= ~ID_MEAS_USED_OBJ; 118 if (measureBig) { measureBig[k].dbFlags &= ~ID_MEAS_USED_OBJ; } 119 119 continue; 120 120 } 121 121 122 // exclude measurements by previous outlier detection 123 // XXX include this code or not? 124 # if (0) 125 if (catalog[i].measure[m].dbFlags & MEAS_BAD) { 126 catalog[i].measure[m].dbFlags |= ID_MEAS_SKIP_ASTROM; 122 measure[k].dbFlags |= ID_MEAS_USED_OBJ; 123 if (measureBig) { measureBig[k].dbFlags |= ID_MEAS_USED_OBJ; } 124 125 R[N] = getMeanR (&measure[k], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]); 126 D[N] = getMeanD (&measure[k], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]); 127 128 // XXX I think this is a problem: T[] is time in years relative to J2000, but ParFactor expects 129 // to get Time in years relative to UNIX Tzero (1970/01/01) 130 T[N] = (measure[k].t - T2000) / (86400*365.25) ; // time relative to J2000 in years 131 132 // dX, dY : error in arcsec -- 133 dX[N] = GetAstromErrorTiny (&measure[k], ERROR_MODE_RA); 134 dY[N] = GetAstromErrorTiny (&measure[k], ERROR_MODE_DEC); 135 136 // allow a given photcode or measurement to be 137 // ignored if the error is NAN (for photcode, set astromErrSys to NaN) 138 if (isnan(dX[N])) { 139 measure[k].dbFlags &= ~ID_MEAS_USED_OBJ; 127 140 continue; 128 141 } 129 # endif 130 131 catalog[i].measure[m].dbFlags |= ID_MEAS_USED_OBJ; 132 133 R[N] = getMeanR (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]); 134 D[N] = getMeanD (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]); 135 T[N] = (catalog[i].measure[m].t - T2000) / (86400*365.25) ; // time relative to J2000 in years 136 137 Tmin = MIN(Tmin, T[N]); 138 Tmax = MAX(Tmax, T[N]); 139 Tmean += T[N]; 140 141 // dX, dY : error in arcsec -- 142 dX[N] = GetAstromError (&catalog[i].measure[m], ERROR_MODE_RA); 143 dY[N] = GetAstromError (&catalog[i].measure[m], ERROR_MODE_DEC); 142 if (isnan(dY[N])) { 143 measure[k].dbFlags &= ~ID_MEAS_USED_OBJ; 144 continue; 145 } 144 146 145 147 // add systematic error in quadrature, if desired 146 148 // only do this after the fit has converged (or you will never improve the poor images) 147 149 // if (INCLUDE_SYS_ERR) { 148 // float dRsys = FromShortPixels( catalog[i].measure[m].dRsys);150 // float dRsys = FromShortPixels(measure[k].dRsys); 149 151 // dX[N] = hypot(dX[N], dRsys); 150 152 // dY[N] = hypot(dY[N], dRsys); … … 154 156 // dY[N] = 0.1; 155 157 156 dT[N] = catalog[i].measure[m].dt;158 dT[N] = measure[k].dt; 157 159 158 160 // XXX this is (slightly) inconsistent: dX,dY are the X and Y direction errors in … … 172 174 catalog[i].average[j].flags &= ~ID_STAR_FEW; 173 175 176 // find Tmin & Tmax from the list of accepted measurements 177 Tmean = 0; 178 Tmin = Tmax = T[0]; 179 for (k = 0; k < N; k++) { 180 Tmin = MIN(Tmin, T[k]); 181 Tmax = MAX(Tmax, T[k]); 182 Tmean += T[k]; 183 } 174 184 // XXX add the parallax factor range as a criterion as well 175 185 Trange = Tmax - Tmin; 176 186 if (Trange < PM_DT_MIN) mode = FIT_AVERAGE; 177 187 if ((mode == FIT_PM_ONLY) && (N < PM_TOOFEW)) mode = FIT_AVERAGE; 188 189 if (FIT_TARGET == TARGET_HIGH_SPEED) { 190 Tmean = 0.5*(Tmax - Tmin); 191 } else { 192 Tmean /= (float) N; 193 } 178 194 179 195 // too few measurements for average position (require 2 values) … … 192 208 coords.crval2 = D[0]; 193 209 194 if (FIT_TARGET == TARGET_HIGH_SPEED) {195 Tmean = 0.5*(Tmax - Tmin);196 } else {197 Tmean /= (float) N;198 }199 200 210 // XVERB |= (catalog[i].averge[j].objID == 0xc90) && (catalog[i].average[j].catID == 0x2a1e); 201 211 XVERB |= (catalog[i].average[j].objID == OBJ_ID_SRC) && (catalog[i].average[j].catID == CAT_ID_SRC); 202 212 XVERB |= (catalog[i].average[j].objID == OBJ_ID_DST) && (catalog[i].average[j].catID == CAT_ID_DST); 203 // XVERB = (catalog[i].measure[m].dM < 0.01) && (N == 6) && (mode == FIT_PM_ONLY);204 213 205 214 // to judge the quality of the PM and PAR fits, we need to fit all three models and compare Chisq … … 232 241 // fprintf (stderr, "parallax fitting is still untested (%s, %d)\n", __FILE__, __LINE__); 233 242 243 float pXmin = +2.0; 244 float pXmax = -2.0; 245 float pYmin = +2.0; 246 float pYmax = -2.0; 234 247 for (k = 0; k < N; k++) { 235 248 ParFactor (&pX[k], &pY[k], R[k], D[k], T[k], Tmean); 236 } 237 FitPMandPar (&fitPAR, X, dX, Y, dY, T, pX, pY, N, XVERB); 238 XY_to_RD (&fitPAR.Ro, &fitPAR.Do, fitPAR.Ro, fitPAR.Do, &coords); 239 catalog[i].average[j].flags |= ID_STAR_FIT_PAR; 240 Npar ++; 249 pXmin = MIN (pXmin, pX[k]); 250 pXmax = MAX (pXmax, pX[k]); 251 pYmin = MIN (pYmin, pY[k]); 252 pYmax = MAX (pYmax, pY[k]); 253 } 254 float dXRange = pXmax - pXmin; 255 float dYRange = pYmax - pYmin; 256 float parRange = hypot (dXRange, dYRange); 257 258 if (parRange >= PAR_FACTOR_MIN) { 259 FitPMandPar (&fitPAR, X, dX, Y, dY, T, pX, pY, N, XVERB); 260 XY_to_RD (&fitPAR.Ro, &fitPAR.Do, fitPAR.Ro, fitPAR.Do, &coords); 261 catalog[i].average[j].flags |= ID_STAR_FIT_PAR; 262 Npar ++; 263 } 241 264 } 242 265 … … 307 330 308 331 // the measure fields must be updated before the average fields 309 m = catalog[i].average[j].measureOffset; 310 for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) { 311 setMeanR (fit.Ro, &catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]); 312 setMeanD (fit.Do, &catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]); 332 for (k = 0; k < catalog[i].average[j].Nmeasure; k++) { 333 setMeanR (fit.Ro, &measure[k], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]); 334 setMeanD (fit.Do, &measure[k], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]); 335 if (measureBig) { 336 setMeanR_Big (fit.Ro, &measureBig[k], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]); 337 setMeanD_Big (fit.Do, &measureBig[k], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]); 338 } 313 339 } 314 340 -
trunk/Ohana/src/relastro/src/args.c
r32695 r33652 1 1 # include "relastro.h" 2 2 void usage (void); 3 void usage_client (void); 3 4 void usage_merge_source (void); 4 5 void usage_merge_source_id (char *name); … … 42 43 if ((N = get_argument (argc, argv, "-update-objects"))) { 43 44 remove_argument (N, &argc, argv); 44 FIT_TARGET = TARGET_OBJECTS; 45 FIT_TARGET = TARGET_UPDATE_OBJECTS; 46 } 47 48 if ((N = get_argument (argc, argv, "-update-offsets"))) { 49 remove_argument (N, &argc, argv); 50 FIT_TARGET = TARGET_UPDATE_OFFSETS; 45 51 } 46 52 … … 92 98 RADIUS = atof(argv[N]); 93 99 remove_argument (N, &argc, argv); 94 HIGH_SPEED_DIR = strcreate(argv[N]); 95 remove_argument (N, &argc, argv); 100 HIGH_SPEED_DIR = abspath(argv[N], MAX_PATH_LENGTH); 101 remove_argument (N, &argc, argv); 102 } 103 104 PARALLEL_OUTPUT = FALSE; 105 if ((N = get_argument (argc, argv, "-parallel-output"))) { 106 remove_argument (N, &argc, argv); 107 PARALLEL_OUTPUT = TRUE; 108 if (FIT_TARGET != TARGET_HIGH_SPEED) { 109 fprintf (stderr, "-parallel-output only valid for -high-speed mode\n"); 110 exit (1); 111 } 96 112 } 97 113 … … 118 134 119 135 if (FIT_TARGET == TARGET_NONE) usage(); 120 121 UserCatalog = FALSE;122 if ((N = get_argument (argc, argv, "-catalog"))) {123 remove_argument (N, &argc, argv);124 UserCatalogRA = atof(argv[N]);125 remove_argument (N, &argc, argv);126 UserCatalogDEC = atof(argv[N]);127 remove_argument (N, &argc, argv);128 UserCatalog = TRUE;129 }130 136 131 137 /* specify portion of the sky : allow default of all sky? */ … … 144 150 UserPatch.Dmax = atof (argv[N]); 145 151 remove_argument (N, &argc, argv); 146 } else { 147 if (!UserCatalog) { 148 usage (); 152 } 153 if ((N = get_argument (argc, argv, "-catalog"))) { 154 remove_argument (N, &argc, argv); 155 UserPatch.Rmin = atof (argv[N]); 156 UserPatch.Rmax = UserPatch.Rmin + 0.001; 157 remove_argument (N, &argc, argv); 158 UserPatch.Dmin = atof (argv[N]); 159 UserPatch.Dmax = UserPatch.Dmin + 0.001; 160 remove_argument (N, &argc, argv); 161 } 162 163 // XXX for the moment, make this selection manual. it needs to be automatic 164 // based on the state of the SkyTable 165 PARALLEL = FALSE; 166 if ((N = get_argument (argc, argv, "-parallel"))) { 167 PARALLEL = TRUE; 168 remove_argument (N, &argc, argv); 169 } 170 // this is a test mode : rather than launching the remote jobs and waiting for completion, 171 // relastro will simply list the remote command and wait for the user to signal completion 172 PARALLEL_MANUAL = FALSE; 173 if ((N = get_argument (argc, argv, "-parallel-manual"))) { 174 PARALLEL = TRUE; // -parallel-manual implies -parallel 175 PARALLEL_MANUAL = TRUE; 176 remove_argument (N, &argc, argv); 177 } 178 // this is a test mode : rather than launching the relastro_client jobs remotely, they are 179 // run in serial via 'system' 180 PARALLEL_SERIAL = FALSE; 181 if ((N = get_argument (argc, argv, "-parallel-serial"))) { 182 if (PARALLEL_MANUAL) { 183 fprintf (stderr, "ERROR: cannot mix -parallel-manual and -parallel-serial\n"); 184 exit (1); 149 185 } 186 PARALLEL = TRUE; // -parallel-serial implies -parallel 187 PARALLEL_SERIAL = TRUE; 188 remove_argument (N, &argc, argv); 150 189 } 151 190 … … 290 329 } 291 330 292 AreaSelect = FALSE;293 if ((N = get_argument (argc, argv, "-area"))) {294 remove_argument (N, &argc, argv);295 AreaXmin = atof (argv[N]);296 remove_argument (N, &argc, argv);297 AreaXmax = atof (argv[N]);298 remove_argument (N, &argc, argv);299 AreaYmin = atof (argv[N]);300 remove_argument (N, &argc, argv);301 AreaYmax = atof (argv[N]);302 remove_argument (N, &argc, argv);303 AreaSelect = TRUE;304 }305 306 331 ImagSelect = FALSE; 307 332 if ((N = get_argument (argc, argv, "-instmag"))) { … … 336 361 } 337 362 338 /* XXX drop this? */339 DophotSelect = FALSE;340 if ((N = get_argument (argc, argv, "-dophot"))) {341 remove_argument (N, &argc, argv);342 DophotValue = atof (argv[N]);343 remove_argument (N, &argc, argv);344 DophotSelect = TRUE;345 }346 347 363 NLOOP = 4; 348 364 if ((N = get_argument (argc, argv, "-nloop"))) { 349 365 remove_argument (N, &argc, argv); 350 366 NLOOP = atof (argv[N]); 367 remove_argument (N, &argc, argv); 368 } 369 370 NTHREADS = 0; 371 if ((N = get_argument (argc, argv, "-threads"))) { 372 remove_argument (N, &argc, argv); 373 NTHREADS = atof (argv[N]); 351 374 remove_argument (N, &argc, argv); 352 375 } … … 356 379 } 357 380 381 int args_client (int argc, char **argv) { 382 383 int N; 384 double trange; 385 char *endptr; 386 387 /* possible operations */ 388 FIT_TARGET = TARGET_NONE; 389 FIT_MODE = FIT_AVERAGE; 390 391 // by definition, the client is not parallel 392 PARALLEL = FALSE; 393 PARALLEL_MANUAL = FALSE; 394 PARALLEL_SERIAL = FALSE; 395 396 BCATALOG = NULL; 397 398 HOST_ID = 0; 399 if ((N = get_argument (argc, argv, "-hostID"))) { 400 remove_argument (N, &argc, argv); 401 HOST_ID = atoi (argv[N]); 402 remove_argument (N, &argc, argv); 403 } 404 if (!HOST_ID) usage_client(); 405 406 HOSTDIR = NULL; 407 if ((N = get_argument (argc, argv, "-hostdir"))) { 408 remove_argument (N, &argc, argv); 409 HOSTDIR = strcreate (argv[N]); 410 remove_argument (N, &argc, argv); 411 } 412 if (!HOSTDIR) usage_client(); 413 414 if ((N = get_argument (argc, argv, "-load-objects"))) { 415 remove_argument (N, &argc, argv); 416 BCATALOG = strcreate(argv[N]); 417 remove_argument (N, &argc, argv); 418 FIT_TARGET = TARGET_LOAD_OBJECTS; 419 } 420 421 if ((N = get_argument (argc, argv, "-update-objects"))) { 422 remove_argument (N, &argc, argv); 423 FIT_TARGET = TARGET_UPDATE_OBJECTS; 424 } 425 426 if ((N = get_argument (argc, argv, "-update-offsets"))) { 427 remove_argument (N, &argc, argv); 428 FIT_TARGET = TARGET_UPDATE_OFFSETS; 429 } 430 431 // check for object fitting modes 432 if ((N = get_argument (argc, argv, "-pm"))) { 433 remove_argument (N, &argc, argv); 434 FIT_MODE = FIT_PM_ONLY; 435 } 436 if ((N = get_argument (argc, argv, "-par"))) { 437 remove_argument (N, &argc, argv); 438 FIT_MODE = FIT_PAR_ONLY; 439 } 440 if ((N = get_argument (argc, argv, "-pmpar"))) { 441 remove_argument (N, &argc, argv); 442 FIT_MODE = FIT_PM_AND_PAR; 443 } 444 445 if ((N = get_argument (argc, argv, "-high-speed"))) { 446 // XXX include a parallax / no-parallax option 447 if (N >= argc - 3) usage_client(); 448 FIT_TARGET = TARGET_HIGH_SPEED; 449 remove_argument (N, &argc, argv); 450 PHOTCODE_A_LIST = strcreate(argv[N]); 451 remove_argument (N, &argc, argv); 452 PHOTCODE_B_LIST = strcreate(argv[N]); 453 remove_argument (N, &argc, argv); 454 RADIUS = atof(argv[N]); 455 remove_argument (N, &argc, argv); 456 HIGH_SPEED_DIR = strcreate(argv[N]); 457 remove_argument (N, &argc, argv); 458 } 459 460 if ((N = get_argument (argc, argv, "-testobj1"))) { 461 if (N > argc - 3) usage (); 462 remove_argument (N, &argc, argv); 463 OBJ_ID_SRC = strtol(argv[N], &endptr, 0); 464 if (*endptr) usage (); 465 remove_argument (N, &argc, argv); 466 CAT_ID_SRC = strtol(argv[N], &endptr, 0); 467 if (*endptr) usage (); 468 remove_argument (N, &argc, argv); 469 } 470 471 if ((N = get_argument (argc, argv, "-testobj2"))) { 472 if (N > argc - 3) usage (); 473 remove_argument (N, &argc, argv); 474 OBJ_ID_DST = strtol(argv[N], &endptr, 0); 475 if (*endptr) usage (); 476 remove_argument (N, &argc, argv); 477 CAT_ID_DST = strtol(argv[N], &endptr, 0); 478 if (*endptr) usage (); 479 remove_argument (N, &argc, argv); 480 } 481 482 FlagOutlier = FALSE; 483 if ((N = get_argument (argc, argv, "-clip"))) { 484 remove_argument (N, &argc, argv); 485 CLIP_THRESH = atof (argv[N]); 486 remove_argument (N, &argc, argv); 487 FlagOutlier = TRUE; 488 } 489 490 if (FIT_TARGET == TARGET_NONE) usage_client(); 491 492 /* specify portion of the sky : allow default of all sky? */ 493 UserPatch.Rmin = 0; 494 UserPatch.Rmax = 360; 495 UserPatch.Dmin = -90; 496 UserPatch.Dmax = +90; 497 if ((N = get_argument (argc, argv, "-region"))) { 498 remove_argument (N, &argc, argv); 499 UserPatch.Rmin = atof (argv[N]); 500 remove_argument (N, &argc, argv); 501 UserPatch.Rmax = atof (argv[N]); 502 remove_argument (N, &argc, argv); 503 UserPatch.Dmin = atof (argv[N]); 504 remove_argument (N, &argc, argv); 505 UserPatch.Dmax = atof (argv[N]); 506 remove_argument (N, &argc, argv); 507 } 508 if ((N = get_argument (argc, argv, "-catalog"))) { 509 remove_argument (N, &argc, argv); 510 UserPatch.Rmin = atof (argv[N]); 511 UserPatch.Rmax = UserPatch.Rmin + 0.001; 512 remove_argument (N, &argc, argv); 513 UserPatch.Dmin = atof (argv[N]); 514 UserPatch.Dmax = UserPatch.Dmin + 0.001; 515 remove_argument (N, &argc, argv); 516 } 517 518 USE_BASIC_CHECK = FALSE; 519 if ((N = get_argument (argc, argv, "-basic-image-search"))) { 520 remove_argument (N, &argc, argv); 521 USE_BASIC_CHECK = TRUE; 522 } 523 524 MaxDensityUse = FALSE; 525 if ((N = get_argument (argc, argv, "-max-density"))) { 526 remove_argument (N, &argc, argv); 527 MaxDensityValue = atof(argv[N]); 528 remove_argument (N, &argc, argv); 529 MaxDensityUse = TRUE; 530 } 531 532 /* define time */ 533 TimeSelect = FALSE; 534 if ((N = get_argument (argc, argv, "-time"))) { 535 remove_argument (N, &argc, argv); 536 if (!ohana_str_to_time (argv[N], &TSTART)) { 537 fprintf (stderr, "ERROR: syntax error\n"); 538 return (FALSE); 539 } 540 remove_argument (N, &argc, argv); 541 if (!ohana_str_to_dtime (argv[N], &trange)) { 542 if (!ohana_str_to_time (argv[N], &TSTOP)) { 543 fprintf (stderr, "ERROR: syntax error\n"); 544 return (FALSE); 545 } 546 } else { 547 if (trange < 0) { 548 trange = fabs (trange); 549 TSTOP = TSTART; 550 TSTART -= trange; 551 } else { 552 TSTOP = TSTART + trange; 553 } 554 } 555 remove_argument (N, &argc, argv); 556 TimeSelect = TRUE; 557 } 558 559 PHOTCODE_KEEP_LIST = NULL; 560 if ((N = get_argument (argc, argv, "+photcode"))) { 561 remove_argument (N, &argc, argv); 562 PHOTCODE_KEEP_LIST = strcreate(argv[N]); 563 remove_argument (N, &argc, argv); 564 } 565 566 PHOTCODE_SKIP_LIST = NULL; 567 if ((N = get_argument (argc, argv, "-photcode"))) { 568 remove_argument (N, &argc, argv); 569 PHOTCODE_SKIP_LIST = strcreate(argv[N]); 570 remove_argument (N, &argc, argv); 571 } 572 573 VERBOSE = VERBOSE2 = FALSE; 574 if ((N = get_argument (argc, argv, "-v"))) { 575 VERBOSE = TRUE; 576 remove_argument (N, &argc, argv); 577 } 578 if ((N = get_argument (argc, argv, "-vv"))) { 579 VERBOSE = VERBOSE2 = TRUE; 580 remove_argument (N, &argc, argv); 581 } 582 583 // by default, require > 10pts to clip 584 strcpy (STATMODE, "CHI_INNER_80_WTMEAN"); 585 if ((N = get_argument (argc, argv, "-statmode"))) { 586 remove_argument (N, &argc, argv); 587 strcpy (STATMODE, argv[N]); 588 remove_argument (N, &argc, argv); 589 } 590 591 RESET = FALSE; 592 if ((N = get_argument (argc, argv, "-reset"))) { 593 remove_argument (N, &argc, argv); 594 RESET = TRUE; 595 } 596 597 UPDATE = FALSE; 598 if ((N = get_argument (argc, argv, "-update"))) { 599 remove_argument (N, &argc, argv); 600 UPDATE = TRUE; 601 } 602 603 // do not hold the lock on the Image table for relastro_client -update-offsets 604 if (FIT_TARGET == TARGET_UPDATE_OFFSETS) { 605 UPDATE = FALSE; 606 } 607 608 /* XXX update this */ 609 MIN_ERROR = 0.001; 610 if ((N = get_argument (argc, argv, "-minerror"))) { 611 remove_argument (N, &argc, argv); 612 MIN_ERROR = atof (argv[N]); 613 remove_argument (N, &argc, argv); 614 /* require MIN_ERROR > 0 */ 615 } 616 617 ImagSelect = FALSE; 618 if ((N = get_argument (argc, argv, "-instmag"))) { 619 remove_argument (N, &argc, argv); 620 ImagMin = atof (argv[N]); 621 remove_argument (N, &argc, argv); 622 ImagMax = atof (argv[N]); 623 remove_argument (N, &argc, argv); 624 ImagSelect = TRUE; 625 } 626 627 // for now, make the default to ignore the photflags 628 // XXX make it true by default instead? 629 PhotFlagSelect = FALSE; 630 if ((N = get_argument (argc, argv, "+photflags"))) { 631 remove_argument (N, &argc, argv); 632 PhotFlagSelect = TRUE; 633 } 634 635 PhotFlagBad = 0; 636 if ((N = get_argument (argc, argv, "-photflagbad"))) { 637 remove_argument (N, &argc, argv); 638 PhotFlagBad = atoi (argv[N]); 639 remove_argument (N, &argc, argv); 640 } 641 642 PhotFlagPoor = 0; 643 if ((N = get_argument (argc, argv, "-photflagpoor"))) { 644 remove_argument (N, &argc, argv); 645 PhotFlagPoor = atoi (argv[N]); 646 remove_argument (N, &argc, argv); 647 } 648 649 if (argc != 1) usage_client (); 650 return TRUE; 651 } 652 358 653 void usage () { 359 fprintf (stderr, "ERROR: USAGE: relastro -region RA RA DEC DEC\n"); 360 fprintf (stderr, " OR: relastro -catalog (ra) (dec)\n\n"); 361 fprintf (stderr, " OR: relastro -high-speed [options]\n\n"); 654 fprintf (stderr, "ERROR: USAGE: relastro -update-simple [options]\n"); 655 fprintf (stderr, " OR: relastro -update-chips [options]\n"); 656 fprintf (stderr, " OR: relastro -update-mosaic [options]\n"); 657 fprintf (stderr, " OR: relastro -update-objects [options]\n"); 658 fprintf (stderr, " OR: relastro -high-speed [options]\n"); 362 659 fprintf (stderr, " OR: relastro -merge-source [options]\n\n"); 660 363 661 fprintf (stderr, " specify one of the following modes: \n"); 364 662 fprintf (stderr, " -update-objects\n"); … … 369 667 fprintf (stderr, " -update-chips\n"); 370 668 fprintf (stderr, " -update-mosaics\n"); 371 fprintf (stderr, " -high-speed (code[,code,code]) (code[,code,code]) (radius) (output catdir)\n\n"); 372 fprintf (stderr, " additional options: \n"); 669 fprintf (stderr, " -high-speed (code[,code,code]) (code[,code,code]) (radius) (output catdir)\n"); 670 fprintf (stderr, " -merge-source (objID) (catID) into (objID) (catID)\n\n"); 671 672 fprintf (stderr, " additional options: \n"); 673 fprintf (stderr, " -region RA RA DEC DEC\n"); 674 fprintf (stderr, " -catalog (ra) (dec)\n\n"); 373 675 fprintf (stderr, " -time (start)(stop)\n"); 374 676 fprintf (stderr, " +photcode (code)[,code,code...]\n"); … … 383 685 fprintf (stderr, " -plrange\n"); 384 686 fprintf (stderr, " -minerror\n"); 385 fprintf (stderr, " -area\n");386 fprintf (stderr, " -area Xmin Xmax Ymin Ymax\n");387 687 fprintf (stderr, " -instmag min max\n\n"); 388 688 fprintf (stderr, " +photflags\n"); … … 394 694 } 395 695 696 void usage_client () { 697 fprintf (stderr, "ERROR: USAGE: relastro_client -load\n"); 698 fprintf (stderr, " OR: relastro_client -update-offsets\n"); 699 fprintf (stderr, " OR: relastro_client -update-objects\n"); 700 fprintf (stderr, " OR: relastro_client -high-speed\n\n"); 701 702 fprintf (stderr, " specify one of the following modes: \n"); 703 fprintf (stderr, " -load : load the bright source detections for analysis\n"); 704 fprintf (stderr, " -update-offsets : apply the updated image parameters\n"); 705 fprintf (stderr, " -update-objects : calculate average astrometric properties of objects\n"); 706 fprintf (stderr, " -high-speed (code[,code,code]) (code[,code,code]) (radius) (output catdir)\n"); 707 fprintf (stderr, " support for the special high-speed mode\n"); 708 709 fprintf (stderr, " additional options: \n"); 710 fprintf (stderr, " -pm : calculate proper motions\n"); 711 fprintf (stderr, " -par : calculate parallaxes\n"); 712 fprintf (stderr, " -pmpar : calculate motions and parallaxes\n"); 713 fprintf (stderr, " -region Rmin Rmax Dmin Dmax"); 714 fprintf (stderr, " -catalog RA DEC"); 715 fprintf (stderr, " -time (start)(stop)\n"); 716 fprintf (stderr, " +photcode (code)[,code,code...]\n"); 717 fprintf (stderr, " -photcode (code)[,code,code...]\n"); 718 fprintf (stderr, " -statmode (mode)\n"); 719 fprintf (stderr, " -reset\n"); 720 fprintf (stderr, " -minerror\n"); 721 fprintf (stderr, " -instmag min max\n\n"); 722 fprintf (stderr, " +photflags\n"); 723 fprintf (stderr, " -photflagbad\n"); 724 fprintf (stderr, " -photflagpoor\n"); 725 fprintf (stderr, " -v\n"); 726 fprintf (stderr, " \n"); 727 exit (2); 728 } 729 396 730 void usage_merge_source_id (char *name) { 397 731 -
trunk/Ohana/src/relastro/src/bcatalog.c
r31664 r33652 1 1 # include "relastro.h" 2 3 static int Nskip1 = 0; 4 static int Nskip2 = 0; 5 static unsigned int Tref = 1323353985; 6 static short Cref = 10355; 2 7 3 8 int bcatalog (Catalog *subcatalog, Catalog *catalog) { … … 12 17 13 18 /* we are moving only the subset of measurements from catalog[0] to subcatalog[0] */ 19 memset(subcatalog, 0, sizeof(Catalog)); 14 20 NAVERAGE = 50; 15 21 NMEASURE = 1000; 16 ALLOCATE (subcatalog[0].average, Average,NAVERAGE);17 ALLOCATE (subcatalog[0].secfilt, SecFilt,NAVERAGE*Nsecfilt);18 ALLOCATE (subcatalog[0].measure , Measure, NMEASURE);22 ALLOCATE (subcatalog[0].average, Average, NAVERAGE); 23 ALLOCATE (subcatalog[0].secfilt, SecFilt, NAVERAGE*Nsecfilt); 24 ALLOCATE (subcatalog[0].measureT, MeasureTiny, NMEASURE); 19 25 Nmeasure = Naverage = 0; 26 27 DVOAverageFlags averageBits = 28 ID_STAR_FEW | 29 ID_STAR_POOR | 30 ID_STAR_FIT_AVE | 31 ID_STAR_FIT_PM | 32 ID_STAR_FIT_PAR | 33 ID_STAR_USE_AVE | 34 ID_STAR_USE_PM | 35 ID_STAR_USE_PAR; 20 36 21 37 /* exclude stars not in range or with too few measurements */ … … 23 39 if (catalog[0].average[i].Nmeasure <= SRC_MEAS_TOOFEW) { 24 40 continue; 41 // XXX can't (easily) count this for a given chip 25 42 } 26 43 … … 33 50 34 51 if (RESET) { 35 // XXX reset the ra,dec coords? 36 // XXX define astrometry vs photometry average.dbFlags 37 // XXX put photometry flags in secfilt (ie, per average mag?) 38 subcatalog[0].average[Naverage].flags &= ~ID_STAR_FEW; 39 subcatalog[0].average[Naverage].flags &= ~ID_STAR_POOR; 52 subcatalog[0].average[Naverage].flags &= ~averageBits; 40 53 } 41 54 … … 48 61 if (!MeasFilterTest(&catalog[0].measure[offset], TRUE)) { 49 62 catalog[0].measure[offset].dbFlags &= ~ID_MEAS_USED_CHIP; 63 if (FALSE && (abs(catalog[0].measure[offset].t - Tref) < 10) && (catalog[0].measure[offset].photcode == Cref)) { 64 Nskip1 ++; 65 } 50 66 continue; 51 67 } … … 54 70 if (FlagOutlier && (catalog[0].measure[offset].dbFlags & ID_MEAS_POOR_ASTROM)) { 55 71 catalog[0].measure[offset].dbFlags &= ~ID_MEAS_USED_CHIP; 72 if (FALSE && (abs(catalog[0].measure[offset].t - Tref) < 10) && (catalog[0].measure[offset].photcode == Cref)) { 73 Nskip2 ++; 74 } 56 75 continue; 57 76 } … … 70 89 // allowed. 71 90 72 // CopyMeasureTiny (&subcatalog[0].measureT[Nmeasure], &catalog[0].measure[offset]); 73 74 subcatalog[0].measure[Nmeasure] = catalog[0].measure[offset]; 75 subcatalog[0].measure[Nmeasure].dbFlags &= ~ID_MEAS_SKIP_ASTROM; 76 subcatalog[0].measure[Nmeasure].dbFlags &= ~ID_MEAS_NOCAL; 77 subcatalog[0].measure[Nmeasure].averef = Naverage; 91 CopyMeasureToTiny (&subcatalog[0].measureT[Nmeasure], &catalog[0].measure[offset]); 92 // subcatalog[0].measure[Nmeasure] = catalog[0].measure[offset]; 93 subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_SKIP_ASTROM; 94 subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_NOCAL; 95 subcatalog[0].measureT[Nmeasure].averef = Naverage; 78 96 if (RESET) { 79 subcatalog[0].measure [Nmeasure].dbFlags &= ~ID_MEAS_POOR_ASTROM;80 subcatalog[0].measure [Nmeasure].dbFlags &= ~ID_MEAS_AREA;97 subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_POOR_ASTROM; 98 subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_AREA; 81 99 } 82 100 … … 85 103 if (Nmeasure == NMEASURE) { 86 104 NMEASURE += 1000; 87 REALLOCATE (subcatalog[0].measure , Measure, NMEASURE);105 REALLOCATE (subcatalog[0].measureT, MeasureTiny, NMEASURE); 88 106 } 89 107 } … … 96 114 } 97 115 } 98 REALLOCATE (subcatalog[0].average, Average,MAX (Naverage, 1));99 REALLOCATE (subcatalog[0].measure , Measure, MAX (Nmeasure, 1));100 REALLOCATE (subcatalog[0].secfilt, SecFilt,MAX (Naverage, 1)*Nsecfilt);116 REALLOCATE (subcatalog[0].average, Average, MAX (Naverage, 1)); 117 REALLOCATE (subcatalog[0].measureT, MeasureTiny, MAX (Nmeasure, 1)); 118 REALLOCATE (subcatalog[0].secfilt, SecFilt, MAX (Naverage, 1)*Nsecfilt); 101 119 subcatalog[0].Naverage = Naverage; 102 120 subcatalog[0].Nmeasure = Nmeasure; 103 121 subcatalog[0].Nsecfilt = catalog[0].Nsecfilt; 104 subcatalog[0].Nsecf_mem = Naverage * Nsecfilt; 122 subcatalog[0].Nsecfilt = catalog[0].Nsecfilt; 123 subcatalog[0].catID = catalog[0].catID; 105 124 assert (Nsecfilt == catalog[0].Nsecfilt); 106 125 107 126 // limit the total number of stars in the catalog 108 127 if (MaxDensityUse) { 109 LimitDensityCatalog (subcatalog, catalog); 110 } 111 112 if (VERBOSE) { 113 fprintf (stderr, OFF_T_FMT": using "OFF_T_FMT" stars ("OFF_T_FMT" measures) for catalog\n", i, subcatalog[0].Naverage, subcatalog[0].Nmeasure); 114 } 128 LimitDensityCatalog_ByNmeasure (subcatalog, catalog); 129 } else { 130 if (VERBOSE2) { 131 char *basename = filebasename (catalog[0].filename); 132 fprintf (stderr, "subset of "OFF_T_FMT" ("OFF_T_FMT" total) stars, "OFF_T_FMT" ("OFF_T_FMT" total) measures for catalog %s\n", 133 subcatalog[0].Naverage, catalog[0].Naverage, subcatalog[0].Nmeasure, catalog[0].Nmeasure, basename); 134 free (basename); 135 } 136 } 115 137 return (TRUE); 116 138 } 117 139 140 void bcatalog_show_skips () { 141 fprintf (stderr, "Nskip: %d, %d\n", Nskip1, Nskip2); 142 } 143 144 // sort by decreasing Nmeasure (X) 145 void sort_by_Nmeasure (int *X, off_t *Y, off_t N) { 146 147 # define SWAPFUNC(A,B){ int tmpI; off_t tmpT; \ 148 tmpI = X[A]; X[A] = X[B]; X[B] = tmpI; \ 149 tmpT = Y[A]; Y[A] = Y[B]; Y[B] = tmpT; \ 150 } 151 # define COMPARE(A,B)(X[A] > X[B]) 152 153 OHANA_SORT (N, COMPARE, SWAPFUNC); 154 155 # undef SWAPFUNC 156 # undef COMPARE 157 158 } 159 118 160 /* this version does NOT use AverageTiny, MeasureTiny */ 119 int LimitDensityCatalog (Catalog *subcatalog, Catalog *catalog) {161 int LimitDensityCatalog_ByNmeasure (Catalog *subcatalog, Catalog *oldcatalog) { 120 162 121 163 Catalog tmpcatalog; … … 125 167 int Nsecfilt = GetPhotcodeNsecfilt (); 126 168 127 gfits_scan (& catalog[0].header, "RA0", "%lf", 1, &Rmin);128 gfits_scan (& catalog[0].header, "DEC0", "%lf", 1, &Dmin);129 gfits_scan (& catalog[0].header, "RA1", "%lf", 1, &Rmax);130 gfits_scan (& catalog[0].header, "DEC1", "%lf", 1, &Dmax);169 gfits_scan (&oldcatalog[0].header, "RA0", "%lf", 1, &Rmin); 170 gfits_scan (&oldcatalog[0].header, "DEC0", "%lf", 1, &Dmin); 171 gfits_scan (&oldcatalog[0].header, "RA1", "%lf", 1, &Rmax); 172 gfits_scan (&oldcatalog[0].header, "DEC1", "%lf", 1, &Dmax); 131 173 132 174 if (VERBOSE2) fprintf (stderr, "extracting from catalog covering region %f,%f to %f,%f\n", Rmin, Dmin, Rmax, Dmax); … … 147 189 // select a random subset of Nmax stars from subcatalog using Fisher-Yates 148 190 149 // we are going to select Nmax entries by generating a random-sorted index list 150 off_t *index, tmp, i, j, ave; 191 // we are going to select Nmax entries by choosing the brightest objects 192 int *value; 193 off_t *index, i, j, ave; 151 194 ALLOCATE (index, off_t, Naverage); 195 ALLOCATE (value, int, Naverage); 152 196 for (i = 0; i < Naverage; i++) { 153 197 index[i] = i; 154 } 155 for (i = 0; i < Naverage; i++) { 156 j = (Naverage - i) * drand48() + i; // a number between i and Naverage 157 tmp = index[j]; 158 index[j] = index[i]; 159 index[i] = tmp; 160 } 198 value[i] = subcatalog[0].average[i].Nmeasure; 199 } 200 sort_by_Nmeasure (value, index, Naverage); 161 201 162 202 // count the number of measurements this selection will yield … … 168 208 169 209 // allocate the output data 170 ALLOCATE (tmpcatalog.average, Average,Nmax);171 ALLOCATE (tmpcatalog.measure , Measure, NMEASURE);172 ALLOCATE (tmpcatalog.secfilt, SecFilt,Nmax * Nsecfilt);210 ALLOCATE (tmpcatalog.average, Average, Nmax); 211 ALLOCATE (tmpcatalog.measureT, MeasureTiny, NMEASURE); 212 ALLOCATE (tmpcatalog.secfilt, SecFilt, Nmax * Nsecfilt); 173 213 174 214 off_t Nmeasure = 0; … … 181 221 for (j = 0; j < tmpcatalog.average[i].Nmeasure; j++) { 182 222 off_t offset = subcatalog[0].average[ave].measureOffset + j; 183 tmpcatalog.measure [Nmeasure] = subcatalog[0].measure[offset];184 tmpcatalog.measure [Nmeasure].averef = i;223 tmpcatalog.measureT[Nmeasure] = subcatalog[0].measureT[offset]; 224 tmpcatalog.measureT[Nmeasure].averef = i; 185 225 Nmeasure ++; 186 226 } 187 } 188 189 if (VERBOSE) { 227 for (j = 0; j < Nsecfilt; j++) { 228 tmpcatalog.secfilt[i*Nsecfilt + j] = subcatalog[0].secfilt[ave*Nsecfilt + j]; 229 } 230 } 231 232 if (VERBOSE2) { 233 char *basename = filebasename (oldcatalog[0].filename); 234 fprintf (stderr, "limited to "OFF_T_FMT" ("OFF_T_FMT" subset, "OFF_T_FMT" total) stars, "OFF_T_FMT" ("OFF_T_FMT" subset, "OFF_T_FMT" total) measures for catalog %s\n", 235 Nmax, subcatalog[0].Naverage, oldcatalog[0].Naverage, Nmeasure, subcatalog[0].Nmeasure, oldcatalog[0].Nmeasure, basename); 236 free (basename); 237 } 238 239 free (index); 240 free (value); 241 free (subcatalog[0].average); 242 free (subcatalog[0].measureT); 243 free (subcatalog[0].secfilt); 244 245 subcatalog[0].average = tmpcatalog.average; 246 subcatalog[0].measureT = tmpcatalog.measureT; 247 subcatalog[0].secfilt = tmpcatalog.secfilt; 248 subcatalog[0].Naverage = Nmax; 249 subcatalog[0].Nmeasure = Nmeasure; 250 subcatalog[0].Nsecfilt = oldcatalog[0].Nsecfilt; 251 subcatalog[0].Nsecf_mem = Naverage * oldcatalog[0].Nsecfilt; 252 253 return (TRUE); 254 } 255 256 /* this version does NOT use AverageTiny, MeasureTiny */ 257 int LimitDensityCatalog_RandomSample (Catalog *subcatalog, Catalog *catalog) { 258 259 Catalog tmpcatalog; 260 261 double Rmin, Rmax, Dmin, Dmax; 262 263 int Nsecfilt = GetPhotcodeNsecfilt (); 264 265 gfits_scan (&catalog[0].header, "RA0", "%lf", 1, &Rmin); 266 gfits_scan (&catalog[0].header, "DEC0", "%lf", 1, &Dmin); 267 gfits_scan (&catalog[0].header, "RA1", "%lf", 1, &Rmax); 268 gfits_scan (&catalog[0].header, "DEC1", "%lf", 1, &Dmax); 269 270 if (VERBOSE2) fprintf (stderr, "extracting from catalog covering region %f,%f to %f,%f\n", Rmin, Dmin, Rmax, Dmax); 271 272 float AREA = fabs(Dmax - Dmin) * fabs(Rmax - Rmin) * cos (0.5*RAD_DEG*(Dmax + Dmin)); 273 assert (AREA > 0); 274 275 off_t Nmax = MaxDensityValue * AREA; 276 if (subcatalog[0].Naverage <= Nmax) { 277 if (VERBOSE2) { 278 fprintf (stderr, "subcatalog has less than the max density\n"); 279 } 280 return (TRUE); 281 } 282 283 off_t Naverage = subcatalog[0].Naverage; 284 285 // select a random subset of Nmax stars from subcatalog using Fisher-Yates 286 287 // we are going to select Nmax entries by generating a random-sorted index list 288 off_t *index, tmp, i, j, ave; 289 ALLOCATE (index, off_t, Naverage); 290 for (i = 0; i < Naverage; i++) { 291 index[i] = i; 292 } 293 for (i = 0; i < Naverage; i++) { 294 j = (Naverage - i) * drand48() + i; // a number between i and Naverage 295 tmp = index[j]; 296 index[j] = index[i]; 297 index[i] = tmp; 298 } 299 300 // count the number of measurements this selection will yield 301 off_t NMEASURE = 0; 302 for (i = 0; i < Nmax; i++) { 303 ave = index[i]; 304 NMEASURE += subcatalog[0].average[ave].Nmeasure; 305 } 306 307 // allocate the output data 308 ALLOCATE (tmpcatalog.average, Average, Nmax); 309 ALLOCATE (tmpcatalog.measureT, MeasureTiny, NMEASURE); 310 ALLOCATE (tmpcatalog.secfilt, SecFilt, Nmax * Nsecfilt); 311 312 off_t Nmeasure = 0; 313 314 // copy the Nmax selected entries from subcatalog to tmpcatalog (adjusting links) 315 for (i = 0; i < Nmax; i++) { 316 ave = index[i]; 317 tmpcatalog.average[i] = subcatalog[0].average[ave]; 318 tmpcatalog.average[i].measureOffset = Nmeasure; 319 for (j = 0; j < tmpcatalog.average[i].Nmeasure; j++) { 320 off_t offset = subcatalog[0].average[ave].measureOffset + j; 321 tmpcatalog.measureT[Nmeasure] = subcatalog[0].measureT[offset]; 322 tmpcatalog.measureT[Nmeasure].averef = i; 323 Nmeasure ++; 324 } 325 for (j = 0; j < Nsecfilt; j++) { 326 tmpcatalog.secfilt[i*Nsecfilt + j] = subcatalog[0].secfilt[ave*Nsecfilt + j]; 327 } 328 } 329 330 if (VERBOSE2) { 190 331 fprintf (stderr, "limited to "OFF_T_FMT" of "OFF_T_FMT" stars ("OFF_T_FMT" of "OFF_T_FMT" measures) for catalog %s\n", 191 332 Nmax, subcatalog[0].Naverage, Nmeasure, subcatalog[0].Nmeasure, catalog[0].filename); … … 193 334 194 335 free (subcatalog[0].average); 195 free (subcatalog[0].measure );336 free (subcatalog[0].measureT); 196 337 free (subcatalog[0].secfilt); 197 338 198 339 subcatalog[0].average = tmpcatalog.average; 199 subcatalog[0].measure = tmpcatalog.measure;340 subcatalog[0].measureT = tmpcatalog.measureT; 200 341 subcatalog[0].secfilt = tmpcatalog.secfilt; 201 342 subcatalog[0].Naverage = Nmax; -
trunk/Ohana/src/relastro/src/dvo_astrom_ops.c
r12332 r33652 1 1 # include "relastro.h" 2 2 3 double getMeanR (Measure *measure, Average *average, SecFilt *secfilt) {3 double getMeanR (MeasureTiny *measure, Average *average, SecFilt *secfilt) { 4 4 5 5 double ra; … … 21 21 } 22 22 23 double getMeanD (Measure *measure, Average *average, SecFilt *secfilt) {23 double getMeanD (MeasureTiny *measure, Average *average, SecFilt *secfilt) { 24 24 25 25 double dec; … … 41 41 } 42 42 43 int setMeanR (double ra_fit, Measure *measure, Average *average, SecFilt *secfilt) {43 int setMeanR (double ra_fit, MeasureTiny *measure, Average *average, SecFilt *secfilt) { 44 44 45 45 /* math to get from new fitted position to new measure offset … … 66 66 } 67 67 68 int setMeanD (double dec_fit, Measure *measure, Average *average, SecFilt *secfilt) {68 int setMeanD (double dec_fit, MeasureTiny *measure, Average *average, SecFilt *secfilt) { 69 69 70 70 /* math to get from new fitted position to new measure offset … … 90 90 return (TRUE); 91 91 } 92 93 int setMeanR_Big (double ra_fit, Measure *measure, Average *average, SecFilt *secfilt) { 94 95 if (!measure) return TRUE; 96 97 /* math to get from new fitted position to new measure offset 98 ra_obs = average[0].R - measure[0].dR / 3600.0; 99 measure[0].dR = (ra_fit - ra_obs) * 3600.0; 100 measure[0].dR = (ra_fit - average[0].R + measure[0].dR/3600) * 3600.0 101 measure[0].dR = (ra_fit - average[0].R) * 3600.0 + measure[0].dR; 102 */ 103 104 /* the measure carries the instantaneous mean position at the epoch t */ 105 measure[0].dR += (ra_fit - average[0].R) * 3600.0; 106 107 /* possible corrections to mean ra: 108 109 - proper-motion and parallax 110 - abberation 111 - precession and nutation, etc 112 - refraction 113 - DCR 114 115 */ 116 117 return (TRUE); 118 } 119 120 int setMeanD_Big (double dec_fit, Measure *measure, Average *average, SecFilt *secfilt) { 121 122 if (!measure) return TRUE; 123 124 /* math to get from new fitted position to new measure offset 125 dec_obs = average[0].D - measure[0].dD / 3600.0; 126 measure[0].dD = (dec_fit - dec_obs) * 3600.0; 127 measure[0].dD = (dec_fit - average[0].D + measure[0].dD/3600) * 3600.0 128 measure[0].dD = (dec_fit - average[0].D) * 3600.0 + measure[0].dD; 129 */ 130 131 /* the measure carries the instantaneous mean position at the epoch t */ 132 measure[0].dD += (dec_fit - average[0].D) * 3600.0; 133 134 /* possible corrections to mean ra: 135 136 - proper-motion and parallax 137 - abberation 138 - precession and nutation, etc 139 - refraction 140 - DCR 141 142 */ 143 144 return (TRUE); 145 } -
trunk/Ohana/src/relastro/src/fitpoly.c
r29001 r33652 149 149 150 150 if (!dgaussjordan (matrix, vector, fit[0].Nelems, 2)) { 151 array_free (matrix, fit[0].Nelems); 152 array_free (vector, fit[0].Nelems); 151 153 return (FALSE); 152 154 } -
trunk/Ohana/src/relastro/src/high_speed_catalogs.c
r31635 r33652 1 1 # include "relastro.h" 2 2 3 int high_speed_catalogs () { 3 int high_speed_catalogs_parallel (SkyList *sky); 4 5 int high_speed_catalogs (SkyTable *sky, SkyList *skylist, int hostID, char *hostpath) { 4 6 5 7 int i; 6 7 SkyTable *sky = NULL;8 SkyList *skylist = NULL;9 8 Catalog catalog; 10 9 … … 12 11 dvo_set_catdir(CATDIR); 13 12 14 // load the current sky table (layout of all SkyRegions)15 sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, FALSE, SKY_DEPTH, VERBOSE);16 SkyTableSetFilenames (sky, CATDIR, "cpt");17 18 // determine the populated SkyRegions overlapping the requested area (default depth)19 if (UserCatalog) {20 skylist = SkyRegionByPoint (sky, -1, UserCatalogRA, UserCatalogDEC);21 setupAreaSelection(skylist->regions[0]);22 } else {23 skylist = SkyListByPatch (sky, -1, &UserPatch);24 setupAreaSelection(&UserPatch);25 }26 27 13 initializeConstraints(); 14 15 // XXX need to decide how to determine PARALLEL mode... 16 if (PARALLEL && !hostID) { 17 high_speed_catalogs_parallel (skylist); 18 goto finish; 19 } 28 20 29 21 // load data from each region file, only use bright stars 30 22 for (i = 0; i < skylist[0].Nregions; i++) { 31 23 24 // does this host ID match the desired location for the table? 25 if (!HostTableTestHost(skylist[0].regions[i], hostID)) continue; 26 32 27 // set up the basic catalog info 33 catalog.filename = skylist[0].filename[i]; 28 char hostfile[1024]; 29 snprintf (hostfile, 1024, "%s/%s.cpt", hostpath, skylist[0].regions[i]->name); 30 catalog.filename = hostID ? hostfile : skylist[0].filename[i]; 34 31 catalog.catformat = dvo_catalog_catformat (CATFORMAT); // set the default catformat from config data 35 32 catalog.catmode = dvo_catalog_catmode (CATMODE); // set the default catmode from config data … … 37 34 catalog.Nsecfilt = GetPhotcodeNsecfilt (); 38 35 39 if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE , "r")) {36 if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE2, "r")) { 40 37 fprintf (stderr, "ERROR: failure reading catalog %s\n", catalog.filename); 41 38 exit (1); 42 39 } 43 40 if (!catalog.Naves_disk) { 44 if (VERBOSE ) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);41 if (VERBOSE2) fprintf (stderr, "no data in %s, skipping\n", catalog.filename); 45 42 dvo_catalog_unlock (&catalog); 46 43 dvo_catalog_free (&catalog); … … 54 51 } 55 52 53 finish: 54 55 // in relastro (NOT relastr_client), save the Images.dat, Photcodes.dat, SkyTable.fits files 56 if (!hostID) { 57 char photcodeFile[1024]; 58 snprintf (photcodeFile, 1024, "%s/Photcodes.dat", HIGH_SPEED_DIR); 59 if (!SavePhotcodesFITS (photcodeFile)) { 60 fprintf (stderr, "error saving photcode table %s\n", photcodeFile); 61 exit (1); 62 } 63 64 // need to copy across the Images, SkyTable, and Photcode tables: 65 char *skyfile = SkyTableFilename (HIGH_SPEED_DIR); 66 SkyTableSave (sky, skyfile); 67 68 char line[2048]; 69 snprintf (line, 2048, "cp %s/Images.dat %s/Images.dat", CATDIR, HIGH_SPEED_DIR); 70 system (line); 71 } 72 56 73 return (TRUE); 57 74 } 75 76 // CATDIR is supplied globally 77 # define DEBUG 1 78 int high_speed_catalogs_parallel (SkyList *skylist) { 79 80 // launch the setphot_client jobs to the parallel hosts 81 82 // load the list of hosts 83 HostTable *table = HostTableLoad (CATDIR, skylist->hosts); 84 if (!table) { 85 fprintf (stderr, "ERROR: failure reading Host Table %s for database %s\n", skylist->hosts, CATDIR); 86 exit (1); 87 } 88 89 // If we want to parallelize the output, the remote client needs to load the HostTable 90 // for the output catdir. Require the output HostTable to match the input (ie, same 91 // hostIDs must exist). Preferred, but not required, that they match in the host 92 // location. 93 HostTable *tableOut = NULL; 94 if (PARALLEL_OUTPUT) { 95 // load the list of hosts 96 tableOut = HostTableLoad (HIGH_SPEED_DIR, skylist->hosts); 97 if (!tableOut) { 98 fprintf (stderr, "ERROR: failure reading Host Table %s for output database %s\n", skylist->hosts, HIGH_SPEED_DIR); 99 exit (1); 100 } 101 if (table->Nhosts != tableOut->Nhosts) { 102 fprintf (stderr, "ERROR: output HostTable must have matching hosts (%d in, %d out)\n", table->Nhosts, tableOut->Nhosts); 103 exit (1); 104 } 105 } 106 107 int i; 108 for (i = 0; i < table->Nhosts; i++) { 109 110 // ensure that the paths are absolute path names 111 char *tmppath = abspath (table->hosts[i].pathname, MAX_PATH_LENGTH); 112 free (table->hosts[i].pathname); 113 table->hosts[i].pathname = tmppath; 114 115 // use this directory to save the output catalogs (distributed if parallel) 116 char *outputDir = strcreate(HIGH_SPEED_DIR); 117 if (PARALLEL_OUTPUT) { 118 // find the matching host entry in the output HostTable (match by ID, not index) 119 int hostID = table->hosts[i].hostID; 120 int index = table->index[hostID]; 121 if (index == -1) { 122 fprintf (stderr, "ERROR: output HostTable must have matching hosts (host ID %d not found)\n", hostID); 123 exit (1); 124 } 125 126 free (outputDir); 127 outputDir = abspath (tableOut->hosts[index].pathname, MAX_PATH_LENGTH); 128 } 129 130 char command[1024]; 131 snprintf (command, 1024, "relastro_client -high-speed %s %s %f %s -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f", 132 PHOTCODE_A_LIST, PHOTCODE_B_LIST, RADIUS, outputDir, table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax); 133 134 free (outputDir); 135 136 // options / arguments that can affect relastro_client -high-speed 137 char tmpline[1024]; 138 if (FIT_MODE == FIT_PM_ONLY) { snprintf (tmpline, 1024, "%s -pm", command); strcpy (command, tmpline); } 139 if (FIT_MODE == FIT_PAR_ONLY) { snprintf (tmpline, 1024, "%s -par", command); strcpy (command, tmpline); } 140 if (FIT_MODE == FIT_PM_AND_PAR) { snprintf (tmpline, 1024, "%s -pmpar", command); strcpy (command, tmpline); } 141 142 if (VERBOSE) { snprintf (tmpline, 1024, "%s -v", command); strcpy (command, tmpline); } 143 if (VERBOSE2) { snprintf (tmpline, 1024, "%s -vv", command); strcpy (command, tmpline); } 144 if (RESET) { snprintf (tmpline, 1024, "%s -reset", command); strcpy (command, tmpline); } 145 if (ImagSelect) { snprintf (tmpline, 1024, "%s -instmag %f %f", command, ImagMin, ImagMax); strcpy (command, tmpline); } 146 if (MaxDensityUse) { snprintf (tmpline, 1024, "%s -max-density %f", command, MaxDensityValue); strcpy (command, tmpline); } 147 148 if (USE_BASIC_CHECK) { snprintf (tmpline, 1024, "%s -basic-image-search", command); strcpy (command, tmpline); } 149 150 if (FlagOutlier) { snprintf (tmpline, 1024, "%s -clip %d", command, CLIP_THRESH); strcpy (command, tmpline); } 151 152 if (PHOTCODE_KEEP_LIST) { snprintf (tmpline, 1024, "%s +photcode %s", command, PHOTCODE_KEEP_LIST); strcpy (command, tmpline); } 153 if (PHOTCODE_SKIP_LIST) { snprintf (tmpline, 1024, "%s -photcode %s", command, PHOTCODE_SKIP_LIST); strcpy (command, tmpline); } 154 if (PhotFlagSelect) { snprintf (tmpline, 1024, "%s +photflags", command); strcpy (command, tmpline); } 155 if (PhotFlagBad) { snprintf (tmpline, 1024, "%s +photflagbad %d", command, PhotFlagBad); strcpy (command, tmpline); } 156 if (PhotFlagPoor) { snprintf (tmpline, 1024, "%s +photflagpoor %d", command, PhotFlagPoor); strcpy (command, tmpline); } 157 // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values 158 159 if (WHERE_A[0]) { snprintf (tmpline, 1024, "%s -D WHERE_A \"%s\"", command, WHERE_A); strcpy (command, tmpline); } 160 if (WHERE_B[0]) { snprintf (tmpline, 1024, "%s -D WHERE_B \"%s\"", command, WHERE_B); strcpy (command, tmpline); } 161 162 if (TimeSelect) { 163 char *tstart = ohana_sec_to_date (TSTART); 164 char *tstop = ohana_sec_to_date (TSTOP); 165 snprintf (tmpline, 1024, "%s -time %s %s", command, tstart, tstop); 166 free (tstart); 167 free (tstop); 168 strcpy (command, tmpline); 169 } 170 171 fprintf (stderr, "command: %s\n", command); 172 173 if (PARALLEL_MANUAL) continue; 174 175 if (PARALLEL_SERIAL) { 176 int status = system (command); 177 if (status) { 178 fprintf (stderr, "ERROR running relastro_client\n"); 179 exit (2); 180 } 181 } else { 182 // launch the job on the remote machine (no handshake) 183 int errorInfo = 0; 184 int pid = rconnect ("ssh", table->hosts[i].hostname, command, table->hosts[i].stdio, &errorInfo, FALSE); 185 if (!pid) { 186 if (DEBUG) fprintf (stderr, "failure to start %s (error %d)\n", table->hosts[i].hostname, errorInfo); 187 exit (1); 188 } 189 table->hosts[i].pid = pid; // save for future reference 190 } 191 } 192 193 if (PARALLEL_MANUAL) { 194 fprintf (stderr, "run the relastro_client commands above. when these are done, hit return\n"); 195 getchar(); 196 } 197 if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) { 198 HostTableWaitJobsGetIO (table, __FILE__, __LINE__, VERBOSE); 199 } 200 201 return TRUE; 202 } -
trunk/Ohana/src/relastro/src/high_speed_objects.c
r31635 r33652 6 6 int high_speed_objects (SkyRegion *region, Catalog *catalog) { 7 7 8 // XXX seems silly to require region here just to find the catalog bounds / center9 10 off_t i, j, m, J, ni, nj, *N1, Nslow, Ninvalid, NgroupA, NgroupB, NgroupAbad, NgroupBbad,l,i1,Noff,Nmeasure,Naverage, NAVERAGE, NMEASURE;11 int *slowMoving, *groupA, *groupB, status, Nmatch, Nmatchmeas, Nepoch,nv[2],Nmatchmeasobj;12 int foundA, foundB ;8 off_t i, j, m, J, ni, nj, *N1; 9 off_t Nslow, Ninvalid, NgroupA, NgroupB, NgroupAbad, NgroupBbad; 10 off_t l, i1, NAVERAGE, NMEASURE; 11 int *slowMoving, *groupA, *groupB, status, Nmatch, Nmatchmeas, Nepoch, nv[2], Nmatchmeasobj; 12 int foundA, foundB, XVERB; 13 13 double *X1, *Y1; 14 14 double dX, dY, dR, RADIUS2; 15 15 Coords tcoords; 16 Catalog catalog 1;16 Catalog catalogOut; 17 17 18 18 int Nsecfilt; 19 19 char filename[1024]; 20 Noff = strlen(CATDIR); 21 sprintf (filename, "%s%s", HIGH_SPEED_DIR, &catalog[0].filename[Noff]); 22 fprintf(stderr, "%s\n",filename); 23 dvo_catalog_init(&catalog1, TRUE); /*initialise new catalogue*/ 24 catalog1.filename = strcreate(filename); 20 21 snprintf (filename, 1024, "%s/%s.cpt", HIGH_SPEED_DIR, region[0].name); 22 fprintf (stderr, "%s\n",filename); 23 24 dvo_catalog_init (&catalogOut, TRUE); /*initialise new catalogue*/ 25 catalogOut.filename = strcreate(filename); 25 26 26 27 SIGMA_LIM = 0.0; 27 28 28 29 Nsecfilt = GetPhotcodeNsecfilt(); 29 Naverage=catalog[0].Naverage; 30 Nmeasure=catalog[0].Nmeasure; 31 catalog1.filename = filename; // based on the input name, need to keep everything below the catdir portion 32 catalog1.Nsecfilt = Nsecfilt; 33 // always load all of the data (if any exists) 34 catalog1.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF; 30 // off_t Naverage = catalog[0].Naverage; 31 // off_t Nmeasure = catalog[0].Nmeasure; 32 catalogOut.filename = filename; // based on the input name, need to keep everything below the catdir portion 33 catalogOut.Nsecfilt = Nsecfilt; 34 catalogOut.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF; // load all data 35 35 36 catalog 1.catformat = dvo_catalog_catformat (CATFORMAT); // set the default catformat from config data37 catalog 1.catmode = dvo_catalog_catmode (CATMODE); // set the default catmode from config data38 39 if (!dvo_catalog_open (&catalog 1, region, VERBOSE,"w")) {36 catalogOut.catformat = dvo_catalog_catformat (CATFORMAT); // set the default catformat from config data 37 catalogOut.catmode = dvo_catalog_catmode (CATMODE); // set the default catmode from config data 38 39 if (!dvo_catalog_open (&catalogOut, region, VERBOSE2,"w")) { 40 40 fprintf (stderr, "ERROR: failure to open catalog file %s\n", 41 41 filename); … … 45 45 NAVERAGE = 1000; 46 46 NMEASURE = 10000; 47 REALLOCATE (catalog 1.average, Average, NAVERAGE);48 REALLOCATE (catalog 1.measure, Measure, NMEASURE);49 REALLOCATE (catalog1.secfilt, SecFilt, NAVERAGE*Nsecfilt);47 REALLOCATE (catalogOut.average, Average, NAVERAGE); 48 REALLOCATE (catalogOut.measure, Measure, NMEASURE); 49 REALLOCATE (catalogOut.secfilt, SecFilt, NAVERAGE*Nsecfilt); 50 50 51 51 // high-speed between different surveys (easier case): … … 77 77 // mark (exclude) objects with both sets of target photcodes 78 78 for (i = 0; i < catalog[0].Naverage; i++) { 79 80 XVERB = (catalog[0].average[i].objID == OBJ_ID_SRC) && (catalog[0].average[i].catID == CAT_ID_SRC); 81 XVERB |= (catalog[0].average[i].objID == OBJ_ID_DST) && (catalog[0].average[i].catID == CAT_ID_DST); 82 if (XVERB) { 83 fprintf (stderr, "test object\n"); 84 } 85 79 86 // do any of the measures for this object match group A? 80 87 m = catalog[0].average[i].measureOffset; … … 114 121 // fprintf (stderr, "skip "OFF_T_FMT" (group A)\n", i); 115 122 } 116 117 } else if (foundB && !foundA) {118 123 continue; 124 } 125 if (foundB && !foundA) { 119 126 if (applyConstraintsB(catalog, i)) { 120 127 groupB[i] = TRUE; … … 124 131 NgroupBbad++; 125 132 } 133 continue; 126 134 } 127 135 // this object does not have a detection matching the contraints from either gorupA or groupB -- skip as if slow … … 173 181 nj = N1[j]; 174 182 183 XVERB = (catalog[0].average[ni].objID == OBJ_ID_SRC) && (catalog[0].average[ni].catID == CAT_ID_SRC); 184 XVERB |= (catalog[0].average[nj].objID == OBJ_ID_DST) && (catalog[0].average[nj].catID == CAT_ID_DST); 185 if (XVERB) { 186 fprintf (stderr, "test object %d or %d\n", (int) ni, (int) nj); 187 } 188 175 189 if (slowMoving[ni]) NEXT_I; 176 190 if (slowMoving[nj]) NEXT_J; … … 185 199 // look for pairs that are within the maximum separation 186 200 dX = X1[i] - X1[j]; 201 if (XVERB) { 202 fprintf (stderr, "%d %d : %f\n", (int) ni, (int) nj, dX); 203 } 187 204 188 205 if (dX <= -1.02*RADIUS) NEXT_I; // negative dX: i is too small … … 197 214 nj = N1[J]; 198 215 if (!groupB[nj]) continue; 216 217 XVERB = (catalog[0].average[ni].objID == OBJ_ID_SRC) && (catalog[0].average[ni].catID == CAT_ID_SRC); 218 XVERB |= (catalog[0].average[nj].objID == OBJ_ID_DST) && (catalog[0].average[nj].catID == CAT_ID_DST); 219 if (XVERB) { 220 fprintf (stderr, "test object pt2 %d or %d : %f\n", (int) ni, (int) nj, dX); 221 fprintf (stderr, ".\n"); 222 } 199 223 200 224 dY = Y1[i] - Y1[J]; … … 209 233 nv[1]=nj; 210 234 211 catalog 1.average[Nmatch]=catalog[0].average[nv[0]];235 catalogOut.average[Nmatch]=catalog[0].average[nv[0]]; 212 236 /*Loop over index values and set measurements in new catalogue*/ 213 237 Nmatchmeasobj=0; 214 catalog 1.average[Nmatch].measureOffset=Nmatchmeas;238 catalogOut.average[Nmatch].measureOffset=Nmatchmeas; 215 239 for(l=0;l<Nepoch;l++) { 216 240 m = catalog[0].average[nv[l]].measureOffset; 217 241 for(i1=0;i1<catalog[0].average[nv[l]].Nmeasure;i1++) { 218 catalog 1.measure[Nmatchmeas]=catalog[0].measure[m+i1];242 catalogOut.measure[Nmatchmeas]=catalog[0].measure[m+i1]; 219 243 /*Set offset RA and Dec wrt correct average value*/ 220 catalog 1.measure[Nmatchmeas].dR=catalog[0].measure[m+i1].dR+3600.0*(catalog[0].average[nv[0]].R-catalog[0].average[nv[l]].R);221 catalog 1.measure[Nmatchmeas].dD=catalog[0].measure[m+i1].dD+3600.0*(catalog[0].average[nv[0]].D-catalog[0].average[nv[l]].D);222 catalog 1.measure[Nmatchmeas].averef = Nmatch;244 catalogOut.measure[Nmatchmeas].dR=catalog[0].measure[m+i1].dR+3600.0*(catalog[0].average[nv[0]].R-catalog[0].average[nv[l]].R); 245 catalogOut.measure[Nmatchmeas].dD=catalog[0].measure[m+i1].dD+3600.0*(catalog[0].average[nv[0]].D-catalog[0].average[nv[l]].D); 246 catalogOut.measure[Nmatchmeas].averef = Nmatch; 223 247 Nmatchmeasobj++; 224 248 Nmatchmeas++; … … 226 250 if (Nmatchmeas == NMEASURE - 1) { 227 251 NMEASURE += 10000; 228 REALLOCATE (catalog 1.measure, Measure, NMEASURE);252 REALLOCATE (catalogOut.measure, Measure, NMEASURE); 229 253 } 230 254 } 231 255 } 232 catalog 1.average[Nmatch].Nmeasure=Nmatchmeasobj;256 catalogOut.average[Nmatch].Nmeasure = Nmatchmeasobj; 233 257 Nmatch ++; 234 258 235 259 if (Nmatch == NAVERAGE - 1) { 236 260 NAVERAGE += 1000; 237 REALLOCATE (catalog 1.average, Average, NAVERAGE);238 REALLOCATE(catalog 1.secfilt, SecFilt, NAVERAGE*Nsecfilt);261 REALLOCATE (catalogOut.average, Average, NAVERAGE); 262 REALLOCATE(catalogOut.secfilt, SecFilt, NAVERAGE*Nsecfilt); 239 263 } 240 264 } 241 265 i++; 242 266 } 243 catalog1.Naverage=Nmatch; 244 catalog1.Nmeasure=Nmatchmeas; 245 catalog1.Nsecfilt=Nsecfilt; 246 catalog1.Nsecf_mem=Nmatch*Nsecfilt; 247 248 UpdateObjects(&catalog1, 1); 267 catalogOut.Naverage=Nmatch; 268 catalogOut.Nmeasure=Nmatchmeas; 269 catalogOut.Nsecfilt=Nsecfilt; 270 catalogOut.Nsecf_mem=Nmatch*Nsecfilt; 271 272 populate_tiny_values (&catalogOut, DVO_TV_MEASURE); 273 UpdateObjects (&catalogOut, 1); 249 274 250 275 fprintf (stderr, "found %d matches\n", Nmatch); 251 dvo_catalog_save (&catalog 1, VERBOSE);252 dvo_catalog_unlock (&catalog 1);253 dvo_catalog_free (&catalog 1);276 dvo_catalog_save (&catalogOut, VERBOSE2); 277 dvo_catalog_unlock (&catalogOut); 278 dvo_catalog_free (&catalogOut); 254 279 free (slowMoving); 255 280 free (groupA); … … 262 287 } 263 288 264 // return TRUE if any measure->photcodes match the photcodeSet 289 // return TRUE if measure->photcode match any in the photcodeSet 290 // (but, return FALSE if the measurement is bad) 265 291 int MeasMatchesPhotcode(Measure *measure, PhotCode **photcodeSet, int Nset) { 266 292 267 293 int found, k; 268 294 269 assert (Nset > 0); 270 271 if (!finite(measure[0].dR) || !finite(measure[0].dD)) return FALSE; 272 if (!finite(measure[0].M)) return FALSE; 295 if (!Nset) return TRUE; 296 // XXX require a set or not? assert (Nset > 0); 297 298 if (!finite(measure[0].dR)) return FALSE; 299 if (!finite(measure[0].dD)) return FALSE; 300 if (!finite(measure[0].M)) return FALSE; 273 301 302 float dX = GetAstromError (measure, ERROR_MODE_RA); 303 if (isnan(dX)) return FALSE; 304 305 float dY = GetAstromError (measure, ERROR_MODE_DEC); 306 if (isnan(dY)) return FALSE; 307 274 308 /* select measurements by photcode, or equiv photcode, if specified */ 275 if (Nset > 0) { 276 found = FALSE; 277 for (k = 0; (k < Nset) && !found; k++) { 278 if (photcodeSet[k][0].code == measure[0].photcode) found = TRUE; 279 if (photcodeSet[k][0].code == GetPhotcodeEquivCodebyCode(measure[0].photcode)) found = TRUE; 280 } 281 if (!found) return FALSE; 282 } 283 284 return TRUE; 309 found = FALSE; 310 for (k = 0; (k < Nset) && !found; k++) { 311 if (photcodeSet[k][0].code == measure[0].photcode) found = TRUE; 312 if (photcodeSet[k][0].code == GetPhotcodeEquivCodebyCode(measure[0].photcode)) found = TRUE; 313 } 314 315 return found; 285 316 } -
trunk/Ohana/src/relastro/src/high_speed_utils.c
r31635 r33652 17 17 static dbStack *stackA = NULL; 18 18 static int NstackA = 0; 19 19 20 static dbField *fieldsB = NULL; 20 21 static int NfieldsB = 0; 21 22 static dbStack *stackB = NULL; 22 23 static int NstackB = 0; 24 23 25 static dbValue *valuesA; 24 26 // static int NvaluesA; … … 41 43 ALLOCATE(words, char *, NwordsAllocated); 42 44 43 char *copy_of_str = str dup(string);45 char *copy_of_str = strcreate(string); 44 46 45 47 char *saveptr = NULL; … … 60 62 // Create the data strucutres required to apply avextract like cuts 61 63 int setupConstraints(char *whereString, dbField **pFields, int *pNfields, dbStack **pStack, int *pNstack) { 64 65 // an empty where is allowed (no further filtering) 66 if (!whereString[0]) return TRUE; 62 67 63 68 // split the string into words … … 89 94 90 95 int initializeConstraints() { 96 91 97 // if constaints haven't been set by the user use 2mass 92 if (!WHERE_A[0]) { 93 strcpy(WHERE_A, DEFAULT_WHERE_A); 94 } 95 if (!WHERE_B[0]) { 96 strcpy(WHERE_B, DEFAULT_WHERE_B); 97 } 98 // XXX if (!WHERE_A[0]) { 99 // XXX strcpy(WHERE_A, DEFAULT_WHERE_A); 100 // XXX } 101 // XXX if (!WHERE_B[0]) { 102 // XXX strcpy(WHERE_B, DEFAULT_WHERE_B); 103 // XXX } 104 105 fprintf (stderr, "where A: %s\n", WHERE_A); 106 fprintf (stderr, "where B: %s\n", WHERE_B); 107 108 // pull TIMEFORMAT & TIMEREF from the Config system 109 dbExtractAveragesInit(); 98 110 99 111 if (! setupConstraints(WHERE_A, &fieldsA, &NfieldsA, &stackA, &NstackA)) { … … 102 114 exit(1); 103 115 } 104 ALLOCATE(valuesA, dbValue, NfieldsA); 116 if (NfieldsA) { 117 ALLOCATE(valuesA, dbValue, NfieldsA); 118 } 119 105 120 if (! setupConstraints(WHERE_B, &fieldsB, &NfieldsB, &stackB, &NstackB)) { 106 121 print_error(); … … 108 123 exit(1); 109 124 } 110 ALLOCATE(valuesB, dbValue, NfieldsB); 125 if (NfieldsB) { 126 ALLOCATE(valuesB, dbValue, NfieldsB); 127 } 128 111 129 return TRUE; 112 130 } … … 116 134 int applyConstraintsA(Catalog *catalog, off_t i) { 117 135 off_t m = catalog[0].average[i].measureOffset; 118 off_t n;119 136 int Nsecfilt = GetPhotcodeNsecfilt(); 120 137 121 dbExtractAveragesInit(); 138 // an empty WHERE matches all objects 139 if (!NfieldsA) return TRUE; 140 141 off_t n; 122 142 for (n = 0; n < NfieldsA; n++) { 123 143 valuesA[n] = dbExtractAverages (&catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt], &catalog[0].measure[m], &fieldsA[n]); … … 130 150 int Nsecfilt = GetPhotcodeNsecfilt(); 131 151 132 dbExtractAveragesInit(); 152 // an empty WHERE matches all objects 153 if (!NfieldsB) return TRUE; 133 154 134 155 off_t n; -
trunk/Ohana/src/relastro/src/initialize.c
r32346 r33652 2 2 3 3 void initialize (int argc, char **argv) { 4 5 int NPHOTCODES;6 char *codename, *ptr, *list;7 8 ptr = NULL;9 4 10 5 ConfigInit (&argc, argv); … … 13 8 if (FIT_TARGET == TARGET_MERGE_SOURCE) return; 14 9 15 /* build a list of accepted photcodes. these will be used by bcatalog to accept or 16 reject loaded data */ 10 fprintf (stderr, "PHOTCODE_KEEP_LIST: %s\n", PHOTCODE_KEEP_LIST); 11 fprintf (stderr, "PHOTCODE_SKIP_LIST: %s\n", PHOTCODE_SKIP_LIST); 12 fprintf (stderr, "PHOTCODE_A_LIST: %s\n", PHOTCODE_A_LIST); 13 fprintf (stderr, "PHOTCODE_B_LIST: %s\n", PHOTCODE_B_LIST); 17 14 18 NphotcodesKeep = 0; 19 photcodesKeep = NULL; 20 if (PHOTCODE_KEEP_LIST != NULL) { 21 NPHOTCODES = 10; 22 ALLOCATE (photcodesKeep, PhotCode *, NPHOTCODES); 23 24 /* parse the comma-separated list of photcodesKeep */ 25 list = PHOTCODE_KEEP_LIST; 26 while ((codename = strtok_r (list, ",", &ptr)) != NULL) { 27 list = NULL; // pass NULL on successive strtok_r calls 28 fprintf (stderr, "PHOTCODE_LIST: %s\n", PHOTCODE_KEEP_LIST); 29 fprintf (stderr, "codename: %s\n", codename); 30 if ((photcodesKeep[NphotcodesKeep] = GetPhotcodebyName (codename)) == NULL) { 31 fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", codename); 32 exit (1); 33 } 34 NphotcodesKeep ++; 35 CHECK_REALLOCATE (photcodesKeep, PhotCode *, NPHOTCODES, NphotcodesKeep, 10); 36 } 37 } 38 39 NphotcodesSkip = 0; 40 photcodesSkip = NULL; 41 if (PHOTCODE_SKIP_LIST != NULL) { 42 NPHOTCODES = 10; 43 ALLOCATE (photcodesSkip, PhotCode *, NPHOTCODES); 44 45 /* parse the comma-separated list of photcodesSkip */ 46 list = PHOTCODE_SKIP_LIST; 47 while ((codename = strtok_r (list, ",", &ptr)) != NULL) { 48 list = NULL; // pass NULL on successive strtok_r calls 49 fprintf (stderr, "PHOTCODE_LIST: %s\n", PHOTCODE_SKIP_LIST); 50 fprintf (stderr, "codename: %s\n", codename); 51 if ((photcodesSkip[NphotcodesSkip] = GetPhotcodebyName (codename)) == NULL) { 52 fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", codename); 53 exit (1); 54 } 55 NphotcodesSkip ++; 56 CHECK_REALLOCATE (photcodesSkip, PhotCode *, NPHOTCODES, NphotcodesSkip, 10); 57 } 58 } 59 60 NphotcodesGroupA = 0; 61 photcodesGroupA = NULL; 62 if (PHOTCODE_A_LIST != NULL) { 63 NPHOTCODES = 10; 64 ALLOCATE (photcodesGroupA, PhotCode *, NPHOTCODES); 65 66 /* parse the comma-separated list of photcodesGroupA */ 67 fprintf (stderr, "PHOTCODE_A_LIST: %s\n", PHOTCODE_A_LIST); 68 list = PHOTCODE_A_LIST; 69 while ((codename = strtok_r (list, ",", &ptr)) != NULL) { 70 list = NULL; // pass NULL on successive strtok_r calls 71 fprintf (stderr, "codename: %s\n", codename); 72 if ((photcodesGroupA[NphotcodesGroupA] = GetPhotcodebyName (codename)) == NULL) { 73 fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", codename); 74 exit (1); 75 } 76 NphotcodesGroupA ++; 77 CHECK_REALLOCATE (photcodesGroupA, PhotCode *, NPHOTCODES, NphotcodesGroupA, 10); 78 } 79 } 80 81 NphotcodesGroupB = 0; 82 photcodesGroupB = NULL; 83 if (PHOTCODE_B_LIST != NULL) { 84 NPHOTCODES = 10; 85 ALLOCATE (photcodesGroupB, PhotCode *, NPHOTCODES); 86 87 fprintf (stderr, "PHOTCODE_B_LIST: %s\n", PHOTCODE_B_LIST); 88 /* parse the comma-separated list of photcodesGroupB */ 89 list = PHOTCODE_B_LIST; 90 while ((codename = strtok_r (list, ",", &ptr)) != NULL) { 91 list = NULL; // pass NULL on successive strtok_r calls 92 fprintf (stderr, "codename: %s\n", codename); 93 if ((photcodesGroupB[NphotcodesGroupB] = GetPhotcodebyName (codename)) == NULL) { 94 fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", codename); 95 exit (1); 96 } 97 NphotcodesGroupB ++; 98 CHECK_REALLOCATE (photcodesGroupB, PhotCode *, NPHOTCODES, NphotcodesGroupB, 10); 99 } 100 } 15 photcodesKeep = ParsePhotcodeList (PHOTCODE_KEEP_LIST, &NphotcodesKeep, FALSE); 16 photcodesSkip = ParsePhotcodeList (PHOTCODE_SKIP_LIST, &NphotcodesSkip, FALSE); 17 photcodesGroupA = ParsePhotcodeList (PHOTCODE_A_LIST, &NphotcodesGroupA, TRUE); 18 photcodesGroupB = ParsePhotcodeList (PHOTCODE_B_LIST, &NphotcodesGroupB, TRUE); 101 19 102 20 initstats (STATMODE); … … 123 41 } 124 42 43 void initialize_client (int argc, char **argv) { 44 45 ConfigInit (&argc, argv); 46 args_client (argc, argv); 47 48 fprintf (stderr, "PHOTCODE_KEEP_LIST: %s\n", PHOTCODE_KEEP_LIST); 49 fprintf (stderr, "PHOTCODE_SKIP_LIST: %s\n", PHOTCODE_SKIP_LIST); 50 fprintf (stderr, "PHOTCODE_A_LIST: %s\n", PHOTCODE_A_LIST); 51 fprintf (stderr, "PHOTCODE_B_LIST: %s\n", PHOTCODE_B_LIST); 52 53 photcodesKeep = ParsePhotcodeList (PHOTCODE_KEEP_LIST, &NphotcodesKeep, FALSE); 54 photcodesSkip = ParsePhotcodeList (PHOTCODE_SKIP_LIST, &NphotcodesSkip, FALSE); 55 photcodesGroupA = ParsePhotcodeList (PHOTCODE_A_LIST, &NphotcodesGroupA, TRUE); 56 photcodesGroupB = ParsePhotcodeList (PHOTCODE_B_LIST, &NphotcodesGroupB, TRUE); 57 58 initstats (STATMODE); 59 60 // IMAGE_BAD = ID_IMAGE_ASTROM_POOR | ID_IMAGE_ASTROM_FEW | ID_IMAGE_ASTROM_SKIP; 61 // STAR_BAD = ID_STAR_POOR | ID_STAR_FEW; 62 // MEAS_BAD = ID_MEAS_NOCAL | ID_MEAS_POOR_ASTROM | ID_MEAS_SKIP_ASTROM | ID_MEAS_AREA; 63 } 64 -
trunk/Ohana/src/relastro/src/load_catalogs.c
r30616 r33652 1 1 # include "relastro.h" 2 2 3 Catalog *load_catalogs (SkyList *skylist, int *Ncatalog, int subselect) { 3 Catalog *load_catalogs_parallel (SkyList *sky, int *Ncatalog); 4 void bcatalog_show_skips (); 5 6 Catalog *load_catalogs (SkyList *skylist, int *Ncatalog, int subselect, int hostID, char *hostpath) { 4 7 5 8 int i, j, k, m, Nstar; 6 9 Catalog *catalog, *pcatalog, tcatalog; 7 10 11 // XXX need to decide how to determine PARALLEL mode... 12 if (PARALLEL && !hostID) { 13 catalog = load_catalogs_parallel (skylist, Ncatalog); 14 return catalog; 15 } 16 8 17 if (VERBOSE) fprintf (stderr, "loading catalog data\n"); 9 18 10 19 ALLOCATE (catalog, Catalog, skylist[0].Nregions); 11 20 12 initStarMaps();13 14 21 // load data from each region file, only use bright stars 22 int Ncat = 0; 15 23 for (i = 0; i < skylist[0].Nregions; i++) { 24 25 // does this host ID match the desired location for the table? 26 if (!HostTableTestHost(skylist[0].regions[i], hostID)) continue; 16 27 17 28 // we only allow output if we do not use a subset. in this case, … … 19 30 pcatalog = subselect ? &tcatalog : &catalog[i]; 20 31 32 // define the catalog file name 33 char hostfile[1024]; 34 snprintf (hostfile, 1024, "%s/%s.cpt", hostpath, skylist[0].regions[i]->name); 35 pcatalog->filename = hostID ? hostfile : skylist[0].filename[i]; 36 21 37 // set up the basic catalog info 22 pcatalog [0].filename = skylist[0].filename[i];23 pcatalog [0].catformat = dvo_catalog_catformat (CATFORMAT); // set the default catformatfrom config data24 pcatalog [0].catmode = dvo_catalog_catmode (CATMODE); // set the default catmode from config data25 pcatalog [0].catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF; // don't need to load all data at this point26 pcatalog[0].Nsecfilt = GetPhotcodeNsecfilt (); 27 38 pcatalog->catformat = dvo_catalog_catformat (CATFORMAT); // set the default catformat from config data 39 pcatalog->catmode = dvo_catalog_catmode (CATMODE); // set the default catmode from config data 40 pcatalog->catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF; // don't need to load all data at this point 41 pcatalog->Nsecfilt = GetPhotcodeNsecfilt (); 42 43 // loads Average, Measure, SecFilt 28 44 if (!dvo_catalog_open (pcatalog, skylist[0].regions[i], VERBOSE2, "w")) { 29 45 fprintf (stderr, "ERROR: failure reading catalog %s\n", pcatalog[0].filename); 30 46 exit (1); 31 47 } 32 if (VERBOSE2 && !pcatalog[0].Naves_disk) fprintf (stderr, "no data in %s, skipping\n", pcatalog[0].filename); 33 34 //outlier rejection 48 if (!pcatalog[0].Naves_disk) { 49 if (VERBOSE2) fprintf (stderr, "no data in %s, skipping\n", pcatalog[0].filename); 50 dvo_catalog_unlock (pcatalog); 51 dvo_catalog_free (pcatalog); 52 continue; 53 } 54 55 if (!pcatalog->sorted) { 56 fprintf (stderr, "this database is not sorted. please sort using addstar -resort\n"); 57 exit (1); 58 } 59 60 // outlier rejection (operates on full tables (Average, Measure, Secfilt)) 35 61 if (FlagOutlier) { 36 62 FlagOutliers(&tcatalog); 37 63 } 38 64 39 updateStarMaps (&tcatalog);40 41 65 // select only the brighter stars 42 66 if (subselect) { 43 bcatalog (&catalog[i], &tcatalog); 67 // results are in Average, Secfilt, and MeasureTiny 68 // Ncat tracks the actually used catalogs 69 bcatalog (&catalog[Ncat], &tcatalog); 44 70 dvo_catalog_unlock (&tcatalog); 45 71 dvo_catalog_free (&tcatalog); 46 72 } else { 47 73 if (RESET) { 48 for (j = 0; j < catalog[ i].Naverage; j++) {49 catalog[ i].average[j].flags = 0;50 m = catalog[ i].average[j].measureOffset;51 for (k = 0; k < catalog[ i].average[j].Nmeasure; k++) {52 catalog[ i].measure[m+k].dbFlags = 0;74 for (j = 0; j < catalog[Ncat].Naverage; j++) { 75 catalog[Ncat].average[j].flags = 0; 76 m = catalog[Ncat].average[j].measureOffset; 77 for (k = 0; k < catalog[Ncat].average[j].Nmeasure; k++) { 78 catalog[Ncat].measure[m+k].dbFlags = 0; 53 79 } 54 80 } 55 81 } 56 82 } 57 } 58 59 // XXX keep this test? 83 Ncat ++; 84 } 85 86 // XXX TEST : bcatalog_show_skips(); 87 60 88 Nstar = 0; 61 for (i = 0; i < skylist[0].Nregions; i++) {89 for (i = 0; i < Ncat; i++) { 62 90 Nstar += catalog[i].Naverage; 91 if ((sizeof(IDX_T) == 8) && (catalog[i].Nmeasure > 0xffffffff)) { 92 fprintf (stderr, "ERROR: using small-sized IDX_T on data with more than 2G detections per table will cause errors\n"); 93 fprintf (stderr, " If you need to do this, and you can afford the RAM, rebuild with IDX_T set to off_t (see relastro.h, ImagesOps.c)\n"); 94 exit (3); 95 } 63 96 } 64 97 if (Nstar < 2) { … … 66 99 } 67 100 68 // XXX consider only returning the populated catalogs 69 *Ncatalog = skylist[0].Nregions; 101 // only return the populated catalogs 102 REALLOCATE (catalog, Catalog, Ncat); 103 *Ncatalog = Ncat; 70 104 return (catalog); 71 105 } … … 76 110 need to use an XCLD lock here. 77 111 */ 112 113 // CATDIR is supplied globally 114 # define DEBUG 1 115 Catalog *load_catalogs_parallel (SkyList *sky, int *Ncatalog) { 116 117 // load the list of hosts 118 HostTable *table = HostTableLoad (CATDIR, sky->hosts); 119 if (!table) { 120 fprintf (stderr, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR); 121 exit (1); 122 } 123 124 int i; 125 for (i = 0; i < table->Nhosts; i++) { 126 127 // ensure that the paths are absolute path names 128 char *tmppath = abspath (table->hosts[i].pathname, MAX_PATH_LENGTH); 129 free (table->hosts[i].pathname); 130 table->hosts[i].pathname = tmppath; 131 132 ALLOCATE (table->hosts[i].results, char, 1024); 133 snprintf (table->hosts[i].results, 1024, "%s/relastro.catalog.subset.dat", table->hosts[i].pathname); 134 135 // options / arguments that can affect relastro_client -load: 136 // VERBOSE, VERBOSE2 137 // RESET (-reset) 138 // TimeSelect -time 139 // (note that psfQual is applied rigidly at 0.85, as is the galaxy test) 140 // ImagSelect, ImagMin, ImagMax 141 // MaxDensityUse, MaxDensityValue 142 143 char command[1024]; 144 snprintf (command, 1024, "relastro_client -load-objects %s -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -statmode %s -minerror %f -D RELASTRO_SIGMA_LIM %f", 145 table->hosts[i].results, table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, STATMODE, MIN_ERROR, SIGMA_LIM); 146 147 char tmpline[1024]; 148 if (FIT_MODE == FIT_PM_ONLY) { snprintf (tmpline, 1024, "%s -pm", command); strcpy (command, tmpline); } 149 if (FIT_MODE == FIT_PAR_ONLY) { snprintf (tmpline, 1024, "%s -par", command); strcpy (command, tmpline); } 150 if (FIT_MODE == FIT_PM_AND_PAR) { snprintf (tmpline, 1024, "%s -pmpar", command); strcpy (command, tmpline); } 151 152 if (VERBOSE) { snprintf (tmpline, 1024, "%s -v", command); strcpy (command, tmpline); } 153 if (VERBOSE2) { snprintf (tmpline, 1024, "%s -vv", command); strcpy (command, tmpline); } 154 if (RESET) { snprintf (tmpline, 1024, "%s -reset", command); strcpy (command, tmpline); } 155 if (ImagSelect) { snprintf (tmpline, 1024, "%s -instmag %f %f", command, ImagMin, ImagMax); strcpy (command, tmpline); } 156 if (MaxDensityUse) { snprintf (tmpline, 1024, "%s -max-density %f", command, MaxDensityValue); strcpy (command, tmpline); } 157 158 if (FlagOutlier) { snprintf (tmpline, 1024, "%s -clip %d", command, CLIP_THRESH); strcpy (command, tmpline); } 159 160 if (PHOTCODE_KEEP_LIST) { snprintf (tmpline, 1024, "%s +photcode %s", command, PHOTCODE_KEEP_LIST); strcpy (command, tmpline); } 161 if (PHOTCODE_SKIP_LIST) { snprintf (tmpline, 1024, "%s -photcode %s", command, PHOTCODE_SKIP_LIST); strcpy (command, tmpline); } 162 if (PhotFlagSelect) { snprintf (tmpline, 1024, "%s +photflags", command); strcpy (command, tmpline); } 163 if (PhotFlagBad) { snprintf (tmpline, 1024, "%s +photflagbad %d", command, PhotFlagBad); strcpy (command, tmpline); } 164 if (PhotFlagPoor) { snprintf (tmpline, 1024, "%s +photflagpoor %d", command, PhotFlagPoor); strcpy (command, tmpline); } 165 // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values 166 167 if (TimeSelect) { 168 char *tstart = ohana_sec_to_date (TSTART); 169 char *tstop = ohana_sec_to_date (TSTOP); 170 snprintf (tmpline, 1024, "%s -time %s %s", command, tstart, tstop); 171 free (tstart); 172 free (tstop); 173 strcpy (command, tmpline); 174 } 175 176 fprintf (stderr, "command: %s\n", command); 177 178 if (PARALLEL_MANUAL) continue; 179 180 if (PARALLEL_SERIAL) { 181 int status = system (command); 182 if (status) { 183 fprintf (stderr, "ERROR running relastro_client\n"); 184 exit (2); 185 } 186 } else { 187 // launch the job on the remote machine (no handshake) 188 int errorInfo = 0; 189 int pid = rconnect ("ssh", table->hosts[i].hostname, command, table->hosts[i].stdio, &errorInfo, FALSE); 190 if (!pid) { 191 if (DEBUG) fprintf (stderr, "failure to start %s (error %d)\n", table->hosts[i].hostname, errorInfo); 192 exit (1); 193 } 194 table->hosts[i].pid = pid; // save for future reference 195 } 196 } 197 198 if (PARALLEL_MANUAL) { 199 fprintf (stderr, "run the relastro_client commands above. when these are done, hit return\n"); 200 getchar(); 201 } 202 if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) { 203 HostTableWaitJobsGetIO (table, __FILE__, __LINE__, VERBOSE); 204 } 205 206 // each host generates a BrightCatalog structure, with the measure, average, etc value 207 // loaded into a single set of arrays (of MeasureTiny, AverageTiny, Secfilt). I need to 208 // split out the per-catalog measurements into separate catalog entries. 209 210 // set up an initial array of catalogs 211 int Nsecfilt = GetPhotcodeNsecfilt (); 212 CatalogSplitter *catalogs = BrightCatalogSplitInit (Nsecfilt); 213 214 for (i = 0; i < table->Nhosts; i++) { 215 216 BrightCatalog *bcatalog = BrightCatalogLoad (table->hosts[i].results); 217 assert (bcatalog); 218 219 BrightCatalogSplit (catalogs, bcatalog); 220 221 free (bcatalog->average); 222 free (bcatalog->measure); 223 free (bcatalog->secfilt); 224 free (bcatalog); 225 } 226 227 Catalog *catalog = catalogs->catalog; 228 *Ncatalog = catalogs->Ncatalog; 229 BrightCatalogSplitFree (catalogs); 230 231 int Nmeasure = 0; 232 int Naverage = 0; 233 for (i = 0; i < catalogs->Ncatalog; i++) { 234 Nmeasure += catalogs->catalog[i].Nmeasure; 235 Naverage += catalogs->catalog[i].Naverage; 236 } 237 238 fprintf (stderr, "loaded %d catalogs, using a total of %d stars (%d measures)\n", catalogs->Ncatalog, Naverage, Nmeasure); 239 240 return (catalog); 241 } -
trunk/Ohana/src/relastro/src/load_images.c
r32346 r33652 7 7 fprintf (stderr, MSG, __VA_ARGS__); } 8 8 9 SkyList *load_images (FITS_DB *db, SkyRegion *region) {9 int load_images (FITS_DB *db, SkyList *skylist) { 10 10 11 11 Image *image, *subset; … … 14 14 struct timeval start, stop; 15 15 16 SkyTable *sky = NULL;17 SkyList *skylist = NULL;18 19 16 gettimeofday (&start, (void *) NULL); 20 21 // load the current sky table (layout of all SkyRegions)22 sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, TRUE, SKY_DEPTH, VERBOSE);23 SkyTableSetFilenames (sky, CATDIR, "cpt");24 25 // determine the populated SkyRegions overlapping the requested area26 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);32 17 33 18 // convert database table to internal structure … … 37 22 exit (2); 38 23 } 39 40 24 MARKTIME(" convert image table: %f sec\n", dtime); 41 25 … … 53 37 if (!UPDATE) dvo_image_unlock (db); 54 38 55 return (skylist);39 return TRUE; 56 40 } 57 41 … … 71 55 memcpy (vtable[0].buffer[i], &image[i], Nx); 72 56 } 73 return (TRUE);57 return TRUE; 74 58 } -
trunk/Ohana/src/relastro/src/relastro.c
r32346 r33652 3 3 int main (int argc, char **argv) { 4 4 5 int i, status, Ncatalog;6 Catalog *catalog;7 FITS_DB db;8 struct timeval start, stop;9 SkyList *skylist = NULL;10 11 gettimeofday (&start, (void *) NULL);12 13 5 /* get configuration info, args */ 14 6 initialize (argc, argv); 15 7 16 /* the object analysis is a separate process iterating over catalogs */ 17 if (FIT_TARGET == TARGET_OBJECTS) { 18 relastro_objects (); 19 exit (0); 20 } 8 SkyTable *sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, TRUE, SKY_DEPTH, VERBOSE); 9 SkyTableSetFilenames (sky, CATDIR, "cpt"); 10 SkyList *skylist = SkyListByPatch (sky, -1, &UserPatch); 21 11 22 /* the object analysis is a separate process iterating over catalogs */23 if (FIT_TARGET == TARGET_HIGH_SPEED) {24 high_speed_catalogs ();25 exit (0);26 }12 switch (FIT_TARGET) { 13 case TARGET_UPDATE_OBJECTS: 14 /* the object analysis is a separate process iterating over catalogs */ 15 relastro_objects (skylist, 0, NULL); 16 exit (0); 27 17 28 /* the object analysis is a separate process iterating over catalogs */ 29 if (FIT_TARGET == TARGET_MERGE_SOURCE) { 30 relastro_merge_source (); 31 exit (0); 32 } 18 case TARGET_HIGH_SPEED: 19 /* high-speed is a 2pt cross-correlation process for linking moving objects (high PM) */ 20 high_speed_catalogs (sky, skylist, 0, NULL); 21 exit (0); 33 22 34 /* register database handle with shutdown procedure */ 35 set_db (&db); 23 case TARGET_MERGE_SOURCE: 24 /* a special method to manually merge unlinked detections of sources togther (not parallel) */ 25 relastro_merge_source (sky); 26 exit (0); 36 27 37 /* lock and load the image db table */ 38 status = dvo_image_lock (&db, ImageCat, 60.0, (UPDATE ? LCK_XCLD : LCK_SOFT)); 39 if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename); 40 if (db.dbstate == LCK_EMPTY) Shutdown ("ERROR: No images in catalog %s (1)", db.filename); 41 if (!dvo_image_load (&db, VERBOSE, FALSE)) Shutdown ("can't read image catalog %s", db.filename); 42 MARKTIME("load image data: %f sec\n", dtime); 28 case TARGET_SIMPLE: 29 case TARGET_CHIPS: 30 case TARGET_MOSAICS: 31 relastro_images (skylist); 32 exit (0); 43 33 44 /* load regions and images based on specified sky patch (default depth) */ 45 skylist = load_images (&db, &UserPatch); 46 MARKTIME("load images: %f sec\n", dtime); 47 48 initCoords(); 49 50 /* load catalog data from region files : subselect high-quality measurements */ 51 // XXX pass in the image table 52 // XXX who carries the image grid? 53 catalog = load_catalogs (skylist, &Ncatalog, TRUE); 54 MARKTIME("load catalog data: %f sec\n", dtime); 55 56 /* match measurements with images */ 57 initImageBins (catalog, Ncatalog, TRUE); 58 MARKTIME("make image bins: %f sec\n", dtime); 59 60 findImages (catalog, Ncatalog, TRUE); 61 MARKTIME("set up image indexes: %f sec\n", dtime); 62 63 if (PLOTSTUFF) { 64 // plot_star_coords (catalog, Ncatalog); 65 // plot_mosaic_fields (catalog); 66 } 67 68 // set test points based on the starmap 69 createStarMapPoints(); 70 71 /* major modes */ 72 switch (FIT_TARGET) { 73 case TARGET_SIMPLE: 74 for (i = 0; i < NLOOP; i++) { 75 UpdateObjects (catalog, Ncatalog); 76 UpdateSimple (catalog, Ncatalog); 77 } 78 break; 79 80 case TARGET_CHIPS: 81 for (i = 0; i < NLOOP; i++) { 82 UpdateObjects (catalog, Ncatalog); 83 UpdateChips (catalog, Ncatalog); 84 MARKTIME("update chips: %f sec\n", dtime); 85 } 86 // create summary plots of the process 87 // relastroVisualSummaryChips(); 88 break; 89 90 case TARGET_MOSAICS: 91 for (i = 0; i < NLOOP; i++) { 92 UpdateObjects (catalog, Ncatalog); 93 UpdateMosaic (catalog, Ncatalog); 94 } 95 break; 34 case TARGET_UPDATE_OFFSETS: 35 // iterate over catalogs to make detection coordinates consistant 36 UpdateObjectOffsets (skylist, 0, NULL); 96 37 97 38 default: 98 fprintf (stderr, " programming error at %s:%d", __FILE__, __LINE__);99 exit (2);39 fprintf (stderr, "impossible!\n"); 40 abort(); 100 41 } 101 102 if (!UPDATE) exit (0); 103 104 // free the image / measurement pointers 105 freeImageBins (1); 106 107 reload_images (&db); 108 109 // iterate over catalogs to make detection coordinates consistant 110 UpdateObjectOffsets (skylist); 111 112 // iterate over catalogs to make detection coordinates consistant 113 // FixProblemImages (skylist); 114 115 // save the updated image parameters 116 dvo_image_update (&db, VERBOSE); 117 dvo_image_unlock (&db); 118 119 exit (0); 42 exit (1); 120 43 } -
trunk/Ohana/src/relastro/src/relastro_merge_source.c
r32346 r33652 1 1 # include "relastro.h" 2 2 3 int relastro_merge_source ( ) {3 int relastro_merge_source (SkyTable *sky) { 4 4 5 5 int i, m; 6 SkyTable *sky = NULL;7 6 Catalog catalog_src, catalog_dst; 8 7 … … 13 12 dvo_set_catdir(CATDIR); 14 13 15 // load the current sky table (layout of all SkyRegions)16 sky = SkyTableLoadOptimal (CATDIR, NULL, NULL, FALSE, SKY_DEPTH, VERBOSE);17 SkyTableSetFilenames (sky, CATDIR, "cpt");18 19 14 // we are merging the detections of the src into the dst : OBJ_ID_SRC,CAT_ID_SRC -> OBJ_ID_DST,CAT_ID_DST 20 15 … … 52 47 catalog_src.Nsecfilt = GetPhotcodeNsecfilt (); 53 48 54 if (!dvo_catalog_open (&catalog_src, region_src, VERBOSE , "w")) {49 if (!dvo_catalog_open (&catalog_src, region_src, VERBOSE2, "w")) { 55 50 fprintf (stderr, "ERROR: failure reading catalog %s\n", catalog_src.filename); 56 51 exit (1); … … 127 122 resort_catalog (&catalog_src); 128 123 129 dvo_catalog_save (&catalog_src, VERBOSE );124 dvo_catalog_save (&catalog_src, VERBOSE2); 130 125 dvo_catalog_unlock (&catalog_src); 131 126 dvo_catalog_free (&catalog_src); -
trunk/Ohana/src/relastro/src/relastro_objects.c
r27581 r33652 1 1 # include "relastro.h" 2 2 3 int relastro_objects () { 3 int relastro_objects_parallel (SkyList *sky); 4 5 int relastro_objects (SkyList *skylist, int hostID, char *hostpath) { 4 6 5 7 int i, j, k, m; 6 8 7 SkyTable *sky = NULL;8 SkyList *skylist = NULL;9 9 Catalog catalog; 10 10 11 DVOMeasureFlags measureBits = 12 ID_MEAS_POOR_ASTROM | 13 ID_MEAS_SKIP_ASTROM | 14 ID_MEAS_USED_OBJ | 15 ID_MEAS_USED_CHIP; 11 16 12 // load the current sky table (layout of all SkyRegions) 13 sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, TRUE, SKY_DEPTH, VERBOSE); 14 SkyTableSetFilenames (sky, CATDIR, "cpt"); 15 16 // determine the populated SkyRegions overlapping the requested area (default depth) 17 if (UserCatalog) { 18 skylist = SkyRegionByPoint (sky, -1, UserCatalogRA, UserCatalogDEC); 19 } else { 20 skylist = SkyListByPatch (sky, -1, &UserPatch); 17 DVOAverageFlags averageBits = 18 ID_STAR_FEW | 19 ID_STAR_POOR | 20 ID_STAR_FIT_AVE | 21 ID_STAR_FIT_PM | 22 ID_STAR_FIT_PAR | 23 ID_STAR_USE_AVE | 24 ID_STAR_USE_PM | 25 ID_STAR_USE_PAR; 26 27 // XXX need to decide how to determine PARALLEL mode... 28 if (PARALLEL && !hostID) { 29 relastro_objects_parallel (skylist); 30 return TRUE; 21 31 } 22 32 … … 24 34 for (i = 0; i < skylist[0].Nregions; i++) { 25 35 36 // does this host ID match the desired location for the table? 37 if (!HostTableTestHost(skylist[0].regions[i], hostID)) continue; 38 26 39 // set up the basic catalog info 27 catalog.filename = skylist[0].filename[i]; 40 char hostfile[1024]; 41 snprintf (hostfile, 1024, "%s/%s.cpt", hostpath, skylist[0].regions[i]->name); 42 catalog.filename = hostID ? hostfile : skylist[0].filename[i]; 28 43 catalog.catformat = dvo_catalog_catformat (CATFORMAT); // set the default catformat from config data 29 44 catalog.catmode = dvo_catalog_catmode (CATMODE); // set the default catmode from config data … … 31 46 catalog.Nsecfilt = GetPhotcodeNsecfilt (); 32 47 33 if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "w")) { 48 // loads Average, Measure, SecFilt 49 if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE2, "w")) { 34 50 fprintf (stderr, "ERROR: failure reading catalog %s\n", catalog.filename); 35 51 exit (1); 36 52 } 37 53 if (!catalog.Naves_disk) { 38 if (VERBOSE ) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);54 if (VERBOSE2) fprintf (stderr, "no data in %s, skipping\n", catalog.filename); 39 55 dvo_catalog_unlock (&catalog); 40 56 dvo_catalog_free (&catalog); … … 42 58 } 43 59 60 // operates on full tables (Average, Measure, Secfilt) 44 61 if (FlagOutlier) { 45 62 FlagOutliers(&catalog); 46 63 } 47 64 48 // XXX consider what gets reset (only ASTROM flags)65 // reset only the astrometry-related average and measure bits 49 66 if (RESET) { 50 67 for (j = 0; j < catalog.Naverage; j++) { 51 catalog.average[j].flags = 0;68 catalog.average[j].flags &= ~averageBits; 52 69 m = catalog.average[j].measureOffset; 53 70 for (k = 0; k < catalog.average[j].Nmeasure; k++) { 54 catalog.measure[m+k].dbFlags = 0;71 catalog.measure[m+k].dbFlags &= ~measureBits; 55 72 } 56 73 } 57 74 } 58 75 76 populate_tiny_values(&catalog, DVO_TV_MEASURE); 77 59 78 UpdateObjects (&catalog, 1); 79 80 free_tiny_values(&catalog); 60 81 61 82 if (!UPDATE) { … … 70 91 return (TRUE); 71 92 } 93 94 // CATDIR is supplied globally 95 # define DEBUG 1 96 int relastro_objects_parallel (SkyList *sky) { 97 98 // launch the setphot_client jobs to the parallel hosts 99 100 // load the list of hosts 101 HostTable *table = HostTableLoad (CATDIR, sky->hosts); 102 if (!table) { 103 fprintf (stderr, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR); 104 exit (1); 105 } 106 107 int i; 108 for (i = 0; i < table->Nhosts; i++) { 109 110 // ensure that the paths are absolute path names 111 char *tmppath = abspath (table->hosts[i].pathname, MAX_PATH_LENGTH); 112 free (table->hosts[i].pathname); 113 table->hosts[i].pathname = tmppath; 114 115 // options / arguments that can affect relastro_client -update-objects: 116 // VERBOSE, VERBOSE2 117 // RESET (-reset) 118 // TimeSelect -time 119 // (note that psfQual is applied rigidly at 0.85, as is the galaxy test) 120 // ImagSelect, ImagMin, ImagMax 121 // MaxDensityUse, MaxDensityValue 122 123 // FIT_MODE 124 // PM_TOOFEW 125 // SRC_MEAS_TOOFEW 126 // FIT_TARGET 127 128 char command[1024]; 129 snprintf (command, 1024, "relastro_client -update-objects -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f", 130 table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax); 131 132 char tmpline[1024]; 133 if (FIT_MODE == FIT_PM_ONLY) { snprintf (tmpline, 1024, "%s -pm", command); strcpy (command, tmpline); } 134 if (FIT_MODE == FIT_PAR_ONLY) { snprintf (tmpline, 1024, "%s -par", command); strcpy (command, tmpline); } 135 if (FIT_MODE == FIT_PM_AND_PAR) { snprintf (tmpline, 1024, "%s -pmpar", command); strcpy (command, tmpline); } 136 137 if (VERBOSE) { snprintf (tmpline, 1024, "%s -v", command); strcpy (command, tmpline); } 138 if (VERBOSE2) { snprintf (tmpline, 1024, "%s -vv", command); strcpy (command, tmpline); } 139 if (RESET) { snprintf (tmpline, 1024, "%s -reset", command); strcpy (command, tmpline); } 140 if (UPDATE) { snprintf (tmpline, 1024, "%s -update", command); strcpy (command, tmpline); } 141 142 if (ImagSelect) { snprintf (tmpline, 1024, "%s -instmag %f %f", command, ImagMin, ImagMax); strcpy (command, tmpline); } 143 if (MaxDensityUse) { snprintf (tmpline, 1024, "%s -max-density %f", command, MaxDensityValue); strcpy (command, tmpline); } 144 145 if (FlagOutlier) { snprintf (tmpline, 1024, "%s -clip %d", command, CLIP_THRESH); strcpy (command, tmpline); } 146 147 if (PHOTCODE_KEEP_LIST) { snprintf (tmpline, 1024, "%s +photcode %s", command, PHOTCODE_KEEP_LIST); strcpy (command, tmpline); } 148 if (PHOTCODE_SKIP_LIST) { snprintf (tmpline, 1024, "%s -photcode %s", command, PHOTCODE_SKIP_LIST); strcpy (command, tmpline); } 149 if (PhotFlagSelect) { snprintf (tmpline, 1024, "%s +photflags", command); strcpy (command, tmpline); } 150 if (PhotFlagBad) { snprintf (tmpline, 1024, "%s +photflagbad %d", command, PhotFlagBad); strcpy (command, tmpline); } 151 if (PhotFlagPoor) { snprintf (tmpline, 1024, "%s +photflagpoor %d", command, PhotFlagPoor); strcpy (command, tmpline); } 152 // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values 153 154 if (TimeSelect) { 155 char *tstart = ohana_sec_to_date (TSTART); 156 char *tstop = ohana_sec_to_date (TSTOP); 157 snprintf (tmpline, 1024, "%s -time %s %s", command, tstart, tstop); 158 free (tstart); 159 free (tstop); 160 strcpy (command, tmpline); 161 } 162 163 fprintf (stderr, "command: %s\n", command); 164 165 if (PARALLEL_MANUAL) continue; 166 167 if (PARALLEL_SERIAL) { 168 int status = system (command); 169 if (status) { 170 fprintf (stderr, "ERROR running relastro_client\n"); 171 exit (2); 172 } 173 } else { 174 // launch the job on the remote machine (no handshake) 175 int errorInfo = 0; 176 int pid = rconnect ("ssh", table->hosts[i].hostname, command, table->hosts[i].stdio, &errorInfo, FALSE); 177 if (!pid) { 178 if (DEBUG) fprintf (stderr, "failure to start %s (error %d)\n", table->hosts[i].hostname, errorInfo); 179 exit (1); 180 } 181 table->hosts[i].pid = pid; // save for future reference 182 } 183 } 184 185 if (PARALLEL_MANUAL) { 186 fprintf (stderr, "run the relastro_client commands above. when these are done, hit return\n"); 187 getchar(); 188 } 189 if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) { 190 HostTableWaitJobsGetIO (table, __FILE__, __LINE__, VERBOSE); 191 } 192 193 return TRUE; 194 } -
trunk/Ohana/src/relastro/src/resort_catalog.c
r32346 r33652 1 1 # include "relastro.h" 2 3 # define myAbort(MSG) { fprintf (stderr, "%s\n", MSG); abort(); }4 # define myAssert(LOGIC,MSG) { if (!(LOGIC)) { fprintf (stderr, "%s\n", MSG); abort(); } }5 2 6 3 // sort the measure Sequence based on the average Sequence entries -
trunk/Ohana/src/relastro/src/save_catalogs.c
r12731 r33652 8 8 for (i = 0; i < Ncatalog; i++) { 9 9 10 if (VERBOSE ) fprintf (stderr, "saving catalog %s\n", catalog[i].filename);11 dvo_catalog_save (&catalog[i], VERBOSE );10 if (VERBOSE2) fprintf (stderr, "saving catalog %s\n", catalog[i].filename); 11 dvo_catalog_save (&catalog[i], VERBOSE2); 12 12 dvo_catalog_unlock (&catalog[i]); 13 13 dvo_catalog_free (&catalog[i]); -
trunk/Ohana/src/relastro/src/select_images.c
r31160 r33652 25 25 26 26 Image *image; 27 off_t i, j, k, m, nStart, iSky, nimage, NIMAGE ;27 off_t i, j, k, m, nStart, iSky, nimage, NIMAGE, D_NIMAGE; 28 28 off_t *line_number; 29 29 int InRange, found; … … 68 68 DminSkyRegion = +90.0; 69 69 DmaxSkyRegion = -90.0; 70 71 D_NIMAGE = 6000; 70 72 71 73 /* compare with each region file */ … … 113 115 114 116 nimage = 0; 115 NIMAGE = 100;117 NIMAGE = D_NIMAGE; 116 118 ALLOCATE (image, Image, NIMAGE); 117 119 ALLOCATE (line_number, off_t, NIMAGE); … … 167 169 168 170 /* transform corners to ra,dec -- costs ~3sec for 3M images (pikake) */ 169 double RminImage = 360.0;170 double RmaxImage = 0.0;171 double RminImage = RmidSkyRegion + 180.0; 172 double RmaxImage = RmidSkyRegion - 180.0; 171 173 double DminImage = +90.0; 172 174 double DmaxImage = -90.0; … … 194 196 if (RmaxImage < RminSkyRegion) continue; 195 197 198 if (!strncmp(timage[i].name, "o5903g0638o", 10) && (timage[i].photcode == 10355)) { 199 fprintf (stderr, "test image\n"); 200 } 201 202 // require that the full image be inside the region of interest (only for non PHU 203 // images) XXX : if we calibrate the mosaic, require that the full mosaic be inside 204 // the region and all of its chips.. 205 # define FULL_OVERLAP 1 206 if (FULL_OVERLAP && strcmp(&timage[i].coords.ctype[4], "-DIS")) { 207 if (RmaxImage > UserPatch.Rmax) continue; 208 if (RminImage < UserPatch.Rmin) continue; 209 if (DmaxImage > UserPatch.Dmax) continue; 210 if (DminImage < UserPatch.Dmin) continue; 211 } 212 196 213 // image overlaps region, keep it 197 214 if (USE_BASIC_CHECK) goto found_it; … … 243 260 } 244 261 if (RESET) { 245 // XXX do we need / want to do this in relastro? 246 // assignMcal (&image[nimage], (double *) NULL, -1); 247 // image[nimage].Mcal = NAN; 248 // image[nimage].dMcal = NAN; 262 // this only resets the astrometry image flags, not the photometry ones 249 263 image[nimage].flags &= ~badImage; 250 264 } … … 252 266 nimage ++; 253 267 if (nimage == NIMAGE) { 254 NIMAGE += 100; 268 NIMAGE += D_NIMAGE; 269 D_NIMAGE = MAX (100000, D_NIMAGE * 1.5); 255 270 REALLOCATE (image, Image, NIMAGE); 256 271 REALLOCATE (line_number, off_t, NIMAGE); … … 264 279 REALLOCATE (line_number, off_t, MAX (nimage, 1)); 265 280 free (skycoords); 281 free (RmaxSky); 282 free (index); 266 283 267 284 *Nimage = nimage; -
trunk/Ohana/src/relastro/src/testparallax.c
r32741 r33652 1 1 # include "relastro.h" 2 # define NPTS 64 3 # define J2000 2451545. /* Julian date at standard epoch */ 4 # define T1970 2440587.500000 /* JD at UNIX ref time */ 2 5 3 6 int main (int argc, char **argv) { 7 8 int i, Npts; 9 char line[1024]; 10 double R[NPTS], D[NPTS], Time[NPTS], JD[NPTS]; 11 double X[NPTS], Y[NPTS], dX[NPTS], dY[NPTS], pX[NPTS], pY[NPTS]; 12 double Tref[NPTS], Tjyrs[NPTS], TrefS, TjyrsS, TrefMean, TjyrsMean, Ro, Do; 13 Coords coords; 14 PMFit fitPAR; 4 15 5 if (argc != N) { 6 fprintf (stderr, "USAGE: testparallax (file.dat)\n"); 7 exit (1); 16 if (argc != 2) { 17 fprintf (stderr, "USAGE: testparallax (file.dat)\n"); 18 exit (1); 19 } 20 21 // test parallax program 22 FILE *f = fopen (argv[1], "r"); 23 if (!f) { fprintf (stderr, "failed to open %s\n", argv[1]); exit (2); } 24 25 // XXX uncomment to skip first line scan_line(f, line); 26 27 Npts = 0; 28 for (i = 0; scan_line(f, line) != EOF; i++) { 29 if (Npts == NPTS) { 30 fprintf (stderr, "too many point: use dynamic alloc\n"); 31 exit (2); 8 32 } 33 if (line[0] == '#') continue; 34 dparse (&R[Npts], 1, line); 35 dparse (&D[Npts], 2, line); 36 dparse (&JD[Npts], 3, line); 37 dparse (&Time[Npts], 3, line); 9 38 10 // test parallax program 11 FILE *f = fopen (argv[1], "r"); 12 if (!f) { fprintf (stderr, "failed to open %s\n", argv[1]); exit (2); } 39 dparse (&dX[Npts], 4, line); 40 dparse (&dY[Npts], 4, line); 13 41 14 char buffer[1024]; 15 scan_line(f, line); 16 17 while (scan_line(f, line) != EOF) { 18 dparse (&jd, 1, line); 19 dparse (&time, 2, line); 20 dparse (&ra, 3, line); 21 dparse (&dec, 4, line); 42 // trent's file 43 // dparse (&JD[Npts], 1, line); 44 // dparse (&Time[Npts], 2, line); 45 // dparse (&R[Npts], 3, line); 46 // dparse (&D[Npts], 4, line); 47 Npts ++; 48 } 22 49 23 } 50 /* project coordinates to a plane centered on the object with units of arcsec */ 51 coords.crval1 = 0; 52 coords.crval2 = 0; 53 coords.crpix1 = 0; 54 coords.crpix2 = 0; 55 coords.cdelt1 = coords.cdelt2 = 1.0 / 3600.0; 56 coords.pc1_1 = coords.pc2_2 = 1.0; 57 coords.pc1_2 = coords.pc2_1 = 0.0; 58 coords.Npolyterms = 1; 59 strcpy (coords.ctype, "RA---SIN"); 24 60 25 // project to local coords 61 // use one point as a local reference 62 coords.crval1 = R[0]; 63 coords.crval2 = D[0]; 26 64 27 // run fitter 28 FitPMandPar 65 TrefS = TjyrsS = 0.0; 29 66 67 // project to local coords 68 for (i = 0; i < Npts; i++) { 69 RD_to_XY (&X[i], &Y[i], R[i], D[i], &coords); 30 70 71 Tjyrs[i] = Time[i] / 365.25; 72 Tref[i] = Time[i] / 365.25; 73 // Tunix[i] = (JD[i] - T1970) / 365.25; // time relative to T1970 in years 74 // Tjyrs[i] = (JD[i] - J2000) / 365.25; // time relative to J2000 in years 75 76 TrefS += Tref[i]; 77 TjyrsS += Tjyrs[i]; 78 79 // nominal for PS1 80 // dX[i] = 0.020; 81 // dY[i] = 0.020; 82 } 83 TrefMean = TrefS / Npts; 84 TjyrsMean = TjyrsS / Npts; 85 86 for (i = 0; i < Npts; i++) { 87 Tref[i] -= TrefMean; 88 ParFactor (&pX[i], &pY[i], R[i], D[i], Tjyrs[i], 0.0); 89 fprintf (stderr, "%f %f : %f %f : %f %f : %f %f\n", R[i], D[i], X[i], Y[i], Tref[i], Tjyrs[i], pX[i], pY[i]); 90 } 91 92 // run fitter 93 // FitPMandPar (&fitPAR, X, dX, Y, dY, Tref, pX, pY, Npts, TRUE); 94 FitPMandPar (&fitPAR, X, dX, Y, dY, Tjyrs, pX, pY, Npts, TRUE); 95 XY_to_RD (&Ro, &Do, fitPAR.Ro, fitPAR.Do, &coords); 96 97 fprintf (stderr, "Rx : %f\n", fitPAR.Ro); 98 fprintf (stderr, "Dx : %f\n", fitPAR.Do); 99 fprintf (stderr, "Ro : %f\n", Ro); 100 fprintf (stderr, "Do : %f\n", Do); 101 fprintf (stderr, "dRo : %f\n", fitPAR.dRo); 102 fprintf (stderr, "dDo : %f\n", fitPAR.dDo); 103 fprintf (stderr, "uR : %f\n", fitPAR.uR); 104 fprintf (stderr, "uD : %f\n", fitPAR.uD); 105 fprintf (stderr, "duR : %f\n", fitPAR.duR); 106 fprintf (stderr, "duD : %f\n", fitPAR.duD); 107 fprintf (stderr, "p : %f\n", fitPAR.p); 108 fprintf (stderr, "dp : %f\n", fitPAR.dp); 109 fprintf (stderr, "uTot : %f\n", hypot(fitPAR.uR,fitPAR.uD)); 110 fprintf (stderr, "PA : %f\n", DEG_RAD*atan2(fitPAR.uR,fitPAR.uD) + 360.0); 111 112 exit (0); 31 113 } 114
Note:
See TracChangeset
for help on using the changeset viewer.
