Skip to content

Commit

Permalink
Simplest version of the SST Demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
alxmrs authored Mar 23, 2024
1 parent ec0ab53 commit c63d25e
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions demo/sst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3
"""Demo of calculating global average sea surface temperature (SST) with SQL.
Please run the following to access the ERA5 dataset:
```
gcloud auth application-default login
```
"""
import xarray as xr
import xarray_sql as qr

# TODO(alxmrs): Add coiled or dask cluster code.

era5_ds = xr.open_zarr(
'gs://gcp-public-data-arco-era5/ar/'
'1959-2022-full_37-1h-0p25deg-chunk-1.zarr-v2',
chunks={'time': 240, 'level': 1}
)
print('dataset opened.')
# TODO(alxmrs): Slice to small time range based on script args.
era5_sst_ds = era5_ds[['sea_surface_temperature']].sel(
level=1000, # surface level only.
)

# chunk sizes determined from VM memory limit of 16 GB.
c = qr.Context()
c.create_table('era5', era5_sst_ds, chunks=dict(time=24))

print('beginning query.')
df = c.sql("""
SELECT
DATE("time") as date,
AVG("sea_surface_temperature") as daily_avg_sst
FROM
"era5"
GROUP BY
DATE("time")
""")

# TODO(alxmrs): time slice should be in file name.
df.to_csv('global_avg_sst_*.cvs')

0 comments on commit c63d25e

Please sign in to comment.