Skip to content

Instantly share code, notes, and snippets.

@Thomas-Moore-Creative
Created August 4, 2021 00:28
Show Gist options
  • Save Thomas-Moore-Creative/ee5af1b6f3db9d0df0b3c3e5b7f02a7d to your computer and use it in GitHub Desktop.
Save Thomas-Moore-Creative/ee5af1b6f3db9d0df0b3c3e5b7f02a7d to your computer and use it in GitHub Desktop.
Preprocess step for loading ACCESS-S2 Reanalysis data with inconsistent NetCDF file structure
# define preprocess drop function - this unfortunately removes useful information like areau that's missing from 2015 files
def drop_not_in_2015(ds):
if 'latu_bounds' in ds.data_vars:
ds = ds.drop(['latu_bounds'])
if 'lonu_bounds' in ds.data_vars:
ds = ds.drop(['lonu_bounds'])
if 'latv_bounds' in ds.data_vars:
ds = ds.drop(['latv_bounds'])
if 'lonv_bounds' in ds.data_vars:
ds = ds.drop(['lonv_bounds'])
if 'depthu_bounds' in ds.data_vars:
ds = ds.drop(['depthu_bounds'])
if 'areau' in ds.data_vars:
ds = ds.drop(['areau'])
if 'depthv_bounds' in ds.data_vars:
ds = ds.drop(['depthv_bounds'])
if 'areav' in ds.data_vars:
ds = ds.drop(['areav'])
return ds
ds_u_1981_2018 = xr.open_mfdataset('/g/data/ux62/access-s2/reanalysis/ocean/u/mo_u_*.nc',parallel=True,preprocess=drop_not_in_2015)
ds_u_1981_2018
@Thomas-Moore-Creative
Copy link
Author

a typical next step would be to add back in useful information (area*, etc) to the xarray object afterward.

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