From 940c4bd803549a62327c96c88e6848cdad022f05 Mon Sep 17 00:00:00 2001 From: David Kamm Date: Mon, 31 Jul 2023 15:01:11 +0200 Subject: [PATCH 1/3] resolve #1 --- xnemogcm/nemo.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/xnemogcm/nemo.py b/xnemogcm/nemo.py index 79defc4..bc3923c 100644 --- a/xnemogcm/nemo.py +++ b/xnemogcm/nemo.py @@ -81,9 +81,22 @@ def nemo_preprocess(ds, domcfg, point_type=None): except IndexError: # This means that there is no depth dependence of the data (surface data) z_nme = None - x_nme = "x" - y_nme = "y" - to_rename.update({x_nme: point.x, y_nme: point.y}) + # get the name of the variable along i e.g. x, x_grid_U, x_grid_U_inner etc + try: + x_nme = [i for i in ds.dims.keys() if "x_grid" in i] + except IndexError: + # This means that the i-dimension must have the name 'x' + x_nme = ["x"] + # get the name of the variable along j e.g. y, y_grid_U, y_grid_U_inner etc + try: + y_nme = [i for i in ds.dims.keys() if "y_grid" in i] + except IndexError: + # This means that the j-dimension must have the name 'y' + y_nme = ["y"] + + for x, y in zip(x_nme, y_nme): + to_rename.update({x: point.x, y: point.y}) + points = [point.x, point.y] if z_nme: to_rename.update({z_nme: point.z}) From 123f32a2387d0f37ad6c056f48659a081f4c78c6 Mon Sep 17 00:00:00 2001 From: David Kamm Date: Mon, 31 Jul 2023 17:04:40 +0200 Subject: [PATCH 2/3] Include possibility of dimensions x and x_grid/x_grid_inner and of not having the same number of dimensions along i and j --- xnemogcm/nemo.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/xnemogcm/nemo.py b/xnemogcm/nemo.py index bc3923c..d3171a3 100644 --- a/xnemogcm/nemo.py +++ b/xnemogcm/nemo.py @@ -81,21 +81,17 @@ def nemo_preprocess(ds, domcfg, point_type=None): except IndexError: # This means that there is no depth dependence of the data (surface data) z_nme = None - # get the name of the variable along i e.g. x, x_grid_U, x_grid_U_inner etc - try: - x_nme = [i for i in ds.dims.keys() if "x_grid" in i] - except IndexError: - # This means that the i-dimension must have the name 'x' - x_nme = ["x"] - # get the name of the variable along j e.g. y, y_grid_U, y_grid_U_inner etc - try: - y_nme = [i for i in ds.dims.keys() if "y_grid" in i] - except IndexError: - # This means that the j-dimension must have the name 'y' - y_nme = ["y"] + + # get the name of the dimension along i e.g. x, x_grid_U, x_grid_U_inner etc + x_nme = [i for i in ds.dims.keys() if "x_grid" in i or i=='x'] + # get the name of the dimension along j e.g. y, y_grid_U, y_grid_U_inner etc + y_nme = [i for i in ds.dims.keys() if "y_grid" in i or i=='y'] - for x, y in zip(x_nme, y_nme): - to_rename.update({x: point.x, y: point.y}) + for x in x_nme: + to_rename.update({x: point.x}) + + for y in y_nme: + to_rename.update({y: point.y}) points = [point.x, point.y] if z_nme: From 22c718478f6ddbcb347e47bd338b8d632e1d1be0 Mon Sep 17 00:00:00 2001 From: David Kamm Date: Mon, 31 Jul 2023 17:32:15 +0200 Subject: [PATCH 3/3] Update README and formatting --- README.md | 3 +++ xnemogcm/nemo.py | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 94af462..26631e3 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,9 @@ the latest version of the code, and publish them to `example` when commiting to ## What's new +### not released yet +* Allow additional dimension names occurring when variables on inner grid are diagnosed, e.g. `x_grid_U_inner` or `x_grid_U`. + ### v0.4.1 (2023-03-29) * Allow to open files if time bounds are missing * Minor bug correction for nemo 3.6 diff --git a/xnemogcm/nemo.py b/xnemogcm/nemo.py index d3171a3..dd456dd 100644 --- a/xnemogcm/nemo.py +++ b/xnemogcm/nemo.py @@ -83,16 +83,16 @@ def nemo_preprocess(ds, domcfg, point_type=None): z_nme = None # get the name of the dimension along i e.g. x, x_grid_U, x_grid_U_inner etc - x_nme = [i for i in ds.dims.keys() if "x_grid" in i or i=='x'] + x_nme = [i for i in ds.dims.keys() if "x_grid" in i or i == "x"] # get the name of the dimension along j e.g. y, y_grid_U, y_grid_U_inner etc - y_nme = [i for i in ds.dims.keys() if "y_grid" in i or i=='y'] - + y_nme = [i for i in ds.dims.keys() if "y_grid" in i or i == "y"] + for x in x_nme: to_rename.update({x: point.x}) for y in y_nme: to_rename.update({y: point.y}) - + points = [point.x, point.y] if z_nme: to_rename.update({z_nme: point.z})