def test_create_functions(setup_folder):
    """
    Test create root zarr, create position subfolders, and switching between
    position substores

    Parameters
    ----------
    setup_folder

    Returns
    -------

    """

    folder = setup_folder
    writer = WaveorderWriter(folder + '/Test',
                             hcs=True,
                             hcs_meta=hcs_meta,
                             verbose=False)

    writer.create_zarr_root('test_zarr_root')

    assert (writer.sub_writer.root_path == folder +
            '/Test/test_zarr_root.zarr')
    assert (writer.sub_writer.store is not None)

    # Check that the correct hierarchy was initialized
    cnt = 0
    for row in hcs_meta['plate']['rows']:
        for col in hcs_meta['plate']['columns']:
            for fov in range(1, 3):
                path = f'{row["name"]}/{col["name"]}/FOV{fov}'
                assert (isinstance(writer.sub_writer.store[path], zarr.Group))
                assert (writer.sub_writer.positions[cnt] == {
                    'name': f'FOV{fov}',
                    'row': row["name"],
                    'col': col["name"]
                })
                cnt += 1
Exemple #2
0
def test_create_functions(setup_folder):
    """
    Test create root zarr, create position subfolders, and switching between
    position substores

    Parameters
    ----------
    setup_folder

    Returns
    -------

    """

    folder = setup_folder
    writer = WaveorderWriter(folder + '/Test',
                             hcs=False,
                             hcs_meta=None,
                             verbose=False)

    writer.create_zarr_root('test_zarr_root')

    assert (writer.sub_writer.root_path == folder +
            '/Test/test_zarr_root.zarr')
    assert (writer.sub_writer.store is not None)
    assert (isinstance(writer.sub_writer.store['Row_0'], zarr.Group))

    # Check Plate Metadata
    assert ('plate' in writer.sub_writer.plate_meta)
    assert ('rows' in writer.sub_writer.plate_meta.get('plate').keys())
    assert ('columns' in writer.sub_writer.plate_meta.get('plate').keys())
    assert ('wells' in writer.sub_writer.plate_meta.get('plate').keys())
    assert (len(writer.sub_writer.plate_meta.get('plate').get('wells')) == 0)
    assert (len(writer.sub_writer.plate_meta.get('plate').get('columns')) == 0)
    assert (len(writer.sub_writer.plate_meta.get('plate').get('rows')) == 1)

    # Check Well metadata
    assert ('well' in writer.sub_writer.well_meta)
    assert (len(writer.sub_writer.well_meta.get('well').get('images')) == 0)
Exemple #3
0
def test_constructor_existing(setup_folder):
    """
    Test isntantiating the writer into an existing zarr directory

    Parameters
    ----------
    setup_folder

    Returns
    -------

    """

    folder = setup_folder

    writer = WaveorderWriter(folder + '/Test')
    writer.create_zarr_root('existing.zarr')

    writer_existing = WaveorderWriter(folder + '/Test/existing.zarr')

    assert (writer_existing.sub_writer.root_path == folder +
            '/Test/existing.zarr')
    assert (writer_existing.sub_writer.store is not None)
def test_constructor(setup_folder):
    """
    Test that constructor finds correct save directory

    Returns
    -------

    """
    folder = setup_folder
    writer_def = WaveorderWriter(folder + '/Test',
                                 hcs=True,
                                 hcs_meta=hcs_meta,
                                 verbose=False)

    assert (isinstance(writer_def.sub_writer, HCSZarr))
    assert (isinstance(writer_def.sub_writer, WriterBase))
                                z_defocus,
                                n_media=n_media,
                                cali=cali,
                                bg_option=bg_option,
                                A_matrix=A_matrix,
                                phase_deconv='3D',
                                inc_recon='3D',
                                illu_mode='Arbitrary',
                                Source=Source,
                                Source_PolState=Source_PolState,
                                use_gpu=use_gpu,
                                gpu_id=gpu_id)

# ### Writer setup
uPTI_file_name = 'uPTI_subFOVs.zarr'
writer = WaveorderWriter(output_path, hcs=False, hcs_meta=None, verbose=True)
writer.create_zarr_root(uPTI_file_name)

data_shape = (1, 9, N_defocus, int(Ns), int(Ms))
chunk_size = (1, 1, 1, int(Ns), int(Ms))
chan_names = [
    'f_tensor0r', 'f_tensor0i', 'f_tensor1c', 'f_tensor1s', 'f_tensor2c',
    'f_tensor2s', 'f_tensor3', 'mat_map0', 'mat_map1'
]

# append stitching parameters
row_list = (ns // N_space).astype('int')
column_list = (ms // M_space).astype('int')
uPTI_file = zarr.open(os.path.join(output_path, uPTI_file_name), mode='a')
uPTI_file.create_dataset('row_list', data=row_list)
uPTI_file.create_dataset('column_list', data=column_list)
retardance_pr_PT = np.array([((-1)**i) * wo.wavelet_softThreshold(
    ((-1)**i) * retardance_pr_PT[i], 'db8', 0.00303, level=1)
                             for i in range(2)])

# ## Visualize reconstructed physical properties of the anisotropic glass target
# ### Reconstructed phase, absorption, principal retardance, azimuth, and inclination assuming (+) and (-) optic sign
# browse the reconstructed physical properties
wo.plot_multicolumn(np.stack([phase_PT[...,44], retardance_pr_PT[0,:,:,44], azimuth[0,:,:,4], theta[0,:,:,44], \
                                             absorption_PT[...,44], retardance_pr_PT[1,:,:,44], azimuth[1,:,:,44], theta[1,:,:,44]]),
                    num_col=4, origin='lower', set_title=True, size=5, \
                    titles=[r'phase',r'principal retardance (+)', r'$\omega$ (+)', r'$\theta$ (+)',\
                            r'absorption',r'principal retardance (-)', r'$\omega$ (-)', r'$\theta$ (-)'])
plt.show()

# save results to zarr array
writer = WaveorderWriter('.', hcs=False, hcs_meta=None, verbose=True)
writer.create_zarr_root('Anisotropic_target_small_processed.zarr')
chan_names = [
    'f_tensor0r', 'f_tensor0i', 'f_tensor1c', 'f_tensor1s', 'f_tensor2c',
    'f_tensor2s', 'f_tensor3', 'mat_map0', 'mat_map1'
]
uPTI_array = np.transpose(
    np.concatenate((f_tensor, mat_map), axis=0)[np.newaxis, ...],
    (0, 1, 4, 2, 3))  # dimension (T, C, Z, Y, X)
data_shape = uPTI_array.shape
chunk_size = (1, 1, 1) + uPTI_array.shape[3:]
writer.init_array(0,
                  data_shape,
                  chunk_size,
                  chan_names,
                  position_name='f_tensor',
def test_write(setup_folder):
    """
    Test the write function of the writer

    Parameters
    ----------
    setup_folder

    Returns
    -------

    """

    folder = setup_folder
    writer = WaveorderWriter(folder + '/Test',
                             hcs=True,
                             hcs_meta=hcs_meta,
                             verbose=False)
    writer.create_zarr_root('test_zarr_root')

    data = np.random.randint(1,
                             60000,
                             size=(3, 3, 11, 128, 128),
                             dtype='uint16')

    data_shape = data.shape
    chunk_size = (1, 1, 1, 128, 128)
    chan_names = ['State0', 'State1', 'State3']
    clims = [(-0.5, 0.5), (0, 25), (0, 10000)]
    dtype = 'uint16'

    writer.init_array(0,
                      data_shape,
                      chunk_size,
                      chan_names,
                      dtype,
                      clims,
                      position_name=None,
                      overwrite=True)

    # Write single index for each channel
    writer.write(data[0, 0, 0], p=0, t=0, c=0, z=0)
    assert (np.array_equal(
        writer.sub_writer.store['A']['1']['FOV1']['arr_0'][0, 0, 0], data[0, 0,
                                                                          0]))

    # Write full data
    writer.write(data, p=0)
    assert (np.array_equal(
        writer.sub_writer.store['A']['1']['FOV1']['arr_0'][:, :, :, :, :],
        data))

    # Write full data with alt method
    writer.write(data, p=0, t=slice(0, 3), c=slice(0, 3), z=slice(0, 11))
    assert (np.array_equal(
        writer.sub_writer.store['A']['1']['FOV1']['arr_0'][:, :, :, :, :],
        data))
def test_init_array(setup_folder):
    """
    Test the correct initialization of desired array and the associated
    metadata

    Parameters
    ----------
    setup_folder

    Returns
    -------

    """

    folder = setup_folder
    writer = WaveorderWriter(folder + '/Test',
                             hcs=True,
                             hcs_meta=hcs_meta,
                             verbose=False)
    writer.create_zarr_root('test_zarr_root')

    data_shape = (3, 3, 21, 128, 128)  # T, C, Z, Y, X
    chunk_size = (1, 1, 1, 128, 128)
    chan_names = ['State0', 'State1', 'State3']
    clims = [(-0.5, 0.5), (0, 25), (0, 10000)]
    dtype = 'uint16'

    writer.init_array(0,
                      data_shape,
                      chunk_size,
                      chan_names,
                      dtype,
                      clims,
                      position_name=None,
                      overwrite=False)
    writer.init_array(11,
                      data_shape,
                      chunk_size,
                      chan_names,
                      dtype,
                      clims,
                      position_name='Test',
                      overwrite=False)

    assert (isinstance(writer.sub_writer.store['A']['1']['FOV1'], zarr.Group))
    meta_folder = writer.store['A']['1']['FOV1']
    meta = meta_folder.attrs.asdict()
    array = meta_folder['arr_0']

    assert (meta_folder is not None)
    assert (array is not None)
    assert (array.shape == data_shape)
    assert (array.chunks == chunk_size)
    assert (array.dtype == dtype)

    assert (meta is not None)
    assert ('multiscales' in meta)
    assert ('omero' in meta)
    assert ('rdefs' in meta['omero'])

    # Test Chan Names and clims
    for i in range(len(meta['omero']['channels'])):
        assert (meta['omero']['channels'][i]['label'] == chan_names[i])
        assert (meta['omero']['channels'][i]['window']['start'] == clims[i][0])
        assert (meta['omero']['channels'][i]['window']['end'] == clims[i][1])

    assert (isinstance(writer.sub_writer.store['B']['2']['FOV2'], zarr.Group))
    meta_folder = writer.store['B']['2']['FOV2']
    meta = meta_folder.attrs.asdict()
    array = meta_folder['arr_0']

    assert (meta_folder is not None)
    assert (array is not None)
    assert (array.shape == data_shape)
    assert (array.chunks == chunk_size)
    assert (array.dtype == dtype)

    assert (meta is not None)
    assert ('multiscales' in meta)
    assert ('omero' in meta)
    assert ('rdefs' in meta['omero'])

    # Test Chan Names and clims
    for i in range(len(meta['omero']['channels'])):
        assert (meta['omero']['channels'][i]['label'] == chan_names[i])
        assert (meta['omero']['channels'][i]['window']['start'] == clims[i][0])
        assert (meta['omero']['channels'][i]['window']['end'] == clims[i][1])