~gcg/+junk/trunk

« back to all changes in this revision

Viewing changes to gridmethod_1d/gm1d.py

  • Committer: gcg
  • Date: 2020-07-15 07:46:15 UTC
  • Revision ID: gcg-20200715074615-tr80szbt9xq5m2ae
Major Cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
class grid_method_1d():
17
17
    def __init__(self, X0, Y0, ROI, carrier_frequency=None):
18
18
        
19
 
        print "hurz"
20
 
        
21
19
        self.X0 = X0
22
20
        self.Y0 = Y0
23
21
        #print "ROI = ", ROI
25
23
        self.lambda0 = self.freq_from_fft()
26
24
        self.w0 = 2 * np.pi / self.lambda0
27
25
        self.treatBorder = True
28
 
        print "measured sample wavelength is: ", self.lambda0
 
26
        print("measured sample wavelength is: ", self.lambda0)
29
27
        self.phi0, self.border = self.compute_phases_LSA(Y0)
30
28
        
31
29
        
68
66
        shifts = [0, 2*np.pi, -2*np.pi]
69
67
        idx = np.argmax(scores)
70
68
        shift = shifts[idx]
71
 
        print "scores", scores - np.min(scores)
72
 
        print "adding %f to phase 1" % (shift)
 
69
        print( "scores", scores - np.min(scores))
 
70
        print( "adding %f to phase 1" % (shift))
73
71
        self.phi1 += shift
74
72
        
75
73
    def unwrap_by_constrained_displacement(self):
187
185
        # used Blackman window as the signal is non-periodic and do FFT
188
186
        black= np.blackman(len(s))
189
187
        Y = np.fft.fft(s*black)
190
 
        N = len(Y)/2+1
 
188
        N = len(Y)//2 + 1
191
189
        X = np.linspace(0, 0.5, N, endpoint=True)
192
190
    
193
191
        self.periods = 1.0/(X[1:])
203
201
    # generate reference 1d signal
204
202
    carrier_wavelength = 5
205
203
    w0 = 2.0 * np.pi / (carrier_wavelength)
206
 
    print "carrier_frequency is", w0
 
204
    print( "carrier_frequency is", w0)
207
205
    X0 = np.arange(1024)
208
206
    Y0 = 10*np.cos(X0 * w0)
209
207
    #Y0 = signal.square(X0 * w0)
219
217
    start = 256
220
218
    length = 512
221
219
    deformation = np.zeros(len(X0))
222
 
    for i in xrange(len(X0)):
 
220
    for i in range(len(X0)):
223
221
        deformation[i] = 0.0
224
222
        if start < i < start + length: 
225
223
            deformation[i] = (i - start) * 0.002
228
226
    from scipy.integrate import cumtrapz
229
227
    u_prescribed = cumtrapz(deformation, initial = 0.0)
230
228
    u_max = np.max(u_prescribed)
231
 
    print "maximum prescribed displacement is: ", u_max, np.argmax(u_prescribed)
 
229
    print("maximum prescribed displacement is: ", u_max, np.argmax(u_prescribed))
232
230
    X1 = X0 + u_prescribed
233
231
    f = interp1d(X1, Y0)
234
232
    Y1 = f(X0)