-
Notifications
You must be signed in to change notification settings - Fork 16
Snuffling Quick Save #25
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
3c593d2
f6a3f43
84d9706
ab34783
061c873
ebca084
d871b67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| #-*- coding: utf-8 -*- | ||
|
|
||
| import getpass | ||
| import os | ||
|
|
||
| from pyrocko.snuffling import Choice, Snuffling, Switch | ||
| from pyrocko.pile_viewer import Marker | ||
|
|
||
| # TO-DO - save to VELEST format. | ||
|
|
||
| user_def_root_folder = \ | ||
| '/user/defined/root/folder' | ||
|
|
||
| class QuickSave(Snuffling): | ||
|
|
||
| """ | ||
|
|
||
| <html> | ||
| <h2>Quick Save</h2> | ||
| <body> | ||
| <p> | ||
| Choose the predefined or user defined path from the <b>Root folder</b> | ||
| menu, desired <b>options</b> and press <b>Run</b>. Path to marker file is | ||
| printed to the terminal.<br> | ||
| User defined path is selected by default and can be modified in the source | ||
| file. It is given as a string under <i>user_def_root_folder</i> variable | ||
| (line 11). | ||
| </p> | ||
| <p> | ||
| Options:</br> | ||
| <ul> | ||
| <li>Save only selected markers.</li> | ||
| <li>Save only markers associated to the active event.</li> | ||
| <ul> | ||
| <li>Add active event name to path. Creates new folder if needed.</li> | ||
| <li>Use active event name as filename.</li> | ||
| </ul> | ||
| </ul> | ||
| </p> | ||
| <p> | ||
| Author: G. Rajh. | ||
| </p> | ||
| </body> | ||
| </html> | ||
|
|
||
| """ | ||
|
|
||
| def setup(self): | ||
| self.set_name('Quick Save') | ||
|
|
||
| username = getpass.getuser() | ||
|
|
||
| self.add_parameter(Choice('Root folder', 'root_folder', | ||
| user_def_root_folder, [user_def_root_folder, | ||
| '/home/' + username + '/Desktop', | ||
| '/home/' + username + '/Documents' | ||
| ])) | ||
|
|
||
| self.add_parameter(Switch( | ||
| 'Save only selected markers', 'save_sel_markers', False)) | ||
| self.add_parameter(Switch( | ||
| 'Save only markers associated\nto the active event', | ||
| 'save_asc_markers', False)) | ||
| self.add_parameter(Switch('Add active event name to path', | ||
| 'name_to_path', False)) | ||
| self.add_parameter(Switch('Use active event name as filename', | ||
| 'name_as_filename', False)) | ||
| # self.add_parameter(Switch('Save in Velest format', | ||
| # 'velest_format', False)) | ||
|
|
||
| self.setup_gui(reloaded=True) | ||
| self.set_live_update(False) | ||
|
|
||
| def parse_markers(self): | ||
| self.cleanup() | ||
|
|
||
| if self.save_asc_markers and not self.save_sel_markers: | ||
| active_event, asc_phase_markers = \ | ||
| self.get_active_event_and_phase_markers() | ||
| asc_phase_markers.insert(0, active_event) | ||
| self.selected_markers = asc_phase_markers | ||
| self.ae_name = active_event.get_event().name | ||
| elif not self.save_asc_markers and self.save_sel_markers: | ||
| self.selected_markers = self.get_selected_markers | ||
| else: | ||
| self.selected_markers = self.get_markers() | ||
|
|
||
| def save_markers(self): | ||
| if self.save_asc_markers and not self.save_sel_markers: | ||
| if self.name_to_path and self.name_as_filename: | ||
| save_path = self.root_folder + "/" + self.ae_name | ||
| try: | ||
| os.makedirs(save_path) | ||
| except OSError: | ||
| if not os.path.isdir(save_path): | ||
| raise | ||
| self.save_path = save_path + "/" + self.ae_name | ||
| elif self.name_to_path: | ||
| save_path = self.root_folder + "/" + self.ae_name | ||
| try: | ||
| os.makedirs(save_path) | ||
| except OSError: | ||
| if not os.path.isdir(save_path): | ||
| raise | ||
| self.save_path = save_path + "/picks" | ||
| elif self.name_as_filename: | ||
| self.save_path = self.root_folder + "/" + self.ae_name | ||
| else: | ||
| self.save_path = self.root_folder + "picks" | ||
| else: | ||
| self.save_path = self.root_folder + "picks" | ||
|
|
||
| Marker.save_markers(self.selected_markers, self.save_path) | ||
|
|
||
| def save_velest(self): | ||
| pass | ||
|
|
||
| def call(self): | ||
| self.parse_markers() | ||
| self.save_markers() | ||
| print("Markers saved to: {}.".format(self.save_path)) | ||
|
|
||
| def __snufflings__(): | ||
| """Returns a list of snufflings to be exported by this module.""" | ||
|
|
||
| return[QuickSave()] | ||
|
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. Add newline at EOF
Author
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. I noticed that empty lines at EOF are automatically truncated.
Author
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. Now it worked. It was editor's fault. |
||
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.
Capitalize this constant and default to the user's home folder:
os.path.expanduser('~')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.
Done.