Skip to content

Commit fb7214f

Browse files
authored
Merge pull request #43 from paudetseis/save-rfs
Save RFs and modify plotting options
2 parents 3cd4329 + 4f7ac27 commit fb7214f

File tree

5 files changed

+192
-136
lines changed

5 files changed

+192
-136
lines changed

docs/rfpy.rst

+4-6
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ Also, the following packages are required:
3636

3737
- `stdb <https://github.com/paudetseis/StDb>`_
3838
- `spectrum <https://github.com/cokelaer/spectrum>`_
39-
- `cartopy <https://scitools.org.uk/cartopy/docs/latest/>`_
4039

4140
Other required packages (e.g., ``obspy``)
4241
will be automatically installed by ``stdb``.
@@ -49,7 +48,7 @@ where ``RfPy`` can be installed along with some of its dependencies.
4948

5049
.. sourcecode:: bash
5150

52-
conda create -n rfpy python=3.9 obspy cartopy -c conda-forge
51+
conda create -n rfpy python=3.10 obspy spectrum -c conda-forge
5352

5453
Activate the newly created environment:
5554

@@ -62,14 +61,13 @@ Install remaining dependencies using ``pip`` inside the ``rfpy`` environment:
6261
.. sourcecode:: bash
6362

6463
pip install stdb
65-
pip install spectrum
6664

67-
Installing from Pypi
68-
--------------------
65+
Installing from GitHub master branch
66+
------------------------------------
6967

7068
.. sourcecode:: bash
7169

72-
pip install rfpy
70+
pip install rfpy@git+https://github.com/paudetseis/rfpy
7371

7472
Installing from source
7573
----------------------

rfpy/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23-
__version__ = '0.1.3'
23+
__version__ = '0.1.4'
2424

2525
__author__ = 'Pascal Audet'
2626

rfpy/binning.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,20 @@ def bin(stream1, stream2=None, typ='baz', nbin=36+1, pws=False,
7070
raise(Exception("Type has to be 'baz' or 'slow' or 'dist'"))
7171

7272
if typ == 'baz':
73+
stat = [stream1[i].stats.baz for i in range(len(stream1))]
7374
bmin = 0
7475
bmax = 360
75-
stat = [stream1[i].stats.baz for i in range(len(stream1))]
76+
alt = np.mean([stream1[i].stats.slow for i in range(len(stream1))])
7677
elif typ == 'slow':
7778
stat = [stream1[i].stats.slow for i in range(len(stream1))]
7879
bmin = np.min(np.array(stat))
7980
bmax = np.max(np.array(stat))
81+
alt = np.mean([stream1[i].stats.baz for i in range(len(stream1))])
8082
elif typ == 'dist':
8183
stat = [stream1[i].stats.gac for i in range(len(stream1))]
8284
bmin = np.min(np.array(stat))
8385
bmax = np.max(np.array(stat))
86+
alt = np.mean([stream1[i].stats.baz for i in range(len(stream1))])
8487

8588
# Define bins
8689
bins = np.linspace(bmin, bmax, nbin)
@@ -126,16 +129,16 @@ def bin(stream1, stream2=None, typ='baz', nbin=36+1, pws=False,
126129
trace.stats.nbin = nb
127130
if typ == 'baz':
128131
trace.stats.baz = bins[i]
129-
trace.stats.slow = None
132+
trace.stats.slow = alt
130133
trace.stats.nbin = nb
131134
elif typ == 'slow':
132135
trace.stats.slow = bins[i]
133-
trace.stats.baz = None
136+
trace.stats.baz = alt
134137
trace.stats.nbin = nb
135138
elif typ == 'dist':
136139
trace.stats.dist = bins[i]
137140
trace.stats.slow = None
138-
trace.stats.baz = None
141+
trace.stats.baz = alt
139142
trace.stats.nbin = nb
140143
if not pws:
141144
weight = np.ones(len(stream[0].data))

rfpy/plotting.py

+49-48
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ def wiggle(stream1, stream2=None, sort=None, tmin=0., tmax=30, normalize=True,
146146

147147
# PLot wiggles according to either baz or slowness
148148
def wiggle_bins(stream1, stream2=None, tr1=None, tr2=None,
149-
btyp='baz', tmin=0., tmax=30., xtyp='time', scale=None,
150-
norm=None, save=False, title=None, form='png'):
149+
btyp='baz', trange=[0., 30.], xtyp='time',
150+
norm=None, save=None, folder=None, show=True):
151151
"""
152152
Function to plot receiver function according to either baz or
153153
slowness bins. By default,
@@ -167,16 +167,19 @@ def wiggle_bins(stream1, stream2=None, tr1=None, tr2=None,
167167
Trace to plot at the top of ``stream2``
168168
btyp : str
169169
Type of plot to produce (either 'baz', 'slow', or 'dist')
170-
tmax : float
171-
Maximum x-axis value displayed in the Figure.
170+
trange : list of two floats
171+
Range of x-axis values displayed in the Figure.
172172
xtyp : str
173173
Type of x-axis label (either 'time' or 'depth')
174-
scale : float
175-
Scale factor applied to trace amplitudes for plotting
176-
save : bool
177-
Whether or not to save the Figure
178-
title : str
179-
Title of plot
174+
norm : float
175+
Normalization value applied to all traces. If not specified,
176+
default amplitude ranges will be set.
177+
save : str
178+
Filename of figure to be saved, including extension.
179+
folder : str
180+
Folder name where figure will be saved.
181+
show : bool
182+
Whether or not to show the figure upon execution.
180183
181184
"""
182185

@@ -188,35 +191,31 @@ def wiggle_bins(stream1, stream2=None, tr1=None, tr2=None,
188191
raise(Exception("Cannot plot by slowness if data is migrated"))
189192

190193
# Figure out scaling here
191-
if scale:
192-
maxval = scale
193-
maxvalT = maxval
194-
else:
195-
if norm:
196-
for tr in stream1:
194+
if norm is not None:
195+
for tr in stream1:
196+
tr.data /= norm
197+
if stream2:
198+
for tr in stream2:
197199
tr.data /= norm
198-
if stream2:
199-
for tr in stream2:
200-
tr.data /= norm
201-
if btyp == 'baz':
202-
maxval = 10.
203-
maxvalT = maxval
204-
elif btyp == 'slow':
205-
maxval = 0.001
206-
maxvalT = 2.*maxval
207-
elif btyp == 'dist':
208-
maxval = 1
209-
maxvalT = maxval
210-
else:
211-
if btyp == 'baz':
212-
maxval = 100
213-
maxvalT = maxval
214-
elif btyp == 'slow':
215-
maxval = 0.02
216-
maxvalT = maxval
217-
elif btyp == 'dist':
218-
maxval = 20
219-
maxvalT = maxval
200+
if btyp == 'baz':
201+
maxval = 10.
202+
maxvalT = maxval
203+
elif btyp == 'slow':
204+
maxval = 0.001
205+
maxvalT = 2.*maxval
206+
elif btyp == 'dist':
207+
maxval = 1
208+
maxvalT = maxval
209+
else:
210+
if btyp == 'baz':
211+
maxval = 100
212+
maxvalT = maxval
213+
elif btyp == 'slow':
214+
maxval = 0.02
215+
maxvalT = maxval
216+
elif btyp == 'dist':
217+
maxval = 20
218+
maxvalT = maxval
220219

221220
# Time axis
222221
nn = stream1[0].stats.npts
@@ -270,7 +269,7 @@ def wiggle_bins(stream1, stream2=None, tr1=None, tr2=None,
270269
ax1.set_yticks(())
271270
ax1.set_xticks(())
272271
ax1.set_title('Radial')
273-
ax1.set_xlim(tmin, tmax)
272+
ax1.set_xlim(trange[0], trange[1])
274273

275274
# Plot binned SV traces in back-azimuth on bottom left
276275
for tr in stream1:
@@ -299,7 +298,7 @@ def wiggle_bins(stream1, stream2=None, tr1=None, tr2=None,
299298
ax2.plot(time, y+tr.data*maxval,
300299
linewidth=0.25, c='k')
301300

302-
ax2.set_xlim(tmin, tmax)
301+
ax2.set_xlim(trange[0], trange[1])
303302

304303
if btyp == 'baz':
305304
ax2.set_ylim(-5, 370)
@@ -337,7 +336,7 @@ def wiggle_bins(stream1, stream2=None, tr1=None, tr2=None,
337336
linewidth=0)
338337
ax3.plot(time, tr2.data,
339338
linewidth=0.25, c='k')
340-
ax3.set_xlim(tmin, tmax)
339+
ax3.set_xlim(trange[0], trange[1])
341340
ax3.set_ylim(-1.*ylimT, ylimT)
342341
ax3.set_yticks(())
343342
ax3.set_xticks(())
@@ -371,7 +370,7 @@ def wiggle_bins(stream1, stream2=None, tr1=None, tr2=None,
371370
ax4.plot(time, y+tr.data*maxvalT,
372371
linewidth=0.25, c='k')
373372

374-
ax4.set_xlim(tmin, tmax)
373+
ax4.set_xlim(trange[0], trange[1])
375374

376375
if btyp == 'baz':
377376
ax4.set_ylim(-5, 370)
@@ -390,13 +389,15 @@ def wiggle_bins(stream1, stream2=None, tr1=None, tr2=None,
390389
if not ax3:
391390
ax4.set_title('Transverse')
392391

393-
if title:
394-
plt.suptitle(title)
395-
396392
if save:
397-
plt.savefig('RF_PLOTS/' + stream1[0].stats.station +
398-
'.' + title + '.' + form, format=form)
399-
else:
393+
if folder is not None:
394+
plt.savefig(folder + '/' + stream1[0].stats.station +
395+
'.' + save, format=save.split('.')[-1], dpi=300)
396+
else:
397+
plt.savefig('RF_PLOTS/' + stream1[0].stats.station +
398+
'.' + save, format=save.split('.')[-1], dpi=300)
399+
400+
if show:
400401
plt.show()
401402

402403
plt.close()

0 commit comments

Comments
 (0)