@@ -231,6 +231,7 @@ def filter_catalog(catalog, t_start, serial_times, fault_length_multiplier):
231
231
232
232
idx_big_shock = np .argmax (catalog [:, MagnColumn ])
233
233
mag_big_shock = catalog [idx_big_shock , MagnColumn ]
234
+ print ("Mag_big_shock = " , mag_big_shock )
234
235
lat_big_shock = catalog [idx_big_shock , LatColumn ]
235
236
lon_big_shock = catalog [idx_big_shock , LonColumn ]
236
237
@@ -241,8 +242,8 @@ def filter_catalog(catalog, t_start, serial_times, fault_length_multiplier):
241
242
ymax , xmax = trainv (lat_big_shock , lon_big_shock , fault_length_multiplier * l_big_shock , fault_length_multiplier * l_big_shock )
242
243
ymin , xmin = trainv (lat_big_shock , lon_big_shock , - fault_length_multiplier * l_big_shock , - fault_length_multiplier * l_big_shock )
243
244
print (f"Subcatalog limits: "
244
- f"LAT_MIN = { ymin } , LAT_MAX = { ymax } "
245
- f"LON_MIN = { xmin } , LON_MAX = { xmax } " )
245
+ f"LAT_MIN = { round ( ymin , 2 ) } , LAT_MAX = { round ( ymax , 2 ) } "
246
+ f"LON_MIN = { round ( xmin , 2 ) } , LON_MAX = { round ( xmax , 2 ) } " )
246
247
247
248
mask = (ymin <= catalog [:, LatColumn ]) & (catalog [:, LatColumn ] <= ymax ) & \
248
249
(xmin <= catalog [:, LonColumn ]) & (catalog [:, LonColumn ] <= xmax )
@@ -311,6 +312,26 @@ def serial_time(input_):
311
312
return out2
312
313
313
314
315
+ def dynamic_date_formatter (dates ):
316
+ max_date = max (dates )
317
+ min_date = min (dates )
318
+ date_range_days = (max_date - min_date ).days
319
+
320
+ if date_range_days > 365 : # Over a year
321
+ fmt = '%b-%Y'
322
+ elif date_range_days > 30 : # Over a month
323
+ fmt = '%b-%d'
324
+ else : # Shorter intervals
325
+ fmt = '%b-%d'
326
+ return mdates .DateFormatter (fmt )
327
+
328
+
329
+ def equally_spaced_ticks (dates , num_ticks = 6 ):
330
+ min_date = min (dates )
331
+ max_date = max (dates )
332
+ return mdates .drange (min_date , max_date , (max_date - min_date ) / (num_ticks - 1 ))
333
+
334
+
314
335
def timestamp_to_datetime (timestamp ):
315
336
# Converts custom timestamps to datetime objects
316
337
@@ -539,15 +560,16 @@ def mc_vs_time(magcat, magcat_presequence, mc_ok, st_dev_multiplier, alpha, seri
539
560
datenums1 = mdates .date2num (dates1 )
540
561
mc_time_plot = [mc_time [i ] for i in idx_t_window_plot ]
541
562
542
- fig , ax = plt .subplots (figsize = (8 , 6 ))
543
- ax . xaxis_date ( )
544
- fmt = mdates . DateFormatter ( '%b %Y' )
545
- ax .xaxis .set_major_formatter (fmt )
563
+ fig , ax = plt .subplots (figsize = (10 , 6 ))
564
+ ticks = equally_spaced_ticks ( dates1 )
565
+ ax . set_xticks ( ticks )
566
+ ax .xaxis .set_major_formatter (dynamic_date_formatter ( dates1 ) )
546
567
ax .plot (datenums1 , mc_time_plot , label = 'Mc(t)' , ls = '-' )
547
568
ax .fill_between (datenums1 , upper_lim , mc_time_plot ,
548
- where = upper_lim <= mc_time_plot , color = 'C1' , alpha = 0.7 , label = f"$M_c \geq M^*_c$ + { st_dev_multiplier } $\sigma$" )
549
- ax .set_xlabel ("Time" )
550
- ax .set_ylabel ("Mc" )
569
+ where = upper_lim <= mc_time_plot , color = 'C1' , alpha = 0.7 ,
570
+ label = f"$M_c \geq M^*_c$ + { st_dev_multiplier } $\sigma$" )
571
+ ax .set_xlabel ("Time" , labelpad = 10 , fontsize = 14 )
572
+ ax .set_ylabel ("Mc" , labelpad = 10 , fontsize = 14 )
551
573
ax .legend (loc = 'upper right' )
552
574
plt .savefig ('fig/Mc_Time.pdf' , format = 'pdf' )
553
575
@@ -576,17 +598,14 @@ def map_plot(catalog, lon1, lat1, lon2, lat2):
576
598
577
599
parallels = np .arange (- 90 , 90 , lat_interval )
578
600
meridians = np .arange (- 180 , 180 , lon_interval )
579
- m .drawparallels (parallels , labels = [0 , 1 , 0 , 0 ], fontsize = 8 , dashes = [1 , 5 ])
580
- m .drawmeridians (meridians , labels = [0 , 0 , 1 , 0 ], fontsize = 8 , dashes = [1 , 5 ])
601
+ m .drawparallels (parallels , labels = [1 , 1 , 1 , 1 ], fontsize = 10 , dashes = [1 , 5 ])
602
+ m .drawmeridians (meridians , labels = [1 , 1 , 1 , 1 ], fontsize = 10 , dashes = [1 , 5 ])
581
603
m .fillcontinents (color = '#F0F0F0' , lake_color = '#F0F0F0' )
582
-
583
604
x1 , y1 = m (lon1 , lat1 )
584
605
x2 , y2 = m (lon2 , lat2 )
585
-
586
606
plt .plot (x1 , y1 , 'o' , color = '0.3' , alpha = .7 , markersize = 5 , markeredgecolor = 'w' )
587
607
plt .plot (x2 , y2 , 'o' , color = 'steelblue' , alpha = .7 , markersize = 5 , markeredgecolor = 'w' )
588
- plt .xlabel ('Longitude' , fontsize = 12 , labelpad = 10 )
589
- plt .ylabel ('Latitude' , fontsize = 12 , labelpad = 10 )
608
+
590
609
591
610
return m
592
611
@@ -645,7 +664,7 @@ def magnitude_distribution(magcat):
645
664
bin_edges = np .arange (min_m , max_m + bin_m , bin_m )
646
665
bin_counts = np .zeros (len (bin_edges ), dtype = int )
647
666
for mag in magcat :
648
- bin = int ((mag - min_m ) / bin_m )
667
+ bin = int (round (mag / bin_m - min_m * 10 ) )
649
668
bin_counts [bin ] += 1
650
669
651
670
idx_zeros = np .where (bin_counts == 0 )[0 ]
@@ -734,16 +753,17 @@ def ghost_element(catalog, t_start, mc_user, b_user, size, step, st_dev_multipli
734
753
735
754
# Fit hypo depth distribution
736
755
z_data = filtered_catalog [:, DepthColumn ]
756
+ bins = np .linspace (min (z_data ), max (z_data ), 101 )
737
757
if depth_distribution == 'bimodal' :
738
- y , x = np .histogram (z_data , bins = 100 )
758
+ y , x = np .histogram (z_data , bins = bins )
739
759
else :
740
- y , x = np .histogram (z_data , density = 1. , bins = 100 )
760
+ y , x = np .histogram (z_data , density = 1. , bins = bins )
741
761
x = (x [1 :]+ x [:- 1 ])/ 2 # bin centers
742
762
743
763
distribution_function = select_distribution (depth_distribution )
744
764
params = fit_distribution (distribution_function , x , y , p0 = p0 )
745
765
print ('Fitted parameters = ' , params )
746
- y , x , _ = plt .hist (z_data , 100 )
766
+ y , x , _ = plt .hist (z_data , bins )
747
767
x_fit = np .linspace (x .min (), x .max (), 500 )
748
768
y_fit = distribution_function (x_fit , * params )
749
769
@@ -879,7 +899,7 @@ def ghost_element(catalog, t_start, mc_user, b_user, size, step, st_dev_multipli
879
899
z_ghost .extend ([round (value , 1 ) for value in samples ])
880
900
881
901
# Generate n=n_to_sample random numbers btw 0 and 1
882
- u = np .random .random (n_ghost_hole [ i ] )
902
+ u = np .random .random (n_to_sample )
883
903
884
904
for j in range (len (u )):
885
905
if u [j ] < cumulative_sum [0 ]:
@@ -897,21 +917,25 @@ def ghost_element(catalog, t_start, mc_user, b_user, size, step, st_dev_multipli
897
917
lat_ghost .extend (lat_ghost_hole )
898
918
899
919
# Plot hypo depth distribution
900
- fig , ax = plt .subplots ()
920
+
921
+ data_min = np .min (z_ghost )
922
+ data_max = np .max (z_ghost )
923
+ margin = (data_max - data_min ) * 0.95
924
+ depth_min , depth_max = data_min - margin , data_max + margin
925
+
926
+ fig , ax = plt .subplots (figsize = (8 , 6 ))
901
927
if depth_distribution == 'bimodal' :
902
- plt .hist (z_data , bins = 100 , alpha = 0.3 , color = '0.3' , label = 'Hypo depths (filtered) original' )
903
- plt .plot (x_fit , y_fit , color = 'red' , label = f"Fitted distribution: { depth_distribution } " )
904
- plt .hist (z_ghost , bins = 50 , color = 'steelblue' , label = 'Hypo depths replenished' )
905
- plt .xlabel ('Hypocenter Depth [Km]' )
906
- plt .legend ()
907
- plt .savefig ('fig/Hypo_Depth_Distribution.pdf' , format = 'pdf' )
928
+ ax .hist (z_data , bins = bins , alpha = 0.3 , color = '0.3' , label = 'Hypo depths (filtered) original' )
929
+ ax .plot (x_fit , y_fit , color = 'red' , label = f"Fitted distribution: { depth_distribution } " )
930
+ ax .hist (z_ghost , bins = bins , color = 'steelblue' , label = 'Hypo depths replenished' )
908
931
else :
909
- plt .hist (z_data , bins = 100 , density = True , alpha = 0.3 , color = '0.3' , label = 'Hypo depths (filtered) original' )
910
- plt .plot (x_fit , y_fit , color = 'red' , label = f"Fitted distribution: { depth_distribution } " )
911
- plt .hist (z_ghost , bins = 50 , density = True , color = 'steelblue' , label = 'Hypo depths replenished' )
912
- plt .xlabel ('Hypocenter Depth [Km]' )
913
- plt .legend ()
914
- plt .savefig ('fig/Hypo_Depth_Distribution.pdf' , format = 'pdf' )
932
+ ax .hist (z_data , bins = bins , density = True , alpha = 0.3 , color = '0.3' , label = 'Hypo depths (filtered) original' )
933
+ ax .plot (x_fit , y_fit , color = 'red' , label = f"Fitted distribution: { depth_distribution } " )
934
+ ax .hist (z_ghost , bins = bins , density = True , color = 'steelblue' , label = 'Hypo depths replenished' )
935
+ ax .set_xlim (depth_min , depth_max )
936
+ ax .set_xlabel ('Hypocenter Depth [km]' , labelpad = 10 , fontsize = 14 )
937
+ ax .legend ()
938
+ plt .savefig ('fig/Hypo_Depth_Distribution.pdf' , format = 'pdf' )
915
939
916
940
####
917
941
@@ -1036,7 +1060,7 @@ def replenished_catalog(catalog, t_start, mc_user, b_user, size, step, st_dev_mu
1036
1060
# flag: 0 for original events, 1 for simulated events
1037
1061
flag = np .array ([0 ] * len (new_times ))
1038
1062
for i in range (len (new_times )):
1039
- if i <= len (serial_times_compl ):
1063
+ if i < len (serial_times_compl ):
1040
1064
flag [i ] = 0
1041
1065
else :
1042
1066
flag [i ] = 1
@@ -1085,19 +1109,14 @@ def replenished_catalog(catalog, t_start, mc_user, b_user, size, step, st_dev_mu
1085
1109
bin_edges_replenished , log_bin_counts_replenished , log_cum_counts_replenished = \
1086
1110
magnitude_distribution (replenished_catalog [:, MagnColumn ])
1087
1111
1088
- fig , (ax1 , ax2 ) = plt .subplots (1 , 2 , figsize = (8 , 6 ))
1089
- ax1 .plot (bin_edges_original , log_bin_counts_original , 'o' , color = '0.5' , markersize = 3 , label = 'Non-cumulative counts' )
1090
- ax1 .plot (bin_edges_original , log_cum_counts_original , 'ok' , markersize = 3 , label = 'Cumulative counts' )
1091
- ax1 .legend (loc = 'upper right' )
1092
- ax1 .set_xlabel ("Magnitude" )
1093
- ax1 .set_ylabel ("Frequency" )
1094
- ax1 .set_title ("Original Catalog" )
1095
- ax2 .plot (bin_edges_replenished , log_bin_counts_replenished , 'o' , color = '0.5' , markersize = 3 , label = 'Non-cumulative counts' )
1096
- ax2 .plot (bin_edges_replenished , log_cum_counts_replenished , 'ok' , markersize = 3 , label = 'Cumulative counts' )
1097
- ax2 .legend (loc = 'upper right' )
1098
- ax2 .set_xlabel ("Magnitude" )
1099
- ax2 .set_ylabel ("Frequency" )
1100
- ax2 .set_title ("Replenished Catalog" )
1112
+ fig , ax = plt .subplots (figsize = (8 , 10 ))
1113
+ ax .plot (bin_edges_original , log_bin_counts_original , 'o' , color = '0.5' , markersize = 3 , label = 'Non-cumulative counts (Original)' , alpha = 0.7 )
1114
+ ax .plot (bin_edges_original , log_cum_counts_original , '-' , color = '0.5' , label = 'Cumulative counts (Original)' , alpha = 0.7 )
1115
+ ax .plot (bin_edges_replenished , log_bin_counts_replenished , 'o' , color = 'black' , markersize = 3 , label = 'Non-cumulative counts (Replenished)' , alpha = 0.7 )
1116
+ ax .plot (bin_edges_replenished , log_cum_counts_replenished , '-' , color = 'black' , label = 'Cumulative counts (Replenished)' , alpha = 0.7 )
1117
+ ax .set_xlabel ("Magnitude" , labelpad = 10 , fontsize = 14 )
1118
+ ax .set_ylabel ("Frequency" , labelpad = 10 , fontsize = 14 )
1119
+ ax .legend (loc = 'upper right' )
1101
1120
plt .savefig ('fig/Magnitude_Frequency_Distribution.pdf' , format = 'pdf' )
1102
1121
1103
1122
return replenished_catalog
0 commit comments