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.
This PR adds metrics to GeoGraph by defining a Metric dataclass. A Metric object is then returned when a metric is calculated; each metric calculation function accepts only a GeoGraph, so that you can calculate any metric by calling the get_metric method on any GeoGraph and passing only the name of the metric. The PR also changes Habitats and Components to be sub-classes of GeoGraph, so you can now have recursively nested HabitatGeoGraphs, each with a ComponentGeoGraph, and you can calculate metrics on all of them!
Other features:
A merge_classes function which can be used to avoid some extra lines when combining class labels in the dataframe.
Tested support for string class labels as well as integer ones.
An apply_to_habitats function which allows you to apply a GeoGraph method, like merge_nodes, to every HabitatGeoGraph attached to a GeoGraph in one go, assuming each application uses the same arguments.
Further speedup in add_habitat.
Improved get_graph_components function, which now supports optionally calculating the union polygons for each component (by default this is not done for a GeoGraph, but is done for a HabitatGeoGraph since habitats are often small enough that this is fairly cheap).
Habitat-specific saving and loading.
Implemented __eq__ for GeoGraphs which checks if the two GeoGraphs are isomorphic.
Similarly, you can compare Metric objects with < <= == >= > and they will work as you would expect by comparing the underlying values.
ComponentGeoGraphs support optionally adding an edge between every pair of nodes (each node represents a component in the original graph) with the distance between the node polygons as an edge attribute. This is very slow for any habitat with more than about 100 components, so is disabled by default, but it is necessary for the avg_component_isolation metric.
This PR adds metrics to GeoGraph by defining a Metric dataclass. A Metric object is then returned when a metric is calculated; each metric calculation function accepts only a GeoGraph, so that you can calculate any metric by calling the
get_metric
method on any GeoGraph and passing only the name of the metric. The PR also changes Habitats and Components to be sub-classes of GeoGraph, so you can now have recursively nested HabitatGeoGraphs, each with a ComponentGeoGraph, and you can calculate metrics on all of them!Other features:
merge_classes
function which can be used to avoid some extra lines when combining class labels in the dataframe.apply_to_habitats
function which allows you to apply a GeoGraph method, likemerge_nodes
, to every HabitatGeoGraph attached to a GeoGraph in one go, assuming each application uses the same arguments.add_habitat
.get_graph_components
function, which now supports optionally calculating the union polygons for each component (by default this is not done for a GeoGraph, but is done for a HabitatGeoGraph since habitats are often small enough that this is fairly cheap).avg_component_isolation
metric.