Skip to content

Commit

Permalink
frame-cache writer: simple fixes and testing
Browse files Browse the repository at this point in the history
  • Loading branch information
donald e. boyce committed Jan 14, 2024
1 parent f7b97c2 commit 23878a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
9 changes: 5 additions & 4 deletions hexrd/imageseries/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,14 @@ def __init__(self, ims, fname, **kwargs):
the imageseries to write
fname: str or Path
name of file to write;
threshold: float
threshold value for image, at or below which values are zeroed
cache_file: str or Path, optional
name of the npz file to save the image data, if not given in the
`fname` argument; for YAML format (deprecated), this is required
"""
Writer.__init__(self, ims, fname, **kwargs)
self._thresh = self._opts['threshold']
cf = kwargs['cache_file']
self._cache, self.cachename = self._set_cache()
self.max_workers = kwargs.get('max_workers', None)

Expand All @@ -208,10 +209,10 @@ def _set_cache(self):
cachename = cache = self.fname
else:
if os.path.isabs(cf):
self._cache = cf
cache = cf
else:
cdir = os.path.dirname(fname)
self._cache = os.path.join(cdir, cf)
cdir = os.path.dirname(self.fname)
cache = os.path.join(cdir, cf)
cachename = cf

return cache, cachename
Expand Down
12 changes: 11 additions & 1 deletion tests/imageseries/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,17 @@ def test_fmtfc(self):
"""save/load frame-cache format"""
imageseries.write(self.is_a, self.fcfile, self.fmt,
threshold=self.thresh, cache_file=self.cache_file)
# is_fc = imageseries.open(self.fcfile, self.fmt, style='yml')
is_fc = imageseries.open(self.fcfile, self.fmt)
diff = compare(self.is_a, is_fc)
self.assertAlmostEqual(diff, 0., "frame-cache reconstruction failed")
self.assertTrue(compare_meta(self.is_a, is_fc))

def test_fmtfc_nocache_file(self):
"""save/load frame-cache format with no cache_file arg"""
imageseries.write(
self.is_a, self.fcfile, self.fmt,
threshold=self.thresh
)
is_fc = imageseries.open(self.fcfile, self.fmt)
diff = compare(self.is_a, is_fc)
self.assertAlmostEqual(diff, 0., "frame-cache reconstruction failed")
Expand Down

0 comments on commit 23878a3

Please sign in to comment.