@@ -92,6 +92,7 @@ def __init__(
92
92
93
93
if damping_unit not in ['1' , '%' ]:
94
94
raise ValueError ("`damping_unit` must be '1' or '%'." )
95
+
95
96
if density_unit not in ['kg/m^3' , 'g/cm^3' , 'kg/m3' , 'g/cm3' ]:
96
97
raise ValueError ("`density_unit` must be 'kg/m^3' or 'g/cm^3'." )
97
98
@@ -105,6 +106,7 @@ def __init__(
105
106
material_number = np .append (np .arange (1 , n_layer_tmp ), [0 ])
106
107
else :
107
108
material_number = np .arange (1 , n_layer_tmp + 1 )
109
+
108
110
full_data = np .column_stack ((thk , vs , xi , rho , material_number ))
109
111
elif n_col == 5 :
110
112
xi = data_ [:, 2 ]
@@ -128,6 +130,7 @@ def __init__(
128
130
129
131
if density_unit in ['g/cm^3' , 'g/cm3' ]:
130
132
data_ [:, 3 ] *= 1000.0 # g/cm^3 --> kg/m^3
133
+
131
134
if damping_unit == '%' :
132
135
data_ [:, 2 ] /= 100.0 # percent --> 1
133
136
@@ -352,8 +355,10 @@ def truncate(self, depth=None, Vs=1000.0):
352
355
"""
353
356
if depth is None or depth <= 0 :
354
357
raise ValueError ('`depth` needs to be a positive number.' )
358
+
355
359
if Vs is None or Vs <= 0 :
356
360
raise ValueError ('`Vs` needs to be a positive number.' )
361
+
357
362
profile_ = []
358
363
total_depth = 0
359
364
for j in range (len (self ._vs )):
@@ -363,9 +368,9 @@ def truncate(self, depth=None, Vs=1000.0):
363
368
last_row [0 ] = last_thk
364
369
profile_ .append (last_row )
365
370
break
366
- else :
367
- profile_ .append (self .vs_profile [j , :])
368
- total_depth += self ._thk [j ]
371
+
372
+ profile_ .append (self .vs_profile [j , :])
373
+ total_depth += self ._thk [j ]
369
374
else : # `depth` > total depth of the current profile
370
375
last_thk = profile_ [- 1 ][0 ] # thickness of the original last layer
371
376
profile_ [- 1 ][0 ] = depth + last_thk - total_depth # extend to `depth`
@@ -375,6 +380,7 @@ def truncate(self, depth=None, Vs=1000.0):
375
380
bedrock = [0 , Vs , xi [0 ], rho [0 ], 0 ]
376
381
else : # just numbers
377
382
bedrock = [0 , Vs , xi , rho , 0 ]
383
+
378
384
profile_ .append (bedrock ) # add half space whose Vs is `Vs`
379
385
profile_ = np .array (profile_ )
380
386
@@ -413,6 +419,7 @@ def query_Vs_at_depth(self, depth, as_profile=False, show_fig=False):
413
419
'If `as_profile` is set to True, the given '
414
420
'`depth` needs to be monotonically increasing.' ,
415
421
)
422
+
416
423
if has_duplicate_values :
417
424
raise ValueError (
418
425
'If `as_profile` is set to True, the given '
@@ -425,6 +432,7 @@ def query_Vs_at_depth(self, depth, as_profile=False, show_fig=False):
425
432
vs_queried = np .append (vs_queried [0 :1 ], vs_queried )
426
433
else : # `depth` has been guarenteed to be sorted with no duplicates
427
434
thk_array = sr .dep2thk (depth )
435
+
428
436
vs_ = np .column_stack ((thk_array , vs_queried ))
429
437
430
438
if show_fig :
@@ -433,13 +441,14 @@ def query_Vs_at_depth(self, depth, as_profile=False, show_fig=False):
433
441
434
442
# A halfspace is already implicitly added by sr.depth2thk()
435
443
return Vs_Profile (vs_ , add_halfspace = False )
436
- else :
437
- if show_fig :
438
- self ._plot_queried_Vs (vs_queried , depth )
439
- if is_scalar :
440
- return float (vs_queried )
441
- else :
442
- return vs_queried
444
+
445
+ if show_fig :
446
+ self ._plot_queried_Vs (vs_queried , depth )
447
+
448
+ if is_scalar :
449
+ return float (vs_queried )
450
+
451
+ return vs_queried
443
452
444
453
def query_Vs_given_thk (
445
454
self ,
@@ -482,6 +491,7 @@ def query_Vs_given_thk(
482
491
"""
483
492
if n_layers is None and isinstance (thk , (int , float , np .number )):
484
493
n_layers = int (np .ceil (self .z_max / thk ))
494
+
485
495
vs_queried , thk_array = sr .query_Vs_given_thk (
486
496
self .vs_profile ,
487
497
thk ,
@@ -493,13 +503,15 @@ def query_Vs_given_thk(
493
503
if show_fig :
494
504
depth = sr .thk2dep (thk_array , midpoint = at_midpoint )
495
505
self ._plot_queried_Vs (vs_queried , depth )
506
+
496
507
return vs_queried
497
- else :
498
- vs_ = np .column_stack ((thk_array , vs_queried ))
499
- if show_fig :
500
- fig , ax , _ = self .plot ()
501
- sr .plot_Vs_profile (vs_ , fig = fig , ax = ax , c = 'orange' , alpha = 0.75 )
502
- return Vs_Profile (vs_ , add_halfspace = add_halfspace )
508
+
509
+ vs_ = np .column_stack ((thk_array , vs_queried ))
510
+ if show_fig :
511
+ fig , ax , _ = self .plot ()
512
+ sr .plot_Vs_profile (vs_ , fig = fig , ax = ax , c = 'orange' , alpha = 0.75 )
513
+
514
+ return Vs_Profile (vs_ , add_halfspace = add_halfspace )
503
515
504
516
def _plot_queried_Vs (self , vs_queried , depth , dpi = 100 ):
505
517
"""
@@ -518,8 +530,6 @@ def _plot_queried_Vs(self, vs_queried, depth, dpi=100):
518
530
if np .max (y_lim ) <= np .max (depth ):
519
531
ax .set_ylim ((np .max (depth ), np .min (y_lim )))
520
532
521
- return None
522
-
523
533
def get_basin_depth (self , bedrock_Vs = 1000.0 ):
524
534
"""
525
535
Query the depth of the basin as indicated in the Vs profile data.
@@ -604,6 +614,7 @@ def to_txt(
604
614
"""
605
615
if not isinstance (precision , list ):
606
616
raise TypeError ('precision must be a list.' )
617
+
607
618
if len (precision ) != 5 :
608
619
raise ValueError ('Length of precision must be 5.' )
609
620
0 commit comments