Skip to content

Commit

Permalink
Merge pull request #603 from donald-e-boyce/frame-list-omega
Browse files Browse the repository at this point in the history
ProcessedImageseries with frame_list automatically updates omega metadata
  • Loading branch information
donald-e-boyce authored Jan 14, 2024
2 parents ae12b49 + e6f47e8 commit ccd8d56
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
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

0 comments on commit ccd8d56

Please sign in to comment.