Exemplo n.º 1
0
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))
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)
uPTI_file.create_dataset('overlap', data=N_edge)

# ### Patch-wise processing
t0 = time.time()

for ll in range(len(ns)):

    position = ll
    writer.init_array(position,
                      data_shape,
                      chunk_size,
                      chan_names,
                      position_name=None,
                      overwrite=True)
    n_start = [int(ns[ll]), int(ms[ll])]

    # Compute background-removed Stokes vectors
    S_image_recon = setup.Stokes_recon(
        I_meas_full[:, :, n_start[0]:n_start[0] + Ns,
                    n_start[1]:n_start[1] + Ms, ::-1])
    S_bg_recon = setup.Stokes_recon(I_bg_full[:, :, n_start[0]:n_start[0] + Ns,
                                              n_start[1]:n_start[1] + Ms])

    S_image_tm = np.zeros_like(S_image_recon)
    S_image_tm[0] = S_image_recon[0] / S_bg_recon[0, :, :, :, np.newaxis] - 1
    S_image_tm[1] = S_image_recon[1] / S_bg_recon[
        0, :, :, :, np.newaxis] - S_bg_recon[
Exemplo n.º 3
0
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])