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
27 changes: 20 additions & 7 deletions src/whirlwind/_cost.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import importlib.resources
import pickle
from pathlib import Path

import numpy as np
import scipy.ndimage
from scipy.interpolate import RegularGridInterpolator

__all__ = [
"calc_smooth_phase_gradients",
Expand All @@ -29,14 +30,26 @@ def calc_smooth_phase_gradients(igram):
return phase_dy_smooth, phase_dx_smooth


def _load_rgi(path: Path | str) -> RegularGridInterpolator:
"""Reconstruct RegularGridInterpolator from saved data."""
data = np.load(path, allow_pickle=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using numpy=2.3.5 and the latest commit

$ git rev-parse HEAD
46560ee9b55e331be1b82b2bf8e831f50ced7d32

I'm getting the following error:

Traceback (most recent call last):
  File "/home/ggunter/Projects/whirlwind/./test.py", line 12, in <module>
    unw = ww.unwrap(igram, corr, nlooks=1.0)
  File "/home/ggunter/miniforge3/envs/whirlwind/lib/python3.14/site-packages/whirlwind/_unwrap.py", line 28, in unwrap
    cost = compute_carballo_costs(igram, corr, nlooks, mask)
  File "/home/ggunter/miniforge3/envs/whirlwind/lib/python3.14/site-packages/whirlwind/_cost.py", line 65, in compute_carballo_costs
    spline_pdf0, spline_pdf1 = load_carballo_pdf_splines()
                               ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/ggunter/miniforge3/envs/whirlwind/lib/python3.14/site-packages/whirlwind/_cost.py", line 50, in load_carballo_pdf_splines
    spline_pdf0 = _load_rgi(p)
  File "/home/ggunter/miniforge3/envs/whirlwind/lib/python3.14/site-packages/whirlwind/_cost.py", line 37, in _load_rgi
    points=tuple(data["grid"]),
                 ~~~~^^^^^^^^
  File "/home/ggunter/miniforge3/envs/whirlwind/lib/python3.14/site-packages/numpy/lib/_npyio_impl.py", line 257, in __getitem__
    return format.read_array(
           ~~~~~~~~~~~~~~~~~^
        bytes,
        ^^^^^^
    ...<2 lines>...
        max_header_size=self.max_header_size
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/ggunter/miniforge3/envs/whirlwind/lib/python3.14/site-packages/numpy/lib/_format_impl.py", line 833, in read_array
    raise ValueError("Object arrays cannot be loaded when "
                     "allow_pickle=False")
ValueError: Object arrays cannot be loaded when allow_pickle=False

return RegularGridInterpolator(
points=tuple(data["grid"]),
values=data["values"],
method=str(data["method"]),
bounds_error=bool(data["bounds_error"]),
fill_value=float(data["fill_value"])
if data["fill_value"] is not None
else None,
Comment on lines +41 to +43
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like your formatter barfed here. Can we fit this on a single line for readability?

Maybe something like

    fill_value = float(data["fill_value"]) if data["fill_value"] is not None else None
    return RegularGridInterpolator(
        ...,
        fill_value=fill_value,
    )

)


def load_carballo_pdf_splines():
""" """
files = importlib.resources.files(__package__)

with files.joinpath("carballo-pdf-0-spline.pkl").open("rb") as f:
spline_pdf0 = pickle.load(f)
with files.joinpath("carballo-pdf-1-spline.pkl").open("rb") as f:
spline_pdf1 = pickle.load(f)
with importlib.resources.path(__package__, "carballo-pdf-0-spline.npz") as p:
spline_pdf0 = _load_rgi(p)
with importlib.resources.path(__package__, "carballo-pdf-1-spline.npz") as p:
spline_pdf1 = _load_rgi(p)

return spline_pdf0, spline_pdf1

Expand Down
Binary file not shown.
Binary file not shown.