Skip to content
Snippets Groups Projects
Commit 43006f24 authored by Fraser William Goldsworth's avatar Fraser William Goldsworth
Browse files

added new error messages

parent 98929e95
No related branches found
No related tags found
No related merge requests found
import sys, glob, os
import warnings
import json
from pathlib import Path
# --- calculations
......@@ -1901,7 +1902,7 @@ def plot(data,
grid_type='auto',
# --- ckdtree interpolation
res=0.3, fpath_ckdtree='auto',
coordinates='clat clon',
coordinates=None,
antialias=1,
mask_to_zero=False,
# --- original grid
......@@ -2128,12 +2129,54 @@ def plot(data,
f"Unable to find file `fpath_ckdtree={fpath_ckdtree}`. \
Try setting `fpath_ckdtree` explicitly."
)
datai = interp_to_rectgrid_xr(
data.compute(), fpath_ckdtree,
lon_reg=lon_reg, lat_reg=lat_reg, coordinates=coordinates,
antialias=antialias, mask_to_zero=mask_to_zero,
)
if coordinates is None:
# Infer the coordinates
if 'cell' in data.dims:
data = data.rename(cell='ncells')
coordinates = 'clat clon'
elif 'vertex' in data.dims:
data = data.rename(vertex='ncells')
coordinates = 'vlat vlon'
else:
warnings.warn(
"Coordinates are being inferred. If the resulting plot looks \n"
"unreasonable try setting `coordinates` kwarg explicitly."
)
if 'ncells' in data.dims:
coordinates = 'clat clon'
elif 'ncells_2' in data.dims:
data = data.rename(ncells_2='ncells')
coordinates = 'vlat vlon'
else:
raise RuntimeError(
"Unable to infer coordinates. Please try setting the \n"
"`coordinates` key word argument explicitly."
)
try:
datai = interp_to_rectgrid_xr(
data.compute(), fpath_ckdtree,
lon_reg=lon_reg, lat_reg=lat_reg, coordinates=coordinates,
antialias=antialias, mask_to_zero=mask_to_zero,
)
except IndexError:
raise ValueError(
"A problem was encountered attempting to interpolate the data to a \n"
"regular grid before plotting. This was *almost certainly* caused by \n"
"the incorrect specification of the `coordinates` keyword argument. \n"
"If the quantity you wish to plot is on cells it should be \n"
"`'clon clat'`, if on vertices `'vlon vlat'`."
)
except AttributeError:
raise AttributeError(
"The ckdtree used for interpolating this object doesn't support \n"
f"interpolation from {coordinates} to 'lat lon'. You may need to \n"
f"recreate the ckdtree stored in {fpath_ckdtree} or specify a \n"
"different ckdtree."
)
lon = datai.lon
lat = datai.lat
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment