def setup_reconstructed_data_small_npy(setup_gdrive_src_data_small): """ Loads AND Reconstructs SOURCE data. SIZE: 512 x 512 TYPE: .npy :param setup_gdrive_src_data_small: :return: physical data object containing reconstructed data """ bg_dat, sm_dat = setup_gdrive_src_data_small # compute initial reconstructor using background data img_reconstructor = ImgReconstructor(bg_dat, swing=0.03, wavelength=532) bg_stokes = img_reconstructor.compute_stokes(bg_dat) bg_stokes_normalized = img_reconstructor.stokes_normalization(bg_stokes) # compute sample stokes and correct with background data sm_stokes = img_reconstructor.compute_stokes(sm_dat) sm_stokes_normalized = img_reconstructor.stokes_normalization(sm_stokes) sm_stokes_normalized = img_reconstructor.correct_background(sm_stokes_normalized, bg_stokes_normalized) reconstructed_birefring = img_reconstructor.reconstruct_birefringence(sm_stokes_normalized) yield reconstructed_birefring
def test_complete_reconstruction(setup_gdrive_src_data_small): """ tests compute sequence: background correction of birefringence from intensity data one z, one t, one p No config file parsing No plotting Parameters ---------- setup_gdrive_src_data_small : pytest fixture to load data from gdrive Returns ------- """ bg_dat, sm_dat = setup_gdrive_src_data_small # compute initial reconstructor using background data img_reconstructor = ImgReconstructor(bg_dat, swing=0.03, wavelength=532) bg_stokes = img_reconstructor.compute_stokes(bg_dat) bg_stokes_normalized = img_reconstructor.stokes_normalization(bg_stokes) # compute sample stokes and correct with background data sm_stokes = img_reconstructor.compute_stokes(sm_dat) sm_stokes_normalized = img_reconstructor.stokes_normalization(sm_stokes) sm_stokes_normalized = img_reconstructor.correct_background( sm_stokes_normalized, bg_stokes_normalized) reconstructed_birefring = img_reconstructor.reconstruct_birefringence( sm_stokes_normalized) assert reconstructed_birefring.I_trans is not None assert reconstructed_birefring.retard is not None assert reconstructed_birefring.azimuth is not None assert reconstructed_birefring.polarization is not None
def setup_reconstructed_data_small_tif(setup_gdrive_src_data_small): """ Loads AND Reconstructs SOURCE data. SIZE: 512 x 512 TYPE: .tif :param setup_gdrive_src_data_small: :return: physical data object containing reconstructed data """ bg_dat, sm_dat = setup_gdrive_src_data_small # compute initial reconstructor using background data img_reconstructor = ImgReconstructor(bg_dat, swing=0.03, wavelength=532) bg_stokes = img_reconstructor.compute_stokes(bg_dat) bg_stokes_normalized = img_reconstructor.stokes_normalization(bg_stokes) # compute sample stokes and correct with background data sm_stokes = img_reconstructor.compute_stokes(sm_dat) sm_stokes_normalized = img_reconstructor.stokes_normalization(sm_stokes) sm_stokes_normalized = img_reconstructor.correct_background(sm_stokes_normalized, bg_stokes_normalized) reconstructed_birefring = img_reconstructor.reconstruct_birefringence(sm_stokes_normalized) # target data is scaled to uint16 (.tif) spol = (65536*(reconstructed_birefring.polarization - reconstructed_birefring.polarization.min()) / (reconstructed_birefring.polarization.ptp())).astype('uint16') sazi = (65536*(reconstructed_birefring.azimuth - reconstructed_birefring.azimuth.min()) / (reconstructed_birefring.azimuth.ptp())).astype('uint16') stran = (65536*(reconstructed_birefring.I_trans - reconstructed_birefring.I_trans.min()) / (reconstructed_birefring.I_trans.ptp())).astype('uint16') sret = (65536*(reconstructed_birefring.retard - reconstructed_birefring.retard.min()) / (reconstructed_birefring.retard.ptp())).astype('uint16') reconstructed_birefring.I_trans = stran reconstructed_birefring.retard = sret reconstructed_birefring.polarization = spol reconstructed_birefring.azimuth = sazi yield reconstructed_birefring
sample_bg_corrected_local_fit = img_reconstructor.correct_background( sample_normalized, background_normalized) img_reconstructor.bg_method = "Local_filter" sample_bg_corrected_local_filter = img_reconstructor.correct_background( sample_normalized, background_normalized) img_reconstructor.bg_method = None sample_bg_corrected_global = img_reconstructor.correct_background( sample_normalized, background_normalized) #%% print('computing physical') # let's compute physical using several background correction methods sample_physical_local_fit = img_reconstructor.reconstruct_birefringence( sample_bg_corrected_local_fit) sample_physical_local_filter = img_reconstructor.reconstruct_birefringence( sample_bg_corrected_local_filter) sample_physical_global = img_reconstructor.reconstruct_birefringence( sample_bg_corrected_global) #%% from ReconstructOrder.utils.plotting import im_bit_convert print('calculate mse') target_retardance = tf.imread( '/Users/bryant.chhun/Desktop/Data/ForDataStructuresTests/Processed/img_Retardance_t010_p000_z002.tif' ) target_orientation = tf.imread(