-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from nexusformat/master
updating fork
- Loading branch information
Showing
7 changed files
with
162 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
|
||
def find_class(nx_file, nx_class): | ||
""" | ||
Find a given NXclass | ||
""" | ||
hits = [] | ||
if not isinstance(nx_class, list): | ||
nx_class = [nx_class] | ||
def visitor(name, obj): | ||
if "NX_class" in obj.attrs.keys(): | ||
if obj.attrs["NX_class"] in nx_class: | ||
hits.append((name, obj)) | ||
|
||
nx_file.visititems(visitor) | ||
return hits | ||
|
||
REQUIRED_FIELDS = ['photoelectrons_energy', 'detector_sensitivity', 'energy_direction', 'energy_dispersion'] | ||
|
||
def check_detector(d): | ||
hit = [] | ||
for f in REQUIRED_FIELDS: | ||
if f in d.keys(): | ||
hit.append(f) | ||
return hit | ||
|
||
class recipe(object): | ||
""" | ||
Recipe to validate files with the NXrixs feature | ||
WIP: just detector parameters at the moment | ||
""" | ||
|
||
def __init__(self, filedesc, entrypath): | ||
self.file = filedesc | ||
self.entry = entrypath | ||
self.title = "NXrixs" | ||
|
||
def process(self): | ||
hits = dict() | ||
for en, e in find_class(self.file, 'NXentry'): | ||
for dn, d in find_class(e, 'NXdetector'): | ||
h = check_detector(d) | ||
if h: | ||
hits[en + '/' + dn] = h | ||
|
||
if len(hits) == 0: | ||
raise Exception('No detectors found with any required fields') | ||
nh = len(REQUIRED_FIELDS) | ||
msg = '' | ||
for d in hits: | ||
h = hits[d] | ||
if len(h) != nh: | ||
msg += 'Detector %s missing fields: only %s\n' % d, h | ||
if msg: | ||
raise Exception(msg) | ||
|
||
return hits | ||
|
||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class recipe: | ||
""" | ||
Has title. | ||
Proposed by: [email protected] | ||
""" | ||
|
||
def __init__(self, filedesc, entrypath): | ||
""" | ||
:param filedesc: h5py file object of the NeXus/HDF5 file | ||
:param entrypath: path of the entry containing this feature | ||
""" | ||
self.file = filedesc | ||
self.entry = entrypath | ||
self.title = "Has title" | ||
|
||
def process(self): | ||
""" | ||
Finds the title. | ||
:return: the title | ||
:raises: AssertionError if field not found | ||
""" | ||
try: | ||
return self.file[self.entry]['title'][0] | ||
except: | ||
raise AssertionError("This file does not contain a title field") |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class recipe: | ||
""" | ||
Has experiment_identifier. | ||
Proposed by: [email protected] | ||
""" | ||
|
||
def __init__(self, filedesc, entrypath): | ||
""" | ||
:param filedesc: h5py file object of the NeXus/HDF5 file | ||
:param entrypath: path of the entry containing this feature | ||
""" | ||
self.file = filedesc | ||
self.entry = entrypath | ||
self.title = "Has experiment_identifier" | ||
|
||
def process(self): | ||
""" | ||
Finds the experiment identifier. | ||
:return: the experiment identifier | ||
:raises: AssertionError if field not found | ||
""" | ||
try: | ||
return self.file[self.entry]['experiment_identifier'][0] | ||
except: | ||
raise AssertionError("This file does not contain an experiment_identfier field") |