Skip to content

Commit

Permalink
Added npy format support to diffread
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentRDC committed Jan 16, 2021
1 parent 7004fb9 commit 3e0ce33
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Release 2.1.2
-------------

* Improved :func:`autocenter` for diffraction patterns with large Ewald sphere walkoff.
* :func:`diffread` now supports NumPy's ``*.npy`` format.
* Speedup of all routines that use the Fast Fourier transform (:func:`autocenter`, :func:`align`, :func:`ialign`, :func:`itrack_peak`, and :func:`kinematicsim`) by 50%.

Release 2.1.1
Expand Down
6 changes: 6 additions & 0 deletions skued/io/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from pathlib import Path

import numpy as np

from .dm import dmread
from .merlin import mibread

Expand All @@ -18,6 +20,8 @@ def diffread(fname):
* TIFF (`*.tif`, `*.tiff`)
* NumPy (`*.npy`)
* All file formats supported by Scikit-image
Parameters
Expand All @@ -42,6 +46,8 @@ def diffread(fname):
return mibread(fname)
elif fname.suffix in {".dm3", ".dm4"}:
return dmread(fname)
elif fname.suffix == ".npy":
return np.load(fname, fix_imports=False)

# Worst-case scenario, we need skimage.io
# since this is a slow import, we import it here
Expand Down
10 changes: 10 additions & 0 deletions skued/io/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import numpy as np
from skimage.io import imsave
import tempfile

from skued import diffread, dmread, imibread, mibheader, mibread
from skued.utils import suppress_warnings
Expand Down Expand Up @@ -54,6 +55,15 @@ def test_diffread_on_tiff():
os.remove(path)


def test_diffread_on_npy():
""" Test diffread() on *.npy files """
arr = np.random.random(size=(128, 128))
with tempfile.TemporaryDirectory() as tmpdir:
np.save(Path(tmpdir) / "skued_test.npy", arr)
arr2 = diffread(Path(tmpdir) / "skued_test.npy")
assert np.allclose(arr, arr2)


def test_diffread_on_skimage_png():
""" Test the last resort of using skimage.io for pngs """
from_skimage = diffread(TEST_PNG)
Expand Down

0 comments on commit 3e0ce33

Please sign in to comment.