From e83f4499252f83bebc2f3fdcd8c74b5f97c2da15 Mon Sep 17 00:00:00 2001 From: Matthew Newville Date: Mon, 1 Jul 2024 12:09:50 -0500 Subject: [PATCH] fixes for numpy2 deprecations --- larch/builtins.py | 110 ++++++++++++++----------------- larch/math/peaks.py | 2 +- larch/math/tomography.py | 2 +- larch/wxlib/columnframe.py | 2 +- larch/wxlib/specfile_importer.py | 2 +- larch/wxlib/xas_importer.py | 2 +- larch/wxlib/xrfdisplay_utils.py | 4 +- larch/xafs/pre_edge.py | 2 +- 8 files changed, 56 insertions(+), 70 deletions(-) diff --git a/larch/builtins.py b/larch/builtins.py index a5ace7c12..a021aec85 100644 --- a/larch/builtins.py +++ b/larch/builtins.py @@ -51,68 +51,54 @@ 'trunc') # inherit these from numpy - -from_numpy = ('Inf', 'NAN', 'abs', 'absolute', 'add', 'all', 'allclose', - 'alltrue', 'amax', 'amin', 'angle', 'any', 'append', 'arange', - 'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctan2', - 'arctanh', 'argmax', 'argmin', 'argsort', 'argwhere', 'around', - 'array', 'asanyarray', 'asarray', 'atleast_1d', 'atleast_2d', - 'atleast_3d', 'average', 'bartlett', 'bincount', 'bitwise_and', - 'bitwise_not', 'bitwise_or', 'bitwise_xor', 'blackman', - 'broadcast', 'ceil', 'chararray', 'choose', 'clip', - 'column_stack', 'common_type', 'complex128', 'compress', - 'concatenate', 'conjugate', 'convolve', 'copysign', 'corrcoef', - 'correlate', 'cos', 'cosh', 'cov', 'cross', 'cumprod', - 'cumproduct', 'cumsum', 'datetime_data', 'deg2rad', 'degrees', - 'delete', 'diag', 'diag_indices', 'diag_indices_from', - 'diagflat', 'diagonal', 'diff', 'digitize', 'divide', 'dot', - 'dsplit', 'dstack', 'dtype', 'e', 'ediff1d', 'empty', - 'empty_like', 'equal', 'exp', 'exp2', 'expand_dims', 'expm1', - 'extract', 'eye', 'fabs', 'fft', 'fill_diagonal', 'finfo', 'fix', - 'flatiter', 'flatnonzero', 'fliplr', 'flipud', 'float64', - 'floor', 'floor_divide', 'fmax', 'fmin', 'fmod', 'format_parser', - 'frexp', 'frombuffer', 'fromfile', 'fromfunction', 'fromiter', - 'frompyfunc', 'fromregex', 'fromstring', 'genfromtxt', - 'getbufsize', 'geterr', 'gradient', 'greater', 'greater_equal', - 'hamming', 'hanning', 'histogram', 'histogram2d', 'histogramdd', - 'hsplit', 'hstack', 'hypot', 'i0', 'identity', 'iinfo', 'imag', - 'in1d', 'index_exp', 'indices', 'inexact', 'inf', 'info', - 'infty', 'inner', 'insert', 'int32', 'integer', 'interp', - 'intersect1d', 'invert', 'iscomplex', 'iscomplexobj', 'isfinite', - 'isinf', 'isnan', 'isneginf', 'isposinf', 'isreal', 'isrealobj', - 'isscalar', 'issctype', 'iterable', 'kaiser', 'kron', 'ldexp', - 'left_shift', 'less', 'less_equal', 'linalg', 'linspace', - 'little_endian', 'loadtxt', 'log', 'log10', 'log1p', 'log2', - 'logaddexp', 'logaddexp2', 'logical_and', 'logical_not', - 'logical_or', 'logical_xor', 'logspace', 'longcomplex', - 'longdouble', 'longfloat', 'longlong', 'mask_indices', 'mat', - 'matrix', 'max', 'maximum', 'maximum_sctype', 'may_share_memory', - 'mean', 'median', 'memmap', 'meshgrid', 'mgrid', 'min', - 'minimum', 'mintypecode', 'mod', 'modf', 'msort', 'multiply', - 'nan', 'nan_to_num', 'nanargmax', 'nanargmin', 'nanmax', - 'nanmin', 'nansum', 'nbytes', 'ndarray', 'ndenumerate', 'ndim', - 'ndindex', 'negative', 'nextafter', 'nonzero', 'not_equal', - 'number', 'obj2sctype', 'ogrid', 'ones', 'ones_like', 'outer', - 'packbits', 'percentile', 'pi', 'piecewise', 'place', 'poly', - 'poly1d', 'polyadd', 'polyder', 'polydiv', 'polyint', 'polymul', - 'polynomial', 'polysub', 'polyval', 'power', 'prod', 'product', - 'ptp', 'put', 'putmask', 'rad2deg', 'radians', 'random', 'ravel', - 'real', 'real_if_close', 'reciprocal', 'record', 'remainder', - 'repeat', 'reshape', 'resize', 'right_shift', 'rint', 'roll', - 'rollaxis', 'roots', 'rot90', 'round', 'round_', 'row_stack', - 'savetxt', 'savez', 'searchsorted', 'select', 'setbufsize', - 'setdiff1d', 'seterr', 'setxor1d', 'shape', 'short', 'sign', - 'signbit', 'signedinteger', 'sin', 'sinc', 'single', - 'singlecomplex', 'sinh', 'size', 'sometrue', 'sort', - 'sort_complex', 'spacing', 'split', 'sqrt', 'square', 'squeeze', - 'std', 'subtract', 'sum', 'swapaxes', 'take', 'tan', 'tanh', - 'tensordot', 'tile', 'trace', 'transpose', 'trapz', 'tri', - 'tril', 'tril_indices', 'tril_indices_from', 'trim_zeros', - 'triu', 'triu_indices', 'triu_indices_from', 'true_divide', - 'trunc', 'ubyte', 'uint', 'uint32', 'union1d', 'unique', - 'unpackbits', 'unravel_index', 'unsignedinteger', 'unwrap', - 'ushort', 'vander', 'var', 'vdot', 'vectorize', 'vsplit', - 'vstack', 'where', 'who', 'zeros', 'zeros_like') +from_numpy = ('abs', 'add', 'all', 'amax', 'amin', 'angle', 'any', 'append', + 'arange', 'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctan2', + 'arctanh', 'argmax', 'argmin', 'argsort', 'argwhere', 'around', 'array', + 'asarray', 'atleast_1d', 'atleast_2d', 'atleast_3d', 'average', 'bartlett', + 'bitwise_and', 'bitwise_not', 'bitwise_or', 'bitwise_xor', 'blackman', + 'broadcast', 'ceil', 'choose', 'clip', 'column_stack', 'common_type', + 'complex128', 'compress', 'concatenate', 'conjugate', 'convolve', + 'copysign', 'corrcoef', 'correlate', 'cos', 'cosh', 'cov', 'cross', + 'cumprod', 'cumsum', 'datetime_data', 'deg2rad', 'degrees', 'delete', + 'diag', 'diag_indices', 'diag_indices_from', 'diagflat', 'diagonal', + 'diff', 'digitize', 'divide', 'dot', 'dsplit', 'dstack', 'dtype', 'e', + 'ediff1d', 'empty', 'empty_like', 'equal', 'exp', 'exp2', 'expand_dims', + 'expm1', 'extract', 'eye', 'fabs', 'fft', 'fill_diagonal', 'finfo', 'fix', + 'flatiter', 'flatnonzero', 'fliplr', 'flipud', 'float64', 'floor', + 'floor_divide', 'fmax', 'fmin', 'fmod', 'format_parser', 'frexp', + 'frombuffer', 'fromfile', 'fromfunction', 'fromiter', 'frompyfunc', + 'fromregex', 'fromstring', 'genfromtxt', 'getbufsize', 'geterr', + 'gradient', 'greater', 'greater_equal', 'hamming', 'hanning', 'histogram', + 'histogram2d', 'histogramdd', 'hsplit', 'hstack', 'hypot', 'i0', + 'identity', 'iinfo', 'imag', 'indices', 'inexact', 'inf', 'info', 'inner', + 'insert', 'int32', 'integer', 'interp', 'intersect1d', 'invert', + 'iscomplex', 'iscomplexobj', 'isfinite', 'isinf', 'isnan', 'isneginf', + 'isposinf', 'isreal', 'isrealobj', 'isscalar', 'iterable', 'kaiser', + 'kron', 'ldexp', 'left_shift', 'less', 'less_equal', 'linalg', 'linspace', + 'little_endian', 'loadtxt', 'log', 'log10', 'log1p', 'log2', 'logaddexp', + 'logaddexp2', 'logical_and', 'logical_not', 'logical_or', 'logical_xor', + 'logspace', 'longdouble', 'longlong', 'mask_indices', 'matrix', 'maximum', + 'may_share_memory', 'mean', 'median', 'memmap', 'meshgrid', 'minimum', + 'mintypecode', 'mod', 'modf', 'msort', 'multiply', 'nan', 'nan_to_num', + 'nanargmax', 'nanargmin', 'nanmax', 'nanmin', 'nansum', 'ndarray', + 'ndenumerate', 'ndim', 'ndindex', 'negative', 'nextafter', 'nonzero', + 'not_equal', 'number', 'ones', 'ones_like', 'outer', 'packbits', + 'percentile', 'pi', 'piecewise', 'place', 'poly', 'poly1d', 'polyadd', + 'polyder', 'polydiv', 'polyint', 'polymul', 'polynomial', 'polysub', + 'polyval', 'power', 'prod', 'ptp', 'put', 'putmask', 'rad2deg', 'radians', + 'random', 'ravel', 'real', 'real_if_close', 'reciprocal', 'record', + 'remainder', 'repeat', 'reshape', 'resize', 'right_shift', 'rint', 'roll', + 'rollaxis', 'roots', 'rot90', 'round', 'searchsorted', 'select', + 'setbufsize', 'setdiff1d', 'seterr', 'setxor1d', 'shape', 'short', 'sign', + 'signbit', 'signedinteger', 'sin', 'sinc', 'single', 'sinh', 'size', + 'sort', 'sort_complex', 'spacing', 'split', 'sqrt', 'square', 'squeeze', + 'std', 'subtract', 'sum', 'swapaxes', 'take', 'tan', 'tanh', 'tensordot', + 'tile', 'trace', 'transpose', 'tri', 'tril', 'tril_indices', + 'tril_indices_from', 'trim_zeros', 'triu', 'triu_indices', + 'triu_indices_from', 'true_divide', 'trunc', 'ubyte', 'uint', 'uint32', + 'union1d', 'unique', 'unravel_index', 'unsignedinteger', 'unwrap', + 'ushort', 'vander', 'var', 'vdot', 'vectorize', 'vsplit', 'vstack', + 'where', 'zeros', 'zeros_like') numpy_renames = {'ln':'log', 'asin':'arcsin', 'acos':'arccos', 'atan':'arctan', 'atan2':'arctan2', 'atanh':'arctanh', diff --git a/larch/math/peaks.py b/larch/math/peaks.py index 874df536a..a24ad8547 100644 --- a/larch/math/peaks.py +++ b/larch/math/peaks.py @@ -29,7 +29,7 @@ def peak_indices(y, threshold=0.1, min_dist=1): ndarray Array with numeric indexes of the peaks that were detected. """ - thres = threshold * y.ptp()+ y.min() + thres = threshold * np.ptp(y) + y.min() min_dist = int(min_dist) # compute first order difference diff --git a/larch/math/tomography.py b/larch/math/tomography.py index 504f33c60..d908b95cb 100644 --- a/larch/math/tomography.py +++ b/larch/math/tomography.py @@ -35,7 +35,7 @@ def ensure_radians(a): """ensure angle data is in radians, not degrees, converts degrees to radians if a peak-to-peak > 32 or step size > 0.2 """ - if a.ptp() > 32 or np.diff(a).mean() > 0.20: + if np.ptp(a) > 32 or np.diff(a).mean() > 0.20: a = np.radians(a) return a diff --git a/larch/wxlib/columnframe.py b/larch/wxlib/columnframe.py index 706ca289a..fa577d53b 100644 --- a/larch/wxlib/columnframe.py +++ b/larch/wxlib/columnframe.py @@ -1126,7 +1126,7 @@ def onOK(self, event=None): buff.append("{group}.mu = {group}.ydat") buff.append("sort_xafs({group}, overwrite=True, fix_repeats=True)") else: - buff.append("{group}.scale = 1./({group}.ydat.ptp()+1.e-15)") + buff.append("{group}.scale = 1./(ptp({group}.ydat)+1.e-15)") array_desc = dict(xdat=self.workgroup.plot_xlabel, ydat=self.workgroup.plot_ylabel, diff --git a/larch/wxlib/specfile_importer.py b/larch/wxlib/specfile_importer.py index 993ae9200..6e28cb035 100644 --- a/larch/wxlib/specfile_importer.py +++ b/larch/wxlib/specfile_importer.py @@ -537,7 +537,7 @@ def onOK(self, event=None): buff.append("{group}.mu = {group}.ydat") buff.append("sort_xafs({group}, overwrite=True, fix_repeats=True)") else: - buff.append("{group}.scale = 1./({group}.ydat.ptp()+1.e-16)") + buff.append("{group}.scale = 1./(ptp({group}.ydat.ptp)+1.e-16)") script = "\n".join(buff) self.config['array_desc'] = dict(xdat=self.workgroup.plot_xlabel, diff --git a/larch/wxlib/xas_importer.py b/larch/wxlib/xas_importer.py index 7f6806eb7..ff2ecd9c5 100644 --- a/larch/wxlib/xas_importer.py +++ b/larch/wxlib/xas_importer.py @@ -846,7 +846,7 @@ def onOK(self, event=None): buff.append("{group}.mu = {group}.ydat") buff.append("sort_xafs({group}, overwrite=True, fix_repeats=True)") else: - buff.append("{group}.scale = 1./({group}.ydat.ptp()+1.e-16)") + buff.append("{group}.scale = 1./(ptp({group}.ydat))+1.e-16)") script = "\n".join(buff) self.array_sel["xarr"] = xarr diff --git a/larch/wxlib/xrfdisplay_utils.py b/larch/wxlib/xrfdisplay_utils.py index bb1d095c3..8c90659be 100644 --- a/larch/wxlib/xrfdisplay_utils.py +++ b/larch/wxlib/xrfdisplay_utils.py @@ -512,6 +512,6 @@ def get_mean(self): def get_cps(self): valid = np.where(self.times > 0)[0] - if len(valid) < 1 or self.times[valid].ptp() < 0.5: + if len(valid) < 1 or np.ptp(self.times[valid]) < 0.5: return 0 - return self.data[valid].sum() / self.times[valid].ptp() + return self.data[valid].sum() / np.ptp(self.times[valid]) diff --git a/larch/xafs/pre_edge.py b/larch/xafs/pre_edge.py index f5cdbf056..eb36086bd 100644 --- a/larch/xafs/pre_edge.py +++ b/larch/xafs/pre_edge.py @@ -94,7 +94,7 @@ def _finde0(energy, mu_input, estep=None, use_smooth=True): # find points of high derivative dmu[np.where(~np.isfinite(dmu))] = -1.0 dm_min = dmu[nmin:-nmin].min() - dm_ptp = max(1.e-10, dmu[nmin:-nmin].ptp()) + dm_ptp = max(1.e-10, np.ptp(dmu[nmin:-nmin])) dmu = (dmu - dm_min)/dm_ptp dhigh = 0.60 if len(en) > 20 else 0.30