IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 27, 2021, 3:55:13 PM (5 years ago)
Author:
eugene
Message:

consolidate reload_catalogs and relphot_objects; option to supply grid correction in relphot -averages and relphot -apply-offsets

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/relphot.20210521/src/relphot_objects.c

    r41620 r41623  
    66// has been correctly propagated to the measurement, the average will respect that value.
    77
    8 int relphot_objects_parallel (SkyList *sky);
    9 
    108int relphot_objects (SkyList *skylist, int hostID, char *hostpath) {
    119
    12   off_t i;
    13   struct stat filestat;
    14 
    15   Catalog catalog;
     10  FITS_DB db;
    1611
    1712  INITTIME;
    1813
    19   // XXX need to decide how to determine PARALLEL mode...
    20   if (PARALLEL && !hostID) {
    21     relphot_objects_parallel (skylist);
    22     return TRUE;
    23   }
    24 
    25   FITS_DB db;
    26      
    2714  set_db (&db);
    2815  gfits_db_init (&db);
     
    4027  MARKTIME("loaded images: %f sec\n", dtime);
    4128
    42   // XXX can I call reload_catalogs here?
     29  // load grid corrections here (specified by -grid-meanfile)
     30  GridCorrectionLoad (GRID_MEANFILE);
    4331
    44   // load the ZP corrections here
    45   if (SYNTH_ZERO_POINTS) SynthZeroPointsLoad (SYNTH_ZERO_POINTS);
    46 
    47   // load data from each region file, only use bright stars
    48   for (i = 0; i < skylist[0].Nregions; i++) {
    49 
    50     // does this host ID match the desired location for the table?
    51     if (!HostTableTestHost(skylist[0].regions[i], hostID)) continue;
    52 
    53     // set up the basic catalog info
    54     char hostfile[1024];
    55     snprintf (hostfile, 1024, "%s/%s.cpt", hostpath, skylist[0].regions[i]->name);
    56 
    57     dvo_catalog_init (&catalog, TRUE);
    58     catalog.filename    = hostID ? hostfile : skylist[0].filename[i];
    59 
    60     // only update existing db tables
    61     int status = stat (catalog.filename, &filestat);
    62     if ((status == -1) && (errno == ENOENT)) {
    63       if (VERBOSE) fprintf (stderr, "no file %s, skipping\n", catalog.filename);
    64       continue;
    65     }
    66 
    67     catalog.catflags    = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    68     // if we are going to update the format, we should update all tables
    69     if (UPDATE_CATFORMAT) {
    70       catalog.catflags |= DVO_LOAD_LENSING | DVO_LOAD_LENSOBJ | DVO_LOAD_STARPAR | DVO_LOAD_GALPHOT;
    71     }
    72     catalog.Nsecfilt    = GetPhotcodeNsecfilt ();
    73 
    74     if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "w")) {
    75       fprintf (stderr, "ERROR: failure reading catalog %s, skipping\n", catalog.filename);
    76       continue;
    77     }
    78     if (!catalog.Naverage_disk) {
    79       if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    80       dvo_catalog_unlock (&catalog);
    81       dvo_catalog_free (&catalog);
    82       continue;
    83     }
    84 
    85     // reset the calculated average magnitudes (does not affect ubercal-tied measurements or images)
    86     ResetAverageObjects(&catalog);
    87 
    88     populate_tiny_values(&catalog, DVO_TV_MEASURE | DVO_TV_AVERAGE);
    89 
    90     // XXX need to worry about the image subset data
    91     initImageBins  (&catalog, 1, FALSE);
    92     initMosaicBins (&catalog, 1, FALSE);
    93     // XXX reload_catalogs.c calls initTGroupBins here
    94 
    95     initGridBins   ();
    96 
    97     findImages (&catalog, 1, FALSE);
    98     findMosaics (&catalog, 1, FALSE);
    99     // XXX reload_catalogs.c calls findTGroups here
    100 
    101     initMrel (&catalog, 1);
    102     setMrelFinal (&catalog, TRUE);
    103 
    104     // uncomment for extra verbosity
    105     // MARKTIME("setMrelFinal for "OFF_T_FMT" average "OFF_T_FMT" measure : %f sec\n", catalog.Naverage, catalog.Nmeasure, dtime);
    106     // gettimeofday (&startTimer, NULL); // reset timer
    107 
    108     // XXX if we want to have options for setting warp, chip, stack independently, we need to init only the desired ones
    109     // NOTE flatcorr == NULL, but it should have been applied already by setphot
    110 
    111     if (!UPDATE) {
    112       dvo_catalog_unlock (&catalog);
    113       free_tiny_values(&catalog);
    114       dvo_catalog_free (&catalog);
    115       freeImageBins (1, FALSE);
    116       freeMosaicBins (1, FALSE);
    117       freeGridBins ();
    118       continue;
    119     }
    120    
    121     if (VERBOSE) fprintf (stderr, "saving catalog %s\n", catalog.filename);
    122    
    123     struct timeval now;
    124     gettimeofday (&now, (void *) NULL);
    125     char *moddate = ohana_sec_to_date (now.tv_sec);
    126     gfits_modify (&catalog.header, "RELPHOT", "%s", 1, moddate);     
    127     free (moddate);
    128 
    129     // we can optionally convert output format here
    130     // but it would be better to define a dvo crawler program to do this
    131     // catalog.catformat = DVO_FORMAT_PS1_V1;
    132 
    133     // modify the output format as desired (ignore current format on disk)
    134     if (UPDATE_CATFORMAT) {
    135       catalog.catformat = dvo_catalog_catformat (UPDATE_CATFORMAT);
    136     }
    137    
    138     SetProtect (TRUE);
    139     if (!dvo_catalog_save (&catalog, VERBOSE)) { fprintf (stderr, "ERROR: failed to save %s\n", catalog.filename); exit (1); }
    140     if (!dvo_catalog_unlock (&catalog)) { fprintf (stderr, "ERROR: failed to unlock %s\n", catalog.filename); exit (1); }
    141     SetProtect (FALSE);
    142 
    143     free_tiny_values(&catalog);
    144     dvo_catalog_free (&catalog);
    145 
    146     freeImageBins (1, FALSE);
    147     freeMosaicBins (1, FALSE);
    148     freeGridBins ();
    149   }
     32  reload_catalogs (skylist, hostID, hostpath);
    15033
    15134  freeImages(db.ftable.buffer);
     35  freeGridBins ();
     36
    15237  gfits_db_free (&db);
    15338
    15439  return (TRUE);
    15540}
    156 
    157 // CATDIR is supplied globally
    158 # define DEBUG 1
    159 int relphot_objects_parallel (SkyList *sky) {
    160 
    161   // launch the setphot_client jobs to the parallel hosts
    162 
    163   // load the list of hosts
    164   HostTable *table = HostTableLoad (CATDIR, sky->hosts);
    165   if (!table) {
    166     fprintf (stderr, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR);
    167     exit (1);
    168   }   
    169 
    170   if (BOUNDARY_TREE) {
    171     char *tmppath = abspath(BOUNDARY_TREE, DVO_MAX_PATH);
    172     free (BOUNDARY_TREE);
    173     BOUNDARY_TREE = tmppath;
    174   }
    175 
    176   int i;
    177   for (i = 0; i < table->Nhosts; i++) {
    178 
    179     // ensure that the paths are absolute path names
    180     char *tmppath = abspath (table->hosts[i].pathname, DVO_MAX_PATH);
    181     free (table->hosts[i].pathname);
    182     table->hosts[i].pathname = tmppath;
    183 
    184     // options / arguments that can affect relphot_client -update-objects:
    185     // VERBOSE, VERBOSE2
    186     // KEEP_UBERCAL
    187     // RESET (-reset)
    188     // TimeSelect -time
    189     // DophotSelect
    190     // (note that psfQF is applied rigidly at 0.85, as is the galaxy test)
    191     // MAG_LIM
    192     // SIGMA_LIM
    193     // ImagSelect, ImagMin, ImagMax
    194     // MaxDensityUse, MaxDensityValue
    195 
    196     char *command = NULL;
    197     strextend (&command, "relphot_client -update-objects");
    198     strextend (&command, "-hostID %d", table->hosts[i].hostID);
    199     strextend (&command, "-D CATDIR %s", CATDIR);
    200     strextend (&command, "-hostdir %s", table->hosts[i].pathname);
    201     strextend (&command, "-region %f %f %f %f", UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    202     strextend (&command, "-statmode %s", STATMODE);
    203     strextend (&command, "-D CAMERA %s", CAMERA);
    204     strextend (&command, "-D STAR_TOOFEW %d", STAR_TOOFEW);
    205     strextend (&command, "-minerror %f", MIN_ERROR);
    206 
    207     if (VERBOSE)           { strextend (&command, "-v"); }
    208     if (VERBOSE2)          { strextend (&command, "-vv"); }
    209     if (RESET)             { strextend (&command, "-reset"); }
    210     if (RESET_ZEROPTS)     { strextend (&command, "-reset-zpts"); }
    211     if (RESET_FLATCORR)    { strextend (&command, "-reset-flat"); }
    212     if (!KEEP_UBERCAL)     { strextend (&command, "-reset-ubercal"); }
    213     if (PRESERVE_PS1)      { strextend (&command, "-preserve-ps1"); }
    214     if (IS_DIFF_DB)        { strextend (&command, "-is-diff-db"); }
    215     if (UPDATE)            { strextend (&command, "-update"); }
    216     if (UPDATE_CATFORMAT)  { strextend (&command, "-update-catformat %s", UPDATE_CATFORMAT); }
    217     if (BOUNDARY_TREE)     { strextend (&command, "-boundary-tree %s", BOUNDARY_TREE); }
    218     if (SYNTH_ZERO_POINTS) { strextend (&command, "-synthphot-zpts %s", SYNTH_ZERO_POINTS); }
    219     // if (GRID_ZEROPT)       { strextend (&command, "-grid %s", GRID_MEANFILE); }
    220     if (USE_BASIC_CHECK)   { strextend (&command, "-basic-image-search"); }
    221     if (USE_ALL_IMAGES)    { strextend (&command, "-use-all-images"); }
    222     if (USE_MCAL_PSF_FOR_STACK_APER) { strextend (&command, "-use-mcal-psf-for-stack-aper"); }
    223 
    224     if (!(STAGES & STAGE_CHIP))  { strextend (&command, "-skip-chip"); }
    225     if (!(STAGES & STAGE_WARP))  { strextend (&command, "-skip-warp"); }
    226     if (!(STAGES & STAGE_STACK)) { strextend (&command, "-skip-stack"); }
    227 
    228     // if (SET_MREL_VERSION != 1) { strextend (&command, "-set-mrel-version %d", SET_MREL_VERSION); }
    229 
    230     // missing AreaSelect & TimeSelect
    231 
    232     fprintf (stderr, "command: %s\n", command);
    233 
    234     if (PARALLEL_MANUAL) {
    235       free (command);
    236       continue;
    237     }
    238 
    239     if (PARALLEL_SERIAL) {
    240       int status = system (command);
    241       if (status) {
    242         fprintf (stderr, "ERROR running relphot_client\n");
    243         exit (2);
    244       }
    245     } else {
    246       // launch the job on the remote machine (no handshake)
    247       int errorInfo = 0;
    248       int pid = rconnect ("ssh", table->hosts[i].hostname, command, table->hosts[i].stdio, &errorInfo, FALSE);
    249       if (!pid) {
    250         if (DEBUG) fprintf (stderr, "failure to start %s (error %d)\n", table->hosts[i].hostname, errorInfo);
    251         exit (1);
    252       }
    253       table->hosts[i].pid = pid; // save for future reference
    254     }
    255     free (command);
    256   }
    257 
    258   if (PARALLEL_MANUAL) {
    259     fprintf (stderr, "run the relphot_client commands above.  when these are done, hit return\n");
    260     getchar();
    261   }
    262   if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) {
    263     HostTableWaitJobsGetIO (table, __FILE__, __LINE__, VERBOSE);
    264   }
    265 
    266   FreeHostTable (table);
    267   return TRUE;
    268 }     
Note: See TracChangeset for help on using the changeset viewer.