Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/codecov/codecov-ac…
Browse files Browse the repository at this point in the history
…tion-4
  • Loading branch information
seisman authored Jun 7, 2024
2 parents e5d6f1c + e26bfed commit 285fa5e
Show file tree
Hide file tree
Showing 32 changed files with 916 additions and 1,170 deletions.
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ A clear and concise description of what the bug is.

**Full code that generated the error**

*Please be careful not to post your real username and password in the codes.*

```python
PASTE CODE HERE
```
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#
# Code lint and style checks
#
name: Check

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
check:
name: Code Styles
runs-on: ubuntu-latest

steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.12.1

- name: Checkout
uses: actions/checkout@v4

Expand All @@ -25,8 +24,8 @@ jobs:

- name: Install dependencies
run: |
pip install -r requirements.txt
pip install black blackdoc flake8 isort
python -m pip install -r requirements.txt
python -m pip install ruff
- name: Check code style
run: make check
29 changes: 19 additions & 10 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
#
# Build and deploy documentation
#
name: Docs

on:
push:
branches: [main]
paths:
- 'HinetPy/*.py'
- 'docs/**'
pull_request:
branches: [main]
paths:
- 'HinetPy/*.py'
- 'docs/**'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
deploy-docs:
name: Docs
runs-on: ubuntu-latest

steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.12.1

- name: Checkout
uses: actions/checkout@v4
with:
Expand All @@ -28,17 +37,17 @@ jobs:

- name: Install dependencies
run: |
pip install -r requirements.txt
pip install sphinx sphinx-intl sphinx_rtd_theme
python setup.py sdist --formats=zip
pip install dist/*
python -m pip install -r requirements.txt
python -m pip install build sphinx sphinx-intl sphinx_rtd_theme
python -m build --sdist
python -m pip install dist/*
- name: Build documentation
run: make doc

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3.9.3
# Only deploy on master branch
uses: peaceiris/actions-gh-pages@v4.0.0
# Only deploy on main branch
if: github.ref == 'refs/heads/main'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
11 changes: 4 additions & 7 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@ jobs:
with:
python-version: '3.x'

- name: Install dependencies
- name: Build
run: |
pip install setuptools wheel
- name: Build and publish
run: |
python setup.py sdist bdist_wheel
python -m pip install build
python -m build
ls -lh dist/
- name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@v1.8.11
uses: pypa/gh-action-pypi-publish@v1.8.14
with:
password: ${{ secrets.PYPI_API_TOKEN }}
17 changes: 11 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ name: Tests
on:
push:
branches: [main]
paths:
- 'HinetPy/**'
- 'tests/**'
- '.github/workflows/tests.yml'
pull_request:
branches: [main]
paths:
- 'HinetPy/**'
- 'tests/**'
- '.github/workflows/**'
- '.github/workflows/tests.yml'

jobs:
test:
Expand All @@ -18,7 +22,8 @@ jobs:
max-parallel: 1 # Hinet doesn't allow parallel data request
fail-fast: false
matrix:
python-version: ["3.7", "3.10"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
#python-version: ["3.8", "3.12"]
os: [macos-latest, ubuntu-latest]

steps:
Expand All @@ -38,10 +43,10 @@ jobs:

- name: Install dependencies
run: |
pip install -r requirements.txt
pip install pytest>=6.0 pytest-cov coverage[toml] codecov
python setup.py sdist --formats=zip
pip install dist/*
python -m pip install -r requirements.txt
python -m pip install build pytest pytest-cov coverage[toml] codecov
python -m build --sdist
python -m pip install dist/*
- name: Install win32tools
run: |
Expand Down
10 changes: 5 additions & 5 deletions HinetPy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# noqa: N999
"""
HinetPy
=======
HinetPy is a Python package to request and process seismic waveform data
from the NIED Hi-net website.
HinetPy is a Python package to request and process seismic waveform data from the NIED
Hi-net website.
Basis usage:
Expand All @@ -16,13 +17,12 @@
>>> win32.extract_sac(data, ctable)
>>> win32.extract_sacpz(ctable)
"""
# pylint: disable=invalid-name

from pkg_resources import get_distribution
from importlib.metadata import version

from .client import Client
from .header import NETWORK

__all__ = ["Client", "NETWORK", "win32"]
# Get semantic version through setuptools-scm
__version__ = f'v{get_distribution("HinetPy").version}' # e.g. v0.1.2.dev3+g0ab3cd78
__version__ = f'v{version("HinetPy")}' # e.g. v0.1.2.dev3+g0ab3cd78
123 changes: 123 additions & 0 deletions HinetPy/channel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
"""
Class for channels.
"""

from __future__ import annotations

import math
import warnings


class Channel:
"""
Information for a single channel.
"""

def __init__( # noqa: PLR0913
self,
id: str, # noqa: A002
name: str,
component: str,
latitude: float | str,
longitude: float | str,
unit: str,
gain: float | str,
damping: float | str,
period: float | str,
preamplification: float | str,
lsb_value: float | str,
):
"""
Parameters
----------
id
Channel ID.
name
Station Name.
component
Channel component name (e.g., ``U``, ``N`` or ``E``).
latitude
Station latitude.
longitude
Station longitude.
unit
Unit of data (e.g., ``m``, ``m/s``, ``m/s/s``, ``rad``).
gain
Sensor sensitivity.
damping
Damping constant of the sensor.
period
Natural period of the seismometer.
preamplification
Preamplification value.
lsb_value
LSB value.
Notes
-----
The Hi-net website uses the moving-coil velocity-type seismometer. See
:doc:`/appendix/response` for details.
"""
self.id = id
self.name = name
self.component = component
self.latitude = float(latitude)
self.longitude = float(longitude)
self.unit = unit
self.gain = float(gain)
self.damping = float(damping)
self.period = float(period)
self.preamplification = float(preamplification)
self.lsb_value = float(lsb_value)

def _get_polezero(self):
"""
Determine the polezero parameters.
"""
# Calculate natural frequency
freq = 2.0 * math.pi / self.period

# Calculate poles by finding roots of equation s^2+2hws+w^2=0
self.zeros = 3
self.poles = 2
self.real = 0.0 - self.damping * freq
self.imaginary = freq * math.sqrt(1.0 - self.damping**2.0)

# Calculate the CONSTANT
fn = 20.0 # alaways assume normalization frequency is 20 Hz
s = complex(0, 2 * math.pi * fn)
self.a0 = abs((s**2 + 2 * self.damping * freq * s + freq**2) / s**2)
self.sensitivity = (
self.gain * math.pow(10, self.preamplification / 20.0) / self.lsb_value
)

def write_sacpz(self, pzfile, keep_sensitivity=False):
"""
Write channel information into a SAC polezero file.
Parameters
----------
pzfile: str
Name of the SAC polezero file.
k9.999513e-01eep_sensitivity: bool
Keep sensitivity in the SAC polezero "CONSTANT" or not.
"""
chan_info = f"{self.name}.{self.component} ({self.id})"
# Hi-net uses a moving-coil velocity-type seismometer.
if self.unit != "m/s":
msg = f"{chan_info}: Unit is not velocity. The PZ file may be wrong."
warnings.warn(msg, category=RuntimeWarning, stacklevel=2)
if self.period == 0.0:
msg = f"{chan_info}): Natural period = 0.0. Skipped."
warnings.warn(message=msg, category=RuntimeWarning, stacklevel=2)
return

self._get_polezero()
constant = self.a0 * self.sensitivity if keep_sensitivity else self.a0
# write information to a SAC PZ file
with open(pzfile, "w", encoding="utf8") as pz:
pz.write(f"ZEROS {self.zeros}\n")
pz.write(f"POLES {self.poles}\n")
pz.write(f"{self.real:9.6f} {self.imaginary:9.6f}\n")
pz.write(f"{self.real:9.6f} {-self.imaginary:9.6f}\n")
pz.write(f"CONSTANT {constant:e}\n")
Loading

0 comments on commit 285fa5e

Please sign in to comment.