-
Notifications
You must be signed in to change notification settings - Fork 20
Merging Wenjie's edits from years ago #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lsawade
wants to merge
42
commits into
adjtomo:master
Choose a base branch
from
lsawade:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
05fd741
Add more debug output information and fix bugs
wjlei1990 ebe2a32
change c_1(minimum window length parameter) to array
wjlei1990 f64bebe
Add methods that write plain text window output file
wjlei1990 1598642
Change function order(put global data quality check in the beginning)
wjlei1990 8bb59cc
modify window selection strategy(selection region based on surface wave)
wjlei1990 7b4945b
Merge branch 'devel' of https://github.com/wjlei1990/pyflex into devel
wjlei1990 4e6b093
slightly modify curtail window method, data_quality_check return meth…
wjlei1990 22d707c
fix code formatting issue
wjlei1990 d71ccbc
Merge remote-tracking branch 'upstream/master' into devel
wjlei1990 e5d98e5
reset some values to default ones
wjlei1990 dc492bb
fix code formatting issues suggested by Lion
wjlei1990 9eedb17
fix s2n_limit naming issue
wjlei1990 03abfcb
close figure handle after plotting
wjlei1990 c097245
add checks for plotting
wjlei1990 fd0a4b6
fix bug in noise_end_index calculation and refine __eq__ in Window
wjlei1990 6bdc376
Merge branch 'devel' of https://github.com/wjlei1990/pyflex into devel
wjlei1990 3ba2462
Merge branch 'devel' of https://github.com/wjlei1990/pyflex into devel
wjlei1990 03e96e5
PEP8 formatting issue
wjlei1990 ac833d0
update baseline image to pass the test
wjlei1990 19ac9a4
add channel_id_2(to keep track of synt trace id)
wjlei1990 45cc23a
remove the image test since it depands on the specific version of mat…
wjlei1990 20e143a
refactor and refine the code in selection mode and noise region rejec…
wjlei1990 945ab09
add 'is None' test to avoid 0 value conditional trap
wjlei1990 e36297e
add tests to check noise index
wjlei1990 3466e98
change the obspy module import path according to updates in obspy
wjlei1990 cfc45f3
change reject_on_selection_mode to window.center
wjlei1990 aba6768
obspy 1.1.1 compatability(python3)
wjlei1990 f0339c0
Merge remote-tracking branch 'upstream/master' into merge
wjlei1990 26ee35a
change test benchmark figure
wjlei1990 0c5111c
refine and extend selection mode
wjlei1990 04b884c
fix signal_end_idx issue to catch signal after minor-arc surface wave
wjlei1990 ecc7993
bug gix
wjlei1990 4b40aa7
add more information into window
wjlei1990 2de5fde
Merge branch 'merge' of https://github.com/wjlei1990/pyflex into merge
wjlei1990 5573b19
improve window selection region based on arrival time mode
wjlei1990 ca799fc
Merge pull request #1 from lsawade/merge
lsawade 8019cf0
blub
lsawade bc1b90d
Merge branch 'adjtomo-master'
lsawade b844db0
Finally the tests are passing
lsawade c876a8a
removed setup.py
lsawade f70f220
Fixed a bug, that made it hard to select multi orbit arrivals.
lsawade d800bc5
Update bool
lsawade File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,17 +20,21 @@ class Config(object): | |||||||||||
| def __init__(self, min_period, max_period, stalta_waterlevel=0.07, | ||||||||||||
| tshift_acceptance_level=10.0, tshift_reference=0.0, | ||||||||||||
| dlna_acceptance_level=1.3, dlna_reference=0.0, | ||||||||||||
| cc_acceptance_level=0.7, s2n_limit=1.5, earth_model="ak135", | ||||||||||||
| cc_acceptance_level=0.7, earth_model="ak135", | ||||||||||||
| s2n_limit=1.5, s2n_limit_energy=1.5, | ||||||||||||
| min_surface_wave_velocity=3.0, | ||||||||||||
| max_time_before_first_arrival=50.0, | ||||||||||||
| max_surface_wave_velocity=4.2, | ||||||||||||
| max_time_before_first_arrival=None, | ||||||||||||
| max_time_after_last_arrival=None, | ||||||||||||
| c_0=1.0, c_1=1.5, c_2=0.0, | ||||||||||||
| c_3a=4.0, c_3b=2.5, c_4a=2.0, c_4b=6.0, | ||||||||||||
| check_global_data_quality=False, snr_integrate_base=3.5, | ||||||||||||
| snr_max_base=3.0, noise_start_index=0, noise_end_index=None, | ||||||||||||
| signal_start_index=None, signal_end_index=-1, | ||||||||||||
| signal_start_index=None, signal_end_index=None, | ||||||||||||
| window_weight_fct=None, | ||||||||||||
| window_signal_to_noise_type="amplitude", | ||||||||||||
| resolution_strategy="interval_scheduling"): | ||||||||||||
| resolution_strategy="interval_scheduling", | ||||||||||||
| selection_mode=None): | ||||||||||||
| """ | ||||||||||||
| Central configuration object for Pyflex. | ||||||||||||
|
|
||||||||||||
|
|
@@ -105,28 +109,51 @@ def __init__(self, min_period, max_period, stalta_waterlevel=0.07, | |||||||||||
| same number of samples as the data. | ||||||||||||
| :type cc_acceptance_level: float or :class:`numpy.ndarray` | ||||||||||||
|
|
||||||||||||
| :param s2n_limit: Limit of the signal to noise ratio per window. If | ||||||||||||
| the maximum amplitude of the window over the maximum amplitude | ||||||||||||
| of the global noise of the waveforms is smaller than this | ||||||||||||
| :param s2n_limit: Limit of the amplitude signal-to-noise | ||||||||||||
| ratio per window. If the maximum amplitude of the window over | ||||||||||||
| the maximum amplitude of the global noise of the waveforms is | ||||||||||||
| smaller than this window, then it will be rejected. Can be | ||||||||||||
| either a single value or an array with the same number of | ||||||||||||
| samples as the data. | ||||||||||||
| :type s2n_limit: float or :class:`numpy.ndarray` | ||||||||||||
|
|
||||||||||||
| :param s2n_limit_energy: Limit of the energy signal-to-noise ratio | ||||||||||||
| per window. If the average energy of the window over the average | ||||||||||||
| energy of the global noise of the waveforms is smaller than this | ||||||||||||
| window, then it will be rejected. Can be either a single value | ||||||||||||
| or an array with the same number of samples as the data. | ||||||||||||
| :type s2n_limit: float or :class:`numpy.ndarray` | ||||||||||||
| :type s2n_limit_energy: float or :class:`numpy.ndarray` | ||||||||||||
|
|
||||||||||||
| :param earth_model: The earth model used for the traveltime | ||||||||||||
| calculations. Either ``"ak135"`` or ``"iasp91"``. | ||||||||||||
| :type earth_model: str | ||||||||||||
|
|
||||||||||||
| :param min_surface_wave_velocity: The minimum surface wave velocity | ||||||||||||
| in km/s. All windows containing data later then this velocity | ||||||||||||
| will be rejected. Only used if station and event information is | ||||||||||||
| available. | ||||||||||||
| in km/s. The two values, min_surface_wave_velocity and | ||||||||||||
| max_surface_wave_velocity are used to calculate surface wave time | ||||||||||||
| region. All windows containing data earlier than the min velocity | ||||||||||||
| and later than the max velocity will be treated as surface waves. | ||||||||||||
| Only used if station and event information is available. | ||||||||||||
| :type min_surface_wave_velocity: float | ||||||||||||
|
|
||||||||||||
| :param max_surface_wave_velocity: The maxium surface wave velocity | ||||||||||||
| in km/s. The two values, min_surface_wave_velocity and | ||||||||||||
| max_surface_wave_velocity are used to calculate surface wave time | ||||||||||||
| region. All windows containing data earlier than the min velocity | ||||||||||||
| and later than the max velocity will be treated as surface waves. | ||||||||||||
| Only used if station and event information is available. | ||||||||||||
| :type max_surface_wave_velocity: float | ||||||||||||
|
|
||||||||||||
| :param max_time_before_first_arrival: This is the minimum starttime | ||||||||||||
| of any window in seconds before the first arrival. No windows will | ||||||||||||
| have a starttime smaller than this. | ||||||||||||
| :type max_time_before_first_arrival: float | ||||||||||||
|
|
||||||||||||
| :param max_time_after_last_arrival: This is the max endtime | ||||||||||||
| of any window in seconds after the last arrival. No windows will | ||||||||||||
| have a endtime larger then this. | ||||||||||||
| :type max_time_after_last_arrival: float | ||||||||||||
|
|
||||||||||||
| :param c_0: Fine tuning constant for the rejection of windows based | ||||||||||||
| on the height of internal minima. Any windows with internal | ||||||||||||
| minima lower then this value times the STA/LTA water level at | ||||||||||||
|
|
@@ -198,12 +225,19 @@ def __init__(self, min_period, max_period, stalta_waterlevel=0.07, | |||||||||||
| :type window_weight_fct: function | ||||||||||||
|
|
||||||||||||
| :param window_signal_to_noise_type: The type of signal to noise | ||||||||||||
| ratio used to reject windows. If ``"amplitude"``, then the | ||||||||||||
| largest amplitude before the arrival is the noise amplitude and | ||||||||||||
| the largest amplitude in the window is the signal amplitude. If | ||||||||||||
| ``"energy"`` the time normalized energy is used in both cases. | ||||||||||||
| The later one is a bit more stable when having random wiggles | ||||||||||||
| before the first arrival. | ||||||||||||
| ratio used to reject windows | ||||||||||||
| Possiblities are: | ||||||||||||
| * ``"amplitude"``: then the largest amplitude before the arrival | ||||||||||||
| is the noise amplitude and the largest amplitude in the | ||||||||||||
| window is the signal amplitude. If the value is smaller than | ||||||||||||
| "s2n_limit" then the windows will be kept. | ||||||||||||
| * ``"energy"``: the time normalized energy is used. This one is | ||||||||||||
| a bit more stable when having random wiggles before the | ||||||||||||
| first arrival. If the value is smaller than | ||||||||||||
| "s2n_limit_energy", then the window will be kept. | ||||||||||||
| * ``"amplitude_and_energy"``: then both checks(amplitude and | ||||||||||||
| energy) are applied to the trace. But please remember to | ||||||||||||
| assign values for "s2n_limit" and "s2n_limit_energy". | ||||||||||||
| :type window_signal_to_noise_type: str | ||||||||||||
|
|
||||||||||||
| :param resolution_strategy: Strategy used to resolve overlaps. | ||||||||||||
|
|
@@ -212,6 +246,23 @@ def __init__(self, min_period, max_period, stalta_waterlevel=0.07, | |||||||||||
| non-overlapping windows. Merging will simply merge overlapping | ||||||||||||
| windows. | ||||||||||||
| :type resolution_strategy: str | ||||||||||||
|
|
||||||||||||
| :param selection_mode: Strategy to select different types of phases. | ||||||||||||
| For most cases, event and station information are required to | ||||||||||||
| calculate the arrival time information. | ||||||||||||
| Possibilities are: | ||||||||||||
| * ``"all_waves"``: all windows after first arrival | ||||||||||||
| * ``"body_waves"``: windows in the body wave region(after | ||||||||||||
| first arrival and before surface wave arrival). | ||||||||||||
| * ``"surface_waves"``: windows in surface wave region(velocity | ||||||||||||
| between min_surface_wave_velocity and | ||||||||||||
| max_surface_wave_velocity). | ||||||||||||
| * ``"body_and_surface_waves"``: windows inside body and surface | ||||||||||||
| wave regions. | ||||||||||||
|
Comment on lines
+260
to
+261
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| * ``mantle_waves``: pyflex will only accept windows after the | ||||||||||||
| surface wave region. | ||||||||||||
| * ``custom``: all windows will pass the check(nothing rejected) | ||||||||||||
| :type selection_mode: str | ||||||||||||
| """ | ||||||||||||
| self.min_period = min_period | ||||||||||||
| self.max_period = max_period | ||||||||||||
|
|
@@ -223,13 +274,24 @@ def __init__(self, min_period, max_period, stalta_waterlevel=0.07, | |||||||||||
| self.dlna_reference = dlna_reference | ||||||||||||
| self.cc_acceptance_level = cc_acceptance_level | ||||||||||||
| self.s2n_limit = s2n_limit | ||||||||||||
| self.s2n_limit_energy = s2n_limit_energy | ||||||||||||
|
|
||||||||||||
| if earth_model.lower() not in ("ak135", "iasp91"): | ||||||||||||
| raise PyflexError("Earth model must either be 'ak135' or " | ||||||||||||
| "'iasp91'.") | ||||||||||||
| self.earth_model = earth_model.lower() | ||||||||||||
| self.min_surface_wave_velocity = min_surface_wave_velocity | ||||||||||||
| self.max_time_before_first_arrival = max_time_before_first_arrival | ||||||||||||
| self.max_surface_wave_velocity = max_surface_wave_velocity | ||||||||||||
|
|
||||||||||||
| if max_time_before_first_arrival is None: | ||||||||||||
| self.max_time_before_first_arrival = 2 * min_period | ||||||||||||
| else: | ||||||||||||
| self.max_time_before_first_arrival = max_time_before_first_arrival | ||||||||||||
|
|
||||||||||||
| if max_time_after_last_arrival is None: | ||||||||||||
| self.max_time_after_last_arrival = max_period | ||||||||||||
| else: | ||||||||||||
| self.max_time_after_last_arrival = max_time_after_last_arrival | ||||||||||||
|
|
||||||||||||
| self.c_0 = c_0 | ||||||||||||
| self.c_1 = c_1 | ||||||||||||
|
|
@@ -242,6 +304,7 @@ def __init__(self, min_period, max_period, stalta_waterlevel=0.07, | |||||||||||
| self.check_global_data_quality = check_global_data_quality | ||||||||||||
| self.snr_integrate_base = snr_integrate_base | ||||||||||||
| self.snr_max_base = snr_max_base | ||||||||||||
|
|
||||||||||||
| self.noise_start_index = noise_start_index | ||||||||||||
| self.noise_end_index = noise_end_index | ||||||||||||
| self.signal_start_index = signal_start_index | ||||||||||||
|
|
@@ -250,9 +313,10 @@ def __init__(self, min_period, max_period, stalta_waterlevel=0.07, | |||||||||||
| self.window_weight_fct = window_weight_fct | ||||||||||||
|
|
||||||||||||
| snr_type = window_signal_to_noise_type.lower() | ||||||||||||
| if snr_type not in ["amplitude", "energy"]: | ||||||||||||
| raise PyflexError("The window signal to noise type must be either" | ||||||||||||
| "'amplitude' or 'energy'.") | ||||||||||||
| if snr_type not in ["amplitude", "energy", "amplitude_and_energy"]: | ||||||||||||
| raise PyflexError( | ||||||||||||
| "The window signal to noise type must be" | ||||||||||||
| "'amplitude', 'energy' or 'amplitude_and_energy'.") | ||||||||||||
| self.window_signal_to_noise_type = snr_type | ||||||||||||
|
|
||||||||||||
| if resolution_strategy.lower() not in ["interval_scheduling", "merge"]: | ||||||||||||
|
|
@@ -261,14 +325,34 @@ def __init__(self, min_period, max_period, stalta_waterlevel=0.07, | |||||||||||
| "'interval_scheduling' or 'merge'.") | ||||||||||||
| self.resolution_strategy = resolution_strategy.lower() | ||||||||||||
|
|
||||||||||||
| # Add a specific selection mode for different types of phases | ||||||||||||
| if selection_mode is not None: | ||||||||||||
|
|
||||||||||||
| selection_mode = selection_mode.strip() | ||||||||||||
| if selection_mode.split(":")[0].strip().lower() not in [ | ||||||||||||
| "all_waves", "body_and_surface_waves", "body_waves", | ||||||||||||
| "surface_waves", "mantle_waves", "custom", "phase_list", | ||||||||||||
| "body_and_mantle_waves"]: | ||||||||||||
| raise ValueError( | ||||||||||||
| "Invalide selection_mode({}). Choose: 1) all_waves;" | ||||||||||||
| "2) body_and_surface_waves; 3) body_waves; " | ||||||||||||
| "4) surface_waves; 5) mantle_waves; " | ||||||||||||
| "6) custom; 7) phase_list;".format(selection_mode)) | ||||||||||||
|
|
||||||||||||
| self.selection_mode = selection_mode | ||||||||||||
|
|
||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
|
||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def _convert_to_array(self, npts): | ||||||||||||
| """ | ||||||||||||
| Internally converts the acceptance and water levels to arrays. Not | ||||||||||||
| called during initialization as the array length is not yet known. | ||||||||||||
| """ | ||||||||||||
| attributes = ("stalta_waterlevel", "tshift_acceptance_level", | ||||||||||||
| "dlna_acceptance_level", "cc_acceptance_level", | ||||||||||||
| "s2n_limit") | ||||||||||||
| "s2n_limit", "s2n_limit_energy") | ||||||||||||
|
|
||||||||||||
| for name in attributes: | ||||||||||||
| attr = getattr(self, name) | ||||||||||||
|
|
||||||||||||
|
|
@@ -278,6 +362,47 @@ def _convert_to_array(self, npts): | |||||||||||
| "Config value '%s' does not have the same number of " | ||||||||||||
| "samples as the waveforms." % name) | ||||||||||||
| setattr(self, name, np.array(attr)) | ||||||||||||
| continue | ||||||||||||
| else: | ||||||||||||
| setattr(self, name, attr * np.ones(npts)) | ||||||||||||
|
|
||||||||||||
| setattr(self, name, attr * np.ones(npts)) | ||||||||||||
| def _convert_negative_index(self, npts): | ||||||||||||
| """ | ||||||||||||
| Convert negative index into positive. So we can compare and check | ||||||||||||
| """ | ||||||||||||
| def add_npts(_idx, _npts): | ||||||||||||
| if _idx is None: | ||||||||||||
| return None | ||||||||||||
| _idx = int(_idx) | ||||||||||||
| if _idx < 0: | ||||||||||||
| return _idx + _npts | ||||||||||||
| else: | ||||||||||||
| return _idx | ||||||||||||
|
|
||||||||||||
| self.noise_start_index = add_npts(self.noise_start_index, npts) | ||||||||||||
| self.noise_end_index = add_npts(self.noise_end_index, npts) | ||||||||||||
| self.signal_start_index = add_npts(self.signal_start_index, npts) | ||||||||||||
| self.signal_end_index = add_npts(self.signal_end_index, npts) | ||||||||||||
|
|
||||||||||||
| if self.noise_start_index is not None and \ | ||||||||||||
| self.noise_end_index is not None: | ||||||||||||
| if self.noise_start_index >= self.noise_end_index: | ||||||||||||
| raise ValueError( | ||||||||||||
| "noise_start_index is larger than " | ||||||||||||
| "noise_end_idx: %d > %d" % (self.noise_start_index, | ||||||||||||
| self.noise_end_index)) | ||||||||||||
|
|
||||||||||||
| if self.signal_start_index is not None and \ | ||||||||||||
| self.signal_end_index is not None: | ||||||||||||
| if self.signal_start_index >= self.signal_end_index: | ||||||||||||
| raise ValueError("singal_start_index is larger than " | ||||||||||||
| "signal_end_index: %d > %d" | ||||||||||||
| % (self.signal_start_index, | ||||||||||||
| self.signal_end_index)) | ||||||||||||
|
|
||||||||||||
| if self.noise_end_index is not None and \ | ||||||||||||
| self.signal_start_index is not None: | ||||||||||||
| if self.noise_end_index > self.signal_start_index: | ||||||||||||
| raise ValueError("noise_end_index is larger than " | ||||||||||||
| "signal_start_index: %d > %d" | ||||||||||||
| % (self.noise_end_index, | ||||||||||||
| self.signal_start_index)) | ||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.