Skip to content

Commit

Permalink
Added test for correctness of generated datetime-intervals based on f…
Browse files Browse the repository at this point in the history
…ilenames
  • Loading branch information
notger committed Apr 18, 2022
1 parent 635facf commit 471e919
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
6 changes: 3 additions & 3 deletions tests/disabled_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ def test_save_dataset_to_zarr(self): # noqa D102
# test function but save_dataset_to_zarr depends on a dataset being loaded,
# we have to reload the dataset here. This means that this test can theoretically
# fail for two reasons: Either the data-loading failed, or the data-saving failed.
cloudmask_dataset = load_cloudmask_to_dataset(
Path(self.cloud_mask_filename), temp_directory=Path(os.getcwd()), area="UK"
rss_dataset, _ = load_native_to_dataset(
Path(self.rss_filename), temp_directory=Path(os.getcwd()), area="UK"
)

zarr_path = os.path.join(os.getcwd(), "tmp.zarr")

save_dataset_to_zarr(
cloudmask_dataset,
rss_dataset,
zarr_path=zarr_path,
compressor_name="bz2",
zarr_mode="w",
Expand Down
35 changes: 34 additions & 1 deletion tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

import pandas as pd

from satip.download import _determine_datetimes_to_download_files, download_eumetsat_data
from satip.download import (
_determine_datetimes_to_download_files,
_get_missing_datetimes_from_list_of_files,
download_eumetsat_data,
)
from satip.utils import format_dt_str


Expand Down Expand Up @@ -49,3 +53,32 @@ def test_determine_datetime_to_download_files(self):
self.assertEqual(datetimes[0][1], pd.to_datetime("2020-03-09 11:58:00"))
self.assertEqual(datetimes[1][0], pd.to_datetime("2020-03-09 11:59:00"))
self.assertEqual(datetimes[1][1], pd.to_datetime("2020-03-10 11:58:00"))

def test_get_missing_datetimes_from_list_of_files(self):
"""Tests padding of datetimes if files present are missing data for given days."""
# Assume we only have two files present, as something went very wrong
# with the download.
filenames = [
"MSG3-SEVI-MSG15-0100-NA-20190308114036.810000000Z-NA.nat",
"MSG3-SEVI-MSG15-0100-NA-20220308133711.810000000Z-NA.nat",
]

# We then expect the function to pad this by adding missing timeranges
# to fill up everything from the beginning to the first day to the timestamp
# of the first day (case A), then everything between both files (case B)
# and finally fill up the rest until the end of the second day (case C).
expected_timestamps = [
(pd.to_datetime("2019-03-08 00:00:00"), pd.to_datetime("2019-03-08 11:40:00")),
(pd.to_datetime("2019-03-08 11:40:00"), pd.to_datetime("2022-03-08 13:37:00")),
(pd.to_datetime("2022-03-08 13:37:00"), pd.to_datetime("2022-03-08 23:58:00")),
]

# Generate the list of missing datetime interval boundaries:
res = _get_missing_datetimes_from_list_of_files(filenames)

for i, interval in enumerate(expected_timestamps):
for b, boundary in enumerate(interval):
# Note that the function returns datetime-objects, but we defined the expected
# values as pd-datetime. Though their str-repr is different, they still pass
# the equality-check when compared for same dates.
self.assertEqual(boundary, res[i][b])

1 comment on commit 471e919

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.






CML watermark

Please sign in to comment.