Skip to content

Commit

Permalink
Merge pull request #556 from kif/555_numpy2
Browse files Browse the repository at this point in the history
Support for Numpy2
  • Loading branch information
kif authored Mar 15, 2024
2 parents c1eff28 + 5108dc4 commit d08b8ea
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.mathjax',
'sphinxcontrib.programoutput',
"nbsphinx"
'nbsphinx'
]

# Set the theme to sphinx_rtd_theme when *not* building on Read The Docs.
Expand Down
10 changes: 9 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ project('FabIO',
'c', 'cython',
license: 'MIT',
meson_version: '>= 0.60',
version: run_command('src/fabio/_version.py',
version: run_command(['version.py', '--wheel'],
check:true).stdout().strip(),
)

Expand All @@ -13,6 +13,7 @@ if meson.backend() != 'ninja'
endif

cc = meson.get_compiler('c')
cy = meson.get_compiler('cython')
m_dep = cc.find_library('m', required : false)
if m_dep.found()
add_project_link_arguments('-lm', language : 'c')
Expand All @@ -23,4 +24,11 @@ py_mod = import('python')
py = py_mod.find_installation()
py_dep = py.dependency()

py.install_sources([
'version.py',
],
pure: false, # Will be installed next to binaries
subdir: 'fabio' # Folder relative to site-packages to install to
)

subdir('src/fabio')
6 changes: 3 additions & 3 deletions package/debian12/control
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Priority: extra
Build-Depends: cython3,
debhelper,
dh-python,
devscripts,
python3-tomli,
python3-mesonpy,
python3-all-dev,
python3-pil,
python3-lxml,
Expand All @@ -18,10 +21,7 @@ Build-Depends: cython3,
python3-sphinxcontrib.programoutput,
python3-sphinx-rtd-theme,
python3-h5py,
python3-tomli,
python3-mesonpy,
help2man,
devscripts,
python3-pyqt5,
python3-matplotlib,
bitshuffle,
Expand Down
5 changes: 2 additions & 3 deletions src/fabio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
__contact__ = "Jerome.Kieffer@ESRF.eu"
__license__ = "GPLv3+"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "21/06/2023"
__date__ = "15/03/2024"
__status__ = "stable"

import sys
Expand All @@ -39,8 +39,7 @@
logging.basicConfig()

import os
from ._version import __date__ as date # noqa
from ._version import version, version_info, hexversion, strictversion # noqa
from .version import __date__ as date, version, version_info, hexversion, strictversion # noqa
from . import fabioformats as _fabioformats

# provide a global fabio API
Expand Down
4 changes: 2 additions & 2 deletions src/fabio/app/eiger2crysalis.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
__author__ = "Jerome Kieffer"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__licence__ = "MIT"
__date__ = "23/02/2023"
__date__ = "15/03/2024"
__status__ = "production"

FOOTER = """To import your files as a project:
Expand Down Expand Up @@ -401,7 +401,7 @@ def treat_mask(self, full=False):
":param full: complete/slow mask analysis"
if self.progress:
self.progress.update(self.progress.max_value - 1, "Generate mask")
dummy_value = numpy.cast[self.mask.dtype](-1)
dummy_value = numpy.asarray(-numpy.ones(1), dtype=self.mask.dtype)[-1] #-1 in the given datatype
mask = (self.mask==dummy_value).astype(numpy.int8)
esperantoimage.EsperantoImage.DUMMY = 1
new_mask = self.geometry_transform(esperantoimage.EsperantoImage(data=mask).data)
Expand Down
54 changes: 27 additions & 27 deletions src/fabio/cbfimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def read(self, fname, frame=None, check_MD5=True, only_raw=False):
return binary_data

if ("Content-MD5" in self.header) and check_MD5:
ref = numpy.string_(self.header["Content-MD5"])
ref = numpy.bytes_(self.header["Content-MD5"])
obt = md5sum(binary_data)
if ref != obt:
logger.error("Checksum of binary data mismatch: expected %s, got %s" % (ref, obt))
Expand Down Expand Up @@ -294,14 +294,14 @@ def write(self, fname):
b"Content-Type: application/octet-stream;",
b' conversions="x-CBF_BYTE_OFFSET"',
b'Content-Transfer-Encoding: BINARY',
numpy.string_("X-Binary-Size: %d" % (len(binary_blob))),
numpy.bytes_("X-Binary-Size: %d" % (len(binary_blob))),
b"X-Binary-ID: 1",
numpy.string_('X-Binary-Element-Type: "%s"' % (dtype)),
numpy.bytes_('X-Binary-Element-Type: "%s"' % (dtype)),
b"X-Binary-Element-Byte-Order: LITTLE_ENDIAN",
b"Content-MD5: " + md5sum(binary_blob),
numpy.string_("X-Binary-Number-of-Elements: %d" % (dim1 * dim2)),
numpy.string_("X-Binary-Size-Fastest-Dimension: %d" % dim1),
numpy.string_("X-Binary-Size-Second-Dimension: %d" % dim2),
numpy.bytes_("X-Binary-Number-of-Elements: %d" % (dim1 * dim2)),
numpy.bytes_("X-Binary-Size-Fastest-Dimension: %d" % dim1),
numpy.bytes_("X-Binary-Size-Second-Dimension: %d" % dim2),
b"X-Binary-Size-Padding: 1",
b"",
self.STARTER + binary_blob,
Expand Down Expand Up @@ -354,22 +354,22 @@ class CIF(dict):
keys are always unicode (str in python3)
values are bytes
"""
EOL = [numpy.string_(i) for i in ("\r", "\n", "\r\n", "\n\r")]
BLANK = [numpy.string_(i) for i in (" ", "\t")] + EOL
SINGLE_QUOTE = numpy.string_("'")
DOUBLE_QUOTE = numpy.string_('"')
SEMICOLUMN = numpy.string_(';')
DOT = numpy.string_('.')
EOL = [numpy.bytes_(i) for i in ("\r", "\n", "\r\n", "\n\r")]
BLANK = [numpy.bytes_(i) for i in (" ", "\t")] + EOL
SINGLE_QUOTE = numpy.bytes_("'")
DOUBLE_QUOTE = numpy.bytes_('"')
SEMICOLUMN = numpy.bytes_(';')
DOT = numpy.bytes_('.')
START_COMMENT = (SINGLE_QUOTE, DOUBLE_QUOTE)
BINARY_MARKER = numpy.string_("--CIF-BINARY-FORMAT-SECTION--")
HASH = numpy.string_("#")
LOOP = numpy.string_("loop_")
BINARY_MARKER = numpy.bytes_("--CIF-BINARY-FORMAT-SECTION--")
HASH = numpy.bytes_("#")
LOOP = numpy.bytes_("loop_")
UNDERSCORE = ord("_")
QUESTIONMARK = numpy.string_("?")
STOP = numpy.string_("stop_")
GLOBAL = numpy.string_("global_")
DATA = numpy.string_("data_")
SAVE = numpy.string_("save_")
QUESTIONMARK = numpy.bytes_("?")
STOP = numpy.bytes_("stop_")
GLOBAL = numpy.bytes_("global_")
DATA = numpy.bytes_("data_")
SAVE = numpy.bytes_("save_")

def __init__(self, _strFilename=None):
"""
Expand Down Expand Up @@ -416,7 +416,7 @@ def loadCIF(self, _strFilename, _bKeepComment=False):
else:
raise RuntimeError("CIF.loadCIF: what is %s type %s" % (_strFilename, type(_strFilename)))
if _bKeepComment:
self._parseCIF(numpy.string_(infile.read()))
self._parseCIF(numpy.bytes_(infile.read()))
else:
self._parseCIF(CIF._readCIF(infile))
if own_fd:
Expand Down Expand Up @@ -454,13 +454,13 @@ def _readCIF(cls, instream):
if "read" not in dir(instream):
raise RuntimeError("CIF._readCIF(instream): I expected instream to be an opened file,\
here I got %s type %s" % (instream, type(instream)))
out_bytes = numpy.string_("")
out_bytes = numpy.bytes_("")
for sLine in instream:
nline = numpy.string_(sLine)
nline = numpy.bytes_(sLine)
pos = nline.find(cls.HASH)
if pos >= 0:
if cls.isAscii(nline):
out_bytes += nline[:pos] + numpy.string_(os.linesep)
out_bytes += nline[:pos] + numpy.bytes_(os.linesep)
if pos > 80:
logger.warning("This line is too long and could cause problems in PreQuest: %s", sLine)
else:
Expand Down Expand Up @@ -535,7 +535,7 @@ def _splitCIF(cls, bytes_text):
idx += 1 + bytes_text[idx + 1:].find(cls.SINGLE_QUOTE)
if idx >= len(bytes_text) - 1:
fields.append(bytes_text[1:-1].strip())
bytes_text = numpy.string_("")
bytes_text = numpy.bytes_("")
finished = True
break

Expand All @@ -552,7 +552,7 @@ def _splitCIF(cls, bytes_text):
idx += 1 + bytes_text[idx + 1:].find(cls.DOUBLE_QUOTE)
if idx >= len(bytes_text) - 1:
fields.append(bytes_text[1:-1].strip())
bytes_text = numpy.string_("")
bytes_text = numpy.bytes_("")
finished = True
break

Expand Down Expand Up @@ -594,7 +594,7 @@ def _splitCIF(cls, bytes_text):
bytes_text = bytes_text[end_binary:].strip()
else:
fields.append(bytes_text)
bytes_text = numpy.string_("")
bytes_text = numpy.bytes_("")
break
return fields

Expand Down
6 changes: 3 additions & 3 deletions src/fabio/eigerimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Project: FabIO X-ray image reader
#
# Copyright (C) 2010-2016 European Synchrotron Radiation Facility
# Copyright (C) 2010-2024 European Synchrotron Radiation Facility
# Grenoble, France
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -45,7 +45,7 @@
__contact__ = "jerome.kieffer@esrf.fr"
__license__ = "MIT"
__copyright__ = "ESRF"
__date__ = "05/07/2022"
__date__ = "15/03/2024"

import logging
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -184,7 +184,7 @@ def write(self, fname):
for i, ds in enumerate(self.dataset):
if ds is None:
# we are in a trouble
data = numpy.atleast_2d(numpy.NaN)
data = numpy.atleast_2d(numpy.nan)
elif isinstance(ds, h5py.Dataset):
data = numpy.atleat_2d(ds[()])
else:
Expand Down
1 change: 1 addition & 0 deletions src/fabio/fabioimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ def _compressed_stream(self,
fobj.seek(0)
elif self._need_a_seek_to_read and mode[0] == "r":
fo = python_uncompress(fname, mode)
print(fname, mode, fo)
fobj = fabioutils.BytesIO(fo.read(), fname, mode)
else:
fobj = python_uncompress(fname, mode)
Expand Down
1 change: 0 additions & 1 deletion src/fabio/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ subdir('test')
subdir('utils')

py.install_sources([
'_version.py',
'adscimage.py',
'binaryimage.py',
'bruker100image.py',
Expand Down
6 changes: 3 additions & 3 deletions src/fabio/nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
"""

__author__ = "Jerome Kieffer"
__author__ = "Jérôme Kieffer"
__contact__ = "Jerome.Kieffer@ESRF.eu"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "28/04/2021"
__date__ = "15/03/2024"
__status__ = "production"
__docformat__ = 'restructuredtext'

Expand All @@ -44,7 +44,7 @@
import time
import numpy
from .fabioutils import exists
from ._version import version
from .version import version

logger = logging.getLogger(__name__)
try:
Expand Down
6 changes: 3 additions & 3 deletions src/fabio/sparseimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Project: X-ray image reader
# https://github.com/silx-kit/fabio
#
# Copyright 2020-2021(C) European Synchrotron Radiation Facility, Grenoble, France
# Copyright 2020-2024(C) European Synchrotron Radiation Facility, Grenoble, France
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
Expand Down Expand Up @@ -37,7 +37,7 @@
__contact__ = "jerome.kieffer@esrf.fr"
__license__ = "MIT"
__copyright__ = "2020 ESRF"
__date__ = "09/02/2023"
__date__ = "15/03/2024"

import logging
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -183,7 +183,7 @@ def read(self, fname, frame=None):
self.dummy = self.intensity.dtype.type(nx_data["dummy"][()])
except KeyError:
if self.intensity.dtype.char in numpy.typecodes['AllFloat']:
self.dummy = numpy.NaN
self.dummy = numpy.nan
else:
self.dummy = 0

Expand Down
13 changes: 7 additions & 6 deletions src/fabio/utils/deprecation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2016-2017 European Synchrotron Radiation Facility
# Copyright (c) 2016-2024 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -24,15 +24,16 @@
# ###########################################################################*/
"""Bunch of useful decorators"""

__authors__ = ["Jerome Kieffer", "H. Payno", "P. Knobel"]
__authors__ = ["Jérôme Kieffer", "H. Payno", "P. Knobel"]
__license__ = "MIT"
__date__ = "18/12/2020"
__date__ = "15/03/2024"

import logging
import functools
import traceback
import re
from .. import _version

from ..version import calc_hexversion, hexversion as ref_hexversion

depreclog = logging.getLogger("fabio.DEPRECATION")

Expand All @@ -54,7 +55,7 @@ def hexversion_fromstring(string):
releaselevel = result[3]
if releaselevel is None:
releaselevel = 0
return _version.calc_hexversion(major, minor, micro, releaselevel, serial=0)
return calc_hexversion(major, minor, micro, releaselevel, serial=0)


def deprecated(func=None, reason=None, replacement=None, since_version=None,
Expand Down Expand Up @@ -154,7 +155,7 @@ def deprecated_warning(type_, name, reason=None, replacement=None,
deprecated_since = hexversion
else:
deprecated_since = _CACHE_VERSIONS[deprecated_since]
log_as_debug = _version.hexversion < deprecated_since
log_as_debug = ref_hexversion < deprecated_since
else:
log_as_debug = False

Expand Down
8 changes: 4 additions & 4 deletions src/fabio/_version.py → version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Project: X-ray image reader
# https://github.com/silx-kit/fabio
#
# Copyright (C) 2015-2023 European Synchrotron Radiation Facility, Grenoble, France
# Copyright (C) 2015-2024 European Synchrotron Radiation Facility, Grenoble, France
#
# Principal author: Jérôme Kieffer (Jerome.Kieffer@ESRF.eu)
#
Expand Down Expand Up @@ -58,7 +58,7 @@
__contact__ = "Jerome.Kieffer@ESRF.eu"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "07/08/2023"
__date__ = "15/03/2024"
__status__ = "production"
__docformat__ = 'restructuredtext'
__all__ = ["date", "version_info", "strictversion", "hexversion", "debianversion",
Expand All @@ -75,8 +75,8 @@
"beta": "b",
"candidate": "rc"}

MAJOR = 2023
MINOR = 11
MAJOR = 2024
MINOR = 3
MICRO = 0
RELEV = "dev" # <16
SERIAL = 0 # <16
Expand Down

0 comments on commit d08b8ea

Please sign in to comment.