@@ -30,17 +30,13 @@ catchments = gpd.read_file(ROOT / 'catchments_consolidated.shp').set_index('iden
3030print (f ' loaded { len (catchments)} catchments ' )
3131catchments.head()
3232
33- # Drop catchments that are annotated with an overlap comment.
34- catchments = catchments[~ catchments.comment.str.startswith(" Overlap" ).fillna(False )]
35- print (f ' retained { len (catchments)} after dropping annotated catchments ' )
36-
3733# Drop all scottish water catchments because there should not be overlap with LSOAs.
3834catchments = catchments[catchments.company != " scottish_water" ]
3935print (f ' retained { len (catchments)} after dropping Scottish Water ' )
4036```
4137
4238``` python
43- # Find non-trivial intersections between treatment works. That have not already been
39+ # Find non-trivial intersections between treatment works. That have not already been
4440# annotated.
4541sindex = catchments.geometry.sindex
4642indices = sindex.query_bulk(catchments.geometry).T
@@ -71,7 +67,7 @@ identifiers = catchments.index.values[indices]
7167graph = nx.Graph()
7268graph.add_edges_from([(* edge, {" weight" : area}) for edge, area in zip (identifiers, intersection_areas)])
7369components = list (sorted (
74- nx.connected_components(graph),
70+ nx.connected_components(graph),
7571 key = lambda nodes : sum (data[" weight" ] for * _, data in graph.edges(nodes, data = True )),
7672 reverse = True ,
7773))
@@ -117,7 +113,7 @@ grouped = intersections.groupby("LSOA11CD")
117113frac_covered = grouped.intersection_area.sum() / lsoas.geometry.area
118114
119115coverage = pd.DataFrame({
120- " n_catchments" : grouped.identifier.nunique(),
116+ " n_catchments" : grouped.identifier.nunique(),
121117 " frac" : frac_covered,
122118})
123119
@@ -152,11 +148,11 @@ for lsoa_code, subset in tqdm(intersections.groupby('LSOA11CD')):
152148 else :
153149 identifier = subset.identifier.iloc[0 ]
154150 all_intersecting = catchments.geometry.loc[identifier]
155- # Evaluate the intersection of the LSOA with any catchment by intersecting with the spatial
151+ # Evaluate the intersection of the LSOA with any catchment by intersecting with the spatial
156152 # union of the catchments.
157153 intersection = all_intersecting.intersection(lsoas.geometry.loc[lsoa_code])
158154 coverage[lsoa_code] = intersection.area
159-
155+
160156coverage = pd.Series(coverage)
161157
162158# Compute the coverage and fill with zeros where there are no intersections.
0 commit comments