-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ_Velest.py
1848 lines (1475 loc) · 75.3 KB
/
Q_Velest.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
import os
import sys
import time
import statistics
import shutil
import numpy as np
import subprocess as sp
from velest_rw import ids, ReadMod, ReadCNV, ReadSta, ReadVelestMain, ReadVelestOptmVel, \
ReadVelestVar, ReadVelestVel, CNV_EvtCount
from datetime import datetime as dt
from gmt_layout import color_cycle
from matplotlib import pyplot as plt
"""
===========================================
Velest processing routine by @eqhalauwet
==========================================
Python module for reading velest output, ploting and exporting to GMT input.
Written By, eQ Halauwet BMKG-PGR IX Ambon.
yehezkiel.halauwet@bmkg.go.id
Notes:
1. Read velest mainprint to see adjustmet hypocenter, velocity model, and RMS every iteration
Logs:
2017-Sep: Added _check_header line to automatic check data format from few Seiscomp3 version (see Notes).
2019-Oct: Major change: store readed data in dictionary format.
2020-May: Correction: select phase only without 'X' residual (unused phase on routine processing).
2020-Jul: Major change added Run_Velest() and Run_VelestSet() to run Velest recursively
2020-Jul: RunVelestSet() added recursive routine to adjust input velocity layer if velest is hang (solution not stable)
"""
def plot_model(vel_type='P'):
# vel_type = 'P'
my_dir = os.getcwd()
mod_dir = os.path.join('input', 'mod')
inpmod = []
mod_nm = []
for m in os.listdir(os.path.join(my_dir, mod_dir)):
if os.path.isfile(os.path.join(my_dir, mod_dir, m)):
inpmod.append(os.path.join(mod_dir, m))
mod_nm.append(m[:-4])
fig1, ax1 = plt.subplots()
for mod, md_nm in zip(inpmod, mod_nm):
plt.figure()
plt.ion()
plt.show()
md = ReadMod(mod)
x = md[vel_type]['vel']
y = [d * -1 for d in md['P']['dep']]
ax1.plot(x, y)
plt.plot(x, y)
plt.title(md_nm)
plt.draw()
plt.pause(0.001)
def velest2gmt(model_nm, init_pha, final_pha, main_out, itrmax, invratio, plot=False, gmtplot=False):
"""
output gmt plot file in batch. Only works on gmt for windows
:param model_nm: model root name for output
:param init_pha: initial phase.cnv data
:type init_pha: list
:param final_pha: final phase.cnv data
:type final_pha: list
:param main_out: mainprint data
:type main_out: list
:param plot: option to plot model (on python)
:param gmtplot: option to plot all gmt output
"""
# init_pha = ['input/phase.cnv', 'output/grad1_1/finalhypo01_grad1_1.cnv']
# final_pha = ['output/grad1_1/finalhypo01_grad1_1.cnv', 'output/grad1_1/finalhypo02_grad1_1.cnv']
# main_out = ['output/grad1_1/mainprint01_grad1_1.out', 'output/grad1_1/mainprint02_grad1_1.out']
# model_nm = 'grad1_1'
# Cumulative every set output
final_data = {}
velestdata = {}
init_data = {}
optimum_data = {}
if len(main_out) > 1:
flag_iset = True
else:
flag_iset = False
iset = 0
allitt = 0
max_vel = 0
min_vel = 5
# max_dvel = 0
# min_dvel = 5
max_hyp = 0
max_veladj = 0
min_veladj = 5
dep = []
sta_dly = []
itr_all = []
adj_ot_all = []
adj_lon_all = []
adj_lat_all = []
adj_dep_all = []
rms_all = []
ids = ''
station = 'input/station.dat'
outvel = 'gmt'
plot_result = 'plot_result'
bmkg_sta = ReadSta(station)
if not os.path.exists(outvel):
os.makedirs(outvel)
if not os.path.exists(plot_result):
os.makedirs(plot_result)
if len(main_out) == len(init_pha) and len(init_pha) == len(final_pha):
for i in range(len(main_out)):
iset = i + 1
if flag_iset:
outdir = outvel + '/Iteration_Set-' + str(iset)
if not os.path.exists(outdir):
os.makedirs(outdir)
ffinal = open(outdir + '/' + model_nm + '-CatalogFinal-iSet_' + str(iset) + '.dat', 'w')
fvar = open(outdir + '/Plot-' + model_nm + '.bat', 'w')
finit = open(outdir + '/' + model_nm + '-CatalogInitial-iSet_' + str(iset) + '.dat', 'w')
velestdata, init_data, final_data, optimum_data, next_set, ids = ReadVelestMain(main_out[i])
i_dat = ReadCNV(init_pha[i])
f_dat = ReadCNV(final_pha[i])
_catalog = ''
if iset == 1:
f_init = open(outvel + '/' + model_nm + '-CatalogInitial.dat', 'w')
f_final = open(outvel + '/' + model_nm + '-CatalogFinal.dat', 'w')
for evt in sorted(i_dat):
i_hyp = i_dat[evt]
_catalog = (f"{i_hyp['lon']:.4f} {i_hyp['lat']:.4f} {i_hyp['dep']:.2f} {i_hyp['mag']:.2f} "
f"{i_hyp['gap']} {i_hyp['rms']:.2f} "
f"{i_hyp['erlon']} {i_hyp['erlat']} {i_hyp['errv']} {i_hyp['nevt']}\n")
if flag_iset:
finit.write(_catalog)
if iset == 1:
f_init.write(_catalog)
for evt in sorted(f_dat):
f_hyp = f_dat[evt]
_catalog = (f"{f_hyp['lon']:.4f} {f_hyp['lat']:.4f} {f_hyp['dep']:.2f} {f_hyp['mag']:.2f} "
f"{f_hyp['gap']} {f_hyp['rms']} "
f"{f_hyp['erlon']} {f_hyp['erlat']} {f_hyp['errv']} {f_hyp['nevt']}\n")
f_final.write(_catalog)
if flag_iset:
ffinal.write(_catalog)
if flag_iset:
finit.close()
ffinal.close()
if iset == 1:
f_init.close()
f_final.close()
itr = []
adj_ot = []
adj_lon = []
adj_lat = []
adj_dep = []
rms = []
adj_vel = []
vel = []
dep = []
max_vel = 0
min_vel = 5
max_dvel = 0
min_dvel = 5
# output initial model and adjustment iteration 0
ini = init_data
if iset == 1:
vel_arr = ini['vel_mod']['vel']
dep_arr = ini['vel_mod']['dep']
else:
vel_arr, dep_arr = adjust_layer(ini['vel_mod']['vel'], ini['vel_mod']['dep'],
step=2, dev=0.05, plot=False, flag_v=False)
dep_arr = np.array(dep_arr)
vel_arr = np.array(vel_arr)
damp_arr = np.array(ini['vel_mod']['damp'])
model_adj = np.vstack((dep_arr, vel_arr, damp_arr)).T
result = np.asarray(model_adj)
if flag_iset:
np.savetxt(outdir + '/' + model_nm + '-ModelInitial-iSet_' + str(iset) +
'.dat', result, fmt='%.6f', delimiter=" ")
if iset == 1:
np.savetxt(outvel + '/' + model_nm + '-ModelInitial.dat', result, fmt='%.6f', delimiter=" ")
itr.append(0)
adj_ot.append(0)
adj_dep.append(0)
adj_lon.append(0)
adj_lat.append(0)
rms.append(ini['rms_res'])
if iset == 1:
itr_all.append(0)
adj_ot_all.append(0)
adj_dep_all.append(0)
adj_lon_all.append(0)
adj_lat_all.append(0)
rms_all.append(ini['rms_res'])
fin = final_data
hyp = fin['ray_stat']['nhyp']
if max(hyp) > max_hyp:
max_hyp = max(hyp)
sta_dly = fin['stn_stat']['delay']
hyp_arr = np.array(fin['ray_stat']['nhyp'])
sta_nm_arr = np.array(fin['stn_stat']['stn'])
sta_ph_arr = np.array(fin['stn_stat']['pha'])
sta_nobs_arr = np.array(fin['stn_stat']['nobs'])
sta_res_arr = np.array(fin['stn_stat']['avres'])
sta_dly_arr = np.array(fin['stn_stat']['delay'])
sta_lon = []
sta_lat = []
for st in sta_nm_arr:
try:
sta_lon.append(bmkg_sta[st]['lon'])
sta_lat.append(bmkg_sta[st]['lat'])
except KeyError:
print(f'Station {st} not found in the station list!')
sta_lon_arr = np.array(sta_lon)
sta_lat_arr = np.array(sta_lat)
sta_stats = np.vstack((sta_nm_arr, sta_ph_arr, sta_lon_arr,
sta_lat_arr, sta_dly_arr, sta_res_arr, sta_nobs_arr)).T
result = np.asarray(sta_stats)
if flag_iset:
np.savetxt(outdir + '/' + model_nm + '-StationStatistic-iSet_' + str(iset) +
'.dat', result, fmt='%s', delimiter=" ")
if iset == len(main_out):
np.savetxt(outvel + '/' + model_nm + '-StationStatistic-final.dat', result, fmt='%s', delimiter=" ")
if plot:
fig1, (ax1, ax2) = plt.subplots(1, 2, sharey='row')
plt.subplots_adjust(wspace=0, hspace=0)
# count number of invert velmod
# lenveldata = 0
# for itt in velestdata:
# d = velestdata[itt]
# if 'vel_mod' in d:
# lenveldata += 1
# minima_rms = 3
# minima_itr = 1
j = 0
for itt in velestdata:
d = velestdata[itt]
# if 'vel_mod' not in d:
# continue # TODO: debugging filter iteration with invertratio != 1
j += 1
allitt += 1
adj = d['adjustment']['avr']
# if 'min_rms' not in itt:
itr.append(j)
rms.append(d['rms_res'])
adj_ot.append(adj['ot'])
adj_lon.append(adj['x'])
adj_lat.append(adj['y'])
adj_dep.append(adj['z'])
itr_all.append(allitt)
rms_all.append(d['rms_res'])
adj_ot_all.append(adj['ot'])
adj_lon_all.append(adj['x'])
adj_lat_all.append(adj['y'])
adj_dep_all.append(adj['z'])
if 'vel_mod' in d:
dep = d['vel_mod']['dep']
vel.append(d['vel_mod']['vel'])
adj_vel.append(d['vel_mod']['dvel'])
dep_arr = np.array(dep)
dep_array = dep_arr * -1
dep_array = dep_array.T
vel_arr2 = vel_arr
vel_arr, dep_arr = adjust_layer(d['vel_mod']['vel'], d['vel_mod']['dep'],
step=2, dev=0.05, plot=False, flag_v=False)
vel_arr = np.array(vel_arr)
vel_mod = vel_arr.T
# dvel_arr = np.array(d['vel_mod']['dvel'])
# RECALCULATE ADJUSTMENT VELOCITY AFTER READJUST LAYER
# if 'min_rms' in itt:
# dvel_arr = np.zeros(len(vel_arr))
# else:
dvel_arr = vel_arr - vel_arr2
vel_adj = dvel_arr.T
mx_vel = max(vel_arr)
mn_vel = min(vel_arr)
mx_dvel = max(dvel_arr)
mn_dvel = min(dvel_arr)
if mx_vel > max_vel:
max_vel = mx_vel
if mn_vel < min_vel:
min_vel = mn_vel
if mx_dvel > max_dvel:
max_dvel = mx_dvel
if mn_dvel < min_dvel:
min_dvel = mn_dvel
if mx_dvel > max_veladj:
max_veladj = mx_dvel
if mn_dvel < min_veladj:
min_veladj = mn_dvel
if plot:
ax1.plot(vel_mod, dep_array, label=itt)
# ax1.legend(fancybox=True, framealpha=0.5)
ax2.barh(dep_array, vel_adj, alpha=0.5, label=itt)
ax2.legend(fancybox=True, framealpha=0.5)
model_adj = np.vstack((dep_arr, vel_arr, dvel_arr, hyp_arr)).T
result = np.asarray(model_adj)
if j == invratio:
minrms_result = result
last_rms = d['rms_res']
elif d['rms_res'] < last_rms:
minrms_result = result
last_rms = d['rms_res']
if flag_iset:
np.savetxt(outdir + '/' + model_nm + '-ModelAdjustment-iSet_' + str(iset) + '_' + str(j) + '.dat',
result, fmt='%.6f', delimiter=" ")
np.savetxt(outvel + '/' + model_nm + '-ModelAdjustment-iter' + str(allitt) + '.dat',
result, fmt='%.6f', delimiter=" ")
if iset == len(main_out) and j == len(velestdata):
np.savetxt(outvel + '/' + model_nm + '-ModelFinal.dat',
minrms_result, fmt='%.6f', delimiter=" ")
# else:
if plot:
fig1.suptitle('Velocity Adjustment - Iteration Set ' + str(iset), fontsize=12)
ax1.grid(alpha=0.5, axis='y')
ax2.grid(alpha=0.5, axis='y')
ax1.set_ylabel('Depth (km)')
ax1.set_xlabel('Velocity (km/s)')
ax2.spines['left'].set_position('zero')
xmin, xmax = ax2.get_xlim()
xmin = -(max(abs(xmax), abs(xmin)))
xmax = (max(abs(xmax), abs(xmin)))
ax2.set_xlim([xmin, xmax])
ax2.set_xlabel('Vel adjustment (km/s)')
plt.show()
if flag_iset:
plt.savefig(outdir + '/' + model_nm + '-ModelAdjustment-iSet_' + str(iset))
plt.close()
fig2 = plt.figure(constrained_layout=True)
gs = fig2.add_gridspec(3, 3)
axs1 = fig2.add_subplot(gs[0, 0])
axs2 = fig2.add_subplot(gs[0, 1])
axs3 = fig2.add_subplot(gs[1, 0])
axs4 = fig2.add_subplot(gs[1, 1])
axs5 = fig2.add_subplot(gs[0:, 2])
fig2.suptitle('Hypocenter Adjustment and RMS - Iteration Set ' + str(iset), fontsize=12)
axs1.plot(itr, adj_ot)
# min_ot, max_ot = axs1.get_xlim()
axs1.ticklabel_format(style='sci', axis='y', scilimits=(0, 1), useMathText=True)
axs1.set_xlabel('Iteration')
axs1.set_ylabel('Origin Time adjustment (s)')
axs2.plot(itr, adj_dep)
# min_dp, max_dp = axs2.get_xlim()
axs2.ticklabel_format(style='sci', axis='y', scilimits=(0, 1), useMathText=True)
axs2.set_xlabel('Iteration')
axs2.set_ylabel('Depth adjustment (km)')
axs3.plot(itr, adj_lon)
# min_ln, max_ln = axs3.get_xlim()
axs3.ticklabel_format(style='sci', axis='y', scilimits=(0, 1), useMathText=True)
axs3.set_xlabel('Iteration')
axs3.set_ylabel('Longitude adjustment (km)')
axs4.plot(itr, adj_lat)
# min_lt, max_lt = axs4.get_xlim()
axs4.ticklabel_format(style='sci', axis='y', scilimits=(0, 1), useMathText=True)
axs4.set_xlabel('Iteration')
axs4.set_ylabel('Latitude adjustment (km)')
axs5.plot(itr, rms)
# min_rms, max_rms = axs5.get_xlim()
axs5.set_xlabel('Iteration')
axs5.set_ylabel('RMS residual (s)')
if flag_iset:
plt.savefig(outdir + '/' + model_nm + '-HypoAdjustment-iSet_' + str(iset))
plt.close()
itr_arr = np.array(itr)
adj_ot_arr = np.array(adj_ot)
adj_dep_arr = np.array(adj_dep)
adj_lon_arr = np.array(adj_lon)
adj_lat_arr = np.array(adj_lat)
rms_arr = np.array(rms)
hypo_adj = np.vstack((itr_arr, adj_ot_arr, adj_dep_arr, adj_lon_arr, adj_lat_arr, rms_arr)).T
result = np.asarray(hypo_adj)
if flag_iset:
np.savetxt(outdir + '/' + model_nm + '-HypoAdjustment-iSet_' + str(iset) +
'.dat', result, fmt='%.6f', delimiter=" ")
# set scale limit for gmt
min_it = min(itr)
if min_it < 0:
min_x = min_it
else:
min_x = 0
max_it = max(itr)
max_x = max_it + 1
min_ot = (min(adj_ot) * 1000 - np.ceil((max(adj_ot) - min(adj_ot)) * 100)) / 1000
max_ot = (max(adj_ot) * 1000 + np.ceil((max(adj_ot) - min(adj_ot)) * 100)) / 1000
min_ot = -(max(abs(min_ot), abs(max_ot)))
max_ot = (max(abs(min_ot), abs(max_ot)))
if float(max_ot) == 0.0:
max_ot = 0.002
min_ot = -0.002
min_dp = (min(adj_dep) * 1000 - np.ceil((max(adj_dep) - min(adj_dep)) * 100)) / 1000
max_dp = (max(adj_dep) * 1000 + np.ceil((max(adj_dep) - min(adj_dep)) * 100)) / 1000
min_dp = -(max(abs(min_dp), abs(max_dp)))
max_dp = (max(abs(min_dp), abs(max_dp)))
if float(max_dp) == 0.0:
max_dp = 0.002
min_dp = -0.002
min_ln = (min(adj_lon) * 1000 - np.ceil((max(adj_lon) - min(adj_lon)) * 100)) / 1000
max_ln = (max(adj_lon) * 1000 + np.ceil((max(adj_lon) - min(adj_lon)) * 100)) / 1000
min_ln = -(max(abs(min_ln), abs(max_ln)))
max_ln = (max(abs(min_ln), abs(max_ln)))
if float(max_ln) == 0.0:
max_ln = 0.002
min_ln = -0.002
min_lt = (min(adj_lat) * 1000 - np.ceil((max(adj_lat) - min(adj_lat)) * 100)) / 1000
max_lt = (max(adj_lat) * 1000 + np.ceil((max(adj_lat) - min(adj_lat)) * 100)) / 1000
min_lt = -(max(abs(min_lt), abs(max_lt)))
max_lt = (max(abs(min_lt), abs(max_lt)))
if float(max_lt) == 0.0:
max_lt = 0.002
min_lt = -0.002
min_rms = (min(rms) * 1000 - np.ceil((max(rms) - min(rms)) * 100)) / 1000
max_rms = (max(rms) * 1000 + np.ceil((max(rms) - min(rms)) * 100)) / 1000
min_rms = -(max(abs(min_rms), abs(max_rms)))
max_rms = (max(abs(min_rms), abs(max_rms)))
min_vel = (min_vel * 1000 - np.ceil((max_vel - min_vel) * 100)) / 1000
max_vel = (max_vel * 1000 + np.ceil((max_vel - min_vel) * 100)) / 1000
min_dvel = (min_dvel * 1000 - np.ceil((max_dvel - min_dvel) * 100)) / 1000
max_dvel = (max_dvel * 1000 + np.ceil((max_dvel - min_dvel) * 100)) / 1000
min_dvel = -(max(abs(min_dvel), abs(max_dvel)))
max_dvel = (max(abs(min_dvel), abs(max_dvel)))
max_nhyp = max(hyp_arr) + np.ceil(max(hyp_arr) / 10)
max_dly = np.ceil(max(sta_dly_arr) * 10) / 10.0
if abs(min(sta_dly_arr)) > max_dly:
max_dly = np.ceil(abs(min(sta_dly_arr)) * 10) / 10.0
min_dly = -max_dly
intv_dly = np.ceil(max_dly * 50) / 100.0
# TODO : Write variable plot batch using f strings
if flag_iset:
fvar.write('@echo off\n')
fvar.write(f'set ps1=Hypo_adj-iSet-{iset}.ps\n')
fvar.write(f'set ps2=Model_adj-iSet-{iset}.ps\n')
fvar.write(f'set ps3=EQ_location_adj-iSet-{iset}.ps\n')
fvar.write(f'set iset=Set-{iset}\n')
fvar.write(f'set out1=%~dp0../../{plot_result}/{model_nm}-Hypo_adj-iSet-{iset}.png\n')
fvar.write(f'set out2=%~dp0../../{plot_result}/{model_nm}-Model_adj-iSet-{iset}.png\n')
fvar.write(f'set out3=%~dp0../../{plot_result}/{model_nm}-EQ_location_adj-iSet-{iset}.png\n')
fvar.write(f'set init_cat=%~dp0{model_nm}-CatalogInitial-iSet_{iset}.dat\n')
fvar.write(f'set fnal_cat=%~dp0{model_nm}-CatalogFinal-iSet_{iset}.dat\n')
fvar.write(f'set hypo_adj=%~dp0{model_nm}-HypoAdjustment-iSet_{iset}.dat\n')
fvar.write(f'set init_stat=%~dp0{model_nm}-StationStatistic-iSet_{i}.dat\n')
fvar.write(f'set sts_stat=%~dp0{model_nm}-StationStatistic-iSet_{iset}.dat\n')
fvar.write(f'set init_mod=%~dp0{model_nm}-ModelInitial-iSet_{iset}.dat\n')
if i == 0:
fvar.write('set init_lgn=Initial Model\n')
else:
fvar.write(f'set init_lgn=Initial Set-{iset}\n')
if len(velestdata) >= 5:
for k in range(len(velestdata)):
fvar.write(f'set mod_adj{(k + 1)}=%~dp0{model_nm}-ModelAdjustment-iSet_{iset}_{(k + 1)*invratio}.dat\n')
else:
for k in range(5):
fvar.write(f'set mod_adj{(k + 1)}=%~dp0{model_nm}-ModelAdjustment-iSet_{iset}_{(k + 1)*invratio}.dat\n')
fvar.write('set dly_scl=' + str(min_dly) + '/' + str(max_dly) + '\n')
fvar.write('set dly_itvl=' + str(intv_dly) + '\n')
# data hyposenter before after
fvar.write('set R_ot=' + str(min_x) + '/' + str(max_x) + '/' + str(min_ot) + '/' + str(max_ot) + '\n')
fvar.write('set R_dp=' + str(min_x) + '/' + str(max_x) + '/' + str(min_dp) + '/' + str(max_dp) + '\n')
fvar.write('set R_ln=' + str(min_x) + '/' + str(max_x) + '/' + str(min_ln) + '/' + str(max_ln) + '\n')
fvar.write('set R_lt=' + str(min_x) + '/' + str(max_x) + '/' + str(min_lt) + '/' + str(max_lt) + '\n')
# fvar.write('set R_ot=' + str(min_x) + '/' + str(max_x) + '/' + str(0) + '/' + str(max_ot) + '\n')
# fvar.write('set R_dp=' + str(min_x) + '/' + str(max_x) + '/' + str(0) + '/' + str(max_dp) + '\n')
# fvar.write('set R_ln=' + str(min_x) + '/' + str(max_x) + '/' + str(0) + '/' + str(max_ln) + '\n')
# fvar.write('set R_lt=' + str(min_x) + '/' + str(max_x) + '/' + str(0) + '/' + str(max_lt) + '\n')
fvar.write('set R_rms=' + str(min_x) + '/' + str(max_x) + '/' + str(0) + '/' + str(max_rms) + '\n')
fvar.write('set R_mod=' + str(min_vel) + '/' + str(max_vel) + '/' + str(min(dep) - 2) + '/' + str(
max(dep) + 2) + '\n')
fvar.write('set R_dmod=' + str(min_dvel) + '/' + str(max_dvel) + '/' + str(min(dep) - 2) + '/' + str(
max(dep) + 2) + '\n')
fvar.write('set R_nhyp=' + str(min(dep) - 2) + '/' + str(max(dep) + 2) + '/' + str(-5) + '/' + str(
max_nhyp) + '\n')
fvar.write('set R_nhyp2=' + str(-5) + '/' + str(max_nhyp) + '/' + str(min(dep) - 2) + '/' + str(
max(dep) + 2) + '\n')
fvar.write('call velestplot_itt.bat')
fvar.close()
if gmtplot:
# Running GMT Plot
print("________________________________________________________")
time.sleep(1)
print(f"\nPlotting model '{model_nm}' iteration set {iset} . . .\n")
p = sp.Popen(['Plot-' + model_nm + '.bat'], shell=True, cwd=outdir)
p.communicate()
time.sleep(2)
if flag_iset and len(velestdata) > itrmax * invratio:
print(f'Sub iteration more than 5, periksa script plot')
if flag_iset and len(velestdata) < itrmax:
print(f'\nSub iteration less than {itrmax}, iteration stop...')
result = np.asarray(sta_stats)
np.savetxt(outvel + '/' + model_nm + '-StationStatistic-final.dat', result, fmt='%s', delimiter=" ")
result = np.asarray(model_adj)
np.savetxt(outvel + '/' + model_nm + '-ModelFinal.dat', result, fmt='%.6f', delimiter=" ")
break
if not next_set:
print('\nBackup reach 4 times, iteration stop...')
break
else:
print('Number of Velest main output, initial data and final data must match')
itr_arr = np.array(itr_all)
adj_ot_arr = np.array(adj_ot_all)
adj_dep_arr = np.array(adj_dep_all)
adj_lon_arr = np.array(adj_lon_all)
adj_lat_arr = np.array(adj_lat_all)
rms_arr = np.array(rms_all)
# USING LIST MAP
hypo_adj = np.vstack((itr_arr, adj_ot_arr, adj_dep_arr, adj_lon_arr, adj_lat_arr, rms_arr)).T
result = np.asarray(hypo_adj)
np.savetxt(outvel + '/' + model_nm + '-HypoAdjustment-all.dat', result, fmt='%.6f', delimiter=" ")
fvarall = open(outvel + '/Plot_all-' + model_nm + '.bat', 'w')
fvel_mod = open(outvel + '/' + model_nm + '-vel_mod.bat', 'w')
fvel_leg = open(outvel + '/' + model_nm + '-vel_leg.bat', 'w')
fvel_adj = open(outvel + '/' + model_nm + '-vel_adj.bat', 'w')
fvarall.write('@echo off\n')
fvarall.write('set model=' + model_nm + '\n')
fvarall.write('set ps1=Hypo_adj-all.ps\n')
fvarall.write('set ps2=Model_adj-all.ps\n')
fvarall.write('set ps3=EQ_location_adj-all.ps\n')
fvarall.write('set ps4=Model_InitnFinal.ps\n')
fvarall.write(f'set out1=../{plot_result}/{model_nm}-Hypo_adj-all.png\n')
fvarall.write(f'set out2=../{plot_result}/{model_nm}-Model_adj-all.png\n')
fvarall.write(f'set out3=../{plot_result}/{model_nm}-EQ_location_adj-all.png\n')
fvarall.write(f'set out4=../{plot_result}/{model_nm}-Model_InitnFinal.png\n')
fvarall.write('set init_cat=' + model_nm + '-CatalogInitial.dat' + '\n')
fvarall.write('set fnal_cat=' + model_nm + '-CatalogFinal.dat' + '\n')
fvarall.write('set hypo_adj=' + model_nm + '-HypoAdjustment-all.dat' + '\n')
# fvarall.write('set init_stat=' + model_nm + '-StationStatistic-iSet_' + str(i) + '.dat'+'\n')
fvarall.write('set sts_stat=' + model_nm + '-StationStatistic-final.dat' + '\n')
fvarall.write('set init_lgn=Initial Model' + '\n')
fvarall.write('set init_mod=' + model_nm + '-ModelInitial.dat' + '\n')
min_it = min(itr_all)
if min_it < 0:
min_x = min_it
else:
min_x = 0
max_it = max(itr_all)
max_x = max_it + 1
min_ot = (min(adj_ot_all) * 1000 - np.ceil((max(adj_ot_all) - min(adj_ot_all)) * 100)) / 1000
max_ot = (max(adj_ot_all) * 1000 + np.ceil((max(adj_ot_all) - min(adj_ot_all)) * 100)) / 1000
min_ot = -(max(abs(min_ot), abs(max_ot)))
max_ot = (max(abs(min_ot), abs(max_ot)))
if float(max_ot) == 0.0:
max_ot = 0.002
min_ot = -0.002
min_dp = (min(adj_dep_all) * 1000 - np.ceil((max(adj_dep_all) - min(adj_dep_all)) * 100)) / 1000
max_dp = (max(adj_dep_all) * 1000 + np.ceil((max(adj_dep_all) - min(adj_dep_all)) * 100)) / 1000
min_dp = -(max(abs(min_dp), abs(max_dp)))
max_dp = (max(abs(min_dp), abs(max_dp)))
if float(max_dp) == 0.0:
max_dp = 0.002
min_dp = -0.002
min_ln = (min(adj_lon_all) * 1000 - np.ceil((max(adj_lon_all) - min(adj_lon_all)) * 100)) / 1000
max_ln = (max(adj_lon_all) * 1000 + np.ceil((max(adj_lon_all) - min(adj_lon_all)) * 100)) / 1000
min_ln = -(max(abs(min_ln), abs(max_ln)))
max_ln = (max(abs(min_ln), abs(max_ln)))
if float(max_ln) == 0.0:
max_ln = 0.002
min_ln = -0.002
min_lt = (min(adj_lat_all) * 1000 - np.ceil((max(adj_lat_all) - min(adj_lat_all)) * 100)) / 1000
max_lt = (max(adj_lat_all) * 1000 + np.ceil((max(adj_lat_all) - min(adj_lat_all)) * 100)) / 1000
min_lt = -(max(abs(min_lt), abs(max_lt)))
max_lt = (max(abs(min_lt), abs(max_lt)))
if float(max_lt) == 0.0:
max_lt = 0.002
min_lt = -0.002
min_rms = (min(rms_all) * 1000 - np.ceil((max(rms_all) - min(rms_all)) * 100)) / 1000
max_rms = (max(rms_all) * 1000 + np.ceil((max(rms_all) - min(rms_all)) * 100)) / 1000
min_rms = -(max(abs(min_rms), abs(max_rms)))
max_rms = (max(abs(min_rms), abs(max_rms)))
min_vel = (min_vel * 1000 - np.ceil((max_vel - min_vel) * 100)) / 1000
max_vel = (max_vel * 1000 + np.ceil((max_vel - min_vel) * 100)) / 1000
min_dvel = (min_veladj * 1000 - np.ceil((max_veladj - min_veladj) * 100)) / 1000
max_dvel = (max_veladj * 1000 + np.ceil((max_veladj - min_veladj) * 100)) / 1000
min_dvel = -(max(abs(min_dvel), abs(max_dvel)))
max_dvel = (max(abs(min_dvel), abs(max_dvel)))
max_nhyp = max_hyp + np.ceil(max_hyp / 10)
max_dly = np.ceil(max(sta_dly) * 10) / 10.0
if abs(min(sta_dly)) > max_dly:
max_dly = np.ceil(abs(min(sta_dly)) * 10) / 10.0
min_dly = -max_dly
intv_dly = np.ceil(max_dly * 50) / 100.0
# clr = color_cycle
# fvel_mod.write('gawk "{print $2, $1}" %init_mod% | psxy -J -R -W1,black -O -K -t30 >> %ps2%\n')
fvel_leg.write('psbasemap -JX4/10 -R0.5/9/-0.5/22 -BWnSe -O -K >> %ps2%\n')
fvel_adj.write('echo 0 ' + str(max(dep) + 2) + ' > midline.tmp\n')
fvel_adj.write('echo 0 ' + str(min(dep) - 2) + ' >> midline.tmp\n')
fvel_adj.write('psxy midline.tmp -J -R -W0.1,black,- -O -K >> %ps2%\n')
for k in range(int(np.ceil(len(itr_all)/invratio))):
if k == 0:
fvel_mod.write('gawk "{print $2, $1}" %init_mod% | psxy -J -R -W1,black,- -O -K -t30 >> %ps2%\n')
if allitt <= 20:
fvel_leg.write(f'echo 1 {np.ceil(len(itr_all)/invratio) + 1} > leg.tmp\n')
fvel_leg.write(f'echo 3 {np.ceil(len(itr_all)/invratio) + 1} >> leg.tmp\n')
fvel_leg.write(f'echo 3.5 {np.ceil(len(itr_all)/invratio) + 1} %init_lgn% | pstext -J -R -F+f11p,Helvetica,black+jLM -O -K >> %ps2%\n')
fvel_leg.write('psxy leg.tmp -J -R -W1.4,black,- -t30 -N -O -K >> %ps2%\n')
else:
fvel_leg.write('echo 1 22 > leg.tmp\n')
fvel_leg.write('echo 3 22 >> leg.tmp\n')
fvel_leg.write('echo 3.5 22 Initial Model | pstext -J -R '
'-F+f9p,Helvetica,black+jLM -N -O -K >> %ps2%\n')
fvel_leg.write('psxy leg.tmp -J -R -W1.4,black,- -t30 -N -O -K >> %ps2%\n')
else:
clr, transp = color_cycle(k-1)
fvarall.write(f'set mod_adj{k}={model_nm}-ModelAdjustment-iter{k*invratio}.dat\n')
# transp = np.ceil(k / (len(clr) - 1)) * 15 + 15
fvel_mod.write(f'gawk "{{print $2, $1}}" %mod_adj{k}% | psxy -J -R -W1,{clr} -O -K -t{transp} >> %ps2%\n')
fvel_adj.write(f'gawk "{{print $3, $1}}" %mod_adj{k}% | '
f'psxy -J -R -SB0.22b0 -G{clr} -t{transp} -O -K >> %ps2%\n')
if allitt <= 20:
fvel_leg.write(f'echo 3 {np.ceil(len(itr_all)/invratio) + 1 - k} | '
f'psxy -J -R -SB0.2b1 -G{clr} -t{transp} -O -K >> %ps2%\n')
fvel_leg.write(f'echo 3.5 {np.ceil(len(itr_all)/invratio) + 1 - k} Iterasi {k*invratio} | '
f'pstext -J -R -F+f11p,Helvetica,black+jLM -O -K >> %ps2%\n')
else:
fvel_leg.write(f'echo 3 {22 - k * 21 / np.ceil(len(itr_all)/invratio)} | '
f'psxy -J -R -SB0.2b1 -G{clr} -t{transp} -O -K >> %ps2%\n')
fvel_leg.write(f'echo 3.5 {22 - k * 21 / np.ceil(len(itr_all)/invratio)} Iterasi {k*invratio} | '
f'pstext -J -R -F+f9p,Helvetica,black+jLM -O -K >> %ps2%\n')
# if transp >= 95:
# print('Too much data, check plot script')
if k == (int(np.ceil(len(itr_all)/invratio)) - 1):
fvarall.write('set mod_adj' + str(k) + '=' + model_nm + '-ModelAdjustment-iter' + str(k*invratio) + '.dat' + '\n')
fvarall.write('set fnal_mod=' + model_nm + '-ModelFinal.dat' + '\n')
fvel_mod.write('gawk "{print $2, $1}" %fnal_mod% | psxy -J -R -W1,black -O -K -t35 >> %ps2%\n')
fvel_leg.write('echo 3 1 | psxy -J -R -SB0.2b1 -Gblack -t30 -O -K >> %ps2%\n')
fvel_adj.write('gawk "{print $3, $1}" %fnal_mod% | psxy -J -R -SB0.22b0 -Gblack -t35 -O -K >> %ps2%\n')
if allitt <= 20:
fvel_leg.write('echo 3.5 1 Final Model | pstext -J -R -F+f11p,Helvetica,black+jLM -O -K >> %ps2%\n')
else:
fvel_leg.write('echo 3.5 1 Final Model | pstext -J -R -F+f9p,Helvetica,black+jLM -O -K >> %ps2%\n')
fvarall.write('set dly_scl=' + str(min_dly) + '/' + str(max_dly) + '\n')
fvarall.write('set dly_itvl=' + str(intv_dly) + '\n')
# data hyposenter before after
fvarall.write('set R_ot=' + str(min_x) + '/' + str(max_x) + '/' + str(min_ot) + '/' + str(max_ot) + '\n')
fvarall.write('set R_dp=' + str(min_x) + '/' + str(max_x) + '/' + str(min_dp) + '/' + str(max_dp) + '\n')
fvarall.write('set R_ln=' + str(min_x) + '/' + str(max_x) + '/' + str(min_ln) + '/' + str(max_ln) + '\n')
fvarall.write('set R_lt=' + str(min_x) + '/' + str(max_x) + '/' + str(min_lt) + '/' + str(max_lt) + '\n')
# fvarall.write('set R_ot=' + str(min_x) + '/' + str(max_x) + '/' + str(0) + '/' + str(max_ot) + '\n')
# fvarall.write('set R_dp=' + str(min_x) + '/' + str(max_x) + '/' + str(0) + '/' + str(max_dp) + '\n')
# fvarall.write('set R_ln=' + str(min_x) + '/' + str(max_x) + '/' + str(0) + '/' + str(max_ln) + '\n')
# fvarall.write('set R_lt=' + str(min_x) + '/' + str(max_x) + '/' + str(0) + '/' + str(max_lt) + '\n')
fvarall.write('set R_rms=' + str(min_x) + '/' + str(max_x) + '/' + str(0) + '/' + str(max_rms) + '\n')
fvarall.write(
'set R_mod=' + str(min_vel) + '/' + str(max_vel) + '/' + str(min(dep) - 2) + '/' + str(max(dep) + 2) + '\n')
fvarall.write(
'set R_dmod=' + str(min_dvel) + '/' + str(max_dvel) + '/' + str(min(dep) - 2) + '/' + str(max(dep) + 2) + '\n')
fvarall.write(
'set R_nhyp=' + str(min(dep) - 2) + '/' + str(max(dep) + 2) + '/' + str(-5) + '/' + str(max_nhyp) + '\n')
fvarall.write(
'set R_nhyp2=' + str(-5) + '/' + str(max_nhyp) + '/' + str(min(dep) - 2) + '/' + str(max(dep) + 2) + '\n')
fvarall.write('call velestplot_all.bat')
fvarall.close()
# for k in range(len(itr_all)):
# fvel_mod.write('gawk "{print $2, $1}" %init_mod% | psxy -J -R -W1,black -O -K -t30 >> %ps2%\n')
fvel_mod.close()
fvel_leg.close()
fvel_adj.close()
if gmtplot:
# Running GMT Plot
print("========================================================")
time.sleep(1)
print(f"\nPlotting model all itteration result for model '{model_nm} . . .'\n")
p = sp.Popen(['Plot_all-' + model_nm + '.bat'], shell=True, cwd=outvel)
p.communicate()
time.sleep(3)
print(f'\nResult generated on "{outvel}/{plot_result}"'
f'\n========================================================')
time.sleep(2)
log = f'Success generate {iset} set, {allitt} iterasi'
print('\n' + ids + log)
file = open('log.txt', 'w')
file.write(ids + log)
file.close()
return velestdata, init_data, final_data
def damping_test(model=None, phase=None, stacor=None, which_dmp=None,
min_damp=1, max_damp=900, num_damp=10, plot=False):
"""
:param model: input model file
:param phase: input phase file
:param stacor: input phase file
:type model: full path
:type phase: full path
:type stacor: full path
:param which_dmp: damping parameter to test (ot, xy, z, vel, sta)
:param min_damp: minimum damp value to test
:param max_damp: maximum damp value to test
:param num_damp: number damp value to test
:param plot: plot damping test graph or not
"""
if model is None:
my_dir = os.getcwd()
mod_dir = os.path.join('input', 'mod')
if not os.path.exists(os.path.join('input')):
os.makedirs('input')
if not os.path.exists(mod_dir):
os.makedirs(mod_dir)
inpmod = []
mod_nm = []
for m in os.listdir(os.path.join(my_dir, mod_dir)):
if os.path.isfile(os.path.join(my_dir, mod_dir, m)):
inpmod.append(os.path.join(mod_dir, m))
mod_nm.append(m[:-4])
if len(inpmod) == 0:
sys.exit(f'\nPlease place your input model in folder "input/mod/" . . .\n')
else:
print(f'\nList model:\n\n')
for i, m in zip(range(len(mod_nm)), mod_nm):
print(f'{i + 1} {mod_nm[i]}')
mod_number = int(input(f'\nSelect model number:\n\n'))
model = inpmod[mod_number - 1]
# mod_nm = mod_nm[mod_number-1]
if which_dmp is None:
which_dmp = int(input('\nDamping parameter to test?\n\n'
'1. othet (Origin Time Damping Factor)\n'
'2. xythet (Epicenter Damping Factor)\n'
'3. zthet (Depth Damping Factor)\n'
'4. vthet (Velocity Damping Factor)\n'
'5. stathet (Station Correction Damping Factor)\n\n'))
mod_nm = os.path.basename(model)[:-4]
logfile = open('log_damptest.txt', 'w')
if which_dmp == 1:
damp_type = 'Origin Time'
elif which_dmp == 2:
damp_type = 'Epicenter'
elif which_dmp == 3:
damp_type = 'Depth'
elif which_dmp == 4:
damp_type = 'Velocity Model'
elif which_dmp == 5:
damp_type = 'Station Correction'
else:
sys.exit('Wrong damping parameter!')
out_dir = os.path.join('output', 'damping_test')
if not os.path.exists('output'):
os.makedirs('output')
if not os.path.exists(out_dir):
os.makedirs(out_dir)
cons = max_damp ** (1 / (num_damp - 1))
lst_dmp = cons ** np.arange(1, num_damp)
if cons > min_damp:
lst_dmp = np.insert(lst_dmp, 0, 1)
lst_dmp = lst_dmp.round(decimals=1)
# lst_dmp = np.linspace(min_damp, max_damp, int(num_damp), dtype=int)
damp = [999, 999, 999, 999, 999]
set_model = model
if phase is None:
pha_dir = os.path.join('input', 'pha')
if not os.path.exists(pha_dir):
os.makedirs(pha_dir)
set_phafl = os.path.join(pha_dir, f'phase_{mod_nm}.cnv')
else:
set_phafl = phase
if stacor is None:
sta_dir = os.path.join('input', 'sta')
if not os.path.exists(sta_dir):
os.makedirs(sta_dir)
set_stafl = os.path.join(sta_dir, f'stacor_{mod_nm}.out')
else:
set_stafl = stacor
set_outmn = os.path.join(out_dir, f'mainprint_damptest{mod_nm}.out')
set_outph = os.path.join(out_dir, f'finalhypo_damptest{mod_nm}.cnv')
set_outst = os.path.join(out_dir, f'stacorrect_damptest{mod_nm}.out')
if not os.path.exists(set_stafl) or not os.path.exists(set_phafl) or not os.path.exists(set_model):
sys.exit(f'Check required file: model {set_model}, station {set_stafl} and phase {set_phafl}')
eqs_num = CNV_EvtCount(set_phafl)
log = f'\nTest {damp_type} Damping Factor With Model {mod_nm}\n\n'
print(log)
logfile.write(log)
model_var = []
data_var = []
str_damp = []
for dmp in lst_dmp:
damp[which_dmp - 1] = dmp
log = f'>> Use damping value = "{dmp}"'
print(log)
logfile.write(log)
cmnout = open('velest.cmn', 'w')
with open(os.path.join('input', 'base.cmn')) as f:
hint_eqsnm = '*** neqs nshot rotate'
hint_damps = '*** othet xythet zthet vthet stathet'
hint_usecr = '*** nsinv nshcor nshfix iuseelev iusestacorr'
hint_stcrt = '*** delmin ittmax invertratio'
hint_model = '*** Modelfile:'
hint_stafl = '*** Stationfile:'
hint_phafl = '*** File with Earthquake data:'
hint_outmn = '*** Main print output file:'
hint_outst = '*** File with new station corrections:'
hint_outph = '*** File with final hypocenters in *.cnv format:'
flag_eqsnm = False
flag_damps = False
flag_usecr = False
flag_stcrt = False
flag_model = False
flag_stafl = False
flag_phafl = False
flag_outmn = False
flag_outst = False
flag_outph = False
for l in f:
if hint_eqsnm in l:
flag_eqsnm = True
if flag_eqsnm and hint_eqsnm not in l:
ln = l.split()
ln[0] = eqs_num
l = f" {ln[0]:5d} {int(ln[1]):5d} {float(ln[2]):7.1f}\n"
flag_eqsnm = False
if hint_usecr in l:
flag_usecr = True
if flag_usecr and hint_usecr not in l:
ln = l.split()
ln[4] = 1
l = f" {ln[0]} {ln[1]} {ln[2]} {ln[3]} {ln[4]}\n"
flag_usecr = False
if hint_damps in l:
flag_damps = True
if flag_damps and hint_damps not in l:
l = (f" {damp[0]} {damp[1]} {damp[2]}"
f" {damp[3]} {damp[4]}\n")
flag_damps = False
if hint_stcrt in l:
flag_stcrt = True
if flag_stcrt and hint_stcrt not in l:
l = l.split()
l = f" {float(l[0]):.3f} 1 1\n"
flag_stcrt = False
if hint_model in l:
flag_model = True
if flag_model and hint_model not in l:
l = set_model + '\n'
flag_model = False
if hint_stafl in l:
flag_stafl = True
if flag_stafl and hint_stafl not in l:
l = set_stafl + '\n'
flag_stafl = False
if hint_phafl in l:
flag_phafl = True
if flag_phafl and hint_phafl not in l:
l = set_phafl + '\n'
flag_phafl = False
if hint_outmn in l:
flag_outmn = True
if flag_outmn and hint_outmn not in l:
l = set_outmn + '\n'
flag_outmn = False
if hint_outst in l:
flag_outst = True