Skip to content

Commit e1050ec

Browse files
committed
flats support
1 parent 10a605c commit e1050ec

File tree

2 files changed

+227
-1
lines changed

2 files changed

+227
-1
lines changed

R/clean_epc.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ncores = 18
1+
ncores = 30
22
certs <- readRDS("epc_all_raw.Rds")
33

44
library(future)

summarise_epc.R

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
library(dplyr)
2+
library(sf)
3+
4+
# Get most recent EPC
5+
certs <- readRDS("epc_all_clean.Rds")
6+
7+
# dropcol <- c("LMK_KEY","ADDRESS1","ADDRESS2","ADDRESS3",
8+
# "LOCAL_AUTHORITY","COUNTY","LODGEMENT_DATE",
9+
# "ENVIRONMENT_IMPACT_CURRENT",
10+
# "ENVIRONMENT_IMPACT_POTENTIAL","ENERGY_CONSUMPTION_CURRENT","ENERGY_CONSUMPTION_POTENTIAL",
11+
# "CO2_EMISSIONS_CURRENT","CO2_EMISS_CURR_PER_FLOOR_AREA", "CO2_EMISSIONS_POTENTIAL",
12+
# "LIGHTING_COST_CURRENT","LIGHTING_COST_POTENTIAL","HEATING_COST_CURRENT",
13+
# "HEATING_COST_POTENTIAL","HOT_WATER_COST_CURRENT","HOT_WATER_COST_POTENTIAL",
14+
# "MAINS_GAS_FLAG","FLOOR_LEVEL","FLAT_TOP_STOREY","FLAT_STOREY_COUNT","MAIN_HEATING_CONTROLS",
15+
# "MAIN_HEATING_CONTROLS","MULTI_GLAZE_PROPORTION","GLAZED_TYPE",
16+
# "GLAZED_AREA","EXTENSION_COUNT","NUMBER_HABITABLE_ROOMS","NUMBER_HEATED_ROOMS",
17+
# "FLOOR_DESCRIPTION","FLOOR_ENV_EFF","WINDOWS_ENV_EFF","WALLS_ENV_EFF","SHEATING_ENV_EFF",
18+
# "ROOF_ENV_EFF","LIGHTING_ENV_EFF",
19+
# "WIND_TURBINE_COUNT","HEAT_LOSS_CORRIDOOR","HEAT_LOSS_CORRIDOOR",
20+
# "UNHEATED_CORRIDOR_LENGTH","FLOOR_HEIGHT",
21+
# "MECHANICAL_VENTILATION","LOCAL_AUTHORITY_LABEL","NUMBER_OPEN_FIREPLACES",
22+
# "WALLS_DESCRIPTION", "SHEATING_ENERGY_EFF")
23+
24+
# certs <- certs[,!names(certs) %in% dropcol]
25+
certs <- certs[order(certs$INSPECTION_DATE, decreasing = TRUE),]
26+
certs <- certs[!duplicated(certs$BUILDING_REFERENCE_NUMBER),]
27+
28+
source("../../creds2/CarbonCalculator/R/secure_path.R")
29+
30+
dir.create("tmp")
31+
unzip(paste0(paste0(substr(secure_path,1,39),"Postcodes/codepo_20210208/codepo_gpkg_gb.zip")),
32+
exdir = "tmp")
33+
postcodes <- read_sf("tmp/data/codepo_gb.gpkg")
34+
unlink("tmp",recursive = TRUE)
35+
postcodes <- postcodes[,c("Postcode")]
36+
postcodes$Postcode <- gsub(" ","",postcodes$Postcode)
37+
38+
postcodeold <- readRDS("D:/OneDrive - University of Leeds/Data/Postcodes/code_point_open.Rds")
39+
postcodeold$postcode <- gsub(" ","",postcodeold$postcode)
40+
postcodeold <- postcodeold["postcode"]
41+
names(postcodeold) <- c("Postcode","geom")
42+
st_geometry(postcodeold) <- "geom"
43+
postcodeold <- postcodeold[!postcodeold$Postcode %in% postcodes$Postcode,]
44+
postcodes <- rbind(postcodes, postcodeold)
45+
46+
certs$POSTCODE_clean <- gsub(" ","",certs$POSTCODE)
47+
48+
summary(certs$POSTCODE_clean %in% postcodes$Postcode)
49+
50+
# 33916 invalid postcodes
51+
52+
dir.create("tmp")
53+
unzip(paste0(substr(secure_path,1,39),"OA Bounadries/GB_LSOA_2011_clipped.zip"),
54+
exdir = "tmp")
55+
lsoa <- read_sf("tmp/infuse_lsoa_lyr_2011_clipped.shp")
56+
unlink("tmp",recursive = TRUE)
57+
58+
lsoa <- lsoa["geo_code"]
59+
names(lsoa) <- c("LSOA11","geometry")
60+
nrow(postcodes)
61+
postcodes <- st_join(postcodes, lsoa)
62+
nrow(postcodes)
63+
postcodes <- postcodes[!duplicated(postcodes$Postcode),]
64+
postcodes <- st_drop_geometry(postcodes)
65+
postcodes$quality <- NULL
66+
67+
certs <- left_join(certs, postcodes, by = c("POSTCODE_clean" = "Postcode"))
68+
certs$buidling_type <- paste0(certs$BUILT_FORM," ",certs$PROPERTY_TYPE)
69+
certs$fuel <- gsub(" \\(not community\\)","",certs$MAIN_FUEL)
70+
certs$fuel <- gsub(" \\(unknown\\)","",certs$fuel)
71+
certs$fuel <- gsub(" \\(community\\)","",certs$fuel)
72+
73+
certs$FLOOR_ENERGY_EFF[is.na(certs$FLOOR_ENERGY_EFF)] <- "NO DATA!"
74+
75+
certs$WINDOWS_ENERGY_EFF <- as.character(certs$WINDOWS_ENERGY_EFF)
76+
certs$WINDOWS_ENERGY_EFF[is.na(certs$WINDOWS_ENERGY_EFF)] <- "NO DATA!"
77+
certs$WINDOWS_ENERGY_EFF <- as.factor(certs$WINDOWS_ENERGY_EFF)
78+
79+
certs$WALLS_ENERGY_EFF <- as.character(certs$WALLS_ENERGY_EFF)
80+
certs$WALLS_ENERGY_EFF[is.na(certs$WALLS_ENERGY_EFF)] <- "NO DATA!"
81+
certs$WALLS_ENERGY_EFF <- as.factor(certs$WALLS_ENERGY_EFF)
82+
83+
certs$ROOF_ENERGY_EFF <- as.character(certs$ROOF_ENERGY_EFF)
84+
certs$ROOF_ENERGY_EFF[is.na(certs$ROOF_ENERGY_EFF)] <- "NO DATA!"
85+
certs$ROOF_ENERGY_EFF <- as.factor(certs$ROOF_ENERGY_EFF)
86+
87+
certs$MAINHEAT_ENERGY_EFF <- as.character(certs$MAINHEAT_ENERGY_EFF)
88+
certs$MAINHEAT_ENERGY_EFF[is.na(certs$MAINHEAT_ENERGY_EFF)] <- "NO DATA!"
89+
certs$MAINHEAT_ENERGY_EFF <- as.factor(certs$MAINHEAT_ENERGY_EFF)
90+
91+
certs$MAINHEATC_ENERGY_EFF <- as.character(certs$MAINHEATC_ENERGY_EFF)
92+
certs$MAINHEATC_ENERGY_EFF[is.na(certs$MAINHEATC_ENERGY_EFF)] <- "NO DATA!"
93+
certs$MAINHEATC_ENERGY_EFF <- as.factor(certs$MAINHEATC_ENERGY_EFF)
94+
95+
certs$PHOTO_SUPPLY[is.na(certs$PHOTO_SUPPLY)] <- 0
96+
97+
# Flag Roofs and Floors
98+
certs$FLOOR_ENERGY_EFF <- as.character(certs$FLOOR_ENERGY_EFF)
99+
certs$FLOOR_ENERGY_EFF <- ifelse((certs$FLOOR_ENERGY_EFF %in% c("NO DATA!","N/A")) &
100+
(certs$FLOOR_DESCRIPTION %in% c("(another dwelling below)", "(other premises below)")),
101+
"dwelling below",certs$FLOOR_ENERGY_EFF)
102+
103+
certs$ROOF_ENERGY_EFF <- as.character(certs$ROOF_ENERGY_EFF)
104+
certs$ROOF_ENERGY_EFF <- ifelse((certs$ROOF_ENERGY_EFF %in% c("NO DATA!","N/A")) &
105+
(certs$ROOF_DESCRIPTION %in% c("(another dwelling above)", "(other premises above)")),
106+
"dwelling above",certs$ROOF_ENERGY_EFF)
107+
108+
109+
cert_summ <- certs %>%
110+
group_by(LSOA11) %>%
111+
summarise(epc_total = n(),
112+
epc_newbuild = length(TRANSACTION_TYPE[TRANSACTION_TYPE == "new dwelling"]),
113+
epc_A = length(CURRENT_ENERGY_RATING[CURRENT_ENERGY_RATING == "A"]),
114+
epc_B = length(CURRENT_ENERGY_RATING[CURRENT_ENERGY_RATING == "B"]),
115+
epc_C = length(CURRENT_ENERGY_RATING[CURRENT_ENERGY_RATING == "C"]),
116+
epc_D = length(CURRENT_ENERGY_RATING[CURRENT_ENERGY_RATING == "D"]),
117+
epc_E = length(CURRENT_ENERGY_RATING[CURRENT_ENERGY_RATING == "E"]),
118+
epc_F = length(CURRENT_ENERGY_RATING[CURRENT_ENERGY_RATING == "F"]),
119+
epc_G = length(CURRENT_ENERGY_RATING[CURRENT_ENERGY_RATING == "G"]),
120+
epc_other = length(CURRENT_ENERGY_RATING[is.na(CURRENT_ENERGY_RATING)]),
121+
epc_score_avg = mean(CURRENT_ENERGY_EFFICIENCY, na.rm = TRUE),
122+
type_house_semi = length(buidling_type[buidling_type == "Semi-Detached House"]),
123+
type_house_midterrace = length(buidling_type[buidling_type %in% c("Enclosed Mid-Terrace House", "Mid-Terrace House")]),
124+
type_house_endterrace = length(buidling_type[buidling_type %in% c("Enclosed End-Terrace House", "End-Terrace House")]),
125+
type_house_detached = length(buidling_type[buidling_type == "Detached House"]),
126+
type_flat = length(buidling_type[grepl("Flat",buidling_type)]),
127+
type_bungalow_semi = length(buidling_type[buidling_type == "Semi-Detached Bungalow"]),
128+
type_bungalow_midterrace = length(buidling_type[buidling_type %in% c("Enclosed Mid-Terrace Bungalow", "Mid-Terrace Bungalow")]),
129+
type_bungalow_endterrace = length(buidling_type[buidling_type %in% c("Enclosed End-Terrace Bungalow", "End-Terrace Bungalow")]),
130+
type_bungalow_detached = length(buidling_type[buidling_type == "Detached Bungalow"]),
131+
type_maisonette = length(buidling_type[grepl("Maisonette",buidling_type)]),
132+
type_parkhome = length(buidling_type[grepl("Park home",buidling_type)]),
133+
floor_area_avg = round(mean(TOTAL_FLOOR_AREA, na.rm = TRUE)),
134+
low_energy_light = round(mean(LOW_ENERGY_LIGHTING, na.rm = TRUE)),
135+
136+
floor_verygood = length(FLOOR_ENERGY_EFF[FLOOR_ENERGY_EFF == "Very Good"]),
137+
floor_good = length(FLOOR_ENERGY_EFF[FLOOR_ENERGY_EFF == "Good"]),
138+
floor_average = length(FLOOR_ENERGY_EFF[FLOOR_ENERGY_EFF == "Average"]),
139+
floor_poor = length(FLOOR_ENERGY_EFF[FLOOR_ENERGY_EFF == "Poor"]),
140+
floor_verypoor = length(FLOOR_ENERGY_EFF[FLOOR_ENERGY_EFF == "Very Poor"]),
141+
floor_below = length(FLOOR_ENERGY_EFF[FLOOR_ENERGY_EFF == "dwelling below"]),
142+
floor_other = length(FLOOR_ENERGY_EFF[!FLOOR_ENERGY_EFF %in% c("Very Good","Good","Average","Poor","Very Poor","dwelling below")]),
143+
144+
window_verygood = length(WINDOWS_ENERGY_EFF[WINDOWS_ENERGY_EFF == "Very Good"]),
145+
window_good = length(WINDOWS_ENERGY_EFF[WINDOWS_ENERGY_EFF == "Good"]),
146+
window_average = length(WINDOWS_ENERGY_EFF[WINDOWS_ENERGY_EFF == "Average"]),
147+
window_poor = length(WINDOWS_ENERGY_EFF[WINDOWS_ENERGY_EFF == "Poor"]),
148+
window_verypoor = length(WINDOWS_ENERGY_EFF[WINDOWS_ENERGY_EFF == "Very Poor"]),
149+
window_other = length(WINDOWS_ENERGY_EFF[!WINDOWS_ENERGY_EFF %in% c("Very Good","Good","Average","Poor","Very Poor")]),
150+
151+
wall_verygood = length(WALLS_ENERGY_EFF[WALLS_ENERGY_EFF == "Very Good"]),
152+
wall_good = length(WALLS_ENERGY_EFF[WALLS_ENERGY_EFF == "Good"]),
153+
wall_average = length(WALLS_ENERGY_EFF[WALLS_ENERGY_EFF == "Average"]),
154+
wall_poor = length(WALLS_ENERGY_EFF[WALLS_ENERGY_EFF == "Poor"]),
155+
wall_verypoor = length(WALLS_ENERGY_EFF[WALLS_ENERGY_EFF == "Very Poor"]),
156+
wall_other = length(WALLS_ENERGY_EFF[!WALLS_ENERGY_EFF %in% c("Very Good","Good","Average","Poor","Very Poor")]),
157+
158+
roof_verygood = length(ROOF_ENERGY_EFF[ROOF_ENERGY_EFF == "Very Good"]),
159+
roof_good = length(ROOF_ENERGY_EFF[ROOF_ENERGY_EFF == "Good"]),
160+
roof_average = length(ROOF_ENERGY_EFF[ROOF_ENERGY_EFF == "Average"]),
161+
roof_poor = length(ROOF_ENERGY_EFF[ROOF_ENERGY_EFF == "Poor"]),
162+
roof_verypoor = length(ROOF_ENERGY_EFF[ROOF_ENERGY_EFF == "Very Poor"]),
163+
roof_above = length(ROOF_ENERGY_EFF[ROOF_ENERGY_EFF == "dwelling above"]),
164+
roof_other = length(ROOF_ENERGY_EFF[!ROOF_ENERGY_EFF %in% c("Very Good","Good","Average","Poor","Very Poor","dwelling above")]),
165+
166+
mainheat_verygood = length(MAINHEAT_ENERGY_EFF[MAINHEAT_ENERGY_EFF == "Very Good"]),
167+
mainheat_good = length(MAINHEAT_ENERGY_EFF[MAINHEAT_ENERGY_EFF == "Good"]),
168+
mainheat_average = length(MAINHEAT_ENERGY_EFF[MAINHEAT_ENERGY_EFF == "Average"]),
169+
mainheat_poor = length(MAINHEAT_ENERGY_EFF[MAINHEAT_ENERGY_EFF == "Poor"]),
170+
mainheat_verypoor = length(MAINHEAT_ENERGY_EFF[MAINHEAT_ENERGY_EFF == "Very Poor"]),
171+
mainheat_other = length(MAINHEAT_ENERGY_EFF[!MAINHEAT_ENERGY_EFF %in% c("Very Good","Good","Average","Poor","Very Poor")]),
172+
173+
mainheatdesc_gasboiler = length(MAINHEAT_DESCRIPTION[MAINHEAT_DESCRIPTION %in% c("boiler, underfloor heating, mains gas", "boiler, radiators, mains gas") ]),
174+
mainheatdesc_oilboiler = length(MAINHEAT_DESCRIPTION[MAINHEAT_DESCRIPTION %in% c("boiler, underfloor heating, oil","boiler, radiators, oil")]),
175+
mainheatdesc_storageheater = length(MAINHEAT_DESCRIPTION[grepl("electric storage heaters",MAINHEAT_DESCRIPTION)]),
176+
mainheatdesc_portableheater = length(MAINHEAT_DESCRIPTION[grepl("electric heaters",MAINHEAT_DESCRIPTION)]),
177+
mainheatdesc_roomheater = length(MAINHEAT_DESCRIPTION[grepl("room heaters",MAINHEAT_DESCRIPTION)]),
178+
mainheatdesc_heatpump = length(MAINHEAT_DESCRIPTION[grepl("heat pump",MAINHEAT_DESCRIPTION)]),
179+
mainheatdesc_community = length(MAINHEAT_DESCRIPTION[grepl("community",MAINHEAT_DESCRIPTION)]),
180+
181+
mainfuel_mainsgas = length(fuel[fuel == "mains gas"]),
182+
mainfuel_electric = length(fuel[grepl("electric",fuel)]),
183+
mainfuel_oil = length(fuel[fuel == "oil" | grepl("b30",fuel)] ),
184+
mainfuel_coal = length(fuel[grepl("coal",fuel) | grepl("anthracite",fuel)]),
185+
mainfuel_lpg = length(fuel[grepl("lpg",fuel)]),
186+
mainfuel_biomass = length(fuel[grepl("wood",fuel) | grepl("biomass",fuel)]),
187+
188+
mainheatcontrol_verygood = length(MAINHEATC_ENERGY_EFF[MAINHEATC_ENERGY_EFF == "Very Good"]),
189+
mainheatcontrol_good = length(MAINHEATC_ENERGY_EFF[MAINHEATC_ENERGY_EFF == "Good"]),
190+
mainheatcontrol_average = length(MAINHEATC_ENERGY_EFF[MAINHEATC_ENERGY_EFF == "Average"]),
191+
mainheatcontrol_poor = length(MAINHEATC_ENERGY_EFF[MAINHEATC_ENERGY_EFF == "Poor"]),
192+
mainheatcontrol_verypoor = length(MAINHEATC_ENERGY_EFF[MAINHEATC_ENERGY_EFF == "Very Poor"]),
193+
mainheatcontrol_other = length(MAINHEATC_ENERGY_EFF[!MAINHEATC_ENERGY_EFF %in% c("Very Good","Good","Average","Poor","Very Poor")]),
194+
195+
has_solarpv = length(PHOTO_SUPPLY[PHOTO_SUPPLY > 0 ]),
196+
has_solarthermal = length(SOLAR_WATER_HEATING_FLAG[SOLAR_WATER_HEATING_FLAG]),
197+
198+
)
199+
200+
cert_summ$type_other <- cert_summ$epc_total - rowSums(cert_summ[,grepl("type_",names(cert_summ))])
201+
cert_summ$mainheatdesc_other <- cert_summ$epc_total - rowSums(cert_summ[,grepl("mainheatdesc_",names(cert_summ))])
202+
203+
cert_summ <- cert_summ[,c("LSOA11","epc_total","epc_newbuild",
204+
"epc_A","epc_B","epc_C","epc_D","epc_E","epc_F","epc_G","epc_other",
205+
"epc_score_avg",
206+
"type_house_semi","type_house_midterrace","type_house_endterrace",
207+
"type_house_detached","type_flat","type_bungalow_semi",
208+
"type_bungalow_midterrace","type_bungalow_endterrace",
209+
"type_bungalow_detached","type_maisonette","type_parkhome","type_other",
210+
"floor_area_avg","low_energy_light",
211+
"floor_verygood","floor_good","floor_average","floor_poor","floor_verypoor","floor_below","floor_other",
212+
"window_verygood","window_good","window_average","window_poor","window_verypoor","window_other",
213+
"wall_verygood","wall_good","wall_average","wall_poor","wall_verypoor","wall_other",
214+
"roof_verygood","roof_good","roof_average","roof_poor","roof_verypoor","roof_above","roof_other",
215+
"mainheat_verygood","mainheat_good","mainheat_average","mainheat_poor","mainheat_verypoor","mainheat_other",
216+
"mainheatdesc_gasboiler","mainheatdesc_oilboiler","mainheatdesc_storageheater",
217+
"mainheatdesc_portableheater","mainheatdesc_roomheater","mainheatdesc_heatpump",
218+
"mainheatdesc_community","mainheatdesc_other",
219+
"mainfuel_mainsgas","mainfuel_electric","mainfuel_oil","mainfuel_coal",
220+
"mainfuel_lpg","mainfuel_biomass",
221+
"mainheatcontrol_verygood","mainheatcontrol_good","mainheatcontrol_average","mainheatcontrol_poor","mainheatcontrol_verypoor","mainheatcontrol_other",
222+
"has_solarpv","has_solarthermal")]
223+
224+
225+
saveRDS(cert_summ, "epc_lsoa_summary.Rds")
226+

0 commit comments

Comments
 (0)