Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pyrealm/pmodel/acclimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ def _validate_and_set_datetimes(self, datetimes: NDArray[np.datetime64]) -> None
if spacing < 0:
raise ValueError("Datetime sequence must be increasing")

# Validate that we are dealing indeed with subdaily data
if spacing > np.timedelta64(1, "D"):
raise ValueError(
"The AcclimationModel requires datetimes sampled at daily frequency "
"or faster."
)

# Work out observations by date and look for incomplete dates at the start and
# end of the time sequence
dates = datetimes.astype("datetime64[D]")
Expand Down
1 change: 0 additions & 1 deletion pyrealm/pmodel/pmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,6 @@ def _fit_model(
raise ValueError(
"The daily sampling window has not been set in the AcclimationModel"
)

# * Validate the previous realised values and standardise the internal
# representation as a dictionary.
if previous_realised is None:
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/pmodel/test_acclimation_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@
),
id="Negative timedeltas",
),
pytest.param(
pytest.raises(ValueError),
"The AcclimationModel requires datetimes sampled at daily frequency "
"or faster.",
dict(
datetimes=np.arange(
np.datetime64("2014-06-01 00:00"),
np.datetime64("2014-07-01 00:00"),
np.timedelta64(2, "D"),
dtype="datetime64[s]",
)
),
id="Not subdaily",
),
pytest.param(
pytest.raises(ValueError),
"Datetime spacing is not evenly divisible into a day",
Expand Down