From b5e93637c142037b9bd3a6b49b0a3ee57fa7c7bd Mon Sep 17 00:00:00 2001 From: Valentin Cassayre <62183417+ValentinCassayre@users.noreply.github.com> Date: Thu, 24 Apr 2025 14:52:27 +0200 Subject: [PATCH 1/2] number type fix division --- bowpy/util/base.py | 16 ++++++++-------- bowpy/util/fkutil.py | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/bowpy/util/base.py b/bowpy/util/base.py index a107fb3..a332f0e 100644 --- a/bowpy/util/base.py +++ b/bowpy/util/base.py @@ -531,15 +531,15 @@ def line_cut(array, shape): elif name in ["butterworth", "Butterworth", "taper", "Taper"] and isinstance( length, int ): - fil_lh = create_filter(name, array.shape[0] / 2, length, kwarg) + fil_lh = create_filter(name, array.shape[0] // 2, length, kwarg) elif name in ["taper", "Taper"] and isinstance(length, int): - fil_lh = create_filter(name, array.shape[0] / 2, length, kwarg) + fil_lh = create_filter(name, array.shape[0] // 2, length, kwarg) fil_rh = np.flipud(fil_lh)[::-1][0:][::-1] fil = np.zeros(2 * fil_lh.size) - fil[: fil.size / 2] = fil_lh - fil[fil.size / 2 :] = fil_rh + fil[: fil.size // 2] = fil_lh + fil[fil.size // 2 :] = fil_rh new_array = array.transpose() * fil new_array = new_array.transpose() @@ -582,16 +582,16 @@ def line_set_zero(array, shape): elif name in ["butterworth", "Butterworth", "taper", "Taper"] and isinstance( length, int ): - fil_lh = create_filter(name, array.shape[0] / 2, length, kwarg) + fil_lh = create_filter(name, array.shape[0] // 2, length, kwarg) elif name in ["taper", "Taper"] and isinstance(length, int): - fil_lh = create_filter(name, array.shape[0] / 2, length, kwarg) + fil_lh = create_filter(name, array.shape[0] // 2, length, kwarg) # fil_lh = -1. * fil_lh + 1. fil_rh = np.flipud(fil_lh)[::-1][1:][::-1] fil = np.zeros(2 * fil_lh.size) - fil[: fil.size / 2] = fil_lh - fil[fil.size / 2 + 1 :] = fil_rh + fil[: fil.size // 2] = fil_lh + fil[fil.size // 2 + 1 :] = fil_rh newfil = np.ones(fil.shape) newfil = newfil - fil diff --git a/bowpy/util/fkutil.py b/bowpy/util/fkutil.py index cc872ba..5ccee12 100644 --- a/bowpy/util/fkutil.py +++ b/bowpy/util/fkutil.py @@ -482,7 +482,7 @@ def makeMask(fkdata, slope, shape, rth=0.4, expl_cutoff=False): if cutoff < 1: cutoff = 1 - maskshape_tmp = create_filter(name, Mask.shape[0] / 2, cutoff, arg) + maskshape_tmp = create_filter(name, Mask.shape[0] // 2, cutoff, arg) maskshape_lh = ( np.tile(maskshape_tmp, Mask.shape[1]) .reshape(Mask.shape[1], maskshape_tmp.size) @@ -490,8 +490,8 @@ def makeMask(fkdata, slope, shape, rth=0.4, expl_cutoff=False): ) maskshape_rh = np.flipud(maskshape_lh) - maskshape[: maskshape.shape[0] / 2, :] = maskshape_lh - maskshape[maskshape.shape[0] / 2 :, :] = maskshape_rh + maskshape[: maskshape.shape[0] // 2, :] = maskshape_lh + maskshape[maskshape.shape[0] // 2 :, :] = maskshape_rh for m in prange: if m == 0.0: @@ -535,12 +535,12 @@ def makeMask(fkdata, slope, shape, rth=0.4, expl_cutoff=False): Wr[np.where(Wr > rth)] = 1.0 Wr[np.where(Wr < rth)] = 0.0 - Wlhs = np.roll(Wr[:, 0 : Wr.shape[1] / 2 - 1], shift=1, axis=0) - Wrhs = Wr[:, 1 : Wr.shape[1] / 2 + 1] + Wlhs = np.roll(Wr[:, 0 : Wr.shape[1] // 2 - 1], shift=1, axis=0) + Wrhs = Wr[:, 1 : Wr.shape[1] // 2 + 1] Wrhs = np.roll(np.flipud(np.fliplr(Wrhs)), shift=0, axis=0) - Wr[:, 0 : Wr.shape[1] / 2 - 1] = Wlhs - Wr[:, Wr.shape[1] / 2 :] = Wrhs + Wr[:, 0 : Wr.shape[1] // 2 - 1] = Wlhs + Wr[:, Wr.shape[1] // 2 :] = Wrhs return Wr @@ -1276,7 +1276,7 @@ def plotfk( np.log( abs( np.fft.fftshift( - data[:, : data.shape[1] / 2].transpose(), axes=1 + data[:, : data.shape[1] // 2].transpose(), axes=1 ) ) ) @@ -1289,7 +1289,7 @@ def plotfk( else: im = ax.imshow( np.flipud( - abs(np.fft.fftshift(data[:, : data.shape[1] / 2].transpose(), axes=1)) + abs(np.fft.fftshift(data[:, : data.shape[1] // 2].transpose(), axes=1)) ), aspect="auto", extent=(-0.5, 0.5, 0, 0.5), @@ -1637,7 +1637,7 @@ def slope_distribution( pmin = prange[0] pmax = prange[1] - N = abs(pmax - pmin) / pdelta + 1 + N = abs(pmax - pmin) // pdelta + 1 MD = np.zeros(N) srange = np.linspace(pmin, pmax, N) From 8aa68dc16cfd72bda5f4185f68d2a351a6a8617e Mon Sep 17 00:00:00 2001 From: Valentin Date: Fri, 25 Apr 2025 10:59:45 +0200 Subject: [PATCH 2/2] number type fix division --- bowpy/filter/fk.py | 17 ++++++++--------- bowpy/util/fkutil.py | 10 +++++----- bowpy/util/picker.py | 2 +- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/bowpy/filter/fk.py b/bowpy/filter/fk.py index 2270c55..556db27 100644 --- a/bowpy/filter/fk.py +++ b/bowpy/filter/fk.py @@ -299,7 +299,6 @@ def fk_filter( slopes, deltaslope, peakpick=None, - mindist=dist, smoothing=smoothpicks, interactive=slopepicking, ) @@ -908,7 +907,7 @@ def _fk_extract_polygon( """ # Shift 0|0 f-k to center, for easier handling dsfk = np.fft.fftshift(data.conj().transpose()) - dsfk_tmp = dsfk[0 : dsfk.shape[0] / 2] + dsfk_tmp = dsfk[0 : dsfk.shape[0] // 2] # Define polygon by user-input. # If eval_mean is true, select area where to calculate the mean value @@ -930,10 +929,10 @@ def _fk_extract_polygon( data_fk = np.zeros(dsfk.shape).astype("complex") # top half of domain. - data_fk[0 : dsfk.shape[0] / 2] = dsfk_tmp + data_fk[0 : dsfk.shape[0] // 2] = dsfk_tmp # Bottom half of domain, exploiting symmetry and shift properties. - data_fk[dsfk.shape[0] / 2 :] = np.roll( + data_fk[dsfk.shape[0] // 2 :] = np.roll( np.roll(np.flipud(np.fliplr(dsfk_tmp)), 1).transpose(), 1 ).transpose() @@ -960,7 +959,7 @@ def _fk_eliminate_polygon( """ # Shift 0|0 f-k to center, for easier handling dsfk = np.fft.fftshift(data.conj().transpose()) - dsfk_tmp = dsfk[0 : dsfk.shape[0] / 2] + dsfk_tmp = dsfk[0 : dsfk.shape[0] // 2] # Define polygon by user-input. # If eval_mean is true, select area where to calculate the mean value @@ -982,10 +981,10 @@ def _fk_eliminate_polygon( data_fk = np.zeros(dsfk.shape).astype("complex") # top half of domain. - data_fk[0 : dsfk.shape[0] / 2] = dsfk_tmp + data_fk[0 : dsfk.shape[0] // 2] = dsfk_tmp # Bottom half of domain, exploiting symmetry and shift properties. - data_fk[dsfk.shape[0] / 2 :] = np.roll( + data_fk[dsfk.shape[0] // 2 :] = np.roll( np.roll(np.flipud(np.fliplr(dsfk_tmp)), 1).transpose(), 1 ).transpose() @@ -1023,7 +1022,7 @@ def _fk_ls_filter_eliminate_phase_sp(ArrayData, y_dist=False, radius=None, maxk= type snes: int """ # Define freq Array - freq = np.zeros((len(ArrayData), len(ArrayData[0]) / 2 + 1)) + 1j + freq = np.zeros((len(ArrayData), len(ArrayData[0]) // 2 + 1)) + 1j for i in range(len(ArrayData)): freq_new = np.fft.rfftn(ArrayData[i]) @@ -1031,7 +1030,7 @@ def _fk_ls_filter_eliminate_phase_sp(ArrayData, y_dist=False, radius=None, maxk= # Define k Array freqT = freq.conj().transpose() - knum = np.zeros((len(freqT), len(freqT[0]) / 2 + 1)) + knum = np.zeros((len(freqT), len(freqT[0]) // 2 + 1)) # calc best range N = len(freqT[0]) diff --git a/bowpy/util/fkutil.py b/bowpy/util/fkutil.py index 5ccee12..f45cafc 100644 --- a/bowpy/util/fkutil.py +++ b/bowpy/util/fkutil.py @@ -468,9 +468,9 @@ def makeMask(fkdata, slope, shape, rth=0.4, expl_cutoff=False): pnorm = 1 / 2.0 * (float(M.shape[0] + 1) / float(2.0 * M.shape[1])) prange = slope * pnorm - Mask = np.zeros((M.shape[0], 2.0 * M.shape[1])) - maskshape = np.zeros((M.shape[0], 2.0 * M.shape[1])) - W = np.zeros((M.shape[0], 2.0 * M.shape[1])) + Mask = np.zeros((M.shape[0], 2 * M.shape[1])) + maskshape = np.zeros((M.shape[0], 2 * M.shape[1])) + W = np.zeros((M.shape[0], 2 * M.shape[1])) name = shape[0] arg = shape[1] @@ -511,7 +511,7 @@ def makeMask(fkdata, slope, shape, rth=0.4, expl_cutoff=False): Mask[:, f] = np.roll(Mask[:, f], int(f * m)) W += Mask - Mask = np.zeros((M.shape[0], 2.0 * M.shape[1])) + Mask = np.zeros((M.shape[0], 2 * M.shape[1])) # Convolving each frequency slice of the mask with a boxcar # of size L. Widens the the maskfunction along k-axis. @@ -1637,7 +1637,7 @@ def slope_distribution( pmin = prange[0] pmax = prange[1] - N = abs(pmax - pmin) // pdelta + 1 + N = int(abs(pmax - pmin) / pdelta + 1) MD = np.zeros(N) srange = np.linspace(pmin, pmax, N) diff --git a/bowpy/util/picker.py b/bowpy/util/picker.py index 08df6a6..6517dbd 100644 --- a/bowpy/util/picker.py +++ b/bowpy/util/picker.py @@ -230,7 +230,7 @@ def get_polygon( else: xs.append(xmin) - ys = np.linspace(ymin, ymax, no_of_vert / 2) + ys = np.linspace(ymin, ymax, no_of_vert // 2) ys = np.append(ys, ys[::-1]).tolist() poly = Polygon(list(zip(xs, ys)), animated=True, closed=False, fill=False)