Beispiel #1
0
    def get_previous_dataset(self, dataset: xr.Dataset) -> xr.Dataset:
        """Utility method to retrieve the previous set of data for hte same
        datastream as the provided dataset from the DatastreamStorage.

        :param dataset:
            The reference dataset that will be used to search the
            DatastreamStore for prior data.
        :type dataset: xr.Dataset
        :return:
            The previous dataset from the DatastreamStorage if it exists,
            otherwise None.
        :rtype: xr.Dataset
        """
        prev_dataset = None
        start_date, start_time = DSUtil.get_start_time(dataset)
        datastream_name = DSUtil.get_datastream_name(dataset, self.config)

        with self.storage.fetch_previous_file(
            datastream_name, f"{start_date}.{start_time}"
        ) as netcdf_file:
            if netcdf_file:
                prev_dataset = self.storage.handlers.read(
                    file=netcdf_file, name=netcdf_file
                )

        return prev_dataset
Beispiel #2
0
def test_start_time_is_correct(raw_dataset, dataset, config):
    expected = ("20211001", "000000")
    time_definition = config.dataset_definition.get_variable("time")
    assert DSUtil.get_raw_start_time(raw_dataset, time_definition) == expected
    assert DSUtil.get_start_time(dataset) == expected