Skip to content

Commit 272add8

Browse files
committed
ci: pre-commit
1 parent 17668aa commit 272add8

9 files changed

Lines changed: 37 additions & 78 deletions

File tree

docs/scripts/fetch_paraview_presets.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
from pathlib import Path
3535

3636
SOURCE_URL = (
37-
"https://gitlab.kitware.com/paraview/paraview/"
38-
"-/raw/master/Remoting/Views/ColorMaps.json"
37+
"https://gitlab.kitware.com/paraview/paraview/-/raw/master/Remoting/Views/ColorMaps.json"
3938
)
4039
SOURCE_LICENSE = "BSD-3-Clause"
4140

examples/wavelet.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
#!/usr/bin/env -S uv run --script
2+
#
3+
# /// script
4+
# requires-python = ">=3.11"
5+
# dependencies = [
6+
# "trame>=3.13.2",
7+
# "trame-colormaps>=1",
8+
# "trame-vtk",
9+
# "trame-vuetify",
10+
# ]
11+
# ///
112
"""Example: Wavelet with clipped contour + slice plane.
213
314
A fully synthetic VTK pipeline that demonstrates trame-colormaps:
@@ -184,9 +195,7 @@ def _build_ui(self):
184195
),
185196
self.left.provide_as("left"),
186197
):
187-
with html.Div(
188-
style="position:absolute;top:0;bottom:0;left:0;right:0;"
189-
):
198+
with html.Div(style="position:absolute;top:0;bottom:0;left:0;right:0;"):
190199
VerticalScalarBar("left", popup_location="right")
191200

192201
# Middle
@@ -207,9 +216,7 @@ def _build_ui(self):
207216
),
208217
self.right.provide_as("right"),
209218
):
210-
with html.Div(
211-
style="position:absolute;top:0;bottom:0;left:0;right:0;"
212-
):
219+
with html.Div(style="position:absolute;top:0;bottom:0;left:0;right:0;"):
213220
VerticalScalarBar("right", popup_location="left")
214221

215222
# Bottom

src/trame_colormaps/core/presets.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,15 @@ def load(filename):
4545
color_blind = {n for n, p in registry.items() if p.get("ColorBlindSafe", False)}
4646
defaults_path = _PRESET_DIR / "default_presets.json"
4747
defaults = (
48-
json.loads(defaults_path.read_text())
49-
if defaults_path.exists()
50-
else sorted(all_names)
48+
json.loads(defaults_path.read_text()) if defaults_path.exists() else sorted(all_names)
5149
)
5250

5351
# Category-based preset sets
54-
diverging = {
55-
n for n, p in registry.items() if p.get("Category", "").lower() == "diverging"
56-
}
52+
diverging = {n for n, p in registry.items() if p.get("Category", "").lower() == "diverging"}
5753
sequential = {
5854
n for n, p in registry.items() if p.get("Category", "").lower() == "sequential"
5955
}
60-
cyclic = {
61-
n for n, p in registry.items() if p.get("Category", "").lower() == "cyclic"
62-
}
56+
cyclic = {n for n, p in registry.items() if p.get("Category", "").lower() == "cyclic"}
6357
categorical = {
6458
n
6559
for n, p in registry.items()

src/trame_colormaps/core/ticks.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,10 @@ def get_nice_ticks(vmin, vmax, n, scale="linear", linthresh=None):
5151
# Filter out ticks too close to edges
5252
if len(raw_ticks) > 0:
5353
raw_ticks = raw_ticks[
54-
(raw_ticks > vmin + data_range * 0.01)
55-
& (raw_ticks < vmax - data_range * 0.01)
54+
(raw_ticks > vmin + data_range * 0.01) & (raw_ticks < vmax - data_range * 0.01)
5655
]
5756
# Priority: always include 0 if range spans negative to positive
58-
if vmin < 0 < vmax and not np.any(
59-
np.isclose(raw_ticks, 0.0, atol=nice_step * 1e-9)
60-
):
57+
if vmin < 0 < vmax and not np.any(np.isclose(raw_ticks, 0.0, atol=nice_step * 1e-9)):
6158
raw_ticks = np.sort(np.append(raw_ticks, 0.0))
6259
return raw_ticks
6360
elif scale == "log":

src/trame_colormaps/core/transforms.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,7 @@ def _sl(v):
222222
new_rgb_points.extend([float(x_min), clamp_r, clamp_g, clamp_b])
223223
display_rgb_points.extend([float(x_min), clamp_r, clamp_g, clamp_b])
224224
d_lt = x_min + lt_disp_frac * data_range
225-
new_rgb_points.extend(
226-
[float(linthresh) - data_range * 1e-9, clamp_r, clamp_g, clamp_b]
227-
)
225+
new_rgb_points.extend([float(linthresh) - data_range * 1e-9, clamp_r, clamp_g, clamp_b])
228226
display_rgb_points.extend([d_lt - data_range * 1e-9, clamp_r, clamp_g, clamp_b])
229227

230228
# --- Region 2: [linthresh, x_max] — log-mapped ---
@@ -594,9 +592,7 @@ def symlog(v):
594592
neg_outward = list(reversed(neg))
595593
thinned_neg = [neg_outward[i] for i in range(0, len(neg_outward), 2)]
596594
thinned_pos = [pos[i] for i in range(0, len(pos), 2)]
597-
discrete_tick_data = sorted(
598-
thinned_neg + zero + thinned_pos, key=lambda t: t["val"]
599-
)
595+
discrete_tick_data = sorted(thinned_neg + zero + thinned_pos, key=lambda t: t["val"])
600596
else:
601597
discrete_tick_data = all_tick_data
602598

src/trame_colormaps/dataclasses.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -481,15 +481,11 @@ def _sl(v):
481481
pos = (float(_sl(val)) - sl_min) / sl_range * 100
482482
else:
483483
pos = (val - vmin) / data_range * 100
484-
ticks.append(
485-
{"position": round(pos, 2), "label": format_log_tick(val)}
486-
)
484+
ticks.append({"position": round(pos, 2), "label": format_log_tick(val)})
487485

488486
# Sample colors from the *linear* CTF so tick contrast matches the
489487
# displayed colorbar image, not the log/symlog-remapped rendering CTF.
490-
rgb_points = (
491-
linear_rgb_points if linear_rgb_points else get_rgb_points(self._ctf)
492-
)
488+
rgb_points = linear_rgb_points if linear_rgb_points else get_rgb_points(self._ctf)
493489
if len(rgb_points) < 4:
494490
self.color_ticks = []
495491
return
@@ -715,9 +711,7 @@ def update_color_preset(
715711
self.lut_img_v = result[1]
716712
elif log_scale == "symlog":
717713
if discrete_log:
718-
result = apply_discrete_symlog(
719-
self._ctf, linthresh, linear_rgb_points, n_sub
720-
)
714+
result = apply_discrete_symlog(self._ctf, linthresh, linear_rgb_points, n_sub)
721715
if result[0] is not None:
722716
linear_rgb_points = result[0]
723717
self.lut_img_h = result[2]

src/trame_colormaps/widgets.py

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,14 @@
1414
def buttons(name):
1515
return [
1616
{
17-
"icon": (
18-
f"{name}.color_blind ? 'mdi-shield-check-outline' : 'mdi-palette'"
19-
),
17+
"icon": (f"{name}.color_blind ? 'mdi-shield-check-outline' : 'mdi-palette'"),
2018
"click": f"{name}.color_blind = !{name}.color_blind",
21-
"tip": (
22-
f"'Toggle to ' + ({name}.color_blind ? "
23-
"'All Colors' : 'Colorblind Safe')"
24-
),
19+
"tip": (f"'Toggle to ' + ({name}.color_blind ? 'All Colors' : 'Colorblind Safe')"),
2520
},
2621
{
2722
"icon": f"{name}.invert ? 'mdi-invert-colors' : 'mdi-invert-colors-off'",
2823
"click": f"{name}.invert = !{name}.invert",
29-
"tip": (
30-
f"'Toggle to ' + ({name}.invert ? 'Normal Preset' : 'Invert Preset')"
31-
),
24+
"tip": (f"'Toggle to ' + ({name}.invert ? 'Normal Preset' : 'Invert Preset')"),
3225
},
3326
{
3427
"icon": (
@@ -53,17 +46,11 @@ def buttons(name):
5346
{
5447
"icon": f"{name}.diverging ? 'mdi-triangle' : 'mdi-triangle-outline'",
5548
"click": f"{name}.diverging = !{name}.diverging",
56-
"tip": (
57-
f"'Toggle to ' + ({name}.diverging ? 'Normal Mode' : 'Difference Mode')"
58-
),
49+
"tip": (f"'Toggle to ' + ({name}.diverging ? 'Normal Mode' : 'Difference Mode')"),
5950
},
6051
{
61-
"icon": (
62-
f"{name}.override_range ? 'mdi-arrow-expand-horizontal' : 'mdi-pencil'"
63-
),
64-
"click": (
65-
f"!{name}.diverging && ({name}.override_range = !{name}.override_range)"
66-
),
52+
"icon": (f"{name}.override_range ? 'mdi-arrow-expand-horizontal' : 'mdi-pencil'"),
53+
"click": (f"!{name}.diverging && ({name}.override_range = !{name}.override_range)"),
6754
"tip": (
6855
f"{name}.diverging ? 'Range locked in Δ mode'"
6956
f" : 'Toggle to ' + ({name}.override_range ? "
@@ -72,8 +59,7 @@ def buttons(name):
7259
},
7360
{
7461
"icon": (
75-
f"{name}.discrete_log ? 'mdi-view-sequential' :"
76-
" 'mdi-gradient-horizontal'"
62+
f"{name}.discrete_log ? 'mdi-view-sequential' : 'mdi-gradient-horizontal'"
7763
),
7864
"click": f"{name}.discrete_log = !{name}.discrete_log",
7965
"tip": f"'Toggle to ' + ({name}.discrete_log ? 'Continuous' : 'Discrete')",
@@ -224,9 +210,7 @@ def __init__(self, name):
224210
f"{name}.n_colors"
225211
"]"
226212
)
227-
_v_for = (
228-
f"entry in ({name}.invert ? {name}.luts_inverted : {name}.luts_normal)"
229-
)
213+
_v_for = f"entry in ({name}.invert ? {name}.luts_inverted : {name}.luts_normal)"
230214
_v_show = (
231215
f"({name}.search && {name}.search.length"
232216
f" ? entry.name.toLowerCase().includes({name}.search.toLowerCase())"
@@ -308,9 +292,7 @@ def __init__(self, name, popup_location="top", **kwargs):
308292
class VerticalScalarBar(html.Div):
309293
def __init__(self, name, popup_location="top", **kwargs):
310294
super().__init__(
311-
classes=(
312-
"tcmap-vertical bg-blue-grey-darken-2 d-flex flex-column align-center"
313-
),
295+
classes=("tcmap-vertical bg-blue-grey-darken-2 d-flex flex-column align-center"),
314296
)
315297
self.server.enable_module(module)
316298

tests/test_ticks.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ def test_log_within_range(self):
103103
def test_log_majors_first(self):
104104
"""Majors (powers of 10) should appear before any minors."""
105105
ticks = get_nice_ticks(0, 276, 5, scale="log", linthresh=37.35)
106-
powers = [
107-
t for t in ticks if t > 0 and np.isclose(np.log10(t) % 1, 0, atol=1e-9)
108-
]
106+
powers = [t for t in ticks if t > 0 and np.isclose(np.log10(t) % 1, 0, atol=1e-9)]
109107
assert len(powers) >= 1
110108

111109
def test_log_nice_minors(self):
@@ -116,9 +114,7 @@ def test_log_nice_minors(self):
116114
continue
117115
mantissa = t / 10.0 ** int(np.floor(np.log10(t)))
118116
nice = {1, 2, 2.5, 3, 4, 5, 6, 7, 7.5, 8, 9, 10}
119-
assert any(np.isclose(mantissa, n, atol=0.01) for n in nice), (
120-
f"{t} not nice"
121-
)
117+
assert any(np.isclose(mantissa, n, atol=0.01) for n in nice), f"{t} not nice"
122118

123119
def test_symlog_has_negative_and_positive(self):
124120
ticks = get_nice_ticks(-1000, 1000, 10, scale="symlog", linthresh=1.0)
@@ -132,9 +128,5 @@ def test_symlog_includes_zero_when_space(self):
132128
def test_symlog_majors_before_minors(self):
133129
"""At least one power of 10 should be present."""
134130
ticks = get_nice_ticks(-276, 276, 9, scale="symlog", linthresh=37.35)
135-
powers = [
136-
t
137-
for t in ticks
138-
if t != 0 and np.isclose(np.log10(abs(t)) % 1, 0, atol=1e-9)
139-
]
131+
powers = [t for t in ticks if t != 0 and np.isclose(np.log10(abs(t)) % 1, 0, atol=1e-9)]
140132
assert len(powers) >= 1

tests/test_transforms.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,7 @@ def test_returns_tuple(self):
204204
apply_linear(ctf, PRESET_NAME)
205205
rescale_ctf(ctf, -1000.0, 1000.0)
206206
pts = get_rgb_points(ctf)
207-
result = apply_discrete_symlog(
208-
ctf, linthresh=1.0, linear_rgb_points=pts, n_sub=4
209-
)
207+
result = apply_discrete_symlog(ctf, linthresh=1.0, linear_rgb_points=pts, n_sub=4)
210208
assert isinstance(result, tuple)
211209
assert len(result) == 4
212210

0 commit comments

Comments
 (0)