Skip to content

Commit

Permalink
Merge pull request #70 from ai4er-cdt/feature/misc-issues
Browse files Browse the repository at this point in the history
Misc Issues PR
  • Loading branch information
herbiebradley authored May 19, 2021
2 parents 7ac51e5 + 9675843 commit 5bc5892
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 97 deletions.
39 changes: 28 additions & 11 deletions PYPI_README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
<p align="center">
<img src="https://raw.githubusercontent.com/ai4er-cdt/gtc-biodiversity/main/docs/images/geograph_logo.png" alt="GeoGraph" width="300px">
<img src="https://raw.githubusercontent.com/ai4er-cdt/geograph/main/docs/images/geograph_logo.png" alt="GeoGraph" width="300px">
</p>

_Created as part of the AI4ER Group Team Challenge 2021 by the Biodiversity Team._


[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/ai4er-cdt/gtc-biodiversity/main?urlpath=lab%2Ftree%2Fnotebooks)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/ai4er-cdt/geograph/main?urlpath=lab%2Ftree%2Fnotebooks)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
[![Documentation Status](https://readthedocs.org/projects/geograph/badge/?version=latest)](https://geograph.readthedocs.io/en/latest/?badge=latest)

See the [Github repository](https://github.com/ai4er-cdt/gtc-biodiversity) for full details.

## 1. Features
__Table of contents:__
1. Description
2. Installation
3. Requirements
4. Documentation

## 1. Description

GeoGraph provides a tool for analysing habitat fragmentation and related problems in landscape ecology. GeoGraph builds a geospatially referenced graph from land cover or field survey data and enables graph-based landscape ecology analysis as well as interactive visualizations. Beyond the graph-based features, GeoGraph also enables the computation of common landscape metrics.

## 2. Installation

GeoGraph is available via pip, so you can install it using

```
pip install geograph
```

Done, you're ready to go!

You can also visit the [Github repository](https://github.com/ai4er-cdt/geograph).

See the [documentation](https://geograph.readthedocs.io/) for a full getting started guide or check out the [binder](https://mybinder.org/v2/gh/ai4er-cdt/geograph/main?urlpath=lab%2Ftree%2Fnotebooks) for tutorials on how to get started .

GeoGraph provides a full-stack tool for analysing habitat fragmentation, and other related problems. It includes models to predict land cover classes, a method to extract graph structure from the resulting land cover maps and an extensive range of visualisation and analysis tools.
## 3. Requirements

## 2. Requirements
GeoGraph is written in Python 3.8 and builds on [NetworkX](https://github.com/NetworkX/NetworkX), [ipyleaflet](https://github.com/jupyter-widgets/ipyleaflet), [geopandas](https://geopandas.org/), [rasterio](https://rasterio.readthedocs.io/en/latest/) and many more packages. See the [requirements directory](./requirements) for a full list of dependencies.

GeoGraph is written in Python 3.8 and builds on [NetworkX](https://github.com/NetworkX/NetworkX), [ipyleaflet](https://github.com/jupyter-widgets/ipyleaflet) and many more packages. See the [requirements directory](https://github.com/ai4er-cdt/gtc-biodiversity/tree/main/requirements) for a full list of dependencies.
## 3. Documentation
## 4. Documentation

Our documentation is available at [geograph.readthedocs.io](https://geograph.readthedocs.io/).
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
</p>


[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/ai4er-cdt/gtc-biodiversity/main?urlpath=lab%2Ftree%2Fnotebooks)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/ai4er-cdt/geograph/main?urlpath=lab%2Ftree%2Fnotebooks)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
[![Documentation Status](https://readthedocs.org/projects/geograph/badge/?version=latest)](https://geograph.readthedocs.io/en/latest/?badge=latest)
[![PyPI version](https://badge.fury.io/py/geograph.svg)](https://badge.fury.io/py/geograph)

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

Expand Down Expand Up @@ -39,4 +40,4 @@ GeoGraph is written in Python 3.8 and builds on [NetworkX](https://github.com/Ne

## 4. Documentation

Our documentation is available at [geograph.readthedocs.io](https://geograph.readthedocs.io/).
Our documentation is available at [geograph.readthedocs.io](https://geograph.readthedocs.io/).
30 changes: 14 additions & 16 deletions geograph/binary_graph_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


class NodeMap:
"""Class to store node mappings between two graphs (the src_graph and trg_graph)"""
"""Class to store node mappings between two graphs (the src_graph and trg_graph)."""

def __init__(
self,
Expand All @@ -24,7 +24,7 @@ def __init__(
mapping: Dict[int, List[int]],
) -> None:
"""
Class to store node mappings between two graphs (`trg_graph` and `src_graph`)
Class to store node mappings between two graphs (`trg_graph` and `src_graph`).
This class stores a dictionary of node one-to-many relationships of nodes from
`src_graph` to `trg_graph`. It also provides support for convenient methods for
Expand All @@ -45,36 +45,36 @@ def __init__(

@property
def src_graph(self) -> geograph.GeoGraph:
"""Keys in the mapping dict correspond to node indices in the `src_graph`"""
"""Keys in the mapping dict correspond to node indices in the `src_graph`."""
return self._src_graph

@property
def trg_graph(self) -> geograph.GeoGraph:
"""Values in the mapping dict correspond to node indices in the `trg_graph`"""
"""Values in the mapping dict correspond to node indices in the `trg_graph`."""
return self._trg_graph

@property
def mapping(self) -> Dict[int, List[int]]:
"""
Look-up table connecting node indices from `src_graph` to those of `trg_graph`.
"""
"""Look-up table connecting node indices from `src_graph` to `trg_graph`."""
return self._mapping

def __invert__(self) -> NodeMap:
"""Compute the inverse NodeMap"""
"""Compute the inverse NodeMap."""
return self.invert()

def __eq__(self, other: NodeMap) -> bool:
"""Check two NodeMaps for equality"""
def __eq__(self, other: object) -> bool:
"""Check two NodeMaps for equality."""
if not isinstance(other, NodeMap):
return False
return (
self.src_graph == other.src_graph
and self.trg_graph == other.trg_graph
and self.mapping == other.mapping
)

def invert(self) -> NodeMap:
"""Compute the inverse NodeMap from `trg_graph` to `src_graph`"""
inverted_mapping = {index: [] for index in self.trg_graph.df.index}
"""Compute the inverse NodeMap from `trg_graph` to `src_graph`."""
inverted_mapping: Dict = {index: [] for index in self.trg_graph.df.index}

for src_node in self.src_graph.df.index:
for trg_node in self.mapping[src_node]:
Expand Down Expand Up @@ -117,7 +117,7 @@ def identify_graphs(
graph1: geograph.GeoGraph, graph2: geograph.GeoGraph, mode: str
) -> NodeMap:
"""
Idenitfy all nodes from `graph1` with nodes from `graph2` based on the given `mode`
Idenitfy all nodes from `graph1` with nodes from `graph2` based on the given `mode`.
Args:
graph1 (GeoGraph): The GeoGraph whose node indicies will form the domain
Expand All @@ -143,8 +143,7 @@ def identify_graphs(

def graph_polygon_diff(node_map: NodeMap) -> Tuple[gpd.GeoDataFrame, gpd.GeoDataFrame]:
"""
Return the (multi)polygon areas that were added/removed when going
from `src_graph` to `trg_graph`.
Return the polygons that were added/removed going from `src_graph` to `trg_graph`.
Args:
node_map (NodeMap): The node map from `src_graph` to `trg_graph`
Expand Down Expand Up @@ -193,7 +192,6 @@ def node_polygon_diff(
Tuple[BaseGeometry, BaseGeometry]: Added part and removed part as shapely
BaseGeometry objects.
"""

src_polygon: Polygon = node_map.src_graph.df.geometry.loc[src_node_id]
trg_node_ids: List[int] = node_map.mapping[src_node_id]

Expand Down
6 changes: 1 addition & 5 deletions geograph/constants.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
"""
This file is used to save all project wide constants such as the path of the
source folder, the project path, etc.
"""

"""All project wide constants are saved in this module."""
# Place all your constants here
import os
import pathlib
Expand Down
Loading

0 comments on commit 5bc5892

Please sign in to comment.