-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Amendments to KDE calculation for rare but possible 0.0 distance value.
Removed mypy as dev dependency, added coverage. Added tests - >=95% coverage on _utils and geokde. Added lint, test, and publish GH Actions YAML files.
- Loading branch information
1 parent
f085da6
commit b4e4e38
Showing
14 changed files
with
412 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
name: Lint | ||
on: | ||
push: | ||
paths: | ||
- geokde/** | ||
- .github/** | ||
- tests/** | ||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set-up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.10' | ||
|
||
- name: Install Poetry and dependencies | ||
run: | | ||
pip install poetry | ||
poetry install | ||
- name: Run pre-commit | ||
run: poetry run pre-commit run --all-files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
name: Publish | ||
on: | ||
release: | ||
types: [published] | ||
permissions: | ||
contents: read | ||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set-up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.10' | ||
- name: Install Poetry | ||
run: pip install poetry | ||
|
||
- name: Set PyPI token | ||
run: poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }} | ||
|
||
- name: Install dependencies | ||
run: poetry install | ||
|
||
- name: Publish to PyPI | ||
run: poetry publish --build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
--- | ||
name: Test | ||
on: | ||
push: | ||
paths: | ||
- geokde/** | ||
- .github/** | ||
- tests/** | ||
jobs: | ||
test: | ||
name: ${{ matrix.os }} / ${{ matrix.python-version }} | ||
runs-on: ${{ matrix.image }} | ||
strategy: | ||
matrix: | ||
os: | ||
- Ubuntu | ||
- macOS | ||
- Windows | ||
python-version: | ||
- '3.10' | ||
include: | ||
- os: Ubuntu | ||
image: ubuntu-latest | ||
- os: Windows | ||
image: windows-latest | ||
- os: macOS | ||
image: macos-latest | ||
fail-fast: false | ||
defaults: | ||
run: | ||
shell: bash | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set-up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install Poetry | ||
run: curl -sL https://install.python-poetry.org | python - -y | ||
|
||
- name: Update PATH for Ubuntu and MacOS | ||
if: ${{ matrix.os != 'Windows' }} | ||
run: echo "$HOME/.local/bin" >> $GITHUB_PATH | ||
|
||
- name: Update Path for Windows | ||
if: ${{ matrix.os == 'Windows' }} | ||
run: echo "$APPDATA\Python\Scripts" >> $GITHUB_PATH | ||
|
||
- name: Configure Poetry | ||
run: poetry config virtualenvs.in-project true | ||
|
||
- name: Check Poetry lock | ||
run: poetry check --lock | ||
|
||
- name: Install dependencies | ||
run: poetry install | ||
|
||
- name: Run pytest | ||
run: poetry run pytest -s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,49 @@ | ||
## Roadmap | ||
------- | ||
![pypi version](https://img.shields.io/pypi/v/geokde) | ||
![pypi downloads](https://img.shields.io/pypi/dm/geokde) | ||
[![publish](https://github.com/duncanmartyn/geokde/actions/workflows/publish.yaml/badge.svg?branch=main)](https://github.com/duncanmartyn/geokde/actions/workflows/publish.yaml) | ||
[![test](https://github.com/duncanmartyn/geokde/actions/workflows/test.yaml/badge.svg?branch=main)](https://github.com/duncanmartyn/geokde/actions/workflows/test.yaml) | ||
[![security: bandit](https://img.shields.io/badge/security-bandit-yellow.svg)](https://github.com/PyCQA/bandit) | ||
|
||
# GeoKDE | ||
Package for geospatial kernel density estimation (KDE). | ||
|
||
Written in Python 3.10.11 (though compatible with 3.10.11+), GeoKDE depends on the following: | ||
- `geopandas` | ||
- `numpy` (itself a dependency of `geopandas`) | ||
|
||
# Examples | ||
Perform KDE on a GeoJSON of point geometries and write the result to a GeoTIFF raster file with `rasterio`: | ||
``` | ||
gdf = geopandas.read_file("vector_points.geojson") | ||
kde_array, array_bounds = geokde.kde(gdf, 1, 0.1) | ||
transform = rasterio.transform.from_bounds( | ||
*array_bounds, | ||
kde_array.shape[1], | ||
kde_array.shape[0], | ||
) | ||
with rasterio.open( | ||
fp="raster.tif", | ||
mode="w", | ||
driver="GTiff", | ||
width=kde_array.shape[1], | ||
height=kde_array.shape[0], | ||
count=1, | ||
crs=gdf.crs, | ||
transform=transform, | ||
dtype=kde_array.dtype, | ||
nodata=0.0, | ||
) as dst: | ||
dst.write(kde_array, 1) | ||
``` | ||
|
||
# Roadmap | ||
- Add more kernels. | ||
- Implement other methods of distance measurement, e.g. haversine, manhattan. | ||
- Investigate possible alternatives to iterating over points. | ||
- Enable use of single radius and weight values without filling array of the same length as the points GeoDataFrame/GeoSeries. Results in marginal speed up but the current approach may become an issue with large point datasets. | ||
- Finish tests - coverage is >=95% for _utils.py and geokde.py as is. | ||
- Implement other methods of distance measurement, e.g. haversine, Manhattan. | ||
- Investigate alternatives to iterating over points. | ||
- Enable use of single radius and weight values without filling array of the same length as the points GeoDataFrame/GeoSeries. Results in marginal speed up but the current approach may become an issue with very large point datasets. | ||
- Integrate mypy in pre-commit, possibly also linter and formatter though flake8 and black used locally. | ||
|
||
# Contributions | ||
Feel free to raise any issues, especially bugs and feature requests! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.