tests/test_main.py
def random_raw_file(tmpdir, random_stack, metadata_obj):
    """
    This pytest factory writes as random stack to a binary file as it is
    saved by ThorImage in raw data capture mode.

    Parameters
    ----------
    area_mode : int
        Area mode of the acquisition.
    shape : tuple of int
        Shape of a single x-y frame.
    timepoints : int
        Number of timepoints.
    channels : tuple of strings
        Names of the channels.
    n_z : int
        Number of steps in z direction.
    flyback_frames : int
        Number of flyback frames.

    Returns
    -------
    file_path : PosixPath
        Path to binary file.
    metadata_for_raw : Metadata object
        Metadata object with the set parameters.
    images : tuple of numpy arrays
        Each element of the tuple is the acquired stack for a different channel.
    """

    def _random_raw_file(
        area_mode=0,
        shape=(50, 60),
        timepoints=10,
        channels=("ChanA", "ChanB"),
        n_z=1,
        flyback_frames=0,
    ):
        if area_mode == 2 or area_mode == 3:
            new_n_y_pixels = shape[0] / n_z
            assert (
                not new_n_y_pixels % 1
            ), "Invalid test parameter. For kymograph and line the y values has to be divisible by the number of z steps."
            new_n_y_pixels = int(new_n_y_pixels)
            shape = (new_n_y_pixels, shape[1])

        img_stacks = np.zeros(
            (timepoints, n_z + flyback_frames, len(channels)) + shape, dtype=np.uint16
        )
        for t in range(timepoints):
            for i in range(len(channels)):
                img_stacks[t, :n_z, i] = random_stack((n_z,) + shape)
        metadata_for_raw = metadata_obj(
            timepoints=timepoints,
            x_pixels=shape[1],
            y_pixels=shape[0],
            channels=channels,
            n_z=n_z,
            area_mode=area_mode,
        )
        file_path = tmpdir.join("Image_0001_0001.raw")
        sequence = img_stacks.flatten()
        out = bytearray(len(sequence) * 2)
        struct.pack_into(f"<{len(sequence)}H", out, 0, *sequence)
        with open(file_path, "xb") as f:
            f.write(out)
        return (
            file_path,
            metadata_for_raw,
            tuple((np.squeeze(img_stacks[:, :n_z, i]) for i in range(len(channels)))),
        )

    return _random_raw_file

    This pytest factory writes as random stack to a binary file as it is
    saved by ThorImage in raw data capture mode.

    Parameters
    ----------
    area_mode : int
        Area mode of the acquisition.
    shape : tuple of int
        Shape of a single x-y frame.
    timepoints : int
        Number of timepoints.
    channels : tuple of strings
        Names of the channels.
    n_z : int
        Number of steps in z direction.
    flyback_frames : int
        Number of flyback frames.

    Returns
    -------
    file_path : PosixPath
        Path to binary file.
    metadata_for_raw : Metadata object
        Metadata object with the set parameters.
    images : tuple of numpy arrays
        Each element of the tuple is the acquired stack for a different channel.
    
This pytest factory writes as random stack to a binary file as it is
saved by ThorImage in raw data capture mode.

Parameters

area_mode : int
Area mode of the acquisition.
shape : tuple of int
Shape of a single x-y frame.
timepoints : int
Number of timepoints.
channels : tuple of strings
Names of the channels.
n_z : int
Number of steps in z direction.
flyback_frames : int
Number of flyback frames.

Returns

file_path : PosixPath
Path to binary file.
metadata_for_raw : Metadata object
Metadata object with the set parameters.
images : tuple of numpy arrays
Each element of the tuple is the acquired stack for a different channel.
This pytest factory writes as random stack to a binary file as it is saved by ThorImage in raw data capture mode . Parameters area_mode : int Area mode of the acquisition . shape : tuple of int Shape of a single x - y frame . timepoints : int Number of timepoints . channels : tuple of strings Names of the channels . n_z : int Number of steps in z direction . flyback_frames : int Number of flyback frames . Returns file_path : PosixPath Path to binary file . metadata_for_raw : Metadata object Metadata object with the set parameters . images : tuple of numpy arrays Each element of the tuple is the acquired stack for a different channel .
def random_raw_file(tmpdir, random_stack, metadata_obj):
    def _random_raw_file(
        area_mode=0,
        shape=(50, 60),
        timepoints=10,
        channels=("ChanA", "ChanB"),
        n_z=1,
        flyback_frames=0,
    ):
        if area_mode == 2 or area_mode == 3:
            new_n_y_pixels = shape[0] / n_z
            assert (
                not new_n_y_pixels % 1
            ), "Invalid test parameter. For kymograph and line the y values has to be divisible by the number of z steps."
            new_n_y_pixels = int(new_n_y_pixels)
            shape = (new_n_y_pixels, shape[1])
        img_stacks = np.zeros(
            (timepoints, n_z + flyback_frames, len(channels)) + shape, dtype=np.uint16
        )
        for t in range(timepoints):
            for i in range(len(channels)):
                img_stacks[t, :n_z, i] = random_stack((n_z,) + shape)
        metadata_for_raw = metadata_obj(
            timepoints=timepoints,
            x_pixels=shape[1],
            y_pixels=shape[0],
            channels=channels,
            n_z=n_z,
            area_mode=area_mode,
        )
        file_path = tmpdir.join("Image_0001_0001.raw")
        sequence = img_stacks.flatten()
        out = bytearray(len(sequence) * 2)
        struct.pack_into(f"<{len(sequence)}H", out, 0, *sequence)
        with open(file_path, "xb") as f:
            f.write(out)
        return (
            file_path,
            metadata_for_raw,
            tuple((np.squeeze(img_stacks[:, :n_z, i]) for i in range(len(channels)))),
        )
    return _random_raw_file
def random_raw_file ( tmpdir , random_stack , metadata_obj ) : def _random_raw_file ( area_mode = 0 , shape = ( 50 , 60 ) , timepoints = 10 , channels = ( "ChanA" , "ChanB" ) , n_z = 1 , flyback_frames = 0 , ) : if area_mode == 2 or area_mode == 3 : new_n_y_pixels = shape [ 0 ] / n_z assert ( not new_n_y_pixels % 1 ) , "Invalid test parameter. For kymograph and line the y values has to be divisible by the number of z steps." new_n_y_pixels = int ( new_n_y_pixels ) shape = ( new_n_y_pixels , shape [ 1 ] ) img_stacks = np . zeros ( ( timepoints , n_z + flyback_frames , len ( channels ) ) + shape , dtype = np . uint16 ) for t in range ( timepoints ) : for i in range ( len ( channels ) ) : img_stacks [ t , : n_z , i ] = random_stack ( ( n_z , ) + shape ) metadata_for_raw = metadata_obj ( timepoints = timepoints , x_pixels = shape [ 1 ] , y_pixels = shape [ 0 ] , channels = channels , n_z = n_z , area_mode = area_mode , ) file_path = tmpdir . join ( "Image_0001_0001.raw" ) sequence = img_stacks . flatten ( ) out = bytearray ( len ( sequence ) * 2 ) struct . pack_into ( f"<{len(sequence)}H" , out , 0 , * sequence ) with open ( file_path , "xb" ) as f : f . write ( out ) return ( file_path , metadata_for_raw , tuple ( ( np . squeeze ( img_stacks [ : , : n_z , i ] ) for i in range ( len ( channels ) ) ) ) , ) return _random_raw_file
This pytest factory writes as random stack to a binary file as it is
saved by ThorImage in raw data capture mode.
This pytest factory writes as random stack to a binary file as it is saved by ThorImage in raw data capture mode .
"""
    This pytest factory writes as random stack to a binary file as it is
    saved by ThorImage in raw data capture mode.

    Parameters
    ----------
    area_mode : int
        Area mode of the acquisition.
    shape : tuple of int
        Shape of a single x-y frame.
    timepoints : int
        Number of timepoints.
    channels : tuple of strings
        Names of the channels.
    n_z : int
        Number of steps in z direction.
    flyback_frames : int
        Number of flyback frames.

    Returns
    -------
    file_path : PosixPath
        Path to binary file.
    metadata_for_raw : Metadata object
        Metadata object with the set parameters.
    images : tuple of numpy arrays
        Each element of the tuple is the acquired stack for a different channel.
    """
tmpdir
random_stack
metadata_obj