dystrack.manager.manager#

The main event loop manager.

dystrack.manager.manager.run_dystrack_manager(target_dir, image_analysis_func, max_checks=None, max_triggers=None, end_on_esc=True, delay=1.0, recurse=False, file_start='', file_end='', file_regex='', img_kwargs={}, img_cache={}, img_err_fallback=True, tra_method='txt', tra_kwargs={}, tra_err_resume=False, write_txt=True)#

Manages an event loop that monitors a target directory for new files. For each new file found that matches user-defined criteria, the speficied image analysis pipeline is triggered and the results are transmitted to the microscope.

The loop keeps going until max_checks checks for added files have been done or until max_triggers image analysis events have been triggered, whichever is lower. Alternatively, the loop will end if the Esc key is hit, provided end_on_esc is True.

Parameters:
  • target_dir (path-like) – Path to the directory that is to be monitored.

  • image_analysis_func (callable) –

    Function that performs image analysis on detected files and returns new coordinates for transmission to the microscope. Call signature:

    z_pos, y_pos, x_pos, img_msg, img_cache = image_analysis_func(
        target_path, **img_kwargs, **img_cache)
    

  • max_checks (int or None, optional, default None) – Maximum number of checks for new files performed before exiting.

  • max_triggers (int or None, optional, default None) – Maximum number of image analysis pipeline calls before exiting.

  • max_targets (int or None, optional, default None) – Maximum number of target files sent to analysis before exiting.

  • end_on_esc (bool, optional, default True) – If True, hitting the Esc key will terminate the loop.

  • delay (float, optional, default 1.0) – Time (in seconds) to wait before the next check if no new files have been found in the target directory.

  • recurse (bool, optional, default False) – If True, subdirectories of target_dir are monitored recursively.

  • file_start (string, optional, default "") – Only files that start with this string will trigger the pipeline.

  • file_end (string, optional, default "") – Only files that end with this string will trigger the pipeline.

  • file_regex (string, optional, default "") – A regex pattern. Only file names that fully match this pattern will trigger the pipeline.

  • img_kwargs (dict, optional, default {}) – Additional parameters passed to the image analysis function.

  • img_cache (dict, optional, default {}) – Additional parameters passed to the image analysis function. This will be overwritten by the 4th output of the function (after the coordinate values) and passed again during the next loop. Use this to pass values forward across analysis loops, e.g. for use as priors.

  • img_err_fallback (bool, optional, default True) – Whether or not to fall back to the previous coordinates if an image analysis call fails.

  • tra_method (str or callable, optional, default "txt") –

    String indicating the method to use for transmitting coordinates to the microscope, or alternatively a custom callable. String options:

    • ”txt” : Write to txt file in target_dir (“dystrack_coords.txt”)

    • ”MyPiC” : Write to the Windows registry for ZEN Black MyPiC macro

    Call signature for custom transmission function:

    tra_method(
        z_pos, y_pos, x_pos,
        img_msg, img_cache, img_error,
        target_dir, **tra_kwargs)
    

  • tra_kwargs (dict, optional, default {}) – Additional parameters passed to the coordiante transmission function.

  • tra_err_resume (bool, optional, default False) – Whether to resume monitoring after transmission of detected coordinates to the microscope has terminally failed.

  • write_txt (bool, optional, default True) – If True, coordinates are recorded in a txt file (“dystrack_coords.txt”) in target_dir regardless of the specified tra_method. If said method is “txt”, this has no effect as the file is generated anyway.

Returns:

  • coordinates (list of [float, float, float]) – List of all coordinates that have been detected during image analysis (or as a fallback). Coordinates are given as [z_pos, y_pos, x_pos].

  • stats_dict (dict) –

    A dictionary containing the following stats about the run:

    • No. of checks made (check_counter)

    • No. of new files found (found_counter)

    • No. of target files found (target_counter)

    • No. of successful image analysis calls (img_success_counter)

    • No. of successful coordiate transmissions (tra_success_counter)