Skip to content

Commit

Permalink
Fixed typos in adding road values and also updated test for including…
Browse files Browse the repository at this point in the history
… road roughness
  • Loading branch information
rosepearson committed Oct 14, 2024
1 parent 861b7f5 commit 1d6c1e5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/geofabrics/dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2728,12 +2728,12 @@ def add_roads(self, roads_polygon: dict):

# Set unpaved roads
mask = clip_mask(
self._dem.z, roads_polygon[roads_polygon["surface"]=="unpaved"], self.chunk_size
self._dem.z, roads_polygon[roads_polygon["surface"]=="unpaved"].geometry, self.chunk_size
)
self._dem["zo"] = self._dem.zo.where(~mask, self.default_values["unpaved"])
# Then set paved roads
mask = clip_mask(
self._dem.z, roads_polygon[roads_polygon["surface"]=="paved"], self.chunk_size
self._dem.z, roads_polygon[roads_polygon["surface"]=="paved"].geometry, self.chunk_size
)
self._dem["zo"] = self._dem.zo.where(~mask, self.default_values["paved"])
self._write_netcdf_conventions_in_place(self._dem, self.catchment_geometry.crs)
Expand Down
13 changes: 9 additions & 4 deletions src/geofabrics/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1624,8 +1624,8 @@ def get_roughness_instruction(self, key: str):
"rivers": 0.004,
"minimum": 0.00001,
"maximum": 5,
"paved": 0.011,
"unpaved": 0.001
"paved": 0.001,
"unpaved": 0.011
},
"roads": {"source": "osm", "ignore": ["pedestrian", "footway", "footpath", "track", "path", "cycleway"],
"widths": {"default": 8, "residential": 8, "tertiary": 12, "secondary": 12, "motorway": 12}},
Expand Down Expand Up @@ -1708,7 +1708,7 @@ def load_roads_osm(self) -> bool:
element_dict = {
"geometry": [],
"OSM_id": [],
"raod": [],
"road": [],
"surface": [],
}

Expand All @@ -1726,7 +1726,7 @@ def load_roads_osm(self) -> bool:

# Ignore tracks and standadise surfacing
road_instructions = self.get_roughness_instruction("roads")
roads = roads[~roads["roads"].isin(road_instructions["ignore"])]
roads = roads[~roads["road"].isin(road_instructions["ignore"])]
for paving in ["asphalt", "concrete"]:
roads.loc[roads["surface"]==paving, "surface"] = "paved"
logging.info(f"Surfaces of {roads[roads['surface']!='paved']['surface'].unique()} all assumed to be unpaved.")
Expand All @@ -1737,6 +1737,11 @@ def load_roads_osm(self) -> bool:
roads["roughness"] = roughness["paved"]
roads.loc[roads["surface"]!="paved", "roughness"] = roughness["unpaved"]

# Add widths
roads["width"] = road_instructions["widths"]["default"]
for key, value in road_instructions["widths"].items():
roads.loc[roads["road"]==key, "width"] = value

# Clip to land
roads = roads.clip(self.catchment_geometry.land).sort_index(
ascending=True
Expand Down
4 changes: 2 additions & 2 deletions tests/test_many_stages_waikanae/data/benchmark.nc
Git LFS file not shown
3 changes: 2 additions & 1 deletion tests/test_many_stages_waikanae/instruction.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@
"interpolation": {"no_data": "linear"}
},
"roughness": {
"roads": {}
"roads": {"source": "osm", "ignore": ["pedestrian", "footway", "footpath", "track", "path", "cycleway"],
"widths": {"default": 10, "residential": 20, "tertiary": 20, "secondary": 20, "motorway": 20}}
}
}
}
2 changes: 1 addition & 1 deletion tests/test_many_stages_waikanae/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_result_geofabric_linux(self):
numpy.testing.assert_array_almost_equal(
test.zo.data,
benchmark.zo.data,
decimal=1,
decimal=4,
err_msg="The generated test has significantly different roughness from the "
f"benchmark where there is LiDAR: {diff_array}",
)
Expand Down

0 comments on commit 1d6c1e5

Please sign in to comment.