Skip to content

Commit

Permalink
Hotfix: CAP weight file sorting (#145)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bch0w authored May 16, 2024
1 parent 9e77ad3 commit 0b22608
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 29 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,10 @@
- #137: More control over RecSec kwargs and better warning messages
- #138: Improved SAC header creation for SPECFEM synthetics
- #139: Improved RecSec preprocessing setup, more manual control for the User

## Version 0.6.1

- Change log level from warning -> info for empty origin time when reading SPECFEM sources
- Remove README doc page about publishing to PyPi, moved this to adjDocs
- Hotfix: incorrect sorting in CAP weights file related to #144
- Added some more to the RecSec docstring
25 changes: 0 additions & 25 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,3 @@ make html

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

## Publishing Package on PyPi
*Useful link: https://realpython.com/pypi-publish-python-package/*

1. Ensure your `pyproject.toml` file is set up properly; required fields are name and version
2. Set dependencies, do **not(( pin exact versions but allow for upper and lower bounds; only list direct dependencies
3. Include `tests/`, `docs/`, license, and MANIFEST files (MANIFIST used for including non-source code material
4. Ensure you have an account on PyPi and TestPyPi (for testing publishing)
5. Install `twine` and `build` which are used to build and push packages to PyPi
6. Build your packages locally, which creates the `.tar.gz` and `.whl` dist files
```bash
python -m build
```
6. Check that files in your .whl (zip file) are as expected (including everything in 3)
7. Check dist files with:
```bash
twine check dist/*
```
8. Upload test package (note: requires TestPyPi account)
```bash
twine upload -r testpypi dist/*
```
9. Upload real package (note: requires PyPi account)
```bash
twine upload dist/*
```
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pysep-adjtomo"
version = "0.6.0"
version = "0.6.1"
description = "Python Seismogram Extraction and Processing"
readme = "README.md"
requires-python = ">=3.8"
Expand Down
6 changes: 6 additions & 0 deletions pysep/recsec.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,12 @@ def __init__(
:type trim: bool
:param trim: trim waveforms to the same length, and if any data gaps
are present, fill with mean values by default
:type taper: bool
:param taper: if True, taper ends of waveform during preprocessing. Uses
keyword arguments `max_percentage` (float) to define the percentage
to taper, and `taper_type` (str) to define shape of the taper. See
ObsPy's stream.taper() function for acceptable values for these
arguments.
:type integrate: int
:param integrate: apply integration `integrate` times on all traces.
acceptable values [-inf, inf], where positive values are integration
Expand Down
29 changes: 28 additions & 1 deletion pysep/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from obspy import read, read_events, read_inventory, Stream
from obspy.io.sac.sactrace import SACTrace
from pysep.utils.cap_sac import (append_sac_headers,
format_sac_header_w_taup_traveltimes)
format_sac_header_w_taup_traveltimes,
write_cap_weights_files)
from pysep.utils.curtail import (remove_for_clipped_amplitudes, rename_channels,
remove_stations_for_missing_channels,
remove_stations_for_insufficient_length,
Expand Down Expand Up @@ -101,6 +102,32 @@ def test_sac_header_correct_origin_time(tmpdir, test_st, test_inv, test_event):
assert(sac.reftime == test_event.preferred_origin().time)


def test_write_cap_weights_files(tmpdir, test_st, test_inv, test_event):
"""
Test writing out CAP weight files and make sure sorting works for distance
and code works as advertised. No testing for az sorting
"""
st = append_sac_headers(st=test_st, inv=test_inv, event=test_event)

# Check sorting by dist
write_cap_weights_files(st=st, path_out=tmpdir, order_by="dist")
assert(os.path.exists(os.path.join(tmpdir, "weights.dat")))
dists = np.loadtxt(os.path.join(tmpdir, "weights.dat"), usecols=1)
# Check that distances are in ascending order
assert(np.all(np.diff(dists) >= 0))

# Remove so we know that new files are being made each time
os.remove(os.path.join(tmpdir, "weights.dat"))

# Check sorting by code
write_cap_weights_files(st=st, path_out=tmpdir, order_by="code")
assert(os.path.exists(os.path.join(tmpdir, "weights.dat")))
codes = np.loadtxt(os.path.join(tmpdir, "weights.dat"), usecols=0,
dtype=str)
# Check that distances are in ascending order
assert(np.all(codes == np.sort(codes)))


def test_rename_channels(test_st):
"""
Edit some waveforms to be obviously bad and make sure we can catch it
Expand Down
2 changes: 1 addition & 1 deletion pysep/utils/cap_sac.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def write_cap_weights_files(st, path_out="./", order_by="dist"):

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

logger.info("writing CAP weight files")
Expand Down
2 changes: 1 addition & 1 deletion pysep/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def read_specfem2d_source(path_to_source, origin_time=None):
# First set dummy origin time
if origin_time is None:
origin_time = "1970-01-01T00:00:00"
logger.warning("no origin time set for SPECFEM2D source, setting "
logger.info("no origin time set for SPECFEM2D source, setting "
f"dummy value: {origin_time}")

with open(path_to_source, "r") as f:
Expand Down

0 comments on commit 0b22608

Please sign in to comment.