pysmo.functions
Building-block functions for pysmo types.
The pysmo.functions module provides low-level functions that perform
common operations on pysmo types. They are intended as building blocks
for constructing more complex processing workflows.
Many functions accept a clone argument that controls whether the function
operates on the input directly or first creates a clone (via
deepcopy) and returns the modified copy. For example:
>>> from pysmo.functions import resample
>>> from pysmo.classes import SAC
>>> sac_seis = SAC.from_file("example.sac").seismogram
>>> new_delta = sac_seis.delta * 2
>>>
>>> # create a clone and modify data in clone instead of sac_seis:
>>> new_sac_seis = resample(sac_seis, new_delta, clone=True)
>>>
>>> # modify data in sac_seis directly:
>>> resample(sac_seis, new_delta)
>>>
Note
Avoid sac_seis = resample(sac_seis, new_delta, clone=True) when you intend
to modify sac_seis in place. The deepcopy operation is
computationally expensive and unnecessary — use resample(sac_seis, new_delta)
instead.
Hint
Additional functions may be found in pysmo.tools.
Functions:
| Name | Description |
|---|---|
clone_to_mini |
Create a new instance of a Mini class from a matching other one. |
copy_from_mini |
Copy attributes from a Mini instance to matching other one. |
crop |
Shorten a seismogram by providing new begin and end times. |
detrend |
Remove linear and/or constant trends from a seismogram. |
estimate_delta |
Estimate a canonical sampling interval from a set of near-equal deltas. |
merge |
Merge contiguous seismograms into a single seismogram. |
normalize |
Normalise a seismogram with its absolute max value. |
pad |
Pad seismogram data. |
resample |
Resample Seismogram data using the Fourier method. |
taper |
Apply a symmetric taper to the ends of a Seismogram. |
time2index |
Converts a specific timestamp to the corresponding data array index. |
window |
Returns an optionally padded and tapered window of a seismogram. |
clone_to_mini
Create a new instance of a Mini class from a matching other one.
This function creates a clone of an existing class by
copying the attributes defined in mini_cls from the source
to the target. Attributes only present in the source object are ignored,
potentially resulting in a smaller and more performant object.
If the source instance is missing an attribute for which a default is defined in the target class, then that default value for that attribute is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mini_cls
|
type[TMini]
|
The type of Mini class to create. |
required |
source
|
_AnyProto
|
The instance to clone (must contain all attributes present
in |
required |
update
|
dict | None
|
Update or add attributes in the returned |
None
|
Returns:
| Type | Description |
|---|---|
TMini
|
A new Mini instance type mini_cls. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the |
Examples:
Create a MiniSeismogram from a
SacSeismogram instance with
a new begin_time.
>>> from pysmo.functions import clone_to_mini
>>> from pysmo import MiniSeismogram
>>> from pysmo.classes import SAC
>>> import pandas as pd
>>> from datetime import timezone
>>> now = pd.Timestamp.now(timezone.utc)
>>> sac_seismogram = SAC.from_file("example.sac").seismogram
>>> mini_seismogram = clone_to_mini(MiniSeismogram, sac_seismogram, update={"begin_time": now})
>>> all(sac_seismogram.data == mini_seismogram.data)
True
>>> mini_seismogram.begin_time == now
True
>>>
See Also
copy_from_mini: Copy attributes
from a Mini instance to matching other one.
Source code in src/pysmo/functions/_utils.py
copy_from_mini
Copy attributes from a Mini instance to matching other one.
This function copies all attributes in the source Mini class
instance to a compatible target instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
_AnyMini
|
The Mini instance to copy attributes from. |
required |
target
|
_AnyProto
|
Compatible target instance. |
required |
update
|
dict | None
|
Update or add attributes in the target instance. |
None
|
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the |
See Also
clone_to_mini: Create a new
instance of a Mini class from a matching other one.
Source code in src/pysmo/functions/_utils.py
crop
Shorten a seismogram by providing new begin and end times.
This function calculates the indices corresponding to the provided new
begin and end times using time2index, then
slices the seismogram data array accordingly and updates the
begin_time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seismogram
|
T
|
|
required |
begin_time
|
Timestamp
|
New begin time. |
required |
end_time
|
Timestamp
|
New end time. |
required |
clone
|
bool
|
Operate on a clone of the input seismogram. |
False
|
Returns:
| Type | Description |
|---|---|
None | T
|
Cropped |
Raises:
| Type | Description |
|---|---|
ValueError
|
If new begin time is after new end time. |
Examples:
>>> from pysmo.functions import crop
>>> from pysmo.classes import SAC
>>> import pandas as pd
>>> sac_seis = SAC.from_file("example.sac").seismogram
>>> new_begin_time = sac_seis.begin_time + pd.Timedelta(seconds=10)
>>> new_end_time = sac_seis.end_time - pd.Timedelta(seconds=10)
>>> crop(sac_seis, new_begin_time, new_end_time)
>>>
Source code in src/pysmo/functions/_seismogram.py
detrend
detrend(seismogram: T, clone: bool = False) -> None | T
Remove linear and/or constant trends from a seismogram.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seismogram
|
T
|
Seismogram object. |
required |
clone
|
bool
|
Operate on a clone of the input seismogram. |
False
|
Returns:
| Type | Description |
|---|---|
None | T
|
Detrended |
Examples:
>>> import numpy as np
>>> import pytest
>>> from pysmo.functions import detrend
>>> from pysmo.classes import SAC
>>> sac_seis = SAC.from_file("example.sac").seismogram
>>> 0 == pytest.approx(np.mean(sac_seis.data), abs=1e-8)
np.False_
>>> detrend(sac_seis)
>>> 0 == pytest.approx(np.mean(sac_seis.data), abs=1e-8)
np.True_
>>>
Source code in src/pysmo/functions/_seismogram.py
estimate_delta
estimate_delta(
deltas: Sequence[PositiveTimedelta],
) -> PositiveTimedelta
Estimate a canonical sampling interval from a set of near-equal deltas.
Useful when several seismograms nominally share a sampling interval but
report values that differ only by measurement noise (e.g. clock drift
reflected in a reported sample rate) or floating-point noise. Returns the low
median of deltas: an order-independent choice that is always one of
the input values, rather than a synthetic average that none of the
seismograms actually have.
This does not check how close the given deltas are to each other; for a set of genuinely different sampling intervals it simply returns the low median of the sorted values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deltas
|
Sequence[PositiveTimedelta]
|
Sampling intervals to estimate a canonical value from. |
required |
Returns:
| Type | Description |
|---|---|
PositiveTimedelta
|
The estimated canonical sampling interval. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import pandas as pd
>>> from pysmo.functions import estimate_delta
>>> deltas = [
... pd.Timedelta(seconds=0.01),
... pd.Timedelta(seconds=0.010000000000001),
... pd.Timedelta(seconds=0.01),
... ]
>>> estimate_delta(deltas)
Timedelta('0 days 00:00:00.010000')
>>>
Source code in src/pysmo/functions/_seismogram.py
merge
merge(
seismograms: Sequence[Seismogram],
*,
delta: PositiveTimedelta | None = None,
auto_delta: bool = False,
gap_tolerance_factor: NonNegativeNumber = 0.5,
clone: bool = False
) -> None | T
Merge contiguous seismograms into a single seismogram.
Empty seismograms take no part in the merge arithmetic (they never
contribute data and never constrain sampling-interval or gap/overlap
checks) and are absent from the result if there are non-empty
seismograms to merge with. The remaining, non-empty seismograms are
merged in chronological order of begin_time, regardless of the order
they are given in, and must lie on a single regular sampling grid. By
default, this requires equal sampling intervals; when delta is
provided, each non-empty seismogram is first resampled to that common
interval using resample. If delta is
None and auto_delta is True, a common interval is estimated with
estimate_delta instead of requiring
an exact match — useful when sampling intervals only disagree by
measurement or floating-point noise.
A small amount of boundary timestamp jitter is allowed, bounded by
gap_tolerance_factor sampling intervals, so metadata rounding noise does
not block otherwise valid merges. If consecutive seismograms overlap
within this tolerance, the overlapping samples must match (compared with
allclose and its default tolerances, to accommodate
floating-point noise from e.g. prior resampling); they are verified and
the duplicates are discarded rather than concatenated.
When clone=False, the first seismogram in seismograms (as given —
not necessarily the chronologically first, and regardless of whether it
is itself empty) is modified in place and becomes the merged result: its
begin_time and data are overwritten to reflect the full,
chronologically-ordered merge of the non-empty seismograms. Other input
seismograms are never modified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seismograms
|
Sequence[Seismogram]
|
Seismograms to merge. May be given in any order; any mix
of types satisfying the |
required |
delta
|
PositiveTimedelta | None
|
Sampling interval to resample all non-empty seismograms to
before merging. If |
None
|
auto_delta
|
bool
|
Estimate a common sampling interval from the non-empty
seismograms with
|
False
|
gap_tolerance_factor
|
NonNegativeNumber
|
Maximum allowed boundary timestamp jitter between consecutive seismograms, as a fraction of the sampling interval. |
0.5
|
clone
|
bool
|
Operate on a clone of the first input seismogram. |
False
|
Returns:
| Type | Description |
|---|---|
None | T
|
Merged |
None | T
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import numpy as np
>>> import pandas as pd
>>> from pysmo import MiniSeismogram
>>> from pysmo.functions import merge
>>> first = MiniSeismogram(
... begin_time=pd.Timestamp("2010-02-27T06:30:00Z"),
... delta=pd.Timedelta(seconds=1),
... data=np.array([1.0, 2.0, 3.0]),
... )
>>> second = MiniSeismogram(
... begin_time=pd.Timestamp("2010-02-27T06:30:03Z"),
... delta=pd.Timedelta(seconds=1),
... data=np.array([4.0, 5.0]),
... )
>>> merged = merge([first, second], clone=True)
>>> merged.data
array([1., 2., 3., 4., 5.])
>>> merged.begin_time
Timestamp('2010-02-27 06:30:00+0000', tz='UTC')
Merging seismograms of different concrete types works the same way
at runtime. A bare list literal's inferred type comes from its
elements, though, and for a mix of concrete types that inferred type
may not satisfy the Seismogram bound at all, making the call fail
to type-check. Annotate the list as Sequence[Seismogram] to keep
the result type-checked:
>>> from collections.abc import Sequence
>>> from pysmo import Seismogram
>>> from pysmo.classes import GeoCsvSeismogram
>>> geocsv_seis = GeoCsvSeismogram(
... begin_time=pd.Timestamp("2010-02-27T06:30:05Z"),
... delta=pd.Timedelta(seconds=1),
... data=np.array([6.0, 7.0]),
... sid="IU_ANMO_00_LHZ",
... )
>>> mixed: Sequence[Seismogram] = [merged, geocsv_seis]
>>> merged_mixed = merge(mixed, clone=True)
>>> merged_mixed.data
array([1., 2., 3., 4., 5., 6., 7.])
>>>
The merged object's actual class is always seismograms[0]'s class,
regardless of what a type checker can infer — this is purely a
static-typing concern. If downstream code depends on the concrete
type, merging a single concrete type (the common case) lets it be inferred
automatically, without needing the annotation above.
Seismograms whose sampling intervals only disagree by measurement or
floating-point noise (see
estimate_delta) can be merged
with auto_delta=True instead of requiring an exact match:
>>> steady = MiniSeismogram(
... begin_time=pd.Timestamp("2010-02-27T06:30:00Z"),
... delta=pd.Timedelta(seconds=1),
... data=np.array([1.0, 2.0, 3.0]),
... )
>>> jittery = MiniSeismogram(
... begin_time=pd.Timestamp("2010-02-27T06:30:03Z"),
... delta=pd.Timedelta(seconds=1) + pd.Timedelta(nanoseconds=1),
... data=np.array([4.0, 5.0, 6.0]),
... )
>>> auto_merged = merge(
... [steady, jittery], auto_delta=True, clone=True
... )
>>> auto_merged.delta
Timedelta('0 days 00:00:01')
>>> auto_merged.data
array([1., 2., 3., 4., 5., 6.])
>>>
auto_delta estimates a canonical interval with
estimate_delta; it does not
verify that the seismograms genuinely belong on the same sampling
grid. Users are encouraged to inspect the resulting delta (as
above), or call
estimate_delta directly
beforehand, to confirm the estimate is the value expected rather
than assuming it silently.
Source code in src/pysmo/functions/_seismogram.py
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 | |
normalize
normalize(
seismogram: T,
t1: Timestamp | None = None,
t2: Timestamp | None = None,
clone: bool = False,
) -> None | T
Normalise a seismogram with its absolute max value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seismogram
|
T
|
Seismogram object. |
required |
t1
|
Timestamp | None
|
Start of the window used to find the maximum. If |
None
|
t2
|
Timestamp | None
|
End of the window used to find the maximum. If |
None
|
clone
|
bool
|
Operate on a clone of the input seismogram. |
False
|
Returns:
| Type | Description |
|---|---|
None | T
|
Normalised |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the absolute maximum of the data (within the optional time window) is zero, as normalisation would produce undefined results. |
Examples:
>>> import numpy as np
>>> from pysmo.functions import normalize
>>> from pysmo.classes import SAC
>>> sac_seis = SAC.from_file("example.sac").seismogram
>>> normalize(sac_seis)
>>> -1 <= np.max(sac_seis.data) <= 1
np.True_
>>>
Source code in src/pysmo/functions/_seismogram.py
pad
pad(
seismogram: T,
begin_time: Timestamp,
end_time: Timestamp,
mode: _ModeKind | _ModeFunc = "constant",
clone: bool = False,
**kwargs: Any
) -> None | T
Pad seismogram data.
This function calculates the indices corresponding to the provided new
begin and end times using time2index, then
pads the data array using numpy.pad and
updates the begin_time. Note that the
actual begin and end times are set by indexing, so they may be slightly
different than the provided input begin and end times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seismogram
|
T
|
|
required |
begin_time
|
Timestamp
|
New begin time. |
required |
end_time
|
Timestamp
|
New end time. |
required |
mode
|
_ModeKind | _ModeFunc
|
Pad mode to use (see |
'constant'
|
clone
|
bool
|
Operate on a clone of the input seismogram. |
False
|
kwargs
|
Any
|
Keyword arguments to pass to |
{}
|
Returns:
| Type | Description |
|---|---|
None | T
|
Padded |
Raises:
| Type | Description |
|---|---|
ValueError
|
If new begin time is after new end time. |
Examples:
>>> from pysmo.functions import pad
>>> from pysmo.classes import SAC
>>> import pandas as pd
>>> import numpy as np
>>>
>>> sac_seis = SAC.from_file("example.sac").seismogram
>>> original_length = len(sac_seis.data)
>>> sac_seis.data
array([-47201., -47361., -47511., ..., -82144., -71072., -59960.],
shape=(57465,))
>>> new_begin_time = sac_seis.begin_time - pd.Timedelta(seconds=10)
>>> new_end_time = sac_seis.end_time + pd.Timedelta(seconds=10)
>>> pad(sac_seis, new_begin_time, new_end_time)
>>> np.isclose(len(sac_seis.data), original_length + 20 / sac_seis.delta.total_seconds())
np.True_
>>> sac_seis.data
array([0., 0., 0., ..., 0., 0., 0.], shape=(57865,))
>>>
Source code in src/pysmo/functions/_seismogram.py
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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
resample
resample(
seismogram: T,
delta: PositiveTimedelta,
clone: bool = False,
) -> None | T
Resample Seismogram data using the Fourier method.
This function uses scipy.signal.resample to resample the data to a
new sampling interval. If the new sampling interval is identical to the
current one, no action is taken.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seismogram
|
T
|
Seismogram object. |
required |
delta
|
PositiveTimedelta
|
New sampling interval. |
required |
clone
|
bool
|
Operate on a clone of the input seismogram. |
False
|
Returns:
| Type | Description |
|---|---|
None | T
|
Resampled |
Examples:
>>> from pysmo.functions import resample
>>> from pysmo.classes import SAC
>>> sac_seis = SAC.from_file("example.sac").seismogram
>>> len(sac_seis.data)
57465
>>> original_delta = sac_seis.delta
>>> new_delta = original_delta * 2
>>> resample(sac_seis, new_delta)
>>> len(sac_seis.data)
28732
>>>
Source code in src/pysmo/functions/_seismogram.py
taper
taper(
seismogram: T,
taper_width: NonNegativeTimedelta | UnitFloat,
window_type: _WindowType = "hann",
clone: bool = False,
) -> None | T
Apply a symmetric taper to the ends of a Seismogram.
The taper width is understood as the portion of the seismogram affected
by the taper window function. It can be provided as an absolute duration
(non-negative Timedelta), or as a fraction of
seismogram length (float between 0 and 1). Internally, absolute
durations are converted to fractions by dividing by the total seismogram
duration, and absolute durations should therefore not exceed the total
seismogram duration.
The shape of the windowing function is calculated by calling the scipy
get_window() function using the number
of samples corresponding to the fraction specified above, then it is split
in half and applied to the beginning and end of the seismogram data. Thus
taper_width=0 corresponds to a rectangular window (i.e. no tapering), and
taper_width=1 to a symmetric taper applied to the entire length of the
seismogram. A value of e.g. 0.5 applies the "ramp up" portion of the
window to the first quarter of the seismogram, while the "ramp down" portion
of the window is applied to the last quarter.
Warning
The scipy get_window() function
is a helper function that calculates a large variety of window shapes,
which do not all make sense in this application (e.g. boxcar or tukey).
Users are encouraged to read the documentation of the actual window
functions available via
get_window() to see if they can be
split in the middle and used as "ramp up" and "ramp down" functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seismogram
|
T
|
Seismogram object. |
required |
taper_width
|
NonNegativeTimedelta | UnitFloat
|
Width of the taper to use. |
required |
window_type
|
_WindowType
|
Function to calculate taper shape (see
|
'hann'
|
clone
|
bool
|
Operate on a clone of the input seismogram. |
False
|
Returns:
| Type | Description |
|---|---|
None | T
|
Tapered |
Note
If taper_width resolves to fewer than 2 samples, no taper is applied.
This can occur when a very small Timedelta is
provided.
Examples:
>>> from pysmo.functions import taper, detrend
>>> from pysmo.classes import SAC
>>> sac_seis = SAC.from_file("example.sac").seismogram
>>> detrend(sac_seis)
>>> sac_seis.data
array([ 821.53861155, 661.55931267, 511.58001379, ...,
-32931.93353333, -21859.9128322 , -10747.89213108], shape=(57465,))
>>> taper(sac_seis, 0.2)
>>> sac_seis.data
array([ 0.00000000e+00, 4.94398663e-05, 1.52926246e-04, ...,
-9.84431924e-03, -1.63364213e-03, -0.00000000e+00], shape=(57465,))
>>>
Source code in src/pysmo/functions/_seismogram.py
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 | |
time2index
time2index(
seismogram: Seismogram,
time: Timestamp,
allow_out_of_bounds: bool = False,
) -> int
Converts a specific timestamp to the corresponding data array index.
Seismic data is sampled at discrete intervals. When a requested time does not align perfectly with a sample, this function selects the nearest index using the following rules:
- If the time is within 0.1% of a sample interval of an integer, it "snaps" to that integer to account for floating-point jitter.
- Use standard rounding (0.5 rounds up to the next index) otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seismogram
|
Seismogram
|
Seismogram object. |
required |
time
|
Timestamp
|
The absolute time to convert. |
required |
allow_out_of_bounds
|
bool
|
If True, returns the calculated index even if it falls outside the seismogram's data range [0, len-1]. |
False
|
Returns:
| Type | Description |
|---|---|
int
|
The index of the sample closest to the provided time. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the calculated index is outside the data array and
|
Source code in src/pysmo/functions/_seismogram.py
window
window(
seismogram: T,
window_begin_time: Timestamp,
window_end_time: Timestamp,
ramp_width: NonNegativeTimedelta | NonNegativeNumber,
window_type: _WindowType = "hann",
same_shape: bool = False,
clone: bool = False,
) -> None | T
Returns an optionally padded and tapered window of a seismogram.
This function combines the crop,
detrend, taper, and
optionally pad functions to return a 'windowed'
seismogram. Its purpose is to focus on a specific time window of interest,
while also (optionally) preserving the original seismogram length and
tapering the signal before and after the window.
Tip
Note that the window defined by window_begin_time and
window_end_time excludes the tapered sections, so the total length
of the window will be the provided window length plus the tapered
sections of the signal. This behaviour is a bit different from
taper(), where the taper is applied to the
entire signal. In a sense the tapering here is applied to the 'outside'
of the region of interest rather than the 'inside'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seismogram
|
T
|
Seismogram object. |
required |
window_begin_time
|
Timestamp
|
Begin time of the window. |
required |
window_end_time
|
Timestamp
|
End time of the window. |
required |
ramp_width
|
NonNegativeTimedelta | NonNegativeNumber
|
Duration of the taper on each side.
Note: Total duration = window length + (2 * |
required |
window_type
|
_WindowType
|
Taper method to use (see |
'hann'
|
same_shape
|
bool
|
If True, pad the seismogram to its original length after windowing. |
False
|
clone
|
bool
|
Operate on a clone of the input seismogram. |
False
|
Returns:
| Type | Description |
|---|---|
None | T
|
Windowed |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the ramp extends beyond the seismogram on either side. |
Examples:
In this example we focus on a window starting 600 seconds after the
begin_time of the seismogram and lasting for 1200 seconds. Setting the
ramp_width to 300 seconds means that the actual window will start 300
seconds earlier and end 300 seconds later than the specified window
begin and end times.
>>> from pysmo.functions import window, detrend
>>> from pysmo.classes import SAC
>>> from pysmo.tools.plotutils import plotseis
>>> import pandas as pd
>>>
>>> sac_seis = SAC.from_file("example.sac").seismogram
>>> ramp_width = pd.Timedelta(seconds=300)
>>> window_begin_time = sac_seis.begin_time + pd.Timedelta(seconds=600)
>>> window_end_time = window_begin_time + pd.Timedelta(seconds=1200)
>>> windowed_seis = window(sac_seis, window_begin_time, window_end_time, ramp_width, same_shape=True, clone=True)
>>> detrend(sac_seis)
>>> fig = plotseis(sac_seis, windowed_seis)
>>>
Source code in src/pysmo/functions/_seismogram.py
908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 | |