|
| 1 | +import random |
| 2 | +from datetime import date, timedelta |
| 3 | + |
| 4 | +import numpy as np |
| 5 | + |
| 6 | +from epymorph.adrio import prism |
| 7 | +from epymorph.kit import * |
| 8 | + |
| 9 | + |
| 10 | +def test_prism_data_source(monkeypatch): |
| 11 | + """ |
| 12 | + This canary test fetches one data file from PRISM just to quickly verify that our |
| 13 | + ADRIO implementation appears to be valid still. Naturally caching must be disabled |
| 14 | + for the duration of this test. |
| 15 | +
|
| 16 | + Because this still uses the full ADRIO processing, a test failure may be caused by |
| 17 | + issues not related to the fetching of data. You must rule out other causes by |
| 18 | + running the other PRISM tests, which focus on our logic's handling of the data. |
| 19 | + (The other tests will use cached data to avoid excess stress on PRISM's servers.) |
| 20 | + """ |
| 21 | + monkeypatch.setenv("EPYMORPH_CACHE_DISABLED", "true") |
| 22 | + |
| 23 | + # Pick a random day in 2020 to avoid hitting the same file repeatedly. |
| 24 | + # (2020 was a leap year, so it had 366 days.) |
| 25 | + random_date = date(2020, 1, 1) + timedelta(days=random.randint(0, 365)) # noqa: S311 |
| 26 | + print(f"date_loaded: {random_date}") # noqa: T201 |
| 27 | + |
| 28 | + result = ( |
| 29 | + prism.Temperature(temp_var="Minimum") |
| 30 | + .with_context( |
| 31 | + params={ |
| 32 | + "centroid": np.array([(-112.0777, 33.4482)], dtype=CentroidDType), |
| 33 | + }, |
| 34 | + scope=CustomScope(["PHX"]), |
| 35 | + time_frame=TimeFrame.range(random_date, random_date), |
| 36 | + ) |
| 37 | + .evaluate() |
| 38 | + ) |
| 39 | + assert result.shape == (1, 1) |
| 40 | + assert np.issubdtype(result.dtype, np.float64) |
| 41 | + assert result[0, 0] > 0 |
0 commit comments