From e81993608d28357525a93a12ff00660d2354adf2 Mon Sep 17 00:00:00 2001 From: Filipe Fernandes Date: Tue, 30 Jul 2024 22:35:33 +0200 Subject: [PATCH 1/5] better diff when updating --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c2a2ca4..15d5dc1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - python-version: ["3.10", "3.11", "3.12"] + python-version: [ "3.10", "3.11", "3.12" ] os: [ubuntu-latest] fail-fast: false From 43f9f2bea5de0bfdb689d4b2bf4df81b0b337a8b Mon Sep 17 00:00:00 2001 From: Filipe Fernandes Date: Tue, 30 Jul 2024 22:35:41 +0200 Subject: [PATCH 2/5] update --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4846901..959bcea 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,18 +28,18 @@ repos: - id: blackdoc - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.3.5 + rev: v0.5.5 hooks: - id: ruff - repo: https://github.com/psf/black - rev: 24.3.0 + rev: 24.4.2 hooks: - id: black language_version: python3 - repo: https://github.com/codespell-project/codespell - rev: v2.2.6 + rev: v2.3.0 hooks: - id: codespell args: @@ -51,6 +51,6 @@ repos: - id: add-trailing-comma - repo: https://github.com/tox-dev/pyproject-fmt - rev: "1.7.0" + rev: "2.2.0" hooks: - id: pyproject-fmt From e5f363401894bdea8b26d555928b3ee72a1a5943 Mon Sep 17 00:00:00 2001 From: Filipe Fernandes Date: Tue, 30 Jul 2024 22:35:59 +0200 Subject: [PATCH 3/5] run pre-commit --- pyproject.toml | 76 ++++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a11fc8a..b7ac484 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ build-backend = "setuptools.build_meta" requires = [ "setuptools>=42", - "setuptools_scm[toml]>=3.4", + "setuptools-scm[toml]>=3.4", "wheel", ] @@ -10,11 +10,11 @@ requires = [ name = "oceans" description = "Misc functions for oceanographic data analysis" readme = "README.md" -license = {file = "LICENSE.txt"} +license = { file = "LICENSE.txt" } maintainers = [ - {name = "André Palóczy"}, - {name = "Arnaldo Russo"}, - {name = "Filipe Fernandes", email = "ocefpaf+oceans@gmail.com"}, + { name = "André Palóczy" }, + { name = "Arnaldo Russo" }, + { name = "Filipe Fernandes", email = "ocefpaf+oceans@gmail.com" }, ] requires-python = ">=3.10" classifiers = [ @@ -27,69 +27,71 @@ dynamic = [ "dependencies", "version", ] -[project.optional-dependencies] -extras = [ +optional-dependencies.extras = [ "cartopy", "iris", "netcdf4", "pandas", "scipy", ] -[project.urls] -documentation = "https://pyoceans.github.io/python-oceans/" -homepage = "https://pypi.python.org/pypi/oceans/" -repository = "https://github.com/pyoceans/python-oceans" +urls.documentation = "https://pyoceans.github.io/python-oceans/" +urls.homepage = "https://pypi.python.org/pypi/oceans/" +urls.repository = "https://github.com/pyoceans/python-oceans" [tool.setuptools] -packages = ["oceans"] +packages = [ "oceans" ] zip-safe = false include-package-data = true [tool.setuptools.dynamic] -dependencies = {file = ["requirements.txt"]} +dependencies = { file = [ "requirements.txt" ] } [tool.setuptools.package-data] -oceans = ["colormaps/cmap_data/*.dat"] +oceans = [ "colormaps/cmap_data/*.dat" ] [tool.setuptools_scm] write_to = "oceans/_version.py" write_to_template = "__version__ = '{version}'" [tool.ruff] -lint.select = [ - "A", # flake8-builtins - "B", # flake8-bugbear - "C4", # flake8-comprehensions - "F", # flakes - "I", # import sorting - "T20", # flake8-print - "UP", # upgrade -] target-version = "py311" line-length = 79 +lint.select = [ + "A", # flake8-builtins + "B", # flake8-bugbear + "C4", # flake8-comprehensions + "F", # flakes + "I", # import sorting + "T20", # flake8-print + "UP", # upgrade +] lint.ignore = [ - "B905", # zip ztrict arg, enable only for py310 + "B905", # zip ztrict arg, enable only for py310 ] -[tool.ruff.lint.per-file-ignores] -"docs/source/conf.py" = ["E402", "A001"] -"oceans/plotting.py" = ["T201"] # `print` found +lint.per-file-ignores."docs/source/conf.py" = [ + "A001", + "E402", +] +lint.per-file-ignores."oceans/plotting.py" = [ + "T201", +] # `print` found [tool.check-manifest] ignore = [ - ".coveragerc", - "docs", - "docs/*", - "notebooks", - "notebooks/*", - "tests", - "tests/*", + ".coveragerc", + "docs", + "docs/*", + "notebooks", + "notebooks/*", + "tests", + "tests/*", ] [tool.pytest.ini_options] markers = [ - "web: marks tests require connection (deselect with '-m \"not web\"')" - ] + "web: marks tests require connection (deselect with '-m \"not web\"')", +] [tool.interrogate] ignore-init-method = true @@ -99,7 +101,7 @@ ignore-semiprivate = false ignore-private = false ignore-module = false fail-under = 95 -exclude = ["docs", "tests"] +exclude = [ "docs", "tests" ] verbose = 1 quiet = false color = true From 2eab004e03b7746b9d6b8ee69792e8d8d0e8fc95 Mon Sep 17 00:00:00 2001 From: Filipe Fernandes Date: Tue, 30 Jul 2024 22:36:40 +0200 Subject: [PATCH 4/5] fix np20, wao url, pandas delta deprecation --- oceans/RPSstuff.py | 14 +++++++------- oceans/datasets.py | 2 +- oceans/filters.py | 14 +++++++------- oceans/ocfis.py | 15 ++++++++------- oceans/sw_extras/gamma_GP_from_SP_pt.py | 4 ++-- oceans/sw_extras/sw_extras.py | 8 ++++---- oceans/sw_extras/waves.py | 6 +++--- 7 files changed, 32 insertions(+), 31 deletions(-) diff --git a/oceans/RPSstuff.py b/oceans/RPSstuff.py index 85db246..33501e6 100644 --- a/oceans/RPSstuff.py +++ b/oceans/RPSstuff.py @@ -13,7 +13,7 @@ def h2hms(hours): Examples -------- >>> h2hms(12.51) - (12.0, 30.0, 36.0) + (np.float64(12.0), np.float64(30.0), np.float64(36.0)) """ hour = np.floor(hours) @@ -33,7 +33,7 @@ def hms2h(h, m=None, s=None): 12.51 >>> # Or, >>> hms2h(123036) - 12.51 + np.float64(12.51) """ if not m and not s: @@ -55,7 +55,7 @@ def ms2hms(millisecs): Examples -------- >>> ms2hms(1e3 * 60) - (0.0, 1.0, 0.0) + (np.float64(0.0), np.float64(1.0), np.float64(0.0)) """ sec = np.round(millisecs / 1000) @@ -233,7 +233,7 @@ def s2hms(secs): Examples -------- >>> s2hms(3600 + 60 + 1) - (1.0, 1.0, 1) + (np.float64(1.0), np.float64(1.0), np.int64(1)) """ hr = np.floor(secs / 3600) @@ -509,7 +509,7 @@ def fixcoast(coast): """ ind = coast == -99999.0 - coast[ind] = np.NaN + coast[ind] = np.nan ind = np.where(np.isnan(coast[:, 0]))[0] dind = np.diff(ind) @@ -518,9 +518,9 @@ def fixcoast(coast): coast = np.delete(coast, ind[idup], axis=0) if not np.isnan(coast[0, 0]): - coast = np.insert(coast, 0, np.NaN, axis=0) + coast = np.insert(coast, 0, np.nan, axis=0) if not np.isnan(coast[-1, -1]): - coast = np.append(coast, np.c_[np.NaN, np.NaN], axis=0) + coast = np.append(coast, np.c_[np.nan, np.nan], axis=0) return coast diff --git a/oceans/datasets.py b/oceans/datasets.py index 815d63b..edfe935 100644 --- a/oceans/datasets.py +++ b/oceans/datasets.py @@ -28,7 +28,7 @@ def _woa_variable(variable): def _woa_url(variable, time_period, resolution): - base = "https://data.nodc.noaa.gov/thredds/dodsC" + base = "https://www.ncei.noaa.gov/thredds-ocean/dodsC" v = _woa_variable(variable) diff --git a/oceans/filters.py b/oceans/filters.py index 67dc971..ea95e26 100644 --- a/oceans/filters.py +++ b/oceans/filters.py @@ -205,7 +205,7 @@ def smoo2(A, hei, wid, kind="hann", badflag=-9999, beta=14): A = np.asanyarray(A) Fnan = np.isnan(A) imax, jmax = A.shape - As = np.NaN * np.ones((imax, jmax)) + As = np.nan * np.ones((imax, jmax)) for i in range(imax): for j in range(jmax): @@ -257,7 +257,7 @@ def smoo2(A, hei, wid, kind="hann", badflag=-9999, beta=14): a = Ac * wdwc As[i, j] = a.sum() / wdwc.sum() # Assigning NaN to the positions holding NaNs in the original array. - As[Fnan] = np.NaN + As[Fnan] = np.nan return As @@ -329,7 +329,7 @@ def weim(x, N, kind="hann", badflag=-9999, beta=14): ln = (N - 1) / 2 lx = x.size lf = lx - ln - xs = np.NaN * np.ones(lx) + xs = np.nan * np.ones(lx) # Eliminating bad data from mean computation. fbad = x == badflag @@ -459,7 +459,7 @@ def medfilt1(x, L=3): msg = "Input sequence has to be 1d: ndim = {}".format raise ValueError(msg(xin.ndim)) - xout = np.zeros_like(xin) + np.NaN + xout = np.zeros_like(xin) + np.nan Lwing = (L - 1) // 2 @@ -538,7 +538,7 @@ def md_trenberth(x): >>> filtered = md_trenberth(x) >>> fig, ax = plt.subplots() >>> (l1,) = ax.plot(t, x, label="original") - >>> pad = [np.NaN] * 5 + >>> pad = [np.nan] * 5 >>> (l2,) = ax.plot(t, np.r_[pad, filtered, pad], label="filtered") >>> legend = ax.legend() @@ -598,9 +598,9 @@ def pl33tn(x, dt=1.0, T=33.0, mode="valid", t=None): >>> filtered_33d3 = pl33tn(x, dt=4.0, T=72.0) # 3 day filter >>> fig, ax = plt.subplots() >>> (l1,) = ax.plot(t, x, label="original") - >>> pad = [np.NaN] * 8 + >>> pad = [np.nan] * 8 >>> (l2,) = ax.plot(t, np.r_[pad, filtered_33, pad], label="33 hours") - >>> pad = [np.NaN] * 17 + >>> pad = [np.nan] * 17 >>> (l3,) = ax.plot(t, np.r_[pad, filtered_33d3, pad], label="3 days") >>> legend = ax.legend() diff --git a/oceans/ocfis.py b/oceans/ocfis.py index 43e2173..90650af 100644 --- a/oceans/ocfis.py +++ b/oceans/ocfis.py @@ -4,6 +4,7 @@ import gsw import numpy as np import numpy.ma as ma +import pandas as pd def spdir2uv(spd, ang, deg=False): @@ -583,7 +584,7 @@ def bin_dates(self, freq, tz=None): >>> from pandas import Series, date_range >>> n = 24 * 30 >>> sig = np.random.rand(n) + 2 * np.cos(2 * np.pi * np.arange(n)) - >>> dates = date_range(start="1/1/2000", periods=n, freq="H") + >>> dates = date_range(start="1/1/2000", periods=n, freq="h") >>> series = Series(data=sig, index=dates) >>> new_series = bin_dates(series, freq="D", tz=None) @@ -593,7 +594,7 @@ def bin_dates(self, freq, tz=None): new_index = date_range(start=self.index[0], end=self.index[-1], freq=freq, tz=tz) new_series = self.groupby(new_index.asof).mean() # Averages at the center. - secs = new_index.freq.delta.total_seconds() + secs = pd.Timedelta(new_index.freq).total_seconds() new_series.index = new_series.index.values + int(secs // 2) return new_series @@ -625,7 +626,7 @@ def series_spline(self): def despike(self, n=3, recursive=False): """ - Replace spikes with np.NaN. + Replace spikes with np.nan. Removing spikes that are >= n * std. default n = 3. @@ -638,12 +639,12 @@ def despike(self, n=3, recursive=False): ) removed = np.count_nonzero(outliers) - result[outliers] = np.NaN + result[outliers] = np.nan counter = 0 if recursive: while outliers.any(): - result[outliers] = np.NaN + result[outliers] = np.nan base = np.abs(result - np.nanmean(result)) outliers = base >= n * np.nanstd(result) counter += 1 @@ -658,7 +659,7 @@ def pol2cart(theta, radius, units="deg"): Examples -------- >>> pol2cart(0, 1, units="deg") - (1.0, 0.0) + (np.float64(1.0), np.float64(0.0)) """ if units in ["deg", "degs"]: @@ -781,7 +782,7 @@ def get_profile(x, y, f, xi, yi, mode="nearest", order=3): return map_coordinates(f, coords, mode=mode, order=order) -def strip_mask(arr, fill_value=np.NaN): +def strip_mask(arr, fill_value=np.nan): """ Take a masked array and return its data(filled) + mask. diff --git a/oceans/sw_extras/gamma_GP_from_SP_pt.py b/oceans/sw_extras/gamma_GP_from_SP_pt.py index 250f558..638c904 100644 --- a/oceans/sw_extras/gamma_GP_from_SP_pt.py +++ b/oceans/sw_extras/gamma_GP_from_SP_pt.py @@ -445,7 +445,7 @@ def gamma_GP_from_SP_pt(SP, pt, p, lon, lat): gamma_Pac = gamma_G_pacific(SP, pt) gamma_Ind = gamma_G_indian(SP, pt) gamma_SOce = gamma_G_southern_ocean(SP, pt, p) - # gamma_Arc = np.zeros_like(SP) * np.NaN + # gamma_Arc = np.zeros_like(SP) * np.nan # Definition of the Indian part. io_lon = np.array( @@ -590,7 +590,7 @@ def gamma_GP_from_SP_pt(SP, pt, p, lon, lat): gamma_GP = w_so * gamma_SOce + (1.0 - w_so) * gamma_middle # Set NaN in the arctic region. - gamma_GP[lat > 66.0] = np.NaN + gamma_GP[lat > 66.0] = np.nan # De-normalization. gamma_GP = 20.0 * gamma_GP - 20 diff --git a/oceans/sw_extras/sw_extras.py b/oceans/sw_extras/sw_extras.py index e25c1d3..e7c106e 100644 --- a/oceans/sw_extras/sw_extras.py +++ b/oceans/sw_extras/sw_extras.py @@ -321,7 +321,7 @@ def cor_beta(lat): -------- >>> import oceans.sw_extras.sw_extras as swe >>> swe.cor_beta(0) - 2.2891225867210798e-11 + np.float64(2.2891225867210798e-11) References ---------- @@ -358,7 +358,7 @@ def inertial_period(lat): >>> import oceans.sw_extras.sw_extras as swe >>> lat = 30.0 >>> swe.inertial_period(lat) / 3600 - 23.93484986278565 + np.float64(23.93484986278565) """ lat = np.asanyarray(lat) @@ -427,7 +427,7 @@ def visc(s, t, p): -------- >>> import oceans.sw_extras.sw_extras as swe >>> swe.visc(40.0, 40.0, 1000.0) - 8.200192496633804e-07 + np.float64(8.200192496633804e-07) Modifications: Original 1998/01/19 - Ayal Anis 1998 @@ -466,7 +466,7 @@ def tcond(s, t, p): -------- >>> import oceans.sw_extras.sw_extras as swe >>> swe.tcond(35, 20, 0) - 0.5972445569999999 + np.float64(0.5972445569999999) References ---------- diff --git a/oceans/sw_extras/waves.py b/oceans/sw_extras/waves.py index 46eac4f..0d29a73 100644 --- a/oceans/sw_extras/waves.py +++ b/oceans/sw_extras/waves.py @@ -144,8 +144,8 @@ def __init__(self, h, T=None, L=None, thetao=None, Ho=None, lat=None): self.Ks = np.sqrt(1 / (1 + self.G) / np.tanh(self.k * self.h)) if thetao is None: - self.theta = np.NaN - self.Kr = np.NaN + self.theta = np.nan + self.Kr = np.nan if thetao is not None: self.theta = np.rad2deg( np.asin(self.C / self.Co * np.sin(np.deg2rad(self.thetao))), @@ -155,6 +155,6 @@ def __init__(self, h, T=None, L=None, thetao=None, Ho=None, lat=None): ) if Ho is None: - self.H = np.NaN + self.H = np.nan if Ho is not None: self.H = self.Ho * self.Ks * self.Kr From 10772d84673483d76010561a4be381e80787a37e Mon Sep 17 00:00:00 2001 From: Filipe Fernandes Date: Tue, 30 Jul 2024 22:38:50 +0200 Subject: [PATCH 5/5] fix f-strings --- oceans/colormaps.py | 4 ++-- oceans/filters.py | 4 ++-- oceans/plotting.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/oceans/colormaps.py b/oceans/colormaps.py index 7267501..3229465 100644 --- a/oceans/colormaps.py +++ b/oceans/colormaps.py @@ -142,7 +142,7 @@ def load_cmap(fname): } # Data colormaps. -for fname in glob("%s/*.dat" % cmap_path): +for fname in glob(f"{cmap_path}/*.dat"): cmap = os.path.basename(fname).split(".")[0] data = load_cmap(fname) arrays.update({cmap: data}) @@ -150,7 +150,7 @@ def load_cmap(fname): cm = Bunch() for key, value in arrays.items(): cm.update({key: cmat2cmpl(value)}) - cm.update({"%s_r" % key: cmat2cmpl(value, reverse=True)}) + cm.update({f"{key}_r": cmat2cmpl(value, reverse=True)}) def demo(): diff --git a/oceans/filters.py b/oceans/filters.py index ea95e26..590ba27 100644 --- a/oceans/filters.py +++ b/oceans/filters.py @@ -178,7 +178,7 @@ def smoo2(A, hei, wid, kind="hann", badflag=-9999, beta=14): # Checking window type and dimensions kinds = ["hann", "hamming", "blackman", "bartlett", "kaiser"] if kind not in kinds: - raise ValueError("Invalid window type requested: %s" % kind) + raise ValueError(f"Invalid window type requested: {kind}") if (np.mod(hei, 2) == 0) or (np.mod(wid, 2) == 0): raise ValueError("Window dimensions must be odd") @@ -302,7 +302,7 @@ def weim(x, N, kind="hann", badflag=-9999, beta=14): # Checking window type and dimensions. kinds = ["hann", "hamming", "blackman", "bartlett", "kaiser"] if kind not in kinds: - raise ValueError("Invalid window type requested: %s" % kind) + raise ValueError(f"Invalid window type requested: {kind}") if np.mod(N, 2) == 0: raise ValueError("Window size must be odd") diff --git a/oceans/plotting.py b/oceans/plotting.py index 0dc5519..7a7bacc 100644 --- a/oceans/plotting.py +++ b/oceans/plotting.py @@ -130,7 +130,7 @@ def level_colormap(levels, cmap=None): cdict = {"red": tuple(R), "green": tuple(G), "blue": tuple(B)} return matplotlib.colors.LinearSegmentedColormap( - "%s_levels" % cmap.name, + f"{cmap.name}_levels", cdict, 256, )