Skip to content

Staging #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cf6373f
[hotfix] change default requirements to production requirements
Croydon-Brixton Jul 13, 2022
54e0de1
aux: add github action for pypi publishing
rdnfn Sep 23, 2022
f2955f1
docs: add guide for maintaining package and publishing to pypi
rdnfn Sep 23, 2022
a3e647d
rename workfow to pytest.yml
sdat2 Sep 23, 2022
0446ac4
added data-loading code back
kenzaxtazi Sep 23, 2022
1b9eb1c
fixing fstring issue?
sdat2 Sep 23, 2022
5dcdd40
[feature] add optional mamba support in makefile
Croydon-Brixton Sep 23, 2022
35b9bc1
[fix] data loading
kenzaxtazi Sep 23, 2022
df9a4ae
trying to use pytest test data in unit tests
sdat2 Sep 23, 2022
9ab44d9
fix GeoGraph typo
sdat2 Sep 23, 2022
408f2ac
added output
sdat2 Sep 23, 2022
adcfe22
removing pointer
sdat2 Sep 23, 2022
8bf31f6
adding output
sdat2 Sep 23, 2022
adb232d
[fix] bump binder environment and fix dependencies to fix binder bugs
Croydon-Brixton Sep 23, 2022
4499594
[fix]: all docstrings for metric functions
kenzaxtazi Sep 23, 2022
343e1ff
[fix] fix problems with default requirements
Croydon-Brixton Sep 23, 2022
d8b1df8
[temp] remove rasterio pin to 1.1.8
Croydon-Brixton Sep 23, 2022
efbf476
[fix] loose fix requirements for main version
Croydon-Brixton Sep 23, 2022
2518dff
[clean] clean up requirements files
Croydon-Brixton Sep 23, 2022
b40b61a
[merge] merge staging branch into current
Croydon-Brixton Sep 23, 2022
3ce2622
Merge pull request #80 from ai4er-cdt/Croydon-Brixton-patch-1
Croydon-Brixton Sep 23, 2022
b20c22f
Merge pull request #85 from ai4er-cdt/feature/pypi-gh-action
rdnfn Sep 23, 2022
25b85bc
Merge pull request #88 from ai4er-cdt/kenza
kenzaxtazi Sep 23, 2022
8d55a33
Merge pull request #87 from ai4er-cdt/feature/unit-tests
sdat2 Sep 23, 2022
37a07cd
[fix] correct github repo in html context of sphinx documentation
Croydon-Brixton Sep 23, 2022
a7f0671
[format] apply black and isort to standardise files
Croydon-Brixton Sep 23, 2022
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
42 changes: 42 additions & 0 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Publish package to PyPI

on:
release:
types: [published]

permissions:
contents: read

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package
name: pytest

on:
push:
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
repos:
- repo: https://github.com/psf/black
rev: 20.8b1
rev: 22.8.0
hooks:
- id: black
language_version: python3.8
language_version: python3.10
- repo: https://github.com/pycqa/pylint
rev: pylint-2.6.0
hooks:
Expand Down
25 changes: 17 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ else
HAS_CONDA=True
endif

ifeq (,$(shell which mamba))
HAS_MAMBA=False
else
HAS_MAMBA=True
endif

#################################################################################
# COMMANDS #
#################################################################################
Expand All @@ -30,6 +36,7 @@ lint:

## Format geograph directory using black
format:
isort geograph
black geograph

## Set up pre-commit hooks
Expand All @@ -39,20 +46,22 @@ precommit:

## Set up python interpreter environment and install basic dependencies
env:
ifeq (True,$(HAS_CONDA))
@echo ">>> Detected conda, creating conda environment."
ifeq (True, $(HAS_MAMBA))
@echo ">>> Detected mamba, creating conda environment via mamba."

# Create the conda environment
mamba env create --prefix=./env -f requirements/environment.yml

@echo ">>> New mamba env created. Activate from project directory with:\nconda activate ./env"
else ifeq (True,$(HAS_CONDA))
@echo ">>> Detected conda, creating conda environment."

# Create the conda environment
conda env create --prefix=./env -f requirements/environment.yml

@echo ">>> New conda env created. Activate from project directory with:\nconda activate ./env"
else
@echo ">>> No conda detected. Falling back to virtualenv instead. The python verison will be that of your python3 interpreter."
$(PYTHON_INTERPRETER) -m pip install -q virtualenv virtualenvwrapper
@echo ">>> Installing virtualenvwrapper if not already installed.\nMake sure the following lines are in shell startup file\n\
export WORKON_HOME=$$HOME/.virtualenvs\nexport PROJECT_HOME=$$HOME/Devel\nsource /usr/local/bin/virtualenvwrapper.sh\n"
@bash -c "source `which virtualenvwrapper.sh`;mkvirtualenv $(PROJECT_NAME) --python=$(PYTHON_INTERPRETER)"
@echo ">>> New virtualenv created. Activate with:\nworkon $(PROJECT_NAME)"
@echo ">>> No conda detected. Please install conda or manually install requirements in your preferred python version."
endif

#################################################################################
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

![GeoGraphViewer demo gif](docs/images/viewer_demo.gif)


__Table of contents:__
1. Description
1. Installation
Expand Down
36 changes: 33 additions & 3 deletions binder/environment.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
prefix: ./env
channels:
- conda-forge
- defaults
dependencies:
- python=3.8
- pip
- python=3.10
- pip==21.2.4
# linear algebra and general data analysis
- numpy ==1.23.3 # arrays, linear algebra
- pandas ==1.5.0 # tabular data analysis

# plotting
- folium ==0.12.1.post1 # plotting maps
- ipyleaflet ==0.17.1 # plotting ipywidget maps

# interactive computing
- tqdm ==4.64.1 # progress bars

# geospatial analysis requirements
# vector data
- geopandas ==0.11.1 # manipulating geospatial vector data
- shapely ==1.8.4 # working with vector shapes
- rtree ==1.0.0 # efficiently querying polygon data
# raster data
- rasterio ==1.3.2 # opening and loading raster data
- xarray ==2022.6.0 # useful data structures

# graph requirements
- networkx ==2.8.6 # manipulating graph data

# For binder
- rioxarray ==0.12.2
- seaborn ==0.12.0
- netcdf4 ==1.6.1

- pip:
- -r requirements.txt
- pylandstats ==2.4.2
- -e ..
38 changes: 0 additions & 38 deletions binder/requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
html_context = {
"display_github": True,
"github_user": "ai4er-cdt",
"github_repo": "gtc-biodiversity",
"github_repo": "geograph",
"github_version": "main/docs/",
}

Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Polygon Data Visualisation
installation
tutorials
geograph
maintenance
about


Expand Down
20 changes: 20 additions & 0 deletions docs/maintenance.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Maintenance
===========

Some tips for the maintainers of this project.

Deploying
---------

A reminder for the maintainers on how to deploy. Follow this checklist (inspired by `this checklist <https://gist.github.com/audreyfeldroy/5990987>`_ and `this packaging tutorial <https://packaging.python.org/en/latest/tutorials/packaging-projects/>`_):

1. Update ``HISTORY.rst`` and commit with message like "aux: add changelog for upcoming release 0.1.0"
2. Run

.. code-block:: console

bump2version patch # possible: major / minor / patch

3. Push commits *and tags* (`see here how to do this in vscode <https://stackoverflow.com/a/66086007>`_)
4. Merge pull request into ``main`` branch.
5. Add release on GitHub (using existing tag)
3 changes: 3 additions & 0 deletions geograph/binary_graph_operations.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
"""Contains tools for binary operations between GeoGraph objects."""
from __future__ import annotations

from typing import TYPE_CHECKING, Dict, List, Tuple

import geopandas as gpd
from shapely.geometry.base import BaseGeometry
from shapely.geometry.polygon import Polygon

import geograph.utils.geopandas_utils as gpd_utils
from geograph.utils.polygon_utils import EMPTY_POLYGON, collapse_empty_polygon

Expand Down
1 change: 0 additions & 1 deletion geograph/demo/binder_constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""This file is for constants relevant to the binder demo."""
from geograph.constants import PROJECT_PATH


# Data directory on GWS
DATA_DIR = PROJECT_PATH / "data"
# Polygon data of Chernobyl Exclusion Zone (CEZ)
Expand Down
1 change: 1 addition & 0 deletions geograph/demo/plot_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import itertools
from distutils.spawn import find_executable
from typing import Sequence, Tuple

import matplotlib
import matplotlib.style
import numpy as np
Expand Down
13 changes: 13 additions & 0 deletions geograph/geograph.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
See https://networkx.org/documentation/stable/index.html for graph operations.
"""
from __future__ import annotations

import bz2
import gzip
import inspect
Expand All @@ -13,6 +14,7 @@
from copy import deepcopy
from itertools import zip_longest
from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Union

import geopandas as gpd
import networkx as nx
import numpy as np
Expand All @@ -22,6 +24,7 @@
import shapely
from shapely.prepared import prep
from tqdm import tqdm

from geograph import binary_graph_operations, metrics
from geograph.metrics import CLASS_METRICS_DICT, Metric
from geograph.utils import rasterio_utils
Expand Down Expand Up @@ -107,6 +110,16 @@ def __init__(
**apply_buffer (bool, optional): Apply shapely buffer function to
the polygons after polygonising. This can fix issues with the
polygonisation creating invalid geometries.

Example::
>>> import os
>>> from geograph.constants import WGS84
>>> from geograph.tests.create_data_test import TEST_DATA_FOLDER
>>> gg = GeoGraph(os.path.join(TEST_DATA_FOLDER, "adjacent", "full.gpkg"), WGS84, "savepath.gz")
Graph successfully loaded with 15 nodes and 40 edges.
>>> gg.crs == WGS84
True

"""
super().__init__()
self.graph = nx.Graph()
Expand Down
3 changes: 3 additions & 0 deletions geograph/geotimeline.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"""Module for analysing multiple GeoGraph objects."""
from __future__ import annotations

import datetime
from bisect import bisect_left
from typing import Callable, Dict, Iterable, List, Optional, Tuple, Union

import numpy as np
import pandas as pd
import xarray as xr

from geograph import GeoGraph
from geograph.binary_graph_operations import NodeMap, identify_graphs

Expand Down
Loading