File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
5860import fsspec
5961import numpy as np
6062from 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
6977backend = 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
Original file line number Diff line number Diff line change 99# ]
1010# ///
1111
12+ import datetime as dt
13+
1214import cartopy .crs as ccrs
1315import cartopy .feature as cfeature
1416import fsspec
2123VARIABLE = "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 } " )
2834backend = fsspec .open (
2935 f"blockcache::{ S3_URI } " ,
3036 mode = "rb" ,
Original file line number Diff line number Diff line change 77# ]
88# ///
99
10+ import datetime as dt
11+
1012import fsspec
1113import numpy as np
1214from omfiles import OmFileReader
1517VARIABLE = "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
2329backend = fsspec .open (
2430 f"blockcache::{ S3_URI } " ,
Original file line number Diff line number Diff line change 1010# ]
1111# ///
1212
13+ import datetime as dt
14+
1315import cartopy .crs as ccrs
1416import cartopy .feature as cfeature
1517import fsspec
2224VARIABLE = "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
2936backend = fsspec .open (
3037 f"blockcache::{ S3_URI } " ,
Original file line number Diff line number Diff line change 1010# ]
1111# ///
1212
13+ import datetime as dt
14+
1315import cartopy .crs as ccrs
1416import cartopy .feature as cfeature
1517import fsspec
2325VARIABLE = "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
3037LON_MIN = - 130.0
3138LON_MAX = - 100.0
Original file line number Diff line number Diff line change 110110
111111# Save the figure
112112plt .savefig (f"{ VARIABLE } _comparison.png" , dpi = 300 )
113+ print (f"\n Plot saved as: { VARIABLE } _comparison.png" )
Original file line number Diff line number Diff line change 99# ]
1010# ///
1111
12+ import datetime as dt
13+
1214import cartopy .crs as ccrs
1315import cartopy .feature as cfeature
1416import fsspec
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
2936backend = fsspec .open (
3037 f"blockcache::{ S3_URI } " ,
You can’t perform that action at this time.
0 commit comments