Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProcessedImageseries with frame_list automatically updates omega metadata #603

Merged
merged 1 commit into from
Jan 14, 2024
Merged
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
7 changes: 7 additions & 0 deletions hexrd/imageseries/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def __init__(self, imser, oplist, **kwargs):
self._oplist = oplist
self._frames = kwargs.pop('frame_list', None)
self._hasframelist = (self._frames is not None)
if self._hasframelist:
self._update_omega()
self._opdict = {}

self.addop(self.DARK, self._subtract_dark)
Expand Down Expand Up @@ -109,6 +111,11 @@ def _add(self, img, addend):
def _gauss_laplace(self, img, sigma):
return scipy.ndimage.gaussian_laplace(img, sigma)

def _update_omega(self):
"""Update omega if there is a framelist"""
if "omega" in self.metadata:
omega = self.metadata["omega"]
self.metadata["omega"] = omega[self._frames]
#
# ==================== API
#
Expand Down
14 changes: 9 additions & 5 deletions tests/imageseries/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ def make_array_ims():
return random_array, is_a


def make_meta():
md = {'testing': '1,2,3'}
return {'testing': np.array([1, 2, 3])}


def make_omega_meta(n):
return np.linspace((0,0), (1, 1), n)


def compare(ims1, ims2):
"""compare two imageseries"""
if len(ims1) != len(ims2):
Expand All @@ -62,11 +71,6 @@ def compare(ims1, ims2):
return maxdiff


def make_meta():
md = {'testing': '1,2,3'}
return {'testing': np.array([1, 2, 3])}


def compare_meta(ims1, ims2):
# check metadata (simple immutable cases only for now)

Expand Down
5 changes: 4 additions & 1 deletion tests/imageseries/test_process.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from .common import ImageSeriesTest, make_array_ims, compare
from .common import ImageSeriesTest, make_array_ims, make_omega_meta, compare

from hexrd import imageseries
from hexrd.imageseries import process, ImageSeries
Expand Down Expand Up @@ -81,12 +81,15 @@ def test_process_dark(self):
def test_process_framelist(self):
a, _ = make_array_ims()
is_a = imageseries.open(None, 'array', data=a)
is_a.metadata["omega"] = make_omega_meta(len(is_a))
ops = []
frames = [0, 2]
is_p = process.ProcessedImageSeries(is_a, ops, frame_list=frames)
is_a2 = imageseries.open(None, 'array', data=a[tuple(frames), ...])
diff = compare(is_a2, is_p)
self.assertAlmostEqual(diff, 0., msg="frame list failed")
self.assertEqual(len(is_p), len(is_p.metadata["omega"]))


def test_process_shape(self):
a, _ = make_array_ims()
Expand Down