Skip to content

Commit

Permalink
Added functions to parse mesoSPIM metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorTatarnikov committed Dec 22, 2023
1 parent c531fec commit 62e0c7f
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs_build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
branches:
- main
tags:
- '*'
- 'v*'
pull_request:
workflow_dispatch:

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ modification, are permitted provided that the following conditions are met:
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of mesoSPIM-stitcher nor the names of its
* Neither the name of mesospim-stitcher nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ include LICENSE
include README.md
exclude .pre-commit-config.yaml

recursive-include mesospim_stitcher *.py

recursive-exclude * __pycache__
recursive-exclude * *.py[co]
recursive-exclude docs *
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# mesoSPIM-stitcher
# mesospim-stitcher
4 changes: 2 additions & 2 deletions docs/source/api_index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ API
math
----

.. currentmodule:: mesoSPIM-stitcher.math
.. currentmodule:: mesospim-stitcher.math

.. autosummary::
:toctree: api_generated
Expand All @@ -16,7 +16,7 @@ math
greetings
---------

.. currentmodule:: mesoSPIM-stitcher.greetings
.. currentmodule:: mesospim-stitcher.greetings

.. autosummary::
:toctree: api_generated
Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath("../.."))

project = "mesoSPIM-stitcher"
project = "mesospim_stitcher"
copyright = "2023, Igor Tatarnikov"
author = "Igor Tatarnikov"
try:
Expand Down Expand Up @@ -86,7 +86,7 @@
# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
html_theme = "pydata_sphinx_theme"
html_title = "mesoSPIM-stitcher"
html_title = "mesospim_stitcher"

# Customize the theme
html_theme_options = {
Expand Down
4 changes: 2 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.. mesoSPIM-stitcher documentation master file, created by
.. mesospim-stitcher documentation master file, created by
sphinx-quickstart on Fri Dec 9 14:12:42 2022.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to mesoSPIM-stitcher's documentation!
Welcome to mesospim-stitcher's documentation!
=========================================================

.. toctree::
Expand Down
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
84 changes: 84 additions & 0 deletions mesospim_stitcher/file_utils.py
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
8 changes: 4 additions & 4 deletions pyproject.toml
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"
Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -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
"""

0 comments on commit 62e0c7f

Please sign in to comment.