IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33652


Ignore:
Timestamp:
Apr 1, 2012, 3:00:19 PM (14 years ago)
Author:
eugene
Message:

updates to relastro to support distributed dvo; some optmimization (eg, image matching to area); cleanup names of static helper arrays in ImageOps, MosaicOps; cleanup rules for -reset options (relastro does not reset photom bits); skip objects with NAN error bars (can be used to exclude some photcodes from astrometry); enum for mask bits in FitChip and related; choose max order using same rules as psastro; plug leaks; reduce verbosity; big re-org of main (for parallel code); only use accepted measurements for Tmin,Tmax,Trange,Tmean; require a min parallax factor to fit parallaxes; use MeasureTiny where possible; use new ParsePhotcodeList function; testparallax function; threaded version of UpdateChips; bcatalog limit density selecting objects by number of measurements; high-speed now copies support tables to output database; high-speed may write to a parallel database; test for unsorted database (& fail if true)

Location:
trunk/Ohana/src/relastro
Files:
30 edited
5 copied

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/relastro/Makefile

    r32346 r33652  
    1 default: relastro
     1default: relastro relastro_client
    22help:
    33        @echo "make options: relastro (default)"
     
    1818
    1919relastro: $(BIN)/relastro.$(ARCH)
    20 install: $(DESTBIN)/relastro
     20relastro_client: $(BIN)/relastro_client.$(ARCH)
     21
     22install: $(DESTBIN)/relastro $(DESTBIN)/relastro_client $(DESTBIN)/testparallax
    2123
    2224RELASTRO = \
     
    5355$(SRC)/select_images.$(ARCH).o       \
    5456$(SRC)/relastro.$(ARCH).o            \
     57$(SRC)/relastro_images.$(ARCH).o    \
    5558$(SRC)/relastro_objects.$(ARCH).o    \
    5659$(SRC)/save_catalogs.$(ARCH).o       \
    57 $(SRC)/write_coords.$(ARCH).o        \
    5860$(SRC)/CoordOps.$(ARCH).o            \
    5961$(SRC)/FixProblemImages.$(ARCH).o    \
     
    6466$(SRC)/relastro_merge_source.$(ARCH).o  \
    6567$(SRC)/resort_catalog.$(ARCH).o  \
     68$(SRC)/BrightCatalog.$(ARCH).o  \
    6669$(SRC)/relastroVisual.$(ARCH).o
    6770
    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
     76RELASTRO_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
     127testparallax: $(BIN)/testparallax.$(ARCH)
     128
     129TESTPAR = \
     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  
    44# include <signal.h>
    55# 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
    611
    712typedef enum {
     
    1520typedef enum {FIT_NONE, FIT_AVERAGE, FIT_PM_ONLY, FIT_PAR_ONLY, FIT_PM_AND_PAR} FitMode;
    1621
    17 typedef enum {TARGET_NONE, TARGET_OBJECTS, TARGET_SIMPLE, TARGET_CHIPS, TARGET_MOSAICS, TARGET_HIGH_SPEED, TARGET_MERGE_SOURCE} FitTarget;
     22typedef 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
     24typedef 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
     33typedef 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
     41typedef 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;
    1852
    1953typedef struct {
     
    86120
    87121/* global variables set in parameter file */
    88 char   ImageCat[256];
    89 char   GSCFILE[256];
    90 char   CATDIR[256];
     122# define MAX_PATH_LENGTH 1024
     123char   ImageCat[MAX_PATH_LENGTH];
     124char   GSCFILE[MAX_PATH_LENGTH];
     125char   CATDIR[MAX_PATH_LENGTH];
    91126char   *HIGH_SPEED_DIR;
    92127char   CATMODE[16];    /* raw, mef, split, mysql */
    93128char   CATFORMAT[16];  /* internal, elixir, loneos, panstarrs */
    94 char   SKY_TABLE[256];
     129char   SKY_TABLE[MAX_PATH_LENGTH];
    95130int    SKY_DEPTH;  /** XXX EAM : depth of catalog tables, fix usage */
     131
     132int          HOST_ID;
     133char        *HOSTDIR;
     134char        *BCATALOG;
    96135
    97136unsigned int OBJ_ID_SRC;
     
    110149double RADIUS; // match radius for high-speed objects
    111150
     151int    PARALLEL;
     152int    PARALLEL_MANUAL;
     153int    PARALLEL_SERIAL;
     154
     155int    PARALLEL_OUTPUT;
     156
    112157int    VERBOSE;
    113158int    VERBOSE2;
     
    115160int    RESET;
    116161int    NLOOP;
     162int    NTHREADS;
    117163int    UPDATE;
    118164int    PLOTSTUFF;
     
    123169int    PM_TOOFEW;
    124170double PM_DT_MIN;
     171double PAR_FACTOR_MIN;
    125172int    PLOTDELAY;
    126173int    CHIPORDER;
     
    128175int MaxDensityUse;
    129176double MaxDensityValue;
    130 
    131 int UserCatalog;
    132 double UserCatalogRA, UserCatalogDEC;
    133177
    134178char          *PHOTCODE_KEEP_LIST, *PHOTCODE_SKIP_LIST;
     
    142186SkyRegionSelection SELECTION;
    143187
    144 int AreaSelect;
    145 double AreaXmin, AreaXmax, AreaYmin, AreaYmax;
    146 
    147 int ImagSelect, ImagMin, ImagMax;
     188int ImagSelect;
     189double ImagMin, ImagMax;
    148190
    149191double  PlotMmin, PlotMmax, PlotdMmin, PlotdMmax;
    150192
    151 int DophotSelect, DophotValue;
    152193int PhotFlagSelect, PhotFlagPoor, PhotFlagBad;
    153194
     
    181222char         *GetPhotnamebyCode   PROTO((PhotCodeData *photcodes, int code));
    182223void          InterpolateGrid     PROTO((float *buffer, int Nx, int Ny, Coords *ccd, Coords *gcoords));
    183 off_t          *SelectRefMosaic     PROTO((Mosaic **refmosaic, off_t *Nimage));
     224off_t        *SelectRefMosaic     PROTO((Mosaic **refmosaic, off_t *Nimage));
    184225int           args                PROTO((int argc, char **argv));
     226int           args_client         PROTO((int argc, char **argv));
    185227int           bcatalog            PROTO((Catalog *subcatalog, Catalog *catalog));
    186228void          clean_images        PROTO((void));
     
    226268void          initMrel            PROTO((Catalog *catalog, int Ncatalog));
    227269void          initialize          PROTO((int argc, char **argv));
     270void          initialize_client   PROTO((int argc, char **argv));
    228271void          initstats           PROTO((char *mode));
    229272int           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));
     273Catalog      *load_catalogs       PROTO((SkyList *skylist, int *Ncatalog, int subselect, int hostID, char *hostpath));
     274int           load_images         PROTO((FITS_DB *db, SkyList *skylist));
    232275Image        *select_images       PROTO((SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage));
    233276
     
    314357void FlagOutliers(Catalog *catalog);
    315358int MeasFilterTest(Measure *measure, int applySigmaLim);
     359int MeasFilterTestTiny(MeasureTiny *measure, int applySigmaLim);
    316360
    317361int sun_ecliptic (double jd, double *lambda, double *beta, double *epsilon, double *Radius);
     
    333377Mosaic *getMosaicForImage (off_t im);
    334378
    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);
     379double getMeanR (MeasureTiny *measure, Average *average, SecFilt *secfilt);
     380double getMeanD (MeasureTiny *measure, Average *average, SecFilt *secfilt);
     381int setMeanR (double ra_fit, MeasureTiny *measure, Average *average, SecFilt *secfilt);
     382int setMeanD (double dec_fit, MeasureTiny *measure, Average *average, SecFilt *secfilt);
     383int setMeanR_Big (double ra_fit, Measure *measure, Average *average, SecFilt *secfilt);
     384int setMeanD_Big (double dec_fit, Measure *measure, Average *average, SecFilt *secfilt);
    339385
    340386float GetAstromError (Measure *measure, int mode);
    341 int relastro_objects (void);
    342 int UpdateObjectOffsets (SkyList *skylist);
     387float GetAstromErrorTiny (MeasureTiny *measure, int mode);
     388int relastro_objects (SkyList *skylist, int hostID, char *hostpath);
     389int relastro_images (SkyList *skylist);
     390int UpdateObjectOffsets (SkyList *skylist, int hostID, char *hostpath);
    343391
    344392int relastroVisualPlotChipFit(StarData *raw, StarData *ref, double dRmax, int numObj);
     
    361409void resetImageRaw (Catalog *catalog, int Ncatalog, off_t im);
    362410
    363 int high_speed_catalogs ();
     411int high_speed_catalogs (SkyTable *sky, SkyList *skylist, int hostID, char *hostpath);
    364412int high_speed_objects (SkyRegion *region, Catalog *catalog);
    365413int MeasMatchesPhotcode(Measure *measure, PhotCode **photcodeSet, int Nset);
     
    369417int createStarMapPoints();
    370418int checkStarMap(int N);
     419int createStarMap (Catalog *catalog, int Ncatalog);
    371420
    372421int GetScatterRawRef(float *dLsig, float *dMsig, float *dRsig, int *nKeep, StarData *raw, StarData *ref, int Nstars, float SigmaLimit);
    373 int LimitDensityCatalog (Catalog *subcatalog, Catalog *catalog);
     422int LimitDensityCatalog_ByNmeasure (Catalog *subcatalog, Catalog *catalog);
     423int LimitDensityCatalog_RandomSample (Catalog *subcatalog, Catalog *catalog);
    374424
    375425int initializeConstraints();
     
    378428void setupAreaSelection(SkyRegion *region);
    379429
    380 int relastro_merge_source ();
     430int relastro_merge_source (SkyTable *sky);
    381431void resort_catalog (Catalog *catalog);
     432
     433BrightCatalog *BrightCatalogLoad(char *filename);
     434int BrightCatalogSave(char *filename, BrightCatalog *catalog);
     435BrightCatalog *BrightCatalogMerge (Catalog *catalog, int Ncatalog);
     436CatalogSplitter *BrightCatalogSplitInit (int Nsecfilt);
     437int BrightCatalogSplit (CatalogSplitter *catalogs, BrightCatalog *bcatalog);
     438int BrightCatalogSplitFree (CatalogSplitter *catalogs);
     439
     440PhotCode **ParsePhotcodeList (char *rawlist, int *nphotcodes, int needAve);
  • trunk/Ohana/src/relastro/src/ConfigInit.c

    r31635 r33652  
    2626  if (!ScanConfig (config, "RELASTRO_IMFIT_SYS_SIGMA_LIM", "%lf", 0, &IMFIT_SYS_SIGMA_LIM)) IMFIT_SYS_SIGMA_LIM = 0.01;
    2727
    28   // XXX these are used in relphot to identify poor stars / images -- define
    29   // 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 
    3528  GetConfig (config, "PM_DT_MIN",              "%lf", 0, &PM_DT_MIN);
    3629  GetConfig (config, "PM_TOOFEW",              "%d",  0, &PM_TOOFEW);
    3730  GetConfig (config, "POS_TOOFEW",             "%d",  0, &POS_TOOFEW);
     31
     32  GetConfig (config, "PAR_FACTOR_MIN",         "%lf", 0, &PAR_FACTOR_MIN);
    3833
    3934  GetConfig (config, "RELASTRO_MAP_NX",        "%d",  0, &NX_MAP);
     
    4237  GetConfig (config, "ADDSTAR_RADIUS",         "%lf", 0, &ADDSTAR_RADIUS);
    4338
     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
    4445  GetConfig (config, "GSCFILE",                "%s",  0, GSCFILE);
    45   GetConfig (config, "CATDIR",                 "%s",  0, CATDIR);
    4646  ScanConfig(config, "CATMODE",                "%s",  0, CATMODE);
    4747  ScanConfig(config, "CATFORMAT",              "%s",  0, CATFORMAT);
  • trunk/Ohana/src/relastro/src/FitChip.c

    r30616 r33652  
    44int FitChip (StarData *raw, StarData *ref, int Nmatch, Image *image) {
    55
    6   int i, NstatFull, Nstat, Niter, skip;
     6  int i, NstatFull, Nstat, Niter;
    77  float dLsig, dMsig, dRsig;
    88  float dLsigFull, dMsigFull, dRsigFull;
     
    2727      if (raw[i].mask) continue;
    2828      if (isnan(raw[i].dMag)) {
    29         raw[i].mask |= 0x0004;
     29        raw[i].mask |= MARK_NAN_MAG_ERROR;
    3030        continue;
    3131      }
    3232      if (raw[i].dMag > SIGMA_LIM) {
    33         raw[i].mask |= 0x0008;
     33        raw[i].mask |= MARK_BIG_MAG_ERROR;
    3434        continue;
    3535      } // is this redundant with ImageOps.c:915?
     
    3939      dR = hypot (dL, dM);
    4040      if (dR > dRmax) {
    41         raw[i].mask |= 0x0010;
     41        raw[i].mask |= MARK_BIG_OFFSET;
    4242        continue;
    4343      }
     
    5252    // fit the requested order polynomial
    5353    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
    5665    if (fit) fit_free (fit);
    5766    fit = fit_init (image[0].coords.Npolyterms);
     
    6372    }
    6473
     74# if (0)
    6575    // check if the fit has enough data points for the polynomial order
    6676    skip = FALSE;
     
    8696      return FALSE;
    8797    }
     98# endif
    8899
    89100    // measure the fit, update the coords & object coordinates
     
    91102      fprintf (stderr, "failed to fit new model\n");
    92103      image[0].flags |= ID_IMAGE_ASTROM_FAIL;
     104      if (fit) fit_free (fit);
    93105      return FALSE;
    94106    }
     
    97109      fprintf (stderr, "failed to fit new model\n");
    98110      image[0].flags |= ID_IMAGE_ASTROM_FAIL;
     111      if (fit) fit_free (fit);
    99112      return FALSE;
    100113    }
     
    114127  for (i = 0; i < Nmatch; i++) {
    115128    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 ++;
    121134  }
    122135
    123136  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);
    125138
    126139  int Nm = 0;
     
    133146  image[0].nLinkAstrom = (Nm / Ns);
    134147
    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);
    136149
    137150  image[0].dXpixSys = dLsig;
  • trunk/Ohana/src/relastro/src/FixProblemImages.c

    r32346 r33652  
    55
    66int 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();
    710
    811  int Nbad;
     
    6467    }
    6568
    66     catalog = load_catalogs (&sublist, &Ncat, FALSE);
     69    // XXX use a different function here
     70    // catalog = load_catalogs (&sublist, &Ncat, FALSE);
    6771    assert (Ncat == Ncatlist);
    6872
  • trunk/Ohana/src/relastro/src/GetAstromError.c

    r30616 r33652  
    11# include "relastro.h"
    22# define WEIGHTED_ERRORS 1
     3
     4float 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}
    345
    446float GetAstromError (Measure *measure, int mode) {
     
    3072
    3173  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
    3278  AS    = code[0].astromErrScale;
    3379  MS    = code[0].astromErrMagScale;
  • trunk/Ohana/src/relastro/src/ImageOps.c

    r32695 r33652  
    33# define USE_IMAGE_ID 1
    44
    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)
    116static Image        *image;   // list of available images
    127static 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
    1311static off_t       *LineNumber; // match of subset to full image table
    1412
    15 static int         *Ncatlist;  // catalogs associated with each image
    16 static int         *NCATLIST;  // catalogs associated with each image
     13static off_t        *N_onImage;   // number of measurements on image
     14static off_t        *N_ONIMAGE;   // allocated number of measurements on image   
     15
     16static int          *Ncatlist;  // catalogs associated with each image
     17static int          *NCATLIST;  // catalogs associated with each image
    1718static int         **catlist;  // catalogs associated with each image
     19
     20static IDX_T       **MeasureToImage;     // link from catalog,measure to image
     21static IDX_T       **ImageToCatalog;   // catalog which supplied measurement on image
     22static IDX_T       **ImageToMeasure;   // measure reference for measurement on image
    1823
    1924// if we search by image ID, we sort (imageIDs, imageIdx) by imageIDs to get a sorted
     
    2833# endif
    2934
     35// MeasureToImage was 'bin'
     36// ImageToCatalog was 'clist'
     37// ImageToMeasure was 'mlist'
     38
     39// N_onImage was 'Nlist'
     40// N_ONIMAGE was 'NLIST'
     41
    3042Image *getimages (off_t *N, off_t **line_number) {
    3143
     
    105117  off_t i, j;
    106118
    107   ALLOCATE (bin, off_t *, Ncatalog);
     119  ALLOCATE (MeasureToImage, IDX_T *, Ncatalog);
    108120  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 (Nlist, off_t,   Nimage);
    114   ALLOCATE (NLIST, 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);
    117129
    118130  for (i = 0; i < Nimage; i++) {
    119     Nlist[i] =   0;
    120     NLIST[i] = 100;
    121     clist[i] = NULL;  // we allocate these iff they are needed in matchImage
    122     mlist[i] = NULL;  // we allocate these iff they are needed in matchImage
     131    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
    123135  }
    124136
     
    141153
    142154  for (i = 0; i < Ncatalog; i++) {
    143     free (bin[i]);
    144   }
    145   free (bin);
     155    free (MeasureToImage[i]);
     156  }
     157  free (MeasureToImage);
    146158  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 (Nlist);
    153   free (NLIST);
     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);
    154166}
    155167
     
    169181  }
    170182
    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);
    176205}
    177206
     
    181210
    182211  off_t idx, ID;
    183   Measure *measure;
     212  MeasureTiny *measure;
    184213  int i, found;
    185214
    186   measure = &catalog[cat].measure[meas];
     215  measure = &catalog[cat].measureT[meas];
    187216
    188217  ID = measure[0].imageID;
     
    194223
    195224  // index for (catalog, measure) -> image
    196   bin[cat][meas] = idx;
     225  MeasureToImage[cat][meas] = idx;
    197226
    198227  // 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]);
    204233  }
    205234
    206235  // index for image, Nentry -> catalog
    207   clist[idx][Nlist[idx]] = cat;
     236  ImageToCatalog[idx][N_onImage[idx]] = cat;
    208237
    209238  // index for image, Nentry -> measure
    210   mlist[idx][Nlist[idx]] = meas;
    211   Nlist[idx] ++;
    212 
    213   if (Nlist[idx] == NLIST[idx]) {
    214     NLIST[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]);
    217246  }
    218247
     
    241270
    242271  off_t i;
    243   Measure *measure;
    244 
    245   measure = &catalog[cat].measure[meas];
     272  MeasureTiny *measure;
     273
     274  measure = &catalog[cat].measureT[meas];
    246275
    247276  /* find the image that supplied this measurement */
     
    255284
    256285    // index for (catalog, measure) -> image
    257     bin[cat][meas] = i;
     286    MeasureToImage[cat][meas] = i;
    258287
    259288    // index for image, Nentry -> catalog
    260     clist[i][Nlist[i]] = cat;
     289    ImageToCatalog[i][N_onImage[i]] = cat;
    261290
    262291    // index for image, Nentry -> measure
    263     mlist[i][Nlist[i]] = meas;
    264     Nlist[i] ++;
    265 
    266     if (Nlist[i] == NLIST[i]) {
    267       NLIST[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]);
    270299    }
    271300    return;
     
    281310  off_t i;
    282311
    283   i = bin[cat][meas];
     312  i = MeasureToImage[cat][meas];
    284313  if (i == -1) return (NULL);
    285314  return (&image[i].coords);
     
    333362}
    334363
    335 void dump_measures(Average *average, Measure *measure) {
     364void dump_measures (Average *average, Measure *measure) {
    336365
    337366  off_t j, off;
     
    402431  }     
    403432
    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;
    411445
    412446    if (moscoords == NULL) {
     
    428462    // NOTE: This should never happen, or our StarMap tests are not working
    429463    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      }
    432469      // abort ();
    433470    }
    434471    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      }
    437477      // abort ();
    438478    }
    439479
    440480    // 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      }
    444487      // abort();
    445488    }
    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);
    453498    nPos ++;
    454499
    455     catalog[c].measure[m].dR = dR;
    456     catalog[c].measure[m].dD = dD;
     500    measure[0].dR = dR;
     501    measure[0].dD = dD;
    457502   
    458     if (catalog[c].measure[m].dR > +180.0*3600.0) {
     503    if (measure[0].dR > +180.0*3600.0) {
    459504      // average on high end of boundary, move star up
    460505      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) {
    464509      // average on low end of boundary, move star down
    465510      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);
    467512    }
    468513
    469514    // 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);
    473520  saveOffsets (dPos, nPos, im);
    474521
     
    487534  Mosaic *mosaic;
    488535  Coords *moscoords, *imcoords, *oldcoords;
     536
     537  fprintf (stderr, "fix resetImageRaw wrt MeasureTiny\n");
     538  abort();
    489539
    490540  // check if this image is bad and should be skipped
     
    507557  imcoords = &image[im].coords;
    508558
    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;
    516569
    517570    dR = dD = 0.0;
     
    527580    }
    528581
    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) {
    533586      // average on high end of boundary, move star up
    534587      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) {
    538591      // average on low end of boundary, move star down
    539592      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);
    541594    }
    542595  }
     
    567620  }
    568621
    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];
    574629
    575630    /* 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;
    584639
    585640    // an object with only one detection provides no information about the image calibration
    586641    // XXX this is already taken care of in bcatalog
    587     raw[i].mask = 0x0000;
     642    raw[i].mask = MARK_MEAS_DEFAULT;
    588643    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;
    593648    }
    594649    raw[i].Nmeas = catalog[c].average[n].Nmeasure; // record so we can check how well connected an image is
     
    613668  }
    614669
    615   *Nstars = Nlist[im];
     670  *Nstars = N_onImage[im];
    616671  return (raw);
    617672}
     
    639694  }
    640695
    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;
    647704
    648705    /* apply the current image transformation or use the current value of R+dR, D+dD? */
     
    650707    ref[i].D = catalog[c].average[n].D;
    651708
    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);
    655712
    656713    ref[i].mask = FALSE;
     
    675732  }
    676733
    677   *Nstars = Nlist[im];
     734  *Nstars = N_onImage[im];
    678735  return (ref);
    679736}
     
    682739void FlagOutliers2D(Catalog *catalog);
    683740
     741// operates on Full values (not tiny)
    684742void FlagOutliers (Catalog *catalog) {
    685   // XXX FlagOutliers is just using FlagOutliers2D
     743
     744  // XXX FlagOutliers is now just using FlagOutliers2D
    686745  FlagOutliers2D(catalog);
    687746  return;
     
    696755  assert(catalog[0].Nsecfilt == Nsecfilt);
    697756
    698   if (VERBOSE) fprintf (stderr, "marking poor measures\n");
     757  if (VERBOSE2) fprintf (stderr, "marking poor measures\n");
    699758  Nmax = 0;
    700759  for (i = 0; i < catalog[0].Naverage; i++) {
     
    716775  for (j = 0; j < catalog[0].Naverage; j++) {
    717776   
     777    // pointer to this set of measurements
     778    m = catalog[0].average[j].measureOffset;
     779    Measure *measure = &catalog[0].measure[m];
     780
    718781    /* accumulate list of valid measurements */
    719     m = catalog[0].average[j].measureOffset;
    720782    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++) {
    723784      // 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);
    729790      if (isnan(R[N]) || isnan(D[N])) continue;
    730791      N++;
     
    741802   
    742803    /* compare per-object distance to this standard deviation, and flag outliers*/
    743     m = catalog[0].average[j].measureOffset;
    744804    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++) {
    746806      //reset flag on each invocation
    747       catalog[0].measure[m].dbFlags &= ~ID_MEAS_POOR_ASTROM;
     807      measure[k].dbFlags &= ~ID_MEAS_POOR_ASTROM;
    748808
    749809      // skip measurements based on user selected criteria
    750       if (!MeasFilterTest(&catalog[0].measure[m], FALSE)) continue;
     810      if (!MeasFilterTest(&measure[k], FALSE)) continue;
    751811     
    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;
    754814      theta = atan2(y,x);
    755815      if ((x*x + y*y) > (SQR(statsR.sigma * Ns * cos(theta)) +
    756816                         SQR(statsD.sigma * Ns * sin(theta)))) {   
    757         catalog[0].measure[m].dbFlags |= ID_MEAS_POOR_ASTROM;
     817        measure[k].dbFlags |= ID_MEAS_POOR_ASTROM;
    758818        Ndel++;
    759819      }
     
    787847  assert(catalog[0].Nsecfilt == Nsecfilt);
    788848
    789   if (VERBOSE) fprintf (stderr, "marking poor measures\n");
     849  if (VERBOSE2) fprintf (stderr, "marking poor measures\n");
    790850  Nmax = 0;
    791851  for (i = 0; i < catalog[0].Naverage; i++) {
     
    809869  for (j = 0; j < catalog[0].Naverage; j++) {
    810870   
     871    // pointer to this set of measurements
     872    m = catalog[0].average[j].measureOffset;
     873    Measure *measure = &catalog[0].measure[m];
     874
    811875    /* accumulate list of valid measurements */
    812     m = catalog[0].average[j].measureOffset;
    813876    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;
    819881     
    820882      // 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);
    826888      if (isnan(R[N]) || isnan(D[N])) continue;
    827889      N++;
     
    837899   
    838900    /* calculate deviations of all points*/
    839     m = catalog[0].average[j].measureOffset;
    840901    N = 0;
    841     for (k = 0; k < catalog[0].average[j].Nmeasure; k++, m++) {
    842       //skip bad measurements
    843       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;
    846907      theta = atan2(y,x);
    847908      d2[N] = (x*x + y*y) / (SQR(statsR.sigma * Ns * cos(theta)) +
    848909                             SQR(statsD.sigma * Ns * sin(theta)));     
    849       index[N] = m;
     910      index[N] = k;
    850911      N++;
    851912    }
     
    856917
    857918    // recalculate image center, sigma based on closest 50% of points
    858     for(k = 0;  k < N; k++) {
     919    for (k = 0;  k < N; k++) {
    859920      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);
    864925    }
    865926    liststats (R, dR, N, &statsR);
     
    869930   
    870931    // use these new statistics to flag outliers
    871     m = catalog[0].average[j].measureOffset;
    872932    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++) {
    874934      //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;
    878938      theta = atan2(y,x);
    879939      d2[N] = (x*x + y*y) / (SQR(statsR.sigma * Ns * cos(theta)) +
    880940                             SQR(statsD.sigma * Ns * sin(theta)));     
    881941      if ((d2[N]) > 1) {
    882         catalog[0].measure[m].dbFlags |= ID_MEAS_POOR_ASTROM;
     942        measure[k].dbFlags |= ID_MEAS_POOR_ASTROM;
    883943        Ndel ++;
    884944      }
    885945      N++;
    886946      Nave++;
    887     }  //done rejecting outliers
     947    }  // done rejecting outliers
    888948
    889949    // examine results
    890950    // relastroVisualPlotOutliers(catalog, catalog[0].average[j].measureOffset, catalog[0].average[j].Nmeasure, statsR, statsD, Ns);
    891951   
    892   } //done looping over objects
     952  } // done looping over objects
    893953 
    894954  if (VERBOSE) fprintf (stderr, "%d measures marked poor, %d total\n", Ndel, Nave);
     
    901961}
    902962
    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?)
     965int 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}
    9041024
    9051025/** Determine whether a measurement should be included in the analysis, based on supplied filter criteria */
  • trunk/Ohana/src/relastro/src/ParFactor.c

    r32740 r33652  
    11# include "relastro.h"
     2# define J2000 2451545.       /* Julian date at standard epoch */
    23
    34# if (0)
     
    3132  double n, L, g;
    3233
    33 # define J2000 2451545.       /* Julian date at standard epoch */
    3434
    3535  n = jd - J2000;
     
    4646int sun_ecliptic (double jd, double *lambda, double *beta, double *epsilon, double *Radius) {
    4747
    48 # define J2000 2451545.       /* Julian date at standard epoch */
    49 
    5048  double n = jd - J2000;              // day number
    5149  double L = 280.460 + 0.9856474 * n; // mean solar longitute (corr. for aberration)
     
    6058
    6159/* given RA, DEC, Time, calculate the parallax factor */
     60// Time is relative to Tmean, Tmean is years relative to J2000
    6261int ParFactor (double *pR, double *pD, double RA, double DEC, double Time, double Tmean) {
    6362
     
    6665  /* given a time T in UNIX seconds, determine the solar longitude S */
    6766
    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
    6971  sun_ecliptic (jd, &lambda, &beta, &epsilon, &Radius);
    7072
  • trunk/Ohana/src/relastro/src/StarMaps.c

    r32346 r33652  
    6868  for (i = 0; i < catalog[0].Nmeasure; i++) {
    6969   
    70     N = getImageByID(catalog[0].measure[i].imageID);
     70    MeasureTiny *measure = &catalog[0].measureT[i];
     71
     72    N = getImageByID(measure[0].imageID);
    7173    if (N < 0) continue;
    7274
    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;
    7577
    7678    xbin = MAX(0, MIN(NX_MAP-1, xbin));
     
    8284
    8385  return (TRUE);
     86}
     87
     88int 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;
    84101}
    85102
  • trunk/Ohana/src/relastro/src/UpdateChips.c

    r32346 r33652  
    11# include "relastro.h"
     2
    23int plotChipFits (double *Ro, double *Do, char *mode, int Nimage);
    34int saveCenter (Image *image, double *Ro, double *Do, int im);
    4 
     5off_t getNextImageForThread ();
     6int UpdateChips_threaded (Catalog *catalog, int Ncatalog);
     7void *UpdateChips_worker (void *data);
     8
     9enum {THREAD_RUN, THREAD_DONE};
     10
     11typedef 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
     25static Image *image = NULL;
     26static off_t Nimage = 0;
     27static 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
    531int UpdateChips (Catalog *catalog, int Ncatalog) {
    632
    7   int Nskip, Nmosaic, NnewFit, NoldFit;
     33  off_t Nskip, Nmosaic, NnewFit, NoldFit;
    834
    935  /* 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;
    1237  StarData *raw, *ref;
    1338  Coords *oldCoords;
     
    1641  char *mode;
    1742
     43  if (NTHREADS) {
     44    UpdateChips_threaded (catalog, Ncatalog);
     45    return TRUE;
     46  }
     47
    1848  Nskip = Nmosaic = NnewFit = NoldFit = 0;
    1949
     
    2555  ALLOCATE (mode, char, Nimage);
    2656
     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
    2759  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....
    2863
    2964    /* skip all except WRP images */
     
    4782      Nskip ++;
    4883      mode[i] = 0;
     84      free (raw);
    4985      continue;
    5086    }
     
    6298    // fprintf (stderr, "image "OFF_T_FMT" : Nstars: "OFF_T_FMT"\n",  i,  Nraw);
    6399    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);
    65101
    66102      // restore status quo ante
     
    105141
    106142  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);
    109149  return (TRUE);
    110150}
    111151
     152int 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
     232void *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
     333static 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
     337off_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
    112355int saveCenter (Image *image, double *Ro, double *Do, int im) {
    113356
     
    136379    // note that for a Simple image, L,M = P,Q
    137380    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
    139382  } else {
    140383    XY_to_LM (&L, &M, X, Y, imcoords);
    141384    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);
    151389
    152390  R = ohana_normalize_angle_to_midpoint (R, Rmid);
  • trunk/Ohana/src/relastro/src/UpdateMeasures.c

    r32346 r33652  
    11# include "relastro.h"
    22
     3// this function operates on Measure, not MeasureTiny
    34int UpdateMeasures (Catalog *catalog, int Ncatalog) {
    45
  • trunk/Ohana/src/relastro/src/UpdateObjectOffsets.c

    r30616 r33652  
    77//   original coordinates
    88
    9 int UpdateObjectOffsets (SkyList *skylist) {
     9int UpdateObjectOffsets_parallel (SkyList *sky);
     10
     11int UpdateObjectOffsets (SkyList *skylist, int hostID, char *hostpath) {
    1012
    1113  int i;
    1214  Catalog catalog;
    1315
     16  // XXX need to decide how to determine PARALLEL mode...
     17  if (PARALLEL && !hostID) {
     18    UpdateObjectOffsets_parallel (skylist);
     19    return TRUE;
     20  }
     21
    1422  // load data from each region file, only use bright stars
    1523  for (i = 0; i < skylist[0].Nregions; i++) {
    1624
     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
    1733    // set up the basic catalog info
    18     catalog.filename  = skylist[0].filename[i];
    1934    catalog.catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
    2035    catalog.catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
     
    2237    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    2338
    24     if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "w")) {
     39    if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE2, "w")) {
    2540      fprintf (stderr, "ERROR: failure reading catalog %s\n", catalog.filename);
    2641      exit (1);
    2742    }
    2843    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);
    3045      dvo_catalog_unlock (&catalog);
    3146      dvo_catalog_free (&catalog);
    3247      continue;
    3348    }
     49
     50    // set the values in MeasureTiny needed by UpdateObjects
     51    populate_tiny_values(&catalog, DVO_TV_MEASURE);
    3452
    3553    // match measurements with images
     
    4058    UpdateMeasures (&catalog, 1);
    4159
     60    // uses MeasureTiny values, but will also update Measure values when populated
    4261    UpdateObjects (&catalog, 1);
    4362
     
    5069  return (TRUE);
    5170}
     71
     72// CATDIR is supplied globally
     73# define DEBUG 1
     74int 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  
    3838
    3939
     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
    4042int UpdateObjects (Catalog *catalog, int Ncatalog) {
    4143
     
    7274  T2000 = ohana_date_to_sec ("2000/01/01");
    7375  // XXX in the future, use catalog[0].Nsecfilt only?  allow catalogs to have variable Nsecfilt?
     76
    7477  Nsecfilt = GetPhotcodeNsecfilt ();
    75   assert (catalog[0].Nsecfilt == Nsecfilt);
     78  if (Ncatalog) {
     79    assert (catalog[0].Nsecfilt == Nsecfilt);
     80  }
    7681
    7782  NaveSum = NparSum = NpmSum = NskipSum = 0;
    7883  for (i = 0; i < Ncatalog; i++) {
    7984
    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);
    8186
    8287    Nave = Npar = Npm = Nskip = 0;
     
    8691      XVERB = FALSE;
    8792
    88       // skip objects which are known to be problematic
    89       // XXX include this code or not?
    90 # if (0)
    91       if (catalog[i].average[j].code & STAR_BAD) {
    92         Nskip ++;
    93         continue; 
    94       }
    95 # endif
    96 
    9793      if (catalog[i].average[j].Nmeasure == 0) {
    9894          continue;
     
    10197      N = 0;
    10298      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
    104103      mode = FIT_MODE;
    105104
    106105      // 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; }
    113112          continue;
    114113        }
    115114
    116115        //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; }
    119119          continue;
    120120        }
    121121
    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;
    127140          continue;
    128141        }
    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        }
    144146
    145147        // add systematic error in quadrature, if desired
    146148        // only do this after the fit has converged (or you will never improve the poor images)
    147149        // if (INCLUDE_SYS_ERR) {
    148         // float dRsys = FromShortPixels(catalog[i].measure[m].dRsys);
     150        // float dRsys = FromShortPixels(measure[k].dRsys);
    149151        // dX[N] = hypot(dX[N], dRsys);
    150152        // dY[N] = hypot(dY[N], dRsys);
     
    154156        // dY[N] = 0.1;
    155157
    156         dT[N] = catalog[i].measure[m].dt;
     158        dT[N] = measure[k].dt;
    157159
    158160        // XXX this is (slightly) inconsistent: dX,dY are the X and Y direction errors in
     
    172174      catalog[i].average[j].flags &= ~ID_STAR_FEW;
    173175
     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      }
    174184      // XXX add the parallax factor range as a criterion as well
    175185      Trange = Tmax - Tmin;
    176186      if (Trange < PM_DT_MIN) mode = FIT_AVERAGE;
    177187      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      }
    178194
    179195      // too few measurements for average position (require 2 values)
     
    192208      coords.crval2 = D[0];
    193209
    194       if (FIT_TARGET == TARGET_HIGH_SPEED) {
    195           Tmean = 0.5*(Tmax - Tmin);
    196       } else {
    197           Tmean /= (float) N;
    198       }
    199      
    200210      // XVERB |= (catalog[i].averge[j].objID == 0xc90) && (catalog[i].average[j].catID == 0x2a1e);
    201211      XVERB |= (catalog[i].average[j].objID == OBJ_ID_SRC) && (catalog[i].average[j].catID == CAT_ID_SRC);
    202212      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);
    204213
    205214      // to judge the quality of the PM and PAR fits, we need to fit all three models and compare Chisq
     
    232241        // fprintf (stderr, "parallax fitting is still untested (%s, %d)\n", __FILE__, __LINE__);
    233242
     243        float pXmin = +2.0;
     244        float pXmax = -2.0;
     245        float pYmin = +2.0;
     246        float pYmax = -2.0;
    234247        for (k = 0; k < N; k++) {
    235248          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        }
    241264      }   
    242265
     
    307330
    308331      // 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        }
    313339      }     
    314340
  • trunk/Ohana/src/relastro/src/args.c

    r32695 r33652  
    11# include "relastro.h"
    22void usage (void);
     3void usage_client (void);
    34void usage_merge_source (void);
    45void usage_merge_source_id (char *name);
     
    4243  if ((N = get_argument (argc, argv, "-update-objects"))) {
    4344    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;
    4551  }
    4652
     
    9298    RADIUS = atof(argv[N]);
    9399    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    }
    96112  }
    97113
     
    118134
    119135  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   }
    130136
    131137  /* specify portion of the sky : allow default of all sky? */
     
    144150    UserPatch.Dmax = atof (argv[N]);
    145151    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);
    149185    }
     186    PARALLEL = TRUE; // -parallel-serial implies -parallel
     187    PARALLEL_SERIAL = TRUE;
     188    remove_argument (N, &argc, argv);
    150189  }
    151190
     
    290329  } 
    291330
    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 
    306331  ImagSelect = FALSE;
    307332  if ((N = get_argument (argc, argv, "-instmag"))) {
     
    336361  }
    337362
    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 
    347363  NLOOP = 4;
    348364  if ((N = get_argument (argc, argv, "-nloop"))) {
    349365    remove_argument (N, &argc, argv);
    350366    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]);
    351374    remove_argument (N, &argc, argv);
    352375  }
     
    356379}
    357380
     381int 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
    358653void 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");
    362659  fprintf (stderr, "       OR:    relastro -merge-source [options]\n\n");
     660
    363661  fprintf (stderr, "  specify one of the following modes: \n");
    364662  fprintf (stderr, "  -update-objects\n");
     
    369667  fprintf (stderr, "  -update-chips\n");
    370668  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");
    373675  fprintf (stderr, "  -time (start)(stop)\n");
    374676  fprintf (stderr, "  +photcode (code)[,code,code...]\n");
     
    383685  fprintf (stderr, "  -plrange\n");
    384686  fprintf (stderr, "  -minerror\n");
    385   fprintf (stderr, "  -area\n");
    386   fprintf (stderr, "  -area Xmin Xmax Ymin Ymax\n");
    387687  fprintf (stderr, "  -instmag min max\n\n");
    388688  fprintf (stderr, "  +photflags\n");
     
    394694}
    395695
     696void 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
    396730void usage_merge_source_id (char *name) {
    397731
  • trunk/Ohana/src/relastro/src/bcatalog.c

    r31664 r33652  
    11# include "relastro.h"
     2
     3static int Nskip1 = 0;
     4static int Nskip2 = 0;
     5static unsigned int Tref = 1323353985;
     6static short Cref = 10355;
    27
    38int bcatalog (Catalog *subcatalog, Catalog *catalog) {
     
    1217
    1318  /* we are moving only the subset of measurements from catalog[0] to subcatalog[0] */
     19  memset(subcatalog, 0, sizeof(Catalog));
    1420  NAVERAGE = 50;
    1521  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);
    1925  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;
    2036
    2137  /* exclude stars not in range or with too few measurements */
     
    2339    if (catalog[0].average[i].Nmeasure <= SRC_MEAS_TOOFEW) {
    2440      continue;
     41      // XXX can't (easily) count this for a given chip
    2542    }
    2643   
     
    3350
    3451    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;
    4053    }
    4154
     
    4861      if (!MeasFilterTest(&catalog[0].measure[offset], TRUE)) {
    4962        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        }
    5066        continue;
    5167      }
     
    5470      if (FlagOutlier && (catalog[0].measure[offset].dbFlags & ID_MEAS_POOR_ASTROM)) {
    5571        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        }
    5675        continue;
    5776      }
     
    7089      // allowed.
    7190
    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;
    7896      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;
    8199      }
    82100
     
    85103      if (Nmeasure == NMEASURE) {
    86104        NMEASURE += 1000;
    87         REALLOCATE (subcatalog[0].measure, Measure, NMEASURE);
     105        REALLOCATE (subcatalog[0].measureT, MeasureTiny, NMEASURE);
    88106      }
    89107    }
     
    96114    }
    97115  }
    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);
    101119  subcatalog[0].Naverage = Naverage;
    102120  subcatalog[0].Nmeasure = Nmeasure;
    103121  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;
    105124  assert (Nsecfilt == catalog[0].Nsecfilt);
    106125
    107126  // limit the total number of stars in the catalog
    108127  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  }
    115137  return (TRUE);
    116138}
    117139
     140void bcatalog_show_skips () {
     141  fprintf (stderr, "Nskip: %d, %d\n", Nskip1, Nskip2);
     142}
     143
     144// sort by decreasing Nmeasure (X)
     145void 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
    118160/* this version does NOT use AverageTiny, MeasureTiny */
    119 int LimitDensityCatalog (Catalog *subcatalog, Catalog *catalog) {
     161int LimitDensityCatalog_ByNmeasure (Catalog *subcatalog, Catalog *oldcatalog) {
    120162
    121163  Catalog tmpcatalog;
     
    125167  int Nsecfilt = GetPhotcodeNsecfilt ();
    126168
    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);
    131173
    132174  if (VERBOSE2) fprintf (stderr, "extracting from catalog covering region %f,%f to %f,%f\n", Rmin, Dmin, Rmax, Dmax);
     
    147189  // select a random subset of Nmax stars from subcatalog using Fisher-Yates
    148190
    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;
    151194  ALLOCATE (index, off_t, Naverage);
     195  ALLOCATE (value, int, Naverage);
    152196  for (i = 0; i < Naverage; i++) {
    153197    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);
    161201
    162202  // count the number of measurements this selection will yield
     
    168208
    169209  // 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);
    173213
    174214  off_t Nmeasure = 0;
     
    181221    for (j = 0; j < tmpcatalog.average[i].Nmeasure; j++) {
    182222      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;
    185225      Nmeasure ++;
    186226    }
    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 */
     257int 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) {
    190331    fprintf (stderr, "limited to "OFF_T_FMT" of "OFF_T_FMT" stars ("OFF_T_FMT" of "OFF_T_FMT" measures) for catalog %s\n",
    191332             Nmax, subcatalog[0].Naverage, Nmeasure, subcatalog[0].Nmeasure,  catalog[0].filename);
     
    193334
    194335  free (subcatalog[0].average);
    195   free (subcatalog[0].measure);
     336  free (subcatalog[0].measureT);
    196337  free (subcatalog[0].secfilt);
    197338
    198339  subcatalog[0].average = tmpcatalog.average;
    199   subcatalog[0].measure = tmpcatalog.measure;
     340  subcatalog[0].measureT = tmpcatalog.measureT;
    200341  subcatalog[0].secfilt = tmpcatalog.secfilt;
    201342  subcatalog[0].Naverage = Nmax;
  • trunk/Ohana/src/relastro/src/dvo_astrom_ops.c

    r12332 r33652  
    11# include "relastro.h"
    22
    3 double getMeanR (Measure *measure, Average *average, SecFilt *secfilt) {
     3double getMeanR (MeasureTiny *measure, Average *average, SecFilt *secfilt) {
    44
    55  double ra;
     
    2121}
    2222
    23 double getMeanD (Measure *measure, Average *average, SecFilt *secfilt) {
     23double getMeanD (MeasureTiny *measure, Average *average, SecFilt *secfilt) {
    2424
    2525  double dec;
     
    4141}
    4242
    43 int setMeanR (double ra_fit, Measure *measure, Average *average, SecFilt *secfilt) {
     43int setMeanR (double ra_fit, MeasureTiny *measure, Average *average, SecFilt *secfilt) {
    4444
    4545  /* math to get from new fitted position to new measure offset
     
    6666}
    6767
    68 int setMeanD (double dec_fit, Measure *measure, Average *average, SecFilt *secfilt) {
     68int setMeanD (double dec_fit, MeasureTiny *measure, Average *average, SecFilt *secfilt) {
    6969
    7070  /* math to get from new fitted position to new measure offset
     
    9090  return (TRUE);
    9191}
     92
     93int 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
     120int 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  
    149149 
    150150  if (!dgaussjordan (matrix, vector, fit[0].Nelems, 2)) {
     151    array_free (matrix, fit[0].Nelems);
     152    array_free (vector, fit[0].Nelems);
    151153    return (FALSE);
    152154  }
  • trunk/Ohana/src/relastro/src/high_speed_catalogs.c

    r31635 r33652  
    11# include "relastro.h"
    22
    3 int high_speed_catalogs () {
     3int high_speed_catalogs_parallel (SkyList *sky);
     4
     5int high_speed_catalogs (SkyTable *sky, SkyList *skylist, int hostID, char *hostpath) {
    46
    57  int i;
    6 
    7   SkyTable *sky = NULL;
    8   SkyList *skylist = NULL;
    98  Catalog catalog;
    109
     
    1211  dvo_set_catdir(CATDIR);
    1312
    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 
    2713  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  }
    2820
    2921  // load data from each region file, only use bright stars
    3022  for (i = 0; i < skylist[0].Nregions; i++) {
    3123
     24    // does this host ID match the desired location for the table?
     25    if (!HostTableTestHost(skylist[0].regions[i], hostID)) continue;
     26
    3227    // 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];
    3431    catalog.catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
    3532    catalog.catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
     
    3734    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    3835
    39     if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "r")) {
     36    if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE2, "r")) {
    4037      fprintf (stderr, "ERROR: failure reading catalog %s\n", catalog.filename);
    4138      exit (1);
    4239    }
    4340    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);
    4542      dvo_catalog_unlock (&catalog);
    4643      dvo_catalog_free (&catalog);
     
    5451  }
    5552 
     53finish:
     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
    5673  return (TRUE);
    5774}
     75
     76// CATDIR is supplied globally
     77# define DEBUG 1
     78int 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  
    66int high_speed_objects (SkyRegion *region, Catalog *catalog) {
    77
    8   // XXX seems silly to require region here just to find the catalog bounds / center
    9 
    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;
    1313  double *X1, *Y1;
    1414  double dX, dY, dR, RADIUS2;
    1515  Coords tcoords;
    16   Catalog catalog1;
     16  Catalog catalogOut;
    1717
    1818  int Nsecfilt;
    1919  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);
    2526
    2627  SIGMA_LIM = 0.0;
    2728
    2829  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
    3535 
    36   catalog1.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    37   catalog1.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    38 
    39   if (!dvo_catalog_open (&catalog1, 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")) {
    4040    fprintf (stderr, "ERROR: failure to open catalog file %s\n",
    4141             filename);
     
    4545  NAVERAGE = 1000;
    4646  NMEASURE = 10000;
    47   REALLOCATE (catalog1.average, Average, NAVERAGE);
    48   REALLOCATE (catalog1.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);
    5050
    5151  // high-speed between different surveys (easier case):
     
    7777  // mark (exclude) objects with both sets of target photcodes
    7878  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
    7986    // do any of the measures for this object match group A?
    8087    m = catalog[0].average[i].measureOffset;
     
    114121            // fprintf (stderr, "skip "OFF_T_FMT" (group A)\n",  i);
    115122        }
    116 
    117     } else if (foundB && !foundA) {
    118 
     123        continue;
     124    }
     125    if (foundB && !foundA) {
    119126        if (applyConstraintsB(catalog, i)) {
    120127            groupB[i] = TRUE;
     
    124131            NgroupBbad++;
    125132        }
     133        continue;
    126134    }
    127135    // this object does not have a detection matching the contraints from either gorupA or groupB -- skip as if slow
     
    173181    nj = N1[j];
    174182
     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
    175189    if (slowMoving[ni]) NEXT_I;
    176190    if (slowMoving[nj]) NEXT_J;
     
    185199    // look for pairs that are within the maximum separation
    186200    dX = X1[i] - X1[j];
     201    if (XVERB) {
     202      fprintf (stderr, "%d %d : %f\n", (int) ni, (int) nj, dX);
     203    }
    187204
    188205    if (dX <= -1.02*RADIUS) NEXT_I; // negative dX: i is too small
     
    197214      nj = N1[J];
    198215      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      }
    199223
    200224      dY = Y1[i] - Y1[J];
     
    209233      nv[1]=nj;
    210234
    211       catalog1.average[Nmatch]=catalog[0].average[nv[0]];
     235      catalogOut.average[Nmatch]=catalog[0].average[nv[0]];
    212236      /*Loop over index values and set measurements in new catalogue*/
    213237      Nmatchmeasobj=0;
    214       catalog1.average[Nmatch].measureOffset=Nmatchmeas;
     238      catalogOut.average[Nmatch].measureOffset=Nmatchmeas;
    215239      for(l=0;l<Nepoch;l++) {
    216240          m = catalog[0].average[nv[l]].measureOffset;
    217241          for(i1=0;i1<catalog[0].average[nv[l]].Nmeasure;i1++) {
    218               catalog1.measure[Nmatchmeas]=catalog[0].measure[m+i1];
     242              catalogOut.measure[Nmatchmeas]=catalog[0].measure[m+i1];
    219243              /*Set offset RA and Dec wrt correct average value*/
    220               catalog1.measure[Nmatchmeas].dR=catalog[0].measure[m+i1].dR+3600.0*(catalog[0].average[nv[0]].R-catalog[0].average[nv[l]].R);
    221               catalog1.measure[Nmatchmeas].dD=catalog[0].measure[m+i1].dD+3600.0*(catalog[0].average[nv[0]].D-catalog[0].average[nv[l]].D);
    222               catalog1.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;
    223247              Nmatchmeasobj++;
    224248              Nmatchmeas++;
     
    226250              if (Nmatchmeas == NMEASURE - 1) {
    227251                NMEASURE += 10000;
    228                 REALLOCATE (catalog1.measure, Measure, NMEASURE);
     252                REALLOCATE (catalogOut.measure, Measure, NMEASURE);
    229253              }
    230254          }
    231255      }
    232       catalog1.average[Nmatch].Nmeasure=Nmatchmeasobj;
     256      catalogOut.average[Nmatch].Nmeasure = Nmatchmeasobj;
    233257      Nmatch ++;
    234258
    235259      if (Nmatch == NAVERAGE - 1) {
    236260        NAVERAGE += 1000;
    237         REALLOCATE (catalog1.average, Average, NAVERAGE);
    238         REALLOCATE(catalog1.secfilt, SecFilt, NAVERAGE*Nsecfilt);
     261        REALLOCATE (catalogOut.average, Average, NAVERAGE);
     262        REALLOCATE(catalogOut.secfilt, SecFilt, NAVERAGE*Nsecfilt);
    239263      }
    240264    }
    241265    i++;
    242266  }
    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);
    249274
    250275  fprintf (stderr, "found %d matches\n", Nmatch);
    251   dvo_catalog_save (&catalog1, VERBOSE);
    252   dvo_catalog_unlock (&catalog1);
    253   dvo_catalog_free (&catalog1);
     276  dvo_catalog_save (&catalogOut, VERBOSE2);
     277  dvo_catalog_unlock (&catalogOut);
     278  dvo_catalog_free (&catalogOut);
    254279  free (slowMoving);
    255280  free (groupA);
     
    262287}
    263288
    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)
    265291int MeasMatchesPhotcode(Measure *measure, PhotCode **photcodeSet, int Nset) {
    266292
    267293  int found, k;
    268294
    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;
    273301 
     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
    274308  /* 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;
    285316}
  • trunk/Ohana/src/relastro/src/high_speed_utils.c

    r31635 r33652  
    1717static dbStack *stackA = NULL;
    1818static int NstackA = 0;
     19
    1920static dbField *fieldsB = NULL;
    2021static int NfieldsB = 0;
    2122static dbStack *stackB = NULL;
    2223static int NstackB = 0;
     24
    2325static dbValue *valuesA;
    2426// static int NvaluesA;
     
    4143    ALLOCATE(words, char *, NwordsAllocated);
    4244
    43     char *copy_of_str = strdup(string);
     45    char *copy_of_str = strcreate(string);
    4446
    4547    char *saveptr = NULL;
     
    6062// Create the data strucutres required to apply avextract like cuts
    6163int 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;
    6267
    6368    // split the string into words
     
    8994
    9095int initializeConstraints() {
     96
    9197  // 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();
    98110
    99111    if (! setupConstraints(WHERE_A, &fieldsA, &NfieldsA, &stackA, &NstackA)) {
     
    102114        exit(1);
    103115    }
    104     ALLOCATE(valuesA, dbValue, NfieldsA);
     116    if (NfieldsA) {
     117      ALLOCATE(valuesA, dbValue, NfieldsA);
     118    }
     119
    105120    if (! setupConstraints(WHERE_B, &fieldsB, &NfieldsB, &stackB, &NstackB)) {
    106121        print_error();
     
    108123        exit(1);
    109124    }
    110     ALLOCATE(valuesB, dbValue, NfieldsB);
     125    if (NfieldsB) {
     126      ALLOCATE(valuesB, dbValue, NfieldsB);
     127    }
     128
    111129    return TRUE;
    112130}
     
    116134int applyConstraintsA(Catalog *catalog, off_t i) {
    117135    off_t m = catalog[0].average[i].measureOffset;
    118     off_t n;
    119136    int Nsecfilt = GetPhotcodeNsecfilt();
    120137   
    121     dbExtractAveragesInit();
     138    // an empty WHERE matches all objects
     139    if (!NfieldsA) return TRUE;
     140
     141    off_t n;
    122142    for (n = 0; n < NfieldsA; n++) {
    123143        valuesA[n] = dbExtractAverages (&catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt], &catalog[0].measure[m], &fieldsA[n]);
     
    130150    int Nsecfilt = GetPhotcodeNsecfilt();
    131151   
    132     dbExtractAveragesInit();
     152    // an empty WHERE matches all objects
     153    if (!NfieldsB) return TRUE;
    133154
    134155    off_t n;
  • trunk/Ohana/src/relastro/src/initialize.c

    r32346 r33652  
    22
    33void initialize (int argc, char **argv) {
    4 
    5   int NPHOTCODES;
    6   char *codename, *ptr, *list;
    7 
    8   ptr = NULL;
    94
    105  ConfigInit (&argc, argv);
     
    138  if (FIT_TARGET == TARGET_MERGE_SOURCE) return;
    149
    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);
    1714
    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);
    10119
    10220  initstats (STATMODE);
     
    12341}
    12442
     43void 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  
    11# include "relastro.h"
    22
    3 Catalog *load_catalogs (SkyList *skylist, int *Ncatalog, int subselect) {
     3Catalog *load_catalogs_parallel (SkyList *sky, int *Ncatalog);
     4void bcatalog_show_skips ();
     5
     6Catalog *load_catalogs (SkyList *skylist, int *Ncatalog, int subselect, int hostID, char *hostpath) {
    47
    58  int i, j, k, m, Nstar;
    69  Catalog *catalog, *pcatalog, tcatalog;
    710
     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
    817  if (VERBOSE) fprintf (stderr, "loading catalog data\n");
    918
    1019  ALLOCATE (catalog, Catalog, skylist[0].Nregions);
    1120
    12   initStarMaps();
    13 
    1421  // load data from each region file, only use bright stars
     22  int Ncat = 0;
    1523  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;
    1627
    1728    // we only allow output if we do not use a subset.  in this case,
     
    1930    pcatalog = subselect ? &tcatalog : &catalog[i];
    2031
     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
    2137    // 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 catformat from config data
    24     pcatalog[0].catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
    25     pcatalog[0].catflags  = LOAD_AVES | LOAD_MEAS | LOAD_SECF; // don't need to load all data at this point
    26     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
    2844    if (!dvo_catalog_open (pcatalog, skylist[0].regions[i], VERBOSE2, "w")) {
    2945      fprintf (stderr, "ERROR: failure reading catalog %s\n", pcatalog[0].filename);
    3046      exit (1);
    3147    }
    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))
    3561    if (FlagOutlier) {
    3662      FlagOutliers(&tcatalog);
    3763    }
    3864
    39     updateStarMaps (&tcatalog);
    40 
    4165    // select only the brighter stars
    4266    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);
    4470      dvo_catalog_unlock (&tcatalog);
    4571      dvo_catalog_free (&tcatalog);
    4672    } else {
    4773      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;
    5379          }
    5480        }
    5581      }
    5682    }
    57   }
    58 
    59   // XXX keep this test?
     83    Ncat ++;
     84  }
     85
     86  // XXX TEST : bcatalog_show_skips();
     87
    6088  Nstar = 0;
    61   for (i = 0; i < skylist[0].Nregions; i++) {
     89  for (i = 0; i < Ncat; i++) {
    6290    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    }
    6396  }
    6497  if (Nstar < 2) {
     
    6699  }
    67100
    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;
    70104  return (catalog);
    71105}
     
    76110   need to use an XCLD lock here. 
    77111*/
     112
     113// CATDIR is supplied globally
     114# define DEBUG 1
     115Catalog *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  
    77  fprintf (stderr, MSG, __VA_ARGS__); }
    88
    9 SkyList *load_images (FITS_DB *db, SkyRegion *region) {
     9int load_images (FITS_DB *db, SkyList *skylist) {
    1010
    1111  Image     *image, *subset;
     
    1414  struct timeval start, stop;
    1515
    16   SkyTable *sky = NULL;
    17   SkyList *skylist = NULL;
    18 
    1916  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 area
    26   if (UserCatalog) {
    27     skylist = SkyRegionByPoint (sky, -1, UserCatalogRA, UserCatalogDEC);
    28   } else {
    29     skylist = SkyListByPatch (sky, -1, region);
    30   }
    31   MARKTIME("  setup sky: %f sec\n", dtime);
    3217
    3318  // convert database table to internal structure
     
    3722      exit (2);
    3823  }
    39 
    4024  MARKTIME("  convert image table: %f sec\n", dtime);
    4125
     
    5337  if (!UPDATE) dvo_image_unlock (db);
    5438
    55   return (skylist);
     39  return TRUE;
    5640}
    5741
     
    7155    memcpy (vtable[0].buffer[i], &image[i], Nx);
    7256  }
    73   return (TRUE);
     57  return TRUE;
    7458}
  • trunk/Ohana/src/relastro/src/relastro.c

    r32346 r33652  
    33int main (int argc, char **argv) {
    44
    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 
    135  /* get configuration info, args */
    146  initialize (argc, argv);
    157
    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);
    2111
    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);
    2717
    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);
    3322
    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);
    3627
    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);
    4333
    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);
    9637
    9738    default:
    98       fprintf (stderr, "programming error at %s:%d", __FILE__, __LINE__);
    99       exit (2);
     39      fprintf (stderr, "impossible!\n");
     40      abort();
    10041  }
    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);
    12043}
  • trunk/Ohana/src/relastro/src/relastro_merge_source.c

    r32346 r33652  
    11# include "relastro.h"
    22
    3 int relastro_merge_source () {
     3int relastro_merge_source (SkyTable *sky) {
    44
    55  int i, m;
    6   SkyTable *sky = NULL;
    76  Catalog catalog_src, catalog_dst;
    87
     
    1312  dvo_set_catdir(CATDIR);
    1413
    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  
    1914  // we are merging the detections of the src into the dst : OBJ_ID_SRC,CAT_ID_SRC -> OBJ_ID_DST,CAT_ID_DST
    2015
     
    5247  catalog_src.Nsecfilt  = GetPhotcodeNsecfilt ();
    5348
    54   if (!dvo_catalog_open (&catalog_src, region_src, VERBOSE, "w")) {
     49  if (!dvo_catalog_open (&catalog_src, region_src, VERBOSE2, "w")) {
    5550    fprintf (stderr, "ERROR: failure reading catalog %s\n", catalog_src.filename);
    5651    exit (1);
     
    127122    resort_catalog (&catalog_src);
    128123
    129     dvo_catalog_save (&catalog_src, VERBOSE);
     124    dvo_catalog_save (&catalog_src, VERBOSE2);
    130125    dvo_catalog_unlock (&catalog_src);
    131126    dvo_catalog_free (&catalog_src);
  • trunk/Ohana/src/relastro/src/relastro_objects.c

    r27581 r33652  
    11# include "relastro.h"
    22
    3 int relastro_objects () {
     3int relastro_objects_parallel (SkyList *sky);
     4
     5int relastro_objects (SkyList *skylist, int hostID, char *hostpath) {
    46
    57  int i, j, k, m;
    68
    7   SkyTable *sky = NULL;
    8   SkyList *skylist = NULL;
    99  Catalog catalog;
    1010
     11  DVOMeasureFlags measureBits =
     12    ID_MEAS_POOR_ASTROM |
     13    ID_MEAS_SKIP_ASTROM |
     14    ID_MEAS_USED_OBJ    |
     15    ID_MEAS_USED_CHIP;
    1116
    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;
    2131  }
    2232
     
    2434  for (i = 0; i < skylist[0].Nregions; i++) {
    2535
     36    // does this host ID match the desired location for the table?
     37    if (!HostTableTestHost(skylist[0].regions[i], hostID)) continue;
     38
    2639    // 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];
    2843    catalog.catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
    2944    catalog.catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
     
    3146    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    3247
    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")) {
    3450      fprintf (stderr, "ERROR: failure reading catalog %s\n", catalog.filename);
    3551      exit (1);
    3652    }
    3753    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);
    3955      dvo_catalog_unlock (&catalog);
    4056      dvo_catalog_free (&catalog);
     
    4258    }
    4359
     60    // operates on full tables (Average, Measure, Secfilt)
    4461    if (FlagOutlier) {
    4562      FlagOutliers(&catalog);
    4663    }
    4764
    48     // XXX consider what gets reset (only ASTROM flags)
     65    // reset only the astrometry-related average and measure bits
    4966    if (RESET) {
    5067      for (j = 0; j < catalog.Naverage; j++) {
    51         catalog.average[j].flags = 0;
     68        catalog.average[j].flags &= ~averageBits;
    5269        m = catalog.average[j].measureOffset;
    5370        for (k = 0; k < catalog.average[j].Nmeasure; k++) {
    54           catalog.measure[m+k].dbFlags = 0;
     71          catalog.measure[m+k].dbFlags &= ~measureBits;
    5572        }
    5673      }
    5774    }
    5875
     76    populate_tiny_values(&catalog, DVO_TV_MEASURE);
     77
    5978    UpdateObjects (&catalog, 1);
     79
     80    free_tiny_values(&catalog);
    6081
    6182    if (!UPDATE) {
     
    7091  return (TRUE);
    7192}
     93
     94// CATDIR is supplied globally
     95# define DEBUG 1
     96int 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  
    11# 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(); } }
    52
    63// sort the measure Sequence based on the average Sequence entries
  • trunk/Ohana/src/relastro/src/save_catalogs.c

    r12731 r33652  
    88  for (i = 0; i < Ncatalog; i++) {
    99
    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);
    1212    dvo_catalog_unlock (&catalog[i]);
    1313    dvo_catalog_free (&catalog[i]);
  • trunk/Ohana/src/relastro/src/select_images.c

    r31160 r33652  
    2525 
    2626  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;
    2828  off_t *line_number;
    2929  int InRange, found;
     
    6868  DminSkyRegion = +90.0;
    6969  DmaxSkyRegion = -90.0;
     70
     71  D_NIMAGE = 6000;
    7072
    7173  /* compare with each region file */
     
    113115
    114116  nimage = 0;
    115   NIMAGE = 100;
     117  NIMAGE = D_NIMAGE;
    116118  ALLOCATE (image, Image, NIMAGE);
    117119  ALLOCATE (line_number, off_t, NIMAGE);
     
    167169
    168170    /* 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;
    171173    double DminImage = +90.0;
    172174    double DmaxImage = -90.0;
     
    194196    if (RmaxImage < RminSkyRegion) continue;
    195197
     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
    196213    // image overlaps region, keep it
    197214    if (USE_BASIC_CHECK) goto found_it;
     
    243260    }
    244261    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
    249263      image[nimage].flags &= ~badImage;
    250264    }
     
    252266    nimage ++;
    253267    if (nimage == NIMAGE) {
    254       NIMAGE += 100;
     268      NIMAGE += D_NIMAGE;
     269      D_NIMAGE = MAX (100000, D_NIMAGE * 1.5);
    255270      REALLOCATE (image, Image, NIMAGE);
    256271      REALLOCATE (line_number, off_t, NIMAGE);
     
    264279  REALLOCATE (line_number, off_t, MAX (nimage, 1));
    265280  free (skycoords);
     281  free (RmaxSky);
     282  free (index);
    266283
    267284  *Nimage  = nimage;
  • trunk/Ohana/src/relastro/src/testparallax.c

    r32741 r33652  
    11# 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 */
    25
    36int 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;
    415
    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);
    832    }
     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);
    938
    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);
    1341
    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  }
    2249
    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");
    2460
    25     // project to local coords
     61  // use one point as a local reference
     62  coords.crval1 = R[0];
     63  coords.crval2 = D[0];
    2664
    27     // run fitter
    28     FitPMandPar
     65  TrefS = TjyrsS = 0.0;
    2966
     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);
    3070
     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);
    31113}
     114
Note: See TracChangeset for help on using the changeset viewer.