Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_FloorArea(self):
self.df_buildings["area"] = self.df_buildings.geometry.area
self.df_buildings["floor_area"] = mm.FloorArea(
self.df_buildings, "height", "area"
).series
check = self.df_buildings.geometry[0].area * (self.df_buildings.height[0] // 3)
assert self.df_buildings["floor_area"][0] == check
area = self.df_buildings.geometry.area
height = np.linspace(10.0, 30.0, 144)
self.df_buildings["floor_area"] = mm.FloorArea(
self.df_buildings, height, area
).series
assert self.df_buildings["floor_area"][0] == check
self.df_buildings["floor_area"] = mm.FloorArea(
self.df_buildings, "height"
).series
assert self.df_buildings["floor_area"][0] == check
with pytest.raises(KeyError):
self.df_buildings["floor_area"] = mm.FloorArea(
self.df_buildings, "height", "nonexistent"
)
def test_FloorArea(self):
self.df_buildings["area"] = self.df_buildings.geometry.area
self.df_buildings["floor_area"] = mm.FloorArea(
self.df_buildings, "height", "area"
).series
check = self.df_buildings.geometry[0].area * (self.df_buildings.height[0] // 3)
assert self.df_buildings["floor_area"][0] == check
area = self.df_buildings.geometry.area
height = np.linspace(10.0, 30.0, 144)
self.df_buildings["floor_area"] = mm.FloorArea(
self.df_buildings, height, area
).series
assert self.df_buildings["floor_area"][0] == check
self.df_buildings["floor_area"] = mm.FloorArea(
self.df_buildings, "height"
).series
assert self.df_buildings["floor_area"][0] == check
with pytest.raises(KeyError):
self.df_buildings["floor_area"] = mm.FloorArea(
self.df_buildings, "height", "nonexistent"
)
def test_FloorArea(self):
self.df_buildings["area"] = self.df_buildings.geometry.area
self.df_buildings["floor_area"] = mm.FloorArea(
self.df_buildings, "height", "area"
).series
check = self.df_buildings.geometry[0].area * (self.df_buildings.height[0] // 3)
assert self.df_buildings["floor_area"][0] == check
area = self.df_buildings.geometry.area
height = np.linspace(10.0, 30.0, 144)
self.df_buildings["floor_area"] = mm.FloorArea(
self.df_buildings, height, area
).series
assert self.df_buildings["floor_area"][0] == check
self.df_buildings["floor_area"] = mm.FloorArea(
self.df_buildings, "height"
).series
assert self.df_buildings["floor_area"][0] == check
def setup_method(self):
test_file_path = mm.datasets.get_path("bubenec")
self.df_buildings = gpd.read_file(test_file_path, layer="buildings")
self.df_tessellation = gpd.read_file(test_file_path, layer="tessellation")
self.df_streets = gpd.read_file(test_file_path, layer="streets")
self.df_streets["nID"] = range(len(self.df_streets))
self.limit = mm.buffered_limit(self.df_buildings, 50)
def test__split_lines(self):
large = mm.buffered_limit(self.df_buildings, 100)
dense = mm.elements._split_lines(large, 100)
small = mm.buffered_limit(self.df_buildings, 30)
dense2 = mm.elements._split_lines(small, 100)
assert len(dense) == 53
assert len(dense2) == 51
def test_snap_street_network_edge(self):
snapped = mm.snap_street_network_edge(
self.df_streets, self.df_buildings, 20, self.df_tessellation, 70
)
snapped_nonedge = mm.snap_street_network_edge(
self.df_streets, self.df_buildings, 20
)
snapped_edge = mm.snap_street_network_edge(
self.df_streets,
self.df_buildings,
20,
tolerance_edge=70,
edge=mm.buffered_limit(self.df_buildings, buffer=50),
)
assert sum(snapped.geometry.length) == 5980.041004739525
assert sum(snapped_edge.geometry.length) == 5980.718889937014
assert sum(snapped_nonedge.geometry.length) < 5980.041004739525
def test__split_lines(self):
large = mm.buffered_limit(self.df_buildings, 100)
dense = mm.elements._split_lines(large, 100)
small = mm.buffered_limit(self.df_buildings, 30)
dense2 = mm.elements._split_lines(small, 100)
assert len(dense) == 53
assert len(dense2) == 51
def setup_method(self):
test_file_path = mm.datasets.get_path("bubenec")
self.df_buildings = gpd.read_file(test_file_path, layer="buildings")
self.df_tessellation = gpd.read_file(test_file_path, layer="tessellation")
self.df_streets = gpd.read_file(test_file_path, layer="streets")
self.df_streets["nID"] = range(len(self.df_streets))
self.limit = mm.buffered_limit(self.df_buildings, 50)
def test_Tessellation(self):
tes = mm.Tessellation(self.df_buildings, "uID", self.limit, segment=2)
tessellation = tes.tessellation
assert len(tessellation) == len(self.df_tessellation)
bands = mm.Tessellation(
self.df_streets, "nID", mm.buffered_limit(self.df_streets, 50), segment=5
).tessellation
assert len(bands) == len(self.df_streets)
queen_corners = tes.queen_corners(2)
w = libpysal.weights.Queen.from_dataframe(queen_corners)
assert w.neighbors[14] == [35, 36, 13, 15, 26, 27, 28, 30, 31]
def test_sw_high(self):
first_order = libpysal.weights.Queen.from_dataframe(self.df_tessellation)
from_sw = mm.sw_high(2, gdf=None, weights=first_order)
from_df = mm.sw_high(2, gdf=self.df_tessellation)
rook = mm.sw_high(2, gdf=self.df_tessellation, contiguity="rook")
check = [133, 134, 111, 112, 113, 114, 115, 121, 125]
assert from_sw.neighbors[0] == check
assert from_df.neighbors[0] == check
assert rook.neighbors[0] == check
with pytest.raises(AttributeError):
mm.sw_high(2, gdf=None, weights=None)
with pytest.raises(ValueError):
mm.sw_high(2, gdf=self.df_tessellation, contiguity="nonexistent")