imcflibs
Python convenience from and for the IMCF (Imaging Core Facility).
IMCFlibs ๐ โ ๐ฉ ๐ง ๐ช
This package contains a diverse collection of Python functions dealing with paths, I/O (file handles, ...), strings etc. and tons of Fiji / ImageJ2 convenience wrappers to simplify scripting and reduce cross-script redundanciees.
Initially this has been a multi-purpose package where a substantial part had
been useful in CPython as well. However, since the latest Jython
release is still based on Python 2.7 (see the Jython 3 roadmap for
more info), imcflibs is now basically limited to the Fiji / ImageJ2
ecosystem (which is also the reason why no pip installable package is
provided).
Releases are made through Maven and published to the SciJava Maven
repository. The easiest way to use the lib is by adding the IMCF
Uni Basel update site to your ImageJ installation.
Developed and provided by the Imaging Core Facility (IMCF) of the Biozentrum, University of Basel, Switzerland.
Example usage
Shading correction / projection
Apply a shading correction model and create a maximum-intensity projection:
from imcflibs.imagej.shading import correct_and_project
model = "/path/to/shading_model.tif"
raw_image = "/path/to/raw_data/image.ome.tif"
out_path = "/path/to/processed_data/"
correct_and_project(raw_image, out_path, model, "Maximum", ".ics")
Split TIFFs by channels and slices
- See the Split_TIFFs_By_Channels_And_Slices.py script.
Use status and progress bar updates
- See the FluoView_OIF_OIB_OIR_Simple_Stitcher.py script.
Testing ๐งช in Fiji / ImageJ2
Unfortunately there is nothing like pytest available for the parts that are
running exclusively in a ImageJ2 / Fiji context. So in order to provide at least
some basic, semi-interactive tests the following conventions are being used:
- Each function in any of the
imcflibs.imagejsubmodules should have its own directory underneath/tests/imagej/, using their fully qualified name as the path (only skipping theimcflibs.prefix). For example test scripts forimcflibs.imagej.bioformats.import_image()will be placed in the directory/tests/imagej/bioformats/import_image/. - The scripts inside those directories are intended to be run interactively / manually in a (freshly started) Fiji instance. Yes, really. Any other suggestions are highly welcome!
- To facilitate this, a collection of test images (and possibly other input
data) should be cloned to the local file system. Currently this
sample_datarepository is NOT publicly available due to legal โ uncertainties. A repo containing test data ๐ that can be published should be assembled over time though! - Any interactive test script should start with a header similar to the one
described below. Paths to input data inside the test scripts has to be
relative to the location of the
sample_datarepository mentioned above. This will allow for a fairly okayish testing workflow like this:- Make your changes in VS Code, then trigger a build by pressing
Shift+Ctrl+B. If things are configured as described in the DEVELOPMENT document, the resulting.jarfile will be automatically placed in Fiji'sjars/folder. - Next, start a fresh instance of the Fiji that received the newly built JAR.
- After Fiji has started, simply drag and drop the desired test script onto
the main window. This will open the Script Editor, then press
Ctrl+Rto launch the script. - Only on the first run on the machine being used you will have to select the
base location of the
sample_datarepository. - All subsequent runs of any test script using the defined Script
Parameter
IMCF_TESTDATAwill remember this selection, so it will be sufficient to just confirm the dialog by pressingEnter.
- Make your changes in VS Code, then trigger a build by pressing
Test Script Template ๐
As described above, each test script should use the IMCF_TESTDATA parameter to
facilitate the manual testing approach. Simply use this template header for
creating new scripts (or look into existing ones):
# @ File (label="IMCF testdata location", style="directory") IMCF_TESTDATA
import os
from imcflibs.pathtools import join2
testfile = join2(IMCF_TESTDATA, "systems/lsm700/beads/10x_phmax.czi")
assert os.path.exists(testfile)
In case the test requires the components of the testfile's path to be used, this snippet will do the job:
# @ File (label="IMCF testdata location", style="directory") IMCF_TESTDATA
import os
from imcflibs.pathtools import parse_path
components = parse_path("systems/lsm700/beads/10x_phmax.czi", IMCF_TESTDATA)
assert os.path.exists(components["full"])
Changelog ๐งพ
1.3.0
Added
- New functions in
imcflibs.pathtools:imcflibs.pathtools.join2can be used to join paths, much likeos.path.joinexcept that it will work withjava.io.Fileobjects as well (but doesn't support more than two path components / parameters).imcflibs.pathtools.find_dirs_containing_filetypeimcflibs.pathtools.folder_size
- New functions in
imcflibs.imagej.misc: - New
imcflibs.imagej.labelimagesubmodule, providing: - New
imcflibs.imagej.gpusubmodule, providing: - New
imcflibs.imagej.resultstablesubmodule, providing: - New
imcflibs.imagej.roimanagersubmodule, providing:imcflibs.imagej.roimanager.add_rois_to_roimanagerimcflibs.imagej.roimanager.change_roi_colorimcflibs.imagej.roimanager.clear_ij_roi_managerimcflibs.imagej.roimanager.count_all_roisimcflibs.imagej.roimanager.enlarge_all_roisimcflibs.imagej.roimanager.extract_color_of_all_roisimcflibs.imagej.roimanager.get_roimanagerimcflibs.imagej.roimanager.load_rois_from_zipimcflibs.imagej.roimanager.measure_in_all_roisimcflibs.imagej.roimanager.rename_rois_by_numberimcflibs.imagej.roimanager.rename_roisimcflibs.imagej.roimanager.save_rois_to_zipimcflibs.imagej.roimanager.scale_all_roisimcflibs.imagej.roimanager.select_rois_above_min_intensityimcflibs.imagej.roimanager.shift_roi_by_bounding_boximcflibs.imagej.roimanager.show_all_rois_on_image
Changed
- The functions below now also accept parameters of type
java.io.File(instead ofstr), making them safe for being used directly with variables retrieved via ImageJ2's Script Parameter@# File: - Several changes in
imcflibs.pathtools.parse_path:- The returned dict now contains an additional key
basenamethat provides the filename without extension. - OME-TIFF filenames are now treated as special cases in the sense that the
.omepart is stripped from thebasenamekey and added to theextkey instead (as it is part of the suffix).
- The returned dict now contains an additional key
imcflibs.pathtools.listdir_matchingnow has an additional optional argumentsort(defaulting toFalse) to request the resulting list to be sorted.- Many improvements / clarifications in function docstrings.
1"""Python convenience from and for the IMCF (Imaging Core Facility). 2 3.. include:: ../../README.md 4 5.. include:: ../../TESTING.md 6 7.. include:: ../../CHANGELOG.md 8""" 9 10__version__ = "${project.version}" 11 12from . import iotools 13from . import log 14from . import pathtools 15from . import strtools 16 17# check if we're running in Jython, then also import the 'imagej' submodule: 18import platform as _python_platform 19 20if _python_platform.python_implementation() == "Jython": 21 from . import imagej 22del _python_platform