forked from NoisyLeon/NoisePy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfield2d_earth.py
1704 lines (1634 loc) · 86.3 KB
/
field2d_earth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
A python module to perform data interpolation/computation on the surface of the Earth
:Dependencies:
pyproj and its dependencies
GMT 5.x.x (for interpolation on Earth surface)
numba
numexpr
:Copyright:
Author: Lili Feng
Graduate Research Assistant
CIEI, Department of Physics, University of Colorado Boulder
email: lili.feng@colorado.edu
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.mlab import griddata
import numpy.ma as ma
import scipy.ndimage.filters
from scipy.ndimage import convolve
import matplotlib
import multiprocessing
from functools import partial
import os
from subprocess import call
import obspy.geodetics
from mpl_toolkits.basemap import Basemap, shiftgrid, cm
from pyproj import Geod
import random
import copy
import colormaps
import pyasdf
import math
import numba
#--------------------------------------------------
# weight arrays for finite difference computation
#--------------------------------------------------
# first derivatives
lon_diff_weight_2 = np.array([[1., 0., -1.]])/2.
lat_diff_weight_2 = lon_diff_weight_2.T
lon_diff_weight_4 = np.array([[-1., 8., 0., -8., 1.]])/12.
lat_diff_weight_4 = lon_diff_weight_4.T
lon_diff_weight_6 = np.array([[1./60., -3./20., 3./4., 0., -3./4., 3./20., -1./60.]])
lat_diff_weight_6 = lon_diff_weight_6.T
# second derivatives
lon_diff2_weight_2 = np.array([[1., -2., 1.]])
lat_diff2_weight_2 = lon_diff2_weight_2.T
lon_diff2_weight_4 = np.array([[-1., 16., -30., 16., -1.]])/12.
lat_diff2_weight_4 = lon_diff2_weight_4.T
lon_diff2_weight_6 = np.array([[1./90., -3./20., 3./2., -49./18., 3./2., -3./20., 1./90.]])
lat_diff2_weight_6 = lon_diff2_weight_6.T
geodist = Geod(ellps='WGS84')
def discrete_cmap(N, base_cmap=None):
"""Create an N-bin discrete colormap from the specified input map"""
# Note that if base_cmap is a string or None, you can simply do
# return plt.cm.get_cmap(base_cmap, N)
# The following works for string, None, or a colormap instance:
base = plt.cm.get_cmap(base_cmap)
color_list = base(np.linspace(0, 1, N))
cmap_name = base.name + str(N)
return base.from_list(cmap_name, color_list, N)
def _write_txt(fname, outlon, outlat, outZ):
outArr = np.append(outlon, outlat)
outArr = np.append(outArr, outZ)
outArr = outArr.reshape((3,outZ.size))
outArr = outArr.T
np.savetxt(fname, outArr, fmt='%g')
return
def determine_interval(minlat=None, maxlat=None, dlon=0.2, dlat=0.2, verbose=True):
# if (medlat is None) and (minlat is None and maxlat is None):
# raise ValueError('medlat or minlat/maxlat need to be specified!')
# if minlat is not None and maxlat is not None:
medlat = (minlat + maxlat)/2.
dist_lon_max,az,baz = obspy.geodetics.gps2dist_azimuth(minlat, 0., minlat, dlon)
dist_lon_min,az,baz = obspy.geodetics.gps2dist_azimuth(maxlat, 0., maxlat, dlon)
dist_lon_med,az,baz = obspy.geodetics.gps2dist_azimuth(medlat, 0., medlat, dlon)
dist_lat, az, baz = obspy.geodetics.gps2dist_azimuth(medlat, 0., medlat+dlat, 0.)
ratio_min = dist_lat / dist_lon_max
ratio_max = dist_lat / dist_lon_min
index = np.floor(np.log2((ratio_min+ratio_max)/2.))
final_ratio = 2**index
if verbose:
print 'ratio_min =',ratio_min,',ratio_max =',ratio_max,',final_ratio =',final_ratio
return final_ratio
class Field2d(object):
"""
An object to analyze 2D spherical field data on Earth
===============================================================================================
::: parameters :::
dlon, dlat - grid interval
Nlon, Nlat - grid number in longitude, latitude
lon, lat - 1D arrays for grid locations
lonArr, latArr - 2D arrays for grid locations
minlon/maxlon - minimum/maximum longitude
minlat/maxlat - minimum/maximum latitude
dlon_km/dlat_km - 1D arrays for grid interval in km
dlon_kmArr/dlon_kmArr - 2D arrays for grid interval in km
period - period
evid - id for the event
fieldtype - field type (Tph, Tgr, Amp)
Zarr - 2D data array (shape: Nlat, Nlon)
evlo/evla - longitude/latitue of the event
nlon_grad/nlat_grad - number of grids for cutting in gradient array
nlon_lplc/nlat_lplc - number of grids for cutting in Laplacian array
-----------------------------------------------------------------------------------------------
::: derived parameters :::
--- gradient related, shape: Nlat-2*nlat_grad, Nlon-2*nlon_grad
grad[0]/grad[1] - gradient arrays
proAngle - propagation angle arrays
appV - apparent velocity
reason_n - index array indicating validity of data
az/baz - azimuth/back-azimuth array
diffaArr - differences between propagation angle and azimuth
indicating off-great-circle deflection
--- Laplacian related, shape: Nlat-2*nlat_lplc, Nlon-2*nlon_lplc
lplc - Laplacian array
reason_n - index array indicating validity of data
--- others
mask - mask array, shape: Nlat, Nlon
mask_helm - mask for Helmholtz tomography, shape: Nlat, Nlon
lplc_amp - amplitude correction terms for phase speed
shape: Nlat-2*nlat_lplc, Nlon-2*nlon_lplc
corV - corrected velocity, shape: Nlat-2*nlat_lplc, Nlon-2*nlon_lplc
Nvalid_grd/Ntotal_grd - number of valid/total grid points, validity means reason_n == 0.
-----------------------------------------------------------------------------------------------
Note: meshgrid's default indexing is 'xy', which means:
lons, lats = np.meshgrid[lon, lat]
in lons[i, j] or lats[i, j], i->lat, j->lon
===============================================================================================
"""
def __init__(self, minlon, maxlon, dlon, minlat, maxlat, dlat, period=10., evlo=float('inf'), evla=float('inf'), fieldtype='Tph',\
evid='', nlat_grad=1, nlon_grad=1, nlat_lplc=2, nlon_lplc=2):
self.dlon = dlon
self.dlat = dlat
self.Nlon = int(round((maxlon-minlon)/dlon)+1)
self.Nlat = int(round((maxlat-minlat)/dlat)+1)
self.lon = np.arange(self.Nlon)*self.dlon+minlon
self.lat = np.arange(self.Nlat)*self.dlat+minlat
self.lonArr, self.latArr= np.meshgrid(self.lon, self.lat)
self.minlon = minlon
self.maxlon = self.lon.max()
self.minlat = minlat
self.maxlat = self.lat.max()
self._get_dlon_dlat_km()
self.period = period
self.evid = evid
self.fieldtype = fieldtype
self.Zarr = np.zeros((self.Nlat, self.Nlon), dtype=np.float64)
self.evlo = evlo
self.evla = evla
#-----------------------------------------------------------
# parameters indicate edge cutting for gradient/lplc arrays
#-----------------------------------------------------------
self.nlon_grad = nlon_grad
self.nlat_grad = nlat_grad
self.nlon_lplc = nlon_lplc
self.nlat_lplc = nlat_lplc
return
def copy(self):
return copy.deepcopy(self)
def _get_dlon_dlat_km_slow(self):
"""Get longitude and latitude interval in km
"""
self.dlon_km = np.array([])
self.dlat_km = np.array([])
for lat in self.lat:
dist_lon, az, baz = obspy.geodetics.gps2dist_azimuth(lat, 0., lat, self.dlon)
dist_lat, az, baz = obspy.geodetics.gps2dist_azimuth(lat, 0., lat+self.dlat, 0.)
self.dlon_km = np.append(self.dlon_km, dist_lon/1000.)
self.dlat_km = np.append(self.dlat_km, dist_lat/1000.)
self.dlon_kmArr = (np.tile(self.dlon_km, self.Nlon).reshape(self.Nlon, self.Nlat)).T
self.dlat_kmArr = (np.tile(self.dlat_km, self.Nlon).reshape(self.Nlon, self.Nlat)).T
return
def _get_dlon_dlat_km(self):
"""Get longitude and latitude interval in km
"""
az, baz, dist_lon = geodist.inv(np.zeros(self.lat.size), self.lat, np.ones(self.lat.size)*self.dlon, self.lat)
az, baz, dist_lat = geodist.inv(np.zeros(self.lat.size), self.lat, np.zeros(self.lat.size), self.lat+self.dlat)
self.dlon_km = dist_lon/1000.
self.dlat_km = dist_lat/1000.
self.dlon_kmArr = (np.tile(self.dlon_km, self.Nlon).reshape(self.Nlon, self.Nlat)).T
self.dlat_kmArr = (np.tile(self.dlat_km, self.Nlon).reshape(self.Nlon, self.Nlat)).T
return
#--------------------------------------------------
# functions for I/O
#--------------------------------------------------
def read(self, fname):
"""read field file
"""
try:
Inarray = np.loadtxt(fname)
with open(fname) as f:
inline = f.readline()
if inline.split()[0] =='#':
evlostr = inline.split()[1]
evlastr = inline.split()[2]
if evlostr.split('=')[0] =='evlo':
self.evlo = float(evlostr.split('=')[1])
if evlastr.split('=')[0] =='evla':
self.evla = float(evlastr.split('=')[1])
except:
Inarray = np.load(fname)
self.lonArrIn = Inarray[:,0]
self.latArrIn = Inarray[:,1]
self.ZarrIn = Inarray[:,2]
return
def read_HD(self, fname):
"""
"""
Inarray = np.loadtxt(fname)
data = Inarray[:, 2].reshape((self.lonArr.shape[1]-2*self.nlon_grad, self.lonArr.shape[0]-2*self.nlat_grad))
data = data.T
self.appV = data.copy()
self.mask = np.zeros(self.lonArr.shape, dtype=bool)
mask = data == 0.
self.mask[self.nlat_grad:-self.nlat_grad, self.nlon_grad:-self.nlon_grad] \
= mask.copy()
self.appV[np.logical_not(mask)] \
= 1./self.appV[np.logical_not(mask)]
return
def synthetic_field(self, lat0, lon0, v=3.0):
"""generate synthetic field data
"""
az, baz, distevent = geodist.inv( np.ones(self.lonArrIn.size)*lon0, np.ones(self.lonArrIn.size)*lat0, self.lonArrIn, self.latArrIn)
self.ZarrIn = distevent/v/1000.
return
def read_ind(self, fname, zindex=2, dindex=None):
"""read field file
"""
try:
Inarray = np.loadtxt(fname)
with open(fname) as f:
inline = f.readline()
if inline.split()[0] =='#':
evlostr = inline.split()[1]
evlastr = inline.split()[2]
if evlostr.split('=')[0] =='evlo':
self.evlo = float(evlostr.split('=')[1])
if evlastr.split('=')[0] =='evla':
self.evla = float(evlastr.split('=')[1])
except:
Inarray = np.load(fname)
self.lonArrIn = Inarray[:,0]
self.latArrIn = Inarray[:,1]
self.ZarrIn = Inarray[:,zindex]*1e9
if dindex is not None:
darrIn = Inarray[:,dindex]
self.ZarrIn = darrIn/Inarray[:,zindex]
return
def read_array(self, lonArr, latArr, ZarrIn):
"""read field file
"""
self.lonArrIn = lonArr
self.latArrIn = latArr
self.ZarrIn = ZarrIn
return
def load_field(self, inField):
"""Load field data from an input object
"""
self.lonArrIn = inField.lonArr
self.latArrIn = inField.latArr
self.ZarrIn = inField.Zarr
return
def write(self, fname, fmt='npy'):
"""Save field file
"""
OutArr = np.append(self.lonArr, self.latArr)
OutArr = np.append(OutArr, self.Zarr)
OutArr = OutArr.reshape(3, self.Nlon*self.Nlat)
OutArr = OutArr.T
if fmt is 'npy':
np.save(fname, OutArr)
elif fmt is 'txt':
np.savetxt(fname, OutArr)
else:
raise TypeError('Wrong output format!')
return
def write_binary(self, outfname, amplplc=False):
"""write data arrays to a binary npy file
"""
if amplplc:
np.savez( outfname, self.appV, self.reason_n, self.proAngle, self.az, self.baz, self.Zarr,\
self.lplc_amp, self.corV, self.reason_n_helm, np.array([self.Ntotal_grd, self.Nvalid_grd]))
else:
np.savez( outfname, self.appV, self.reason_n, self.proAngle, self.az, self.baz, self.Zarr,\
np.array([self.Ntotal_grd, self.Nvalid_grd]))
return
def np2ma(self):
"""Convert all the data array to masked array according to reason_n array.
"""
try:
reason_n = self.reason_n
except:
raise AttrictError('No reason_n array!')
self.Zarr = ma.masked_array(self.Zarr, mask=np.zeros(reason_n.shape) )
self.Zarr.mask[reason_n!=0] = 1
try:
self.diffaArr = ma.masked_array(self.diffaArr, mask=np.zeros(reason_n.shape) )
self.diffaArr.mask[reason_n!=0] = 1
except:
pass
try:
self.appV = ma.masked_array(self.appV, mask=np.zeros(reason_n.shape) )
self.appV.mask[reason_n!=0] = 1
except:
pass
try:
self.grad[0] = ma.masked_array(self.grad[0], mask=np.zeros(reason_n.shape) )
self.grad[0].mask[reason_n!=0] = 1
self.grad[1] = ma.masked_array(self.grad[1], mask=np.zeros(reason_n.shape) )
self.grad[1].mask[reason_n!=0] = 1
except:
pass
try:
self.lplc = ma.masked_array(self.lplc, mask=np.zeros(reason_n.shape) )
self.lplc.mask[reason_n!=0] = 1
except:
print 'No Laplacian array!'
pass
return
def ma2np(self):
"""Convert all the maksed data array to numpy array
"""
self.Zarr = ma.getdata(self.Zarr)
try:
self.diffaArr = ma.getdata(self.diffaArr)
except:
pass
try:
self.appV = ma.getdata(self.appV)
except:
pass
try:
self.lplc = ma.getdata(self.lplc)
except:
pass
return
def add_noise(self, sigma=0.5):
"""Add Gaussian noise with standard deviation = sigma to the input data
used for synthetic test
"""
for i in xrange(self.ZarrIn.size):
self.ZarrIn[i] = self.ZarrIn[i] + random.gauss(0, sigma)
return
def cut_edge(self, nlon, nlat):
"""Cut edge
=======================================================================================
::: input parameters :::
nlon, nlon - number of edge point in longitude/latitude to be cutted
=======================================================================================
"""
self.Nlon = self.Nlon-2*nlon
self.Nlat = self.Nlat-2*nlat
self.minlon = self.minlon + nlon*self.dlon
self.maxlon = self.maxlon - nlon*self.dlon
self.minlat = self.minlat + nlat*self.dlat
self.maxlat = self.maxlat - nlat*self.dlat
self.lon = np.arange(self.Nlon)*self.dlon+self.minlon
self.lat = np.arange(self.Nlat)*self.dlat+self.minlat
self.lonArr,self.latArr = np.meshgrid(self.lon, self.lat)
self.Zarr = self.Zarr[nlat:-nlat, nlon:-nlon]
try:
self.reason_n = self.reason_n[nlat:-nlat, nlon:-nlon]
except:
pass
self._get_dlon_dlat_km()
return
#--------------------------------------------------
# functions for interpolation/gradient/Laplacian
#--------------------------------------------------
def interp_surface(self, workingdir, outfname, tension=0.0):
"""interpolate input data to grid point with gmt surface command
=======================================================================================
::: input parameters :::
workingdir - working directory
outfname - output file name for interpolation
tension - input tension for gmt surface(0.0-1.0)
---------------------------------------------------------------------------------------
::: output :::
self.Zarr - interpolated field data
---------------------------------------------------------------------------------------
version history
- 2018/07/06 : added the capability of interpolation for dlon != dlat
=======================================================================================
"""
if not os.path.isdir(workingdir):
os.makedirs(workingdir)
OutArr = np.append(self.lonArrIn, self.latArrIn)
OutArr = np.append(OutArr, self.ZarrIn)
OutArr = OutArr.reshape(3, self.lonArrIn.size)
OutArr = OutArr.T
np.savetxt(workingdir+'/'+outfname, OutArr, fmt='%g')
fnameHD = workingdir+'/'+outfname+'.HD'
tempGMT = workingdir+'/'+outfname+'_GMT.sh'
grdfile = workingdir+'/'+outfname+'.grd'
with open(tempGMT,'wb') as f:
REG = '-R'+str(self.minlon)+'/'+str(self.maxlon)+'/'+str(self.minlat)+'/'+str(self.maxlat)
f.writelines('gmt gmtset MAP_FRAME_TYPE fancy \n')
if self.dlon == self.dlat:
f.writelines('gmt surface %s -T%g -G%s -I%g %s \n' %( workingdir+'/'+outfname, tension, grdfile, self.dlon, REG ))
else:
f.writelines('gmt surface %s -T%g -G%s -I%g/%g %s \n' %( workingdir+'/'+outfname, tension, grdfile, self.dlon, self.dlat, REG ))
f.writelines('gmt grd2xyz %s %s > %s \n' %( grdfile, REG, fnameHD ))
call(['bash', tempGMT])
os.remove(grdfile)
os.remove(tempGMT)
inArr = np.loadtxt(fnameHD)
ZarrIn = inArr[:, 2]
self.Zarr = (ZarrIn.reshape(self.Nlat, self.Nlon))[::-1, :]
return
def gauss_smoothing(self, workingdir, outfname, tension=0.0, width=50.):
"""perform a Gaussian smoothing
=======================================================================================
::: input parameters :::
workingdir - working directory
outfname - output file name for interpolation
tension - input tension for gmt surface(0.0-1.0)
width - Gaussian width in km
---------------------------------------------------------------------------------------
::: output :::
self.Zarr - smoothed field data
=======================================================================================
"""
if not os.path.isdir(workingdir):
os.makedirs(workingdir)
OutArr = np.append(self.lonArrIn, self.latArrIn)
OutArr = np.append(OutArr, self.ZarrIn)
OutArr = OutArr.reshape(3, self.lonArrIn.size)
OutArr = OutArr.T
np.savetxt(workingdir+'/'+outfname, OutArr, fmt='%g')
fnameHD = workingdir+'/'+outfname+'.HD'
tempGMT = workingdir+'/'+outfname+'_GMT.sh'
grdfile = workingdir+'/'+outfname+'.grd'
outgrd = workingdir+'/'+outfname+'_filtered.grd'
# http://gmt.soest.hawaii.edu/doc/5.3.2/grdfilter.html
# (g) Gaussian: Weights are given by the Gaussian function,
# where width is 6 times the conventional Gaussian sigma.
width = 6.*width
with open(tempGMT,'wb') as f:
REG = '-R'+str(self.minlon)+'/'+str(self.maxlon)+'/'+str(self.minlat)+'/'+str(self.maxlat)
f.writelines('gmt gmtset MAP_FRAME_TYPE fancy \n')
if self.dlon == self.dlat:
f.writelines('gmt surface %s -T%g -G%s -I%g %s \n' %( workingdir+'/'+outfname, tension, grdfile, self.dlon, REG ))
else:
f.writelines('gmt surface %s -T%g -G%s -I%g/%g %s \n' %( workingdir+'/'+outfname, tension, grdfile, self.dlon, self.dlat, REG ))
f.writelines('gmt grdfilter %s -D4 -Fg%g -G%s %s \n' %( grdfile, width, outgrd, REG))
f.writelines('gmt grd2xyz %s %s > %s \n' %( outgrd, REG, fnameHD ))
call(['bash', tempGMT])
os.remove(grdfile)
os.remove(outgrd)
os.remove(tempGMT)
inArr = np.loadtxt(fnameHD)
ZarrIn = inArr[:, 2]
self.Zarr = (ZarrIn.reshape(self.Nlat, self.Nlon))[::-1, :]
return
def gradient(self, method='diff', edge_order=1, order=2):
"""Compute gradient of the field
=============================================================================================
::: input parameters :::
edge_order - edge_order : {1, 2}, optional, only has effect when method='diff'
Gradient is calculated using Nth order accurate differences at the boundaries
method - method: 'diff' : use numpy.gradient; 'convolve': use convolution
order - order of finite difference scheme, only has effect when method='convolve'
::: note :::
gradient arrays are of shape Nlat-2*nlat_grad, Nlon-2*nlon_grad
=============================================================================================
"""
Zarr = self.Zarr
if method=='diff':
# self.dlat_kmArr : dx here in numpy gradient since Zarr is Z[ilat, ilon]
self.grad = np.gradient( self.Zarr, self.dlat_kmArr, self.dlon_kmArr, edge_order=edge_order)
self.grad[0]= self.grad[0][self.nlat_grad:-self.nlat_grad, self.nlon_grad:-self.nlon_grad]
self.grad[1]= self.grad[1][self.nlat_grad:-self.nlat_grad, self.nlon_grad:-self.nlon_grad]
elif method == 'convolve':
dlat_km = self.dlat_kmArr
dlon_km = self.dlon_kmArr
if order==2:
diff_lon= convolve(Zarr, lon_diff_weight_2)/dlon_km
diff_lat= convolve(Zarr, lat_diff_weight_2)/dlat_km
elif order==4:
diff_lon= convolve(Zarr, lon_diff_weight_4)/dlon_km
diff_lat= convolve(Zarr, lat_diff_weight_4)/dlat_km
elif order==6:
diff_lon= convolve(Zarr, lon_diff_weight_6)/dlon_km
diff_lat= convolve(Zarr, lat_diff_weight_6)/dlat_km
self.grad = []
self.grad.append(diff_lat[self.nlat_grad:-self.nlat_grad, self.nlon_grad:-self.nlon_grad])
self.grad.append(diff_lon[self.nlat_grad:-self.nlat_grad, self.nlon_grad:-self.nlon_grad])
# propagation direction angle
self.proAngle = np.arctan2(self.grad[0], self.grad[1])/np.pi*180.
return
def Laplacian(self, method='green', order=4, verbose=False):
"""Compute Laplacian of the field
=============================================================================================================
::: input parameters :::
method - method: 'diff' : use central finite difference scheme, similar to convolve with order =2
'convolve': use convolution
'green' : use Green's theorem( 2D Gauss's theorem )
order - order of finite difference scheme, only has effect when method='convolve'
::: note :::
Laplacian arrays are of shape Nlat-2*nlat_lplc, Nlon-2*nlon_lplc
=============================================================================================================
"""
Zarr = self.Zarr
if method == 'diff':
dlat_km = self.dlat_kmArr[1:-1, 1:-1]
dlon_km = self.dlon_kmArr[1:-1, 1:-1]
Zarr_latp = Zarr[2:, 1:-1]
Zarr_latn = Zarr[:-2, 1:-1]
Zarr_lonp = Zarr[1:-1, 2:]
Zarr_lonn = Zarr[1:-1, :-2]
Zarr = Zarr[1:-1, 1:-1]
lplc = (Zarr_latp+Zarr_latn-2*Zarr) / (dlat_km**2) + (Zarr_lonp+Zarr_lonn-2*Zarr) / (dlon_km**2)
dnlat = self.nlat_lplc - 1
dnlon = self.nlon_lplc - 1
if dnlat == 0 and dnlon == 0:
self.lplc = lplc
elif dnlat == 0 and dnlon != 0:
self.lplc = lplc[:, dnlon:-dnlon]
elif dnlat != 0 and dnlon == 0:
self.lplc = lplc[dnlat:-dnlat, :]
else:
self.lplc = lplc[dnlat:-dnlat, dnlon:-dnlon]
elif method == 'convolve':
dlat_km = self.dlat_kmArr
dlon_km = self.dlon_kmArr
if order==2:
diff2_lon = convolve(Zarr, lon_diff2_weight_2)/dlon_km/dlon_km
diff2_lat = convolve(Zarr, lat_diff2_weight_2)/dlat_km/dlat_km
elif order==4:
diff2_lon = convolve(Zarr, lon_diff2_weight_4)/dlon_km/dlon_km
diff2_lat = convolve(Zarr, lat_diff2_weight_4)/dlat_km/dlat_km
elif order==6:
diff2_lon = convolve(Zarr, lon_diff2_weight_6)/dlon_km/dlon_km
diff2_lat = convolve(Zarr, lat_diff2_weight_6)/dlat_km/dlat_km
self.lplc = diff2_lon+diff2_lat
self.lplc = self.lplc[self.nlat_lplc:-self.nlat_lplc, self.nlon_lplc:-self.nlon_lplc]
elif method=='green':
#---------------
# gradient arrays
#---------------
try:
grad_y = self.grad[0]
grad_x = self.grad[1]
except:
self.gradient('diff')
grad_y = self.grad[0]
grad_x = self.grad[1]
grad_xp = grad_x[1:-1, 2:]
grad_xn = grad_x[1:-1, :-2]
grad_yp = grad_y[2:, 1:-1]
grad_yn = grad_y[:-2, 1:-1]
dlat_km = self.dlat_kmArr[self.nlat_grad+1:-self.nlat_grad-1, self.nlon_grad+1:-self.nlon_grad-1]
dlon_km = self.dlon_kmArr[self.nlat_grad+1:-self.nlat_grad-1, self.nlon_grad+1:-self.nlon_grad-1]
#------------------
# Green's theorem
#------------------
loopsum = (grad_xp - grad_xn)*dlat_km + (grad_yp - grad_yn)*dlon_km
area = dlat_km*dlon_km
lplc = loopsum/area
#-----------------------------------------------
# cut edges according to nlat_lplc, nlon_lplc
#-----------------------------------------------
dnlat = self.nlat_lplc - self.nlat_grad - 1
if dnlat < 0:
self.nlat_lplc = self.nlat_grad + 1
dnlon = self.nlon_lplc - self.nlon_grad - 1
if dnlon < 0:
self.nlon_lplc = self.nlon_grad + 1
if dnlat == 0 and dnlon == 0:
self.lplc = lplc
elif dnlat == 0 and dnlon != 0:
self.lplc = lplc[:, dnlon:-dnlon]
elif dnlat != 0 and dnlon == 0:
self.lplc = lplc[dnlat:-dnlat, :]
else:
self.lplc = lplc[dnlat:-dnlat, dnlon:-dnlon]
if verbose:
print 'max lplc:',self.lplc.max(), 'min lplc:',self.lplc.min()
return
def get_appV(self):
"""Get the apparent velocity from gradient
"""
slowness = np.sqrt ( self.grad[0] ** 2 + self.grad[1] ** 2)
slowness[slowness==0] = 0.3
self.appV = 1./slowness
return
#--------------------------------------------------
# functions for data quality controls
#--------------------------------------------------
def check_curvature(self, workingdir, outpfx='', threshold=0.005):
"""
Check and discard data points with large curvatures.
Points at boundaries will be discarded.
Two interpolation schemes with different tension (0, 0.2) will be applied to the quality controlled field data file.
=====================================================================================================================
::: input parameters :::
workingdir - working directory
outpfx - prefix for output files
threshold - threshold value for Laplacian, default - 0.005, the value is suggested in Lin et al.(2009)
---------------------------------------------------------------------------------------------------------------------
::: output :::
workingdir/outpfx+fieldtype_per_v1.lst - output field file with data point passing curvature checking
workingdir/outpfx+fieldtype_per_v1.lst.HD - interpolated travel time file
workingdir/outpfx+fieldtype_per_v1.lst.HD_0.2 - interpolated travel time file with tension=0.2
---------------------------------------------------------------------------------------------------------------------
version history
- 07/06/2018 : added the capability of dealing with dlon != dlat
=====================================================================================================================
"""
# Compute Laplacian
self.Laplacian(method='green')
tfield = self.copy()
tfield.cut_edge(nlon=self.nlon_lplc, nlat=self.nlat_lplc)
#--------------------
# quality control
#--------------------
LonLst = tfield.lonArr.reshape(tfield.lonArr.size)
LatLst = tfield.latArr.reshape(tfield.latArr.size)
TLst = tfield.Zarr.reshape(tfield.Zarr.size)
lplc = self.lplc.reshape(self.lplc.size)
index = np.where((lplc>-threshold)*(lplc<threshold))[0]
# 09/24/2018, if no data
if index.size == 0:
return False
LonLst = LonLst[index]
LatLst = LatLst[index]
TLst = TLst[index]
# output to txt file
outfname = workingdir+'/'+outpfx+self.fieldtype+'_'+str(self.period)+'_v1.lst'
TfnameHD = outfname+'.HD'
_write_txt(fname=outfname, outlon=LonLst, outlat=LatLst, outZ=TLst)
# interpolate with gmt surface
tempGMT = workingdir+'/'+outpfx+self.fieldtype+'_'+str(self.period)+'_v1_GMT.sh'
grdfile = workingdir+'/'+outpfx+self.fieldtype+'_'+str(self.period)+'_v1.grd'
with open(tempGMT,'wb') as f:
REG = '-R'+str(self.minlon)+'/'+str(self.maxlon)+'/'+str(self.minlat)+'/'+str(self.maxlat)
f.writelines('gmt gmtset MAP_FRAME_TYPE fancy \n')
if self.dlon == self.dlat:
f.writelines('gmt surface %s -T0.0 -G%s -I%g %s \n' %( outfname, grdfile, self.dlon, REG ))
else:
f.writelines('gmt surface %s -T0.0 -G%s -I%g/%g %s \n' %( outfname, grdfile, self.dlon, self.dlat, REG ))
f.writelines('gmt grd2xyz %s %s > %s \n' %( grdfile, REG, TfnameHD ))
if self.dlon == self.dlat:
f.writelines('gmt surface %s -T0.2 -G%s -I%g %s \n' %( outfname, grdfile+'.T0.2', self.dlon, REG ))
else:
f.writelines('gmt surface %s -T0.2 -G%s -I%g/%g %s \n' %( outfname, grdfile+'.T0.2', self.dlon, self.dlat, REG ))
f.writelines('gmt grd2xyz %s %s > %s \n' %( grdfile+'.T0.2', REG, TfnameHD+'_0.2' ))
call(['bash', tempGMT])
os.remove(grdfile+'.T0.2')
os.remove(grdfile)
os.remove(tempGMT)
return True
def check_curvature_amp(self, workingdir, outpfx='', threshold=0.2):
"""
Check and discard data points with large curvatures, designed for amplitude field
Points at boundaries will be discarded.
Two interpolation schemes with different tension (0, 0.2) will be applied to the quality controlled field data file.
=====================================================================================================================
::: input parameters :::
workingdir - working directory
threshold - threshold value for Laplacian
---------------------------------------------------------------------------------------------------------------------
::: output :::
workingdir/outpfx+fieldtype_per_v1.lst - output field file with data point passing curvature checking
workingdir/outpfx+fieldtype_per_v1.lst.HD - interpolated travel time file
workingdir/outpfx+fieldtype_per_v1.lst.HD_0.2 - interpolated travel time file with tension=0.2
---------------------------------------------------------------------------------------------------------------------
version history
- 2018/07/06 : added the capability of dealing with dlon != dlat
=====================================================================================================================
"""
# Compute Laplacian
self.Laplacian(method='green')
tfield = self.copy()
tfield.cut_edge(nlon=self.nlon_lplc, nlat=self.nlat_lplc)
threshold = threshold*2./(3.**2)
#--------------------
# quality control
#--------------------
LonLst = tfield.lonArr.reshape(tfield.lonArr.size)
LatLst = tfield.latArr.reshape(tfield.latArr.size)
ampLst = tfield.Zarr.reshape(tfield.Zarr.size)
# # # lplc = self.lplc.reshape(self.lplc.size)
# # # lplc_corr = lplc.copy()
# # # lplc_corr = self.lplc.copy()
# # # lplc_corr[ampLst!=0.]\
# # # = lplc[ampLst!=0.]/ampLst[ampLst!=0.]
# # # lplc_corr[ampLst==0.]\
# # # = 0.
lplc_corr = self.lplc.copy()
#
if lplc_corr.shape != tfield.Zarr.shape:
raise ValueError('001: '+tfield.evid)
#
lplc_corr[tfield.Zarr==0.]\
= 0.
lplc_corr = lplc_corr.reshape(lplc_corr.size)
omega = 2.*np.pi/self.period
# original
# lplc_corr = lplc_corr/(omega**2)
# index = np.where((lplc_corr>-threshold)*(lplc_corr<threshold))[0]
# new
c0 = 4.
threshold = (ampLst*omega*omega/c0/c0)
index = np.where((lplc_corr>-threshold)*(lplc_corr<threshold))[0]
if index.size == 0:
return False
LonLst = LonLst[index]
LatLst = LatLst[index]
ampLst = ampLst[index]
# output to txt file
outfname = workingdir+'/'+outpfx+self.fieldtype+'_'+str(self.period)+'_v1.lst'
AfnameHD = outfname+'.HD'
_write_txt(fname=outfname, outlon=LonLst, outlat=LatLst, outZ=ampLst)
# interpolate with gmt surface
tempGMT = workingdir+'/'+outpfx+self.fieldtype+'_'+str(self.period)+'_v1_GMT.sh'
grdfile = workingdir+'/'+outpfx+self.fieldtype+'_'+str(self.period)+'_v1.grd'
with open(tempGMT,'wb') as f:
REG = '-R'+str(self.minlon)+'/'+str(self.maxlon)+'/'+str(self.minlat)+'/'+str(self.maxlat)
f.writelines('gmt gmtset MAP_FRAME_TYPE fancy \n')
if self.dlon == self.dlat:
f.writelines('gmt surface %s -T0.0 -G%s -I%g %s \n' %( outfname, grdfile, self.dlon, REG ))
else:
f.writelines('gmt surface %s -T0.0 -G%s -I%g/%g %s \n' %( outfname, grdfile, self.dlon, self.dlat, REG ))
f.writelines('gmt grd2xyz %s %s > %s \n' %( grdfile, REG, AfnameHD ))
if self.dlon == self.dlat:
f.writelines('gmt surface %s -T0.2 -G%s -I%g %s \n' %( outfname, grdfile+'.T0.2', self.dlon, REG ))
else:
f.writelines('gmt surface %s -T0.2 -G%s -I%g/%g %s \n' %( outfname, grdfile+'.T0.2', self.dlon, self.dlat, REG ))
f.writelines('gmt grd2xyz %s %s > %s \n' %( grdfile+'.T0.2', REG, AfnameHD+'_0.2' ))
call(['bash', tempGMT])
os.remove(grdfile+'.T0.2')
os.remove(grdfile)
os.remove(tempGMT)
return True
def eikonal_operator(self, workingdir, inpfx='', nearneighbor=True, cdist=150., lplcthresh=0.005, lplcnearneighbor=False):
"""
Generate slowness maps from travel time maps using eikonal equation
Two interpolated travel time file with different tension will be used for quality control.
=====================================================================================================================
::: input parameters :::
workingdir - working directory
inpfx - prefix for input files
nearneighbor - do near neighbor quality control or not
cdist - distance for quality control, default is 12*period
lplcthresh - threshold value for Laplacian
lplcnearneighbor- also discard near neighbor points for a grid point with large Laplacian
::: output format :::
outdir/slow_azi_stacode.pflag.txt.HD.2.v2 - Slowness map
=====================================================================================================================
"""
if cdist is None:
cdist = max(12.*self.period/3., 150.)
evlo = self.evlo
evla = self.evla
# Read data
# v1: data that passes check_curvature criterion
# v1HD and v1HD02: interpolated v1 data with tension = 0. and 0.2
fnamev1 = workingdir+'/'+inpfx+self.fieldtype+'_'+str(self.period)+'_v1.lst'
fnamev1HD = fnamev1+'.HD'
fnamev1HD02 = fnamev1HD+'_0.2'
InarrayV1 = np.loadtxt(fnamev1)
loninV1 = InarrayV1[:,0]
latinV1 = InarrayV1[:,1]
fieldin = InarrayV1[:,2]
Inv1HD = np.loadtxt(fnamev1HD)
lonv1HD = Inv1HD[:,0]
latv1HD = Inv1HD[:,1]
fieldv1HD = Inv1HD[:,2]
Inv1HD02 = np.loadtxt(fnamev1HD02)
lonv1HD02 = Inv1HD02[:,0]
latv1HD02 = Inv1HD02[:,1]
fieldv1HD02 = Inv1HD02[:,2]
# Set field value to be zero if there is large difference between v1HD and v1HD02
diffArr = fieldv1HD-fieldv1HD02
fieldArr = fieldv1HD*((diffArr<2.)*(diffArr>-2.))
fieldArr = (fieldArr.reshape(self.Nlat, self.Nlon))[::-1, :]
#-------------------------------------------------------------------------------------
# reason_n array
# 0: accepted point
# 1: data point the has large difference between v1HD and v1HD02
# 2: data point that does not have near neighbor points at all E/W/N/S directions
# 3: slowness is too large/small
# 4: near a zero field data point
# 5: epicentral distance is too small
# 6: large curvature
#-------------------------------------------------------------------------------------
reason_n = np.ones(fieldArr.size, dtype=np.int32)
reason_n1 = np.int32(reason_n*(diffArr>2.))
reason_n2 = np.int32(reason_n*(diffArr<-2.))
reason_n = reason_n1+reason_n2
reason_n = (reason_n.reshape(self.Nlat, self.Nlon))[::-1,:]
#-------------------------------------------------------------------------------------------------------
# check each data point if there are close-by four stations located at E/W/N/S directions respectively
#-------------------------------------------------------------------------------------------------------
if nearneighbor:
for ilat in range(self.Nlat):
for ilon in range(self.Nlon):
if reason_n[ilat, ilon]==1:
continue
lon = self.lon[ilon]
lat = self.lat[ilat]
dlon_km = self.dlon_km[ilat]
dlat_km = self.dlat_km[ilat]
difflon = abs(self.lonArrIn-lon)/self.dlon*dlon_km
difflat = abs(self.latArrIn-lat)/self.dlat*dlat_km
index = np.where((difflon<cdist)*(difflat<cdist))[0]
marker_EN = np.zeros((2,2), dtype=np.bool)
marker_nn = 4
tflag = False
for iv1 in index:
lon2 = self.lonArrIn[iv1]
lat2 = self.latArrIn[iv1]
if lon2-lon<0:
marker_E = 0
else:
marker_E = 1
if lat2-lat<0:
marker_N = 0
else:
marker_N = 1
if marker_EN[marker_E , marker_N]:
continue
az, baz, dist = geodist.inv(lon, lat, lon2, lat2) # loninArr/latinArr are initial points
dist = dist/1000.
if dist< cdist*2 and dist >= 1:
marker_nn = marker_nn-1
if marker_nn==0:
tflag = True
break
marker_EN[marker_E, marker_N] = True
if not tflag:
fieldArr[ilat, ilon] = 0
reason_n[ilat, ilon] = 2
# Start to Compute Gradient
tfield = self.copy()
tfield.Zarr = fieldArr
tfield.gradient('diff')
# if one field point has zero value, reason_n for four near neighbor points will all be set to 4
tempZarr = tfield.Zarr[self.nlat_grad:-self.nlat_grad, self.nlon_grad:-self.nlon_grad]
index0 = np.where(tempZarr==0.)
ilatArr = index0[0] + 1
ilonArr = index0[1] + 1
reason_n[ilatArr+1, ilonArr]= 4
reason_n[ilatArr-1, ilonArr]= 4
reason_n[ilatArr, ilonArr+1]= 4
reason_n[ilatArr, ilonArr-1]= 4
# reduce size of reason_n to be the same shape as gradient arrays
reason_n = reason_n[self.nlat_grad:-self.nlat_grad, self.nlon_grad:-self.nlon_grad]
# if slowness is too large/small, reason_n will be set to 3
slowness = np.sqrt(tfield.grad[0]**2 + tfield.grad[1]**2)
if self.fieldtype=='Tph' or self.fieldtype=='Tgr':
reason_n[(slowness>0.5)*(reason_n==0)] = 3
reason_n[(slowness<0.2)*(reason_n==0)] = 3
#-------------------------------------
# computing propagation deflection
#-------------------------------------
indexvalid = np.where(reason_n==0)
diffaArr = np.zeros(reason_n.shape, dtype = np.float64)
latinArr = self.lat[indexvalid[0] + self.nlat_grad]
loninArr = self.lon[indexvalid[1] + self.nlon_grad]
evloArr = np.ones(loninArr.size, dtype=np.float64)*evlo
evlaArr = np.ones(latinArr.size, dtype=np.float64)*evla
az, baz, distevent = geodist.inv(loninArr, latinArr, evloArr, evlaArr) # loninArr/latinArr are initial points
distevent = distevent/1000.
az = az + 180.
az = 90.-az
baz = 90.-baz
az[az>180.] = az[az>180.] - 360.
az[az<-180.] = az[az<-180.] + 360.
baz[baz>180.] = baz[baz>180.] - 360.
baz[baz<-180.] = baz[baz<-180.] + 360.
# az azimuth receiver -> source
diffaArr[indexvalid[0], indexvalid[1]] = tfield.proAngle[indexvalid[0], indexvalid[1]] - az
self.gradient('diff')
self.az = np.zeros(self.proAngle.shape, dtype=np.float64)
self.az[indexvalid[0], indexvalid[1]] = az
self.baz = np.zeros(self.proAngle.shape, dtype=np.float64)
self.baz[indexvalid[0], indexvalid[1]] = baz
# three wavelength criteria
# if epicentral distance is too small, reason_n will be set to 5, and diffaArr will be 0.
dist_per = 4.*self.period*3.
tempArr = diffaArr[indexvalid[0], indexvalid[1]]
tempArr[distevent<dist_per] = 0.
diffaArr[indexvalid[0], indexvalid[1]] = tempArr
diffaArr[diffaArr>180.] = diffaArr[diffaArr>180.]-360.
diffaArr[diffaArr<-180.] = diffaArr[diffaArr<-180.]+360.
tempArr = reason_n[indexvalid[0], indexvalid[1]]
tempArr[distevent<dist_per] = 5
reason_n[indexvalid[0], indexvalid[1]] = tempArr
#------------------------------------------------------------------------
# final check of curvature, discard grid points with large curvature
#------------------------------------------------------------------------
self.Laplacian(method='green')
dnlat = self.nlat_lplc - self.nlat_grad
dnlon = self.nlon_lplc - self.nlon_grad
tempind = (self.lplc > lplcthresh) + (self.lplc < -lplcthresh)
if dnlat == 0 and dnlon == 0:
reason_n[tempind] = 6
elif dnlat == 0 and dnlon != 0:
(reason_n[:, dnlon:-dnlon])[tempind]= 6
elif dnlat != 0 and dnlon == 0:
(reason_n[dnlat:-dnlat, :])[tempind]= 6
else:
(reason_n[dnlat:-dnlat, dnlon:-dnlon])[tempind]\
= 6
# near neighbor discard for large curvature
if lplcnearneighbor:
indexlplc = np.where(reason_n==6.)
ilatArr = indexlplc[0]
ilonArr = indexlplc[1]
reason_n_temp = np.zeros(self.lonArr.shape)
reason_n_temp[self.nlat_grad:-self.nlat_grad, self.nlon_grad:-self.nlon_grad] \
= reason_n.copy()
reason_n_temp[ilatArr+1, ilonArr] = 6
reason_n_temp[ilatArr-1, ilonArr] = 6
reason_n_temp[ilatArr, ilonArr+1] = 6
reason_n_temp[ilatArr, ilonArr-1] = 6
reason_n = reason_n_temp[self.nlat_grad:-self.nlat_grad, self.nlon_grad:-self.nlon_grad]
# store final data
self.diffaArr = diffaArr
self.grad = tfield.grad
self.get_appV()
###
# cgg on site
# # # reason_n[reason_n==2.] = 0.
# # # reason_n[reason_n==1.] = 0.
# # # reason_n[reason_n==3.] = 0.
###
self.reason_n = reason_n
self.mask = np.ones((self.Nlat, self.Nlon), dtype=np.bool)
tempmask = reason_n != 0
self.mask[self.nlat_grad:-self.nlat_grad, self.nlon_grad:-self.nlon_grad]\
= tempmask
# added 04/05/2018
self.Nvalid_grd = (np.where(reason_n==0.)[0]).size
self.Ntotal_grd = reason_n.size
return
def helmholtz_operator(self, workingdir, inpfx='', lplcthresh=0.2):
"""
Generate amplitude Laplacian maps for helmholtz tomography
Two interpolated amplitude file with different tension will be used for quality control.
=====================================================================================================================
::: input parameters :::
workingdir - working directory
inpfx - prefix for input files
lplcthresh - threshold value for Laplacian
=====================================================================================================================
"""
# Read data,
# v1: data that pass check_curvature criterion
# v1HD and v1HD02: interpolated v1 data with tension = 0. and 0.2
fnamev1 = workingdir+'/'+inpfx+self.fieldtype+'_'+str(self.period)+'_v1.lst'
fnamev1HD = fnamev1+'.HD'
fnamev1HD02 = fnamev1HD+'_0.2'
InarrayV1 = np.loadtxt(fnamev1)
loninV1 = InarrayV1[:,0]
latinV1 = InarrayV1[:,1]
fieldin = InarrayV1[:,2]
Inv1HD = np.loadtxt(fnamev1HD)
lonv1HD = Inv1HD[:,0]
latv1HD = Inv1HD[:,1]