From 87f4ca7a1964ac54db23581f9f0d07a96f57178f Mon Sep 17 00:00:00 2001 From: David A Minton Date: Wed, 16 Nov 2022 16:39:29 -0500 Subject: [PATCH] Checks if 'name' variable is unique, and if so, uses that as the dimension coordinate instead of id --- python/swiftest/swiftest/io.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/swiftest/swiftest/io.py b/python/swiftest/swiftest/io.py index 2ec86f108..64d3f0c6e 100644 --- a/python/swiftest/swiftest/io.py +++ b/python/swiftest/swiftest/io.py @@ -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