Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • ghsc/geomag/geomag-algorithms
1 result
Show changes
Commits on Source (11)
......@@ -69,18 +69,19 @@ variables:
.check_code:
artifacts:
reports:
cobertura: cov.xml
cobertura: coverage.xml
junit: junit.xml
before_script:
# install dependencies
- pipenv --site-packages install --dev --pre --skip-lock
- pipenv run which python
- pipenv install --dev --pre --system
- which python
image: ${DEVOPS_REGISTRY}usgs/obspy:latest
script:
# run checks
- pipenv run black --check .
- pipenv run pytest --cov=geomagio --cov-report xml:cov.xml --junitxml junit.xml
- pipenv run safety check
- black --check .
- pytest --cov=geomagio --junitxml junit.xml
- coverage xml
- safety check
stage: test
tags:
- development
......@@ -150,10 +151,11 @@ variables:
# Test Stage
## --------------------------------------------------
Check Python 3.6:
extends:
- .check_code
image: ${DEVOPS_REGISTRY}usgs/obspy:3
# Numpy 1.20 requires python 3.7 or newer
# Check Python 3.6:
# extends:
# - .check_code
# image: ${DEVOPS_REGISTRY}usgs/obspy:3
Check Python 3.8:
extends:
......
......@@ -13,24 +13,22 @@ ENV GIT_BRANCH_NAME=${GIT_BRANCH_NAME} \
WEBSERVICE=${WEBSERVICE}
RUN useradd \
-c 'Docker image user' \
-m \
-r \
-s /sbin/nologin \
geomag_user \
&& mkdir -p /data \
&& chown -R geomag_user:geomag_user /data
# install packages into system python, when Pipfile changes
COPY Pipfile Pipfile.lock /geomag-algorithms/
RUN cd /geomag-algorithms \
&& pipenv install --dev --pre --system
USER geomag_user
# install rest of library as editable
COPY . /geomag-algorithms
RUN cd /geomag-algorithms \
&& pip install -e . \
# add data directory owned by usgs-user
&& mkdir -p /data \
&& chown -R usgs-user:usgs-user /data
# install dependencies via pipenv
USER usgs-user
WORKDIR /data
COPY Pipfile /data/
RUN pipenv --site-packages install --dev --skip-lock
# copy library (ignores set in .dockerignore)
COPY . /geomag-algorithms
# entrypoint needs double quotes
ENTRYPOINT [ "/geomag-algorithms/docker-entrypoint.sh" ]
......
......@@ -6,7 +6,6 @@ verify_ssl = true
[dev-packages]
bandit = "*"
black = "==20.8b1"
jupyter = "*"
pre-commit = "*"
pytest = "*"
pytest-cov = "*"
......@@ -30,6 +29,7 @@ openpyxl = "*"
pydantic = "*"
sqlalchemy = "*"
sqlalchemy-utc = "*"
typer = "*"
typing = "*"
typing-extensions = "*"
uvicorn = {extras=["standard"], version="*"}
......
This diff is collapsed.
Geomag Algorithms
=================
[![Build Status](https://travis-ci.org/usgs/geomag-algorithms.svg?branch=master)](https://travis-ci.org/usgs/geomag-algorithms)
# Geomag Algorithms
[![pipeline status](https://code.usgs.gov/ghsc/geomag/geomag-algorithms/badges/master/pipeline.svg)](https://code.usgs.gov/ghsc/geomag/geomag-algorithms/-/commits/master)
[![coverage report](https://code.usgs.gov/ghsc/geomag/geomag-algorithms/badges/master/coverage.svg)](https://code.usgs.gov/ghsc/geomag/geomag-algorithms/-/commits/master)
Geomag Algorithms is an open source library for processing
Geomagnetic timeseries data. It includes algorithms and input/output factories
Geomagnetic timeseries data. It includes algorithms and input/output factories
used by the [USGS Geomagnetism Program](http://geomag.usgs.gov) to
translate between data formats,
generate derived data and indices in near-realtime,
and research and develop new algorithms.
translate between data formats,
generate derived data and indices in near-realtime,
and research and develop new algorithms.
- Accesses USGS data services.
- Built using established open source python libraries
[NumPy](http://www.numpy.org/),
[SciPy](http://www.scipy.org/), and
[ObsPy](http://www.obspy.org/).
[NumPy](http://www.numpy.org/),
[SciPy](http://www.scipy.org/), and
[ObsPy](http://www.obspy.org/).
- Common geomagnetic formats including
IAGA2002,
IMFV122,
IMFV283 (read only), and
PCDCP.
IAGA2002,
IMFV122,
IMFV283 (read only), and
PCDCP.
- Defines command line interface, `geomag.py`.
- Embeddable Python API, `import geomagio`.
## Examples
> [More Examples in docs/example/](./docs/example/)
The following examples request data from USGS for
`BOU` observatory,
`H`, `E`, `Z`, and `F` component,
`minute` interval,
and `variation` type data
for the day `2016-07-04`,
`BOU` observatory,
`H`, `E`, `Z`, and `F` component,
`minute` interval,
and `variation` type data
for the day `2016-07-04`,
then write `IAGA2002` formatted output to the console.
### Command Line Interface Example
```
geomag.py \
--input edge \
......@@ -49,9 +49,11 @@ geomag.py \
--starttime 2016-07-04T00:00:00Z \
--endtime 2016-07-04T23:59:00Z
```
[Command Line Interface documentation](./docs/cli.md)
### Python API Example
```
import sys
import geomagio
......@@ -72,66 +74,55 @@ output_factory.write_file(
fh = sys.stdout,
timeseries = timeseries)
```
[Python API documentation](./docs/api.md)
[Python API documentation](./docs/api.md)
## Install
> [More Install options in docs/install.md](./docs/install.md).
### Docker
Docker is the simplest install option.
1. Create and start a new container
named `geomagio`,
listening on local port `8000`,
from the image `usgs/geomag-algorithms` on docker hub
```
docker run -d --name geomagio -p 8000:8000 usgs/geomag-algorithms
```
named `geomagio`,
listening on local port `8000`,
from the image `usgs/geomag-algorithms` on docker hub
2. Find the token, (the token improves security)
```
docker run -d --name geomagio -p 8000:8000 usgs/geomag-algorithms
```
```
docker logs geomagio
```
2. Use the running container
This outputs a URL to copy/paste into your browser address bar:
```
Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://localhost:8000/?token=TOKEN
```
- Run the `geomag.py` command line interface:
3. Use the running container
> To work with files outside the container,
> use a volume mount when starting the container
- Run the `geomag.py` command line interface:
```
docker exec -it geomagio geomag.py
```
```
docker exec -it geomagio geomag.py
```
- Run python interactively in a web browser (using the token found in step 2):
```
http://localhost:8000/?token=TOKEN
```
> In the top right corner, choose "New" then "Python 2"
- Or, to run an interactive python prompt:
```
docker exec -it geomagio python
```
## Algorithms
[Algorithms described in docs/algorithms/](./docs/algorithms)
[Algorithms described in docs/algorithms/](./docs/algorithms)
## Developing
[Developing described in docs/develop.md](./docs/develop.md).
[Developing described in docs/develop.md](./docs/develop.md).
## License
[License described in LICENSE.md](./LICENSE.md)
[License described in LICENSE.md](./LICENSE.md)
## Problems or Questions?
......@@ -139,7 +130,6 @@ Docker is the simplest install option.
- [Join the USGS geomag-data mailing list](https://geohazards.usgs.gov/mailman/listinfo/geomag-data)
- [Email jmfee at usgs.gov](mailto:jmfee@usgs.gov)
## Additional Links
- [USGS Geomagnetism Program Home Page](http://geomag.usgs.gov/)
......
#! /bin/bash
# Environment variable to determine whether to start webservice
export WEBSERVICE=${WEBSERVICE:-false}
# add geomagio to notebook path
export PYTHONPATH=/geomag-algorithms
if [ "${WEBSERVICE}" = "false" ]; then
# run jupyter notebook server
exec pipenv run jupyter \
notebook \
--ip='*' \
--notebook-dir=/data \
--no-browser \
--port=8000
# run arguments as command, or bash prompt if no arguments
exec "${@:-/bin/bash}"
else
# run gunicorn server for web service
exec pipenv run gunicorn \
exec gunicorn \
--access-logfile - \
--bind 0.0.0.0:8000 \
--threads 2 \
......
......@@ -25,13 +25,8 @@ The following command creates and starts a container in the background.
- Run an interactive python prompt
docker exec -it geomagio python
- Use the Jupyter Notebook server
Check the output for a URL like this, that can be opened in a web browser: `http://127.0.0.1:8000/?token=...`
- Use the `geomag.py` command line interface
docker exec -it geomagio geomag.py \
......
......@@ -203,8 +203,8 @@ class Controller(object):
output_observatory=options.output_observatory,
starttime=options.starttime,
endtime=options.endtime,
input_channels=options.input_channels,
output_channels=options.output_channels,
input_channels=options.inchannels,
output_channels=options.outchannels,
no_trim=options.no_trim,
realtime=options.realtime,
rename_input_channel=options.rename_input_channel,
......
......@@ -465,7 +465,7 @@ class SqDistAlgorithm(Algorithm):
ts = np.linspace(
np.max((-m, -3 * np.round(sig))),
np.min((m, 3 * np.round(sig))),
np.int(np.round(np.min((2 * m, 6 * np.round(sig))) + 1)),
int(np.round(np.min((2 * m, 6 * np.round(sig))) + 1)),
)
nts = ts.size
weights = np.exp(-0.5 * (ts / sig) ** 2)
......
......@@ -4,9 +4,9 @@
import numpy
# values that represent missing data points in PCDCP
NINES = numpy.int("9999999")
NINES_RAW = numpy.int("99999990")
NINES_DEG = numpy.int("9999")
NINES = int("9999999")
NINES_RAW = int("99999990")
NINES_DEG = int("9999")
class PCDCPParser(object):
......
......@@ -11,7 +11,7 @@ from obspy.core import Stream
class TEMPWriter(object):
"""TEMP writer."""
def __init__(self, empty_value=numpy.int("9999")):
def __init__(self, empty_value=int("9999")):
self.empty_value = empty_value
def write(self, out, timeseries, channels):
......
......@@ -11,7 +11,7 @@ from obspy.core import Stream
class VBFWriter(object):
"""VBF writer."""
def __init__(self, empty_value=numpy.int("9999999")):
def __init__(self, empty_value=int("9999999")):
self.empty_value = empty_value
def write(self, out, timeseries, channels):
......