Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion src/sed/binning/binning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(cast(list[np.ndarray], 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):
Expand Down
4 changes: 2 additions & 2 deletions src/sed/calibrator/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, :]
Expand Down Expand Up @@ -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)

Expand Down
20 changes: 11 additions & 9 deletions src/sed/calibrator/momentum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1832,11 +1833,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 "."
)
Expand All @@ -1860,7 +1861,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 "."
)
Expand All @@ -1875,10 +1876,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 "."
)
Expand Down
2 changes: 1 addition & 1 deletion src/sed/config/NXmpes_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/sed/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 12 additions & 12 deletions tests/calibrator/test_momentum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
]
Expand Down
14 changes: 7 additions & 7 deletions tests/test_dfops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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")
Expand All @@ -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)
Expand All @@ -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]))
Expand All @@ -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()
Expand Down