Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace np.NAN with np.nan everywhere #22

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions esmgrids/base_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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, :]
Expand Down
8 changes: 4 additions & 4 deletions esmgrids/mom_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ 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]
clon_t[3, :, :] = x[2::2, 0:-1:2]
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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down
12 changes: 6 additions & 6 deletions esmgrids/nemo_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ 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:]
clon_t[3, :, :] = x_f[1:, 0:-1]
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:]
Expand All @@ -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:]
Expand All @@ -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:]
Expand All @@ -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:]
Expand All @@ -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:]
Expand Down
4 changes: 2 additions & 2 deletions esmgrids/tripolar_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions esmgrids/um_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ 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
clon[3, :, :] = x - dx
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
Expand Down Expand Up @@ -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",
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions esmgrids/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
Expand All @@ -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
Expand Down
Loading