Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

- name: Run publiccode parser
run: |
docker run -i --rm italia/publiccode-parser-go /dev/stdin < publiccode.yml
docker run -i --rm -v $(pwd):/publiccode_folder italia/publiccode-parser-go /publiccode_folder/publiccode.yml

build_and_push_to_registry:
name: Build and Push Docker image to Docker Hub
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.idea/
__pycache__/
mytests/
27 changes: 18 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
FROM debian:bullseye-slim
FROM debian:bookworm-slim

LABEL maintainer="Raffaele Di Stefano <raffaele.distefano@ingv.it>"
ENV DEBIAN_FRONTEND=noninteractive
# Bookworm marks the system Python as externally managed (PEP 668) and pip
# refuses to install into it. This image is single-purpose, so installing
# system-wide is fine and avoids changing how entrypoint.sh calls python3.
ENV PIP_BREAK_SYSTEM_PACKAGES=1

# Installing all needed applications
RUN apt-get clean \
Expand All @@ -20,14 +24,19 @@ RUN apt-get clean \

# Adding python3 libraries
RUN python3 -m pip install --upgrade pip
RUN python3 -m pip install numpy
RUN python3 -m pip install obspy
RUN python3 -m pip install pyrocko
RUN python3 -m pip install plotly
#RUN python3 -m pip install sklearn
RUN python3 -m pip install scipy
RUN python3 -m pip install pandas
RUN python3 -m pip install geographiclib
# One resolver run, so the pins hold across all packages: installed one by
# one, a later package silently upgrades numpy past what pyrocko accepts.
# numpy<2 is required by pyrocko on Python <= 3.11; pandas<3 because
# pyml.py assigns float results into columns that pandas 3 no longer
# upcasts (LossySetitemError). Both match what bullseye was resolving to.
RUN python3 -m pip install \
"numpy<2" \
obspy \
pyrocko \
plotly \
scipy \
"pandas<3" \
geographiclib

COPY ./dbona_magnitudes_stations_corrections_extended_mq.csv /opt/dbona_magnitudes_stations_corrections_extended_mq.csv
COPY ./pyml.py /opt/pyml.py
Expand Down
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# pyml [![Version](https://img.shields.io/badge/dynamic/yaml?label=ver&query=softwareVersion&url=https://raw.githubusercontent.com/INGV/pyml/main/publiccode.yml)](https://github.com/INGV/pyml/blob/main/publiccode.yml) | [![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ingv/pyml/docker-image.yml?branch=main&style=flat&logo=GitHub-Actions&logoColor=white&logoSize=auto&label=GitHub%20Actions)](https://github.com/INGV/pyml/actions)
## Introduction
Python code, complementary to pyamp, to calculate ML with different methods and attenuation functions using pyamp_amplitude output file or database table.
Python code, complementary to pyamp or REI, to calculate ML with different methods and attenuation functions.

## Quickstart
### Docker image
Expand All @@ -37,6 +37,27 @@ To run the container, use the command below; the `-v` option is used to "mount"
docker run --rm -v $(pwd)/examples/input:/opt/data ingv/pyml --in_file_name /opt/data/eventid_28745631.json --in_file_format json --out_format json
```

## Station metadata

Station azimuths are measured from the station toward the event. A bearing of
`0.0` degrees is valid and is returned as a JSON number on both horizontal
components. An azimuth or angular distance that was not calculated is returned
as JSON `null`. Zero latitude, longitude and elevation are valid metadata;
stations with missing coordinates or elevation are omitted from the
`stationmagnitudes` list.

## Tests

With the Python dependencies listed in `Dockerfile` installed, run:

```sh
python3 -m unittest discover -s tests -v
```

The tests run the complete CLI in temporary directories. They cover the CPTP
zero-azimuth regression reported in REI issue #684, nonzero bearings, sea-level
and zero-coordinate stations, missing metadata, and unchanged magnitude results.

## Contribute
Thanks to your contributions!

Expand Down
Loading
Loading