Skip to content

Commit

Permalink
Fix load function when reading in groups
Browse files Browse the repository at this point in the history
  • Loading branch information
mwiesenberger committed Jan 22, 2024
1 parent 62d6043 commit 6b9a3be
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions xfeltor/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def open_feltordataset(
datapath: str = "./*.nc",
chunks: Union[int, dict] = None,
restart_indices: bool = False,
inputfile_as_attr: bool = True,
**kwargs: dict,
) -> xr.Dataset:
"""Loads FELTOR output into one xarray Dataset. Can load either a single
Expand All @@ -25,6 +26,9 @@ def open_feltordataset(
http://xarray.pydata.org/en/stable/user-guide/dask.html#chunking-and-performance
restart_indices: bool, optional
if True, duplicate time steps from restared runs are kept
inputfile_as_attr: bool, optional
if True, read in the global attribute "inputfile" as a json string and store its variables
as attributes of the xarray Dataset
kwargs : optional
Keyword arguments are passed down to `xarray.open_mfdataset`, which in
turn passes extra kwargs down to `xarray.open_dataset`.
Expand All @@ -48,9 +52,10 @@ def open_feltordataset(
_, index = np.unique(ds["time"], return_index=True)

# store inputfile data in ds.attrs
input_variables = json.loads(ds.attrs["inputfile"])
if inputfile_as_attr:
input_variables = json.loads(ds.attrs["inputfile"])

for i in input_variables:
ds.attrs[i] = input_variables[i]
for i in input_variables:
ds.attrs[i] = input_variables[i]

return ds.isel(time=index)

0 comments on commit 6b9a3be

Please sign in to comment.