def plot_bayesian_spot_from_h5(h5_bayesian_grp, h5_resh, pix_ind, **kwargs): """ Plots the basic Bayesian Inference results for a specific pixel Parameters ---------- h5_bayesian_grp : h5py.Datagroup reference Group containing the Bayesian Inference results h5_resh : h5py.Dataset reference Dataset containing the raw / filtered measured current split by pixel pix_ind : unsigned int Integer index of the desired pixel Returns ------- fig : matplotlib.pyplot figure handle Handle to figure """ bias_triang = np.squeeze(h5_bayesian_grp['Spectroscopic_Values'][()]) h5_resistance = h5_bayesian_grp['Resistance'] h5_r_variance = h5_bayesian_grp['R_variance'] h5_i_corrected = h5_bayesian_grp['Corrected_Current'] i_meas = np.squeeze(h5_resh[pix_ind]) orig_bias = np.squeeze(get_auxiliary_datasets(h5_resh, aux_dset_name=['Spectroscopic_Values'])[0]) h5_pos = get_auxiliary_datasets(h5_resh, aux_dset_name=['Position_Indices'])[0] resistance = h5_resistance[pix_ind] i_correct = h5_i_corrected[pix_ind] r_variance = h5_r_variance[pix_ind] return plot_bayesian_results(orig_bias, i_meas, i_correct, bias_triang, resistance, r_variance, pix_pos=h5_pos[pix_ind], **kwargs)
def test_single(self): with h5py.File(data_utils.std_beps_path, mode='r') as h5_f: h5_main = h5_f['/Raw_Measurement/source_main'] h5_pos = h5_f['/Raw_Measurement/Position_Indices'] [ret_val] = hdf_utils.get_auxiliary_datasets( h5_main, aux_dset_name='Position_Indices') self.assertEqual(ret_val, h5_pos)
def is_reshapable(h5_main, step_start_inds=None): """ A BE dataset is said to be reshape-able if the number of bins per steps is constant. Even if the dataset contains multiple excitation waveforms (harmonics), We know that the measurement is always at the resonance peak, so the frequency vector should not change. Parameters ---------- h5_main : h5py.Dataset object Reference to the main dataset step_start_inds : list or 1D array Indices that correspond to the start of each BE pulse / UDVS step Returns --------- reshapable : Boolean Whether or not the number of bins per step are constant in this dataset """ if step_start_inds is None: h5_spec_inds = get_auxiliary_datasets( h5_main, aux_dset_name=['Spectroscopic_Indices'])[0] step_start_inds = np.where(h5_spec_inds[0] == 0)[0] # Adding the size of the main dataset as the last (virtual) step step_start_inds = np.hstack((step_start_inds, h5_main.shape[1])) num_bins = np.diff(step_start_inds) step_types = np.unique(num_bins) return len(step_types) == 1
def is_reshapable(h5_main, step_start_inds=None): """ A BE dataset is said to be reshape-able if the number of bins per steps is constant. Even if the dataset contains multiple excitation waveforms (harmonics), We know that the measurement is always at the resonance peak, so the frequency vector should not change. Parameters ---------- h5_main : h5py.Dataset object Reference to the main dataset step_start_inds : list or 1D array Indices that correspond to the start of each BE pulse / UDVS step Returns --------- reshapable : Boolean Whether or not the number of bins per step are constant in this dataset """ if step_start_inds is None: h5_spec_inds = get_auxiliary_datasets(h5_main, aux_dset_name=['Spectroscopic_Indices'])[0] step_start_inds = np.where(h5_spec_inds[0] == 0)[0] # Adding the size of the main dataset as the last (virtual) step step_start_inds = np.hstack((step_start_inds, h5_main.shape[1])) num_bins = np.diff(step_start_inds) step_types = np.unique(num_bins) return len(step_types) == 1
def test_multiple(self): with h5py.File(data_utils.std_beps_path, mode='r') as h5_f: h5_main = h5_f['/Raw_Measurement/source_main'] h5_pos_inds = h5_f['/Raw_Measurement/Position_Indices'] h5_pos_vals = h5_f['/Raw_Measurement/Position_Values'] ret_val = hdf_utils.get_auxiliary_datasets( h5_main, aux_dset_name=['Position_Indices', 'Position_Values']) self.assertEqual(set(ret_val), set([h5_pos_inds, h5_pos_vals]))
def test_all(self): with h5py.File(data_utils.std_beps_path, mode='r') as h5_f: h5_main = h5_f['/Raw_Measurement/source_main'] expected = [ h5_f['/Raw_Measurement/Position_Indices'], h5_f['/Raw_Measurement/Position_Values'], h5_f['/Raw_Measurement/Spectroscopic_Indices'], h5_f['/Raw_Measurement/Spectroscopic_Values'] ] ret_val = hdf_utils.get_auxiliary_datasets(h5_main) self.assertEqual(set(expected), set(ret_val))
def plot_bayesian_spot_from_h5(h5_bayesian_grp, h5_resh, pix_ind, **kwargs): """ Plots the basic Bayesian Inference results for a specific pixel Parameters ---------- h5_bayesian_grp : h5py.Datagroup reference Group containing the Bayesian Inference results h5_resh : h5py.Dataset reference Dataset containing the raw / filtered measured current split by pixel pix_ind : unsigned int Integer index of the desired pixel Returns ------- fig : matplotlib.pyplot figure handle Handle to figure """ bias_triang = np.squeeze(h5_bayesian_grp['Spectroscopic_Values'][()]) h5_resistance = h5_bayesian_grp['Resistance'] h5_r_variance = h5_bayesian_grp['R_variance'] h5_i_corrected = h5_bayesian_grp['Corrected_Current'] i_meas = np.squeeze(h5_resh[pix_ind]) orig_bias = np.squeeze( get_auxiliary_datasets(h5_resh, aux_dset_name=['Spectroscopic_Values'])[0]) h5_pos = get_auxiliary_datasets(h5_resh, aux_dset_name=['Position_Indices'])[0] resistance = h5_resistance[pix_ind] i_correct = h5_i_corrected[pix_ind] r_variance = h5_r_variance[pix_ind] return plot_bayesian_results(orig_bias, i_meas, i_correct, bias_triang, resistance, r_variance, pix_pos=h5_pos[pix_ind], **kwargs)
def test_illegal_target_type_list(self): with h5py.File(data_utils.std_beps_path, mode='r') as h5_f: h5_main = h5_f['/Raw_Measurement/source_main'] with self.assertRaises(TypeError): _ = hdf_utils.get_auxiliary_datasets( h5_main, aux_dset_name=[14, 'Position_Indices'])
def test_illegal_dset_type(self): with self.assertRaises(TypeError): _ = hdf_utils.get_auxiliary_datasets( np.arange(5), aux_dset_name='Does_Not_Exist')
def test_illegal(self): with h5py.File(data_utils.std_beps_path, mode='r') as h5_f: h5_main = h5_f['/Raw_Measurement/source_main'] with self.assertRaises(KeyError): _ = hdf_utils.get_auxiliary_datasets( h5_main, aux_dset_name='Does_Not_Exist')