From 572f4bf9a39ff0648f5a19025715d5c73e52a8d4 Mon Sep 17 00:00:00 2001 From: rettigl Date: Tue, 27 Jan 2026 21:56:53 +0100 Subject: [PATCH 1/6] adaption to accepted nexus definitions --- src/sed/calibrator/momentum.py | 13 +++++++------ src/sed/config/NXmpes_config.json | 2 +- tests/calibrator/test_momentum.py | 24 ++++++++++++------------ 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/sed/calibrator/momentum.py b/src/sed/calibrator/momentum.py index 16088945..dd87bb6e 100644 --- a/src/sed/calibrator/momentum.py +++ b/src/sed/calibrator/momentum.py @@ -1832,11 +1832,11 @@ def gather_correction_metadata(self) -> dict: metadata["registration"]["creation_date"] = datetime.now() metadata["registration"]["applied"] = True metadata["registration"]["depends_on"] = ( - "/entry/process/registration/transformations/rot_z" + "/entry/registration/transformations/rot_z" if "angle" in metadata["registration"] and metadata["registration"]["angle"] - else "/entry/process/registration/transformations/trans_y" + else "/entry/registration/transformations/trans_y" if "xtrans" in metadata["registration"] and metadata["registration"]["xtrans"] - else "/entry/process/registration/transformations/trans_x" + else "/entry/registration/transformations/trans_x" if "ytrans" in metadata["registration"] and metadata["registration"]["ytrans"] else "." ) @@ -1860,7 +1860,7 @@ def gather_correction_metadata(self) -> dict: [0.0, 1.0, 0.0], ) metadata["registration"]["trans_y"]["depends_on"] = ( - "/entry/process/registration/transformations/trans_x" + "/entry/registration/transformations/trans_x" if "ytrans" in metadata["registration"] and metadata["registration"]["ytrans"] else "." ) @@ -1875,10 +1875,11 @@ def gather_correction_metadata(self) -> dict: metadata["registration"]["rot_z"]["offset"] = np.concatenate( (metadata["registration"]["center"], [0.0]), ) + metadata["registration"]["rot_z"]["offset_units"] = "pixel" metadata["registration"]["rot_z"]["depends_on"] = ( - "/entry/process/registration/transformations/trans_y" + "/entry/registration/transformations/trans_y" if "xtrans" in metadata["registration"] and metadata["registration"]["xtrans"] - else "/entry/process/registration/transformations/trans_x" + else "/entry/registration/transformations/trans_x" if "ytrans" in metadata["registration"] and metadata["registration"]["ytrans"] else "." ) diff --git a/src/sed/config/NXmpes_config.json b/src/sed/config/NXmpes_config.json index 17e7b1cb..5211d674 100644 --- a/src/sed/config/NXmpes_config.json +++ b/src/sed/config/NXmpes_config.json @@ -296,7 +296,7 @@ }, "/ENTRY/REGISTRATION[registration]": { "applied": "!@attrs:metadata/momentum_correction/registration/applied", - "depends_on": "/entry/process/registration/transformations/rot_z", + "depends_on": "/entry/registration/transformations/rot_z", "TRANSFORMATIONS[transformations]": { "AXISNAME[trans_x]": "@attrs:metadata/momentum_correction/registration/trans_x/value", "AXISNAME[trans_x]/@transformation_type": "translation", diff --git a/tests/calibrator/test_momentum.py b/tests/calibrator/test_momentum.py index dcddaa85..cfde93da 100644 --- a/tests/calibrator/test_momentum.py +++ b/tests/calibrator/test_momentum.py @@ -239,44 +239,44 @@ def test_apply_correction() -> None: ] depends_on_list = [ { - "root": "/entry/process/registration/transformations/trans_x", + "root": "/entry/registration/transformations/trans_x", "axes": {"trans_x": "."}, }, { - "root": "/entry/process/registration/transformations/trans_y", + "root": "/entry/registration/transformations/trans_y", "axes": {"trans_y": "."}, }, { - "root": "/entry/process/registration/transformations/rot_z", + "root": "/entry/registration/transformations/rot_z", "axes": {"rot_z": "."}, }, { - "root": "/entry/process/registration/transformations/trans_y", + "root": "/entry/registration/transformations/trans_y", "axes": { "trans_x": ".", - "trans_y": "/entry/process/registration/transformations/trans_x", + "trans_y": "/entry/registration/transformations/trans_x", }, }, { - "root": "/entry/process/registration/transformations/rot_z", + "root": "/entry/registration/transformations/rot_z", "axes": { "trans_x": ".", - "rot_z": "/entry/process/registration/transformations/trans_x", + "rot_z": "/entry/registration/transformations/trans_x", }, }, { - "root": "/entry/process/registration/transformations/rot_z", + "root": "/entry/registration/transformations/rot_z", "axes": { "trans_y": ".", - "rot_z": "/entry/process/registration/transformations/trans_y", + "rot_z": "/entry/registration/transformations/trans_y", }, }, { - "root": "/entry/process/registration/transformations/rot_z", + "root": "/entry/registration/transformations/rot_z", "axes": { "trans_x": ".", - "trans_y": "/entry/process/registration/transformations/trans_x", - "rot_z": "/entry/process/registration/transformations/trans_y", + "trans_y": "/entry/registration/transformations/trans_x", + "rot_z": "/entry/registration/transformations/trans_y", }, }, ] From 0204c7c3a7df874c1048e15c9e4aaffda529c524 Mon Sep 17 00:00:00 2001 From: rettigl Date: Tue, 27 Jan 2026 22:55:25 +0100 Subject: [PATCH 2/6] fix tests for pandas>=3 --- tests/test_dfops.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/test_dfops.py b/tests/test_dfops.py index 3a6482cd..b3945787 100644 --- a/tests/test_dfops.py +++ b/tests/test_dfops.py @@ -160,7 +160,7 @@ def swap(x, y): def test_forward_fill_lazy_sparse_nans() -> None: """test that a lazy forward fill works as expected with sparse nans""" t_df = df.copy() - t_df["energy"][::2] = np.nan + t_df.iloc[::2, 2] = np.nan t_dask_df = ddf.from_pandas(t_df, npartitions=N_PARTITIONS) t_dask_df = forward_fill_lazy(t_dask_df, "energy", before="max") t_df = t_df.ffill() @@ -170,7 +170,7 @@ def test_forward_fill_lazy_sparse_nans() -> None: def test_forward_fill_lazy_full_partition_nans() -> None: """test that a lazy forward fill works as expected with a full partition of nans""" t_df = df.copy() - t_df["energy"][5:25] = np.nan + t_df.iloc[5:25, 2] = np.nan t_dask_df = ddf.from_pandas(t_df, npartitions=N_PARTITIONS) t_dask_df = forward_fill_lazy(t_dask_df, "energy", before="max") t_df = t_df.ffill() @@ -182,7 +182,7 @@ def test_forward_fill_lazy_consecutive_full_partition_nans() -> None: full of nans """ t_df = df.copy() - t_df["energy"][5:35] = np.nan + t_df.iloc[5:35, 2] = np.nan t_dask_df = ddf.from_pandas(t_df, npartitions=N_PARTITIONS) t_dask_df = forward_fill_lazy(t_dask_df, "energy", before="max") t_df = t_df.ffill() @@ -192,7 +192,7 @@ def test_forward_fill_lazy_consecutive_full_partition_nans() -> None: def test_forward_fill_lazy_wrong_parameters() -> None: """test that a lazy forward fill fails as expected on wrong parameters""" t_df = df.copy() - t_df["energy"][5:35] = np.nan + t_df.iloc[5:35, 2] = np.nan t_dask_df = ddf.from_pandas(t_df, npartitions=N_PARTITIONS) with pytest.raises(TypeError): t_dask_df = forward_fill_lazy(t_dask_df, "energy", before="wrong parameter") @@ -201,7 +201,7 @@ def test_forward_fill_lazy_wrong_parameters() -> None: def test_forward_fill_lazy_compute() -> None: """test that a lazy forward fill works as expected with compute=True""" t_df = df.copy() - t_df["energy"][5:35] = np.nan + t_df.iloc[5:35, 2] = np.nan t_dask_df = ddf.from_pandas(t_df, npartitions=N_PARTITIONS) t_dask_df_comp = forward_fill_lazy(t_dask_df, "energy", before="max", compute_lengths=True) t_dask_df_nocomp = forward_fill_lazy(t_dask_df, "energy", before="max", compute_lengths=False) @@ -212,7 +212,7 @@ def test_forward_fill_lazy_keep_head_nans() -> None: """test that a lazy forward fill works as expected with missing values at the beginning of the dataframe""" t_df = df.copy() - t_df["energy"][:5] = np.nan + t_df.iloc[:5, 2] = np.nan t_dask_df = ddf.from_pandas(t_df, npartitions=N_PARTITIONS) t_df = forward_fill_lazy(t_dask_df, "energy", before="max").compute() assert np.all(np.isnan(t_df["energy"][:5])) @@ -238,7 +238,7 @@ def test_forward_fill_lazy_wrong_channels() -> None: def test_forward_fill_lazy_multiple_iterations() -> None: """test that a lazy forward fill works as expected with multiple iterations""" t_df = df.copy() - t_df["energy"][5:35] = np.nan + t_df.loc[5:35, "energy"] = np.nan t_dask_df = ddf.from_pandas(t_df, npartitions=N_PARTITIONS) t_dask_df = forward_fill_lazy(t_dask_df, "energy", before="max", iterations=5) t_df = t_df.ffill() From 1563bd3f764ac4a7636665a5981163e2881365f5 Mon Sep 17 00:00:00 2001 From: rettigl Date: Sat, 31 Jan 2026 23:50:47 +0100 Subject: [PATCH 3/6] create copy in bin_partition to avoid modifying input data --- src/sed/binning/binning.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sed/binning/binning.py b/src/sed/binning/binning.py index e6884538..ecd9b215 100644 --- a/src/sed/binning/binning.py +++ b/src/sed/binning/binning.py @@ -121,11 +121,14 @@ def bin_partition( # convert bin centers to bin edges: if all(isinstance(x, np.ndarray) for x in bins): - bins = cast(list[np.ndarray], bins) + # create a copy to avoid modifying input data + bins = list(bins) for i, bin_centers in enumerate(bins): bins[i] = bin_centers_to_bin_edges(bin_centers) else: bins = cast(list[int], bins) + # create a copy to avoid modifying input data + ranges = list(ranges) # shift ranges by half a bin size to align the bin centers to the given ranges, # as the histogram functions interpret the ranges as limits for the edges. for i, nbins in enumerate(bins): From 31fed8853d92b83c0f8788d45b14be5dadf086bb Mon Sep 17 00:00:00 2001 From: rettigl Date: Sat, 31 Jan 2026 23:52:09 +0100 Subject: [PATCH 4/6] remove limit on bokeh --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c2875329..6df968c8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ classifiers = [ "Operating System :: OS Independent", ] dependencies = [ - "bokeh>=2.4.2,<3.7.0", + "bokeh>=2.4.2", "dask>=2021.12.0,<2024.8", "elabapi-python>=5.0,<5.2", "fastdtw>=0.3.4", From e1021703dd11ba1967e6d49c1cff843da54b8f74 Mon Sep 17 00:00:00 2001 From: rettigl Date: Sun, 1 Feb 2026 12:44:35 +0100 Subject: [PATCH 5/6] fix liniting --- src/sed/binning/binning.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sed/binning/binning.py b/src/sed/binning/binning.py index ecd9b215..04a399cb 100644 --- a/src/sed/binning/binning.py +++ b/src/sed/binning/binning.py @@ -122,7 +122,7 @@ def bin_partition( # convert bin centers to bin edges: if all(isinstance(x, np.ndarray) for x in bins): # create a copy to avoid modifying input data - bins = list(bins) + bins = list(cast(list[np.ndarray], bins)) for i, bin_centers in enumerate(bins): bins[i] = bin_centers_to_bin_edges(bin_centers) else: From 973d6ddf53c15338d0c7ee51a6c149cf66f63256 Mon Sep 17 00:00:00 2001 From: rettigl Date: Sun, 1 Feb 2026 13:01:44 +0100 Subject: [PATCH 6/6] changes for new bokeh versions --- src/sed/calibrator/energy.py | 4 ++-- src/sed/calibrator/momentum.py | 7 ++++--- src/sed/diagnostics.py | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/sed/calibrator/energy.py b/src/sed/calibrator/energy.py index b5d055dd..ec34483c 100644 --- a/src/sed/calibrator/energy.py +++ b/src/sed/calibrator/energy.py @@ -734,8 +734,8 @@ def view( title=ttl, width=figsize[0] * 100, height=figsize[1] * 100, - tooltips=ttp, ) + fig.hover.tooltips = ttp # Plotting the main traces for itr, color in zip(range(len(traces)), colors): trace = traces[itr, :] @@ -790,7 +790,7 @@ def view( if show_legend: fig.legend.location = kwds.pop("legend_location", "top_right") fig.legend.spacing = 0 - fig.legend.padding = 2 + fig.legend.padding = 2 # type: ignore pbk.show(fig) diff --git a/src/sed/calibrator/momentum.py b/src/sed/calibrator/momentum.py index dd87bb6e..dd65536d 100644 --- a/src/sed/calibrator/momentum.py +++ b/src/sed/calibrator/momentum.py @@ -21,6 +21,7 @@ import xarray as xr from bokeh.colors import RGB from bokeh.io import output_notebook +from bokeh.models import Range1d from bokeh.palettes import Category10 as ColorCycle from IPython.display import display from joblib import delayed @@ -1408,10 +1409,10 @@ def view( fig = pbk.figure( width=figsize[0] * 100, height=figsize[1] * 100, - tooltips=ttp, - x_range=(0, num_rows), - y_range=(0, num_cols), + x_range=Range1d(0, num_rows), + y_range=Range1d(0, num_cols), ) + fig.hover.tooltips = ttp fig.image( image=[image.T], x=0, diff --git a/src/sed/diagnostics.py b/src/sed/diagnostics.py index 4f44b1f7..a25e63aa 100644 --- a/src/sed/diagnostics.py +++ b/src/sed/diagnostics.py @@ -34,7 +34,8 @@ def plot_single_hist( """ ttp = kwds.pop("tooltip", [("(x, y)", "($x, $y)")]) - fig = pbk.figure(background_fill_color="white", tooltips=ttp) + fig = pbk.figure(background_fill_color="white") + fig.hover.tooltips = ttp fig.quad( top=histvals, bottom=0,