-
Notifications
You must be signed in to change notification settings - Fork 37
Developer Installation
This guide assumes you are familiar with the Python path and Python environments. See Python Primer for more info.
The Contributing guide highlights what is expected if you submit issues or pull requests.
There are a few installation techniques and file layouts to use when installing Nion Swift. This one assumes you will be installing for development.
The Nion Swift project is broken into several distinct libraries.
-
nionswiftcontains the Nion Swift application. It utilizes the libraries below. -
nionutilscontains utility functions that are used by other libraries, but not Nion Swift specific. -
niondatacontains the data algorithms and works in conjunctions with NumPy and Scipy. -
nionuicontains a general Pythonic user interface API that is used for Nion Swift, but not Nion Swift specific. -
nionswift-iocontains file handlers for importing/exporting data. -
nionswift-instrumentation-kitcontains acquisition related user interface and algorithms. -
nionswift-toolcontains a Python launcher based on Qt/C++ with high performance display (threaded, low latency, high throughput).
The nionswift project is split into various packages and namespaces.
The nion.utils namespace in the nionutils package contains utility functions and classes used by the other packages.
The nion.ui namespace in the nionui package contains a general Pythonic user interface API.
The nion.data namespace in the niondata package contains data processing algorithms and works in conjunctions with NumPy and Scipy.
The nion.swift.model namespace in nionswift package contains the non-UI portion of Nion Swift. Classes in this namespace do not utilize UI widgets or canvas items, although they may utilize a drawing context. They also do not reference anything in the nion.swift namespace.
The nion.swift namespace in nionswift package contains the UI portion of Nion Swift. Classes in this namespace may reference anything in any other namespace.
The "Nion Swift" program is a Python program running within a backend application launcher. There are a few different launchers available for different purposes.
-
nionswift-toolis the recommended launcher. It is a native C++ program that provides high performance display capabilities for everyday use. - The
PySide6launcher utilizes the official Qt Python bindings to launch Nion Swift. It is native C++ for the Qt part but does not provide high performance display capabilities. However, it is useful for launching Nion Swift with a Python debugger and also for prototyping Qt-based changes to eventually go intonionswift-tool. ThePyQtProxy.pyfile implements the bulk of the underlying UI in Python when launching using this technique. -
nionui-toolis the underlying C++ launcher on whichnionswift-toolis based. It is nearly identical except for the executable name, icon, and default Python application (i.e. branding). This would be the place for development of the launcher tool itself.
To launch Nion Swift using the nionswift-tool from the command line, first ensure both nionswift and nionswift-tool are installed (see below) and then run either of these commands from the command line:
nionswift
python -m nionswift --ui tool --no-fallback
To launch Nion Swift using the nionui-tool from the command line, first ensure both nionswift and nionui-tool are installed (see below) and then run either of these commands from the command line (note: you have to specify the application to run when running nionui-tool, whereas nionswift-tool always uses nionui_app.nionswift as the application):
nionui nionui_app.nionswift
python -m nionui --ui tool --no-fallback nionswift
To launch Nion Swift using the PySide6 Qt package from the command line, first ensure both nionswift and pyside6 are installed (see below) and then run either of these commands from the command line:
python -m nionswift --ui qt --no-fallback
python -m nionui --ui qt --no-fallback nionswift
If you are making changes to nionui-tool itself, you can build it locally and run it directly with something like the following command:
/path/to/NionUILauncher.exe /path/to/python/environment nionui_app.nionswift
If you are making changes to nionui-tool that have been merged but not released, the build artifacts will be available in the Artifacts section of the appropriate workflow run for the GitHub action here.
After finding the appropriate workflow run and the artifact matching your environment, you will download the artifact, unzip it, then install it from the command line using conda install /path/to/conda-artifact.tar.gz or something similar. Then you can use the instructions above to run the installed version of nionui-tool.
Nion Swift can be installed and launched using several Python environments and flavors.
- Using Miniconda or Miniforge and the
conda-forgeinstallation channel. This is useful when you need the latest versions of common libraries. - Using PyPI. This is usually installed into a Python virtual environment. This is useful when you do not want to use a
condabased installation. - Using Anaconda/Miniconda and the
nioninstallation channel. This is useful when you want to use an Anaconda official installation. - Using an installer (currently only available for Windows and macOS). The installer includes a full Python environment based on the official Python distribution and the PyPI packages. This is experimental and currently difficult to extend with custom packages.
Once you have decided on your environment, you should activate it and create a virtual environment in which to install Nion Swift. The instructions below assume a conda-forge installation using Miniconda.
On Windows, ensure that the Visual C++ Redistributables for VS 2015 is installed.
On Linux, if you are launching with nionui-tool or nionswift-tool, ensure that qt5-default is installed.
sudo apt-get install qt5-default.
- Install NotePad++
- Install Git
- Install conda (
C:\NionApps\Miniconda3)
C:\NionApps\Miniconda3\Scripts\Activate.bat
conda create -n developer -c conda-forge scipy pytz h5py imageio pillow tzlocal tifffile pip mypy -y
conda activate developer
conda config --env --add channels conda-forge
conda config --env --add channels nion
conda config --env --remove channels defaults
conda config --env --show channels
cd C:\NionApps
mkdir Developer\main
cd Developer\main
git clone https://github.com/nion-software/nionutils.git
git clone https://github.com/nion-software/niondata.git
git clone https://github.com/nion-software/nionui.git
git clone https://github.com/nion-software/nionswift.git
git clone https://github.com/nion-software/nionswift-io.git
git clone https://github.com/nion-software/nionswift-instrumentation-kit.git
git clone https://github.com/nion-software/nionswift-video-capture.git
git clone https://github.com/nion-software/eels-analysis.git nionswift-eels-analysis
git clone https://github.com/nion-software/experimental.git nionswift-experimental
# only if you are installing the microscope simulator.
git clone https://github.com/nion-software/nionswift-usim.git
# editable install type checking: see https://github.com/python/mypy/issues/13392
# use the following line on macos before running the commands below
export SETUPTOOLS_ENABLE_FEATURES="legacy-editable"
# use the following line on windows
set SETUPTOOLS_ENABLE_FEATURES=legacy-editable
python -m pip install --no-deps --editable nionutils
python -m pip install --no-deps --editable niondata
python -m pip install --no-deps --editable nionui
python -m pip install --no-deps --editable nionswift
python -m pip install --no-deps --editable nionswift-io
python -m pip install --no-deps --editable nionswift-instrumentation-kit
python -m pip install --no-deps --editable nionswift-video-capture
python -m pip install --no-deps --editable nionswift-eels-analysis
python -m pip install --no-deps --editable nionswift-experimental
# only if you are installing the microscope simulator.
python -m pip install --no-deps --editable nionswift-usim
conda install -c nion nionswift-tool
- Copy the DLL files to Python environment (if installing for acquisition).
conda update --all
- install PyCharm CE, run with defaults
- configure the Python interpreter to point to your developer environment
- create a new project using the directory
Developer\main - add configuration (Python)
- enter
nionswiftfor module name and--ui tool --no-fallbackfor the parameters. - double check by running
python -m nionswift --ui tool --no-fallbackfrom the command line.
You can launch nionswift with PyCharm CE using the alternate slower front-end based on Qt for Python.
- follow the instructions above
- install the
pyside6package. - add configuration (Python)
- enter
nionswiftfor module name and--ui qt --no-fallbackfor the parameters. - launch the configuration using the debugger.
- Activate your Python environment with Swift installed
-
nionswiftfrom command line
Most nionswift related packages enforce strict type checking. To run type checking locally using the command line:
- ensure your conda development environment is activated
- ensure
mypyis installed in your conda development environment - change directory to package to be type checked (i.e.
nionswift) - run type checking with
mypycommand, which will read the filemypy.inifor options specific to the package you're type checking.
You can also install the PyCharm MyPy Plug-in for live type checking, although the plug-in is somewhat less reliable (misses some failures; highlights some things that aren't failures) than running type checking from the command line.
Most type checks are run in strict mode.
In each project, refer to the .github/workflows/python-package.yml for specific commands to run type checking.
This script / gist may serve as a useful template for running mass type checks from the command line.
Each package contributing to nionswift has associated integration tests.
To run the tests for a specific package, add a Run/Debug Configuration (see PyCharm Run/debug configurations) with the Python Tests > Unittests type. Select your preferred Python interpreter. Select Custom. Then add additional arguments according to the specific module you are testing.
| Module | Target | Additional Arguments for Test |
|---|---|---|
| nionswift | Custom | discover -s nionswift/nion/swift/test -p "*_test.py" |
| nionutils | Custom | discover -s nionutils/nion/utils/test -p "*_test.py" |
| niondata | Custom | discover -s niondata/nion/data/test -p "*_test.py" |
| nionui | Custom | discover -s nionui/nion/ui/test -p "*_test.py" |
| nionswift-io (DM) | Module name | dm3parser_test.TestDM3ImportExportClass |
| nionswift-instrumentation-kit | Custom | discover -s nion/instrumentation/test -p "*_test.py" |
| eels-analysis (lib) | Custom | discover nionswift-eels-analysis/nion -v -p '*_test.py' |
| eels-analysis (UI) | Custom | discover nionswift-eels-analysis/nionswift_plugin -v -p '*_test.py' |
You can also write a script to run all tests at once. You can run scripts like this from PyCharm by creating a new Run/Debug Configuration as a Python configuration. Choose your interpreter and point the script to your test script.
Each project also runs tests for each commit and PR on GitHub actions. To see how these tests are run, refer to the GitHub actino file in each project .github/workflows/python-package.yml. These files contain specific commands to run the tests for their respective package.
pushd nionutils
git pull origin master
popd
pushd niondata
git pull origin master
popd
pushd nionui
git pull origin master
popd
pushd nionswift
git pull origin master
popd
pushd nionswift-io
git pull origin master
popd
pushd nionswift-instrumentation-kit
git pull origin master
popd
pushd nionswift-video-capture
git pull origin master
popd
pushd nionswift-eels-analysis
git pull origin master
popd
pushd nionswift-experimental
git pull origin master
popd
git clone https://github.com/nion-software/nionswift-usim.git
pushd nionswift-usim
python setup.py develop --no-deps
popd
pushd nionswift-usim
git pull origin master
popd