Skip to content

Commit 8d16275

Browse files
always keep msoa21cd
1 parent bf65e49 commit 8d16275

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/acbm/preprocessing.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
def edit_boundary_resolution(
15-
study_area: gpd.GeoDataFrame, geography: str
15+
study_area: gpd.GeoDataFrame, geography: str, zone_id: str
1616
) -> gpd.GeoDataFrame:
1717
"""
1818
This function takes a GeoDataFrame and a geography resolution as input and returns
@@ -26,6 +26,8 @@ def edit_boundary_resolution(
2626
A GeoDataFrame containing the study area boundaries
2727
geography : str
2828
A string specifying the geography resolution. It can be either "OA" or "MSOA"
29+
zone_id : str
30+
The column name of the zone identifier in the study_area GeoDataFrame
2931
3032
Returns
3133
-------
@@ -36,20 +38,16 @@ def edit_boundary_resolution(
3638
# Dissolve based on the specified geography
3739
if geography == "MSOA":
3840
# Drop unnecessary columns (they are lower level than MSOA)
39-
columns_to_drop = ["GlobalID", "OA21CD", "LSOA21CD", "LSOA21NM"]
40-
study_area = study_area.drop(
41-
columns=[col for col in columns_to_drop if col in study_area.columns]
42-
)
41+
study_area = study_area[[zone_id, "geometry"]]
4342

4443
print("converting from OA to MSOA")
4544
study_area = study_area.dissolve(by="MSOA21CD").reset_index()
4645

4746
elif geography == "OA":
4847
# Drop unnecessary columns
49-
columns_to_drop = ["GlobalID"]
50-
study_area = study_area.drop(
51-
columns=[col for col in columns_to_drop if col in study_area.columns]
52-
)
48+
study_area = study_area[
49+
[zone_id, "MSOA21CD", "geometry"]
50+
] # we always need MSOA21CD to filter to study area
5351
print("keeping original OA boundaries")
5452

5553
# Ensure all geometries are MultiPolygon

0 commit comments

Comments
 (0)