Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Checks if 'name' variable is unique, and if so, uses that as the dime…
Browse files Browse the repository at this point in the history
…nsion coordinate instead of id
  • Loading branch information
daminton committed Nov 16, 2022
1 parent ec048b6 commit 87f4ca7
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/swiftest/swiftest/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,10 @@ def swiftest2xr(param, verbose=True):
ds = fix_types(ds,ftype=np.float64)
elif param['OUT_TYPE'] == "NETCDF_FLOAT":
ds = fix_types(ds,ftype=np.float32)
# Check if the name variable contains unique values. If so, make name the dimension instead of id
if len(np.unique(ds['name'])) == len(ds['name']):
ds = ds.swap_dims({"id" : "name"})
sim.ds.reset_coords("id")
else:
print(f"Error encountered. OUT_TYPE {param['OUT_TYPE']} not recognized.")
return None
Expand Down

0 comments on commit 87f4ca7

Please sign in to comment.