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

Imagefiles yaml text #604

Merged
merged 2 commits into from
Jan 16, 2024
Merged
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
29 changes: 22 additions & 7 deletions hexrd/imageseries/load/imagefiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class ImageFilesImageSeriesAdapter(ImageSeriesAdapter):

format = 'image-files'

def __init__(self, fname, **kwargs):
def __init__(self, fname):
"""Constructor for image files image series

*fname* - should be yaml file with files and metadata sections
*kwargs* - keyword arguments
. 'files' = a list of image files
. 'metadata' = a dictionary
Parameters
----------
fname: string | Path
name of YAML file or bytestring of YAML contents
"""
self._fname = fname
self._load_yml()
Expand Down Expand Up @@ -81,13 +81,28 @@ def __str__(self):
self.dtype, self.shape, self.singleframes)
return s

@property
def fname(self):
return self._fname

def _load_yml(self):
EMPTY = 'empty-frames'
MAXTOTF = 'max-total-frames'
MAXFILF = 'max-file-frames'
DTYPE = 'dtype'
with open(self._fname, "r") as f:
d = yaml.safe_load(f)
#
# Check whether fname is a pathlib Path, a filename or YAML content.
# If it has multiple lines, we consider it to be YAML content,
# otherwise a file name.
#
is_str = isinstance(self.fname, str)
nlines = len(self.fname.splitlines()) if is_str else 1
if nlines > 1:
psavery marked this conversation as resolved.
Show resolved Hide resolved
d = yaml.safe_load(self.fname)
else:
with open(self._fname, "r") as f:
d = yaml.safe_load(f)

imgsd = d['image-files']
dname = imgsd['directory']
fglob = imgsd['files']
Expand Down