This repository was archived by the owner on Sep 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_average_consumptions.py
More file actions
100 lines (78 loc) · 3.03 KB
/
get_average_consumptions.py
File metadata and controls
100 lines (78 loc) · 3.03 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# ---
# jupyter:
# jupytext:
# text_representation:
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.10.2
# kernelspec:
# display_name: 'Python 3.9.1 64-bit (''cso-network-gas'': conda)'
# metadata:
# interpreter:
# hash: b61c169e19bc7874f8b9dc129b8bf2779b9e66e59b5e90264a492b9ef4b9b65d
# name: python3
# ---
# %%
import geopandas as gpd
import numpy as np
import pandas as pd
from clean import amalgamate_postal_districts
# %%
years = [str(2011 + i) for i in range(0, 9, 1)]
# %% [markdown]
# # Get Dublin Postcode Boundaries
# %%
dublin_postcode_boundaries = gpd.read_file("data/dublin_postcode_boundaries").pipe(amalgamate_postal_districts)
# %% [markdown]
# # Get Residential Average Gas Consumption
# %%
resi_total_annual_gas_by_postcodes = gpd.read_file("data/resi_total_annual_gas_by_postcodes.geojson", driver="GeoJSON")
# %%
resi_total_meters_by_postcodes = gpd.read_file("data/resi_total_meters_by_postcodes.geojson", driver="GeoJSON")
# %%
resi_avg_annual_gas_by_postcodes = resi_total_annual_gas_by_postcodes.copy()
resi_avg_annual_gas_by_postcodes.loc[:, years] = np.round(
1*10**6 * resi_total_annual_gas_by_postcodes[years].astype(np.int64) / resi_total_meters_by_postcodes[years].astype(np.int64),
0,
)
# %%
resi_avg_annual_gas_by_postcodes.to_file("data/resi_avg_annual_gas_by_postcodes.geojson", driver="GeoJSON")
# %% [markdown]
# # Get Non-Residential Average Gas Consumption
# %%
non_resi_total_annual_gas_by_postcodes = gpd.read_file("data/non_resi_total_annual_gas_by_postcodes.geojson", driver="GeoJSON")
# %%
non_resi_total_annual_gas_dublin_postal_districts = (
non_resi_total_annual_gas_by_postcodes
.query("`postcodes` != 'Co. Dublin'")
.loc[:, years]
.sum()
.to_frame().T
.assign(postcodes="Dublin Postal Districts")
.merge(dublin_postcode_boundaries)
)
# %%
non_resi_total_annual_gas_dublin_postal_districts
# %%
non_resi_total_annual_gas_by_postcodes = pd.concat(
[
non_resi_total_annual_gas_by_postcodes,
non_resi_total_annual_gas_dublin_postal_districts,
]
).query("`postcodes` == ['Co. Dublin', 'Dublin Postal Districts']").reset_index(drop=True)
# %%
non_resi_total_annual_gas_by_postcodes
# %%
non_resi_total_annual_gas_by_postcodes.loc["Dublin Postal Districts", years] = non_resi_total_annual_gas_dublin_postal_districts
# %%
non_resi_total_meters_by_postcodes = gpd.read_file("data/non_resi_total_meters_by_postcodes.geojson", driver="GeoJSON")
non_resi_total_meters_by_postcodes.loc[:, years] = non_resi_total_meters_by_postcodes[years].astype(np.int64)
# %%
non_resi_total_annual_gas_by_postcodes
# %%
non_resi_avg_annual_gas_by_postcodes = non_resi_total_annual_gas_by_postcodes.copy()
non_resi_avg_annual_gas_by_postcodes.loc[:, years] = 1*10**6 * non_resi_total_annual_gas_by_postcodes[years] / non_resi_total_meters_by_postcodes[years]
non_resi_avg_annual_gas_by_postcodes.loc[:, years] = non_resi_avg_annual_gas_by_postcodes[years].round(0)
# %%
non_resi_avg_annual_gas_by_postcodes