Commit 6b5f5598 authored by Raj Giridharagopal's avatar Raj Giridharagopal
Browse files

added custom group name ability to pifm and igor

parent a3879709
...@@ -22,7 +22,8 @@ class IgorIBWTranslator(Translator): ...@@ -22,7 +22,8 @@ class IgorIBWTranslator(Translator):
Translates Igor Binary Wave (.ibw) files containing images or force curves to .h5 Translates Igor Binary Wave (.ibw) files containing images or force curves to .h5
""" """
def translate(self, file_path, verbose=False, append_path='', parm_encoding='utf-8'): def translate(self, file_path, verbose=False, append_path='',
grp_name='', parm_encoding='utf-8'):
""" """
Translates the provided file to .h5 Translates the provided file to .h5
...@@ -34,6 +35,8 @@ class IgorIBWTranslator(Translator): ...@@ -34,6 +35,8 @@ class IgorIBWTranslator(Translator):
Whether or not to show print statements for debugging Whether or not to show print statements for debugging
append_path : string (Optional) append_path : string (Optional)
h5_file to add these data to h5_file to add these data to
grp_name : string (Optional)
Change from default "Measurement" name to something specific
parm_encoding : str, optional parm_encoding : str, optional
Codec to be used to decode the bytestrings into Python strings if needed. Codec to be used to decode the bytestrings into Python strings if needed.
Default 'utf-8' Default 'utf-8'
...@@ -55,6 +58,8 @@ class IgorIBWTranslator(Translator): ...@@ -55,6 +58,8 @@ class IgorIBWTranslator(Translator):
h5_file = h5py.File(h5_path, 'w') h5_file = h5py.File(h5_path, 'w')
else: else:
h5_path = append_path h5_path = append_path
if not path.exists(append_path):
raise Exception('Improper file')
h5_file = h5py.File(h5_path, 'r+') h5_file = h5py.File(h5_path, 'r+')
...@@ -118,7 +123,10 @@ class IgorIBWTranslator(Translator): ...@@ -118,7 +123,10 @@ class IgorIBWTranslator(Translator):
spec_desc = Dimension('Z', 'm', spec_data) spec_desc = Dimension('Z', 'm', spec_data)
# Create measurement group # Create measurement group
meas_grp = create_indexed_group(h5_file, 'Measurement') if not grp_name:
meas_grp = create_indexed_group(h5_file, 'Measurement')
else:
meas_grp = create_indexed_group(h5_file, grp_name)
# Write file and measurement level parameters # Write file and measurement level parameters
global_parms = generate_dummy_main_parms() global_parms = generate_dummy_main_parms()
......
...@@ -12,7 +12,7 @@ class PiFMTranslator(Translator): ...@@ -12,7 +12,7 @@ class PiFMTranslator(Translator):
structure. structure.
""" """
def translate(self, path, append_path=''): def translate(self, path, append_path='', grp_name=''):
""" """
Parameters Parameters
---------- ----------
...@@ -38,7 +38,7 @@ class PiFMTranslator(Translator): ...@@ -38,7 +38,7 @@ class PiFMTranslator(Translator):
self.read_imgs() self.read_imgs()
self.read_spectra() self.read_spectra()
self.make_pos_vals_inds_dims() self.make_pos_vals_inds_dims()
self.create_hdf5_file(append_path) self.create_hdf5_file(append_path, grp_name)
self.write_spectrograms() self.write_spectrograms()
self.write_images() self.write_images()
self.write_spectra() self.write_spectra()
...@@ -184,7 +184,7 @@ class PiFMTranslator(Translator): ...@@ -184,7 +184,7 @@ class PiFMTranslator(Translator):
usid.write_utils.Dimension('Y', self.params_dictionary['YPhysUnit'].replace('\xb5', 'u'), self.y_len)] usid.write_utils.Dimension('Y', self.params_dictionary['YPhysUnit'].replace('\xb5', 'u'), self.y_len)]
self.pos_ind, self.pos_val, self.pos_dims = pos_ind, pos_val, pos_dims self.pos_ind, self.pos_val, self.pos_dims = pos_ind, pos_val, pos_dims
def create_hdf5_file(self, append_path=''): def create_hdf5_file(self, append_path='', grp_name=''):
if not append_path: if not append_path:
h5_path = os.path.join(self.directory, self.basename.replace('.txt', '.h5')) h5_path = os.path.join(self.directory, self.basename.replace('.txt', '.h5'))
if os.path.exists(h5_path): if os.path.exists(h5_path):
...@@ -196,7 +196,11 @@ class PiFMTranslator(Translator): ...@@ -196,7 +196,11 @@ class PiFMTranslator(Translator):
else: else:
self.h5_f = h5py.File(append_path, mode='r+') self.h5_f = h5py.File(append_path, mode='r+')
self.h5_meas_grp = usid.hdf_utils.create_indexed_group(self.h5_f, 'Measurement_') if not grp_name:
self.h5_meas_grp = usid.hdf_utils.create_indexed_group(self.h5_f, 'Measurement_')
else:
self.h5_meas_grp = usid.hdf_utils.create_indexed_group(self.h5_f, grp_name)
usid.hdf_utils.write_simple_attrs(self.h5_meas_grp, self.params_dictionary) usid.hdf_utils.write_simple_attrs(self.h5_meas_grp, self.params_dictionary)
return return
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment