Skip to content

Commit

Permalink
allow for parsing of files with missing attenuation.h5
Browse files Browse the repository at this point in the history
  • Loading branch information
P-Mousley authored Jan 6, 2025
1 parent 6d77379 commit 9b6803f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
19 changes: 15 additions & 4 deletions src/islatu/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def load_images_from_h5(h5_file_path,datanxfilepath,transpose=False):
images = []
debug.log("Loading images from file " + h5_file_path, unimportance=0)
with h5py.File(h5_file_path, "r") as file_handle:
dataset = file_handle[internal_data_path][()]
dataset = file_handle[internal_data_path]#[()]

num_images = dataset.shape[0]
# Prepare to show a progress bar for image loading.
Expand Down Expand Up @@ -579,7 +579,17 @@ def i07_nxs_parser(file_path: str,remove_indices=None):
i07_nxs = I07Nexus(file_path)
detname=i07_nxs.detector_name
if 'attenuation_filters_moving' in i07_nxs.entry[f'{detname}'].keys():
remove_indices=np.where(np.array(i07_nxs.entry[f'{detname}/attenuation_filters_moving']))[0]
try:
attenuationvalues=i07_nxs.entry[f'{detname}/attenuation_value'].nxdata
movingfilters=[0 if attenuationvalues[i]==attenuationvalues[i-1] else 1 for i in np.arange(1,len(attenuationvalues[0:5]))]
except (AttributeError,TypeError):
debug.log("unable to read in attenuation information, possible missing attenuation h5 file. Will assume no moving attenuation.", unimportance=2)
attenuationvalues=i07_nxs.entry[f'{detname}/attenuation_value']
movingfilters=[]
remove_indices=np.where(movingfilters)[0]
#remove_indices=np.where(np.array(i07_nxs.entry[f'{detname}/attenuation_filters_moving']))[0]
remove_indices+=1

# Load the images, taking a transpose if necessary (because which axis is
# x and which is why is determined by fast vs slow detector axes in memory).
if i07_nxs.detector_name in [
Expand All @@ -604,10 +614,11 @@ def i07_nxs_parser(file_path: str,remove_indices=None):
data = Data(rough_intensity, rough_intensity_e, i07_nxs.probe_energy,
theta=axis)
elif i07_nxs.default_axis_type == 'tth':
data = Data(rough_intensity, rough_intensity_e, i07_nxs.probe_energy, theta=axis/2)
data = Data(rough_intensity, rough_intensity_e, i07_nxs.probe_energy,
theta=axis/2)
else:
raise NotImplementedError(
f"{i07_nxs.default_axis_type} is not a supported axis type.")
f"{i07_nxs.default_axis_type} is not a supported axis type. Axis name={i07_nxs.default_axis_name}")

# Returns the Scan2D object
return Scan2D(data, i07_nxs, images, remove_indices)
Expand Down
6 changes: 5 additions & 1 deletion src/islatu/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ def __init__(self, data: Data, metadata: Metadata, images: List[Image],remove_in
self.images = images
self.detname=self.metadata.detector_name
if 'attenuation_filters_moving' in self.metadata.entry[f'{self.detname}'].keys():
if len(self.metadata.entry[f'{self.detname}/attenuation_filters_moving'].nxdata) >1:
try:
filterslist=self.metadata.entry[f'{self.detname}/attenuation_filters_moving'].nxdata
except (AttributeError,TypeError):
filterslist=[]
if len(filterslist) >1:
self.metadata.transmissionsraw=self.metadata.entry[f'{self.detname}_transmission/transmission'].nxdata
self.metadata.transmissions=np.delete(np.insert(self.metadata.transmissionsraw,0,1e-9),-1)
if remove_indices is not None:
Expand Down

0 comments on commit 9b6803f

Please sign in to comment.