Skip to content

Commit ea6b64e

Browse files
kikocorreosokikocorreosoterraputix
authored
refactor: Use a valid date and time and avoid the need for user changes in the examples (#94)
Co-authored-by: kikocorreoso <kiko@example.com> Co-authored-by: terraputix <terraputix@mailbox.org>
1 parent 47bee22 commit ea6b64e

7 files changed

Lines changed: 63 additions & 21 deletions

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,27 @@ reader.close() # Close the reader to release resources
5555
### Reading Hierarchical Files, e.g. S3 Spatial Files
5656

5757
```python
58+
import datetime as dt
59+
5860
import fsspec
5961
import numpy as np
6062
from omfiles import OmFileReader
6163

6264
# Example: URI for a spatial data file in the `data_spatial` S3 bucket
6365
# See data organization details: https://github.com/open-meteo/open-data?tab=readme-ov-file#data-organization
64-
# Note: Spatial data is only retained for 7 days. The example file below may no longer exist.
65-
# Please update the URI to match a currently available file.
66-
s3_uri = "s3://openmeteo/data_spatial/dwd_icon/2025/09/23/0000Z/2025-09-30T0000.om"
66+
MODEL_DOMAIN = "dwd_icon"
67+
# Note: Spatial data is only retained for 7 days. The script uses one file within this period.
68+
date_time = dt.datetime.now(dt.timezone.utc) - dt.timedelta(days=2)
69+
S3_URI = (
70+
f"s3://openmeteo/data_spatial/{MODEL_DOMAIN}/{date_time.year}/"
71+
f"{date_time.month:02}/{date_time.day:02}/0000Z/"
72+
f"{date_time.strftime('%Y-%m-%d')}T0000.om"
73+
)
74+
print(f"Using om file: {S3_URI}")
6775

6876
# Create and open filesystem, wrapping it in a blockcache
6977
backend = fsspec.open(
70-
f"blockcache::{s3_uri}",
78+
f"blockcache::{S3_URI}",
7179
mode="rb",
7280
s3={"anon": True, "default_block_size": 65536}, # s3 settings
7381
blockcache={"cache_storage": "cache"}, # blockcache settings

examples/plot_map.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
# ]
1010
# ///
1111

12+
import datetime as dt
13+
1214
import cartopy.crs as ccrs
1315
import cartopy.feature as cfeature
1416
import fsspec
@@ -21,10 +23,14 @@
2123
VARIABLE = "relative_humidity_2m"
2224
# Example: URI for a spatial data file in the `data_spatial` S3 bucket
2325
# See data organization details: https://github.com/open-meteo/open-data?tab=readme-ov-file#data-organization
24-
# Note: Spatial data is only retained for 7 days. The example file below may no longer exist.
25-
# Please update the URI to match a currently available file.
26-
S3_URI = f"s3://openmeteo/data_spatial/{MODEL_DOMAIN}/2026/01/10/0000Z/2026-01-12T0000.om"
27-
26+
# Note: Spatial data is only retained for 7 days. The script uses one file within this period.
27+
date_time = dt.datetime.now(dt.timezone.utc) - dt.timedelta(days=2)
28+
S3_URI = (
29+
f"s3://openmeteo/data_spatial/{MODEL_DOMAIN}/{date_time.year}/"
30+
f"{date_time.month:02}/{date_time.day:02}/0000Z/"
31+
f"{date_time.strftime('%Y-%m-%d')}T0000.om"
32+
)
33+
print(f"Using om file: {S3_URI}")
2834
backend = fsspec.open(
2935
f"blockcache::{S3_URI}",
3036
mode="rb",

examples/readme_example.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
# ]
88
# ///
99

10+
import datetime as dt
11+
1012
import fsspec
1113
import numpy as np
1214
from omfiles import OmFileReader
@@ -15,10 +17,14 @@
1517
VARIABLE = "temperature_2m"
1618
# Example: URI for a spatial data file in the `data_spatial` S3 bucket
1719
# See data organization details: https://github.com/open-meteo/open-data?tab=readme-ov-file#data-organization
18-
# Note: Spatial data is only retained for 7 days. The example file below may no longer exist.
19-
# Please update the URI to match a currently available file.
20-
S3_URI = f"s3://openmeteo/data_spatial/{MODEL_DOMAIN}/2026/01/10/0000Z/2026-01-12T0000.om"
21-
20+
# Note: Spatial data is only retained for 7 days. The script uses one file within this period.
21+
date_time = dt.datetime.now(dt.timezone.utc) - dt.timedelta(days=2)
22+
S3_URI = (
23+
f"s3://openmeteo/data_spatial/{MODEL_DOMAIN}/{date_time.year}/"
24+
f"{date_time.month:02}/{date_time.day:02}/0000Z/"
25+
f"{date_time.strftime('%Y-%m-%d')}T0000.om"
26+
)
27+
print(f"Using om file: {S3_URI}")
2228
# Create and open filesystem, wrapping it in a blockcache
2329
backend = fsspec.open(
2430
f"blockcache::{S3_URI}",

examples/regrid_ecmwf_ifs_hres_gaussian_O1280_to_0.1_degree.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
# ]
1111
# ///
1212

13+
import datetime as dt
14+
1315
import cartopy.crs as ccrs
1416
import cartopy.feature as cfeature
1517
import fsspec
@@ -22,9 +24,14 @@
2224
VARIABLE = "temperature_2m"
2325
# Example: URI for a spatial data file in the `data_spatial` S3 bucket
2426
# See data organization details: https://github.com/open-meteo/open-data?tab=readme-ov-file#data-organization
25-
# Note: Spatial data is only retained for 7 days. The example file below may no longer exist.
26-
# Please update the URI to match a currently available file.
27-
S3_URI = f"s3://openmeteo/data_spatial/{MODEL_DOMAIN}/2026/01/10/0000Z/2026-01-12T0000.om"
27+
# Note: Spatial data is only retained for 7 days. The script uses one file within this period.
28+
date_time = dt.datetime.now(dt.timezone.utc) - dt.timedelta(days=2)
29+
S3_URI = (
30+
f"s3://openmeteo/data_spatial/{MODEL_DOMAIN}/{date_time.year}/"
31+
f"{date_time.month:02}/{date_time.day:02}/0000Z/"
32+
f"{date_time.strftime('%Y-%m-%d')}T0000.om"
33+
)
34+
print(f"Using om file: {S3_URI}")
2835

2936
backend = fsspec.open(
3037
f"blockcache::{S3_URI}",

examples/regrid_subset_of_projected_domain.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
# ]
1111
# ///
1212

13+
import datetime as dt
14+
1315
import cartopy.crs as ccrs
1416
import cartopy.feature as cfeature
1517
import fsspec
@@ -23,9 +25,14 @@
2325
VARIABLE = "temperature_2m"
2426
# Example: URI for a spatial data file in the `data_spatial` S3 bucket
2527
# See data organization details: https://github.com/open-meteo/open-data?tab=readme-ov-file#data-organization
26-
# Note: Spatial data is only retained for 7 days. The example file below may no longer exist.
27-
# Please update the URI to match a currently available file.
28-
S3_URI = f"s3://openmeteo/data_spatial/{MODEL_DOMAIN}/2026/01/17/0000Z/2026-01-19T0000.om"
28+
# Note: Spatial data is only retained for 7 days. The script uses one file within this period.
29+
date_time = dt.datetime.now(dt.timezone.utc) - dt.timedelta(days=2)
30+
S3_URI = (
31+
f"s3://openmeteo/data_spatial/{MODEL_DOMAIN}/{date_time.year}/"
32+
f"{date_time.month:02}/{date_time.day:02}/0000Z/"
33+
f"{date_time.strftime('%Y-%m-%d')}T0000.om"
34+
)
35+
print(f"Using om file: {S3_URI}")
2936

3037
LON_MIN = -130.0
3138
LON_MAX = -100.0

examples/select_by_coordinates.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,4 @@
110110

111111
# Save the figure
112112
plt.savefig(f"{VARIABLE}_comparison.png", dpi=300)
113+
print(f"\nPlot saved as: {VARIABLE}_comparison.png")

examples/spatial_xarray.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
# ]
1010
# ///
1111

12+
import datetime as dt
13+
1214
import cartopy.crs as ccrs
1315
import cartopy.feature as cfeature
1416
import fsspec
@@ -22,9 +24,14 @@
2224

2325
# Example: URI for a spatial data file in the `data_spatial` S3 bucket
2426
# See data organization details: https://github.com/open-meteo/open-data?tab=readme-ov-file#data-organization
25-
# Note: Spatial data is only retained for 7 days. The example file below may no longer exist.
26-
# Please update the URI to match a currently available file.
27-
S3_URI = f"s3://openmeteo/data_spatial/{MODEL_DOMAIN}/2026/01/10/0000Z/2026-01-12T0000.om"
27+
# Note: Spatial data is only retained for 7 days. The script uses one file within this period.
28+
date_time = dt.datetime.now(dt.timezone.utc) - dt.timedelta(days=2)
29+
S3_URI = (
30+
f"s3://openmeteo/data_spatial/{MODEL_DOMAIN}/{date_time.year}/"
31+
f"{date_time.month:02}/{date_time.day:02}/0000Z/"
32+
f"{date_time.strftime('%Y-%m-%d')}T0000.om"
33+
)
34+
print(f"Using om file: {S3_URI}")
2835

2936
backend = fsspec.open(
3037
f"blockcache::{S3_URI}",

0 commit comments

Comments
 (0)