def init_h5file(self): file, curr_dir = get_new_file_name(self.settings.child('acquisition','base_path').value(), 'tttr_data') self.h5saver = H5Saver(save_type='custom') self.h5saver.init_file(update_h5=False, custom_naming=True, addhoc_file_path=os.path.join(curr_dir, f'{file}.h5'), metadata=dict(settings=custom_tree.parameter_to_xml_string(self.settings), format_name='timestamps')) self.settings.child('acquisition', 'temp_file').setValue(f'{file}.h5')
def save_data(self): try: path = select_file(start_path=self.settings.child( 'main_settings', 'base_path').value(), save=True, ext='h5') if path is not None: # init the file object with an addhoc name given by the user h5saver = H5Saver(save_type='custom') h5saver.init_file(update_h5=True, addhoc_file_path=path) # save all metadata settings_str = ioxml.parameter_to_xml_string(self.settings) settings_str = b'<All_settings>' + settings_str settings_str += ioxml.parameter_to_xml_string( self.detector.settings) + ioxml.parameter_to_xml_string( h5saver.settings) + b'</All_settings>' data_group = h5saver.add_data_group( h5saver.raw_group, group_data_type='data0D', title='data from custom app', settings_as_xml=settings_str) for dat in self.raw_data: channel = h5saver.add_CH_group(data_group) data_dict = dict(data=np.array(dat), x_axis=dict(data=np.linspace( 0, len(dat) - 1, len(dat)), units='pxl')) h5saver.add_data(channel, data_dict=data_dict, scan_type='') st = 'file {:s} has been saved'.format(str(path)) self.add_log(st) self.settings.child('main_settings', 'info').setValue(st) h5saver.close_file() except Exception as e: logger.exception(str(e))
def __init__(self, dockarea=None, dashboard=None): """ Parameters ---------- dockarea: (dockarea) instance of the modified pyqtgraph Dockarea (see daq_utils) dashboard: (DashBoard) instance of the pymodaq dashboard """ QLocale.setDefault(QLocale(QLocale.English, QLocale.UnitedStates)) super().__init__() self.dockarea = dockarea self.dashboard = dashboard if dashboard is None: raise Exception('No valid dashboard initialized') self.mainwindow = self.dockarea.parent() self.wait_time = 1000 self.logger_thread = None self.detector_modules = self.dashboard.detector_modules self.det_modules_log = [] self.log_types = ['None', 'H5 File'] if is_sql: self.log_types.append('SQL DataBase') self.logger = None # should be a reference either to self.h5saver or self.dblogger depending the choice of the user self.h5saver = H5Saver(save_type='logger') if is_sql: self.dblogger = DbLoggerGUI(self.dashboard.preset_file.stem) else: self.dblogger = None self.modules_manager = ModulesManager() self.setupUI() self.setup_modules(self.dashboard.title) self.h5saver.settings_tree.setVisible(False) if is_sql: self.dblogger.settings_tree.setVisible(False)
def create_test_file(request, qtbot): bck = H5Saver(backend=request.param) filepath = f'./data/data_test_{request.param}.h5' bck.init_file(update_h5=True, addhoc_file_path=filepath) Nx = 12 Nnavx = 5 Nnavy = 10 scan_shape = (Nnavx, Nnavy) x_axis = dict(label='this is data axis', units='no units', data=np.arange(Nx)) data1D = dict(data=np.arange(Nx) * 1.0 + 7, x_axis=x_axis) nav_x_axis = dict(label='this is nav x axis', units='x units', data=np.arange(Nnavx)) nav_y_axis = utils.Axis(label='this is nav y axis', units='y units', data=np.arange(Nnavy)) d = datetime(year=2020, month=5, day=24, hour=10, minute=52, second=55) raw_group = bck.add_group( 'Agroup', 'data', '/', metadata=dict( date_time=d, author='Seb Weber', settings='this should be xml', scan_settings=b'scan binary setting', type='scan', shape=(10, 45), pixmap_1D=b'this should be binary png in reality', pixmap_2D=b'this should be another binary png in reality')) bck.add_data(raw_group, data1D) scan_group = bck.add_scan_group( 'first scan', settings_as_xml='this should dbe xml settings') params = [{ 'title': 'Main Settings:', 'name': 'main_settings', 'expanded': False, 'type': 'group', 'children': [ { 'title': 'DAQ type:', 'name': 'DAQ_type', 'type': 'list', 'values': ['DAQ0D', 'DAQ1D', 'DAQ2D', 'DAQND'], 'readonly': True }, { 'title': 'Detector type:', 'name': 'detector_type', 'type': 'str', 'value': '', 'readonly': True }, { 'title': 'Nviewers:', 'name': 'Nviewers', 'type': 'int', 'value': 1, 'min': 1, 'default': 1, 'readonly': True }, ] }] settings = Parameter.create(name='settings', type='group', children=params) settings_xml = ctree.parameter_to_xml_string(settings) det_group = bck.add_det_group(scan_group, 'det group', settings_as_xml=settings_xml) data_group = bck.add_data_group(det_group, 'data1D') ch_group = bck.add_CH_group(data_group) data = np.arange(Nx * Nnavx * Nnavy) data = data.reshape(Nnavx, Nnavy, Nx) data_dict = dict(data=data, x_axis=x_axis) bck.add_data(ch_group, data_dict, scan_type='scan2D', scan_shape=scan_shape, add_scan_dim=False) bck.add_navigation_axis(nav_x_axis.pop('data'), scan_group, 'x_axis', metadata=nav_x_axis) bck.add_navigation_axis(nav_y_axis.pop('data'), scan_group, 'y_axis', metadata=nav_y_axis) bck.logger_array.append('log1 to check') bck.logger_array.append('log2 to check') bck.close_file() return bck
def get_h5saver_scan(request, qtbot): return H5Saver(save_type='scan', backend=request.param)
def get_h5saver(get_save_type, request, qtbot): return H5Saver(save_type=get_save_type, backend=request.param)
def save_data(self, export=False): try: if export: ext = 'dat' else: ext = 'h5' path = select_file(start_path=self.save_file_pathname, save=True, ext=ext) if not (not (path)): if not export: h5saver = H5Saver(save_type='detector') h5saver.init_file(update_h5=True, custom_naming=False, addhoc_file_path=path) settings_str = b'<All_settings>' + custom_tree.parameter_to_xml_string( self.settings) if self.detector is not None: settings_str += custom_tree.parameter_to_xml_string( self.detector.settings) if hasattr(self.detector.ui.viewers[0], 'roi_manager'): settings_str += custom_tree.parameter_to_xml_string( self.detector.ui.viewers[0].roi_manager. settings) settings_str += custom_tree.parameter_to_xml_string( h5saver.settings) settings_str += b'</All_settings>' det_group = h5saver.add_det_group(h5saver.raw_group, "Data", settings_str) try: self.channel_arrays = OrderedDict([]) data_dim = 'data1D' if not h5saver.is_node_in_group(det_group, data_dim): self.channel_arrays['data1D'] = OrderedDict([]) data_group = h5saver.add_data_group( det_group, data_dim) for ind_channel, data in enumerate( self.raw_data): # list of numpy arrays channel = f'CH{ind_channel:03d}' channel_group = h5saver.add_CH_group( data_group, title=channel) self.channel_arrays[data_dim][ 'parent'] = channel_group self.channel_arrays[data_dim][ channel] = h5saver.add_data( channel_group, dict(data=data, x_axis=self.viewer_freq_axis), scan_type='', enlargeable=False) h5saver.close_file() except Exception as e: logger.exception(str(e)) else: data_to_save = [self.viewer_freq_axis['data']] data_to_save.extend([dat for dat in self.raw_data]) np.savetxt(path, data_to_save, delimiter='\t') except Exception as e: logger.exception(str(e))