Skip to content

Commit

Permalink
Merge pull request #509 from OpenCOMPES/style_fixes
Browse files Browse the repository at this point in the history
Style fixes
  • Loading branch information
rettigl authored Nov 13, 2024
2 parents 49b4b02 + 7ff8fc2 commit 8ecde26
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 53 deletions.
5 changes: 5 additions & 0 deletions .cspell/custom-dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ scicat
SDIAG
sdir
segs
setp
sfile
shutil
Sixten
Expand Down Expand Up @@ -404,6 +405,8 @@ xpos
xratio
xrng
xscale
xticklabels
xticks
xtrans
Xuser
xval
Expand All @@ -414,6 +417,8 @@ ylabel
ypos
yratio
yscale
yticklabels
yticks
ytrans
zain
Zenodo
Expand Down
6 changes: 0 additions & 6 deletions docs/user_guide/advanced_topics.md

This file was deleted.

6 changes: 3 additions & 3 deletions docs/user_guide/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ The config mechanism returns the combined dictionary, and reports the loaded con

## Default configuration settings

```{literalinclude} ../../sed/config/default.yaml
```{literalinclude} ../../config/default.yaml
:language: yaml
```

## Example configuration file for mpes (METIS momentum microscope at FHI-Berlin)

```{literalinclude} ../../sed/config/mpes_example_config.yaml
```{literalinclude} ../../config/mpes_example_config.yaml
:language: yaml
```

## Example configuration file for flash (HEXTOF momentum microscope at FLASH, Desy)

```{literalinclude} ../../sed/config/flash_example_config.yaml
```{literalinclude} ../../config/flash_example_config.yaml
:language: yaml
```
5 changes: 3 additions & 2 deletions docs/user_guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ config
```

## Advanced Topics

```{toctree}
:maxdepth: 1
advanced_topics
../tutorial/6_binning_with_time-stamped_data
../tutorial/7_correcting_orthorhombic_symmetry
../tutorial/8_jittering_tutorial
```
26 changes: 17 additions & 9 deletions src/sed/calibrator/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,11 @@ def adjust_ranges(

# make plot
labels = kwds.pop("labels", [str(b) + " V" for b in self.biases])
figsize = kwds.pop("figsize", (8, 4))
figsize = kwds.pop("figsize", (6, 4))
plot_segs = []
plot_peaks = []
fig, ax = plt.subplots(figsize=figsize)
colors = plt.get_cmap("rainbow")(np.linspace(0, 1, len(traces)))
colors = it.cycle(plt.rcParams["axes.prop_cycle"].by_key()["color"])
for itr, color in zip(range(len(traces)), colors):
trace = traces[itr, :]
# main traces
Expand All @@ -378,6 +378,9 @@ def adjust_ranges(
plot_peaks.append(scatt)
ax.legend(fontsize=8, loc="upper right")
ax.set_title("")
plt.xlabel("Time-of-flight")
plt.ylabel("Intensity")
plt.tight_layout()

def update(refid, ranges):
self.add_ranges(ranges, refid, traces=traces, **kwds)
Expand Down Expand Up @@ -664,15 +667,19 @@ def view(

sign = 1 if energy_scale == "kinetic" else -1

figsize = kwds.pop("figsize", (6, 4))

if backend == "matplotlib":
figsize = kwds.pop("figsize", (6, 4))
fig_plt, ax = plt.subplots(figsize=figsize)
for itr, trace in enumerate(traces):
colors = it.cycle(plt.rcParams["axes.prop_cycle"].by_key()["color"])
_, ax = plt.subplots(figsize=figsize)
for itr, color in zip(range(len(traces)), colors):
trace = traces[itr, :]
if align:
ax.plot(
xaxis + sign * (self.biases[itr]),
trace,
ls="-",
color=color,
linewidth=1,
label=lbs[itr],
**linekwds,
Expand All @@ -682,6 +689,7 @@ def view(
xaxis,
trace,
ls="-",
color=color,
linewidth=1,
label=lbs[itr],
**linekwds,
Expand All @@ -696,6 +704,7 @@ def view(
tofseg,
traceseg,
ls="-",
color=color,
linewidth=2,
**linesegkwds,
)
Expand All @@ -710,7 +719,7 @@ def view(

if show_legend:
try:
ax.legend(fontsize=12, **legkwds)
ax.legend(fontsize=8, loc="upper right", **legkwds)
except TypeError:
pass

Expand All @@ -721,11 +730,10 @@ def view(
colors = it.cycle(ColorCycle[10])
ttp = [("(x, y)", "($x, $y)")]

figsize = kwds.pop("figsize", (800, 300))
fig = pbk.figure(
title=ttl,
width=figsize[0],
height=figsize[1],
width=figsize[0] * 100,
height=figsize[1] * 100,
tooltips=ttp,
)
# Plotting the main traces
Expand Down
29 changes: 17 additions & 12 deletions src/sed/calibrator/momentum.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def __init__(
self.include_center: bool = False
self.use_center: bool = False
self.pouter: np.ndarray = None
self.pcent: tuple[float, ...] = None
self.pcent: tuple[float, float] = None
self.pouter_ord: np.ndarray = None
self.prefs: np.ndarray = None
self.ptargs: np.ndarray = None
Expand Down Expand Up @@ -1348,7 +1348,9 @@ def view(

if annotated:
tsr, tsc = kwds.pop("textshift", (3, 3))
txtsize = kwds.pop("textsize", 12)
txtsize = kwds.pop("textsize", 10)

title = kwds.pop("title", "")

# Handle unexpected kwds:
handled_kwds = {"figsize"}
Expand All @@ -1358,7 +1360,7 @@ def view(
)

if backend == "matplotlib":
fig_plt, ax = plt.subplots(figsize=figsize)
_, ax = plt.subplots(figsize=figsize)
ax.imshow(image.T, origin=origin, cmap=cmap, **imkwds)

if cross:
Expand All @@ -1368,15 +1370,12 @@ def view(

# Add annotation to the figure
if annotated:
for (
p_keys, # pylint: disable=unused-variable
p_vals,
) in points.items():
for p_keys, p_vals in points.items():
try:
ax.scatter(p_vals[:, 0], p_vals[:, 1], **scatterkwds)
ax.scatter(p_vals[:, 0], p_vals[:, 1], s=15, **scatterkwds)
except IndexError:
try:
ax.scatter(p_vals[0], p_vals[1], **scatterkwds)
ax.scatter(p_vals[0], p_vals[1], s=15, **scatterkwds)
except IndexError:
pass

Expand All @@ -1389,15 +1388,21 @@ def view(
fontsize=txtsize,
)

if crosshair and self.pcent is not None:
for radius in crosshair_radii:
circle = plt.Circle(self.pcent, radius, color="k", fill=False)
ax.add_patch(circle)

ax.set_title(title)

elif backend == "bokeh":
output_notebook(hide_banner=True)
colors = it.cycle(ColorCycle[10])
ttp = [("(x, y)", "($x, $y)")]
figsize = kwds.pop("figsize", (320, 300))
palette = cm2palette(cmap) # Retrieve palette colors
fig = pbk.figure(
width=figsize[0],
height=figsize[1],
width=figsize[0] * 100,
height=figsize[1] * 100,
tooltips=ttp,
x_range=(0, num_rows),
y_range=(0, num_cols),
Expand Down
27 changes: 17 additions & 10 deletions src/sed/core/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,24 +649,28 @@ def generate_splinewarp(
self.mc.spline_warp_estimate(use_center=use_center, **kwds)

if self.mc.slice is not None and self._verbose:
print("Original slice with reference features")
self.mc.view(annotated=True, backend="bokeh", crosshair=True)
self.mc.view(
annotated=True,
backend="matplotlib",
crosshair=True,
title="Original slice with reference features",
)

print("Corrected slice with target features")
self.mc.view(
image=self.mc.slice_corrected,
annotated=True,
points={"feats": self.mc.ptargs},
backend="bokeh",
backend="matplotlib",
crosshair=True,
title="Corrected slice with target features",
)

print("Original slice with target features")
self.mc.view(
image=self.mc.slice,
points={"feats": self.mc.ptargs},
annotated=True,
backend="bokeh",
backend="matplotlib",
title="Original slice with target features",
)

# 3a. Save spline-warp parameters to config file.
Expand Down Expand Up @@ -1243,8 +1247,11 @@ def load_bias_series(
self.ec.view(
traces=self.ec.traces_normed,
xaxis=self.ec.tof,
backend="bokeh",
backend="matplotlib",
)
plt.xlabel("Time-of-flight")
plt.ylabel("Intensity")
plt.tight_layout()

# 2. extract ranges and get peak positions
@call_logger(logger)
Expand Down Expand Up @@ -1303,7 +1310,7 @@ def find_bias_peaks(
segs=self.ec.featranges,
xaxis=self.ec.tof,
peaks=self.ec.peaks,
backend="bokeh",
backend="matplotlib",
)
except IndexError:
logger.error("Could not determine all peaks!")
Expand Down Expand Up @@ -2381,7 +2388,7 @@ def view_event_histogram(
bins: Sequence[int] = None,
axes: Sequence[str] = None,
ranges: Sequence[tuple[float, float]] = None,
backend: str = "bokeh",
backend: str = "matplotlib",
legend: bool = True,
histkwds: dict = None,
legkwds: dict = None,
Expand All @@ -2400,7 +2407,7 @@ def view_event_histogram(
ranges (Sequence[tuple[float, float]], optional): Value ranges of all
specified axes. Defaults to config["histogram"]["ranges"].
backend (str, optional): Backend of the plotting library
('matplotlib' or 'bokeh'). Defaults to "bokeh".
("matplotlib" or "bokeh"). Defaults to "matplotlib".
legend (bool, optional): Option to include a legend in the histogram plots.
Defaults to True.
histkwds (dict, optional): Keyword arguments for histograms
Expand Down
Loading

0 comments on commit 8ecde26

Please sign in to comment.