From 1a0fa3fabeea20a2a6844ed1f37eac1f5439b3d9 Mon Sep 17 00:00:00 2001 From: Benoit Seignovert Date: Tue, 22 Oct 2024 16:58:11 +0200 Subject: [PATCH] Fix numpy depreciated np.product and OverflowError error on uint8 mask (fix #5) --- pyvims/interp.py | 9 +++++++-- pyvims/projections/equirectangular.py | 2 +- pyvims/projections/sky_old.py | 4 ++-- pyvims/vims.py | 6 +++--- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pyvims/interp.py b/pyvims/interp.py index cadd21e..c9a4f28 100644 --- a/pyvims/interp.py +++ b/pyvims/interp.py @@ -204,7 +204,12 @@ def cube_interp(xy, data, res, contour=False, method='cubic'): m = mask(grid, contour) if np.ndim(data) == 3: - z = np.moveaxis([z[:, :, 0], z[:, :, 1], z[:, :, 2], 255 * np.int8(~m)], 0, 2) + z = np.moveaxis([ + z[:, :, 0], + z[:, :, 1], + z[:, :, 2], + 255 * np.uint8(~m), + ], 0, 2) else: z = np.ma.array(z, mask=m) @@ -264,7 +269,7 @@ def cube_interp_filled(xy, data, res, contour, method='cubic'): if np.ndim(data) == 3: # Add alpha channel outside the contour - z = rgba(z[:, :, 0], z[:, :, 1], z[:, :, 2], np.int8(~m)) + z = rgba(z[:, :, 0], z[:, :, 1], z[:, :, 2], np.uint8(~m)) else: # Mask the data outside the contour z = np.ma.array(z, mask=m) diff --git a/pyvims/projections/equirectangular.py b/pyvims/projections/equirectangular.py index a251c5d..61efa2e 100644 --- a/pyvims/projections/equirectangular.py +++ b/pyvims/projections/equirectangular.py @@ -147,7 +147,7 @@ def equi_interp(xy, data, res, contour, sc, r, npix=1440, method='cubic'): gz_interp[:, :, 0], gz_interp[:, :, 1], gz_interp[:, :, 2], - 255 * np.int8(~m) + 255 * np.uint8(~m), ], 0, 2) else: z_mask = np.ma.array(gz_interp, mask=m) diff --git a/pyvims/projections/sky_old.py b/pyvims/projections/sky_old.py index 1026a17..505591e 100644 --- a/pyvims/projections/sky_old.py +++ b/pyvims/projections/sky_old.py @@ -106,7 +106,7 @@ def sky_pixels(radec, m_sky): """ s = np.shape(radec) - npix = int(np.product(s) / 2) + npix = int(np.prod(s) / 2) pix = xy(*np.reshape(radec, (2, npix)), m_sky) return np.reshape(pix, s) @@ -147,7 +147,7 @@ def sky_grid(grid, m_sky): """ s = np.shape(grid) - npix = int(np.product(s) / 2) + npix = int(np.prod(s) / 2) x, y = np.reshape(grid, (2, npix)) return radec(x, y, m_sky).reshape(s) diff --git a/pyvims/vims.py b/pyvims/vims.py index 3c49c19..1f35eea 100644 --- a/pyvims/vims.py +++ b/pyvims/vims.py @@ -297,10 +297,10 @@ def _flat(self, array): Returns ------- np.array - Flattenned array. + Flattened array. """ - ndim = int(np.product(np.shape(array)) / self.NP) + ndim = int(np.prod(np.shape(array)) / self.NP) return np.reshape(array, (ndim, self.NP)) def _grid(self, array): @@ -317,7 +317,7 @@ def _grid(self, array): Gridded array. """ - ndim = int(np.product(np.shape(array)) / self.NP) + ndim = int(np.prod(np.shape(array)) / self.NP) return np.reshape(array, (ndim, self.NL, self.NS)) @staticmethod