-
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.
enh: support .ome.tif files (no stacks supported yet)
- Loading branch information
1 parent
20e12a8
commit 2922b56
Showing
6 changed files
with
85 additions
and
9 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
0.4.7 | ||
- enh: support .ome.tif files (no stacks supported yet) | ||
0.4.6 | ||
- maintenance release | ||
0.4.5 | ||
|
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,46 @@ | ||
from collections import OrderedDict | ||
from xml.dom.minidom import parseString | ||
|
||
import numpy as np | ||
import tifffile | ||
|
||
|
||
def load_ometif(path): | ||
"""Load .ome.tif files | ||
Please see :func:`impose.formats.load` for more information. | ||
""" | ||
with tifffile.TiffFile(path) as tif: | ||
if not tif.is_ome: | ||
raise NotImplementedError( | ||
f"Could not load ome_metadata from file {path}. Please ask " | ||
f"for implementing support for your file format.") | ||
ome_meta = parseString(tif.ome_metadata) | ||
data = tif.asarray() | ||
|
||
channels = OrderedDict() | ||
name = ome_meta.getElementsByTagName("Image")[0].attributes["Name"].value | ||
channels[name] = data | ||
|
||
# Initial Metadata | ||
px = ome_meta.getElementsByTagName("Pixels")[0] | ||
xs = float(px.attributes["PhysicalSizeX"].value) | ||
ys = float(px.attributes["PhysicalSizeY"].value) | ||
|
||
# sanity checks | ||
assert px.attributes["PhysicalSizeXUnit"].value == "µm" | ||
assert px.attributes["PhysicalSizeYUnit"].value == "µm" | ||
|
||
# Channel names | ||
data_uuid = ome_meta.getElementsByTagName( | ||
"UUID")[0].childNodes[0].data.split(":")[-1] | ||
|
||
meta = { | ||
"pixel size x": xs, | ||
"pixel size y": ys, | ||
"pixel size z": np.nan, | ||
"shape": data.shape, | ||
"signature": data_uuid, | ||
} | ||
|
||
return channels, meta |
Binary file not shown.
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,34 @@ | ||
import pathlib | ||
import tempfile | ||
import zipfile | ||
|
||
import numpy as np | ||
|
||
from impose import formats | ||
|
||
|
||
data_path = pathlib.Path(__file__).parent / "data" | ||
|
||
|
||
def get_ometif(): | ||
td = pathlib.Path(tempfile.mkdtemp(prefix="impose_ometif_")) | ||
with zipfile.ZipFile(data_path / "fmt_fl_ometif.zip") as arc: | ||
arc.extractall(path=td) | ||
return list(td.glob("*.ome.tif"))[0] | ||
|
||
|
||
def test_load_ometif(): | ||
path = get_ometif() | ||
data, meta = formats.load(path) | ||
|
||
# check metadata | ||
assert np.allclose(meta["pixel size x"], 0.2136) | ||
assert np.allclose(meta["pixel size y"], 0.2136) | ||
assert np.isnan(meta["pixel size z"]) | ||
assert meta["shape"] == (512, 512) | ||
assert meta["signature"] == "a704111f-8e8d-40b0-9f55-4d649ef49167" | ||
chan = "Brillouin-2_MMStack_Default" | ||
assert data[chan].shape == (512, 512) | ||
assert data[chan][10, 10] == 246 | ||
assert data[chan][205, 227] == 217 | ||
assert data[chan][113, 206] == 280 |