IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8390


Ignore:
Timestamp:
Aug 16, 2006, 11:17:15 AM (20 years ago)
Author:
eugene
Message:

update to new DVO APIs

Location:
trunk/Ohana/src/relastro/src
Files:
2 added
11 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/relastro/src/ConfigInit.c

    r6808 r8390  
    3434  sprintf (ImageCat, "%s/Images.dat", CATDIR);
    3535
     36  if (!ScanConfig (config, "SKY_DEPTH",         "%d",  0, &SKY_DEPTH)) {
     37    SKY_DEPTH = 2;
     38  }
     39  if (!ScanConfig (config, "SKY_TABLE",         "%s",  0, SKY_TABLE)) {
     40    SKY_TABLE[0] = 0;
     41  }
     42
    3643  GetConfig (config, "PHOTCODE_FILE",          "%s",  0, PhotCodeFile);
    3744  GetConfig (config, "ZERO_PT",                "%lf", 0, &ZERO_POINT);
  • trunk/Ohana/src/relastro/src/args.c

    r6808 r8390  
    11# include "relphot.h"
     2void usage (void);
    23
    34int args (int argc, char **argv) {
    45
    56  int N;
     7  double trange;
    68
    79  /* define time */
     
    1416    }
    1517    remove_argument (N, &argc, argv);
    16     if (!str_to_time (argv[N], &TSTOP)) {
    17       fprintf (stderr, "ERROR: syntax error\n");
    18       return (FALSE);
     18    if (!str_to_dtime (argv[N], &trange)) {
     19      if (!str_to_time (argv[N], &TSTOP)) {
     20        fprintf (stderr, "ERROR: syntax error\n");
     21        return (FALSE);
     22      }
     23    } else {
     24      if (trange < 0) {
     25        trange = fabs (trange);
     26        TSTOP = TSTART;
     27        TSTART -= trange;
     28      } else {
     29        TSTOP = TSTART + trange;
     30      }
    1931    }
    2032    remove_argument (N, &argc, argv);
    2133    TimeSelect = TRUE;
     34  }
     35
     36  /* specify portion of the sky */
     37  UserPatch.Rmin = 0;
     38  UserPatch.Rmax = 360;
     39  UserPatch.Dmin = -90;
     40  UserPatch.Dmax = +90;
     41  UserPatchSelect = FALSE;
     42  if ((N = get_argument (argc, argv, "-region"))) {
     43    remove_argument (N, &argc, argv);
     44    UserPatch.Rmin = atof (argv[N]);
     45    remove_argument (N, &argc, argv);
     46    UserPatch.Rmax = atof (argv[N]);
     47    remove_argument (N, &argc, argv);
     48    UserPatch.Dmin = atof (argv[N]);
     49    remove_argument (N, &argc, argv);
     50    UserPatch.Dmax = atof (argv[N]);
     51    remove_argument (N, &argc, argv);
     52    UserPatchSelect = TRUE;
    2253  }
    2354
     
    142173  }
    143174
    144   if (argc != 3) {
    145     fprintf (stderr, "ERROR: USAGE: nrphot (region) (photcode)\n");
    146     fprintf (stderr, "  options: \n");
    147     fprintf (stderr, "  -time (start) (stop)\n");
    148     fprintf (stderr, "  -v\n");
    149     fprintf (stderr, "  -plot\n");
    150     fprintf (stderr, "  -plotdelay (seconds)\n");
    151     fprintf (stderr, "  -statmode (mode)\n");
    152     fprintf (stderr, "  -n (nloop)\n");
    153     fprintf (stderr, "  -reset\n");
    154     fprintf (stderr, "  -update\n");
    155     fprintf (stderr, "  -params\n");
    156     fprintf (stderr, "  -mosaic (mosaic)\n");
    157     fprintf (stderr, "  -imfreeze\n");
    158     fprintf (stderr, "  -grid\n");
    159     fprintf (stderr, "  -area Xmin Xmax Ymin Ymax\n");
    160     fprintf (stderr, "  -instmag min max\n");
    161     fprintf (stderr, "  \n");
    162     exit (2);
    163   }
    164   return (TRUE);
     175  if ( UserPatchSelect && (argc != 2)) usage ();
     176  if (!UserPatchSelect && (argc != 3)) usage ();
     177
     178  return TRUE;
    165179}
    166180
     181void usage () {
     182  fprintf (stderr, "ERROR: USAGE: relphot (region) (photcode)\n");
     183  fprintf (stderr, "       or:    relphot (photcode) -region RA RA DEC DEC\n");
     184  fprintf (stderr, "  options: \n");
     185  fprintf (stderr, "  -time (start) (stop)\n");
     186  fprintf (stderr, "  -v\n");
     187  fprintf (stderr, "  -plot\n");
     188  fprintf (stderr, "  -plotdelay (seconds)\n");
     189  fprintf (stderr, "  -statmode (mode)\n");
     190  fprintf (stderr, "  -n (nloop)\n");
     191  fprintf (stderr, "  -reset\n");
     192  fprintf (stderr, "  -update\n");
     193  fprintf (stderr, "  -params\n");
     194  fprintf (stderr, "  -mosaic (mosaic)\n");
     195  fprintf (stderr, "  -imfreeze\n");
     196  fprintf (stderr, "  -grid\n");
     197  fprintf (stderr, "  -area Xmin Xmax Ymin Ymax\n");
     198  fprintf (stderr, "  -instmag min max\n");
     199  fprintf (stderr, "  \n");
     200  exit (2);
     201}
  • trunk/Ohana/src/relastro/src/bcatalog.c

    r6808 r8390  
    11# include "relphot.h"
    22
    3 int bcatalog (Catalog *subcatalog, Catalog *catalog, GSCRegion *fullregion) {
     3int bcatalog (Catalog *subcatalog, Catalog *catalog) {
    44 
    55  int i, j, offset, ecode;
     
    1818  for (i = 0; i < catalog[0].Naverage; i++) {
    1919    if (catalog[0].average[i].Nm < 2) continue;
     20
     21    /* XXX this limitation is absurd
    2022    if (catalog[0].average[i].R < fullregion[0].RA[0]) continue;
    2123    if (catalog[0].average[i].R > fullregion[0].RA[1]) continue;
    2224    if (catalog[0].average[i].D < fullregion[0].DEC[0]) continue;
    2325    if (catalog[0].average[i].D > fullregion[0].DEC[1]) continue;
     26    */
    2427
    2528    /* start with all stars good */
  • trunk/Ohana/src/relastro/src/initialize.c

    r6808 r8390  
    33void initialize (int argc, char **argv) {
    44
    5   /* are these set correctly? */
     5  int N;
     6
    67  ConfigInit (&argc, argv);
    78  args (argc, argv);
    89
    9   if ((photcode = GetPhotcodebyName (argv[2])) == NULL) {
    10     fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", argv[2]);
     10  N = UserPatchSelect ? 1 : 2;
     11  if ((photcode = GetPhotcodebyName (argv[N])) == NULL) {
     12    fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", argv[N]);
    1113    exit (1);
    1214  }
    1315  if ((photcode[0].type != PHOT_PRI) && (photcode[0].type != PHOT_SEC)) {
    14     fprintf (stderr, "photcode %s is not a primary or secondary filter\n", argv[2]);
     16    fprintf (stderr, "photcode %s is not a primary or secondary filter\n", argv[N]);
    1517    exit (1);
    1618  }
  • trunk/Ohana/src/relastro/src/load_catalogs.c

    r6808 r8390  
    11# include "relphot.h"
    22
    3 Catalog *load_catalogs (GSCRegion *region, int Nregion, GSCRegion *fullregion) {
     3Catalog *load_catalogs (SkyList *skylist, int *Ncatalog) {
    44
    55  int i, Nstar;
    6   char filename[256];
    76  Catalog *catalog, tcatalog;
    87
    98  if (VERBOSE) fprintf (stderr, "loading catalog data\n");
    109
    11   ALLOCATE (catalog, Catalog, Nregion);
     10  ALLOCATE (catalog, Catalog, skylist[0].Nregions);
    1211
    13   /* load data from each region file, only use bright stars */
    14   for (i = 0; i < Nregion; i++) {
    15     sprintf (filename, "%s/%s", CATDIR, region[i].filename);
    16     tcatalog.filename = filename;  /* don't free region before catalog! */
    17     switch (lock_catalog (&tcatalog, LCK_SOFT)) {
    18     case 0:
    19       fprintf (stderr, "ERROR: can't lock file %s\n", region[i].filename);
    20       exit (1);
    21     case 1:
    22       gcatalog (&tcatalog, FALSE); /* load from disk */
    23       break;
    24     case 2:
    25       if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", tcatalog.filename);
    26       tcatalog.Naverage = 0;
    27       tcatalog.Nmeasure = 0;
    28       break;
    29     default:
    30       fprintf (stderr, "weird lock_catalog exit state\n");
     12  // load data from each region file, only use bright stars
     13  for (i = 0; i < skylist[0].Nregions; i++) {
     14
     15    // set up the basic catalog info
     16    tcatalog.filename = skylist[0].filename[i];
     17    tcatalog.catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
     18    tcatalog.catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
     19    tcatalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_SECF; // don't need to load all data at this point
     20
     21    if (!dvo_catalog_open (&tcatalog, skylist[0].regions[i], VERBOSE, "r")) {
     22      fprintf (stderr, "ERROR: failure reading catalog %s\n", tcatalog.filename);
    3123      exit (1);
    3224    }
    33     bcatalog (&catalog[i], &tcatalog, fullregion);
     25    if (VERBOSE && !tcatalog.Nave_disk) fprintf (stderr, "no data in %s, skipping\n", tcatalog.filename);
     26
     27    // select only the brighter stars
     28    bcatalog (&catalog[i], &tcatalog);
     29    dvo_catalog_unlock (&tcatalog);
     30    dvo_catalog_free (&tcatalog);
    3431  }
    3532
     33  // XXX keep this test?
    3634  Nstar = 0;
    37   for (i = 0; i < Nregion; i++) {
     35  for (i = 0; i < skylist[0].Nregions; i++) {
    3836    Nstar += catalog[i].Naverage;
    3937  }
     
    4240    exit (0);
    4341  }
     42
     43  // XXX consider only returning the populated catalogs
     44  *Ncatalog = skylist[0].Nregions;
    4445  return (catalog);
    4546}
     47
     48/* this function loads all relevant catalog files for the first pass.  it currently loads the data
     49   read only (SOFT lock) since it assumes the image table has been locked. if we go to the new
     50   addstar locking paradigm, in which the images and catalogs are updated independently, then we may
     51   need to use an XCLD lock here. 
     52*/
  • trunk/Ohana/src/relastro/src/load_images.c

    r7080 r8390  
    11# include "relphot.h"
    22
    3 GSCRegion *load_images (FITS_DB *db, char *seed, int *nregion, GSCRegion *fullregion) {
     3SkyList *load_images (FITS_DB *db, char *regionName, SkyRegion *region, int RegionSelect) {
    44
    5   GSCRegion *region;
    6   int        Nregion;
    7   Image     *image;
    8   int       *Line;
    9   int        Nimage;
     5  Image     *image, *subset;
     6  int        Nimage, Nsubset, Nchar;
     7  int       *LineNumber;
    108
    11   /* read entire db table */
    12   if (!dvo_image_load (db, VERBOSE, FALSE)) Shutdown ("can't read image catalog %s", db[0].filename);
     9  SkyTable *sky = NULL;
     10  SkyList *skylist = NULL;
    1311
    14   region = name_region (seed, &Nregion);
     12  // load the current sky table (layout of all SkyRegions)
     13  sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, SKY_DEPTH, VERBOSE);
     14  SkyTableSetFilenames (sky, CATDIR, "cpt");
     15 
     16  // determine the populated SkyRegions overlapping the requested area
     17  if (RegionSelect) {
     18    skylist = SkyListByPatch (sky, -1, region);
     19  } else {
     20    Nchar = strlen(regionName);
     21    if (!strcmp (&regionName[Nchar-4], ".cpt")) regionName[Nchar-4] = 0;
     22    skylist = SkyListByName (sky, regionName);
     23  }
    1524
    16   /* find images which supplied all measurements */
    17   image = find_images (db, region, Nregion, &Nimage, &Line);
    18   free (Line);
     25  // convert database table to internal structure
     26  image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
    1927
    20   /* find all region files which touch images */
    21   region = find_regions (image, Nimage, &Nregion, fullregion);
    22   free (image);
     28  // select the images which overlap the selected sky regions
     29  subset = select_images (skylist, image, Nimage, &LineNumber, &Nsubset);
    2330
    24   /* find images which supplied all measurements for all regions */
    25   image = find_images (db, region, Nregion, &Nimage, &Line);
    26   getfullregion (image, Nimage, fullregion);
     31  gfits_vtable_from_ftable (&db[0].ftable, &db[0].vtable, LineNumber, Nsubset);
    2732
    28   gfits_vtable_from_ftable (&db[0].ftable, &db[0].vtable, Line, Nimage);
    29 
    30   initImages (image, Nimage);
    31   initMosaics (image, Nimage);
     33  initImages (subset, Nsubset);
     34  initMosaics (subset, Nsubset);
    3235 
    33   *nregion = Nregion;
    34   return (region);
     36  return (skylist);
    3537}
  • trunk/Ohana/src/relastro/src/reload_catalogs.c

    r6808 r8390  
    11# include "relphot.h"
    22
    3 void reload_catalogs (GSCRegion *region, int Nregion, GSCRegion *fullregion) {
     3void reload_catalogs (SkyList *skylist) {
    44
    55  int i;
    6   char filename[256];
     6  int status;
     7  struct stat filestat;
    78  Catalog catalog;
    89
     
    1011
    1112  /* load data from each region file */
    12   for (i = 0; i < Nregion; i++) {
    13     sprintf (filename, "%s/%s", CATDIR, region[i].filename);
    14     catalog.filename = filename;  /* don't free region before catalog! */
    15     switch (lock_catalog (&catalog, LCK_XCLD)) {
    16     case 0:
    17       fprintf (stderr, "ERROR: can't lock file %s\n", region[i].filename);
    18       exit (1);
    19     case 1:
    20       gcatalog (&catalog, TRUE); /* load from disk */
    21       break;
    22     case 2:
    23       if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    24       unlock_catalog (&catalog);
     13  for (i = 0; i < skylist[0].Nregions; i++) {
     14    catalog.filename = skylist[0].filename[i];
     15
     16    // only update existing db tables
     17    status = stat (catalog.filename, &filestat);
     18    if ((status == -1) && (errno == ENOENT)) {
     19      if (VERBOSE) fprintf (stderr, "no file %s, skipping\n", catalog.filename);
    2520      continue;
    26       break;
    27     default:
    28       fprintf (stderr, "weird lock_catalog exit state\n");
     21    }
     22
     23    catalog.catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
     24    catalog.catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
     25    catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     26
     27    if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "w")) {
     28      fprintf (stderr, "ERROR: failure reading catalog %s\n", catalog.filename);
    2929      exit (1);
    3030    }
     31    if (VERBOSE && (catalog.Nave_disk == 0)) {
     32        fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
     33        dvo_catalog_unlock (&catalog);
     34        dvo_catalog_free (&catalog);
     35        continue;
     36    }
     37
    3138    initImageBins  (&catalog, 1);
    3239    initMosaicBins (&catalog, 1);
     
    3744
    3845    setMrelFinal (&catalog);
    39     wcatalog (&catalog);
    40     unlock_catalog (&catalog);
     46    dvo_catalog_save (&catalog, VERBOSE);
     47    dvo_catalog_unlock (&catalog);
     48    dvo_catalog_free (&catalog);
    4149
    4250    freeImageBins (1);
  • trunk/Ohana/src/relastro/src/relphot.c

    r6808 r8390  
    11# include "relphot.h"
    2 /** I'm not currently setting the lockfiles.  this should be fixed! **/
    32
    43int main (int argc, char **argv) {
     
    65  int i, status, Ncatalog;
    76  Catalog *catalog;
    8   GSCRegion fullregion, *region;
    97  FITS_DB db;
     8
     9  SkyList *skylist = NULL;
    1010
    1111  /* get configuration info, args */
    1212  initialize (argc, argv);
    1313
     14  /* register database handle with shutdown procedure */
    1415  set_db (&db);
     16
     17  /* lock and load the image db table */
    1518  status = dvo_image_lock (&db, ImageCat, 60.0, (UPDATE ? LCK_XCLD : LCK_SOFT));
    1619  if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename);
    1720  if (db.dbstate == LCK_EMPTY) Shutdown ("ERROR: No images in catalog %s (1)", db.filename);
     21  if (!dvo_image_load (&db, VERBOSE, FALSE)) Shutdown ("can't read image catalog %s", db.filename);
    1822
    19   /* load regions and images based on seed region */
    20   // XXX EAM : load images and regions based on bounds, not name
    21   region = load_images (&db, argv[1], &Ncatalog, &fullregion);
     23  /* load regions and images based on specified sky patch */
     24  // XXX need to mimic old-style load by passing patch name
     25  // XXX need to reduce number of global variables in use.
     26  // XXX this is fairly lame: argv[1] is photcode if UserPatchSelect is true
     27  skylist = load_images (&db, argv[1], &UserPatch, UserPatchSelect);
     28
     29  /* unlock, if we can (else, unlocked below) */
    2230  if (!UPDATE) dvo_image_unlock (&db);
    2331
    2432  /* load catalog data from region files */
    25   catalog = load_catalogs (region, Ncatalog, &fullregion);
     33  catalog = load_catalogs (skylist, &Ncatalog);
    2634
    2735  /* match measurements with images, mosaics */
     
    8088
    8189  /* at this point, we have correct cal coeffs in the image/mosaic structures */
    82   free_catalogs (catalog, Ncatalog);
     90  for (i = 0; i < Ncatalog; i++) dvo_catalog_free (&catalog[i]);
    8391  freeImageBins (Ncatalog);
    8492  freeMosaicBins (Ncatalog);
     
    8694
    8795  /* load catalog data from region files, update Mrel include all data */
    88   reload_catalogs (region, Ncatalog, &fullregion);
     96  reload_catalogs (skylist);
    8997  setMcalFinal ();
    9098  dvo_image_update (&db, VERBOSE);
Note: See TracChangeset for help on using the changeset viewer.