def test_build_plane_time(): start = ac.get_datetime('2012-09-03T01:04:44') end = ac.get_datetime('2012-09-03T03:04:44') exposure = end - start result = ac.build_plane_time(start, end, exposure) assert result is not None, 'expected a value' assert result.bounds is not None, 'expected a bounds value' assert math.isclose(result.exposure, 7199.999999999994), 'wrong exposure value'
def _build_time(row): bounds = CoordBounds1D() start_date = ac.get_datetime(row[3].strip()) end_date = ac.get_datetime(row[4].strip()) start_date.format = 'mjd' end_date.format = 'mjd' exposure = float(ac.get_timedelta_in_s(row[5].strip())) start_ref_coord = RefCoord(0.5, start_date.value) end_ref_coord = RefCoord(1.5, end_date.value) bounds.samples.append(CoordRange1D(start_ref_coord, end_ref_coord)) return bounds, exposure
def _build_time(start, end, tos): bounds = CoordBounds1D() if start is not None and end is not None: start_date = ac.get_datetime(start) start_date.format = 'mjd' end_date = ac.get_datetime(end) end_date.format = 'mjd' start_ref_coord = RefCoord(0.5, start_date.value) end_ref_coord = RefCoord(1.5, end_date.value) bounds.samples.append(CoordRange1D(start_ref_coord, end_ref_coord)) exposure = None if tos is not None: exposure = float(ac.get_timedelta_in_s(tos)) return bounds, exposure
def get_time_refcoord_value(header): dateobs = header[0].get('DATE-OBS') if dateobs is not None: result = ac.get_datetime(dateobs) if result is not None: return result.mjd else: return None
def get_time_axis_val(params): header = params.get('header') uri = params.get('uri') ignore_scheme, ignore_path, f_name = mc.decompose_uri(uri) keyword = 'DATE-OBS' if f_name.startswith('a'): keyword = 'CLOCKVAL' return ac.get_datetime(header.get(keyword))
def get_time_refcoord_value(self, ext): dateobs = self._headers[ext].get('DATE-OBS') if dateobs is not None: result = ac.get_datetime(dateobs) if result is not None: return result.mjd else: return None
def test_get_datetime(): result = ac.get_datetime('2006-12-12T12:12:12') assert result is not None assert result == '2006-12-12 12:12:12.000' result = ac.get_datetime('2006-12-12 12:12:12.001') assert result is not None assert result == '2006-12-12 12:12:12.001' result = ac.get_datetime('2006-12-12') assert result is not None assert result == '2006-12-12 00:00:00.000' # a format that is not understood result = ac.get_datetime('16-Dec-12T01:23:45') assert result is None result = ac.get_datetime(None) assert result is None
def _update_time(plane): logging.debug('Begin _update_time') # dates are from the GMIMS paper The Global Magneto-Ionic Survey: # Polarimetry of the Southern Sky from 300 to 480 MHz # survey = [['2009-09-07', '2009-09-21'], ['2009-11-30', '2009-12-09'], ['2010-02-23', '2010-03-09'], ['2010-06-25', '2010-07-08'], ['2010-08-26', '2010-09-10'], ['2010-11-10', '2010-11-24'], ['2011-02-09', '2011-02-23'], ['2011-10-20', '2011-11-10'], ['2012-02-08', '2012-02-29'], ['2012-06-08', '2012-07-02']] mc.check_param(plane, Plane) samples = [] for ii in survey: start_date = ac.get_datetime(ii[0]) end_date = ac.get_datetime(ii[1]) time_bounds = ac.build_plane_time_sample(start_date, end_date) samples.append(time_bounds) survey_start = ac.get_datetime(survey[0][0]) survey_end = ac.get_datetime(survey[9][1]) interval = ac.build_plane_time_interval(survey_start, survey_end, samples) plane.time = caom_Time(bounds=interval, dimension=1) logging.debug('End _update_time')
def get_skycam_release_date(header): return ac.get_datetime(header.get('CLOCKVAL'))
def get_time_function_val(header): time_string = header.get('DATE-OBS') return ac.get_datetime(time_string)
def get_time_axis_val(self, ext): return ac.get_datetime(self._headers[ext].get('CLOCKVAL'))
def get_release_date(self, ext): return ac.get_datetime(self._headers[ext].get('CLOCKVAL'))
def get_time_axis_val(self, ext): return ac.get_datetime(self._headers[ext].get('DATE-OBS'))
def run(self): """ Uses an iterable with a two-item list: 0 - key - input parameter to a NameBuilder implementation 1 - timestamp - for tracking progress :return: 0 for success, -1 for failure """ self._logger.debug(f'Begin run state for {self._bookmark_name}') if not os.path.exists(os.path.dirname(self._config.progress_fqn)): os.makedirs(os.path.dirname(self._config.progress_fqn)) state = mc.State(self._config.state_fqn) if self._data_source.start_time_ts is None: start_time = state.get_bookmark(self._bookmark_name) else: start_time = self._data_source.start_time_ts # make sure prev_exec_time is type datetime prev_exec_time = mc.increment_time(start_time, 0) exec_time = min( mc.increment_time(prev_exec_time, self._config.interval), self._end_time, ) self._logger.debug( f'Starting at {start_time}, ending at {self._end_time}') result = 0 cumulative = 0 cumulative_correct = 0 if prev_exec_time == self._end_time: self._logger.info( f'Start time is the same as end time {start_time}, stopping.') exec_time = prev_exec_time else: cumulative = 0 result = 0 while exec_time <= self._end_time: self._logger.info( f'Processing from {prev_exec_time} to {exec_time}') save_time = exec_time self._organizer.success_count = 0 entries = self._data_source.get_time_box_work( prev_exec_time, exec_time) num_entries = len(entries) if num_entries > 0: self._logger.info(f'Processing {num_entries} entries.') self._organizer.complete_record_count = num_entries self._organizer.set_log_location() pop_action = entries.pop if isinstance(entries, deque): pop_action = entries.popleft while len(entries) > 0: entry = pop_action() entry_time = ac.get_datetime(entry.entry_ts) result |= self._process_entry(entry.entry_name) save_time = min(entry_time, exec_time) self._finish_run() cumulative += num_entries cumulative_correct += self._organizer.success_count self._record_progress(num_entries, cumulative, start_time, save_time) self._wrap_state_save(state, save_time) if exec_time == self._end_time: # the last interval will always have the exec time # equal to the end time, which will fail the while check # so leave after the last interval has been processed # # but the while <= check is required so that an interval # smaller than exec_time -> end_time will get executed, # so don't get rid of the '=' in the while loop # comparison, just because this one exists break prev_exec_time = exec_time exec_time = min( mc.increment_time(prev_exec_time, self._config.interval), self._end_time) self._reporter.add_entries(cumulative) self._reporter.add_successes(cumulative_correct) self._wrap_state_save(state, exec_time) self._logger.info('==================================================') self._logger.info( f'Done {self._organizer.command_name}, saved state is {exec_time}') self._logger.info( f'{cumulative_correct} of {cumulative} records processed ' f'correctly.') self._logger.info('==================================================') return result