Skip to content

Configuring custom MDAEngine with YAML files #222

@JAMoreno-Larios

Description

@JAMoreno-Larios

Hi,

Thank you for working in making Micro-Manager scripting better for everyone.
I'm building a custom hyperspectral microscope using pymmcore-plus and useq-schema to control a Liquid Crystal Tunable Filter and a monochromator via serial port. For that, I subclassed the MDAEngine to set up these devices through the metadata field.

Currently, I am defining my experiments with the following functions, depending on what I need:

# Define configuration function
def configure_experiment_illumination(exposure, ext_wavelengths, em_wavelengths,
                                      loops, z_positions, channel_names,
                                      lctf_device_name):
    """
    Generates a list of MDAEvents following the next proceedure.
    We define exposure, the emission LCTF wavelength, the dichroic
    mirror to use and the number of times we want to repeat the measurement.
    We should be able to get a time series for a given configuration.
    """
    # Since we just want to generate lists, no additional validation is needed.
    experiment = []
    for position in range(0, len(z_positions)):
        for channel in channel_names:
            for excitation in ext_wavelengths:
                for emission in em_wavelengths:
                    for timepoint in range(0, loops):
                        event = useq.MDAEvent(exposure=exposure,
                                              z_pos=z_positions[position],
                                              channel=channel,
                                              keep_shutter_open=True,
                                              metadata = {
                                                  'timepoint' : timepoint,
                                                  'monochromator' : excitation,
                                                  'lctf' : (lctf_device_name,
                                                            'Wavelength', str(emission)),
                                                  'z_pos_index' : position,
                                                  'z_pos' : z_positions[position],})
                        experiment.append(event)
    return experiment

def configure_experiment_sets(exposure,
                              mirror_ext_em_set,
                              loops, z_positions,
                              lctf_device_name):
    """
    Similar to configure_experiment_illumination, but we expect the channel
    names, an excitation wavelength, and emission wavelengths to be input
    as a list of tuples,
    i. e. sets = [(mirror1, ext_wav1, list_of_em_wavelengths1), 
                  (mirror2, ext_wav2, list_of_em_wavelengths2),
                  (mirror3, ext_wav3, list_of_em_wavelengths3),...]
    so on and so forth.
    """
    # Since we just want to generate lists, no additional validation is needed.
    experiment = []
    for position in range(0, len(z_positions)):
        for channel, excitation, em_wavelengths in mirror_ext_em_set:
            for emission in em_wavelengths:
                for timepoint in range(0, loops):
                    event = useq.MDAEvent(exposure=exposure,
                                          z_pos=z_positions[position],
                                          channel=channel,
                                          keep_shutter_open=True,
                                          metadata = {
                                              'timepoint' : timepoint,
                                              'monochromator' : excitation,
                                              'lctf' : (lctf_device_name,
                                                        'Wavelength', str(emission)),
                                              'z_pos_index' : position,
                                              'z_pos' : z_positions[position],})
                    experiment.append(event)
    return experiment

With my approach, I cannot define tiling, and if someone different than me wants to use my scripts, I fear they will not be able to set up experiments easily. I wish to be able to define the experiments using a YAML file, what would be a good starting point?

Thanks,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions