Skip to content

Commit

Permalink
refactor: Refactor pyrorisks (#83)
Browse files Browse the repository at this point in the history
* refactor: Deprecate the outdated pyro_risks modules, CLI, and examples

* refactor: Remove Heroku deployment files

* refactor: Remove DVC / CML pipelines

* chore: Add poetry for packaging and dependency management

* chore: Bump Geopandas to 1.0.1, replace fiona backend with pyogrio

* chore: Add rasterio manylinux wheel

* chore: Add ruff for linting and formatting

* chore: Update docker build and config

* chore: Update CI workflows

* chore: Add Mock predictor

* fix: Update mypy config 

* fix: Fix type hints and linting

* style: Fix type hints, formatting, and linting

* docs: Remove deprecated modules from docs
  • Loading branch information
jsakv authored Jul 12, 2024
1 parent fcc633d commit 1b07dc2
Show file tree
Hide file tree
Showing 107 changed files with 2,770 additions and 6,170 deletions.
2 changes: 0 additions & 2 deletions .coveragerc

This file was deleted.

3 changes: 0 additions & 3 deletions .dvc/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions .dvc/config

This file was deleted.

3 changes: 0 additions & 3 deletions .dvcignore

This file was deleted.

4 changes: 0 additions & 4 deletions .flake8

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: web-server
name: builds

on:
push:
Expand All @@ -7,14 +7,14 @@ on:
branches: [ master ]

jobs:
docker-ready:
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build & run docker
- uses: actions/checkout@v4
- name: Build & run docker container
env:
CDS_UID: ${{ secrets.CDS_UID }}
CDS_API_KEY: ${{ secrets.CDS_API_KEY }}
run: PORT=8003 docker-compose up -d --build
- name: Ping app inside the container
- name: Ping containerized app
run: sleep 5 && nc -vz localhost 8003
28 changes: 8 additions & 20 deletions .github/workflows/doc-deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,27 @@
name: doc-deploy
on:
push:
branches: master
branches: [master]

jobs:
docs-publish:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
persist-credentials: false
- name: Set up Python 3.7
- name: Set up Python 3.10.5
uses: actions/setup-python@v1
with:
python-version: 3.7
architecture: x64
- name: Cache python modules
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pkg-deps-${{ hashFiles('requirements.txt') }}-${{ hashFiles('**/*.py') }}
restore-keys: |
${{ runner.os }}-pkg-deps-${{ hashFiles('requirements.txt') }}-
${{ runner.os }}-pkg-deps-
${{ runner.os }}-
python-version: 3.10.5

- name: Install dependencies
run: |
sudo apt install libspatialindex-dev python3-rtree
python -m pip install --upgrade pip
pip install -e .
pip install -r docs/requirements.txt
run: poetry install


- name: Build documentation
run: |
sphinx-build docs/source docs/build -a -v
poetry run sphinx-build docs/source docs/build -a -v
- name: Install SSH Client 🔑
uses: webfactory/ssh-agent@v0.4.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ jobs:
see-page-build-payload:
runs-on: ubuntu-latest
steps:
- name: Set up Python 3.7
uses: actions/setup-python@v1
- name: Set up Python 3.10.5
uses: actions/setup-python@v4
with:
python-version: 3.7
architecture: x64
python-version: 3.10.5

- name: check status
run: |
import os
Expand Down
26 changes: 0 additions & 26 deletions .github/workflows/get_today_effis_fwi.yml

This file was deleted.

46 changes: 0 additions & 46 deletions .github/workflows/main.yml

This file was deleted.

1 change: 0 additions & 1 deletion .github/workflows/requirements.txt

This file was deleted.

37 changes: 37 additions & 0 deletions .github/workflows/scripts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Scheduled Scripts

on:
workflow_dispatch:
schedule:
- cron: "0 1 * * *"

jobs:
get-effis-fwi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Python Version
uses: actions/setup-python@v4
with:
python-version: 3.10.5

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.1
virtualenvs-create: true
virtualenvs-in-project: true

- name: Install dependencies
run: poetry install

- name: Get Today Effis Fwi
run: poetry run python pyrorisks/platform_fwi/main.py
env:
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
BUCKET_NAME: risk
REGION_NAME: gra
ENDPOINT_URL: https://s3.gra.io.cloud.ovh.net/

80 changes: 80 additions & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: style

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
linting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python Version
uses: actions/setup-python@v4
with:
python-version: 3.10.5

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.1
virtualenvs-create: true
virtualenvs-in-project: true

- name: Install dependencies
run: poetry install

- name: Run Ruff linter
run: |
poetry run ruff --version
poetry run ruff check --diff .
formating:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python Version
uses: actions/setup-python@v4
with:
python-version: 3.10.5

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.1
virtualenvs-create: true
virtualenvs-in-project: true

- name: Install dependencies
run: poetry install

- name: Run Ruff formatter
run: |
poetry run ruff --version
poetry run ruff format --diff .
typing:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python Version
uses: actions/setup-python@v4
with:
python-version: 3.10.5

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.1
virtualenvs-create: true
virtualenvs-in-project: true

- name: Install dependencies
run: poetry install

- name: Run mypy
run: |
poetry run mypy --version
poetry run mypy app pyrorisks
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ __pycache__/

# Distribution / packaging
.Python
build/
docs/build/
develop-eggs/
dist/
downloads/
Expand Down
2 changes: 0 additions & 2 deletions Aptfile

This file was deleted.

37 changes: 14 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
FROM python:3.8.1
FROM python:3.10-buster

# set work directory
WORKDIR /usr/src/app
RUN pip install poetry==1.8.1

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache \
VIRTUAL_ENV=/app/.venv \
PATH="/app/.venv/bin:$PATH"

# copy app requirements
COPY ./requirements.txt requirements.txt
COPY ./requirements-app.txt /usr/src/app/requirements-app.txt
COPY ./setup.py setup.py
COPY ./README.md README.md
COPY ./pyro_risks pyro_risks
WORKDIR /app

# install dependencies
RUN apt-get update && \
apt-get install --no-install-recommends -y libspatialindex-dev python3-rtree && \
pip install --upgrade pip setuptools wheel && \
pip install -e . && \
pip install -r /usr/src/app/requirements-app.txt && \
mkdir /usr/src/app/app && \
rm -rf /root/.cache/pip && \
rm -rf /var/lib/apt/lists/*
COPY pyrorisks ./pyrorisks
COPY app ./app
COPY build ./build
COPY pyproject.toml poetry.lock README.md ./

# copy project
COPY app/ /usr/src/app/app/
RUN poetry install
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

File renamed without changes.
File renamed without changes.
10 changes: 7 additions & 3 deletions app/api/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
# This program is licensed under the Apache License version 2.
# See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0.txt> for full license details.

from pyro_risks.models.predict import PyroRisk


__all__ = ["predictor"]


predictor = PyroRisk(which="RF")
class Mock:
def predict(self, date):
_ = date
return {"01": {"score": 0.5, "explainability": "weather"}, "02": {"score": 0.5, "explainability": "weather"}}


predictor = Mock()
Empty file added app/api/routes/__init__.py
Empty file.
5 changes: 1 addition & 4 deletions app/api/routes/risk.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,4 @@
async def get_pyrorisk(country: str, date: str):
"""Using the country identifier, this will compute the wildfire risk for all known subregions"""
preds = predictor.predict(date)
return [
RegionRisk(geocode=k, score=v["score"], explainability=v["explainability"])
for k, v in preds.items()
]
return [RegionRisk(geocode=k, score=v["score"], explainability=v["explainability"]) for k, v in preds.items()]
Loading

0 comments on commit 1b07dc2

Please sign in to comment.