Skip to content

Commit

Permalink
Merge pull request #339 from ericpre/python3.13
Browse files Browse the repository at this point in the history
Python 3.13
  • Loading branch information
CSSFrancis authored Dec 12, 2024
2 parents 46952b3 + 160807e commit 623328f
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 90 deletions.
60 changes: 42 additions & 18 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,48 @@ jobs:
# test oldest supported version of main dependencies on python 3.8
- os: ubuntu
os_version: latest
PYTHON_VERSION: '3.8'
PYTHON_VERSION: '3.9'
# 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 tifffile==2022.7.28 dask[array]==2021.5.1 distributed==2021.5.1 numba==0.52 imageio==2.16 pillow==8.3.2 scikit-image==0.18.0 python-box==6.0.0
# align matplotlib dependency with hyperspy
DEPENDENCIES: matplotlib==3.6 numpy==1.20.0 tifffile==2022.7.28 dask[array]==2021.5.1 distributed==2021.5.1 numba==0.53 imageio==2.16 pillow==8.3.2 scikit-image==0.18.0 python-box==6.0.0
LABEL: '-oldest'
# test minimum requirement
- os: ubuntu
os_version: latest
PYTHON_VERSION: '3.9'
PYTHON_VERSION: '3.10'
LABEL: '-minimum'
- os: ubuntu
os_version: latest
PYTHON_VERSION: '3.12'
LABEL: '-minimum-without-hyperspy'
LABEL: '-hyperspy-dev'
- os: ubuntu
os_version: latest
PYTHON_VERSION: '3.11'
LABEL: '-hyperspy-dev'
PYTHON_VERSION: '3.10'
LABEL: '-without-hyperspy'
- os: ubuntu
os_version: latest
PYTHON_VERSION: '3.9'
LABEL: '-without-hyperspy'
- os: ubuntu
os_version: latest
PYTHON_VERSION: '3.8'
PYTHON_VERSION: '3.12'
- os: ubuntu
os_version: latest
PYTHON_VERSION: '3.11'
PYTHON_VERSION: '3.13'
# can remove minimum dependencies when numba supports 3.13
LABEL: '-minimum'
- os: macos
os_version: latest
PYTHON_VERSION: '3.13'
# can remove minimum dependencies when numba supports 3.13
LABEL: '-minimum'
- os: windows
os_version: latest
PYTHON_VERSION: '3.13'
# can remove minimum dependencies when numba supports 3.13
LABEL: '-minimum'
- os: macos
os_version: '13'
PYTHON_VERSION: '3.11'
PYTHON_VERSION: '3.12'

steps:
- uses: actions/checkout@v4
Expand All @@ -79,6 +90,7 @@ jobs:
name: Install Python
with:
python-version: ${{ matrix.PYTHON_VERSION }}
cache: 'pip'

- name: Get the number of CPUs
id: cpus
Expand All @@ -91,7 +103,7 @@ jobs:
with open(output_file, "a", encoding="utf-8") as output_stream:
output_stream.write(f"count={num_cpus}\n")
shell: python

- name: Set Environment Variable
shell: bash
# Set PIP_SELECTOR environment variable according to matrix.LABEL
Expand All @@ -108,8 +120,14 @@ jobs:
python --version
pip --version
- name: Install traits dev for python 3.13
if: ${{ matrix.PYTHON_VERSION == '3.13' }}
run: |
# traits release with python 3.13 pending
pip install git+https://github.com/enthought/traits.git
- name: Install hyperspy and exspy
if: ${{ ! contains(matrix.LABEL, 'without-hyperspy') }}
if: ${{ ! contains(matrix.LABEL, 'without-hyperspy') && matrix.PYTHON_VERSION != '3.13'}}
run: |
pip install hyperspy exspy
Expand All @@ -119,14 +137,20 @@ jobs:
pip install git+https://github.com/hyperspy/hyperspy.git
pip install git+https://github.com/hyperspy/exspy.git
- name: Install pint and python-mrcz dev
- name: Install hyperspy (python 3.13) and exspy (dev)
if: ${{ matrix.PYTHON_VERSION == '3.13' }}
run: |
# speed up installing scikit-image using pre-release with python 3.13 wheels
pip install scikit-image --pre
pip install git+https://github.com/ericpre/hyperspy.git@python313
pip install git+https://github.com/hyperspy/exspy.git
- name: Install python-mrcz dev
# for numpy 2.0 support for python >= 3.9
# https://github.com/em-MRCZ/python-mrcz/pull/15
# https://github.com/hgrecco/pint/issues/1974
if: ${{ ! contains(matrix.LABEL, 'oldest') && matrix.PYTHON_VERSION != '3.8' }}
if: ${{ ! contains(matrix.LABEL, 'oldest') && ! contains(matrix.LABEL, 'minimum') }}
run: |
pip install git+https://github.com/ericpre/[email protected]_and_deprecation_fixes
pip install git+https://github.com/hgrecco/pint
- name: Install
shell: bash
Expand All @@ -147,7 +171,7 @@ jobs:
- name: Install numpy 2.0
if: ${{ ! contains(matrix.LABEL, 'oldest') && matrix.PYTHON_VERSION != '3.8' }}
run: |
pip install numpy==2
pip install numpy>=2
- name: Pip list
run: |
Expand Down
24 changes: 12 additions & 12 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ resources:

strategy:
matrix:
Linux_Python312:
vmImage: 'ubuntu-latest'
PYTHON_VERSION: '3.12'
MINIFORGE_PATH: $(Agent.BuildDirectory)/miniforge3
Linux_Python310:
vmImage: 'ubuntu-latest'
PYTHON_VERSION: '3.10'
Expand All @@ -31,25 +35,21 @@ strategy:
vmImage: 'ubuntu-latest'
PYTHON_VERSION: '3.9'
MINIFORGE_PATH: $(Agent.BuildDirectory)/miniforge3
Linux_Python38:
vmImage: 'ubuntu-latest'
PYTHON_VERSION: '3.8'
MINIFORGE_PATH: $(Agent.BuildDirectory)/miniforge3
MacOS_Python38:
MacOS_Python39:
vmImage: 'macOS-latest'
PYTHON_VERSION: '3.8'
PYTHON_VERSION: '3.9'
MINIFORGE_PATH: $(Agent.BuildDirectory)/miniforge3
MacOS_Python310:
MacOS_Python312:
vmImage: 'macOS-latest'
PYTHON_VERSION: '3.10'
PYTHON_VERSION: '3.12'
MINIFORGE_PATH: $(Agent.BuildDirectory)/miniforge3
Windows_Python38:
Windows_Python39:
vmImage: 'windows-latest'
PYTHON_VERSION: '3.8'
PYTHON_VERSION: '3.9'
MINIFORGE_PATH: $(Agent.BuildDirectory)\miniforge3
Windows_Python310:
Windows_Python312:
vmImage: 'windows-latest'
PYTHON_VERSION: '3.10'
PYTHON_VERSION: '3.12'
MINIFORGE_PATH: $(Agent.BuildDirectory)\miniforge3

pool:
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ build-backend = "setuptools.build_meta"
[project]
name = "rosettasciio"
description = "Reading and writing scientific file formats"
requires-python = ">=3.8"
requires-python = ">=3.9"
readme = "README.md"
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Physics",
"Topic :: Software Development :: Libraries",
Expand Down Expand Up @@ -94,8 +94,8 @@ eds-stream = ["sparse"]
hdf5 = ["h5py>=2.3"]
image = ["imageio>=2.16"]
mrcz = ["blosc>=1.5", "mrcz>=0.3.6"]
scalebar_export = ["matplotlib-scalebar", "matplotlib>=3.5"]
speed = ["numba>=0.52"]
scalebar_export = ["matplotlib-scalebar", "matplotlib>=3.6"]
speed = ["numba>=0.53"]
tiff = ["tifffile>=2022.7.28", "imagecodecs"]
usid = ["pyUSID>=0.0.11"]
zspy = ["zarr", "msgpack"]
Expand Down
4 changes: 2 additions & 2 deletions rsciio/bruker/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,9 @@ def __init__(self, spectrum):
self.detector_metadata["DetLayers"][i.tag] = dict(i.attrib)

# map stuff from esma xml branch:
if esma_header:
if esma_header is not None:
self.esma_metadata = x2d.dictionarize(esma_header)
if xrf_header:
if xrf_header is not None:
xrf_header_dict = x2d.dictionarize(xrf_header)
self.esma_metadata = {
"PrimaryEnergy": xrf_header_dict["Voltage"],
Expand Down
4 changes: 3 additions & 1 deletion rsciio/digitalsurf/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,9 @@ def _split_signal_dict(self):
self._split_surfaceserie()
elif (n_nav, n_sig) == (2, 0):
warnings.warn(
f"Signal dimension {n_sig} and navigation dimension {n_nav} exported as surface type. Consider transposing signal object before exporting if this is intentional."
f"Signal dimension {n_sig} and navigation dimension {n_nav} exported "
"as surface type. Consider transposing signal object before exporting "
"if this is intentional."
)
if self._is_binary():
self._split_binary_img()
Expand Down
4 changes: 2 additions & 2 deletions rsciio/edax/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def get_ipr_dtype_list(endianess="<", version=333):
dtype_list = [
("version", end + "u2"),
("imageType", end + "u2"),
("label", end + "a8"),
("label", end + "S8"),
("sMin", end + "u2"),
("sMax", end + "u2"),
("color", end + "u2"),
Expand All @@ -618,7 +618,7 @@ def get_ipr_dtype_list(endianess="<", version=333):
("mppX", end + "f4"),
("mppY", end + "f4"),
("nTextLines", end + "u2"),
("charText", end + "4a32"),
("charText", end + "4S32"),
("reserved3", end + "4f4"),
("nOverlayElements", end + "u2"),
("overlayColors", end + "16u2"),
Expand Down
30 changes: 16 additions & 14 deletions rsciio/emd/_emd_ncem.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,10 @@ def _read_dataset(dataset):
if h5py.check_string_dtype(dataset.dtype) and hasattr(dataset, "asstr"):
# h5py 3.0 and newer
# https://docs.h5py.org/en/3.0.0/strings.html
dataset = dataset.asstr()[:]
return dataset, chunks
data = dataset.asstr()[:]
else:
data = dataset[:]
return data, chunks

def _read_emd_version(self, group):
"""Return the group version if the group is an EMD group, otherwise
Expand All @@ -225,38 +227,38 @@ def _read_data_from_groups(
axes = []
transpose_required = True if dataset_name != "datacube" else False

array_list = [self.file.get(f"{key}/{dataset_name}") for key in group_path]
dataset_list = [self.file.get(f"{key}/{dataset_name}") for key in group_path]

if None in array_list:
if None in dataset_list:
raise IOError("Dataset can't be found.")

if len(array_list) > 1:
if len(dataset_list) > 1:
# Squeeze the data only when
if self.lazy:
data_list = [da.from_array(*self._read_dataset(d)) for d in array_list]
data_list = [
da.from_array(*self._read_dataset(d)) for d in dataset_list
]
if transpose_required:
data_list = [da.transpose(d) for d in data_list]
data = da.stack(data_list)
data = da.squeeze(data)
else:
data_list = [
np.asanyarray(self._read_dataset(d)[0]) for d in array_list
]
data_list = [self._read_dataset(d)[0] for d in dataset_list]
if transpose_required:
data_list = [np.transpose(d) for d in data_list]
data = np.stack(data_list).squeeze()
else:
d = array_list[0]
d = dataset_list[0]
if self.lazy:
data = da.from_array(*self._read_dataset(d))
else:
data = np.asanyarray(self._read_dataset(d)[0])
data = self._read_dataset(d)[0]
if transpose_required:
data = data.transpose()

shape = data.shape

if len(array_list) > 1:
if len(dataset_list) > 1:
offset, scale, units = 0, 1, None
if self._is_prismatic_file and "depth" in stack_key:
simu_om = original_metadata.get("simulation_parameters", {})
Expand All @@ -274,7 +276,7 @@ def _read_data_from_groups(
simu_om.get("tile", 0)[2] * simu_om.get("cellDimension", 0)[0]
)
if not math.isclose(
total_thickness, len(array_list) * scale, rel_tol=1e-4
total_thickness, len(dataset_list) * scale, rel_tol=1e-4
):
_logger.warning(
"Depth axis is non-uniform and its offset "
Expand All @@ -289,7 +291,7 @@ def _read_data_from_groups(
"name": stack_key if stack_key is not None else None,
"offset": offset,
"scale": scale,
"size": len(array_list),
"size": len(dataset_list),
"units": units,
"navigate": True,
}
Expand Down
7 changes: 4 additions & 3 deletions rsciio/tests/generate_dm_testing_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ def generate_4D_files(f, data_types, dmversion):


if __name__ == "__main__":
with open("generate_dm3_test_files.s", "w") as f1, open(
"generate_dm4_test_files.s", "w"
) as f2:
with (
open("generate_dm3_test_files.s", "w") as f1,
open("generate_dm4_test_files.s", "w") as f2,
):
for f in (f1, f2):
f.write("image im\n")
f.write("string filename, path\n")
Expand Down
Loading

0 comments on commit 623328f

Please sign in to comment.