Skip to content

Commit

Permalink
bump versions and refactor for tifffile
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed May 28, 2020
1 parent e0e3701 commit f1d055b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.10.5
- setup: bump qpimage from 0.6.1 to 0.6.2
- setup: change dependency of scikit-image to tifffile 2020.5.25
- ref: make code work with latest version of tifffile
0.10.4
- setup: bump qpimage from 0.5.0 to 0.6.1
0.10.3
Expand Down
7 changes: 4 additions & 3 deletions qpformat/file_formats/single_tif_holo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import numpy as np
import qpimage
from skimage.external import tifffile
import tifffile

from .dataset import SingleData

Expand Down Expand Up @@ -59,9 +59,10 @@ def verify(path):
valid = False
try:
tf = SingleTifHolo._get_tif(path)
except (ValueError, IsADirectoryError):
except (ValueError, IsADirectoryError, KeyError,
tifffile.tifffile.TiffFileError):
pass
else:
if len(tf) == 1:
if len(tf.pages) == 1:
valid = True
return valid
34 changes: 20 additions & 14 deletions qpformat/file_formats/single_tif_phasics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@

import numpy as np
import qpimage
from skimage.external import tifffile
import tifffile

from .dataset import SingleData


# baseline clamp intensity normalization for phasics tif files
INTENSITY_BASELINE_CLAMP = 150

# https://www.loc.gov/preservation/digital/formats/content/tiff_tags.shtml
TIFF_TAGS = {
"MaxSampleValue": 281,
}


class LoadTifPhasicsError(BaseException):
pass
Expand Down Expand Up @@ -52,7 +57,7 @@ def __init__(self, path, meta_data={}, *args, **kwargs):
@staticmethod
def _get_meta_data(path, section, name):
with SingleTifPhasics._get_tif(path) as tf:
meta = tf.pages[0].tags["61238"].as_str()
meta = tf.pages[0].tags[61238].value

meta = meta.strip("'b")
meta = meta.replace("\\n", "\n")
Expand Down Expand Up @@ -123,7 +128,7 @@ def get_qpimage_raw(self, idx=0):
inttags = tf.pages[0].tags
imin = inttags["61243"].value
imax = inttags["61242"].value
isamp = inttags["max_sample_value"].value
isamp = inttags[TIFF_TAGS["MaxSampleValue"]].value
blc = INTENSITY_BASELINE_CLAMP
inten = tf.pages[0].asarray() * (imax - imin) / isamp + imin - blc
inten[inten < 0] = 0
Expand Down Expand Up @@ -153,7 +158,7 @@ def get_qpimage_raw(self, idx=0):
phatags = tf.pages[phaid].tags
pmin = phatags["61243"].value
pmax = phatags["61242"].value
psamp = phatags["max_sample_value"].value
psamp = phatags[TIFF_TAGS["MaxSampleValue"]].value
if psamp == 0 or pmin == pmax:
# no phase data
pha = np.zeros_like(inten)
Expand Down Expand Up @@ -183,17 +188,18 @@ def verify(path):
valid = False
try:
tf = SingleTifPhasics._get_tif(path)
except (ValueError, IsADirectoryError):
except (ValueError, IsADirectoryError, KeyError,
tifffile.tifffile.TiffFileError):
pass
else:
if (len(tf) == 3 and
"61243" in tf.pages[0].tags and
"61242" in tf.pages[0].tags and
"61238" in tf.pages[0].tags and
"61243" in tf.pages[1].tags and
"61242" in tf.pages[1].tags and
"max_sample_value" in tf.pages[0].tags and
(tf.pages[0].tags["61242"].value !=
tf.pages[1].tags["61242"].value)):
if (len(tf.pages) == 3 and
61243 in tf.pages[0].tags and
61242 in tf.pages[0].tags and
61238 in tf.pages[0].tags and
61243 in tf.pages[1].tags and
61242 in tf.pages[1].tags and
TIFF_TAGS["MaxSampleValue"] in tf.pages[0].tags and
(tf.pages[0].tags[61242].value !=
tf.pages[1].tags[61242].value)):
valid = True
return valid
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
install_requires=["h5py>=2.7.0",
"nrefocus>=0.1.5",
"numpy>=1.12.0",
"qpimage>=0.6.1",
"scikit-image>=0.11.0",
"qpimage>=0.6.2",
"tifffile>=2020.5.25",
"scipy>=0.18.0",
],
setup_requires=['pytest-runner'],
Expand Down
2 changes: 1 addition & 1 deletion tests/test_series_hdf5_hyperspy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import warnings

import h5py
from skimage.external import tifffile
import tifffile

import qpformat
from qpformat.file_formats import WrongFileFormatError
Expand Down

0 comments on commit f1d055b

Please sign in to comment.