Git Product home page Git Product logo

mcsim's Introduction

preprint paper website Github commit

multicolor DMD-SIM

This repository contains code for designing, analyzing, and carrying out multicolor structured illumination microscopy experiments based on a digital micromirror device (DMD-SIM), including DMD simulation code, DMD pattern generation, SIM reconstruction and instrument control. It also includes a number of useful utilities for simulating the resulting diffraction pattern given certain DMD patterns, determining system point-spread functions and optical transfer functions, and determining the affine transformation between the DMD coordinates and the imaging space coordinates. The various files are described in more detail below.

Published work using this code

Installation

The best way to use this python package is to install it with pip

git clone https://github.com/QI2lab/mcSIM.git
cd mcSIM
pip install .

If you would like to edit the code, then install using the -e option,

git clone https://github.com/QI2lab/mcSIM.git
cd mcSIM
pip install -e .

The dependencies for the experimental control code are not installed by default because the DMD control code relies on the Windows specific pywinusb. To install these dependencies run

git clone https://github.com/QI2lab/mcSIM.git
cd mcSIM
pip install .[expt_ctrl]

Some functions can be optionally run on a GPU. This functionality has been tested with CUDA 11.2 and 11.8. If GPU support is desired, first install CuPy manually, and then install mcSIM with pip. For example, if you are using a conda environment and CUDA toolkit 11.8

conda install -c conda-forge cudatoolkit=11.8
git clone https://github.com/QI2lab/mcSIM.git
cd mcSIM
pip install .[gpu]

This will install the appropriate version of the scikit-image portion of cuCIM. Note that the entire package cannot be installed on Windows, but the scikit-image portion can. This portion of cuCIM can be installed manually using

pip install "git+https://github.com/rapidsai/[email protected]#egg=cucim&subdirectory=python/cucim"

or the tag v22.12.00 can be replaced with the most recent version

SIM reconstruction code

Code for reconstructing SIM images from raw data using a Gustafsson/Heintzmann Wiener filter style reconstruction. Several reconstruction options are available, largely following either the approach of openSIM or fairSIM. To get started with reconstructing SIM data, see the example scripts

DMD simulation code

Code for simulating the diffraction patterns produced by the DMD. Various scripts illustrating the usage of this code can be found in the examples directory. This simulation code has many useful features, including an analytic solution for the joint blaze/diffraction condition, pattern simulation tools, tools for extracting the intensity pattern in the Fourier plane of a collecting lens, etc. For example usage, see

This file can be used to generate multicolor SIM patterns and other useful calibrations patterns for the DMD. It also contains many tools for working with the basis vector/unit cell representation of DMD patterns. This allows a complete enumeration of DMD diffraction orders in a compact and computationally efficient form.

Utility code

Code to fit the affine transformation between the DMD coordinates and camera coordinates using imaging data from a DMD pattern consisting of many small points. These code relies on tools for working with affine transformations found here. For example usage, see

Code for extracting optical transfer function from measurement of the strength of various Fourier peaks for a given SIM DMD pattern.

Miscellaneous image processing tools, primarily for working with Fourier transforms

Useful tools for automatically localizing sparse fluorescent beads and performing both 2D and 3D PSF fitting using various PSF models. Also provides useful statistics and figures summarizing the results. This code has now been split out into a separate repository. For more information about these tools, see the readme pip installing the mcsim repository as described above will also pull in these dependencies.

Examples

Scripts illustrated examples of different DMD simulations and analysis are stored in examples. Associated data necessary to run some of these examples can be downloaded from Zenodo. These scripts assume this data has been placed in a directory called examples/data

Hardware control code

Hardware control is based around MicroManager2.0. Currently, we control the instrument using a fork of the napari-micromanager project which controls the MicroManager core using pymmcore-plus. Our fork of this project relies on MicroManager device drives to control cameras and stages, and on python code to control the DMD and DAQ. The "device adapters" for the DMD and DAQ are found below

Code for controlling the DLP6500 DMD over USB on Windows. This code was initially based on the approaches of Lightcrafter6500DMDControl and Pycrafter6500. Extension to other operating systems has not been implemented but should be straightforward.

This file also includes functions used to define pattern sequences on the DMD using patterns have either been previously loaded onto the firmware using the Texas Instruments DLP6500 and DLP9000 GUI or which are loaded "on-the-fly". There is a low-level interface for running these patterns based directly on their index in the firmware. There is also a higher-level interface which supports defining "channels" and "modes" which can be saved in a json configuration file.

When run as a script, this file provides a command line interface to programming DMD pattern sequences.

Code for controlling a national instruments DAQ through PyDAQmx

DAQ configuration file describing "modes" and "channels" for the DAQ. This file is used by nidaq instances created with daq.py

This file is used to create DAQ sequences for SIM and ODT experiments

expt_ctrl/*.cfg

MicroManager configuration files describing the equipment and settings used in the experiment.

useful script files

Example scripts which are useful for controlling various instruments during testing include load_dmd_pattern.py, setup_optotune_mre2.py, and set_dmd_odt_pattern.py

Instrument design

A parts list is available here. Mechanical drawings and 3D models of custom parts such as the DMD mount are available on Zenodo. For a more complete description of the optical path, see our BOE paper linked above.

Documentation

Documentation is generated from function docstrings and built with Sphinx. e.g. navigate to docs and run

make html

Then open docs/_build/html/index.html in your browser

Acknowlegements

Thank you to Songyun Gu for extending the DMD control code to work with the DLP9000

mcsim's People

Contributors

dpshepherd avatar ptbrown1729 avatar sjshep avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mcsim's Issues

cupy-related install issue on Windows

Via email exchange Christophe Leterrier,

Ran into an error setting up mcsim. Other CUDA based packages work on his machine using system CUDA. I thought it might be the cupy version, but now I am not so sure.

One idea that comes to mind is a potential python=3.11 issue. Have we tested with that version?

Environment creation and python call:

conda create -n mcsim_env
conda activate mcsim_env
cd C:\Users\chris\christo\Processing
conda install pip
git clone [https://github.com/QI2lab/mcSIM.git](https://urldefense.com/v3/__https://github.com/QI2lab/mcSIM.git__;!!IKRxdwAv5BmarQ!avDFKv2snekFYnaCqbJ-cR51YIeiU-VsHMO61fgln81lQI2jwurr6RHQ-tqBgUcDUjPz4ungXil6dgsl1gI4ztxm9540HW1Yc8SPiA$)
cd mcSIM
pip install .[gpu]
cd examples
python reconstruction_sim_gpu_repeatedly.py

Error:

(mcsim_env) C:\Users\chris\christo\Processing\mcSIM>python ./examples/reconstruction_sim_gpu_repeatedly.py
Traceback (most recent call last):
  File "C:\Users\chris\.conda\envs\mcsim_env\Lib\site-packages\cupy\__init__.py", line 17, in <module>
    from cupy import _core  # NOQA
    ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\chris\.conda\envs\mcsim_env\Lib\site-packages\cupy\_core\__init__.py", line 3, in <module>
    from cupy._core import core  # NOQA
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "cupy\_core\core.pyx", line 1, in init cupy._core.core
  File "C:\Users\chris\.conda\envs\mcsim_env\Lib\site-packages\cupy\cuda\__init__.py", line 8, in <module>
    from cupy.cuda import compiler  # NOQA
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\chris\.conda\envs\mcsim_env\Lib\site-packages\cupy\cuda\compiler.py", line 13, in <module>
    from cupy.cuda import device
  File "cupy\cuda\device.pyx", line 1, in init cupy.cuda.device
ImportError: DLL load failed while importing runtime: Le module spécifié est introuvable.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\chris\christo\Processing\mcSIM\examples\reconstruction_sim_gpu_repeatedly.py", line 7, in <module>
    import cupy as cp
  File "C:\Users\chris\.conda\envs\mcsim_env\Lib\site-packages\cupy\__init__.py", line 19, in <module>
    raise ImportError(f'''
ImportError:
================================================================
Failed to import CuPy.

If you installed CuPy via wheels (cupy-cudaXXX or cupy-rocm-X-X), make sure that the package matches with the version of CUDA or ROCm installed.

On Linux, you may need to set LD_LIBRARY_PATH environment variable depending on how you installed CUDA/ROCm.
On Windows, try setting CUDA_PATH environment variable.

Check the Installation Guide for details:
  [https://docs.cupy.dev/en/latest/install.html](https://urldefense.com/v3/__https://docs.cupy.dev/en/latest/install.html__;!!IKRxdwAv5BmarQ!cOM0Y-teafEDZSikbEeamol8WyQOsx6UJLd5YJ0ov9vGvxo8ejMMOtQDKhnCHmIoyZ8c_vIuuq5GAK_NZwLD_JD3Z9Uv4m3Qo_0rLg$)

CUDA Path: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6
DLL dependencies:
  KERNEL32.dll -> C:\WINDOWS\System32\KERNEL32.DLL
  MSVCP140.dll -> C:\Users\chris\.conda\envs\mcsim_env\MSVCP140.dll
  VCRUNTIME140.dll -> C:\Users\chris\.conda\envs\mcsim_env\VCRUNTIME140.dll
  api-ms-win-crt-convert-l1-1-0.dll -> C:\WINDOWS\System32\ucrtbase.dll
  api-ms-win-crt-environment-l1-1-0.dll -> C:\WINDOWS\System32\ucrtbase.dll
  api-ms-win-crt-filesystem-l1-1-0.dll -> C:\WINDOWS\System32\ucrtbase.dll
  api-ms-win-crt-heap-l1-1-0.dll -> C:\WINDOWS\System32\ucrtbase.dll
  api-ms-win-crt-runtime-l1-1-0.dll -> C:\WINDOWS\System32\ucrtbase.dll
  api-ms-win-crt-stdio-l1-1-0.dll -> C:\WINDOWS\System32\ucrtbase.dll
  cuTENSOR.dll -> not found
  cublas64_11.dll -> not found
  cudart64_110.dll -> not found
  cudnn64_8.dll -> not found
  cufft64_10.dll -> not found
  curand64_10.dll -> not found
  cusolver64_11.dll -> not found
  cusparse64_11.dll -> not found
  nvcuda.dll -> C:\WINDOWS\SYSTEM32\nvcuda.dll
  nvrtc64_112_0.dll -> not found
  python311.dll -> C:\Users\chris\.conda\envs\mcsim_env\python311.dll

Original error:
  ImportError: DLL load failed while importing runtime: Le module spécifié est introuvable.
=============

Conda package list

# packages in environment at C:\Users\chris\.conda\envs\mcsim_env:
#
# Name                    Version                   Build  Channel
asciitree                 0.3.3                    pypi_0    pypi
bzip2                     1.0.8                h8ffe710_4    conda-forge
ca-certificates           2023.5.7             h56e8100_0    conda-forge
click                     8.1.3                    pypi_0    pypi
cloudpickle               2.2.1                    pypi_0    pypi
colorama                  0.4.6                    pypi_0    pypi
contourpy                 1.1.0                    pypi_0    pypi
cucim                     23.2.0                   pypi_0    pypi
cupy-cuda11x              12.1.0                   pypi_0    pypi
cycler                    0.11.0                   pypi_0    pypi
dask                      2023.6.0                 pypi_0    pypi
dask-image                2023.3.0                 pypi_0    pypi
entrypoints               0.4                      pypi_0    pypi
fasteners                 0.18                     pypi_0    pypi
fastrlock                 0.8.1                    pypi_0    pypi
fonttools                 4.40.0                   pypi_0    pypi
fsspec                    2023.6.0                 pypi_0    pypi
h5py                      3.9.0                    pypi_0    pypi
imageio                   2.31.1                   pypi_0    pypi
importlib-metadata        6.7.0                    pypi_0    pypi
joblib                    1.2.0                    pypi_0    pypi
kiwisolver                1.4.4                    pypi_0    pypi
lazy-loader               0.2                      pypi_0    pypi
libexpat                  2.5.0                h63175ca_1    conda-forge
libffi                    3.4.2                h8ffe710_5    conda-forge
libsqlite                 3.42.0               hcfcfb64_0    conda-forge
libzlib                   1.2.13               hcfcfb64_5    conda-forge
llvmlite                  0.40.1rc1                pypi_0    pypi
localize-psf              0.2.0                    pypi_0    pypi
locket                    1.0.0                    pypi_0    pypi
matplotlib                3.7.1                    pypi_0    pypi
mcsim                     1.4.0                    pypi_0    pypi
networkx                  3.1                      pypi_0    pypi
numba                     0.57.0                   pypi_0    pypi
numcodecs                 0.11.0                   pypi_0    pypi
numpy                     1.24.3                   pypi_0    pypi
openssl                   3.1.1                hcfcfb64_1    conda-forge
packaging                 23.1                     pypi_0    pypi
pandas                    2.0.2                    pypi_0    pypi
partd                     1.4.0                    pypi_0    pypi
pillow                    9.5.0                    pypi_0    pypi
pims                      0.6.1                    pypi_0    pypi
pip                       23.1.2             pyhd8ed1ab_0    conda-forge
psutil                    5.9.5                    pypi_0    pypi
pyparsing                 3.1.0                    pypi_0    pypi
python                    3.11.4          h2628c8c_0_cpython    conda-forge
python-dateutil           2.8.2                    pypi_0    pypi
pytz                      2023.3                   pypi_0    pypi
pywavelets                1.4.1                    pypi_0    pypi
pyyaml                    6.0                      pypi_0    pypi
scikit-image              0.21.0                   pypi_0    pypi
scipy                     1.10.1                   pypi_0    pypi
setuptools                67.7.2             pyhd8ed1ab_0    conda-forge
six                       1.16.0                   pypi_0    pypi
slicerator                1.1.0                    pypi_0    pypi
tifffile                  2023.4.12                pypi_0    pypi
tk                        8.6.12               h8ffe710_0    conda-forge
toolz                     0.12.0                   pypi_0    pypi
tzdata                    2023.3                   pypi_0    pypi
ucrt                      10.0.22621.0         h57928b3_0    conda-forge
vc                        14.3                hb25d44b_16    conda-forge
vc14_runtime              14.34.31931         h5081d32_16    conda-forge
vs2015_runtime            14.34.31931         hed1258a_16    conda-forge
wheel                     0.40.0             pyhd8ed1ab_0    conda-forge
xz                        5.2.6                h8d14728_0    conda-forge
zarr                      2.15.0                   pypi_0    pypi
zipp                      3.15.0                   pypi_0    pypi

Error notification of the DMD simulation code

Hallo,
Firstly, thanks for providing the code for all!
I have downloaded the code and wanna to try to do some simulation with your code. But when i tried the example first, it came with a error notification and it cant go through the code. Could you have a look of the error and find where is the problem?

C:\Users\wanghaoran\Desktop\SIM_simulation\mcSIM-master\mcsim\simulate_dmd.py:582: RuntimeWarning: invalid value encountered in sqrt
  bz = -np.sqrt(1 - bx**2 - by**2)
Traceback (most recent call last):

  File "C:\Users\wanghaoran\Desktop\SIM_simulation\mcSIM-master\mcsim\simulate_dmd.py", line 1586, in <module>
    tout_offsets=np.linspace(-25, 25, 150) * np.pi / 180)

  File "C:\Users\wanghaoran\Desktop\SIM_simulation\mcSIM-master\mcsim\simulate_dmd.py", line 1146, in simulate_2d
    zip(tx_out[ii, jj].ravel(), ty_out[ii, jj].ravel())

  File "C:\Users\wanghaoran\.conda\envs\tfcpu2\lib\site-packages\joblib\parallel.py", line 1041, in __call__
    if self.dispatch_one_batch(iterator):

  File "C:\Users\wanghaoran\.conda\envs\tfcpu2\lib\site-packages\joblib\parallel.py", line 859, in dispatch_one_batch
    self._dispatch(tasks)

  File "C:\Users\wanghaoran\.conda\envs\tfcpu2\lib\site-packages\joblib\parallel.py", line 777, in _dispatch
    job = self._backend.apply_async(batch, callback=cb)

  File "C:\Users\wanghaoran\.conda\envs\tfcpu2\lib\site-packages\joblib\_parallel_backends.py", line 208, in apply_async
    result = ImmediateResult(func)

  File "C:\Users\wanghaoran\.conda\envs\tfcpu2\lib\site-packages\joblib\_parallel_backends.py", line 572, in __init__
    self.results = batch()

  File "C:\Users\wanghaoran\.conda\envs\tfcpu2\lib\site-packages\joblib\parallel.py", line 263, in __call__
    for func, args, kwargs in self.items]

  File "C:\Users\wanghaoran\.conda\envs\tfcpu2\lib\site-packages\joblib\parallel.py", line 263, in <listcomp>
    for func, args, kwargs in self.items]

  File "C:\Users\wanghaoran\Desktop\SIM_simulation\mcSIM-master\mcsim\simulate_dmd.py", line 122, in simulate_dmd
    phases = phase_fn(mxmx, mymy, amb[0], amb[1])

IndexError: index 1 is out of bounds for axis 0 with size 1

Thanks for your supporting!

issue with set_trigger_out function

Hey,

I am having an issue with the "set_trigger_out" in dlp6500.py.

On line 1188 (for me), "data = trig_byte + rising_edge_bytes + falling_edge_bytes" is leading to a type error. I have attached a screenshot below.

Thank You,
Forest

Screen Shot 2023-05-30 at 5 55 31 PM

Can't import dmd_patterns

Hi, I'm trying to start using mcSIM but I got stuck right away.
It can't find localize_psf module.

In [4]: from mcsim.analysis import dmd_patterns
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[4], line 1
----> 1 from mcsim.analysis import dmd_patterns

File ~/Area51/DMD/mcSIM/mcsim/analysis/dmd_patterns.py:23
     21 from matplotlib.patches import Circle
     22 #
---> 23 import mcsim.analysis.analysis_tools as tools
     24 from mcsim.analysis import simulate_dmd
     25 from localize_psf import affine

File ~/Area51/DMD/mcSIM/mcsim/analysis/analysis_tools.py:8
      6 import numpy as np
      7 from typing import Union, Optional
----> 8 import localize_psf.rois as rois
     10 _cupy_available = True
     11 try:

ModuleNotFoundError: No module named 'localize_psf'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.