@@ -79,6 +79,7 @@ import obspy as ob
7979from azimpy import OrientOBS
8080
8181# # Initialize web client
82+ # # Specity the timezone of recording data
8283obs = OrientOBS(base_url = ' USGS' , timezone = 9 )
8384
8485# # Query earthquake event catalog
@@ -96,15 +97,19 @@ obs.find_stream(
9697 ' /path/to/datadir' ,
9798 output_path = ' /path/to/output/stationA1' ,
9899 polezero_fpath = ' /path/to/polezero/hoge.paz' ,
99- fileformat = f ' *.*.%y%m%d%H%M.sac ' ,
100+ fileformat = " sac" ,
101+ filenameformat = f ' *.*.%y%m%d%H%M.sac ' ,
100102 freqmin = 1 ./ 40 , freqmax = 1 ./ 20 ,
101103 max_workers = 4 ,
102104 vel_surface = 4.0 ,
103105 time_before_arrival = - 20.0 ,
104106 time_after_arrival = 600.0 ,
105107 distmin = 5 ., distmax = 120 .,
108+ read_func = ob.read
106109)
107110```
111+ Note that ` fileformat ` was renamed as ` filenameformat ` in ` v0.3.0 ` . ` fileformat ` denotes the data format of the records.
112+ Also, a user-defined read function can be incorpolated in ` v0.3.0 ` . Specify the function in ` read_func ` argument. This would allow us to read data recorded by local formats such as ` WIN/WIN32 ` , which are not supported by the ` ObsPy ` 's read function.
108113
109114Then, the output dataframe will be pickled as ` stationA1_020_040.pickle ` under ` /path/to/output/stationA1 ` directory. The pickled dataframe can be loaded by ` pd.read_pickle() ` .
110115
@@ -114,101 +119,138 @@ Then, the output dataframe will be pickled as `stationA1_020_040.pickle` under `
114119
115120The example uses a single station ` stationA1 ` .
116121
117- ``` python
118- import pandas as pd
119- from azimpy import OrientSingle, read_chtbl
122+ 1 . Perform analysis and save as pickled data
123+ ``` python
124+ import pandas as pd
125+ from azimpy import OrientSingle, read_chtbl
120126
121- # # Init params
122- min_CC = 0.5
123- alpha_CI = 0.05 # # 100(1-a)% CI
124- bootstrap_iteration = 5000
127+ # # Init params
128+ min_CC = 0.5
129+ alpha_CI = 0.05 # # 100(1-a)% CI
130+ bootstrap_iteration = 5000
125131
126- # # The output dataframe of orientations
127- df_orient = pd.read_pickle(
128- ' /path/to/output/stationA1/stationA1_020_040.pickle'
129- )
132+ # # The output dataframe of orientations
133+ df_orient = pd.read_pickle(
134+ ' /path/to/output/stationA1/stationA1_020_040.pickle'
135+ )
130136
131- # # Init OrientSingle for circular statistics
132- orientsingle_raw = OrientSingle(
133- df_orient, ' stationA1' ,
134- if_selection = False , # w/o bootstrap analysis
135- min_CC = min_CC, weight_CC = True ,
136- )
137- orientsingle_boot = OrientSingle(
138- df_orient, ' stationA1' ,
139- if_selection = True , # perform bootstrap analysis
140- min_CC = min_CC, weight_CC = True , K = 5.0 ,
141- bootstrap_iteration = bootstrap_iteration, alpha_CI = alpha_CI
142- )
137+ # # Init OrientSingle for circular statistics
138+ orientsingle_raw = OrientSingle(
139+ df_orient, ' stationA1' ,
140+ if_selection = False , # w/o bootstrap analysis
141+ min_CC = min_CC, weight_CC = True ,
142+ )
143+ orientsingle_boot = OrientSingle(
144+ df_orient, ' stationA1' ,
145+ if_selection = True , # perform bootstrap analysis
146+ min_CC = min_CC, weight_CC = True , K = 5.0 ,
147+ bootstrap_iteration = bootstrap_iteration, alpha_CI = alpha_CI
148+ )
149+ # # Save orientsingle objects as pickled data
150+ orientsingle_raw.write_obj(
151+ ' /path/to/output/orientsingle/raw/stationA1_020_040.pickle'
152+ )
153+ orientsingle_boot.write_obj(
154+ ' /path/to/output/orientsingle/boot/stationA1_020_040.pickle'
155+ )
156+ ```
157+ 1 . Plot the result
158+ ```py
159+ # # Load orientsingle objects
160+ # # You may skip this part
161+ orientsingle_raw = OrientSingle.load_obj(
162+ ' /path/to/output/orientsingle/raw/stationA1_020_040.pickle'
163+ )
164+ orientsingle_boot = OrientSingle.load_obj(
165+ ' /path/to/output/orientsingle/boot/stationA1_020_040.pickle'
166+ )
143167
144- # # Init a figure with subfigures
145- fig = plt.figure(figsize = [8 ,4 ])
146- subfigs = fig.subfigures(nrows = 1 , ncols = 2 ).flatten()
168+ # # Init a figure with subfigures
169+ fig = plt.figure(figsize = [8 ,4 ])
170+ subfigs = fig.subfigures(nrows = 1 , ncols = 2 ).flatten()
147171
148- # # Plot for `orientsingle_raw`
149- orientsingle_raw.plot(
150- polar = True ,
151- fig = subfigs[0 ], in_parentheses = ' BB' ,
152- add_cbar = True
153- )
154- subfigs[0 ].legend(loc = 1 , bbox_to_anchor = (1 ,1.15 ), fontsize = ' small' )
172+ # # Plot for `orientsingle_raw`
173+ orientsingle_raw.plot(
174+ polar = True ,
175+ fig = subfigs[0 ], in_parentheses = ' BB' ,
176+ add_cbar = True
177+ )
178+ subfigs[0 ].legend(loc = 1 , bbox_to_anchor = (1 ,1.15 ), fontsize = ' small' )
155179
156- # # Plot for `orientsingle_boot`
157- orientsingle_boot.plot(
158- fig = subfigs[1 ], in_parentheses = ' BB' ,
159- )
160- subfigs[1 ].legend(loc = 1 , bbox_to_anchor = (1 ,1.15 ), fontsize = ' small' )
180+ # # Plot for `orientsingle_boot`
181+ orientsingle_boot.plot(
182+ fig = subfigs[1 ], in_parentheses = ' BB' ,
183+ )
184+ subfigs[1 ].legend(loc = 1 , bbox_to_anchor = (1 ,1.15 ), fontsize = ' small' )
161185
162- # # Show or save the figure
163- fig.savefig()
164- plt.show()
165- ```
186+ # # Show or save the figure
187+ fig.savefig(' /path/to/fig/stationA1_020_040.png ' )
188+ plt.show()
189+ ```
166190
167191
168192# ### Multiple stations
169193The example uses multiple stations whose names are `stationAX` .
170194
171- ``` python
172- from azimpy import OrientAnalysis
173-
174- stationList = [' stationA1' ,' stationA2' ,' stationA3' ,' stationA4' ]
195+ 1 . Initialize `OrientAnalysis`
196+ ```python
197+ from azimpy import OrientAnalysis
175198
176- # # Channeltable including above stations' info
177- df_chtbl = read_chtbl(' /path/to/channeltable.txt' )
178- df_chtbl = df_chtbl.query(' comp.str.endswith("U")' )
199+ stationList = [' stationA1' ,' stationA2' ,' stationA3' ,' stationA4' ]
179200
180- # # Init OrientAnalysis for circular statistics
181- oa_raw = OrientAnalysis(
182- if_selection = False , # w/o bootstrap analysis
183- df_chtbl = df_chtbl,
184- min_CC = min_CC,
185- )
186- oa_boot = OrientAnalysis(
187- if_selection = True , # perform bootstrap analysis
188- df_chtbl = df_chtbl,
189- min_CC = min_CC, alpha_CI = alpha_CI,
190- bootstrap_iteration = bootstrap_iteration,
191- )
201+ # # Channeltable including above stations' info
202+ df_chtbl = read_chtbl(' /path/to/channeltable.txt' )
203+ df_chtbl = df_chtbl.query(' comp.str.endswith("U")' )
192204
193- for stationName in stationList:
194- period = df_chtbl.at[stationName,' period' ]
195- df_orient = pd.read_pickle(
196- f ' /path/to/output/ { stationName} / { stationName} _020_040.pickle '
197- )
198- # # Add the dataframe in `oa_raw`
199- # # This is actually passed to `OrientSingle`
200- oa_raw.add_station(
201- df_orient, stationName,
202- period = period
205+ # # Init OrientAnalysis for circular statistics
206+ oa_raw = OrientAnalysis(
207+ if_selection = False , # w/o bootstrap analysis
208+ df_chtbl = df_chtbl,
209+ min_CC = min_CC,
203210 )
204- # # Add the dataframe in `oa_boot`
205- oa_boot.add_station(
206- df_orient, stationName,
207- period = period
211+ oa_boot = OrientAnalysis(
212+ if_selection = True , # perform bootstrap analysis
213+ df_chtbl = df_chtbl,
214+ min_CC = min_CC, alpha_CI = alpha_CI,
215+ bootstrap_iteration = bootstrap_iteration,
208216 )
209- ```
210-
211- - Plot the results using ` matplotlib.pyplot `
217+ ```
218+ 1 . Store the analyzed data or perform analysis
219+ - If storing the orientation data by `OrientSingle`
220+ ```py
221+ for stationName in stationList:
222+ period = df_chtbl.at[stationName,' period' ]
223+
224+ # # Add the dataframe in `oa_raw`
225+ oa_raw.add_station(
226+ orientsingle_path = f ' /path/to/output/orientsingle/raw/ { stationName} _020_040.pickle ' ,
227+ period = period,
228+ )
229+ oa_boot.add_station(
230+ orientsingle_path = f ' /path/to/output/orientsingle/boot/ { stationName} _020_040.pickle ' ,
231+ period = period,
232+ )
233+ ```
234+ - If performing analysis
235+ ```py
236+ for stationName in stationList:
237+ period = df_chtbl.at[stationName,' period' ]
238+ df_orient = pd.read_pickle(
239+ f ' /path/to/output/ { stationName} / { stationName} _020_040.pickle '
240+ )
241+ # # Add the dataframe in `oa_raw`
242+ # # This is actually passed to `OrientSingle`
243+ oa_raw.add_station(
244+ df_orient, stationName,
245+ period = period
246+ )
247+ # # Add the dataframe in `oa_boot`
248+ oa_boot.add_station(
249+ df_orient, stationName,
250+ period = period
251+ )
252+ ```
253+ 1 . Plot the results using `matplotlib.pyplot`
212254 - Original results w/ o bootstrap resampling
213255 ```python
214256 fig = oa_raw.plot()
@@ -217,6 +259,35 @@ for stationName in stationList:
217259 ```python
218260 fig = oa_boot.plot()
219261 ```
262+ 1 . Save the results
263+ ```py
264+ # # Write dataframe as csv, json, or pickle
265+ df_analysis = oa_boot.write(
266+ " /path/to/output/orientation/StationAX_020_040.csv" ,
267+ networkname = ' StationAX' ,
268+ format = ' csv'
269+ )
270+ ```
271+
272+ # ## How to read the result CSV file
273+
274+ - Saved dataframe can be loaded as
275+ ```py
276+ from azimpy import read_result
277+
278+ df_analysis = read_result(
279+ " /path/to/output/orientation/StationAX_020_040.csv"
280+ )
281+ ```
282+ - The column `station` is indexed
283+ - The estimated orientation is in the column `circular mean` . `circular_mean` and `h1azimuth` are aliases for `circular mean` .
284+ ```py
285+ df_analysis.h1azimuth
286+ ```
287+ - The uncertainty is in the column `Half 95 % CI ` . `uncertainty` is the alias for `Half 95 % CI ` .
288+ ```py
289+ df_analysis.uncertainty
290+ ```
220291
221292
222293# # Note
@@ -235,7 +306,7 @@ for stationName in stationList:
235306
236307# # Acknowledgments
237308
238- This package makes use of [`ObsPy v1 .3.0` ](https:// github.com/ obspy/ obspy) for [FDSN web client services](https:// www.fdsn.org/ webservices/ ) and processing seismograms.
309+ This package makes use of [`ObsPy>= 1 .3 .0` ](https:// github.com/ obspy/ obspy) for [FDSN web client services](https:// www.fdsn.org/ webservices/ ) and processing seismograms.
239310
240311
241312# # License
0 commit comments