Skip to content

Commit 2ec7fb1

Browse files
authored
Merge pull request #581 from OpenCOMPES/update_pynxtools
Update pynxtools
2 parents b92c760 + d22240c commit 2ec7fb1

8 files changed

Lines changed: 42 additions & 36 deletions

File tree

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ classifiers = [
2929
"Operating System :: OS Independent",
3030
]
3131
dependencies = [
32-
"bokeh>=2.4.2,<3.7.0",
32+
"bokeh>=2.4.2",
3333
"dask>=2021.12.0,<2024.8",
3434
"elabapi-python>=5.0,<5.2",
3535
"fastdtw>=0.3.4",
@@ -44,8 +44,8 @@ dependencies = [
4444
"pandas>=1.4.1",
4545
"photutils<2.0",
4646
"psutil>=5.9.0",
47-
"pynxtools-mpes>=0.2.6",
48-
"pynxtools>=0.12.0",
47+
"pynxtools-mpes>=0.2.8",
48+
"pynxtools>=0.13.2",
4949
"pyyaml>=6.0.0",
5050
"scipy>=1.8.0",
5151
"symmetrize>=0.5.5",

src/sed/binning/binning.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,14 @@ def bin_partition(
121121

122122
# convert bin centers to bin edges:
123123
if all(isinstance(x, np.ndarray) for x in bins):
124-
bins = cast(list[np.ndarray], bins)
124+
# create a copy to avoid modifying input data
125+
bins = list(cast(list[np.ndarray], bins))
125126
for i, bin_centers in enumerate(bins):
126127
bins[i] = bin_centers_to_bin_edges(bin_centers)
127128
else:
128129
bins = cast(list[int], bins)
130+
# create a copy to avoid modifying input data
131+
ranges = list(ranges)
129132
# shift ranges by half a bin size to align the bin centers to the given ranges,
130133
# as the histogram functions interpret the ranges as limits for the edges.
131134
for i, nbins in enumerate(bins):

src/sed/calibrator/energy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,8 @@ def view(
734734
title=ttl,
735735
width=figsize[0] * 100,
736736
height=figsize[1] * 100,
737-
tooltips=ttp,
738737
)
738+
fig.hover.tooltips = ttp
739739
# Plotting the main traces
740740
for itr, color in zip(range(len(traces)), colors):
741741
trace = traces[itr, :]
@@ -790,7 +790,7 @@ def view(
790790
if show_legend:
791791
fig.legend.location = kwds.pop("legend_location", "top_right")
792792
fig.legend.spacing = 0
793-
fig.legend.padding = 2
793+
fig.legend.padding = 2 # type: ignore
794794

795795
pbk.show(fig)
796796

src/sed/calibrator/momentum.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import xarray as xr
2222
from bokeh.colors import RGB
2323
from bokeh.io import output_notebook
24+
from bokeh.models import Range1d
2425
from bokeh.palettes import Category10 as ColorCycle
2526
from IPython.display import display
2627
from joblib import delayed
@@ -1408,10 +1409,10 @@ def view(
14081409
fig = pbk.figure(
14091410
width=figsize[0] * 100,
14101411
height=figsize[1] * 100,
1411-
tooltips=ttp,
1412-
x_range=(0, num_rows),
1413-
y_range=(0, num_cols),
1412+
x_range=Range1d(0, num_rows), # type: ignore
1413+
y_range=Range1d(0, num_cols), # type: ignore
14141414
)
1415+
fig.hover.tooltips = ttp
14151416
fig.image(
14161417
image=[image.T],
14171418
x=0,
@@ -1832,11 +1833,11 @@ def gather_correction_metadata(self) -> dict:
18321833
metadata["registration"]["creation_date"] = datetime.now()
18331834
metadata["registration"]["applied"] = True
18341835
metadata["registration"]["depends_on"] = (
1835-
"/entry/process/registration/transformations/rot_z"
1836+
"/entry/registration/transformations/rot_z"
18361837
if "angle" in metadata["registration"] and metadata["registration"]["angle"]
1837-
else "/entry/process/registration/transformations/trans_y"
1838+
else "/entry/registration/transformations/trans_y"
18381839
if "xtrans" in metadata["registration"] and metadata["registration"]["xtrans"]
1839-
else "/entry/process/registration/transformations/trans_x"
1840+
else "/entry/registration/transformations/trans_x"
18401841
if "ytrans" in metadata["registration"] and metadata["registration"]["ytrans"]
18411842
else "."
18421843
)
@@ -1860,7 +1861,7 @@ def gather_correction_metadata(self) -> dict:
18601861
[0.0, 1.0, 0.0],
18611862
)
18621863
metadata["registration"]["trans_y"]["depends_on"] = (
1863-
"/entry/process/registration/transformations/trans_x"
1864+
"/entry/registration/transformations/trans_x"
18641865
if "ytrans" in metadata["registration"] and metadata["registration"]["ytrans"]
18651866
else "."
18661867
)
@@ -1875,10 +1876,11 @@ def gather_correction_metadata(self) -> dict:
18751876
metadata["registration"]["rot_z"]["offset"] = np.concatenate(
18761877
(metadata["registration"]["center"], [0.0]),
18771878
)
1879+
metadata["registration"]["rot_z"]["offset_units"] = "pixel"
18781880
metadata["registration"]["rot_z"]["depends_on"] = (
1879-
"/entry/process/registration/transformations/trans_y"
1881+
"/entry/registration/transformations/trans_y"
18801882
if "xtrans" in metadata["registration"] and metadata["registration"]["xtrans"]
1881-
else "/entry/process/registration/transformations/trans_x"
1883+
else "/entry/registration/transformations/trans_x"
18821884
if "ytrans" in metadata["registration"] and metadata["registration"]["ytrans"]
18831885
else "."
18841886
)

src/sed/config/NXmpes_config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@
296296
},
297297
"/ENTRY/REGISTRATION[registration]": {
298298
"applied": "!@attrs:metadata/momentum_correction/registration/applied",
299-
"depends_on": "/entry/process/registration/transformations/rot_z",
299+
"depends_on": "/entry/registration/transformations/rot_z",
300300
"TRANSFORMATIONS[transformations]": {
301301
"AXISNAME[trans_x]": "@attrs:metadata/momentum_correction/registration/trans_x/value",
302302
"AXISNAME[trans_x]/@transformation_type": "translation",

src/sed/diagnostics.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def plot_single_hist(
3434
"""
3535
ttp = kwds.pop("tooltip", [("(x, y)", "($x, $y)")])
3636

37-
fig = pbk.figure(background_fill_color="white", tooltips=ttp)
37+
fig = pbk.figure(background_fill_color="white")
38+
fig.hover.tooltips = ttp
3839
fig.quad(
3940
top=histvals,
4041
bottom=0,

tests/calibrator/test_momentum.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -239,44 +239,44 @@ def test_apply_correction() -> None:
239239
]
240240
depends_on_list = [
241241
{
242-
"root": "/entry/process/registration/transformations/trans_x",
242+
"root": "/entry/registration/transformations/trans_x",
243243
"axes": {"trans_x": "."},
244244
},
245245
{
246-
"root": "/entry/process/registration/transformations/trans_y",
246+
"root": "/entry/registration/transformations/trans_y",
247247
"axes": {"trans_y": "."},
248248
},
249249
{
250-
"root": "/entry/process/registration/transformations/rot_z",
250+
"root": "/entry/registration/transformations/rot_z",
251251
"axes": {"rot_z": "."},
252252
},
253253
{
254-
"root": "/entry/process/registration/transformations/trans_y",
254+
"root": "/entry/registration/transformations/trans_y",
255255
"axes": {
256256
"trans_x": ".",
257-
"trans_y": "/entry/process/registration/transformations/trans_x",
257+
"trans_y": "/entry/registration/transformations/trans_x",
258258
},
259259
},
260260
{
261-
"root": "/entry/process/registration/transformations/rot_z",
261+
"root": "/entry/registration/transformations/rot_z",
262262
"axes": {
263263
"trans_x": ".",
264-
"rot_z": "/entry/process/registration/transformations/trans_x",
264+
"rot_z": "/entry/registration/transformations/trans_x",
265265
},
266266
},
267267
{
268-
"root": "/entry/process/registration/transformations/rot_z",
268+
"root": "/entry/registration/transformations/rot_z",
269269
"axes": {
270270
"trans_y": ".",
271-
"rot_z": "/entry/process/registration/transformations/trans_y",
271+
"rot_z": "/entry/registration/transformations/trans_y",
272272
},
273273
},
274274
{
275-
"root": "/entry/process/registration/transformations/rot_z",
275+
"root": "/entry/registration/transformations/rot_z",
276276
"axes": {
277277
"trans_x": ".",
278-
"trans_y": "/entry/process/registration/transformations/trans_x",
279-
"rot_z": "/entry/process/registration/transformations/trans_y",
278+
"trans_y": "/entry/registration/transformations/trans_x",
279+
"rot_z": "/entry/registration/transformations/trans_y",
280280
},
281281
},
282282
]

tests/test_dfops.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def swap(x, y):
160160
def test_forward_fill_lazy_sparse_nans() -> None:
161161
"""test that a lazy forward fill works as expected with sparse nans"""
162162
t_df = df.copy()
163-
t_df["energy"][::2] = np.nan
163+
t_df.iloc[::2, 2] = np.nan
164164
t_dask_df = ddf.from_pandas(t_df, npartitions=N_PARTITIONS)
165165
t_dask_df = forward_fill_lazy(t_dask_df, "energy", before="max")
166166
t_df = t_df.ffill()
@@ -170,7 +170,7 @@ def test_forward_fill_lazy_sparse_nans() -> None:
170170
def test_forward_fill_lazy_full_partition_nans() -> None:
171171
"""test that a lazy forward fill works as expected with a full partition of nans"""
172172
t_df = df.copy()
173-
t_df["energy"][5:25] = np.nan
173+
t_df.iloc[5:25, 2] = np.nan
174174
t_dask_df = ddf.from_pandas(t_df, npartitions=N_PARTITIONS)
175175
t_dask_df = forward_fill_lazy(t_dask_df, "energy", before="max")
176176
t_df = t_df.ffill()
@@ -182,7 +182,7 @@ def test_forward_fill_lazy_consecutive_full_partition_nans() -> None:
182182
full of nans
183183
"""
184184
t_df = df.copy()
185-
t_df["energy"][5:35] = np.nan
185+
t_df.iloc[5:35, 2] = np.nan
186186
t_dask_df = ddf.from_pandas(t_df, npartitions=N_PARTITIONS)
187187
t_dask_df = forward_fill_lazy(t_dask_df, "energy", before="max")
188188
t_df = t_df.ffill()
@@ -192,7 +192,7 @@ def test_forward_fill_lazy_consecutive_full_partition_nans() -> None:
192192
def test_forward_fill_lazy_wrong_parameters() -> None:
193193
"""test that a lazy forward fill fails as expected on wrong parameters"""
194194
t_df = df.copy()
195-
t_df["energy"][5:35] = np.nan
195+
t_df.iloc[5:35, 2] = np.nan
196196
t_dask_df = ddf.from_pandas(t_df, npartitions=N_PARTITIONS)
197197
with pytest.raises(TypeError):
198198
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:
201201
def test_forward_fill_lazy_compute() -> None:
202202
"""test that a lazy forward fill works as expected with compute=True"""
203203
t_df = df.copy()
204-
t_df["energy"][5:35] = np.nan
204+
t_df.iloc[5:35, 2] = np.nan
205205
t_dask_df = ddf.from_pandas(t_df, npartitions=N_PARTITIONS)
206206
t_dask_df_comp = forward_fill_lazy(t_dask_df, "energy", before="max", compute_lengths=True)
207207
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:
212212
"""test that a lazy forward fill works as expected with missing values at the
213213
beginning of the dataframe"""
214214
t_df = df.copy()
215-
t_df["energy"][:5] = np.nan
215+
t_df.iloc[:5, 2] = np.nan
216216
t_dask_df = ddf.from_pandas(t_df, npartitions=N_PARTITIONS)
217217
t_df = forward_fill_lazy(t_dask_df, "energy", before="max").compute()
218218
assert np.all(np.isnan(t_df["energy"][:5]))
@@ -238,7 +238,7 @@ def test_forward_fill_lazy_wrong_channels() -> None:
238238
def test_forward_fill_lazy_multiple_iterations() -> None:
239239
"""test that a lazy forward fill works as expected with multiple iterations"""
240240
t_df = df.copy()
241-
t_df["energy"][5:35] = np.nan
241+
t_df.loc[5:35, "energy"] = np.nan
242242
t_dask_df = ddf.from_pandas(t_df, npartitions=N_PARTITIONS)
243243
t_dask_df = forward_fill_lazy(t_dask_df, "energy", before="max", iterations=5)
244244
t_df = t_df.ffill()

0 commit comments

Comments
 (0)