def load_windows(self, windows=None): """ Load the set of start and stop times for the observation windows. """ if windows is None: windows = self._defaults['windows'] logging.info("Setting default observing windows:\n %s" % windows) if isinstance(windows, basestring): windows = fileio.csv2rec(windows) self.windows = [] for start, end in windows: self.windows.append([ephem.Date(start), ephem.Date(end)]) # Sanity check that observation windows are properly sorted for ii, (start, end) in enumerate(self.windows): msg = 'Observation windows are not properly sorted\n' msg += '%s: %s -- %s' % (get_nite(start), datestr(start), datestr(end)) if (end < start): logging.warn(msg) if ii > 0 and (start < self.windows[ii - 1][1]): logging.warn(msg) logging.debug('Observation Windows:') for start, end in self.windows: logging.debug(' %s: %s UTC -- %s UTC' % (get_nite(start), datestr(start), datestr(end))) logging.debug(30 * '-')
def schedule_survey(self, start=None, end=None, chunk=60, plot=False, mode=None, write=False, dirname=None): """ Schedule the entire survey. Parameters: ----------- start : Start of survey (int or str) end : End of survey (int or str) chunk : The duration of a chunk of exposures (minutes) plot : Dynamically plot the progress after each night mode : Mode of scheduler tactician Returns: -------- scheduled_nites : An ordered dictionary of scheduled nites """ self.scheduled_nites = odict() for tstart, tend in self.windows: if start is not None and ephem.Date(tstart) < ephem.Date(start): continue if end is not None and ephem.Date(tend) > ephem.Date(end): continue #nite = nitestring(tstart) nite = get_nite(tstart) try: chunks = self.schedule_nite(tstart, chunk, clip=True, plot=False, mode=mode) except ValueError as error: ortho.plotField(self.completed_fields[-1:], self.target_fields, self.completed_fields) raise (error) self.scheduled_nites[nite] = chunks if write: self.write_nite(nite, chunks, dirname=dirname) if plot: ortho.plotField(self.completed_fields[-1:], self.target_fields, self.completed_fields) if (raw_input(' ...continue ([y]/n)').lower() == 'n'): import pdb pdb.set_trace() if plot: raw_input(' ...finish... ') return self.scheduled_nites
def plot_progress(outfile=None, **kwargs): defaults = dict(edgecolor='none', s=50, vmin=0, vmax=4, cmap='summer_r') for k, v in defaults.items(): kwargs.setdefault(k, v) fields = FieldArray.load_database() nites = [get_nite(date) for date in fields['DATE']] nite = ephem.Date(np.max(nites)) date = '%d/%02d/%d 00:00:00' % (nite.tuple()[:3]) fig, basemap = makePlot(date=date, moon=False, airmass=False, center=(0, -90), smash=False) proj = basemap.proj(fields['RA'], fields['DEC']) basemap.scatter(*proj, c=fields['TILING'], **kwargs) colorbar = plt.colorbar() colorbar.set_label('Tiling') plt.title('Maglites Coverage (%d/%02d/%d)' % nite.tuple()[:3]) if outfile is not None: plt.savefig(outfile, bbox_inches='tight') return fig, basemap
def schedule_nite(self, date=None, start=None, chunk=60, clip=False, plot=False, mode=None): """ Schedule a night of observing. A `nite` is defined by the day (UTC) at noon local time before observing started. Parameters: ----------- date : The date of the nite to schedule chunk : The duration of a chunk of exposures (minutes) plot : Dynamically plot the progress after each chunk mode : Mode for scheduler tactician Returns: -------- chunks : A list of the chunks generated for the scheduled nite. """ # Create the nite nite = get_nite(date) # Convert chunk to MJD if chunk > 1: chunk = chunk * ephem.minute try: nites = [get_nite(w[0]) for w in self.windows] idx = nites.index(nite) winstart, finish = self.windows[idx] if start is None: start = winstart else: logging.warn("Over-writing nite start time") except (TypeError, ValueError): msg = "Requested nite (%s) not found in windows:\n" % nite msg += '[' + ', '.join([n for n in nites]) + ']' logging.warning(msg) start = date self.observatory.date = date self.observatory.horizon = self.observatory.twilight finish = self.observatory.next_rising(ephem.Sun(), use_center=True) self.observatory.horizon = '0' logging.info("Night start (UTC): %s" % datestr(start)) logging.info("Night finish (UTC): %s" % datestr(finish)) chunks = [] i = 0 while start < finish: i += 1 msg = "Scheduling %s -- Chunk %i" % (start, i) logging.debug(msg) end = start + chunk try: scheduled_fields = self.run(start, end, clip=clip, plot=False, mode=mode) except ValueError: # Write fields even if there is an error #chunks.append(self.scheduled_fields) break if plot: field_select = scheduled_fields[-1:] bmap = ortho.plotField(field_select, self.target_fields, self.completed_fields) if (raw_input(' ...continue ([y]/n)').lower() == 'n'): import pdb pdb.set_trace() chunks.append(scheduled_fields) fieldtime = chunks[-1]['EXPTIME'][ -1] * ephem.second + constants.OVERHEAD start = ephem.Date(chunks[-1]['DATE'][-1]) + fieldtime #start = end if plot: raw_input(' ...finish... ') return chunks