Skip to main content

Suite of tools for processing and reconstruction of electron tomography data

Project description

ETSpy

⚠️ ETSpy is still in a pre-release status, and the API may change with little warning, and the documentation may not be 100% correct/complete!

Documentation link PyPI - Python Version Conda versions

ETSpy is a HyperSpy extension package package for the processing, aligment, and reconstruction of electron tomography data from TEM/STEM instruments. Tools are provided for basic tilt series data processing, stack alignment, and reconstruction using the ASTRA Toolbox.

Installation

Depending on your system, there are a few ways to install ETSpy. Due to dependencies that require compilation of binaries and the use of GPU-accelerated libraries, conda is the simplest way to get started. It will auto-detect CUDA-capable GPUs and install the correct version of whatever packages are required.

⚠️ ETSpy requires a Python version >= 3.10 and <= 3.12 (3.13 and above are not supported due to dependencies). If installing manually using pip, please ensure you are using a supported version.

Anaconda (Preferred)

Works on Windows, MacOS, and Linux

  • First, ensure you have either Anaconda or Miniconda installed on your system.

  • Run the following command to create a new environment based on the contents of the ETSpy YAML specification file, which will install the required dependencies, and then activate the newly created environment:

    $ conda env create -f https://raw.githubusercontent.com/usnistgov/etspy/refs/heads/master/resources/etspy.yml
    # if you would like your environment to be stored in a specific place, use the "-p <path>" option
    
    $ conda activate etspy
    
  • Finally, (with the etspy environment activated), install the ETSpy package from PyPI:

    (etspy) $ pip install etspy
    

Optional Jupyter components (higly recommended)

  • To use ETSpy from within a Jupyter Lab/Notebook environment, a few other optional dependencies are required.

    • ipympl enables interactive plotting in Jupyter Lab or Notebook.
    • ipykernel allows use of the the etspy kernel with Jupyter installed in a different environment.
    (etspy) $ conda install ipympl ipykernel
    
  • To "register" the python kernel associated with the etspy conda environment, run the following after ensuring that environment is activated (with conda activate etspy):

    (etspy) $ python -m ipykernel install --user --name ETSpy
    

    You will then be able to select the "ETSpy" kernel when running Jupyter and creating new notebooks

Using pip

Works on Linux, with additional prerequisites

Assuming you have the prequisite packages on your system (including the CUDA libraries), ETSpy should be able to be installed with a simple pip command (it is recommended to install ETSpy in a dedicated virtual environment):

On Ubuntu-based systems, the NVIDIA/CUDA dependencies installed via the system-provided `nvidia-cuda-toolkit` apt package may be out of date and incompatible with the ASTRA toolkit. We recommend installing the version directly from NVIDIA.
  • $ pip install etspy
    
  • To use ETSpy in Jupyter interface from within a dedicated virtual environment, installing ipykernel and ipympl are necessary (as with Anaconda). This can be done by specifying the [jupyter] group when installing ETSpy:

    $ pip install etspy[jupyter]
    
  • To register the ETSpy virtual environment as a Jupyter kernel, run the following with the virtual environment enabled:

    (etspy) $ python -m ipykernel install --user --name ETSpy
    

Some dependencies of ETSpy require compilation of C code, meaning using the Anaconda approach above will simplify things greatly if you have trouble with "pure" pip.

Removal

The package can be removed with:

$ pip uninstall etspy

Developer instructions

If you wish to contribute to ETSpy or otherwise install a development version, this can be accomplished using either Anaconda or Poetry.

If using conda, create and activate a new environment using the development specification, clone the repository, and then install the package in "editable" mode using pip:

$ conda env create -f https://raw.githubusercontent.com/usnistgov/etspy/refs/heads/master/resources/etspy-dev.yml
$ conda activate etspy-dev
$ git clone https://github.com/usnistgov/etspy
$ cd etspy
$ pip install -e .

If using Poetry (currently only working on Linux), make sure you have poetry and the CUDA libraries installed, clone the etspy repository, and run the install command:

$ git clone https://github.com/usnistgov/etspy
$ cd etspy
$ poetry install
Sometimes, on headless Linux systems without a desktop environment installed, the `poetry install`
command will hang due to an outstanding issue with handling the system keyring
(see [this issue](https://github.com/python-poetry/poetry/issues/8623)). To workaround the issue,
run the command `export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring` prior to running
`poetry install`, and it should work. 

At this point, you should have an "editable" version of the latest development version of ETSpy installed to hack on as you wish.

Contributions to the project are welcome, and can be submitted via the GitHub pull request mechanism.

Basic Usage

The majority of the functionality of ETSpy can be accessed by importing the etspy.api module. For example, to load a tilt series dataset into a TomoStack, you could do the following:

import etspy.api as etspy
stack = etspy.load('TiltSeries.mrc')

For more details, see the dedicated documentation, including the example Jupyter notebook and the more detailed API Reference.

Development tips (testing and coverage)

ETSpy strives to have high code coverage through the use of tests in the etspy/tests/ directory. When developing, you can run the tests from the main directory with the following command, which will output the coverage results to the terminal, as well as to a etspy/tests/coverage.xml file that can be interpreted by various editors to display the coverage stats interactively, and as html in the etspy/tests/htmlcov directory that can be viewed in a web browser:

$ poetry run pytest etspy/tests/

By default, this will exclude CUDA-related code from the coverage report (via the [tool.coverage.report] setting in pyproject.toml), since most CI/CD systems will not have CUDA enabled. If you would like to run the tests with coverage (including CUDA), you can use the run_tests.sh helper script (on Linux), which will detect whether or not CUDA is available, and choose whether or not to exclude those lines from the report depending:

$ poetry run ./run_tests.sh

Debugging when using coverage

ETSpy has the test suite configured to automatically run code coverage analysis when using pytest. This interferes when using interactive debuggers (such as PyCharm or VSCode), since they use the same mechanism under the hood to inspect what code is being run. This will manifest as your breakpoints never triggering when running a "Debug" configuration. For more information, see the following links: one, two, three. There are a few workarounds discussed in those threads, but the gist is that when debugging, you should disable the coverage plugin to ensure that breakpoints will be hit. This varies depending on your IDE/setup, but one option for VSCode is to put the following configuration in your project's launch.json, which will ensure coverage is disabled when running "Debug test" via the PYTEST_ADDOPTS environment variable:

  {
      "name": "Debug Tests",
      "type": "debugpy",
      "request": "launch",
      "purpose": ["debug-test"],
      "console": "integratedTerminal",
      "justMyCode": false,
      "env": {"PYTEST_ADDOPTS": "--no-cov"}
  }

Releasing a version

Note: this is primarily documentation for the developers. Feel free to ignore

Testing a pre-release

# bump version using poetry
$ poetry version prerelease  # this will append the version number and a pre-release indicator e.g ".a0"
$ poetry lock  # ensure you've updated the lockfile and any dependencies
$ poetry build
$ poetry publish

Releasing a new version

Basically the same as above, but run poetry version patch rather than prerelease.

Related projects

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

etspy-0.9.3a3.tar.gz (66.5 MB view details)

Uploaded Source

Built Distribution

etspy-0.9.3a3-py3-none-any.whl (66.6 MB view details)

Uploaded Python 3

File details

Details for the file etspy-0.9.3a3.tar.gz.

File metadata

  • Download URL: etspy-0.9.3a3.tar.gz
  • Upload date:
  • Size: 66.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.7 Linux/6.6.57-1-lts

File hashes

Hashes for etspy-0.9.3a3.tar.gz
Algorithm Hash digest
SHA256 f598bf573058cfaeed5cc412691e3bbc07df1350b8fc6f4f0f29d8eba65e5c0d
MD5 f6a8884e703d93e4f38cecfdbc24fa29
BLAKE2b-256 87e295df7e958698daa59be64fd3576b38e09f0baa15a9916d9e7249d45e5f5f

See more details on using hashes here.

File details

Details for the file etspy-0.9.3a3-py3-none-any.whl.

File metadata

  • Download URL: etspy-0.9.3a3-py3-none-any.whl
  • Upload date:
  • Size: 66.6 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.7 Linux/6.6.57-1-lts

File hashes

Hashes for etspy-0.9.3a3-py3-none-any.whl
Algorithm Hash digest
SHA256 cacf897731141bbf22f1aef9f21d39f55a054958d5ea7c4505f25eaa4fcec3d7
MD5 aa5015808211c278622ccfc84e8fbca9
BLAKE2b-256 20b2845b73f62fa33334305809233d8f3d03259c19d780e322ed4f83df884e52

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page