Skip to content
Snippets Groups Projects
Commit da901fee authored by Nicolas Schmid's avatar Nicolas Schmid
Browse files

feat: Initial Commit

parents
No related branches found
No related tags found
No related merge requests found
*.pyc
*.swp
src/*
*.db
test.py
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
This diff is collapsed.
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
\ No newline at end of file
from ramsis.schemas import ModelInput # noqa
from ramsis.validation import validate_entrypoint # noqa
from datetime import datetime
from pydantic import BaseModel, ConfigDict
class GeometryExtent(BaseModel):
bounding_polygon: str
altitude_min: float
altitude_max: float
class ModelInput(BaseModel):
forecast_start: datetime
forecast_end: datetime
injection_well: dict | str | None = None
injection_plan: dict | str | None = None
geometry: GeometryExtent
seismic_catalog: str
model_parameters: dict
model_config = ConfigDict(
protected_namespaces=()
)
from functools import wraps
import pandas as pd
from hydws.parser import BoreholeHydraulics
from seismostats import Catalog, GRRateGrid
from seismostats.utils import _check_required_cols
from shapely import wkt
from ramsis.schemas import ModelInput
def validate_entrypoint(func):
@wraps(func)
def wrapper(*args, **kwargs):
# check only one argument is passed
if len(args) != 1:
raise ValueError("Only one argument is allowed")
model_input = ModelInput(**args[0])
# check if hydraulics are in the right format
try:
BoreholeHydraulics(model_input.injection_well)
except BaseException:
raise ValueError("Invalid format for injection well, "
"please use valid hydjson.")
try:
BoreholeHydraulics(model_input.injection_plan)
except BaseException:
raise ValueError("Invalid format for injection plan, "
"please use valid hydjson.")
try:
Catalog.from_quakeml(model_input.seismic_catalog)
except BaseException:
raise ValueError("Invalid format for seismic catalog, "
"please use valid quakeml.")
try:
wkt.loads(model_input.geometry.bounding_polygon)
except BaseException:
raise ValueError("Invalid format for bounding polygon, "
"please use valid WKT.")
results = func(model_input, **kwargs)
if not all(isinstance(r, GRRateGrid)
or isinstance(r, Catalog)
or isinstance(r, pd.DataFrame) for r in results):
raise ValueError(
"Results need to be of type (Forecast)GRRateGrid, "
"(Forecast)Catalog or DataFrame.")
if not all(
_check_required_cols(r, Catalog._required_cols)
for r in results) \
and not all(
_check_required_cols(r, GRRateGrid._required_cols)
for r in results):
raise ValueError("Results are missing required columns.")
return results
return wrapper
[metadata]
name = ramsis-model
author =
Schmid Nicolas
author_email =
nicolas.schmid@sed.ethz.ch
version = 0.1.0
description =
Interface and documentation on how to create an interface to the RAMSIS software.
long_description = file: README.md, LICENSE
license = AGPL License
classifiers =
Programming Language :: Python :: 3
[options]
packages = find:
install_requires =
hydws-client @ git+https://git@gitlab.seismo.ethz.ch/indu/hydws-client.git@v2.0
pydantic
seismostats @ git+https://github.com/swiss-seismological-service/SeismoStats.git@main
python_requires = >= 3.10
[options.extras_require]
dev =
pytest
pytest-cov
autopep8
flake8
[flake8]
select = E,F,W
max_line_length = 79
ignore = E402, W503
exclude =
.git,
.tox,
.eggs,
.config,
*.egg-info,
__pycache__,
.pytest_cache,
env,
tox.ini 0 → 100644
[tox]
envlist = py310-tests,flake8
minversion = 4.0
[testenv]
usedevelop = true
download = true
extras =
tests
py310: py310
deps =
cython
[testenv:flake8]
skip_install = true
deps = flake8
commands = flake8 .
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment