-
Notifications
You must be signed in to change notification settings - Fork 80
[WIP] shared perimeter-weighted contiguity #507
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
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c3ee291
"rebase" onto latest
knaaptime b59bfa0
allow scaling in perimeter weights
knaaptime eff3366
docstring
knaaptime c795fea
update perimeter tests to include perim_std argument
knaaptime a6b80d1
Update libpysal/weights/contiguity.py
knaaptime 998dbe8
Update libpysal/weights/contiguity.py
knaaptime 374e8aa
Update libpysal/weights/contiguity.py
knaaptime 5b20a2d
Merge branch 'pysal:master' into perim_update
knaaptime 14b41e5
add example
knaaptime 7a7b33c
Merge branch 'pysal:master' into perim_update
knaaptime e37ac66
Merge branch 'pysal:master' into perim_update
knaaptime File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,56 @@ | ||
import os | ||
import tempfile | ||
|
||
import unittest | ||
import pytest | ||
import numpy as np | ||
import geopandas as gpd | ||
from ..weights import W, WSP | ||
from ..user import build_lattice_shapefile | ||
from .. import util | ||
from ..contiguity import Rook, _return_length_weighted_w | ||
from ... import examples | ||
|
||
NPTA3E = np.testing.assert_array_almost_equal | ||
|
||
|
||
class TestPerimeter(unittest.TestCase): | ||
def setUp(self): | ||
shp = build_lattice_shapefile(3, 3, "tmp.shp") | ||
gdf = gpd.read_file("tmp.shp") | ||
dv = [0] * 3 | ||
dv.extend(list(range(1, 7))) | ||
gdf["dv"] = dv | ||
gdf = gdf.dissolve(by="dv") | ||
self.w0 = Rook.from_dataframe(gdf, perimeter=True, perim_std=False) | ||
self.gdf = gdf | ||
|
||
# us case | ||
usgdf = gpd.read_file(examples.get_path("us48.shp")) | ||
usgdf.set_crs("epsg:4326", inplace=True) | ||
usgdf.to_crs(usgdf.estimate_utm_crs(), inplace=True) | ||
self.usgdf = usgdf | ||
self.wus = Rook.from_dataframe(usgdf, perimeter=True) | ||
|
||
def test_perimeter(self): | ||
NPTA3E(self.w0.pct_nonzero, 40.81632653) | ||
|
||
def test_return_length_weighted(self): | ||
w1 = _return_length_weighted_w(self.w0, self.gdf, False) | ||
NPTA3E(w1.pct_nonzero, 40.81632653) | ||
self.assertEqual(w1.weights[0], [1, 1, 1]) | ||
self.assertEqual(w1.weights[2], [1, 1, 1, 1]) | ||
|
||
def test_return_length_weighted_us(self): | ||
w1 = _return_length_weighted_w(self.wus, self.usgdf, False) | ||
self.assertAlmostEqual(w1[0][7], 354625.0684908081) | ||
self.assertAlmostEqual(w1[0][10], 605834.5010118643) | ||
NPTA3E(w1[0][7], w1[7][0]) | ||
w1.transform = "r" | ||
self.assertAlmostEqual(w1[0][7], 0.3692243585791264) | ||
self.assertAlmostEqual(w1[7][0], 0.12891667056448083) | ||
self.assertNotAlmostEquals(w1[0][7], w1[7][0]) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ljwolf do we want to keep the option to standardize when the boundary isnt exhausted? (so the denom is boundary_i instead of \sum{sharedboundary_ij})?