Skip to content

Instantly share code, notes, and snippets.

@phinate
Created April 3, 2024 11:41
Show Gist options
  • Save phinate/2cd53517f91845fbdd010776a1f11551 to your computer and use it in GitHub Desktop.
Save phinate/2cd53517f91845fbdd010776a1f11551 to your computer and use it in GitHub Desktop.
load slice of era5 for local use
import xarray
variables = [
'u_component_of_wind',
'v_component_of_wind',
'geopotential',
'temperature',
# ... full list of variables here: https://console.cloud.google.com/storage/browser/gcp-public-data-arco-era5/ar/1959-2022-full_37-1h-0p25deg-chunk-1.zarr-v2;tab=objects?pli=1&prefix=&forceOnObjectsSortingFiltering=false
]
# Loading ERA5 data from Google Cloud arco project
era5_path = 'gs://gcp-public-data-arco-era5/ar/full_37-1h-0p25deg-chunk-1.zarr-v3'
full_era5_ds = xarray.open_zarr(era5_path, chunks=None)
full_era5_ds = full_era5_ds[variables]
start_time = '2020-02-14'
end_time = '2020-02-18'
data_inner_steps = 12 # process every 12th hour
era5_ds = full_era5_ds.sel(time=slice(start_time, end_time))
era5_ds = era5_ds.thin(time=data_inner_steps)
# here, era5_ds will be much smaller, and you can then materialize it/save it/etc.
era5_ds.to_netcdf(f'{start_time}_{end_time}_era5_slice.nc')
@phinate
Copy link
Author

phinate commented May 8, 2024

dependencies:

gcsfs
fsspec
xarray
zarr
netcdf4

@dsj976
Copy link

dsj976 commented May 16, 2024

name: era5
channels:

  • defaults
    dependencies:
  • python=3.11
  • bottleneck
  • dask
  • netcdf4
  • xarray
  • zarr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment