Viewer Core

ViewerWorkEnv

This objects stores the data that the Viewer interacts with.

class mesmerize.viewer.core.ViewerWorkEnv(imgdata=None, sample_id='', UUID=None, meta=None, stim_maps=None, roi_manager=None, roi_states=None, comments='', origin_file='', custom_cols=None, history_trace: list = None, additional_data: dict = None, misc: dict = None, **kwargs)[source]
_UUID = None

UUID, if opened from a project Sample refers to the ImgUUID

__init__(imgdata=None, sample_id='', UUID=None, meta=None, stim_maps=None, roi_manager=None, roi_states=None, comments='', origin_file='', custom_cols=None, history_trace: list = None, additional_data: dict = None, misc: dict = None, **kwargs)[source]

A class that encapsulates the main work environment objects (img sequence, ROIs, and ROI associated curves) of the viewer. Allows for a work environment to be easily spawned from different types of sources and allows for a work environment to be easily saved in different ways regardless of the type of original data source.

Parameters:
  • roi_states (dict) – roi states from ROI Manager module
  • stim_maps (dict) – {‘units’: str, ‘dataframe’: pd.DataFrame}
  • history_trace (list) – list of dicts containing a traceable history of what what done with the work environment, such as params used from modules to process the data
__weakref__

list of weak references to the object (if defined)

static _organize_meta(meta: dict, origin: str) → dict[source]

Organize input meta data dict into a uniform structure :param meta: meta data dict, origin from a json file for example :param origin: name of the origin source of the meta data, such a program or microscope etc. :return: dict organized with keys that are used throughout Mesmerize.

clear()[source]

Cleanup of the work environment

classmethod from_mesfile(mesfile_object: mesmerize.viewer.core.mesfile.MES, img_reference: str)[source]

Return instance of work environment with MesmerizeCore.ImgData class object using seq returned from MES.load_img from MesmerizeCore.FileInput module and any stimulus map that the user may have specified.

Parameters:
classmethod from_pickle(pickle_file_path: str, tiff_path: str = None)[source]

Get pickled image data from a pickle file & image sequence from a npz or tiff. Used after motion correction & to view a sample from a project DataFrame. Create ImgData class object (See MesmerizeCore.DataTypes) and return instance of the work environment.

Param:pickle_file_path: full path to the pickle containing image metadata, stim maps, and roi_states
Param:tiff_path: str of the full path to a tiff file containing the image sequence
classmethod from_tiff(path: str, method: str, meta_path: Optional[str] = '')[source]

Return instance of work environment with ImgData.seq set from the tiff file.

Parameters:
  • path – path to the tiff file
  • method – one of ‘imread’, ‘asarray’, or ‘asarray-multi’. Refers to usage of either tifffile.imread or tifffile.asarray. ‘asarray-multi’ will load multi-page tiff files.
  • meta_path – path to a json file containing meta data
history_trace = None

history log

imgdata = None

ImgData instance

isEmpty = None

Return True if the work environment is empty

static load_mesfile(path: str) → mesmerize.viewer.core.mesfile.MES[source]

Just passes the path of a .mes file to the constructor of class MES in MesmerizeCore.FileInput. Loads .mes file & constructs MES obj from which individual images & their respective metadata can be loaded to construct viewer work environments using the classmethod viewerWorkEnv.from_mesfile.

Parameters:path – full path to a single .mes file.
roi_manager = None

reference to the back-end ROI Manager that is currently in use

sample_id = None

SampleID, if opened from a project Sample

stim_maps = None

Stimulus maps

to_pandas(proj_path: str, modify_options: Optional[dict] = None) → list[source]

Used for saving the work environment as a project Sample.

Parameters:
  • proj_path – Root path of the current project
  • modify_options
Returns:

list of dicts that each correspond to a single curve that can be appended as rows to the project dataframe

to_pickle(dir_path: str, filename: Optional[str] = None, save_img_seq=True, UUID=None) → str[source]

Package the current work Env ImgData class object (See MesmerizeCore.DataTypes) and any paramteres such as for motion correction and package them into a pickle & image seq array. Used for batch motion correction and for saving current sample to the project. Image sequence is saved as a tiff and other information about the image is saved in a pickle.

ImgData

class mesmerize.viewer.core.data_types.ImgData(seq: numpy.ndarray = None, meta: dict = None)[source]

Object that stores the image sequence and meta data from the imaging source

__init__(seq: numpy.ndarray = None, meta: dict = None)[source]
Parameters:
  • seq – Image sequence as a numpy array, shape is [x, y, t]
  • meta – Meta data dict from the imaging source.

ViewerUtils

The Viewer is usually not interacted with directly from modules outside of the viewer (such as viewer modules. They instead use the ViewerUtils class which includes helper functions and a reference to the viewer.

class mesmerize.viewer.core.ViewerUtils(viewer_reference: <module 'mesmerize.pyqtgraphCore.imageview.ImageView' from '/home/kushal/MESmerize/mesmerize/pyqtgraphCore/imageview/ImageView.py'>)[source]
__init__(viewer_reference: <module 'mesmerize.pyqtgraphCore.imageview.ImageView' from '/home/kushal/MESmerize/mesmerize/pyqtgraphCore/imageview/ImageView.py'>)[source]

Some utility functions for interfacing viewer.core.ViewerWorkEnv with the pyqtgraphCore.ImageView widget

__weakref__

list of weak references to the object (if defined)

_clear_workEnv(clear_sample_id=False)[source]

Cleanup of the ViewerWorkEnv and ImageView widget

discard_workEnv(clear_sample_id=False)[source]

Ask the user if they want to discard their work environment. If Yes, calls _clear_workEnv()

update_workEnv()[source]

Update the ImageView widget with the ViewerWorkEnv

viewer = None

reference to the pyqtgraph ImageView widget instance (viewer)

work_env = None

ViewerWorkEnv instance

Mesfile

class mesmerize.viewer.core.mesfile.MES(filename: str)[source]

Handles of opening .mes files and organizing the images and meta data. The load_img() method returns a 3D array (dims are [time, cols, rows]) of the image sequence and its associated meta data.

Usage: Create a MES instance by passing the path of your mes file, example:

mesfile = MES(‘/path/to/mesfile/experiment_Feb_31.mes’)

Call the get_image_references() method to get a list of references for images that can be loaded.

To load an image that is available in the instance, just pass one of the references from get_image_references() to the load_img method:

img_array, meta_dict = mesfile.load_img(‘IF0001_0001’)
__init__(filename: str)[source]
Parameters:filename – full path of a single .mes file
__weakref__

list of weak references to the object (if defined)

get_image_references() → list[source]

Get a list of all image references available in the instance

load_img(img_reference: str) -> (<class 'numpy.ndarray'>, <class 'dict'>)[source]
Parameters:img_reference – The image reference, usually something like IFxxxx_xxxx or Ifxxxx_xxxx
Returns:(image sequence array, meta data dict)