def prepare_windows(self, nights, horizon=-14., standards=False, outfile=None): """Create a list of observation windows consisting of start-stop times for all dates of observation. Parameters: ----------- nights : A list of the nights and modes ('full','first','second'). horizon : Sun altitude at the start of observing. standards: Add time for taking standards outfile : Output file of observing windows. Returns: -------- observation_windows : Record array of observation windows. """ observatory = obztak.ctio.CTIO() observatory.horizon = str(horizon) sun = ephem.Sun() observation_windows = [] for date, mode in nights: mode = mode.lower().strip() # Afternoon observatory.date = '%s 03:00'%(date) observatory.date = observatory.date + 24. * ephem.hour time_setting = ephem.Date(observatory.previous_setting(sun)) time_rising = ephem.Date(observatory.next_rising(sun)) time_midpoint = ephem.Date(0.5*(time_setting + time_rising)) if mode == 'full': window = [time_setting, time_rising] elif mode == 'first': # Don't do midpoint standards if standards: time_midpoint = time_midpoint - STANDARDS window = [time_setting, time_midpoint] elif mode == 'second': # Don't do midpoint standards if standards: time_midpoint = time_midpoint + STANDARDS window = [time_midpoint, time_rising] else: msg = "Unrecognized mode: '%s'"%mode raise ValueError(msg) window = [datestring(w,0) for w in window] observation_windows.append(window) #dtype=[('UTC_START','S28'),('UTC_END','S28')] #observation_windows = np.rec.fromrecords(observation_windows,dtype=dtype) names=['UTC_START','UTC_END'] observation_windows = np.rec.fromrecords(observation_windows,names=names) if outfile: logging.debug("Writing %s..."%outfile) fileio.rec2csv(outfile,observation_windows) return observation_windows
def write(self, filename, **kwargs): base,ext = os.path.splitext(filename) logging.debug('Writing %s...'%filename) if ext in ('.json'): data = self.to_sispi() fileio.write_json(filename,data,**kwargs) elif ext in ('.csv','.txt'): data = self.to_recarray() fileio.rec2csv(filename,data,**kwargs) else: msg = "Unrecognized file extension: %s"%ext raise IOError(msg)
def write(self, filename, **kwargs): base, ext = os.path.splitext(filename) logging.debug('Writing %s...' % filename) if ext in ('.json'): data = self.to_sispi() fileio.write_json(filename, data, **kwargs) elif ext in ('.csv', '.txt', '.gz'): data = self.to_recarray() fileio.rec2csv(filename, data, **kwargs) elif ext in ('.fits', '.fz', '.gz'): import fitsio data = self.to_recarray() kwargs.setdefault('clobber', True) fitsio.write(filename, data, **kwargs) else: msg = "Unrecognized file extension: %s" % ext raise IOError(msg)
np.random.seed(0) schedule = [] for key,(start,stop,size) in SEMESTERS.items(): if key == '2019A': choice = choose_2019A(data) else: d = data[data['semester'] == key] w = d['weight']/d['weight'].sum() idx = np.random.choice(np.arange(len(d)),size,p=w,replace=False) choice = d[np.sort(idx)] schedule.append(choice) schedule = np.concatenate(schedule) filename = 'delve-schedule.csv' print("Writing schedule %s..."%filename) fileio.rec2csv(filename,schedule) print("Creating windows...") survey = obztak.survey.Survey() nights = [[d['date'].strftime('%Y/%m/%d'),d['half']] for d in schedule] outfile = 'delve-windows-predicted.csv' windows = survey.prepare_windows(nights,outfile=outfile) ################ ### Plotting ### ################ fig = plt.figure() ax1 = fig.add_subplot(111) ax2 = ax1.twiny()
from obztak.utils.fileio import get_datafile, to_csv, read_csv from obztak.utils.database import Database import obztak.delve import datetime import skymap import skymap.survey from status import * filename = EXPOSURES if not os.path.exists(filename): db = Database('db-fnal') db.connect() data = db.query2recarray(QUERY) print("Writing %s..." % filename) fileio.rec2csv(filename, data) else: print("Reading %s..." % filename) data = fileio.csv2rec(filename) good = data[select_good_exposures(data)] guid = np.char.rpartition(good['object'].astype(str), ' ')[:, -1] # Unique fields guid, idx = np.unique(guid, return_index=True) good = good[idx] fields = obztak.delve.DelveFieldArray().load(get_datafile(TARGETS)) fuid = fields.unique_id fields = pd.DataFrame(fields) fields['DONE'] = 0