Skip to content

Commit 85af470

Browse files
committed
Add data pipeline example for efficient weather data handling
1 parent 4c5d883 commit 85af470

58 files changed

Lines changed: 1572 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/data_pipeline/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Data Pipeline Example for Weather Routing Tool
2+
3+
This example demonstrates how to efficiently handle and process weather datasets using scalable techniques.
4+
5+
## Overview
6+
7+
Working with large weather datasets can be memory-intensive and slow when using traditional loading methods. This example shows how to improve performance and scalability by using:
8+
9+
- Chunked data loading with Dask
10+
- Subsetting and interpolation
11+
- Efficient storage formats (NetCDF and Zarr)
12+
- Basic performance comparison
13+
14+
## Features
15+
16+
- Load dataset using chunking (`xarray + Dask`)
17+
- Subset a specific geographic region
18+
- Interpolate data at a given location
19+
- Save processed data in:
20+
- NetCDF format
21+
- Zarr format
22+
- Compare execution time for different storage methods
23+
24+
## File Structure

examples/data_pipeline/analysis.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import xarray as xr
2+
import time
3+
import os
4+
5+
# -------------------------------
6+
# LOAD DATASET WITH CHUNKING
7+
# -------------------------------
8+
print("\n--- Loading Dataset ---")
9+
ds = xr.open_dataset("weather.nc", chunks={"time": 10})
10+
11+
print(ds)
12+
13+
# -------------------------------
14+
# SUBSETTING REGION
15+
# -------------------------------
16+
ds = ds.sel(
17+
latitude=slice(10, 20),
18+
longitude=slice(80, 90)
19+
)
20+
21+
print("\n--- After Subsetting ---")
22+
print(ds)
23+
24+
# -------------------------------
25+
# INTERPOLATION
26+
# -------------------------------
27+
ds = ds.interp(latitude=15, longitude=85)
28+
29+
print("\n--- After Interpolation ---")
30+
print(ds)
31+
32+
# -------------------------------
33+
# SAVE AS NETCDF
34+
# -------------------------------
35+
print("\n--- Saving as NetCDF ---")
36+
start = time.time()
37+
38+
ds.to_netcdf("output.nc")
39+
40+
end = time.time()
41+
netcdf_time = end - start
42+
43+
print("NetCDF Save Time:", netcdf_time, "seconds")
44+
45+
# -------------------------------
46+
# SAVE AS ZARR
47+
# -------------------------------
48+
print("\n--- Saving as Zarr ---")
49+
start = time.time()
50+
51+
ds.to_zarr("output.zarr", mode="w")
52+
53+
end = time.time()
54+
zarr_time = end - start
55+
56+
print("Zarr Save Time:", zarr_time, "seconds")
57+
58+
# -------------------------------
59+
# FILE SIZE (NetCDF)
60+
# -------------------------------
61+
if os.path.exists("output.nc"):
62+
nc_size = os.path.getsize("output.nc") / (1024 * 1024)
63+
print("\nNetCDF File Size:", round(nc_size, 2), "MB")
64+
65+
# -------------------------------
66+
# VARIABLES INFO
67+
# -------------------------------
68+
print("\n--- Dataset Variables ---")
69+
print(list(ds.data_vars))
70+
71+
72+
print("\n--- Performance Summary ---")
73+
print("NetCDF Time:", netcdf_time, "seconds")
74+
print("Zarr Time:", zarr_time, "seconds")
75+
76+
if zarr_time < netcdf_time:
77+
print("Zarr is faster for this dataset")
78+
else:
79+
print("NetCDF is faster for this dataset")
80+
81+
print("\n✔ Data pipeline example completed successfully")

examples/data_pipeline/output.nc

19.4 KB
Binary file not shown.
24 Bytes
Binary file not shown.
24 Bytes
Binary file not shown.
29 Bytes
Binary file not shown.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"shape": [
3+
25
4+
],
5+
"data_type": "float64",
6+
"chunk_grid": {
7+
"name": "regular",
8+
"configuration": {
9+
"chunk_shape": [
10+
10
11+
]
12+
}
13+
},
14+
"chunk_key_encoding": {
15+
"name": "default",
16+
"configuration": {
17+
"separator": "/"
18+
}
19+
},
20+
"fill_value": "NaN",
21+
"codecs": [
22+
{
23+
"name": "bytes",
24+
"configuration": {
25+
"endian": "little"
26+
}
27+
},
28+
{
29+
"name": "zstd",
30+
"configuration": {
31+
"level": 0,
32+
"checksum": false
33+
}
34+
}
35+
],
36+
"attributes": {
37+
"coordinates": "latitude longitude",
38+
"_FillValue": "AAAAAAAA+H8="
39+
},
40+
"dimension_names": [
41+
"time"
42+
],
43+
"zarr_format": 3,
44+
"node_type": "array",
45+
"storage_transformers": []
46+
}
24 Bytes
Binary file not shown.
24 Bytes
Binary file not shown.
28 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)