Skip to content

Commit

Permalink
Add concat_dim as option to open_feltordataset
Browse files Browse the repository at this point in the history
  • Loading branch information
mwiesenberger committed Apr 29, 2024
1 parent 2c9ec4d commit f1022f6
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 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,
concat_dim : str = "time",
**kwargs: dict,
) -> xr.Dataset:
"""Loads FELTOR output into one xarray Dataset. Can load either a single
Expand All @@ -27,6 +28,8 @@ 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
concat_dim : str, optional
The name of the dimension along which to concatenate
kwargs : optional
Keyword arguments are passed down to `xarray.open_mfdataset`, which in
turn passes extra kwargs down to `xarray.open_dataset`.
Expand All @@ -38,22 +41,23 @@ def open_feltordataset(
datapath,
chunks=chunks,
combine="nested",
concat_dim="time",
concat_dim=concat_dim,
decode_times=False,
join="outer",
**kwargs,
)

if restart_indices:
return ds

_, index = np.unique(ds["time"], return_index=True)

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

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

return ds.isel(time=index)
if restart_indices:
return ds

_, index = np.unique(ds[concat_dim], return_index=True)

#return ds.isel(time=index)
return ds[{concat_dim : index}]

0 comments on commit f1022f6

Please sign in to comment.