From d90931e939a31de06dd869fad5f1b5ab9b5685a6 Mon Sep 17 00:00:00 2001 From: Juuso Lehtivarjo Date: Wed, 13 Nov 2024 09:36:38 +0200 Subject: [PATCH 1/6] Function rename for NumPy >2.0 --- nmrglue/process/proc_lp.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/nmrglue/process/proc_lp.py b/nmrglue/process/proc_lp.py index 4a8ef948..0269dc91 100644 --- a/nmrglue/process/proc_lp.py +++ b/nmrglue/process/proc_lp.py @@ -528,8 +528,8 @@ def cadzow_single(x, M, K, min_var=False): U, s, Vh = scipy.linalg.svd(X) # correct the singular values and truncate the rank K - Ul = np.mat(U[:, :K]) - Vlh = np.mat(Vh[:K, :]) # first K columns of V are first K rows of Vh + Ul = np.asmatrix(U[:, :K]) + Vlh = np.asmatrix(Vh[:K, :]) # first K columns of V are first K rows of Vh sl = s[:K] if min_var: # adjust singular values using minimum variance method @@ -537,7 +537,7 @@ def cadzow_single(x, M, K, min_var=False): s2 = (1. / (M - K)) * np.power(s[K:], 2).sum() sl = np.array([l - s2 / l for l in sl]) - Sl = np.mat(np.diag(sl)) + Sl = np.asmatrix(np.diag(sl)) # compute enhanced data vector for rank-reduced data matrix Xp = Ul * Sl * Vlh @@ -803,7 +803,7 @@ def find_lpc_svd(D, d): L = D.shape[0] m = D.shape[1] U, s, Vh = scipy.linalg.svd(D) # SVD decomposition - U, Vh = np.mat(U), np.mat(Vh) # make U and Vh matrices + U, Vh = np.asmatrix(U), np.asmatrix(Vh) # make U and Vh matrices Si = pinv_diagsvd(s, m, L) # construct the pseudo-inverse sigma matrix return np.array(Vh.H * Si * U.H * d) @@ -833,7 +833,7 @@ def find_lpc_qr(D, d): Find linear prediction filter using QR decomposition. """ q, r = scipy.linalg.qr(D) - q, r = np.mat(q), np.mat(r) + q, r = np.asmatrix(q), np.asmatrix(r) # SPEED # the next line is slow and the use of pinv2 should be avoided as @@ -852,9 +852,9 @@ def find_lpc_cholesky(D, d): # form the normal equation (D.H*D)*a = D.H*d # SPEED # this can be improved by using the Hankel nature of D - D = np.mat(D) - DhD = np.mat(np.dot(D.H, D)) - Dhd = np.mat(np.dot(D.H, d)) + D = np.asmatrix(D) + DhD = np.asmatrix(np.dot(D.H, D)) + Dhd = np.asmatrix(np.dot(D.H, d)) c, lower = scipy.linalg.cho_factor(DhD) # Compute Cholesky decomp. return scipy.linalg.cho_solve((c, lower), Dhd) # solve normal equation @@ -1018,7 +1018,7 @@ def find_lproots_hsvd(x, M, K, mode, zmethod='sm'): # SVD of data matrix and truncation of U to form Uk U, s, Vh = scipy.linalg.svd(X) - Uk = np.mat(U[:, :K]) # truncated U matrix of rank K + Uk = np.asmatrix(U[:, :K]) # truncated U matrix of rank K Ub = Uk[:-1] # Uk with bottom row removed Ut = Uk[1:] # Uk with top row removed From d18cfb7c2debac2a13d544d1ccfff98aba836dcd Mon Sep 17 00:00:00 2001 From: Juuso Lehtivarjo Date: Wed, 13 Nov 2024 10:18:23 +0200 Subject: [PATCH 2/6] More numpy 2.0 compatibility changes with pylint --- .../t1_measurements/extract_trajs.py | 4 +- .../t1_measurements/fit_exp_leastsq.py | 8 ++- examples/fitting_data/t1_measurements/pt.py | 5 +- .../integration/integrate_1d/integrate_1d.py | 4 +- .../integration/integrate_2d/integrate_2d.py | 6 +- .../extract_traj.py | 4 +- .../s12-s15_relaxation_analysis/plot_boxes.py | 16 ++--- .../plot_trajectories.py | 11 ++-- examples/plotting/plot_2d/plot_assignments.py | 4 +- examples/plotting/plot_2d/plot_boxes.py | 12 ++-- .../simulation/simulate_ucsf/make_ucsf.py | 2 +- nmrglue/fileio/pipe.py | 23 ++++--- nmrglue/fileio/table.py | 2 +- nmrglue/fileio/tecmag.py | 62 +++++++++---------- 14 files changed, 89 insertions(+), 74 deletions(-) diff --git a/examples/fitting_data/t1_measurements/extract_trajs.py b/examples/fitting_data/t1_measurements/extract_trajs.py index f96628b1..dbffd751 100755 --- a/examples/fitting_data/t1_measurements/extract_trajs.py +++ b/examples/fitting_data/t1_measurements/extract_trajs.py @@ -5,8 +5,8 @@ import numpy as np # read in the integration limits and list of spectra -peak_list = np.recfromtxt("boxes.in", encoding="UTF-8") -spectra_list = np.recfromtxt("spectra.in", encoding="UTF-8") +peak_list = np.genfromtxt("boxes.in", encoding="UTF-8") +spectra_list = np.genfromtxt("spectra.in", encoding="UTF-8") # prepare the trajs records array num_spec = spectra_list.size diff --git a/examples/fitting_data/t1_measurements/fit_exp_leastsq.py b/examples/fitting_data/t1_measurements/fit_exp_leastsq.py index eaa967a7..efeef81b 100755 --- a/examples/fitting_data/t1_measurements/fit_exp_leastsq.py +++ b/examples/fitting_data/t1_measurements/fit_exp_leastsq.py @@ -7,9 +7,11 @@ # read in the trajectories and times trajs = np.load("traj.npy") -t1 = np.recfromtxt("time.dat") +t1 = np.genfromtxt("time.dat") # fitting function and residual calculation + + def fit_func(p, x): A, R2 = p # bound A between 0.98 and 1.02 (although fits do not reflect this) @@ -20,11 +22,13 @@ def fit_func(p, x): return A * np.exp(-1.0 * np.array(x) * R2 / 1.0e6) + def residuals(p, y, x): err = y - fit_func(p, x) return err -p0 = [1.0, 0.05] # initial guess + +p0 = [1.0, 0.05] # initial guess fits = {} # loop over the peak trajectories diff --git a/examples/fitting_data/t1_measurements/pt.py b/examples/fitting_data/t1_measurements/pt.py index fa2710c6..3dec254c 100755 --- a/examples/fitting_data/t1_measurements/pt.py +++ b/examples/fitting_data/t1_measurements/pt.py @@ -6,6 +6,8 @@ import numpy as np # the same fit_func as in fit_exp_leastsq.py + + def fit_func(p, x): A, R2 = p @@ -18,10 +20,11 @@ def fit_func(p, x): return A * np.exp(-1.0 * np.array(x) * R2 / 1.0e6) + # read in the trajectories, fitting results, and times fits = pickle.load(open("fits.pickle", "rb")) trajs = np.load("traj.npy") -times = np.recfromtxt("time.dat") +times = np.genfromtxt("time.dat") sim_times = np.linspace(times[0], times[-1], 2000) diff --git a/examples/integration/integrate_1d/integrate_1d.py b/examples/integration/integrate_1d/integrate_1d.py index 4645f623..c47bb239 100755 --- a/examples/integration/integrate_1d/integrate_1d.py +++ b/examples/integration/integrate_1d/integrate_1d.py @@ -10,7 +10,7 @@ length = data.shape[0] # read in the integration limits -peak_list = np.recfromtxt("limits.in") +peak_list = np.genfromtxt("limits.in") # determine the ppm scale uc = ng.pipe.make_uc(dic, data) @@ -40,7 +40,7 @@ ax.plot(peak_scale, peak.cumsum() / 100. + peak.max(), 'g-') ax.plot(peak_scale, [0] * len(peak_scale), 'r-') ax.text(peak_scale[0], 0.5 * peak.sum() / 100. + peak.max(), name, - fontsize=8) + fontsize=8) # write out the integration info tup = (name, peak_scale[0], peak_scale[-1], peak.sum()) diff --git a/examples/integration/integrate_2d/integrate_2d.py b/examples/integration/integrate_2d/integrate_2d.py index 46a6271f..13f81a88 100755 --- a/examples/integration/integrate_2d/integrate_2d.py +++ b/examples/integration/integrate_2d/integrate_2d.py @@ -8,10 +8,10 @@ dic, data = ng.pipe.read("nmrpipe_2d/test.ft2") # read in the integration limits -peak_list = np.recfromtxt("limits.in") +peak_list = np.genfromtxt("limits.in") # prepare the output file -f = open("volumes.out",'w') +f = open("volumes.out", 'w') f.write("# Name\tVolume\n") # loop over the integration limits @@ -23,7 +23,7 @@ y0, y1 = y1, y0 vol = data[y0:y1 + 1, x0:x1 + 1].sum() - f.write("%s\t%.3f\n"%(name, vol)) + f.write("%s\t%.3f\n" % (name, vol)) # close the output file f.close() diff --git a/examples/jbnmr_examples/s12-s15_relaxation_analysis/extract_traj.py b/examples/jbnmr_examples/s12-s15_relaxation_analysis/extract_traj.py index 0d837103..65110227 100644 --- a/examples/jbnmr_examples/s12-s15_relaxation_analysis/extract_traj.py +++ b/examples/jbnmr_examples/s12-s15_relaxation_analysis/extract_traj.py @@ -2,8 +2,8 @@ import numpy as np # read the integration limits and list of spectra -peak_list = np.recfromtxt("boxes.in", names=True) -spectra_list = np.recfromtxt("spectra.in") +peak_list = np.genfromtxt("boxes.in", names=True) +spectra_list = np.genfromtxt("spectra.in") # create an array to hold the trajectories trajectories = np.empty((peak_list.size, spectra_list.size), dtype='float') diff --git a/examples/jbnmr_examples/s12-s15_relaxation_analysis/plot_boxes.py b/examples/jbnmr_examples/s12-s15_relaxation_analysis/plot_boxes.py index a364b938..939b79d5 100644 --- a/examples/jbnmr_examples/s12-s15_relaxation_analysis/plot_boxes.py +++ b/examples/jbnmr_examples/s12-s15_relaxation_analysis/plot_boxes.py @@ -12,8 +12,8 @@ cl = 30000 * 1.20 ** np.arange(20) # read in the box limits and list of spectra -peak_list = np.recfromtxt("boxes.in", names=True) -spectra_list = np.recfromtxt("spectra.in") +peak_list = np.genfromtxt("boxes.in", names=True) +spectra_list = np.genfromtxt("spectra.in") # loop over the spectra for spec_number, spectra in enumerate(spectra_list): @@ -30,16 +30,16 @@ y0, y1 = y1, y0 # slice the data around the peak - slice = data[y0 - ypad:y1 + 1 + ypad, x0 - xpad:x1 + 1 + xpad] + slice_ = data[y0 - ypad:y1 + 1 + ypad, x0 - xpad:x1 + 1 + xpad] # create the figure fig = plt.figure() ax = fig.add_subplot(111) # plot the contours - print "Plotting:", peak, spec_number + print("Plotting:", peak, spec_number) extent = (x0 - xpad + 1, x1 + xpad - 1, y0 - ypad + 1, y1 + ypad - 1) - ax.contour(slice, cl, cmap=cmap, extent=extent) + ax.contour(slice_, cl, cmap=cmap, extent=extent) # draw a box around the peak ax.plot([x0, x1, x1, x0, x0], [y0, y0, y1, y1, y0], 'k--') @@ -51,6 +51,6 @@ [y0 + 1, y0 + 1, y1 - 1, y1 - 1, y0 + 1], 'k--', alpha=0.35) # set the title, save the figure - ax.set_title('Peak: %s Spectrum: %i'%(peak, spec_number)) - fig.savefig('peak_%s_spectrum_%i'%(peak, spec_number)) - del(fig) + ax.set_title('Peak: %s Spectrum: %i' % (peak, spec_number)) + fig.savefig('peak_%s_spectrum_%i' % (peak, spec_number)) + del fig diff --git a/examples/jbnmr_examples/s12-s15_relaxation_analysis/plot_trajectories.py b/examples/jbnmr_examples/s12-s15_relaxation_analysis/plot_trajectories.py index 7137c964..d67d2dc7 100644 --- a/examples/jbnmr_examples/s12-s15_relaxation_analysis/plot_trajectories.py +++ b/examples/jbnmr_examples/s12-s15_relaxation_analysis/plot_trajectories.py @@ -2,18 +2,21 @@ import matplotlib.pyplot as plt # exponential function used to fit the data -def fit_func(p,x): + + +def fit_func(p, x): A, R2 = p return A * np.exp(-1.0 * np.array(x) * R2 / 1.0e6) -fitting_results = np.recfromtxt('fits.txt') + +fitting_results = np.genfromtxt('fits.txt') experimental_relaxation_times = np.loadtxt("relaxation_times.in") -simulated_relaxation_times = np.linspace(0,4000000,2000) +simulated_relaxation_times = np.linspace(0, 4000000, 2000) # loop over the fitting results for peak, A, R2, ier in fitting_results: - print "Plotting:", peak + print("Plotting:", peak) # load the experimental and simulated relaxation trajectories experimental_trajectory = np.loadtxt(peak + '.dat') diff --git a/examples/plotting/plot_2d/plot_assignments.py b/examples/plotting/plot_2d/plot_assignments.py index 8165258c..9abf5ffa 100755 --- a/examples/plotting/plot_2d/plot_assignments.py +++ b/examples/plotting/plot_2d/plot_assignments.py @@ -20,7 +20,7 @@ dic, data = ng.pipe.read("nmrpipe_2d/test.ft2") # read in the integration limits -peak_list = np.recfromtxt("limits.in") +peak_list = np.genfromtxt("limits.in") # create the figure fig = plt.figure() @@ -28,7 +28,7 @@ # plot the contours ax.contour(data, cl, cmap=cmap, - extent=(0, data.shape[1] - 1, 0, data.shape[0] - 1)) + extent=(0, data.shape[1] - 1, 0, data.shape[0] - 1)) # loop over the peaks for name, x0, y0, x1, y1 in peak_list: diff --git a/examples/plotting/plot_2d/plot_boxes.py b/examples/plotting/plot_2d/plot_boxes.py index 7c30606e..ebd4e6bf 100755 --- a/examples/plotting/plot_2d/plot_boxes.py +++ b/examples/plotting/plot_2d/plot_boxes.py @@ -21,7 +21,7 @@ dic, data = ng.pipe.read("nmrpipe_2d/test.ft2") # read in the integration limits -peak_list = np.recfromtxt("limits.in") +peak_list = np.genfromtxt("limits.in") # loop over the peaks for name, x0, y0, x1, y1 in peak_list: @@ -32,16 +32,16 @@ y0, y1 = y1, y0 # slice the data around the peak - slice = data[y0 - ypad:y1 + 1 + ypad, x0 - xpad:x1 + 1 + xpad] + slice_ = data[y0 - ypad:y1 + 1 + ypad, x0 - xpad:x1 + 1 + xpad] # create the figure fig = plt.figure() ax = fig.add_subplot(111) # plot the contours - print "Plotting:", name + print("Plotting:", name) etup = (x0 - xpad + 1, x1 + xpad - 1, y0 - ypad + 1, y1 + ypad - 1) - ax.contour(slice, cl, cmap=cmap, extent=etup) + ax.contour(slice_, cl, cmap=cmap, extent=etup) # draw a box around the peak ax.plot([x0, x1, x1, x0, x0], [y0, y0, y1, y1, y0], 'k--') @@ -50,11 +50,11 @@ ax.plot([x0 - 1, x1 + 1, x1 + 1, x0 - 1, x0 - 1], [y0 - 1, y0 - 1, y1 + 1, y1 + 1, y0 - 1], 'k--', alpha=0.35) ax.plot([x0 + 1, x1 - 1, x1 - 1, x0 + 1, x0 + 1], - [y0 + 1, y0 + 1, y1 - 1, y1 - 1, y0 + 1], 'k--',alpha=0.35) + [y0 + 1, y0 + 1, y1 - 1, y1 - 1, y0 + 1], 'k--', alpha=0.35) # set the title ax.set_title(name) # save the figure fig.savefig(f"{name}.png") - del(fig) + del fig diff --git a/examples/simulation/simulate_ucsf/make_ucsf.py b/examples/simulation/simulate_ucsf/make_ucsf.py index bc7b5126..892b8954 100644 --- a/examples/simulation/simulate_ucsf/make_ucsf.py +++ b/examples/simulation/simulate_ucsf/make_ucsf.py @@ -32,7 +32,7 @@ data = np.empty((512, 1024), dtype='float32') # read in the peak list -peak_list = np.recfromtxt('peaks.txt', names=True) +peak_list = np.genfromtxt('peaks.txt', names=True) npeaks = len(peak_list) # convert the peak list from PPM to points diff --git a/nmrglue/fileio/pipe.py b/nmrglue/fileio/pipe.py index f4f8ef60..9964c2f8 100644 --- a/nmrglue/fileio/pipe.py +++ b/nmrglue/fileio/pipe.py @@ -81,7 +81,7 @@ def read_table(filename): # print(dtd['names'],dtd['formats']) s = [l.encode('utf-8') for l in dl] - rec = np.recfromtxt(s, dtype=dtd, comments='XXXXXXXXXXX') + rec = np.genfromtxt(s, dtype=dtd, comments='XXXXXXXXXXX') return cl, pformat, np.atleast_1d(rec) @@ -192,6 +192,7 @@ def make_uc(dic, data, dim=-1): # dictionary/data creation # ############################ + fd2dphase_dic = {"magnitude": 0, "tppi": 1, "states": 2, "image": 3} @@ -318,7 +319,7 @@ def create_dic(udic, datetimeobj=datetime.datetime.now()): if ((dic["FDF1QUADFLAG"] == dic["FDF2QUADFLAG"] == dic["FDF3QUADFLAG"]) and (dic["FDF1QUADFLAG"] == dic["FDF4QUADFLAG"] == 1)): - dic["FDQUADFLAG"] = 1.0 + dic["FDQUADFLAG"] = 1.0 return dic @@ -1111,7 +1112,7 @@ def write_slice_3D(filemask, dic, data, shape, slices): # file doesn't exist, create a empty one ndata = np.zeros((dy, dx), dtype=data.dtype) write_single(f, dic, data, False) - del(ndata) + del ndata # mmap the [new] file mdata = np.memmap(f, dtype='float32', offset=512 * 4, mode='r+') @@ -1132,11 +1133,11 @@ def write_slice_3D(filemask, dic, data, shape, slices): if data.dtype == 'complex64': idata[sy, sx] = data.imag[i] idata.flush() - del(idata) + del idata # clean up - del(rdata) - del(mdata) + del rdata + del mdata # iter3D tools (xyz2pipe and pipe2xyz replacements) # Notes for iter3D implementation @@ -1260,6 +1261,7 @@ class iter3D: ziter.write("ft/test%03d.ft3",XZplane,dic) """ + def __init__(self, filemask, in_lead="x", out_lead="DEFAULT"): """ Create a iter3D object @@ -1806,9 +1808,9 @@ def __init__(self, filemask, order=(0, 1, 2), fcheck=False): f3 = "FDF" + str(int(dic["FDDIMORDER3"])) quadrature_factor = [2, 1][int(dic[f3 + 'QUADFLAG'])] - #Checking whether "nmrPipe -fn EXT ..." has been applied to z-dim or not. - #If EXT has been applied, FDF*XN is not zero. - #If z-dim is in time-domain, data-size given by FDF*X1 and FDF*XN has to be doubled. + # Checking whether "nmrPipe -fn EXT ..." has been applied to z-dim or not. + # If EXT has been applied, FDF*XN is not zero. + # If z-dim is in time-domain, data-size given by FDF*X1 and FDF*XN has to be doubled. if dic[f3 + 'FTFLAG']: if int(dic[f3 + 'XN']) == 0: @@ -1900,6 +1902,7 @@ class pipestream_3d(fileiobase.data_nd): Ordering of axes against file. """ + def __init__(self, filename, order=(0, 1, 2)): """ Create and set up object @@ -1995,6 +1998,7 @@ class pipe_4d(fileiobase.data_nd): set exist. Raises a IOError if files are missing. Default is False. """ + def __init__(self, filemask, order=(0, 1, 2, 3), fcheck=False): """ Create and set up object, check that files exist if fcheck is True @@ -2195,6 +2199,7 @@ def __fgetitem__(self, slices): f.close() return out + # data, see fdata.h fdata_nums = { 'FDMAGIC': '0', diff --git a/nmrglue/fileio/table.py b/nmrglue/fileio/table.py index 16cb9ece..16c1726b 100644 --- a/nmrglue/fileio/table.py +++ b/nmrglue/fileio/table.py @@ -144,7 +144,7 @@ def read(filename): dtd['formats'] = comments.pop(dl[0])[9:].split() # return the data as a records array - return comments, np.atleast_1d(np.recfromtxt(filename, dtype=dtd)) + return comments, np.atleast_1d(np.genfromtxt(filename, dtype=dtd)) def write(filename, comments, rec, overwrite=False): diff --git a/nmrglue/fileio/tecmag.py b/nmrglue/fileio/tecmag.py index a5931e3a..beab90c4 100644 --- a/nmrglue/fileio/tecmag.py +++ b/nmrglue/fileio/tecmag.py @@ -24,8 +24,8 @@ TNTMAGIC_RE = re.compile(br"^TNT1\.\d\d\d$") -TNTMAGIC = np.dtype('a8') -TNTTLV = np.dtype([('tag', 'a4'), ('bool', ' Date: Wed, 13 Nov 2024 11:04:05 +0200 Subject: [PATCH 3/6] One more numpy 2.0 fix... --- nmrglue/fileio/tecmag.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nmrglue/fileio/tecmag.py b/nmrglue/fileio/tecmag.py index beab90c4..c22e2f1a 100644 --- a/nmrglue/fileio/tecmag.py +++ b/nmrglue/fileio/tecmag.py @@ -93,7 +93,7 @@ ('DF_DN', ' Date: Wed, 27 Nov 2024 10:03:30 +0200 Subject: [PATCH 4/6] ...and more NumPy 2.0 fixes --- nmrglue/fileio/tecmag.py | 2 +- nmrglue/process/proc_lp.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/nmrglue/fileio/tecmag.py b/nmrglue/fileio/tecmag.py index c22e2f1a..34d7a5ba 100644 --- a/nmrglue/fileio/tecmag.py +++ b/nmrglue/fileio/tecmag.py @@ -97,7 +97,7 @@ ('LatchLP', ' Date: Wed, 22 Jan 2025 14:43:37 +0200 Subject: [PATCH 5/6] Added dtype=None to np.genfromtxt calls --- examples/fitting_data/t1_measurements/extract_trajs.py | 4 ++-- examples/fitting_data/t1_measurements/fit_exp_leastsq.py | 2 +- examples/fitting_data/t1_measurements/pt.py | 2 +- examples/integration/integrate_1d/integrate_1d.py | 2 +- examples/integration/integrate_2d/integrate_2d.py | 2 +- .../s12-s15_relaxation_analysis/extract_traj.py | 4 ++-- .../jbnmr_examples/s12-s15_relaxation_analysis/plot_boxes.py | 4 ++-- .../s12-s15_relaxation_analysis/plot_trajectories.py | 2 +- examples/plotting/plot_2d/plot_assignments.py | 2 +- examples/plotting/plot_2d/plot_boxes.py | 2 +- examples/simulation/simulate_ucsf/make_ucsf.py | 2 +- 11 files changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/fitting_data/t1_measurements/extract_trajs.py b/examples/fitting_data/t1_measurements/extract_trajs.py index dbffd751..298e1872 100755 --- a/examples/fitting_data/t1_measurements/extract_trajs.py +++ b/examples/fitting_data/t1_measurements/extract_trajs.py @@ -5,8 +5,8 @@ import numpy as np # read in the integration limits and list of spectra -peak_list = np.genfromtxt("boxes.in", encoding="UTF-8") -spectra_list = np.genfromtxt("spectra.in", encoding="UTF-8") +peak_list = np.genfromtxt("boxes.in", dtype=None, encoding="UTF-8") +spectra_list = np.genfromtxt("spectra.in", dtype=None, encoding="UTF-8") # prepare the trajs records array num_spec = spectra_list.size diff --git a/examples/fitting_data/t1_measurements/fit_exp_leastsq.py b/examples/fitting_data/t1_measurements/fit_exp_leastsq.py index efeef81b..2bccc8c4 100755 --- a/examples/fitting_data/t1_measurements/fit_exp_leastsq.py +++ b/examples/fitting_data/t1_measurements/fit_exp_leastsq.py @@ -7,7 +7,7 @@ # read in the trajectories and times trajs = np.load("traj.npy") -t1 = np.genfromtxt("time.dat") +t1 = np.genfromtxt("time.dat", dtype=None) # fitting function and residual calculation diff --git a/examples/fitting_data/t1_measurements/pt.py b/examples/fitting_data/t1_measurements/pt.py index 3dec254c..96705870 100755 --- a/examples/fitting_data/t1_measurements/pt.py +++ b/examples/fitting_data/t1_measurements/pt.py @@ -24,7 +24,7 @@ def fit_func(p, x): # read in the trajectories, fitting results, and times fits = pickle.load(open("fits.pickle", "rb")) trajs = np.load("traj.npy") -times = np.genfromtxt("time.dat") +times = np.genfromtxt("time.dat", dtype=None) sim_times = np.linspace(times[0], times[-1], 2000) diff --git a/examples/integration/integrate_1d/integrate_1d.py b/examples/integration/integrate_1d/integrate_1d.py index c47bb239..5141b6d5 100755 --- a/examples/integration/integrate_1d/integrate_1d.py +++ b/examples/integration/integrate_1d/integrate_1d.py @@ -10,7 +10,7 @@ length = data.shape[0] # read in the integration limits -peak_list = np.genfromtxt("limits.in") +peak_list = np.genfromtxt("limits.in", dtype=None) # determine the ppm scale uc = ng.pipe.make_uc(dic, data) diff --git a/examples/integration/integrate_2d/integrate_2d.py b/examples/integration/integrate_2d/integrate_2d.py index 13f81a88..71af4bc8 100755 --- a/examples/integration/integrate_2d/integrate_2d.py +++ b/examples/integration/integrate_2d/integrate_2d.py @@ -8,7 +8,7 @@ dic, data = ng.pipe.read("nmrpipe_2d/test.ft2") # read in the integration limits -peak_list = np.genfromtxt("limits.in") +peak_list = np.genfromtxt("limits.in", dtype=None) # prepare the output file f = open("volumes.out", 'w') diff --git a/examples/jbnmr_examples/s12-s15_relaxation_analysis/extract_traj.py b/examples/jbnmr_examples/s12-s15_relaxation_analysis/extract_traj.py index 65110227..d3301bcb 100644 --- a/examples/jbnmr_examples/s12-s15_relaxation_analysis/extract_traj.py +++ b/examples/jbnmr_examples/s12-s15_relaxation_analysis/extract_traj.py @@ -2,8 +2,8 @@ import numpy as np # read the integration limits and list of spectra -peak_list = np.genfromtxt("boxes.in", names=True) -spectra_list = np.genfromtxt("spectra.in") +peak_list = np.genfromtxt("boxes.in", dtype=None, names=True) +spectra_list = np.genfromtxt("spectra.in", dtype=None) # create an array to hold the trajectories trajectories = np.empty((peak_list.size, spectra_list.size), dtype='float') diff --git a/examples/jbnmr_examples/s12-s15_relaxation_analysis/plot_boxes.py b/examples/jbnmr_examples/s12-s15_relaxation_analysis/plot_boxes.py index 939b79d5..4a923f96 100644 --- a/examples/jbnmr_examples/s12-s15_relaxation_analysis/plot_boxes.py +++ b/examples/jbnmr_examples/s12-s15_relaxation_analysis/plot_boxes.py @@ -12,8 +12,8 @@ cl = 30000 * 1.20 ** np.arange(20) # read in the box limits and list of spectra -peak_list = np.genfromtxt("boxes.in", names=True) -spectra_list = np.genfromtxt("spectra.in") +peak_list = np.genfromtxt("boxes.in", dtype=None, names=True) +spectra_list = np.genfromtxt("spectra.in", dtype=None) # loop over the spectra for spec_number, spectra in enumerate(spectra_list): diff --git a/examples/jbnmr_examples/s12-s15_relaxation_analysis/plot_trajectories.py b/examples/jbnmr_examples/s12-s15_relaxation_analysis/plot_trajectories.py index d67d2dc7..3aeef6c4 100644 --- a/examples/jbnmr_examples/s12-s15_relaxation_analysis/plot_trajectories.py +++ b/examples/jbnmr_examples/s12-s15_relaxation_analysis/plot_trajectories.py @@ -9,7 +9,7 @@ def fit_func(p, x): return A * np.exp(-1.0 * np.array(x) * R2 / 1.0e6) -fitting_results = np.genfromtxt('fits.txt') +fitting_results = np.genfromtxt('fits.txt', dtype=None) experimental_relaxation_times = np.loadtxt("relaxation_times.in") simulated_relaxation_times = np.linspace(0, 4000000, 2000) diff --git a/examples/plotting/plot_2d/plot_assignments.py b/examples/plotting/plot_2d/plot_assignments.py index 9abf5ffa..4f20a039 100755 --- a/examples/plotting/plot_2d/plot_assignments.py +++ b/examples/plotting/plot_2d/plot_assignments.py @@ -20,7 +20,7 @@ dic, data = ng.pipe.read("nmrpipe_2d/test.ft2") # read in the integration limits -peak_list = np.genfromtxt("limits.in") +peak_list = np.genfromtxt("limits.in", dtype=None) # create the figure fig = plt.figure() diff --git a/examples/plotting/plot_2d/plot_boxes.py b/examples/plotting/plot_2d/plot_boxes.py index ebd4e6bf..fa4da3da 100755 --- a/examples/plotting/plot_2d/plot_boxes.py +++ b/examples/plotting/plot_2d/plot_boxes.py @@ -21,7 +21,7 @@ dic, data = ng.pipe.read("nmrpipe_2d/test.ft2") # read in the integration limits -peak_list = np.genfromtxt("limits.in") +peak_list = np.genfromtxt("limits.in", dtype=None) # loop over the peaks for name, x0, y0, x1, y1 in peak_list: diff --git a/examples/simulation/simulate_ucsf/make_ucsf.py b/examples/simulation/simulate_ucsf/make_ucsf.py index 892b8954..a783ab40 100644 --- a/examples/simulation/simulate_ucsf/make_ucsf.py +++ b/examples/simulation/simulate_ucsf/make_ucsf.py @@ -32,7 +32,7 @@ data = np.empty((512, 1024), dtype='float32') # read in the peak list -peak_list = np.genfromtxt('peaks.txt', names=True) +peak_list = np.genfromtxt('peaks.txt', dtype=None, names=True) npeaks = len(peak_list) # convert the peak list from PPM to points From c47f249bf6fd4feefb4676a556dfbfba82acd288 Mon Sep 17 00:00:00 2001 From: Juuso Lehtivarjo Date: Mon, 14 Jul 2025 13:54:02 +0300 Subject: [PATCH 6/6] Fix new Numpy deprecation (binary mode of np.fromstring) --- nmrglue/fileio/nmrml.py | 2 +- nmrglue/fileio/tecmag.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/nmrglue/fileio/nmrml.py b/nmrglue/fileio/nmrml.py index 28dfb450..3956301f 100644 --- a/nmrglue/fileio/nmrml.py +++ b/nmrglue/fileio/nmrml.py @@ -76,6 +76,6 @@ def _get_nmrml_data(fid_dict, data_dtype): # convert to ndarray if data_dtype is None: data_dtype = BYTE_FORMAT_TO_DTYPE[byte_format] - data = np.fromstring(uncompressed_bytes, dtype=data_dtype) + data = np.frombuffer(uncompressed_bytes, dtype=data_dtype) return data diff --git a/nmrglue/fileio/tecmag.py b/nmrglue/fileio/tecmag.py index 34d7a5ba..d2d9b56c 100644 --- a/nmrglue/fileio/tecmag.py +++ b/nmrglue/fileio/tecmag.py @@ -253,7 +253,7 @@ def read(filename): with open(filename, 'rb') as tntfile: - tntmagic = np.fromstring(tntfile.read(TNTMAGIC.itemsize), + tntmagic = np.frombuffer(tntfile.read(TNTMAGIC.itemsize), TNTMAGIC, count=1)[0] if not TNTMAGIC_RE.match(tntmagic): @@ -263,21 +263,21 @@ def read(filename): # Read in the section headers tnthdrbytes = tntfile.read(TNTTLV.itemsize) - while (TNTTLV.itemsize == len(tnthdrbytes)): - tlv = np.fromstring(tnthdrbytes, TNTTLV)[0] + while TNTTLV.itemsize == len(tnthdrbytes): + tlv = np.frombuffer(tnthdrbytes, TNTTLV)[0] data_length = tlv['length'] hdrdict = {'offset': tntfile.tell(), 'length': data_length, 'bool': bool(tlv['bool'])} if data_length <= 4096: hdrdict['data'] = tntfile.read(data_length) - assert (len(hdrdict['data']) == data_length) + assert len(hdrdict['data']) == data_length else: tntfile.seek(data_length, os.SEEK_CUR) tnt_sections[tlv['tag'].decode()] = hdrdict tnthdrbytes = tntfile.read(TNTTLV.itemsize) - assert (tnt_sections['TMAG']['length'] == TNTTMAG.itemsize) + assert tnt_sections['TMAG']['length'] == TNTTMAG.itemsize tmag = np.fromstring(tnt_sections['TMAG']['data'], TNTTMAG, count=1)[0] assert (tnt_sections['DATA']['length'] == @@ -291,7 +291,7 @@ def read(filename): shape=tmag['actual_npts'].prod()) data = np.reshape(data, tmag['actual_npts'], order='F') - assert (tnt_sections['TMG2']['length'] == TNTTMG2.itemsize) + assert tnt_sections['TMG2']['length'] == TNTTMG2.itemsize tmg2 = np.fromstring(tnt_sections['TMG2']['data'], TNTTMG2, count=1)[0] dic = dict()