-
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.
Added functions to parse mesoSPIM metadata
- Loading branch information
1 parent
c531fec
commit 62e0c7f
Showing
10 changed files
with
100 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ on: | |
branches: | ||
- main | ||
tags: | ||
- '*' | ||
- 'v*' | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
|
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
# mesoSPIM-stitcher | ||
# mesospim-stitcher |
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
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from importlib.metadata import PackageNotFoundError, version | ||
|
||
try: | ||
__version__ = version("mesoSPIM-stitcher") | ||
__version__ = version("mesospim_stitcher") | ||
except PackageNotFoundError: | ||
# package is not installed | ||
pass |
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,84 @@ | ||
from pathlib import Path | ||
|
||
HEADERS = [ | ||
"[POSITION]", | ||
"[ETL PARAMETERS]", | ||
"[GALVO PARAMETERS]", | ||
"[CAMERA PARAMETERS]", | ||
] | ||
|
||
|
||
def write_big_stitcher_tile_config(meta_file_name: Path) -> list[dict]: | ||
tile_metadata = parse_mesospim_metadata(meta_file_name) | ||
|
||
output_file = str(meta_file_name)[:-12] + "_tile_config.txt" | ||
|
||
first_channel = tile_metadata[0]["Laser"] | ||
num_channels = 1 | ||
|
||
for metadata in tile_metadata[1:]: | ||
if metadata["Laser"] == first_channel: | ||
break | ||
else: | ||
num_channels += 1 | ||
|
||
num_tiles = len(tile_metadata) // num_channels | ||
tile_xy_locations = [] | ||
|
||
for i in range(0, len(tile_metadata), num_channels): | ||
curr_tile_dict = tile_metadata[i] | ||
|
||
x = round(curr_tile_dict["x_pos"] / curr_tile_dict["Pixelsize in um"]) | ||
y = round(curr_tile_dict["y_pos"] / curr_tile_dict["Pixelsize in um"]) | ||
|
||
tile_xy_locations.append((x, y)) | ||
|
||
relative_locations = [(0, 0)] | ||
|
||
for abs_tuple in tile_xy_locations[1:]: | ||
rel_tuple = ( | ||
abs(abs_tuple[0] - tile_xy_locations[0][0]), | ||
abs(abs_tuple[1] - tile_xy_locations[0][1]), | ||
) | ||
relative_locations.append(rel_tuple) | ||
|
||
with open(output_file, "w") as f: | ||
f.write("dim=3\n") | ||
for i in range(len(tile_metadata)): | ||
f.write( | ||
f"{i};;" | ||
f"({relative_locations[i%num_tiles][0]}," | ||
f"{relative_locations[i%num_tiles][1]},0)\n" | ||
) | ||
|
||
return tile_metadata | ||
|
||
|
||
def parse_mesospim_metadata(meta_file_name: Path): | ||
tile_metadata = [] | ||
with open(meta_file_name, "r") as f: | ||
lines = f.readlines() | ||
curr_tile_metadata: dict[str, str | int | float] = {} | ||
|
||
for line in lines[3:]: | ||
line = line.strip() | ||
if line.startswith("[CFG"): | ||
tile_metadata.append(curr_tile_metadata) | ||
curr_tile_metadata = {} | ||
elif line in HEADERS: | ||
continue | ||
elif not line: | ||
continue | ||
else: | ||
split_line = line.split("]") | ||
value = split_line[1].strip() | ||
if value.isdigit(): | ||
curr_tile_metadata[split_line[0][1:]] = int(value) | ||
else: | ||
try: | ||
curr_tile_metadata[split_line[0][1:]] = float(value) | ||
except ValueError: | ||
curr_tile_metadata[split_line[0][1:]] = value | ||
|
||
tile_metadata.append(curr_tile_metadata) | ||
return tile_metadata |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[project] | ||
name = "mesoSPIM-stitcher" | ||
name = "mesospim-stitcher" | ||
authors = [{name = "Igor Tatarnikov", email= "[email protected]"}] | ||
description = "A tool to stich large tiled datasets generated by the mesoSPIM." | ||
readme = "README.md" | ||
|
@@ -52,12 +52,12 @@ build-backend = "setuptools.build_meta" | |
include-package-data = true | ||
|
||
[tool.setuptools.packages.find] | ||
include = ["mesoSPIM-stitcher*"] | ||
include = ["mesospim-stitcher*"] | ||
exclude = ["tests", "docs*"] | ||
|
||
|
||
[tool.pytest.ini_options] | ||
addopts = "--cov=mesoSPIM-stitcher" | ||
addopts = "--cov=mesospim-stitcher" | ||
|
||
[tool.black] | ||
target-version = ['py39', 'py310', 'py311'] | ||
|
@@ -100,5 +100,5 @@ python = | |
extras = | ||
dev | ||
commands = | ||
pytest -v --color=yes --cov=mesoSPIM-stitcher --cov-report=xml | ||
pytest -v --color=yes --cov=mesospim-stitcher --cov-report=xml | ||
""" |