Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set-scale utility #228

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
9e0bc16
add update_scale_metadata.py
aaronalvarezcz Jul 2, 2024
59ab2ac
add update-scale-metadata command to cli
aaronalvarezcz Jul 2, 2024
6217bad
add zyx flags for update-scale-metadata utility
aaronalvarezcz Jul 2, 2024
7bda4b3
add handling of missing zyx cli flags for update-scale-metadata
aaronalvarezcz Jul 2, 2024
953b4b9
update order of params in update_scale_metadata to be passed as z, y, x
aaronalvarezcz Jul 2, 2024
4e158d6
Merge branch 'main' into update-scale-metadata-util
talonchandler Jul 9, 2024
ea4dd73
black
talonchandler Jul 9, 2024
fdfca08
isort
talonchandler Jul 9, 2024
a5ec62f
flake8
talonchandler Jul 9, 2024
826b250
Merge branch 'main' into update-scale-metadata-util
talonchandler Sep 17, 2024
e660042
update to `iohub.ngff.models`
talonchandler Sep 17, 2024
fcc408d
move parsing utilities to iohub
talonchandler Sep 17, 2024
c8816e5
move update_scale_metadata inside cli folder
talonchandler Sep 17, 2024
2642a51
typo
talonchandler Sep 17, 2024
e0ff8e2
update import for refactor
talonchandler Sep 17, 2024
7fac9f8
require -z, -y, -x flags
talonchandler Sep 17, 2024
de5c883
simplify interface and print statements
talonchandler Sep 17, 2024
9d6492e
clean up print statement
talonchandler Sep 17, 2024
387ac59
update the last three dimensions for OME compatibility
talonchandler Sep 17, 2024
461dc65
fix tests
talonchandler Sep 17, 2024
dcb00a1
fix test
talonchandler Sep 17, 2024
37add16
helper functions for axis names
talonchandler Sep 18, 2024
6b4461d
set_scale API
talonchandler Sep 18, 2024
353ab65
consolidate and clean CLI
talonchandler Sep 18, 2024
a900763
test get_axis_index
talonchandler Sep 18, 2024
b98381f
test_set_scale
talonchandler Sep 18, 2024
74bdb7b
case insensitive axis name
talonchandler Sep 18, 2024
6b857a9
tests don't overwrite data
talonchandler Sep 18, 2024
9e6d676
save old metadata in a namespace
talonchandler Sep 19, 2024
9df8007
test multiple inputs to cli
talonchandler Sep 19, 2024
e858dc6
handle empty current_transforms
talonchandler Sep 19, 2024
75d2525
improved empty handling
talonchandler Sep 19, 2024
b46c5f3
unit test CLI plate expansion into positions
talonchandler Sep 25, 2024
d657c88
cleanup test
talonchandler Sep 25, 2024
0e3ac36
test OptionEatAll
talonchandler Sep 25, 2024
e1a04cc
stronger plate-expansion test
talonchandler Sep 25, 2024
f678f44
fix bug when scale transform does not exist
ieivanov Sep 26, 2024
a551257
create "iohub" dict if it doesn't exist, and update it
talonchandler Sep 26, 2024
b49980e
test old_* metadata
talonchandler Sep 26, 2024
bb419b2
rename old_x to prior_x_scale
ieivanov Sep 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions iohub/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from iohub._version import __version__
from iohub.convert import TIFFConverter
from iohub.reader import print_info
from iohub.update_scale_metadata import update_scale_metadata as _update_scale_metadata
from mantis.cli.parsing import input_position_dirpaths

VERSION = __version__

Expand Down Expand Up @@ -117,3 +119,32 @@ def convert(
chunks=chunks,
)
converter.run(check_image=check_image)


@cli.command()
@click.help_option("-h", "--help")
@input_position_dirpaths()
@click.option(
"--x-scale",
"-x",
required=False,
type=float,
help="New x scale",
)
@click.option(
"--y-scale",
"-y",
required=False,
type=float,
help="New y scale",
)
@click.option(
"--z-scale",
"-z",
required=False,
type=float,
help="New z scale",
)
def update_scale_metadata(input_position_dirpaths, z_scale, y_scale, x_scale):
"""Update scale metadata in OME-Zarr datasets"""
talonchandler marked this conversation as resolved.
Show resolved Hide resolved
_update_scale_metadata(input_position_dirpaths, z_scale=z_scale, y_scale=y_scale, x_scale=x_scale)
44 changes: 44 additions & 0 deletions iohub/update_scale_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from typing import List

from iohub import open_ome_zarr
from iohub.ngff_meta import TransformationMeta


def update_scale_metadata(
input_position_dirpaths: List[str],
z_scale: float = None,
y_scale: float = None,
x_scale: float = None,
):
with open_ome_zarr(input_position_dirpaths[0]) as input_dataset:
print(
f"The first dataset in the list you provided has (z, y, x) scale {input_dataset.scale[2:]}"
)

print(
"Please enter the new z, y, and x scales that you would like to apply to all of the positions in the list."
)
print(
"The old scale will be saved in a metadata field named 'old_scale', and the new scale will adhere to the NGFF spec."
)
new_scale = [z_scale, y_scale, x_scale]
for i, character in enumerate("zyx"):
if new_scale[i] is None:
new_scale[i] = (float(input(f"Enter a new {character} scale: ")))

for input_position_dirpath in input_position_dirpaths:
with open_ome_zarr(input_position_dirpath, layout="fov", mode="a") as input_dataset:
input_dataset.zattrs['old_scale'] = input_dataset.scale[2:]
transform = [
TransformationMeta(
type="scale",
scale=(
1,
1,
)
+ tuple(new_scale),
)
]
input_dataset.set_transform("0", transform=transform)

print(f"The dataset now has (z, y, x) scale {tuple(new_scale)}.")