From 1cbfd36a63c79a44f90fd527e0146c50a8a58b02 Mon Sep 17 00:00:00 2001 From: rettigl Date: Tue, 15 Oct 2024 21:26:01 +0200 Subject: [PATCH 1/7] adopt figure sizes --- src/sed/calibrator/energy.py | 19 ++++++++++++------- src/sed/calibrator/momentum.py | 5 ++--- src/sed/core/processor.py | 4 ++-- src/sed/diagnostics.py | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/sed/calibrator/energy.py b/src/sed/calibrator/energy.py index 65493f66..7f1426f9 100644 --- a/src/sed/calibrator/energy.py +++ b/src/sed/calibrator/energy.py @@ -351,7 +351,7 @@ 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) @@ -664,15 +664,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)) + colors = plt.get_cmap("rainbow")(np.linspace(0, 1, len(traces))) fig_plt, ax = plt.subplots(figsize=figsize) - for itr, trace in enumerate(traces): + 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, @@ -682,6 +686,7 @@ def view( xaxis, trace, ls="-", + color=color, linewidth=1, label=lbs[itr], **linekwds, @@ -696,6 +701,7 @@ def view( tofseg, traceseg, ls="-", + color=color, linewidth=2, **linesegkwds, ) @@ -710,7 +716,7 @@ def view( if show_legend: try: - ax.legend(fontsize=12, **legkwds) + ax.legend(fontsize=8, loc="upper right", **legkwds) except TypeError: pass @@ -721,11 +727,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 diff --git a/src/sed/calibrator/momentum.py b/src/sed/calibrator/momentum.py index 33047292..36a41b86 100644 --- a/src/sed/calibrator/momentum.py +++ b/src/sed/calibrator/momentum.py @@ -1393,11 +1393,10 @@ def view( 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), diff --git a/src/sed/core/processor.py b/src/sed/core/processor.py index f40089bb..b23dfa74 100644 --- a/src/sed/core/processor.py +++ b/src/sed/core/processor.py @@ -1243,7 +1243,7 @@ def load_bias_series( self.ec.view( traces=self.ec.traces_normed, xaxis=self.ec.tof, - backend="bokeh", + backend="matplotlib", ) # 2. extract ranges and get peak positions @@ -1303,7 +1303,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!") diff --git a/src/sed/diagnostics.py b/src/sed/diagnostics.py index 02bcc0a0..25fddd9a 100644 --- a/src/sed/diagnostics.py +++ b/src/sed/diagnostics.py @@ -88,7 +88,7 @@ def grid_histogram( if legkwds is None: legkwds = {} - figsz = kwds.pop("figsize", (14, 8)) + figsz = kwds.pop("figsize", (10, 7)) if len(kwds) > 0: raise TypeError(f"grid_histogram() got unexpected keyword arguments {kwds.keys()}.") From dd913139515a695a1e461290a6236613e8946d57 Mon Sep 17 00:00:00 2001 From: rettigl Date: Tue, 15 Oct 2024 21:44:43 +0200 Subject: [PATCH 2/7] change color map to default plt cycle --- src/sed/calibrator/energy.py | 9 ++++++--- src/sed/core/processor.py | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/sed/calibrator/energy.py b/src/sed/calibrator/energy.py index 7f1426f9..b5d055dd 100644 --- a/src/sed/calibrator/energy.py +++ b/src/sed/calibrator/energy.py @@ -355,7 +355,7 @@ def adjust_ranges( 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 @@ -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) @@ -667,8 +670,8 @@ def view( figsize = kwds.pop("figsize", (6, 4)) if backend == "matplotlib": - colors = plt.get_cmap("rainbow")(np.linspace(0, 1, len(traces))) - fig_plt, ax = plt.subplots(figsize=figsize) + 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: diff --git a/src/sed/core/processor.py b/src/sed/core/processor.py index b23dfa74..6c51acfb 100644 --- a/src/sed/core/processor.py +++ b/src/sed/core/processor.py @@ -1245,6 +1245,9 @@ def load_bias_series( xaxis=self.ec.tof, backend="matplotlib", ) + plt.xlabel("Time-of-flight") + plt.ylabel("Intensity") + plt.tight_layout() # 2. extract ranges and get peak positions @call_logger(logger) From 6f5f0333a435e79bc7b1ee814c1a28a7bdf59857 Mon Sep 17 00:00:00 2001 From: rettigl Date: Tue, 15 Oct 2024 22:54:43 +0200 Subject: [PATCH 3/7] use matplotlib also for momentum correction --- .cspell/custom-dictionary.txt | 2 ++ src/sed/calibrator/momentum.py | 22 ++++++++++++++-------- src/sed/core/processor.py | 20 ++++++++++++-------- src/sed/diagnostics.py | 23 +++++++++++++---------- 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/.cspell/custom-dictionary.txt b/.cspell/custom-dictionary.txt index 38f8c89c..88ff0b12 100644 --- a/.cspell/custom-dictionary.txt +++ b/.cspell/custom-dictionary.txt @@ -404,6 +404,7 @@ xpos xratio xrng xscale +xticks xtrans Xuser xval @@ -414,6 +415,7 @@ ylabel ypos yratio yscale +yticks ytrans zain Zenodo diff --git a/src/sed/calibrator/momentum.py b/src/sed/calibrator/momentum.py index 36a41b86..534ad81f 100644 --- a/src/sed/calibrator/momentum.py +++ b/src/sed/calibrator/momentum.py @@ -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"} @@ -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: @@ -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 @@ -1389,6 +1388,13 @@ 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]) diff --git a/src/sed/core/processor.py b/src/sed/core/processor.py index 6c51acfb..5888855d 100644 --- a/src/sed/core/processor.py +++ b/src/sed/core/processor.py @@ -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. @@ -2384,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, @@ -2403,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 diff --git a/src/sed/diagnostics.py b/src/sed/diagnostics.py index 25fddd9a..6ec8e507 100644 --- a/src/sed/diagnostics.py +++ b/src/sed/diagnostics.py @@ -59,7 +59,7 @@ def grid_histogram( rvs: Sequence, rvbins: Sequence, rvranges: Sequence[tuple[float, float]], - backend: str = "bokeh", + backend: str = "matplotlib", legend: bool = True, histkwds: dict = None, legkwds: dict = None, @@ -73,22 +73,22 @@ def grid_histogram( rvs (Sequence): List of names for the random variables (rvs). rvbins (Sequence): Bin values for all random variables. rvranges (Sequence[tuple[float, float]]): Value ranges of all random variables. - backend (str, optional): Backend for making the plot ('matplotlib' or 'bokeh'). - Defaults to "bokeh". + backend (str, optional): Backend for making the plot ("matplotlib" or "bokeh"). + Defaults to "matplotlib". legend (bool, optional): Option to include a legend in each histogram plot. Defaults to True. histkwds (dict, optional): Keyword arguments for histogram plots. Defaults to None. legkwds (dict, optional): Keyword arguments for legends. Defaults to None. **kwds: - - *figsize*: Figure size. Defaults to (14, 8) + - *figsize*: Figure size. Defaults to (6, 4) """ if histkwds is None: histkwds = {} if legkwds is None: legkwds = {} - figsz = kwds.pop("figsize", (10, 7)) + figsz = kwds.pop("figsize", (6, 4)) if len(kwds) > 0: raise TypeError(f"grid_histogram() got unexpected keyword arguments {kwds.keys()}.") @@ -96,7 +96,7 @@ def grid_histogram( if backend == "matplotlib": nrv = len(rvs) nrow = int(np.ceil(nrv / ncol)) - histtype = kwds.pop("histtype", "step") + histtype = kwds.pop("histtype", "bar") fig, ax = plt.subplots(nrow, ncol, figsize=figsz) otherax = ax.copy() @@ -114,7 +114,7 @@ def grid_histogram( **histkwds, ) if legend: - ax[axind].legend(fontsize=15, **legkwds) + ax[axind].legend(fontsize=10, **legkwds) otherax[axind] = None @@ -128,13 +128,16 @@ def grid_histogram( **histkwds, ) if legend: - ax[i].legend(fontsize=15, **legkwds) + ax[i].legend(fontsize=10, **legkwds) otherax[i] = None for oax in otherax.flatten(): if oax is not None: fig.delaxes(oax) + plt.xticks(fontsize=8) + plt.yticks(fontsize=8) + plt.tight_layout() elif backend == "bokeh": output_notebook(hide_banner=True) @@ -163,7 +166,7 @@ def grid_histogram( gridplot( plots, # type: ignore ncols=ncol, - width=figsz[0] * 30, - height=figsz[1] * 28, + width=figsz[0] * 100 // ncol, + height=figsz[1] * 100 // (len(plots) // ncol), ), ) From 366de39badeb9bae4413acec8eff344e78f3c7b8 Mon Sep 17 00:00:00 2001 From: rettigl Date: Tue, 15 Oct 2024 22:59:17 +0200 Subject: [PATCH 4/7] fix type error --- src/sed/calibrator/momentum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sed/calibrator/momentum.py b/src/sed/calibrator/momentum.py index 534ad81f..75b7425f 100644 --- a/src/sed/calibrator/momentum.py +++ b/src/sed/calibrator/momentum.py @@ -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 From 6365b930166c2f083a0c4fd8854ff5ace680936f Mon Sep 17 00:00:00 2001 From: rettigl Date: Wed, 16 Oct 2024 13:26:24 +0200 Subject: [PATCH 5/7] fix figure sizes and font sizes --- .cspell/custom-dictionary.txt | 3 +++ src/sed/diagnostics.py | 16 ++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.cspell/custom-dictionary.txt b/.cspell/custom-dictionary.txt index 88ff0b12..546e29ae 100644 --- a/.cspell/custom-dictionary.txt +++ b/.cspell/custom-dictionary.txt @@ -334,6 +334,7 @@ scicat SDIAG sdir segs +setp sfile shutil Sixten @@ -404,6 +405,7 @@ xpos xratio xrng xscale +xticklabels xticks xtrans Xuser @@ -415,6 +417,7 @@ ylabel ypos yratio yscale +yticklabels yticks ytrans zain diff --git a/src/sed/diagnostics.py b/src/sed/diagnostics.py index 6ec8e507..4f44b1f7 100644 --- a/src/sed/diagnostics.py +++ b/src/sed/diagnostics.py @@ -88,7 +88,7 @@ def grid_histogram( if legkwds is None: legkwds = {} - figsz = kwds.pop("figsize", (6, 4)) + figsz = kwds.pop("figsize", (3, 2)) # figure size of each panel if len(kwds) > 0: raise TypeError(f"grid_histogram() got unexpected keyword arguments {kwds.keys()}.") @@ -98,13 +98,16 @@ def grid_histogram( nrow = int(np.ceil(nrv / ncol)) histtype = kwds.pop("histtype", "bar") - fig, ax = plt.subplots(nrow, ncol, figsize=figsz) + figsize = [figsz[0] * ncol, figsz[1] * nrow] + fig, ax = plt.subplots(nrow, ncol, figsize=figsize) otherax = ax.copy() for i, zipped in enumerate(zip(rvs, rvbins, rvranges)): # Make each histogram plot rvname, rvbin, rvrg = zipped try: axind = np.unravel_index(i, (nrow, ncol)) + plt.setp(ax[axind].get_xticklabels(), fontsize=8) + plt.setp(ax[axind].get_yticklabels(), fontsize=8) ax[axind].hist( dct[rvname], bins=rvbin, @@ -119,6 +122,8 @@ def grid_histogram( otherax[axind] = None except IndexError: + plt.setp(ax[i].get_xticklabels(), fontsize=8) + plt.setp(ax[i].get_yticklabels(), fontsize=8) ax[i].hist( dct[rvname], bins=rvbin, @@ -135,8 +140,7 @@ def grid_histogram( for oax in otherax.flatten(): if oax is not None: fig.delaxes(oax) - plt.xticks(fontsize=8) - plt.yticks(fontsize=8) + plt.tight_layout() elif backend == "bokeh": @@ -166,7 +170,7 @@ def grid_histogram( gridplot( plots, # type: ignore ncols=ncol, - width=figsz[0] * 100 // ncol, - height=figsz[1] * 100 // (len(plots) // ncol), + width=figsz[0] * 100, + height=figsz[1] * 100, ), ) From fb0b025a0d653387d0748dc1b9e0326c27677492 Mon Sep 17 00:00:00 2001 From: rettigl Date: Wed, 13 Nov 2024 09:11:28 +0100 Subject: [PATCH 6/7] remove redundant toctree entry --- docs/user_guide/advanced_topics.md | 6 ------ docs/user_guide/index.md | 5 +++-- 2 files changed, 3 insertions(+), 8 deletions(-) delete mode 100644 docs/user_guide/advanced_topics.md diff --git a/docs/user_guide/advanced_topics.md b/docs/user_guide/advanced_topics.md deleted file mode 100644 index ebd773c8..00000000 --- a/docs/user_guide/advanced_topics.md +++ /dev/null @@ -1,6 +0,0 @@ -```{toctree} -:maxdepth: 1 -../tutorial/6_binning_with_time-stamped_data -../tutorial/7_correcting_orthorhombic_symmetry -../tutorial/8_jittering_tutorial -``` diff --git a/docs/user_guide/index.md b/docs/user_guide/index.md index 16d36aaf..12485b87 100644 --- a/docs/user_guide/index.md +++ b/docs/user_guide/index.md @@ -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 ``` From 7ff8fc2a7a1ee4f9873035085f6cdb00b2f50077 Mon Sep 17 00:00:00 2001 From: rettigl Date: Wed, 13 Nov 2024 09:40:04 +0100 Subject: [PATCH 7/7] fix config docs --- docs/user_guide/config.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/user_guide/config.md b/docs/user_guide/config.md index 7fb62f7d..450d4da2 100644 --- a/docs/user_guide/config.md +++ b/docs/user_guide/config.md @@ -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 ```