def gregorian_to_ut_mjd(date): '''Convert Gregorian calendar date to UTC MJD.''' # Do the date part caldj_error = { 0: 'OK', 1: 'bad year (MJD not computed)', 2: 'bad month (MJD not computed)', 3: 'bad day (MJD not computed)', } caldj_status = 0 mjd, caldj_status = sla.sla_caldj(date.year, date.month, date.day) if caldj_status != 0: raise InvalidDateTimeError('Error:' + caldj_error[caldj_status]) # Do the time part dtf2d_error = { 0: 'OK', 1: 'IHOUR outside range 0-23', 2: 'IMIN outside range 0-59', 3: 'SEC outside range 0-59.999 ', } dtf2d_status = 0 days, dtf2d_status = sla.sla_dtf2d(date.hour, date.minute, date.second + (date.microsecond / 1e6)) if dtf2d_status != 0: raise InvalidDateTimeError('Error:' + dtf2d_error[dtf2d_status]) mjd += days return mjd
def import_from_catalogs(db, det_tabname, exp_tabname, catalog_files, create=False, all=False): """ Import a PTF catalog from a collection of SExtractor catalog files. Note: Assumes underlying shared storage for all output table cells (i.e., any worker is able to write to any cell). """ with locking.lock(db.path[0] + "/.__smf-import-lock.lock"): if not db.table_exists(det_tabname) and create: # Set up commit hooks exp_table_def["commit_hooks"] = [("Updating neighbors", 1, "lsd.smf", "make_image_cache", [det_tabname])] # Create new tables det_table = db.create_table(det_tabname, det_table_def) exp_table = db.create_table(exp_tabname, exp_table_def) # Set up a one-to-X join relationship between the two tables (join det_table:exp_id->exp_table:exp_id) db.define_default_join( det_tabname, exp_tabname, type="indirect", m1=(det_tabname, "det_id"), m2=(det_tabname, "exp_id") ) else: det_table = db.table(det_tabname) exp_table = db.table(exp_tabname) # MJD of import now = datetime.datetime.now() (djm, j) = sla_caldj(now.year, now.month, now.day) djm -= 55682 t0 = time.time() at = 0 ntot = 0 pool = pool2.Pool() explist_file = open("explist.txt", "w") for (file, nloaded, error_type, expID) in pool.imap_unordered( catalog_files, import_from_catalogs_aux, (det_table, exp_table, djm, all), progress_callback=pool2.progress_pass ): at = at + 1 ntot = ntot + nloaded t1 = time.time() time_pass = (t1 - t0) / 60 time_tot = time_pass / at * len(catalog_files) # sfile = (file)[-65:] if len(file) > 70 else file sfile = file if error_type == 0: print ( " ===> Imported %s [%d/%d, %5.2f%%] +%-6d %9d (%.0f/%.0f min.)" % ( sfile, at, len(catalog_files), 100 * float(at) / len(catalog_files), nloaded, ntot, time_pass, time_tot, ) ) explist_file.write("%s\n" % str(expID)) elif error_type == 1: print ("%s is missing!" % (sfile)) elif error_type == 2: print ("%s has bad data type in exposure database!" % (sfile)) elif error_type == 3: print ("%s has bad data type in detection database!" % (sfile)) elif error_type == 4: print ("%s has bad WCS transform parameters!" % (sfile)) else: print "Nothing" # show the dirt every 100 ingests # if at % 100. == 0: # gc.collect() # n_collected = gc.collect() # if n_collected > 0: # dump_garbage() del pool explist_file.close()
def calc_jd_utc(self): h = time.gmtime() ret = slalib.sla_caldj(h.tm_year, h.tm_mon, h.tm_mday) # ret[0] = MJD jd_utc = ret[ 0] + 2400000.5 + h.tm_hour / 24.0 + h.tm_min / 1440.0 + h.tm_sec / 86400.0 return jd_utc
# ) # ra.append(math.degrees(r1)) # dec.append(math.degrees(d1)) # #with open("slalib_hip_map.txt", "w") as f: # f.write("# Apparent RA DEC for J2000.0 in degrees.\n") # for r, d in zip(ra, dec): # s = "%14.9f %14.9f\n" # f.write(s % (r, d)) # sla_aop # Convert apparent to observed place. tab['pma'] = np.radians(tab['pma'] / 3600.0) / 100.0 tab['pmd'] = np.radians(tab['pmd'] / 3600.0) / 100.0 utc = slalib.sla_caldj(2010, 1, 1)[0] tt = slalib.sla_dtt(utc) / 86400.0 + utc dut = 1.4823561643834426 # from TPM. aob = np.zeros((len(tab['raj2']), ), dtype=np.float64) zob = aob.copy() hob = aob.copy() dob = aob.copy() rob = aob.copy() lon = np.radians(-111.598333) lat = np.radians(31.956389) for j, i in enumerate(tab): r1, d1 = slalib.sla_map(i['raj2'], i['decj2'], i['pma'], i['pmd'], i['px'], 0.0, 2000.0, tt) aob[j], zob[j], hob[j], dob[j], rob[j] = \
def calc_jd_utc(self): h = time.gmtime() ret = slalib.sla_caldj(h.tm_year, h.tm_mon, h.tm_mday) # ret[0] = MJD jd_utc = ret[0]+2400000.5+h.tm_hour/24.0+h.tm_min/1440.0+h.tm_sec/86400.0 return jd_utc