Skip to content
Snippets Groups Projects
Commit 91fd969b authored by fraserwg's avatar fraserwg
Browse files

added converted_tgrid check which prevents double conversion of a tgrid file

parent dd69e7c5
No related branches found
No related tags found
No related merge requests found
......@@ -12,18 +12,43 @@ print('xarray')
import xarray as xr
print('Done modules calc.')
def convert_tgrid_data(ds_tg):
def convert_tgrid_data(ds_tg, check_previous_conversion=True, set_dim_order=True):
""" Convert xarray grid file to grid file compatible with pyicon function.
Open classical ICON grid file by:
ds_tg = xr.open_dataset(fpath_tg, chunks=dict())
Parameters
----------
ds_tg : xr.Dataset
raw, unprocessed tgrid
check_previous_conversion : bool
check whether the dataset has already been converted and raise an error
if so
set_dim_order : bool or list
Transpose the dataset so dimensions appear in the standard pyicon
order, or the order listed
Then convert by:
ds_IcD = pyic.convert_tgrid_data(ds_tg)
Returns
-------
ds_icd : xr.Dataset
A tgrid dataset compatible with pyicon functions
ds_tg and ds_IcD are both lazy xarray data sets containing dask arrays.
Notes
-----
Open classical ICON grid file by:
ds_tg = xr.open_dataset(fpath_tg, chunks=dict())
Then convert by:
ds_IcD = pyic.convert_tgrid_data(ds_tg)
"""
if check_previous_conversion:
if "converted_tgrid" in ds_tg.attrs:
raise ValueError(
"ds_tg has previously been converted by this function, \
applying the function again will lead to undocumented \
behaviour. To proceed, set 'check_previous_conversion=False'"
)
ds_IcD = xr.Dataset()
# --- constants (from src/shared/mo_physical_constants.f90)
......
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