From f56a3ee1b3c982408fdadcb74c771affc94b3dc1 Mon Sep 17 00:00:00 2001 From: Andrew Kiss <31054815+aekiss@users.noreply.github.com> Date: Wed, 15 Jan 2025 16:33:40 +1100 Subject: [PATCH] Replace np.NAN with np.nan everywhere; fixes https://github.com/COSIMA/esmgrids/issues/21 --- esmgrids/base_grid.py | 4 ++-- esmgrids/mom_grid.py | 8 ++++---- esmgrids/nemo_grid.py | 12 ++++++------ esmgrids/tripolar_grid.py | 4 ++-- esmgrids/um_grid.py | 8 ++++---- esmgrids/util.py | 4 ++-- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/esmgrids/base_grid.py b/esmgrids/base_grid.py index 617ec24..8af9879 100644 --- a/esmgrids/base_grid.py +++ b/esmgrids/base_grid.py @@ -242,7 +242,7 @@ def make_corners(x, y, dx, dy): # Set grid corners, we do these one corner at a time. Start at the # bottom left and go anti-clockwise. This is the SCRIP convention. clon = np.empty((4, nrow, ncol)) - clon[:] = np.NAN + clon[:] = np.nan clon[0, :, 1:] = x[:, 1:] - dx_half[:, :] clon[0, :, 0] = x[:, 0] - dx_half[:, 0] @@ -257,7 +257,7 @@ def make_corners(x, y, dx, dy): assert not np.isnan(np.sum(clon)) clat = np.empty((4, nrow, ncol)) - clat[:] = np.NAN + clat[:] = np.nan clat[0, 1:, :] = y[1:, :] - dy_half[:, :] clat[0, 0, :] = y[0, :] - dy_half[0, :] diff --git a/esmgrids/mom_grid.py b/esmgrids/mom_grid.py index ec4297b..1bfb286 100644 --- a/esmgrids/mom_grid.py +++ b/esmgrids/mom_grid.py @@ -173,7 +173,7 @@ def make_corners(x, y): # Corners of t cells. Index 0 is bottom left and then # anti-clockwise. clon_t = np.empty((4, nrow, ncol)) - clon_t[:] = np.NAN + clon_t[:] = np.nan clon_t[0, :, :] = x[0:-1:2, 0:-1:2] clon_t[1, :, :] = x[0:-1:2, 2::2] clon_t[2, :, :] = x[2::2, 2::2] @@ -181,7 +181,7 @@ def make_corners(x, y): assert not np.isnan(np.sum(clon_t)) clat_t = np.empty((4, nrow, ncol)) - clat_t[:] = np.NAN + clat_t[:] = np.nan clat_t[0, :, :] = y[0:-1:2, 0:-1:2] clat_t[1, :, :] = y[0:-1:2, 2::2] clat_t[2, :, :] = y[2::2, 2::2] @@ -197,7 +197,7 @@ def make_corners(x, y): # Do the easy bits first and then fix up below. clon_u = np.empty((4, nrow, ncol)) - clon_u[:] = np.NAN + clon_u[:] = np.nan clon_u[0, 1:, 1:] = x[1:-2:2, 1:-2:2] clon_u[1, 1:, 1:] = x[1:-2:2, 3::2] clon_u[2, 1:, 1:] = x[3::2, 3::2] @@ -223,7 +223,7 @@ def make_corners(x, y): assert not np.isnan(np.sum(clon_u)) clat_u = np.empty((4, nrow, ncol)) - clat_u[:] = np.NAN + clat_u[:] = np.nan clat_u[0, 1:, 1:] = y[1:-2:2, 1:-2:2] clat_u[1, 1:, 1:] = y[1:-2:2, 3::2] clat_u[2, 1:, 1:] = y[3::2, 3::2] diff --git a/esmgrids/nemo_grid.py b/esmgrids/nemo_grid.py index aabdd08..562d9f5 100644 --- a/esmgrids/nemo_grid.py +++ b/esmgrids/nemo_grid.py @@ -139,7 +139,7 @@ def make_corners(x_f, y_f, x_t, y_t, x_u, y_u, x_v, y_v): # Corners of t cells are f points. Index 0 is bottom left and then # anti-clockwise. clon_t = np.empty((4, x_t.shape[0], x_t.shape[1])) - clon_t[:] = np.NAN + clon_t[:] = np.nan clon_t[0, :, :] = x_f[0:-1, 0:-1] clon_t[1, :, :] = x_f[0:-1, 1:] clon_t[2, :, :] = x_f[1:, 1:] @@ -147,7 +147,7 @@ def make_corners(x_f, y_f, x_t, y_t, x_u, y_u, x_v, y_v): assert not np.isnan(np.sum(clon_t)) clat_t = np.empty((4, x_t.shape[0], x_t.shape[1])) - clat_t[:] = np.NAN + clat_t[:] = np.nan clat_t[0, :, :] = y_f[0:-1, 0:-1] clat_t[1, :, :] = y_f[0:-1, 1:] clat_t[2, :, :] = y_f[1:, 1:] @@ -156,7 +156,7 @@ def make_corners(x_f, y_f, x_t, y_t, x_u, y_u, x_v, y_v): # The corners of u cells are v points. clon_u = np.empty((4, x_t.shape[0], x_t.shape[1])) - clon_u[:] = np.NAN + clon_u[:] = np.nan clon_u[0, :, :] = x_v[0:-1, 0:-1] clon_u[1, :, :] = x_v[0:-1, 1:] @@ -165,7 +165,7 @@ def make_corners(x_f, y_f, x_t, y_t, x_u, y_u, x_v, y_v): assert not np.isnan(np.sum(clon_u)) clat_u = np.empty((4, x_t.shape[0], x_t.shape[1])) - clat_u[:] = np.NAN + clat_u[:] = np.nan clat_u[0, :, :] = y_v[0:-1, 0:-1] clat_u[1, :, :] = y_v[0:-1, 1:] clat_u[2, :, :] = y_v[1:, 1:] @@ -174,7 +174,7 @@ def make_corners(x_f, y_f, x_t, y_t, x_u, y_u, x_v, y_v): # The corners of v cells are u points. clon_v = np.empty((4, x_t.shape[0], x_t.shape[1])) - clon_v[:] = np.NAN + clon_v[:] = np.nan clon_v[0, :, :] = x_u[0:-1, 0:-1] clon_v[1, :, :] = x_u[0:-1, 1:] @@ -183,7 +183,7 @@ def make_corners(x_f, y_f, x_t, y_t, x_u, y_u, x_v, y_v): assert not np.isnan(np.sum(clon_v)) clat_v = np.empty((4, x_t.shape[0], x_t.shape[1])) - clat_v[:] = np.NAN + clat_v[:] = np.nan clat_v[0, :, :] = y_u[0:-1, 0:-1] clat_v[1, :, :] = y_u[0:-1, 1:] clat_v[2, :, :] = y_u[1:, 1:] diff --git a/esmgrids/tripolar_grid.py b/esmgrids/tripolar_grid.py index 4de0453..6cc9895 100644 --- a/esmgrids/tripolar_grid.py +++ b/esmgrids/tripolar_grid.py @@ -70,7 +70,7 @@ def make_corners(self): dx_half[:, 0] = dx_half[:, 1] clon = np.empty((self.num_lat_points, self.num_lon_points, 4)) - clon[:] = np.NAN + clon[:] = np.nan clon[:, :, 0] = x - dx_half clon[:, :, 1] = x + dx_half @@ -79,7 +79,7 @@ def make_corners(self): assert not np.isnan(np.sum(clon)) clat = np.empty((self.num_lat_points, self.num_lon_points, 4)) - clat[:] = np.NAN + clat[:] = np.nan clat[:, :, 0] = y - dy_half clat[:, :, 1] = y - dy_half clat[:, :, 2] = y + dy_half diff --git a/esmgrids/um_grid.py b/esmgrids/um_grid.py index 767b748..fb805c0 100644 --- a/esmgrids/um_grid.py +++ b/esmgrids/um_grid.py @@ -47,7 +47,7 @@ def make_corners(x, y, dx, dy): # Set grid corners, we do these one corner at a time. Start at the # bottom left and go anti-clockwise. This is the OASIS convention. clon = np.empty((self.corners, x.shape[0], x.shape[1])) - clon[:] = np.NAN + clon[:] = np.nan clon[0, :, :] = x - dx clon[1, :, :] = x + dx clon[2, :, :] = x + dx @@ -55,7 +55,7 @@ def make_corners(x, y, dx, dy): assert not np.isnan(np.sum(clon)) clat = np.empty((self.corners, x.shape[0], x.shape[1])) - clat[:] = np.NAN + clat[:] = np.nan clat[0, :, :] = y[:, :] - dy clat[1, :, :] = y[:, :] - dy clat[2, :, :] = y[:, :] + dy @@ -149,7 +149,7 @@ def segments(v): return 0.5 * abs(sum(x0 * y1 - x1 * y0 for ((x0, y0), (x1, y1)) in segments(p))) areas = np.zeros_like(clons[0]) - areas[:] = np.NAN + areas[:] = np.nan m = Basemap( projection="laea", @@ -168,7 +168,7 @@ def segments(v): for j in range(x[0, :].shape[1]): areas[i, j] = area_polygon(zip(x[:, i, j], y[:, i, j])) - assert np.sum(areas) is not np.NAN + assert np.sum(areas) is not np.nan assert np.min(areas) > 0 assert abs(1 - np.sum(areas) / EARTH_AREA) < 2e-4 diff --git a/esmgrids/util.py b/esmgrids/util.py index a0fdb68..1fa5c5f 100644 --- a/esmgrids/util.py +++ b/esmgrids/util.py @@ -19,7 +19,7 @@ def calc_area_of_polygons(clons, clats): """ areas = np.zeros(clons.shape[1:]) - areas[:] = np.NAN + areas[:] = np.nan for j in range(areas.shape[0]): for i in range(areas.shape[1]): @@ -36,7 +36,7 @@ def calc_area_of_polygons(clons, clats): cop = {"type": "Polygon", "coordinates": [zip(x, y)]} areas[j, i] = shape(cop).area - assert np.sum(areas) is not np.NAN + assert np.sum(areas) is not np.nan assert np.min(areas) > 0 return areas