Skip to content

Commit

Permalink
https://github.com/pycroscopy/SciFiReaders/issues/87
Browse files Browse the repository at this point in the history
  • Loading branch information
Utkarsh Pratiush committed Oct 20, 2023
1 parent 2285dd4 commit eb5443a
Show file tree
Hide file tree
Showing 2 changed files with 192 additions and 1,054 deletions.
28 changes: 22 additions & 6 deletions SciFiReaders/readers/SID/Usid_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import warnings
import sidpy
from sidpy.sid import Reader
import numpy as np

try:
import pyUSID as usid
Expand Down Expand Up @@ -134,7 +135,6 @@ def _get_dimension_descriptors(main_dataset, verbose):

pos_dim, spec_dim = 0, 0
dims, dim_labels, dim_types, dim_quantities, dim_units, dim_values = [], [], [], [], [], []

for dim, dim_label in enumerate(main_dataset.n_dim_labels):
dims.append(dim)
dim_labels.append(dim_label)
Expand All @@ -152,7 +152,7 @@ def _get_dimension_descriptors(main_dataset, verbose):

else:
dim_types.append('spectral')
dim_values.append(main_dataset.get_spec_values(dim_label))
dim_values.append(main_dataset.get_spec_values(dim_label))# error here
descriptor = main_dataset.spec_dim_descriptors[spec_dim].split('(')
if descriptor[1][0] != ')':
dim_quantities.append(descriptor[0][:-1])
Expand All @@ -173,7 +173,6 @@ def _get_main_data_descriptors(main_dataset):
"""
Gets the descriptors (quatity and units) of the output quantity
of a non compund main dataset
Parameters
----------
main_dataset: USID main dataset
Expand Down Expand Up @@ -238,7 +237,6 @@ def _get_metadata(main_dataset):




def read(self, dataset_path = None):
"""
Parameters
Expand All @@ -254,9 +252,23 @@ def read(self, dataset_path = None):
"""
self._dataset_path = dataset_path
self._get_maindatasets()

def read_not_in_ndim():
h5_file = self._file
h5_main = usid.hdf_utils.find_dataset(h5_file, 'Raw_Data')[0]
data_array = np.array(h5_main)# (3600, 216576)
position_index = np.array(h5_main.h5_pos_inds)# (3600, 2)
position_values = np.array(h5_main.h5_pos_vals)# (3600, 2)
spectroscopic_index = np.array(h5_main.h5_spec_inds)# (216576, 2)
spectroscopic_values = np.array(h5_main.h5_spec_vals)# (216576, 2)

metadata_dict = {"pos_index": position_index, "pos_values": position_values,
"spec_index": spectroscopic_index, "spec_values": spectroscopic_values}
sid_data = sidpy.Dataset.from_array(data_array)
sid_data.metadata = metadata_dict
return sid_data

sid_datasets = []

for j,main_dataset in enumerate(self._main_datasets):
# Check if the main dataset is compound
if main_dataset.dtype.names is not None:
Expand All @@ -283,7 +295,11 @@ def read(self, dataset_path = None):
#For a non-compound dataset
else:
#Get descriptors of the main dataset
dims, dim_labels, dim_types, dim_quantities, dim_units, dim_values = Usid_reader._get_dimension_descriptors(main_dataset, verbose = self.verbose)
try :
dims, dim_labels, dim_types, dim_quantities, dim_units, dim_values = Usid_reader._get_dimension_descriptors(main_dataset, verbose = self.verbose)
except ValueError:
return read_not_in_ndim()

sid_dataset = sidpy.Dataset.from_array(main_dataset.get_n_dim_form())
#Get descriptors (units) of each of the output quantity
sid_dataset.quantity, sid_dataset.units = Usid_reader._get_main_data_descriptors(main_dataset)
Expand Down
Loading

0 comments on commit eb5443a

Please sign in to comment.