Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 16 additions & 5 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,24 @@ 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=True)
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,
)


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)
spline_pdf0 = _load_rgi(files.joinpath("carballo-pdf-0-spline.npz"))
spline_pdf1 = _load_rgi(files.joinpath("carballo-pdf-1-spline.npz"))

return spline_pdf0, spline_pdf1

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