Skip to content

Commit

Permalink
Merge pull request #76 from munterfi/bugfix/ci-poetry-install
Browse files Browse the repository at this point in the history
Bugfix/ci poetry install
  • Loading branch information
munterfi authored Dec 7, 2022
2 parents 5da51cd + 9d1b176 commit 8ede50c
Show file tree
Hide file tree
Showing 11 changed files with 884 additions and 628 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/gdal-stable-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
- name: Install poetry
run: |
curl -sSL \
"https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py" | python
curl -sSL https://install.python-poetry.org | python3 -
echo "${HOME}/.local/bin" >> $GITHUB_PATH
- name: Set up cache
uses: actions/cache@v1
Expand All @@ -36,7 +36,6 @@ jobs:

- name: Install dependencies
run: |
source "$HOME/.poetry/env"
poetry config virtualenvs.in-project true
# Pip install without GDAL
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/gdal-unstable-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
- name: Install poetry
run: |
curl -sSL \
"https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py" | python
curl -sSL https://install.python-poetry.org | python3 -
echo "${HOME}/.local/bin" >> $GITHUB_PATH
- name: Set up cache
uses: actions/cache@v1
Expand All @@ -35,7 +35,6 @@ jobs:

- name: Install dependencies
run: |
source "$HOME/.poetry/env"
poetry config virtualenvs.in-project true
# Pip install without GDAL
Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/package-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
- name: Install poetry
run: |
curl -sSL \
"https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py" | python
curl -sSL https://install.python-poetry.org | python3 -
echo "${HOME}/.local/bin" >> $GITHUB_PATH
- name: Set up cache
uses: actions/cache@v1
Expand All @@ -33,21 +33,16 @@ jobs:

- name: Install dependencies
run: |
source "$HOME/.poetry/env"
poetry config virtualenvs.in-project true
# Install
poetry install
- name: Run checks
run: |
source "$HOME/.poetry/env"
poetry run flake8 glacier_flow_model tests --count
poetry run mypy .
poetry run pytest --cov=glacier_flow_model
cd docs && poetry run make html && cd ..
- name: Upload coverage reports to Codecov
run: |
source "$HOME/.poetry/env"
poetry run codecov
7 changes: 2 additions & 5 deletions .github/workflows/package-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@ jobs:
- name: Install poetry
run: |
curl -sSL \
"https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py" | python
curl -sSL https://install.python-poetry.org | python3 -
echo "${HOME}/.local/bin" >> $GITHUB_PATH
- name: Install dependencies
run: |
source "$HOME/.poetry/env"
poetry config virtualenvs.in-project true
poetry install
- name: Run checks
run: |
source "$HOME/.poetry/env"
poetry run flake8 glacier_flow_model tests --count
poetry run mypy .
poetry run pytest --cov=glacier_flow_model
Expand All @@ -46,7 +44,6 @@ jobs:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
source "$HOME/.poetry/env"
poetry build
python3 -m pip install --upgrade twine
python3 -m twine upload dist/*
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ Changelog

This packages uses `semantic versioning <https://semver.org/>`_.

Version 0.3.0
-------------

- Features:
- Remove the direct dependency on GDAL via the :code:`osgeo` package and
use the :code:`rasterio` package to read and write raster files instead.
- Bugfixes:
- Fix failing CI due to an defunct poetry installation instruction.

Version 0.2.0
-------------

Expand Down
1 change: 1 addition & 0 deletions docs/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ channels:
dependencies:
- scipy
- numpy
- rasterio
- gdal
- libgdal
- matplotlib
Expand Down
8 changes: 4 additions & 4 deletions glacier_flow_model/data/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import importlib.resources as resources
from logging import getLogger

from osgeo.gdal import Dataset
from osgeo.gdal import Open
from rasterio import open
from rasterio import DatasetReader

LOG = getLogger(__name__)

Expand Down Expand Up @@ -39,7 +39,7 @@ def locate_dem() -> str:
return str(file_path)

@staticmethod
def load_dem() -> Dataset:
def load_dem() -> DatasetReader:
"""
Loads the file 'dem.tif' on the current system.
Expand All @@ -51,5 +51,5 @@ def load_dem() -> Dataset:
"""
file_path = PkgDataAccess.locate_dem()
LOG.info("Reading DEM from '%s' ...", file_path)
dem = Open(file_path)
dem = open(file_path)
return dem
34 changes: 11 additions & 23 deletions glacier_flow_model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
from osgeo.gdal import GDT_Float32
from osgeo.gdal import GetDriverByName
from osgeo.gdal import Open
from rasterio import open
from scipy.ndimage import gaussian_filter
from scipy.ndimage import uniform_filter

Expand Down Expand Up @@ -120,9 +118,8 @@ def __init__(
"""

# Load DEM ------------------------------------------------------------
dem = Open(dem_path)
band = dem.GetRasterBand(1)
ele = band.ReadAsArray().astype(np.float32)
dem = open(dem_path)
ele = dem.read(1).astype(np.float32)

# Instance variables --------------------------------------------------
self.model_name = Path(dem_path).stem if model_name is None else model_name
Expand All @@ -138,15 +135,11 @@ def __init__(
self._setup_ndarrays() # Variable arrays (ele, h, u ,hs)

# Coordinate reference system and dem resolution
self._geo_trans = dem.GetGeoTransform()
self._geo_proj = dem.GetProjection()
self.res = self._geo_trans[1]
self._dem_meta = dem.meta
self.res = dem.res[0]

# Geographical extent of the dem
nrows, ncols = ele.shape
x0, dx, dxdy, y0, dydx, dy = self._geo_trans
x1 = x0 + dx * ncols
y1 = y0 + dy * nrows
x0, y0, x1, y1 = dem.bounds
self.extent = (x0, x1, y1, y0)

# Setup statistics
Expand Down Expand Up @@ -591,16 +584,11 @@ def _export_tif(self, file_path: Path) -> None:
self.h.shape[1],
file_path,
)
driver = GetDriverByName("GTiff")
data_set = driver.Create(
str(file_path), self.h.shape[1], self.h.shape[0], 3, GDT_Float32
)
data_set.GetRasterBand(1).WriteArray(self.store.mean("h"))
data_set.GetRasterBand(2).WriteArray(self.store.mean("u"))
data_set.GetRasterBand(3).WriteArray(self.store.diff("h"))
data_set.SetGeoTransform(self._geo_trans)
data_set.SetProjection(self._geo_proj)
data_set.FlushCache()
self._dem_meta.update(count=3)
with open(file_path, 'w', **self._dem_meta) as dst:
dst.write_band(1, self.store.mean("h"))
dst.write_band(2, self.store.mean("u"))
dst.write_band(3, self.store.diff("h"))

# Visualization -----------------------------------------------------------
@staticmethod
Expand Down
Loading

0 comments on commit 8ede50c

Please sign in to comment.