def _get_date(self) -> list: time_first = self.raw_data['time'][0] time_last = self.raw_data['time'][-1] date_first = utils.seconds2date(time_first)[:3] date_last = utils.seconds2date(time_last)[:3] if date_first != date_last: logging.warning('Measurements from different days') return date_first
def screen_by_date(self, expected_date: str) -> None: """Screens incorrect time stamps.""" time_stamps = self.getvar("time") valid_indices = [] for ind, timestamp in enumerate(time_stamps): date = "-".join(utils.seconds2date(timestamp, self.epoch)[:3]) if date == expected_date: valid_indices.append(ind) if not valid_indices: raise ValidTimeStampError general.screen_time_indices(self, valid_indices)
def _validate_date(obj, expected_date: str): if obj.header['_time_reference'] == 0: raise ValueError('Ignoring a file (can not validate non-UTC dates)') inds = [] for ind, timestamp in enumerate(obj.data['time'][:]): date = '-'.join(utils.seconds2date(timestamp)[:3]) if date == expected_date: inds.append(ind) if not inds: raise ValueError('Ignoring a file (time stamps not what expected)') for key in obj.data.keys(): obj.data[key] = obj.data[key][inds] return obj
def screen_time(self, expected_date: str) -> None: """Screens incorrect time stamps.""" time_stamps = self.getvar('time') inds = [] for ind, timestamp in enumerate(time_stamps): date = '-'.join(utils.seconds2date(timestamp, self.epoch)[:3]) if date == expected_date: inds.append(ind) if not inds: raise ValueError('Error: MIRA date differs from expected.') for cloudnet_array in self.data.values(): array = cloudnet_array.data n_time = len(time_stamps) if isinstance(array, np.ndarray ) and array.ndim == 2 and array.shape[0] == n_time: cloudnet_array.data = array[inds, :] self.time = self.time[inds]
def _fetch_time(self) -> np.ndarray: time = self.variables['time'][:] ind = time.argsort() time = time[ind] self.backscatter = self.backscatter[ind, :] if self._expected_date is not None: epoch = utils.get_epoch(self.variables['time'].units) valid_ind = [] for ind, timestamp in enumerate(time): date = '-'.join(utils.seconds2date(timestamp, epoch)[:3]) if date == self._expected_date: valid_ind.append(ind) if not valid_ind: raise ValueError('Error: CHM15k date differs from expected.') time = time[valid_ind] self.backscatter = self.backscatter[valid_ind, :] return utils.seconds2hours(time)
def get_date_and_time(self, epoch: Epoch) -> None: if self.expected_date is not None: self.data = utils.screen_by_time(self.data, epoch, self.expected_date) self.date = utils.seconds2date(self.data["time"][0], epoch=epoch)[:3] self.data["time"] = utils.seconds2hours(self.data["time"])
def _init_mira_date(self) -> List[str]: time_stamps = self.getvar('time') return utils.seconds2date(time_stamps[0], self.epoch)[:3]
def _validate_date(obj, expected_date: str) -> None: for t in obj.data['time'][:]: date_str = '-'.join(utils.seconds2date(t)[:3]) if date_str != expected_date: raise ValueError('Ignoring a file (time stamps not what expected)')
def test_seconds2date(input, result, epoch): assert utils.seconds2date(input, epoch) == result assert result[3:] == utils.seconds2time(input)