diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 26a582c..d592958 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,7 +14,7 @@ repos: files: requirements-dev.txt - repo: https://github.com/keewis/blackdoc - rev: v0.3.9 + rev: v0.4.1 hooks: - id: blackdoc @@ -39,7 +39,7 @@ repos: - id: add-trailing-comma - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.11.12 + rev: v0.12.2 hooks: - id: ruff args: ["--fix", "--show-fixes"] diff --git a/README.md b/README.md index 11794b3..65e0091 100644 --- a/README.md +++ b/README.md @@ -33,11 +33,11 @@ and then, from pathlib import Path import ctd -path = Path('tests', 'data', 'CTD') -fname = path.joinpath('g01l06s01.cnv.gz') +path = Path("tests", "data", "CTD") +fname = path.joinpath("g01l06s01.cnv.gz") down, up = ctd.from_cnv(fname).split() -ax = down['t090C'].plot_cast() +ax = down["t090C"].plot_cast() ``` ![Bad Processing](https://raw.githubusercontent.com/pyoceans/python-ctd/main/docs/readme_01.png) @@ -45,22 +45,19 @@ ax = down['t090C'].plot_cast() We can do [better](https://www.go-ship.org/Manual/McTaggart_et_al_CTD.pdf): ```python -temperature = down['t090C'] +temperature = down["t090C"] fig, ax = plt.subplots(figsize=(5.5, 6)) temperature.plot_cast(ax=ax) -temperature.remove_above_water()\ - .despike()\ - .lp_filter()\ - .press_check()\ - .interpolate(method='index', - limit_direction='both', - limit_area='inside')\ - .bindata(delta=1, method='interpolate')\ - .smooth(window_len=21, window='hanning') \ - .plot_cast(ax=ax) -ax.set_ylabel('Pressure (dbar)') -ax.set_xlabel('Temperature (°C)') +temperature.remove_above_water().despike().lp_filter().press_check().interpolate( + method="index", limit_direction="both", limit_area="inside" +).bindata(delta=1, method="interpolate").smooth( + window_len=21, window="hanning" +).plot_cast( + ax=ax +) +ax.set_ylabel("Pressure (dbar)") +ax.set_xlabel("Temperature (°C)") ``` ![Good Processing](https://raw.githubusercontent.com/pyoceans/python-ctd/main/docs/readme_02.png) diff --git a/ctd/extras.py b/ctd/extras.py index 34c79e7..12d8168 100644 --- a/ctd/extras.py +++ b/ctd/extras.py @@ -68,7 +68,7 @@ def extrap_sec( Extrapolated variable """ - from scipy.interpolate import interp1d + from scipy.interpolate import interp1d # noqa: PLC0415 new_data1 = [] for row in data: @@ -138,8 +138,8 @@ def gen_topomask( André Palóczy Filho (paloczy@gmail.com) -- October/2012 """ - import gsw - from scipy.interpolate import interp1d + import gsw # noqa: PLC0415 + from scipy.interpolate import interp1d # noqa: PLC0415 h, lon, lat = list(map(np.asanyarray, (h, lon, lat))) # Distance in km. @@ -160,7 +160,7 @@ def plot_section( # noqa: PLR0915 **kw: dict, ) -> tuple: """Plot a sequence of CTD casts as a section.""" - import gsw + import gsw # noqa: PLC0415 lon, lat, data = list( map(np.asanyarray, (self.lon, self.lat, self.to_numpy())), @@ -298,7 +298,7 @@ def barrier_layer_thickness(sa: pd.Series, ct: pd.Series) -> pd.Series: using density. """ - import gsw + import gsw # noqa: PLC0415 sigma_theta = gsw.sigma0(sa, ct) mask = mixed_layer_depth(ct) diff --git a/ctd/processing.py b/ctd/processing.py index fe86784..36f64df 100644 --- a/ctd/processing.py +++ b/ctd/processing.py @@ -13,7 +13,7 @@ def _rolling_window(data: np.ndarray, block: int) -> np.ndarray: Using strides for an efficient moving average filter. """ - shape = data.shape[:-1] + (data.shape[-1] - block + 1, block) + shape = *data.shape[:-1], *(data.shape[-1] - block + 1, block) strides = (*data.strides, data.strides[-1]) return np.lib.stride_tricks.as_strided(data, shape=shape, strides=strides) @@ -80,7 +80,7 @@ def lp_filter( https://scipy-cookbook.readthedocs.io/items/FIRFilter.html """ - from scipy import signal + from scipy import signal # noqa: PLC0415 # Butter is closer to what SBE is doing with their cosine filter. wn = (1.0 / time_constant) / (sample_rate * 2.0)