pysmo.tools.plotutils
Utilities for plotting with pysmo types.
Provides functions to convert a Seismogram's time axis
into arrays matplotlib can plot directly
(time_array,
unix_time_array,
relative_time_array), plus a
basic plotting helper (plotseis).
Functions:
| Name | Description |
|---|---|
plotseis |
Plot Seismogram objects. |
relative_time_array |
Create an array of elapsed seconds relative to a reference time. |
time_array |
Create an array containing Matplotlib dates. |
unix_time_array |
Create an array containing unix epoch dates. |
plotseis
plotseis(
*seismograms: Seismogram,
outfile: str = "",
showfig: bool = True,
title: str = "",
**kwargs: Any
) -> Figure
Plot Seismogram objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seismograms
|
Seismogram
|
One or more seismogram objects. If a 'label' attribute is found it will be used to label the trace in the plot. |
()
|
outfile
|
str
|
Optionally save figure to this filename. |
''
|
showfig
|
bool
|
Display figure. |
True
|
title
|
str
|
Optionally set figure title. |
''
|
kwargs
|
Any
|
Optional keyword arguments passed directly to |
{}
|
Returns:
| Type | Description |
|---|---|
Figure
|
The matplotlib |
Examples:
>>> from pysmo.classes import SAC
>>> from pysmo.tools.plotutils import plotseis
>>> seis = SAC.from_file("example.sac").seismogram
>>> fig = plotseis(seis)
>>>
Source code in src/pysmo/tools/plotutils.py
relative_time_array
relative_time_array(
seismogram: Seismogram, reference: Timestamp
) -> ndarray
Create an array of elapsed seconds relative to a reference time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seismogram
|
Seismogram
|
Seismogram object. |
required |
reference
|
Timestamp
|
Reference time. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Array containing the elapsed time (in seconds) of each point in the |
ndarray
|
seismogram data, relative to |
ndarray
|
points before |
Examples:
>>> from pysmo.tools.plotutils import relative_time_array
>>> from pysmo.classes import SAC
>>> seis = SAC.from_file("example.sac").seismogram
>>> reference = seis.begin_time + (seis.end_time - seis.begin_time) / 2
>>> rel_times = relative_time_array(seis, reference)
>>> bool(rel_times[0] < 0 < rel_times[-1])
True
>>>
Source code in src/pysmo/tools/plotutils.py
time_array
time_array(seismogram: Seismogram) -> ndarray
Create an array containing Matplotlib dates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seismogram
|
Seismogram
|
Seismogram object. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Array containing the Matplotlib dates (number of days since the |
ndarray
|
Matplotlib epoch, default 1970-01-01) of each point in the |
ndarray
|
seismogram data. |
Examples:
>>> from pysmo.tools.plotutils import time_array
>>> from pysmo.classes import SAC
>>> seis = SAC.from_file("example.sac").seismogram
>>> seis_data = seis.data
>>> seis_times = time_array(seis)
>>> for t, v in zip(seis_times, seis_data):
... print(t,v)
...
14667.280625804839 -47201.0
14667.280626383543 -47361.0
14667.280626962245 -47511.0
14667.28062754095 -47666.0
14667.280628119654 -47826.0
14667.280628698358 -47993.0
...
>>>
Source code in src/pysmo/tools/plotutils.py
unix_time_array
unix_time_array(seismogram: Seismogram) -> ndarray
Create an array containing unix epoch dates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seismogram
|
Seismogram
|
Seismogram object. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Array containing the unix epoch times (number of seconds since 1970) |
ndarray
|
of each point in the seismogram data. |
Examples:
>>> from pysmo.classes import SAC
>>> from pysmo.tools.plotutils import unix_time_array
>>> seis = SAC.from_file("example.sac").seismogram
>>> seis_data = seis.data
>>> seis_times = unix_time_array(seis)
>>> for t, v in zip(seis_times, seis_data):
... print(t,v)
...
1267253046.069538 -47201.0
1267253046.119538 -47361.0
1267253046.169538 -47511.0
1267253046.2195382 -47666.0
1267253046.2695382 -47826.0
1267253046.319538 -47993.0
...
>>>