-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Call BigStitcher by command line and read the results (#7)
* Add macro that calls big stitcher * Add function to call BigStitcher via the command line * Add functions to read the output of BigStitcher * Add stitch button to napari widget * Added tests for big_stitcher_bridge * Added tests for file_utils * Fixed tests to account for new defaults in stitch function * Added tests for new functions in image_mosaic * Added tests for new ImageMosaic and StitchingWidget functions * Updated docstring from big_stitcher_bridge * Updated docs for file_utils * Added docstrings for ImageMosaic and StitchingWidget * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * WIP apply suggestions from code review * More code review changes * Move test constants out of test_image_mosaic to conftest * Moved constants out of test_file_utils * Moved constants out of test_big_stitcher_bridge * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Make sure all ImageMosaic objects are explicitly cleaned up * Update error for wrong imagej path * WIP adding docstrings to test_stitching_widgets * Added docstrings to test_stitching_widget * Added comments for conftest.py * Added docstrings for test_big_stitcher_bridge * Added tests for test_image_mosaic * Add docstring to test_file_utils --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
f310c5a
commit 5ba8cf3
Showing
13 changed files
with
1,301 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import subprocess | ||
from pathlib import Path | ||
from platform import system | ||
|
||
|
||
def run_big_stitcher( | ||
imagej_path: Path, | ||
xml_path: Path, | ||
tile_config_path: Path, | ||
all_channels: bool = False, | ||
selected_channel: int = 488, | ||
downsample_x: int = 4, | ||
downsample_y: int = 4, | ||
downsample_z: int = 1, | ||
) -> subprocess.CompletedProcess: | ||
""" | ||
Run the BigStitcher ImageJ macro. Output is captured and returned as part | ||
of the subprocess.CompletedProcess. | ||
Parameters | ||
---------- | ||
imagej_path : Path | ||
The path to the ImageJ executable. | ||
xml_path : Path | ||
The path to the BigDataViewer XML file. | ||
tile_config_path : Path | ||
The path to the BigStitcher tile configuration file. | ||
all_channels : bool, optional | ||
Whether to stitch based on all channels (default False). | ||
selected_channel : int, optional | ||
The channel on which to base the stitching (default 488). | ||
downsample_x : int, optional | ||
The downsample factor in the x-dimension for the stitching (default 4). | ||
downsample_y : int, optional | ||
The downsample factor in the y-dimension for the stitching (default 4). | ||
downsample_z : int, optional | ||
The downsample factor in the z-dimension for the stitching (default 1). | ||
Returns | ||
------- | ||
subprocess.CompletedProcess | ||
The result of the subprocess run. | ||
Raises | ||
------ | ||
subprocess.CalledProcessError | ||
If the subprocess returns a non-zero exit status. | ||
""" | ||
stitch_macro_path = ( | ||
Path(__file__).resolve().parent / "bigstitcher_macro.ijm" | ||
) | ||
|
||
if system().startswith("Darwin"): | ||
imagej_path = imagej_path / "Contents/MacOS/ImageJ-macosx" | ||
|
||
command = ( | ||
f"{imagej_path} --ij2 " | ||
f"--headless -macro {stitch_macro_path} " | ||
f'"{xml_path} {tile_config_path} {int(all_channels)} ' | ||
f'{selected_channel} {downsample_x} {downsample_y} {downsample_z}"' | ||
) | ||
|
||
result = subprocess.run( | ||
command, capture_output=True, text=True, check=True, shell=True | ||
) | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
args = getArgument(); | ||
args = split(args, " "); | ||
xmlPath = args[0]; | ||
tilePath = args[1]; | ||
allChannels = args[2]; | ||
selectedChannel = args[3]; | ||
downSampleX = args[4]; | ||
downSampleY = args[5]; | ||
downSampleZ = args[6]; | ||
|
||
print("Stitching " + xmlPath); | ||
print("Loading TileConfiguration from " + tilePath) | ||
run( | ||
"Load TileConfiguration from File...", | ||
"browse=" + xmlPath + | ||
" select=" + xmlPath + | ||
" tileconfiguration=" + tilePath + | ||
" use_pixel_units keep_metadata_rotation" | ||
); | ||
|
||
print("Calculating pairwise shifts"); | ||
if (allChannels == 1) { | ||
run( | ||
"Calculate pairwise shifts ...", | ||
"select=" + xmlPath + | ||
" process_angle=[All angles] process_channel=[All channels] process_illumination=[All illuminations]" + | ||
" process_tile=[All tiles] process_timepoint=[All Timepoints]" + | ||
" method=[Phase Correlation] channels=[Average Channels]" + | ||
" downsample_in_x=" + downSampleX + | ||
" downsample_in_y=" + downSampleY + | ||
" downsample_in_z=" + downSampleZ | ||
); | ||
} else { | ||
run( | ||
"Calculate pairwise shifts ...", | ||
"select=" + xmlPath + | ||
" process_angle=[All angles] process_channel=[All channels] process_illumination=[All illuminations]" + | ||
" process_tile=[All tiles] process_timepoint=[All Timepoints]" + | ||
" method=[Phase Correlation] channels=[use Channel " + selectedChannel + " nm]" + | ||
" downsample_in_x=" + downSampleX + | ||
" downsample_in_y=" + downSampleY + | ||
" downsample_in_z=" + downSampleZ | ||
); | ||
} | ||
|
||
print("Optimizing globally and applying shifts"); | ||
run( | ||
"Optimize globally and apply shifts ...", | ||
"select=" + xmlPath + | ||
" process_angle=[All angles] process_channel=[All channels] process_illumination=[All illuminations]" + | ||
" process_tile=[All tiles] process_timepoint=[All Timepoints] relative=2.500 absolute=3.500" + | ||
" global_optimization_strategy=[Two-Round using Metadata to align unconnected Tiles and iterative dropping of bad links]" + | ||
" fix_group_0-0," | ||
); | ||
|
||
print("Done"); | ||
eval("script", "System.exit(0);"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.