Functions#
Pysmo provides functions that perform common operations on the types of data that match pysmo's types.
azimuth(point1, point2, ellps=DEFAULT_ELLPS)
#
Calculate azimuth between two points.
info
For more information see: https://pyproj4.github.io/pyproj/stable
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point1 |
Location
|
Name of the event object providing coordinates of the origin point. |
required |
point2 |
Location
|
Name of the station object providing coordinates of the target point. |
required |
ellps |
str
|
Ellipsoid to use for azimuth calculation |
DEFAULT_ELLPS
|
Returns:
Type | Description |
---|---|
float
|
Azimuth in degrees from point 1 to point 2. |
Examples:
>>> from pysmo import SAC, azimuth
>>> sacobj = SAC.from_file('testfile.sac')
>>> # the SAC class provides both event and station
>>> azimuth(sacobj.event, sacobj.station)
181.9199258637492
>>> # Use Clarke 1966 instead of default
>>> azimuth(sacobj.event, sacobj.station, ellps='clrk66')
181.92001941872516
Source code in pysmo/functions.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
|
backazimuth(point1, point2, ellps=DEFAULT_ELLPS)
#
Calculate backazimuth (in DEG) between two points.
info
For more information see: https://pyproj4.github.io/pyproj/stable
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point1 |
Location
|
Name of the event object providing coordinates of the origin point. |
required |
point2 |
Location
|
Name of the station object providing coordinates of the target point. |
required |
ellps |
str
|
Ellipsoid to use for azimuth calculation |
DEFAULT_ELLPS
|
Returns:
Type | Description |
---|---|
float
|
Backzimuth in degrees from point 2 to point 1 |
Examples:
>>> from pysmo import SAC, backazimuth
>>> sacobj = SAC.from_file('testfile.sac')
>>> # the SAC class provides both event and station
>>> backazimuth(sacobj.event, sacobj.station)
2.4677533885335947
>>> # Use Clarke 1966 instead of default
>>> backazimuth(sacobj.event, sacobj.station, ellps='clrk66')
2.467847115319614
Source code in pysmo/functions.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
|
detrend(seismogram)
#
Remove linear and/or constant trends from a seismogram.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seismogram |
Seismogram
|
Seismogram object. |
required |
Returns:
Type | Description |
---|---|
MiniSeismogram
|
Detrended seismogram. |
Note
This function is also available as a method in the MiniSeismogram class. Thus, if you intend detrending data of a MiniSeismogram object in-place, instead of writing:
my_seis.data = detrend(my_seis)
you should instead use:
my_seis.detrend()
Examples:
>>> import numpy as np
>>> import pytest
>>> from pysmo import SAC, detrend
>>> original_seis = SAC.from_file('testfile.sac').seismogram
>>> assert 0 == pytest.approx(np.mean(original_seis.data), abs=1e-11)
False
>>> detrended_seis = detrend(original_seis)
>>> assert 0 == pytest.approx(np.mean(detrended_seis.data), abs=1e-11)
True
Source code in pysmo/functions.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
distance(point1, point2, ellps=DEFAULT_ELLPS)
#
Calculate the great circle distance (in metres) between two points.
info
For more information see: https://pyproj4.github.io/pyproj/stable
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point1 |
Location
|
Name of the event object providing coordinates of the origin point. |
required |
point2 |
Location
|
Name of the station object providing coordinates of the target point. |
required |
ellps |
str
|
Ellipsoid to use for distance calculation |
DEFAULT_ELLPS
|
Returns:
Type | Description |
---|---|
float
|
Great Circle Distance in metres. |
Examples:
>>> from pysmo import SAC, distance
>>> sacobj = SAC.from_file('testfile.sac')
>>> # the SAC class provides both event and station
>>> distance(sacobj.event, sacobj.station)
1889154.9940066522
>>> # Use Clarke 1966 instead of default
>>> distance(sacobj.event, sacobj.station, ellps='clrk66')
1889121.778136402
Source code in pysmo/functions.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
normalize(seismogram)
#
Normalize a seismogram with its absolute max value
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seismogram |
Seismogram
|
Seismogram object. |
required |
Returns:
Type | Description |
---|---|
MiniSeismogram
|
Normalized seismogram. |
Note
This function is also available as a method in the MiniSeismogram class. Thus, if you intend normalizing data of a MiniSeismogram object in-place, instead of writing:
my_seis.data = normalize(my_seis)
you should instead use:
my_seis.normalize()
Examples:
>>> import numpy as np
>>> from pysmo import SAC, normalize
>>> original_seis = SAC.from_file('testfile.sac').seismogram
>>> normalized_seis = normalize(original_seis)
>>> assert np.max(normalized_seis.data) <= 1
True
Source code in pysmo/functions.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
plotseis(*seismograms, outfile='', showfig=True, title='', **kwargs)
#
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 |
dict
|
Optionally add kwargs to pass to the plot command |
{}
|
Examples:
>>> from pysmo import SAC, plotseis
>>> seis = SAC.from_file('testfile.sac').seismogram
>>> plotseis(seis)
Source code in pysmo/functions.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
resample(seismogram, delta)
#
Resample Seismogram object data using the Fourier method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seismogram |
Seismogram
|
Seismogram object. |
required |
delta |
float
|
New sampling interval. |
required |
Returns:
Type | Description |
---|---|
MiniSeismogram
|
Resampled seismogram. |
Note
This function is also available as a method in the MiniSeismogram class. Thus, if you intend resampling data of a MiniSeismogram object in-place, instead of writing:
my_seis.data = resample(my_seis)
you should instead use:
my_seis.resample()
Examples:
>>> from pysmo import SAC, resample
>>> original_seis = SAC.from_file('testfile.sac').seismogram
>>> len(original_seis)
180000
>>> original_delta = original_seis.delta
>>> new_delta = original_delta * 2
>>> resampled_seis = resample(original_seis, new_delta)
>>> len(resampled_seis)
90000
Source code in pysmo/functions.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|