Skip to content

Commit

Permalink
Merge pull request #262 from ericpre/tifffile_fixes
Browse files Browse the repository at this point in the history
Fix `tifffile` deprecations
  • Loading branch information
ericpre authored May 27, 2024
2 parents a7327e4 + 244cca7 commit be858cf
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
PYTHON_VERSION: '3.8'
# Set pillow and scikit-image version to be compatible with imageio and scipy
# matplotlib needs 3.5 to support markers in hyperspy 2.0 (requires `collection.set_offset_transform`)
DEPENDENCIES: matplotlib==3.5 numpy==1.20.0 imagecodecs==2020.1.31 tifffile==2020.2.16 dask[array]==2021.3.1 numba==0.52 imageio==2.16 pillow==8.3.2 scikit-image==0.18.0
DEPENDENCIES: matplotlib==3.5 numpy==1.20.0 tifffile==2022.7.28 dask[array]==2021.3.1 numba==0.52 imageio==2.16 pillow==8.3.2 scikit-image==0.18.0
LABEL: '-oldest'
# test minimum requirement
- os: ubuntu
Expand Down
10 changes: 7 additions & 3 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,20 @@ pool:

steps:
- checkout: self
fetchDepth: 0 # Fetch all commits for setuptools_scm
fetchTags: true # tags necessary for setuptools_scm
fetchDepth: '0' # Fetch all commits for setuptools_scm
fetchTags: 'true' # tags necessary for setuptools_scm
- bash: |
git remote add upstream https://github.com/hyperspy/rosettasciio.git
git fetch upstream --tags
condition: ne(variables['Build.Repository.Name'], 'hyperspy/rosettasciio')
displayName: Fetch tags from hyperspy/rosettasciio
- template: azure_pipelines/clone_ci-scripts_repo.yml@templates
- template: azure_pipelines/install_mambaforge.yml@templates
- template: azure_pipelines/activate_conda.yml@templates
- template: azure_pipelines/setup_anaconda_packages.yml@templates

- bash: |
source activate $ENV_NAME
pip install "hyperspy>=2.0rc0"
pip install --no-deps -e .
conda list
displayName: Install package
Expand Down
9 changes: 3 additions & 6 deletions conda_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ name: test_env
channels:
- conda-forge
dependencies:
- dask-core >=2.11
- h5py
- imageio
- numba >=0.52
- numpy
- pint
- dask-core >=2021.3.1
- numpy >=1.20.0
- pint >=0.8
- python-box >=6.0,<7.0
- python-dateutil
- pyyaml
Expand Down
10 changes: 8 additions & 2 deletions conda_environment_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ channels:
- conda-forge
dependencies:
- cython
- filelock
- h5py >=2.3
- imageio >=2.16
- numba >=0.52
- pooch
- pytest
- pytest-xdist
- pytest-rerunfailures
- hyperspy-base
- hyperspy-base >=2.0
- setuptools-scm
- filelock
- sparse
- tifffile>=2022.7.28
- zarr
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ image = ["imageio>=2.16"]
mrcz = ["blosc>=1.5", "mrcz>=0.3.6"]
scalebar_export = ["matplotlib-scalebar", "matplotlib>=3.5"]
speed = ["numba>=0.52"]
tiff = ["tifffile>=2020.2.16", "imagecodecs>=2020.1.31"]
tiff = ["tifffile>=2022.7.28", "imagecodecs"]
# Add sidpy dependency and pinning as workaround to fix pyUSID import
# Remove sidpy dependency once https://github.com/pycroscopy/pyUSID/issues/85 is fixed.
usid = ["pyUSID", "sidpy<=0.12.0"]
Expand Down
13 changes: 7 additions & 6 deletions rsciio/tiff/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
from datetime import datetime, timedelta

import numpy as np
import tifffile
from dateutil import parser
from tifffile import TIFF, TiffFile, TiffPage, imwrite
from tifffile import TiffFile, TiffPage, imwrite

from rsciio._docstrings import (
FILENAME_DOC,
Expand Down Expand Up @@ -284,7 +285,7 @@ def _read_tiff(
shape = handle.shape
dtype = handle.dtype

is_rgb = page.photometric == TIFF.PHOTOMETRIC.RGB and RGB_as_structured_array
is_rgb = page.photometric == tifffile.PHOTOMETRIC.RGB and RGB_as_structured_array
_logger.debug("Is RGB: %s" % is_rgb)
if is_rgb:
axes = axes[:-1]
Expand Down Expand Up @@ -420,15 +421,15 @@ def _is_force_readable(op, force_read_resolution) -> bool:
def _axes_force_read(op, shape, names):
scales, offsets, units = _axes_defaults()
res_unit_tag = op["ResolutionUnit"]
if res_unit_tag != TIFF.RESUNIT.NONE:
if res_unit_tag != tifffile.RESUNIT.NONE:
_logger.debug("Resolution unit: %s" % res_unit_tag)
scales["x"], scales["y"] = _get_scales_from_x_y_resolution(op)
# conversion to µm:
if res_unit_tag == TIFF.RESUNIT.INCH:
if res_unit_tag == tifffile.RESUNIT.INCH:
for key in ["x", "y"]:
units[key] = "µm"
scales[key] = scales[key] * 25400
elif res_unit_tag == TIFF.RESUNIT.CENTIMETER:
elif res_unit_tag == tifffile.RESUNIT.CENTIMETER:
for key in ["x", "y"]:
units[key] = "µm"
scales[key] = scales[key] * 10000
Expand Down Expand Up @@ -601,7 +602,7 @@ def _axes_jeol_sightx(tiff, op, shape, names):
op["SightX_Notes"] = ", ".join(mode_strs)

res_unit_tag = op["ResolutionUnit"]
if res_unit_tag == TIFF.RESUNIT.INCH:
if res_unit_tag == tifffile.RESUNIT.INCH:
scale = 0.0254 # inch/m
else:
scale = 0.01 # tiff scaling, cm/m
Expand Down
1 change: 1 addition & 0 deletions upcoming_changes/262.maintenance.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``tifffile`` deprecation.

0 comments on commit be858cf

Please sign in to comment.