From c7dd2745aa14592ae6aa15959afd665b6facb083 Mon Sep 17 00:00:00 2001 From: John Omotani Date: Wed, 13 Nov 2024 13:37:27 +0000 Subject: [PATCH 1/6] Hack coordinate names when opening grid file to avoid conflict There is a 'theta' variable in grid files, which prevents naming a dimension 'theta'. Also keep the 'psixy' variable in the Dataset - create a new variable referecing it rather than renaming it to make the 'psi_poloidal' coordinate. --- xbout/geometries.py | 2 +- xbout/load.py | 7 ++++++- xbout/tests/test_boutdataset.py | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/xbout/geometries.py b/xbout/geometries.py index 2299f54b..fb50b432 100644 --- a/xbout/geometries.py +++ b/xbout/geometries.py @@ -400,7 +400,7 @@ def add_toroidal_geometry_coords(ds, *, coordinates=None, grid=None): ds = ds.rename(y=coordinates["y"]) # TODO automatically make this coordinate 1D in simplified cases? - ds = ds.rename(psixy=coordinates["x"]) + ds[coordinates["x"]] = ds["psixy"] ds = ds.set_coords(coordinates["x"]) ds[coordinates["x"]].attrs["units"] = "Wb" diff --git a/xbout/load.py b/xbout/load.py index 3a82a617..b8feb980 100644 --- a/xbout/load.py +++ b/xbout/load.py @@ -367,7 +367,12 @@ def attrs_remove_section(obj, section): ds.metadata[v] = grid[v].values # Update coordinates to match particular geometry of grid - ds = geometries.apply_geometry(ds, geometry, grid=grid) + if input_type == "grid": + # Specify coordinate names to avoid name clash + coordinates = {"x": "psi_poloidal", "y": "y", "z": "zeta"} + else: + coordinates = None + ds = geometries.apply_geometry(ds, geometry, grid=grid, coordinates=coordinates) if remove_yboundaries: ds = ds.bout.remove_yboundaries() diff --git a/xbout/tests/test_boutdataset.py b/xbout/tests/test_boutdataset.py index 50448c68..2d97ecb0 100644 --- a/xbout/tests/test_boutdataset.py +++ b/xbout/tests/test_boutdataset.py @@ -1136,6 +1136,7 @@ def test_interpolate_parallel_all_variables_arg(self, bout_xyt_example_files): "G3", "J", "Bxy", + "psixy", ) ) From 992f1b10fe4013e1de6756a2aab79d969df12707 Mon Sep 17 00:00:00 2001 From: John Omotani Date: Thu, 14 Nov 2024 14:19:26 +0000 Subject: [PATCH 2/6] Correct region-plotting function in grid plot example --- examples/plot_grid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/plot_grid.py b/examples/plot_grid.py index e8ea3b4a..1b504d2e 100644 --- a/examples/plot_grid.py +++ b/examples/plot_grid.py @@ -13,6 +13,6 @@ grid["psi_poloidal"].bout.pcolormesh() grid["psi_poloidal"].bout.pcolormesh(shading="gouraud") -grid["psi_poloidal"].bout.regions() +grid["psi_poloidal"].bout.plot_regions() plt.show() From 0ff4e76596b3e1e9ad08f53d9268ebdfda02b6e7 Mon Sep 17 00:00:00 2001 From: Michael Hardman <29800382+mrhardman@users.noreply.github.com> Date: Fri, 6 Dec 2024 15:19:35 +0000 Subject: [PATCH 3/6] Add optional argument to make sure xbout reads David Bold's MMS output file as a dump file rather than a grid file. --- xbout/load.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/xbout/load.py b/xbout/load.py index b8feb980..33a4b8f7 100644 --- a/xbout/load.py +++ b/xbout/load.py @@ -84,6 +84,7 @@ def open_boutdataset( run_name=None, info=True, is_restart=None, + is_mms_dump=False, **kwargs, ): """ @@ -180,12 +181,12 @@ def open_boutdataset( chunks = {} input_type = _check_dataset_type(datapath) - if is_restart is None: is_restart = input_type == "restart" elif is_restart is True: input_type = "restart" - + if is_mms_dump: + input_type = "dump" if "reload" in input_type: if input_type == "reload": if isinstance(datapath, Path): @@ -633,7 +634,6 @@ def _auto_open_mfboutdataset( nxpe, nype, mxg, myg, mxsub, mysub, is_squashed_doublenull = _read_splitting( filepaths[0], info, keep_yboundaries ) - if is_squashed_doublenull: # Need to remove y-boundaries after loading: (i) in case we are loading a # squashed data-set, in which case we cannot easily remove the upper @@ -737,9 +737,10 @@ def _auto_open_mfboutdataset( ) if not is_restart: - # Remove any duplicate time values from concatenation - _, unique_indices = unique(ds["t_array"], return_index=True) - ds = ds.isel(t=unique_indices) + if "t_array" in ds.keys(): + # Remove any duplicate time values from concatenation + _, unique_indices = unique(ds["t_array"], return_index=True) + ds = ds.isel(t=unique_indices) return ds, remove_yboundaries From 168244b90aae504ae3eed5b52248667caaed5910 Mon Sep 17 00:00:00 2001 From: Michael Hardman <29800382+mrhardman@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:05:22 +0000 Subject: [PATCH 4/6] Modify plot2d_polygon to use the standard Rxy, Zxy coordinates labels. Mike Kryjak indicates that this coordinate use was originally an error. --- xbout/plotting/plotfuncs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xbout/plotting/plotfuncs.py b/xbout/plotting/plotfuncs.py index db0a1e67..b3439d1b 100644 --- a/xbout/plotting/plotfuncs.py +++ b/xbout/plotting/plotfuncs.py @@ -945,14 +945,14 @@ def plot2d_polygon( if "Rxy_lower_right_corners" in da.coords: r_nodes = [ - "R", + "Rxy", "Rxy_lower_left_corners", "Rxy_lower_right_corners", "Rxy_upper_left_corners", "Rxy_upper_right_corners", ] z_nodes = [ - "Z", + "Zxy", "Zxy_lower_left_corners", "Zxy_lower_right_corners", "Zxy_upper_left_corners", From 3bad4189d7310800f6534b623e689126d2a2d5c3 Mon Sep 17 00:00:00 2001 From: Michael Hardman <29800382+mrhardman@users.noreply.github.com> Date: Tue, 10 Dec 2024 09:13:58 +0000 Subject: [PATCH 5/6] Revert "Modify plot2d_polygon to use the standard Rxy, Zxy coordinates labels. Mike Kryjak indicates that this coordinate use was originally an error." This reverts commit 168244b90aae504ae3eed5b52248667caaed5910. --- xbout/plotting/plotfuncs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xbout/plotting/plotfuncs.py b/xbout/plotting/plotfuncs.py index b3439d1b..db0a1e67 100644 --- a/xbout/plotting/plotfuncs.py +++ b/xbout/plotting/plotfuncs.py @@ -945,14 +945,14 @@ def plot2d_polygon( if "Rxy_lower_right_corners" in da.coords: r_nodes = [ - "Rxy", + "R", "Rxy_lower_left_corners", "Rxy_lower_right_corners", "Rxy_upper_left_corners", "Rxy_upper_right_corners", ] z_nodes = [ - "Zxy", + "Z", "Zxy_lower_left_corners", "Zxy_lower_right_corners", "Zxy_upper_left_corners", From 1b8986fc5e8b33194b8b1f2a30db743e1eb1f00c Mon Sep 17 00:00:00 2001 From: Ben Dudson Date: Wed, 11 Dec 2024 18:07:38 -0800 Subject: [PATCH 6/6] load: Removing unique t_array filter Seems it was removed in `master`, then the merge partly put it back. Hopefully it's supposed to be removed... --- xbout/load.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/xbout/load.py b/xbout/load.py index 3598653f..5c3d8a61 100644 --- a/xbout/load.py +++ b/xbout/load.py @@ -724,12 +724,6 @@ def _auto_open_mfboutdataset( combine_attrs="override", ) - if not is_restart: - if "t_array" in ds.keys(): - # Remove any duplicate time values from concatenation - _, unique_indices = unique(ds["t_array"], return_index=True) - ds = ds.isel(t=unique_indices) - return ds, remove_yboundaries