Skip to content

Commit 0b22608

Browse files
authored
Hotfix: CAP weight file sorting (#145)
* removed pypi version documentation, moved to adjdocs bump patch version number remove annoying warning log when specfem source does not have origin time * added docstring for recsec taper parameter * fixed sorting issue related to #144 and extended test to cover this function * update changelog
1 parent 9e77ad3 commit 0b22608

File tree

7 files changed

+44
-29
lines changed

7 files changed

+44
-29
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,10 @@
122122
- #137: More control over RecSec kwargs and better warning messages
123123
- #138: Improved SAC header creation for SPECFEM synthetics
124124
- #139: Improved RecSec preprocessing setup, more manual control for the User
125+
126+
## Version 0.6.1
127+
128+
- Change log level from warning -> info for empty origin time when reading SPECFEM sources
129+
- Remove README doc page about publishing to PyPi, moved this to adjDocs
130+
- Hotfix: incorrect sorting in CAP weights file related to #144
131+
- Added some more to the RecSec docstring

docs/README.md

-25
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,3 @@ make html
2626

2727
See your locally built documentation by opening *_build/html/index.html*
2828

29-
## Publishing Package on PyPi
30-
*Useful link: https://realpython.com/pypi-publish-python-package/*
31-
32-
1. Ensure your `pyproject.toml` file is set up properly; required fields are name and version
33-
2. Set dependencies, do **not(( pin exact versions but allow for upper and lower bounds; only list direct dependencies
34-
3. Include `tests/`, `docs/`, license, and MANIFEST files (MANIFIST used for including non-source code material
35-
4. Ensure you have an account on PyPi and TestPyPi (for testing publishing)
36-
5. Install `twine` and `build` which are used to build and push packages to PyPi
37-
6. Build your packages locally, which creates the `.tar.gz` and `.whl` dist files
38-
```bash
39-
python -m build
40-
```
41-
6. Check that files in your .whl (zip file) are as expected (including everything in 3)
42-
7. Check dist files with:
43-
```bash
44-
twine check dist/*
45-
```
46-
8. Upload test package (note: requires TestPyPi account)
47-
```bash
48-
twine upload -r testpypi dist/*
49-
```
50-
9. Upload real package (note: requires PyPi account)
51-
```bash
52-
twine upload dist/*
53-
```

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "pysep-adjtomo"
7-
version = "0.6.0"
7+
version = "0.6.1"
88
description = "Python Seismogram Extraction and Processing"
99
readme = "README.md"
1010
requires-python = ">=3.8"

pysep/recsec.py

+6
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,12 @@ def __init__(
340340
:type trim: bool
341341
:param trim: trim waveforms to the same length, and if any data gaps
342342
are present, fill with mean values by default
343+
:type taper: bool
344+
:param taper: if True, taper ends of waveform during preprocessing. Uses
345+
keyword arguments `max_percentage` (float) to define the percentage
346+
to taper, and `taper_type` (str) to define shape of the taper. See
347+
ObsPy's stream.taper() function for acceptable values for these
348+
arguments.
343349
:type integrate: int
344350
:param integrate: apply integration `integrate` times on all traces.
345351
acceptable values [-inf, inf], where positive values are integration

pysep/tests/test_utils.py

+28-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
from obspy import read, read_events, read_inventory, Stream
1212
from obspy.io.sac.sactrace import SACTrace
1313
from pysep.utils.cap_sac import (append_sac_headers,
14-
format_sac_header_w_taup_traveltimes)
14+
format_sac_header_w_taup_traveltimes,
15+
write_cap_weights_files)
1516
from pysep.utils.curtail import (remove_for_clipped_amplitudes, rename_channels,
1617
remove_stations_for_missing_channels,
1718
remove_stations_for_insufficient_length,
@@ -101,6 +102,32 @@ def test_sac_header_correct_origin_time(tmpdir, test_st, test_inv, test_event):
101102
assert(sac.reftime == test_event.preferred_origin().time)
102103

103104

105+
def test_write_cap_weights_files(tmpdir, test_st, test_inv, test_event):
106+
"""
107+
Test writing out CAP weight files and make sure sorting works for distance
108+
and code works as advertised. No testing for az sorting
109+
"""
110+
st = append_sac_headers(st=test_st, inv=test_inv, event=test_event)
111+
112+
# Check sorting by dist
113+
write_cap_weights_files(st=st, path_out=tmpdir, order_by="dist")
114+
assert(os.path.exists(os.path.join(tmpdir, "weights.dat")))
115+
dists = np.loadtxt(os.path.join(tmpdir, "weights.dat"), usecols=1)
116+
# Check that distances are in ascending order
117+
assert(np.all(np.diff(dists) >= 0))
118+
119+
# Remove so we know that new files are being made each time
120+
os.remove(os.path.join(tmpdir, "weights.dat"))
121+
122+
# Check sorting by code
123+
write_cap_weights_files(st=st, path_out=tmpdir, order_by="code")
124+
assert(os.path.exists(os.path.join(tmpdir, "weights.dat")))
125+
codes = np.loadtxt(os.path.join(tmpdir, "weights.dat"), usecols=0,
126+
dtype=str)
127+
# Check that distances are in ascending order
128+
assert(np.all(codes == np.sort(codes)))
129+
130+
104131
def test_rename_channels(test_st):
105132
"""
106133
Edit some waveforms to be obviously bad and make sure we can catch it

pysep/utils/cap_sac.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def write_cap_weights_files(st, path_out="./", order_by="dist"):
9898

9999
# Order codes based on distance, name or azimuth
100100
idx = ["code", "dist", "az"].index(order_by)
101-
code_list = np.array(code_list)
101+
code_list = np.array(code_list, dtype="object")
102102
ordered_codes = code_list[code_list[:, idx].argsort()]
103103

104104
logger.info("writing CAP weight files")

pysep/utils/io.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def read_specfem2d_source(path_to_source, origin_time=None):
269269
# First set dummy origin time
270270
if origin_time is None:
271271
origin_time = "1970-01-01T00:00:00"
272-
logger.warning("no origin time set for SPECFEM2D source, setting "
272+
logger.info("no origin time set for SPECFEM2D source, setting "
273273
f"dummy value: {origin_time}")
274274

275275
with open(path_to_source, "r") as f:

0 commit comments

Comments
 (0)