Skip to content
Merged
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 .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"]
Expand Down
29 changes: 13 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,31 @@ 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)

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)
Expand Down
10 changes: 5 additions & 5 deletions ctd/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -138,8 +138,8 @@ def gen_topomask(
André Palóczy Filho ([email protected]) -- 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.
Expand All @@ -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())),
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions ctd/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down