Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: James Gaboardi <jgaboardi@gmail.com>
  • Loading branch information
martinfleis and jGaboardi authored Jul 9, 2024
1 parent 358e43e commit 28c76af
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions docs/user_guide/migration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"source": [
"# Migration to momepy 1.0 API\n",
"\n",
"Starting with the version 0.8, momepy contains completely new API (and refactored internals) that will become the only API in the momepy 1.0. Given this is a complete reimplemnation of nearly entirety of the package, it is not compatible with the legacy class-based API. This notebook contains a succint migration guide, highlighiting the key differences between the two APIs and outlines required changes to existing code to make it compatible with upcoming 1.0 release."
"Starting with version 0.8, momepy contains a completely new API (and refactored internals) that will become the only API in the momepy 1.0. Given this is a complete reimplementation of nearly the entire package, it is not compatible with the legacy class-based API. This notebook contains a succinct migration guide, highlighting the key differences between the two APIs and outlines required changes to existing code to make it compatible with the upcoming 1.0 release."
]
},
{
Expand Down Expand Up @@ -34,7 +34,7 @@
"source": [
"## Functions over classes\n",
"\n",
"The first key difference you may notice is that vast majority of functionality is now offered in a form of functions, rather than classes. Take an example fo equivalent rectangular index and its asssignemnt as a new column.\n",
"The first key difference you may notice is the vast majority of functionality is now offered as functions, rather than classes. Take equivalent rectangular index as an example and its assignment as a new column.\n",
"\n",
"The new API is simple:"
]
Expand All @@ -61,7 +61,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The old API, which furhter required extracting the series from the class:"
"The old API, which further required extracting the series from the class:"
]
},
{
Expand Down Expand Up @@ -94,9 +94,9 @@
"FutureWarning: Class based API like `momepy.EquivalentRectangularIndex` is deprecated. Replace it with `momepy.equivalent_rectangular_index` to use functional API instead or pin momepy version <1.0. Class-based API will be removed in 1.0.\n",
"```\n",
"\n",
"If there is a direct equivalent, it also tells you its name. In some cases, there is no equivalent in `momepy` but is elsewhere. \n",
"If there is a direct equivalent, it also tells you its name. In some cases, there is no equivalent in `momepy` but one elsewhere. \n",
"\n",
"Measuring area with new API will requiring using `geopandas` directly."
"Measuring area with the new API will require using `geopandas` directly."
]
},
{
Expand Down Expand Up @@ -137,19 +137,19 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The warning is a bit different but still provides a guidance.\n",
"The warning is a bit different but still provides guidance.\n",
"\n",
"```\n",
"FutureWarning: `momepy.Area` is deprecated. Replace it with `.area` attribute of a GeoDataFrame or pin momepy version <1.0. This class will be removed in 1.0.\n",
"```\n",
"\n",
"## Dependency on libpysal `Graph` over `W`\n",
"\n",
"Spatial relationship in the legacy API is represented using `libpysal.weights.W` object. In the new one, `momepy` depends on new `libpysal.graph.Graph` implementation. That has two consequences - different ways of building the object and reliance on `GeoDataFrame` index.\n",
"Spatial relationships in the legacy API are represented using `libpysal.weights.W` objects. In the new one, `momepy` depends on the new `libpysal.graph.Graph` implementation. That has two consequences - different ways of building the object and reliance on `GeoDataFrame` indices.\n",
"\n",
"`Graph` encodes geoemtries using the index they have in the `GeoDataFrame`. It does not use positional indexing nor custom column. The two objects are tied together via the index. For momepy, it means that index plays a central role in the implementation and there's no `\"unique_id\"` column any longer. Its role takes index.\n",
"`Graph` encodes geometries using the index they have in the `GeoDataFrame`. It does not use positional indexing nor custom column. The two objects are tied together via the index. For momepy, this means that indices plays a central role in the implementation and there's no `\"unique_id\"` column any longer, which is superseded by index.\n",
"\n",
"Exmple of omputing a number of neighbors relative to the perimeter of each geometry using the new API:"
"Example of computing a number of neighbors relative to the perimeter of each geometry using the new API:"
]
},
{
Expand Down Expand Up @@ -220,26 +220,26 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that the `sw_high` function alowed bulding contiguity only.\n",
"Note that the `sw_high` function allowed bulding contiguity only.\n",
"\n",
"## Reliance on index\n",
"\n",
"When we need to capture relationship between two objects (e.g., `GeoDataFrame` and its `Graph`), the primary method is to rely on index. Unlike momepy 0.7, which heavily depends on columns with IDs mapping rows of one GeoDataFrame to the other, new API attempts to minimise use of such columns. Below is the overview of the logic used in various situations.\n",
"When we need to capture the relationship between two objects (e.g., a `GeoDataFrame` and its `Graph`), the primary method is to rely on index. Unlike momepy 0.7, which heavily depends on columns with IDs mapping rows of one GeoDataFrame to the other, the new API attempts to minimise use of such columns. Below is the overview of the logic used in various situations.\n",
"\n",
"### Geometry and Graph\n",
"\n",
"This case is easy. `Graph` is mapped to geometry (either `GeoSeries` or `GeoDataFrame`) via index of the GeoPandas object. \n",
"This case is easy. `Graph` is mapped to geometry (either a `GeoSeries` or a `GeoDataFrame`) via index of the GeoPandas object. \n",
"\n",
"```py\n",
"contiguity = graph.Graph.build_contiguity(geometry)\n",
"momepy.neighbor_distance(geometry, contiguity)\n",
"```\n",
"\n",
"In this case, you shall ensure that the index of `geometry` does not change and, in some cases, that the order of rows is also preserved to ensure the mapping of values to sparse arrays is not mismatched.\n",
"In this case, we ensure that the index of `geometry` does not change and, in some cases, that the order of rows is also preserved to ensure the mapping of values to sparse arrays is not mismatched.\n",
"\n",
"### Series and Graph\n",
"\n",
"A subset of the case above is linking of a `pandas.Series` to the `Graph`. Such a situation assumes that the index of the `Series` is equal to the index of the original geometry from which the `Graph` was created.\n",
"A subset of the case above is linking a `pandas.Series` to the `Graph`. Such a situation assumes that the index of the `Series` is equal to the index of the original geometry from which the `Graph` was created.\n",
"\n",
"```py\n",
"# typically, the Series is taken directly from the DataFrame\n",
Expand All @@ -266,7 +266,7 @@
"\n",
"## Geometry and Geometry\n",
"\n",
"When linking two geometry arrays together, which can be for example a used to capture which building belongs to which street segment, or which building belongs to which block/enclosure, you cannot rely solely on indices as the two objects do not match. In this situation, momepy will use the index of one Series, typically the shorter one, and a Series (i.e. a column) in another. \n",
"When linking two geometry arrays togetherfor example capturing which building belongs to which street segment, or which building belongs to which block/enclosure you cannot rely solely on indices as the two objects do not match. In this situation, momepy will use the index of one Series, typically the shorter one, and a Series (i.e. a column) in another. \n",
"\n",
"```py\n",
"buildings[\"street_index\"] = momepy.get_nearest_street(\n",
Expand Down

0 comments on commit 28c76af

Please sign in to comment.