Skip to content
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

fix doc and make yaml_load for internal usage only #37

Merged
merged 1 commit into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion stream2segment/process/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import numpy as np

from stream2segment.process.db import get_session
from stream2segment.io import yaml_load # utility functions for users: yaml_load(file)
from stream2segment.io.db import close_session
from stream2segment.process.db.models import (Segment, Channel, Event, Station,
DataCenter, Download, Class)
Expand Down
4 changes: 2 additions & 2 deletions stream2segment/resources/templates/The-Segment-object.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -232,7 +232,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
"version": "3.11.0"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,14 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"from stream2segment.process import yaml_load\n",
"import yaml\n",
"# uncomment the line below using an existing file on your OS:\n",
"# dburl = yaml_load(download_file.yaml)['dburl']"
"# with open('replace_with_your_download_config_path.yaml', 'r') as fpt:\n",
"# dburl = yaml.safe_load(fpt)['dburl']"
]
},
{
Expand Down
25 changes: 15 additions & 10 deletions stream2segment/resources/templates/paramtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@

def main(segment, config):
"""Main processing function, called iteratively for any segment selected from `imap`
or `process` functions of stream2segment. See section `if __name__ == "__main__"`
at the end of the module for details.

IMPORTANT: any exception raised here or from any sub-function will interrupt the
whole processing routine with one special case: `stream2segment.process.SkipSegment`
will resume from the next segment. Raise it to programmatically skip a segment, e.g.:
or `process` functions of stream2segment. If you just created this file with
`s2s init`, see section `if __name__ == "__main__"` at the end of the module for
details.

IMPORTANT: Any exception raised here or from any sub-function will interrupt the
whole processing routine (`imap` or `process`) with one special case:
`stream2segment.process.SkipSegment` will resume from the next segment.
Raise it to programmatically skip a segment, e.g.:
```
if segment.sample_rate < 60:
raise SkipSegment("segment sample rate too low")`
Expand Down Expand Up @@ -537,15 +539,18 @@ def meanslice(trace, nptmin=100, starttime=None, endtime=None):

# Example code: Check and customize before run
# ------------------------------------
from stream2segment.process import yaml_load # similar to yaml.safe_load
# Load config (below we assume to be a YAML file with the same name as this module):
# Setup config: you can build your own dict of parameters or load it from a YAML
# file as in the example below (change path according to your needs):
import yaml
config_path = os.path.splitext(os.path.abspath(__file__))[0] + '.yaml'
config = yaml_load(config_path)
with open(config_path, 'r') as fpt:
config = yaml.safe_load(fpt)
# get the database URL. Do NOT TYPE anywhere URLs with passwords (e.g. postgres), or
# if you do, do not COMMIT the file and keep it local. A good solution is to read
# the db URL used for downloading the data from its config. Example:
download_path = os.path.join(os.path.dirname(__file__), 'download.yaml')
dburl = yaml_load(download_path)['dburl']
with open(download_path, 'r') as fpt:
dburl = yaml.safe_load(fpt)['dburl']
# segments to process
# For details, see {{ THE_SEGMENT_OBJECT_WIKI_URL_SEGMENT_SELECTION }}
# The variable below can also be a list/numpy array of integers denoting the
Expand Down
Loading