diff --git a/.cspell/custom-dictionary.txt b/.cspell/custom-dictionary.txt index 38f8c89c..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,8 @@ xpos xratio xrng xscale +xticklabels +xticks xtrans Xuser xval @@ -414,6 +417,8 @@ ylabel ypos yratio yscale +yticklabels +yticks ytrans zain Zenodo 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/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 ``` 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 ``` diff --git a/src/sed/calibrator/energy.py b/src/sed/calibrator/energy.py index 65493f66..b5d055dd 100644 --- a/src/sed/calibrator/energy.py +++ b/src/sed/calibrator/energy.py @@ -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 @@ -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) @@ -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, @@ -682,6 +689,7 @@ def view( xaxis, trace, ls="-", + color=color, linewidth=1, label=lbs[itr], **linekwds, @@ -696,6 +704,7 @@ def view( tofseg, traceseg, ls="-", + color=color, linewidth=2, **linesegkwds, ) @@ -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 @@ -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 diff --git a/src/sed/calibrator/momentum.py b/src/sed/calibrator/momentum.py index 33047292..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 @@ -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,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), diff --git a/src/sed/core/processor.py b/src/sed/core/processor.py index f40089bb..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. @@ -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) @@ -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!") @@ -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, @@ -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 diff --git a/src/sed/diagnostics.py b/src/sed/diagnostics.py index 02bcc0a0..4f44b1f7 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", (14, 8)) + 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()}.") @@ -96,15 +96,18 @@ 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) + 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, @@ -114,11 +117,13 @@ def grid_histogram( **histkwds, ) if legend: - ax[axind].legend(fontsize=15, **legkwds) + ax[axind].legend(fontsize=10, **legkwds) 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, @@ -128,7 +133,7 @@ def grid_histogram( **histkwds, ) if legend: - ax[i].legend(fontsize=15, **legkwds) + ax[i].legend(fontsize=10, **legkwds) otherax[i] = None @@ -136,6 +141,8 @@ def grid_histogram( if oax is not None: fig.delaxes(oax) + plt.tight_layout() + elif backend == "bokeh": output_notebook(hide_banner=True) @@ -163,7 +170,7 @@ def grid_histogram( gridplot( plots, # type: ignore ncols=ncol, - width=figsz[0] * 30, - height=figsz[1] * 28, + width=figsz[0] * 100, + height=figsz[1] * 100, ), )