Skip to content

Instantly share code, notes, and snippets.

@chrishavlin
Created July 28, 2022 20:22
Show Gist options
  • Save chrishavlin/aaf887a5f36eb5f6a7f7ae45f936c2fa to your computer and use it in GitHub Desktop.
Save chrishavlin/aaf887a5f36eb5f6a7f7ae45f936c2fa to your computer and use it in GitHub Desktop.
function for loading IRIS data into yt from xarray
import xarray as xr
import yt
import os
import numpy as np
import cartopy.feature as cfeature
import cartopy.crs as ccrs
ddir = os.path.join(yt.config.ytcfg.get('yt','test_data_dir'), 'sample_nc')
# https://ds.iris.edu/files/products/emc/emc-files/GYPSUM_percent.nc : a global model
# https://ds.iris.edu/files/products/emc/emc-files/wUS-SH-2010_percent.nc : a non-global model covering the western US
datasets = {
"internal_geographic_partial": os.path.join(ddir,'wUS-SH-2010_percent.nc'),
"internal_geographic_global": os.path.join(ddir,'GYPSUM_percent.nc'),
}
def get_internal_IRIS(case):
# both datasets have the same variables and dimension order
fi = datasets[case]
with xr.open_dataset(fi) as xr_ds:
dvs = xr_ds.dvs.to_masked_array().data
deprng = [xr_ds.depth.data.min(), xr_ds.depth.data.max()]
lonrng=[xr_ds.longitude.data.min(), xr_ds.longitude.data.max()]
latrng=[xr_ds.latitude.data.min(), xr_ds.latitude.data.max()]
data = {'dvs': (dvs, "%")}
bbox = np.array([
deprng,
latrng,
lonrng
])
dims = ['depth', 'latitude', 'longitude']
return yt.load_uniform_grid(data, data['dvs'][0].shape, 1.0,
geometry=("internal_geographic", dims),
bbox=bbox)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment