-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathab-wildfire-perimeters-burncode-error-identification.py
38 lines (33 loc) · 1.46 KB
/
ab-wildfire-perimeters-burncode-error-identification.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import geopandas as gpd
import pandas as pd
wildfire_perimeters_path = "WildfirePerimeters1931to2022.shp"
wildfire_perimeters = gpd.read_file(wildfire_perimeters_path)
wildfire_perimeters = wildfire_perimeters.to_crs(epsg=3400)
in_province_codes = ["B", "PB", "I", "B_NP", "PB_NP", "I_NP"]
out_of_province_codes = list(
set(wildfire_perimeters["BURNCODE"].unique()) - set(in_province_codes)
)
canada_provincial_perimeter_path = "lpr_000a16a_e.shp"
canada_provincial_perimeters = gpd.read_file(canada_provincial_perimeter_path)
alberta_perimeter = canada_provincial_perimeters[
canada_provincial_perimeters["PRNAME"] == "Alberta"
]
alberta_perimeter = alberta_perimeter.to_crs(epsg=3400)
wildfire_perimeters["burncode_within_AB"] = wildfire_perimeters["BURNCODE"].isin(
in_province_codes
)
wildfire_perimeters["intersects_AB"] = wildfire_perimeters.intersects(
alberta_perimeter.unary_union
)
wildfire_perimeters["within_AB"] = wildfire_perimeters.within(
alberta_perimeter.unary_union
)
# wildfire_perimeters['outside_AB'] = ~wildfire_perimeters['within_AB'] & wildfire_perimeters['intersects_AB']
wildfire_perimeters["straddles_AB"] = (
wildfire_perimeters["intersects_AB"] & ~wildfire_perimeters["within_AB"]
)
wildfire_perimeters["mislabeled_AB"] = (
(wildfire_perimeters["burncode_within_AB"] & ~wildfire_perimeters["within_AB"])
| (~wildfire_perimeters["burncode_within_AB"] & wildfire_perimeters["within_AB"])
| wildfire_perimeters["straddles_AB"]
)