forked from blaylockbk/Herbie
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_hrdps.py
More file actions
76 lines (60 loc) · 1.69 KB
/
Copy pathtest_hrdps.py
File metadata and controls
76 lines (60 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
## Nikhil Shankar
## August 10, 2025
"""
Tests for downloading HRDPS model.
DRAGONS:
At ~00Z the HRDPS servers are cleared of the previous day's forecasts.
The next forecast arrives at ~06Z. During the interim period these tests will fail.
"""
from datetime import datetime
import pandas as pd
from herbie import Herbie, config
now = datetime.now()
latest = pd.Timestamp("now").floor("6h") - pd.Timedelta("6h")
save_dir = config["default"]["save_dir"] / "Herbie-Tests-Data/"
# Remove all previous test data
for i in (save_dir / "hrdps").rglob("*"):
if i.is_file():
i.unlink()
def test_hrdps_download():
H = Herbie(
latest,
model="hrdps",
product="continental/2.5km",
variable="TMP",
level="AGL-2m",
overwrite=True,
save_dir=save_dir,
)
f = H.download()
assert H.get_localFilePath().exists()
f.unlink()
def test_hrdps_xarray():
H = Herbie(
latest,
model="hrdps",
product="continental/2.5km",
variable="TMP",
level="AGL-2m",
overwrite=True,
save_dir=save_dir,
)
H.xarray(remove_grib=False)
assert H.get_localFilePath().exists()
H.get_localFilePath().unlink()
def test_hrdps_to_netcdf():
"""Check that a xarray Dataset can be written to a NetCDF file.
It is important that I have haven't put any python objects in the
xarray Dataset attributes.
"""
H = Herbie(
latest,
model="hrdps",
product="continental/2.5km",
variable="TMP",
level="AGL-2m",
overwrite=True,
save_dir=save_dir,
)
ds = H.xarray(remove_grib=False)
ds.to_netcdf(save_dir / "test_hrdps_to_netcdf.nc")