From 37507459fef33a49d01be5875a49d1c8fc56d73a Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Wed, 3 Jul 2024 02:09:48 -0500 Subject: [PATCH 1/7] ruff --fix still need to deal with trapz --> trapezoid (not backward compatible) be sure to change docs as well --- WrightTools/_open.py | 3 ++- WrightTools/collection/_cary.py | 3 ++- WrightTools/data/_aramis.py | 3 ++- WrightTools/data/_brunold.py | 3 ++- WrightTools/data/_colors.py | 3 ++- WrightTools/data/_jasco.py | 3 ++- WrightTools/data/_kent.py | 3 ++- WrightTools/data/_labram.py | 3 ++- WrightTools/data/_ocean_optics.py | 3 ++- WrightTools/data/_pycmds.py | 3 ++- WrightTools/data/_shimadzu.py | 3 ++- WrightTools/data/_solis.py | 3 ++- WrightTools/data/_spcm.py | 3 ++- WrightTools/data/_tensor27.py | 3 ++- 14 files changed, 28 insertions(+), 14 deletions(-) diff --git a/WrightTools/_open.py b/WrightTools/_open.py index 85c80516..215a8d9e 100644 --- a/WrightTools/_open.py +++ b/WrightTools/_open.py @@ -13,6 +13,7 @@ from . import collection as wt_collection from . import data as wt_data from . import _group as wt_group +from numpy.lib.npyio import DataSource # --- define ------------------------------------------------------------------------------------- @@ -45,7 +46,7 @@ def open(filepath, edit_local=False): Root-level object in file. """ filepath = os.fspath(filepath) - ds = np.DataSource(None) + ds = DataSource(None) if edit_local is False: tf = tempfile.mkstemp(prefix="", suffix=".wt5") with _open(tf[1], "w+b") as tff: diff --git a/WrightTools/collection/_cary.py b/WrightTools/collection/_cary.py index 06a7a18c..a6dbc556 100644 --- a/WrightTools/collection/_cary.py +++ b/WrightTools/collection/_cary.py @@ -11,6 +11,7 @@ from .. import exceptions as wt_exceptions from ._collection import Collection +from numpy.lib.npyio import DataSource # --- define -------------------------------------------------------------------------------------- @@ -64,7 +65,7 @@ def from_Cary(filepath, name=None, parent=None, verbose=True): name = "cary" # import array lines = [] - ds = np.DataSource(None) + ds = DataSource(None) with ds.open(filestr, "rt", encoding="iso-8859-1") as f: header = f.readline() columns = f.readline() diff --git a/WrightTools/data/_aramis.py b/WrightTools/data/_aramis.py index bb825c0d..8d5f8947 100644 --- a/WrightTools/data/_aramis.py +++ b/WrightTools/data/_aramis.py @@ -12,6 +12,7 @@ from ._data import Data from .. import exceptions as wt_exceptions +from numpy.lib.npyio import DataSource # --- define -------------------------------------------------------------------------------------- @@ -51,7 +52,7 @@ def from_Aramis(filepath, name=None, parent=None, verbose=True) -> Data: if not ".ngc" in filepath.suffixes: wt_exceptions.WrongFileTypeWarning.warn(filepath, ".ngc") - ds = np.DataSource(None) + ds = DataSource(None) f = ds.open(filestr, "rb") header = f.readline() if header != b"NGSNextGen\x01\x00\x00\x00\x01\x00\x00\x00\n": diff --git a/WrightTools/data/_brunold.py b/WrightTools/data/_brunold.py index 048eb395..5e616f7d 100644 --- a/WrightTools/data/_brunold.py +++ b/WrightTools/data/_brunold.py @@ -10,6 +10,7 @@ from ._data import Data from .. import exceptions as wt_exceptions +from numpy.lib.npyio import DataSource # --- define -------------------------------------------------------------------------------------- @@ -61,7 +62,7 @@ def from_BrunoldrRaman(filepath, name=None, parent=None, verbose=True) -> Data: else: data = parent.create_data(**kwargs) # array - ds = np.DataSource(None) + ds = DataSource(None) f = ds.open(filestr, "rt") arr = np.genfromtxt(f, delimiter="\t").T f.close() diff --git a/WrightTools/data/_colors.py b/WrightTools/data/_colors.py index d0ba1cd4..0f59e400 100644 --- a/WrightTools/data/_colors.py +++ b/WrightTools/data/_colors.py @@ -13,6 +13,7 @@ from ._data import Data from .. import kit as wt_kit +from numpy.lib.npyio import DataSource # --- define -------------------------------------------------------------------------------------- @@ -66,7 +67,7 @@ def from_COLORS( else: filestrs = [os.fspath(filepaths)] filepaths = [pathlib.Path(filepaths)] - ds = np.DataSource(None) + ds = DataSource(None) # define format of dat file ------------------------------------------------------------------- if cols: pass diff --git a/WrightTools/data/_jasco.py b/WrightTools/data/_jasco.py index c652f5ba..5c5d020f 100644 --- a/WrightTools/data/_jasco.py +++ b/WrightTools/data/_jasco.py @@ -10,6 +10,7 @@ from ._data import Data from .. import exceptions as wt_exceptions +from numpy.lib.npyio import DataSource # --- define -------------------------------------------------------------------------------------- @@ -59,7 +60,7 @@ def from_JASCO(filepath, name=None, parent=None, verbose=True) -> Data: else: data = parent.create_data(**kwargs) # array - ds = np.DataSource(None) + ds = DataSource(None) f = ds.open(filestr, "rt") arr = np.genfromtxt(f, skip_header=18).T f.close() diff --git a/WrightTools/data/_kent.py b/WrightTools/data/_kent.py index 38435b38..b9809994 100644 --- a/WrightTools/data/_kent.py +++ b/WrightTools/data/_kent.py @@ -14,6 +14,7 @@ from ._data import Data from .. import kit as wt_kit +from numpy.lib.npyio import DataSource # --- define -------------------------------------------------------------------------------------- @@ -86,7 +87,7 @@ def from_KENT( filestrs = [os.fspath(f) for f in filepaths] filepaths = [pathlib.Path(f) for f in filepaths] # import full array --------------------------------------------------------------------------- - ds = np.DataSource(None) + ds = DataSource(None) arr = [] for f in filestrs: ff = ds.open(f, "rt") diff --git a/WrightTools/data/_labram.py b/WrightTools/data/_labram.py index 612a91a4..44d86792 100644 --- a/WrightTools/data/_labram.py +++ b/WrightTools/data/_labram.py @@ -11,6 +11,7 @@ from ._data import Data from .. import exceptions as wt_exceptions from ..kit import _timestamp as timestamp +from numpy.lib.npyio import DataSource # --- define -------------------------------------------------------------------------------------- @@ -62,7 +63,7 @@ def from_LabRAM(filepath, name=None, parent=None, verbose=True) -> Data: else: data = parent.create_data(**kwargs) - ds = np.DataSource(None) + ds = DataSource(None) f = ds.open(filestr, "rt", encoding="ISO-8859-1") # header diff --git a/WrightTools/data/_ocean_optics.py b/WrightTools/data/_ocean_optics.py index 6541c555..d89ecfa4 100644 --- a/WrightTools/data/_ocean_optics.py +++ b/WrightTools/data/_ocean_optics.py @@ -10,6 +10,7 @@ from ._data import Data from .. import exceptions as wt_exceptions +from numpy.lib.npyio import DataSource # --- define -------------------------------------------------------------------------------------- @@ -61,7 +62,7 @@ def from_ocean_optics(filepath, name=None, *, parent=None, verbose=True) -> Data # array skip_header = 14 skip_footer = 1 - ds = np.DataSource(None) + ds = DataSource(None) f = ds.open(filestr, "rt") arr = np.genfromtxt(f, skip_header=skip_header, skip_footer=skip_footer, delimiter="\t").T f.close() diff --git a/WrightTools/data/_pycmds.py b/WrightTools/data/_pycmds.py index 3f13fdfa..631c127c 100644 --- a/WrightTools/data/_pycmds.py +++ b/WrightTools/data/_pycmds.py @@ -15,6 +15,7 @@ from ._data import Data from .. import kit as wt_kit from .. import units as wt_units +from numpy.lib.npyio import DataSource # --- define -------------------------------------------------------------------------------------- @@ -51,7 +52,7 @@ def from_PyCMDS(filepath, name=None, parent=None, verbose=True, *, collapse=True filestr = os.fspath(filepath) # header - ds = np.DataSource(None) + ds = DataSource(None) file_ = ds.open(filestr, "rt") headers = tidy_headers.read(file_) file_.seek(0) diff --git a/WrightTools/data/_shimadzu.py b/WrightTools/data/_shimadzu.py index 00dbdd7e..1aab5c31 100644 --- a/WrightTools/data/_shimadzu.py +++ b/WrightTools/data/_shimadzu.py @@ -10,6 +10,7 @@ from ._data import Data from .. import exceptions as wt_exceptions +from numpy.lib.npyio import DataSource # --- define -------------------------------------------------------------------------------------- @@ -59,7 +60,7 @@ def from_shimadzu(filepath, name=None, parent=None, verbose=True) -> Data: else: data = parent.create_data(**kwargs) # array - ds = np.DataSource(None) + ds = DataSource(None) f = ds.open(filestr, "rt") arr = np.genfromtxt(f, skip_header=2, delimiter=",").T f.close() diff --git a/WrightTools/data/_solis.py b/WrightTools/data/_solis.py index c9ce5ce2..9f45f3f0 100644 --- a/WrightTools/data/_solis.py +++ b/WrightTools/data/_solis.py @@ -13,6 +13,7 @@ from ._data import Data from .. import exceptions as wt_exceptions from ..kit import _timestamp as timestamp +from numpy.lib.npyio import DataSource # --- define -------------------------------------------------------------------------------------- @@ -68,7 +69,7 @@ def from_Solis(filepath, name=None, parent=None, verbose=True) -> Data: if not name: name = filepath.name.split(".")[0] # create data - ds = np.DataSource(None) + ds = DataSource(None) f = ds.open(filestr, "rt") axis0 = [] arr = [] diff --git a/WrightTools/data/_spcm.py b/WrightTools/data/_spcm.py index ab9737fb..d5696eb8 100644 --- a/WrightTools/data/_spcm.py +++ b/WrightTools/data/_spcm.py @@ -13,6 +13,7 @@ from ._data import Data from .. import exceptions as wt_exceptions from ..kit import _timestamp as timestamp +from numpy.lib.npyio import DataSource # --- define -------------------------------------------------------------------------------------- @@ -65,7 +66,7 @@ def from_spcm(filepath, name=None, *, delimiter=",", parent=None, verbose=True) # create headers dictionary headers = collections.OrderedDict() header_lines = 0 - ds = np.DataSource(None) + ds = DataSource(None) f = ds.open(filestr, "rt") while True: line = f.readline().strip() diff --git a/WrightTools/data/_tensor27.py b/WrightTools/data/_tensor27.py index c030e6e3..c2e04f83 100644 --- a/WrightTools/data/_tensor27.py +++ b/WrightTools/data/_tensor27.py @@ -10,6 +10,7 @@ from ._data import Data from .. import exceptions as wt_exceptions +from numpy.lib.npyio import DataSource # --- define -------------------------------------------------------------------------------------- @@ -70,7 +71,7 @@ def from_Tensor27(filepath, name=None, parent=None, verbose=True) -> Data: else: data = parent.create_data(**kwargs) # array - ds = np.DataSource(None) + ds = DataSource(None) f = ds.open(filestr, "rt") arr = np.genfromtxt(f, skip_header=0).T f.close() From c34a86131725b8a505663a43e9ad7d937ae7e387 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Wed, 3 Jul 2024 08:32:04 -0500 Subject: [PATCH 2/7] trapezoid --- WrightTools/data/_data.py | 9 +++++---- tests/kit/lineshapes.py | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/WrightTools/data/_data.py b/WrightTools/data/_data.py index 57ed6652..25202359 100644 --- a/WrightTools/data/_data.py +++ b/WrightTools/data/_data.py @@ -852,27 +852,28 @@ def moment(self, axis, channel=0, moment=1, *, resultant=None): np.sum(np.diff(x, axis=axis_index), axis=axis_index, keepdims=True) ) + trapezoid = np.trapezoid if (int(np.__version__.split(".")[0]) > 1) else np.trapz for moment in moments: about = 0 norm = 1 if moment > 0: - norm = np.trapz(y, x, axis=axis_index) + norm = trapezoid(y, x, axis=axis_index) norm = np.array(norm) norm.shape = new_shape if moment > 1: - about = np.trapz(x * y, x, axis=axis_index) + about = trapezoid(x * y, x, axis=axis_index) about = np.array(about) about.shape = new_shape about /= norm if moment > 2: - sigma = np.trapz((x - about) ** 2 * y, x, axis=axis_index) + sigma = trapezoid((x - about) ** 2 * y, x, axis=axis_index) sigma = np.array(sigma) sigma.shape = new_shape sigma /= norm sigma **= 0.5 norm *= sigma**moment - values = np.trapz((x - about) ** moment * y, x, axis=axis_index) + values = trapezoid((x - about) ** moment * y, x, axis=axis_index) values = np.array(values) values.shape = new_shape values /= norm diff --git a/tests/kit/lineshapes.py b/tests/kit/lineshapes.py index ccaa5957..15ebcbf2 100644 --- a/tests/kit/lineshapes.py +++ b/tests/kit/lineshapes.py @@ -6,7 +6,8 @@ import numpy as np import WrightTools as wt - +# numpy 2.0 compatibility +trapezoid = np.trapezoid if int(np.__version__.split(".")[0]) > 1 else np.trapz # --- test ---------------------------------------------------------------------------------------- @@ -16,7 +17,7 @@ def test_gaussian(): x0 = 0 FWHM = 1 y = wt.kit.gaussian(x, x0, FWHM, norm="area") - assert np.isclose(np.trapz(y, x), 1, rtol=1e-3, atol=1e-3) + assert np.isclose(trapezoid(y, x), 1, rtol=1e-3, atol=1e-3) y = wt.kit.gaussian(x, x0, FWHM, norm="height") assert np.isclose(y.max(), 1, rtol=1e-3, atol=1e-3) @@ -26,7 +27,7 @@ def test_lorentzian_complex(): x0 = 0 G = 0.1 y = wt.kit.lorentzian_complex(x, x0, G, norm="area_int") - assert np.isclose(np.trapz(np.abs(y) ** 2, x), 1, rtol=1e-3, atol=1e-3) + assert np.isclose(trapezoid(np.abs(y) ** 2, x), 1, rtol=1e-3, atol=1e-3) y = wt.kit.lorentzian_complex(x, x0, G, norm="height_imag") assert np.isclose(y.imag.max(), 1, rtol=1e-3, atol=1e-3) @@ -36,7 +37,7 @@ def test_lorentzian_real(): x0 = 0 G = 0.1 y = wt.kit.lorentzian_real(x, x0, G, norm="area") - assert np.isclose(np.trapz(y, x), 1, rtol=1e-3, atol=1e-3) + assert np.isclose(trapezoid(y, x), 1, rtol=1e-3, atol=1e-3) y = wt.kit.lorentzian_real(x, x0, G, norm="height") assert np.isclose(y.max(), 1, rtol=1e-3, atol=1e-3) From 7d0c124c19361c5daa182bf380c564441067329a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 3 Jul 2024 13:32:23 +0000 Subject: [PATCH 3/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/kit/lineshapes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/kit/lineshapes.py b/tests/kit/lineshapes.py index 15ebcbf2..431e86aa 100644 --- a/tests/kit/lineshapes.py +++ b/tests/kit/lineshapes.py @@ -6,6 +6,7 @@ import numpy as np import WrightTools as wt + # numpy 2.0 compatibility trapezoid = np.trapezoid if int(np.__version__.split(".")[0]) > 1 else np.trapz From 43605f223dceed5857bc958b3c0233490d5a0108 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Mon, 21 Oct 2024 15:18:04 -0500 Subject: [PATCH 4/7] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd1e54d5..265cfd30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/). - constants in chopped data will inherit the units of the original data ## Changed +- numpy 2.0 compatible - refactor of artists.quick1D and artists.quick2D - quick2D and quick1D will not force `autosave=True` if the number of figures is large. Instead, interactive plotting will be truncated if the number of figures is large. - artists now gets turbo colormap straight from matplotlib From a7f0c1de31ee636005ddd69675f5260cfa25f909 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Mon, 21 Oct 2024 15:20:11 -0500 Subject: [PATCH 5/7] Update setup.py increment tidy_headers so there is no numpy 2.0 issue --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d4fe3588..c49ff13e 100755 --- a/setup.py +++ b/setup.py @@ -45,7 +45,7 @@ def read(fname): "python-dateutil", "scipy", "click", - "tidy_headers>=1.0.0", + "tidy_headers>=1.0.4", "rich", ], extras_require={ From 7103a7a5e356e89b9eb70204c51a0c722d1c4b85 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:27:30 -0500 Subject: [PATCH 6/7] Update write_from_function.rst --- docs/write_from_function.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/write_from_function.rst b/docs/write_from_function.rst index 2a92fcc0..18071544 100644 --- a/docs/write_from_function.rst +++ b/docs/write_from_function.rst @@ -72,7 +72,7 @@ We will walk through by way of example, using :meth:`~WrightTools.data.from_JASC else: data = parent.create_data(**kwargs) # array - ds = np.DataSource(None) + ds = np.lib.npyio.DataSource(None) f = ds.open(filestr, "rt") arr = np.genfromtxt(f, skip_header=18).T f.close() @@ -249,7 +249,7 @@ For one-dimensional data formats, this is particularly easy: .. code-block:: python # array - ds = np.DataSource(None) + ds = np.lib.npyio.DataSource(None) f = ds.open(filestr, "rt") arr = np.genfromtxt(f, skip_header=18).T f.close() @@ -260,7 +260,7 @@ For one-dimensional data formats, this is particularly easy: :class:`numpy.DataSource` is a class which provides transparent decompression and remote file retrieval. :func:`numpy.genfromtxt` will handle this itself, however it will leave the downloaded files in the working directory, and opening explicitly allows you to use the file more directly as well. -Using ``np.DataSource(None)`` causes it to use temporary files which are removed automatically. +Using ``numpy.lib.npyio.DataSource(None)`` causes it to use temporary files which are removed automatically. Opening in ``"rt"`` mode ensures that you are reading as text. Parsing multidimensional datasets (and in particular formats which allow arbitrary dimensionality) From 48e912167180eb043db652ed580e4306322e4a81 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Wed, 23 Oct 2024 11:55:23 -0500 Subject: [PATCH 7/7] pin sphinx --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c49ff13e..3b5c8e32 100755 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ def read(fname): with open(os.path.join(here, "WrightTools", "VERSION")) as version_file: version = version_file.read().strip() -docs_require = ["sphinx", "sphinx-gallery==0.8.2", "sphinx-rtd-theme"] +docs_require = ["sphinx<8.0", "sphinx-gallery==0.8.2", "sphinx-rtd-theme"] setup( name="WrightTools",