I am trying to reuse this old function generated by a former employee and the company I now work at and am receiving the error “TypeError: object of type <class ‘float’> cannot be safely interpreted as an integer.” I thought I could fix it quite easily with integer division // but that doesn’t seem to be fixing the issue.
JavaScript
x
35
35
1
def ricker(f, length, dt): # function for Ricker wavelet
2
t = np.linspace(-length / 2, (length-dt) / 2, length / dt)
3
y = (1. - 2.*(np.pi**2)*(f**2)*(t**2))*np.exp(-(np.pi**2)*(f**2)*(t**2))
4
return t, y
5
6
def synthy(rho,v,f,dt,v_scale,h_scale):
7
Z = rho*v
8
scaled_dt = v_scale * 1.0/v[:,0]
9
tdr = 2 * np.cumsum(scaled_dt)
10
t = np.arange(tdr.min(), tdr.max(), dt)
11
tw, w = ricker (f=f, length = 0.99*len(t)*dt, dt = dt)
12
13
Stemp = []
14
lengths = []
15
16
17
for i in range(rho.shape[1]):
18
scaled_dt = v_scale * 1.0/v[:,i]
19
tdr = 2 * np.cumsum(scaled_dt)
20
t = np.arange(tdr.min(), tdr.max(), dt)
21
Z_t = np.interp(x = t, xp = tdr, fp = Z[:,i])
22
RC_t = (Z_t[1:] - Z_t[:-1]) / (Z_t[1:] + Z_t[:-1])
23
synth = np.convolve(RC_t, w, mode='same')
24
Stemp.append(synth)
25
lengths.append(len(synth))
26
27
S = np.zeros((min(lengths),rho.shape[1]))
28
for i in range(rho.shape[1]):
29
S[:,i] = Stemp[i][:min(lengths)]
30
31
32
return S, fig, w, tw
33
34
S, fig, w, tw = synthy(rho,v,f=100,dt=0.0001,v_scale=v_scale,h_scale=h_scale)
35
Advertisement
Answer
numpy.linspace requires an integer for its third parameter:
JavaScript
1
2
1
t = np.linspace(-length / 2, (length-dt) / 2, int(length / dt))
2