-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add TIFF Metadata for Offsets #19
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
264d535
First pass with ometiff metadata addition
ilan-gold 59a9392
Clean up with comments
ilan-gold 63c8582
Pin version back
ilan-gold 033c35d
Update tests
ilan-gold 0b1ec48
Update .travis.yml
ilan-gold e655d4f
Add python to travis
ilan-gold 38042b6
Update test.sh
ilan-gold 5e25222
Update testing
ilan-gold a1a96dd
Update sed
ilan-gold a9d5c62
Update Dockerfile
ilan-gold 820595d
Address comments
ilan-gold 3883361
Merge branch 'ilan-gold/tiff_metadata' of https://github.com/hubmapco…
ilan-gold b77e406
Apply suggestions from code review
ilan-gold cf260a7
Update test.sh
ilan-gold 784350a
Update output for regex
ilan-gold 043d1c0
Update ordering of operations.
ilan-gold File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,5 +1,7 @@ | ||
**/test-output-actual | ||
|
||
settings.json | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# ome-tiff-offsets | ||
|
||
This docker container adds a structured annotation to the OMEXML | ||
which contains the `IFD_Offsets` in bytes |
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 @@ | ||
0.0.1 |
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,65 @@ | ||
import argparse | ||
from glob import glob | ||
from pathlib import Path | ||
from os import makedirs | ||
|
||
from aicsimageio import AICSImage | ||
from aicsimageio.writers import ome_tiff_writer | ||
from tifffile import TiffFile | ||
import xml.dom.minidom | ||
|
||
def get_offsets(tiff_filepath): | ||
with TiffFile(tiff_filepath) as tif: | ||
offsets = [page.offset for page in tif.pages] | ||
return offsets | ||
|
||
|
||
|
||
def main(input_dir, output_dir): | ||
makedirs(output_dir, exist_ok=True) | ||
for input in glob(input_dir + '/*.ome.tif*') + glob(input_dir + '/*.ome.tiff'): | ||
# Get image metadata and image data. | ||
with AICSImage(input) as input_image: | ||
image_data_from_input = input_image.get_image_data()[0] | ||
omexml = input_image.metadata | ||
# Create the output path for the compressed ome tiff. | ||
input_path = Path(input) | ||
compressed_dir = Path('/compressed/') | ||
compressed_ome_tiff = compressed_dir / input_path.name | ||
makedirs(compressed_dir) | ||
with ome_tiff_writer.OmeTiffWriter(compressed_ome_tiff) as ome_writer: | ||
ome_writer.save( | ||
image_data_from_input, | ||
ome_xml = omexml | ||
) | ||
# Read in the newly compressed file. | ||
with AICSImage(compressed_ome_tiff) as compressed_image: | ||
image_data_from_compressed = compressed_image.get_image_data()[0] | ||
omexml_compressed = compressed_image.metadata | ||
# Get the offsets of said compressed file and add them to the omexml as structured annotations. | ||
offsets = get_offsets(compressed_ome_tiff) | ||
structured_annotations = omexml_compressed.structured_annotations | ||
structured_annotations.add_original_metadata(key='IFD_Offsets', value=str(offsets)) | ||
# Write the file out to the bound output directory. | ||
with open(Path(output_dir) / 'ome.xml', 'w') as xml_write: | ||
xml_write.write(xml.dom.minidom.parseString(str(omexml_compressed)).toprettyxml()) | ||
new_ome_tiff_path = Path(output_dir) / input_path.name | ||
with ome_tiff_writer.OmeTiffWriter(new_ome_tiff_path, overwrite_file=True) as ome_writer: | ||
ome_writer.save( | ||
image_data_from_compressed, | ||
ome_xml = omexml_compressed | ||
) | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser( | ||
description='Add offsets to the OMEXML Metadata') | ||
parser.add_argument( | ||
'--input_dir', required=True, | ||
help='Directory containing ome-tiff files to read') | ||
parser.add_argument( | ||
'--output_dir', required=True, | ||
help='Directory where ome-tiff files should be written') | ||
args = parser.parse_args() | ||
main(args.input_dir, args.output_dir) |
48 changes: 48 additions & 0 deletions
48
containers/ome-tiff-offsets/context/requirements-freeze.txt
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,48 @@ | ||
aicsimageio==3.1.4 | ||
aicspylibczi==2.5.1 | ||
asn1crypto==1.0.1 | ||
certifi==2019.9.11 | ||
cffi==1.12.3 | ||
chardet==3.0.4 | ||
click==7.1.1 | ||
cloudpickle==1.3.0 | ||
conda==4.7.12 | ||
conda-package-handling==1.6.0 | ||
cryptography==2.7 | ||
cycler==0.10.0 | ||
dask==2.13.0 | ||
decorator==4.4.2 | ||
distributed==2.13.0 | ||
HeapDict==1.0.1 | ||
idna==2.8 | ||
imagecodecs==2020.2.18 | ||
imageio==2.8.0 | ||
kiwisolver==1.1.0 | ||
lxml==4.5.0 | ||
matplotlib==3.2.1 | ||
msgpack==1.0.0 | ||
networkx==2.4 | ||
numpy==1.18.2 | ||
Pillow==7.0.0 | ||
psutil==5.7.0 | ||
pycosat==0.6.3 | ||
pycparser==2.19 | ||
pyOpenSSL==19.0.0 | ||
pyparsing==2.4.6 | ||
PySocks==1.7.1 | ||
python-dateutil==2.8.1 | ||
PyWavelets==1.1.1 | ||
PyYAML==5.3.1 | ||
requests==2.22.0 | ||
ruamel-yaml==0.15.46 | ||
scikit-image==0.16.2 | ||
scipy==1.4.1 | ||
six==1.14.0 | ||
sortedcontainers==2.1.0 | ||
tblib==1.6.0 | ||
tifffile==2020.2.16 | ||
toolz==0.10.0 | ||
tornado==6.0.4 | ||
tqdm==4.36.1 | ||
urllib3==1.24.2 | ||
zict==2.0.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
aicsimageio==3.1.4 | ||
tifffile==2020.2.16 | ||
mccalluc marked this conversation as resolved.
Show resolved
Hide resolved
|
Binary file not shown.
Binary file added
BIN
+6.26 KB
containers/ome-tiff-offsets/test-output-expected/multi-channel.ome.tif
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" ?> | ||
<OME Creator="OME Bio-Formats 5.2.2" UUID="urn:uuid:bebd2be7-8253-4b90-be93-4df567ffe1be" xmlns="http://www.openmicroscopy.org/Schemas/OME/2016-06" xmlns:ns2="None" xmlns:ns3="openmicroscopy.org/OriginalMetadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openmicroscopy.org/Schemas/OME/2016-06 http://www.openmicroscopy.org/Schemas/OME/2016-06/ome.xsd"> | ||
<Image ID="Image:0" Name="multi-channel.ome.tif"> | ||
<Pixels BigEndian="true" DimensionOrder="XYZCT" ID="Pixels:0" SizeC="3" SizeT="1" SizeX="439" SizeY="167" SizeZ="1" Type="int8"> | ||
<Channel ID="Channel:0:0" SamplesPerPixel="1"> | ||
<LightPath/> | ||
</Channel> | ||
<Channel ID="Channel:0:1" SamplesPerPixel="1"> | ||
<LightPath/> | ||
</Channel> | ||
<Channel ID="Channel:0:2" SamplesPerPixel="1"> | ||
<LightPath/> | ||
</Channel> | ||
<TiffData FirstC="0" FirstT="0" FirstZ="0" IFD="0" PlaneCount="1"/> | ||
<TiffData FirstC="1" FirstT="0" FirstZ="0" IFD="1" PlaneCount="1"/> | ||
<TiffData FirstC="2" FirstT="0" FirstZ="0" IFD="2" PlaneCount="1"/> | ||
</Pixels> | ||
</Image> | ||
<ns2:StructuredAnnotations> | ||
<ns2:XMLAnnotation ID="PLACEHOLDER"> | ||
<ns2:Value> | ||
<ns3:OriginalMetadata> | ||
<ns3:Key>IFD_Offsets</ns3:Key> | ||
<ns3:Value>[8, 2712, 4394]</ns3:Value> | ||
</ns3:OriginalMetadata> | ||
</ns2:Value> | ||
</ns2:XMLAnnotation> | ||
</ns2:StructuredAnnotations> | ||
</OME> |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally, I was thinking we could use the same base image for everything... but if we end up with a lot of installs for just one pipeline or another, then might not be the right right.
No action for now, but something to keep in mind.