jrpyprogramming 0.2.4__tar.gz → 0.2.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {jrpyprogramming-0.2.4 → jrpyprogramming-0.2.6}/PKG-INFO +5 -6
- {jrpyprogramming-0.2.4 → jrpyprogramming-0.2.6}/jrpyprogramming/__init__.py +0 -1
- jrpyprogramming-0.2.6/jrpyprogramming/__version__.py +1 -0
- jrpyprogramming-0.2.6/jrpyprogramming/data/buildings.zip +0 -0
- jrpyprogramming-0.2.6/jrpyprogramming/data/energy_demand.zip +0 -0
- {jrpyprogramming-0.2.4 → jrpyprogramming-0.2.6}/jrpyprogramming/data.py +14 -0
- jrpyprogramming-0.2.6/jrpyprogramming/data_raw/ccc_data/residential_buildings_archetype_dataset.zip +0 -0
- jrpyprogramming-0.2.6/jrpyprogramming/data_raw/ccc_data/seventh_carbon_budget_full_dataset.zip +0 -0
- jrpyprogramming-0.2.6/jrpyprogramming/dev/__init__.py +0 -0
- jrpyprogramming-0.2.6/jrpyprogramming/dev/buildings.py +106 -0
- jrpyprogramming-0.2.6/jrpyprogramming/dev/energy_demand.py +105 -0
- jrpyprogramming-0.2.6/jrpyprogramming/dev/sectors.py +147 -0
- jrpyprogramming-0.2.6/jrpyprogramming/examples/agriculture.csv +27 -0
- jrpyprogramming-0.2.6/jrpyprogramming/examples/aviation.csv +27 -0
- jrpyprogramming-0.2.6/jrpyprogramming/examples/electricity_supply.csv +27 -0
- jrpyprogramming-0.2.6/jrpyprogramming/examples/industry.csv +27 -0
- jrpyprogramming-0.2.6/jrpyprogramming/examples/source.txt +3 -0
- jrpyprogramming-0.2.6/jrpyprogramming/examples/surface_transport.csv +27 -0
- {jrpyprogramming-0.2.4 → jrpyprogramming-0.2.6}/pyproject.toml +4 -4
- jrpyprogramming-0.2.4/jrpyprogramming/__version__.py +0 -1
- jrpyprogramming-0.2.4/jrpyprogramming/vignettes/practical1.pdf +0 -0
- jrpyprogramming-0.2.4/jrpyprogramming/vignettes/practical2.pdf +0 -0
- jrpyprogramming-0.2.4/jrpyprogramming/vignettes/practical3.pdf +0 -0
- jrpyprogramming-0.2.4/jrpyprogramming/vignettes/practical4.pdf +0 -0
- jrpyprogramming-0.2.4/jrpyprogramming/vignettes/practical5.pdf +0 -0
- jrpyprogramming-0.2.4/jrpyprogramming/vignettes/solutions1.pdf +0 -0
- jrpyprogramming-0.2.4/jrpyprogramming/vignettes/solutions2.pdf +0 -0
- jrpyprogramming-0.2.4/jrpyprogramming/vignettes/solutions3.pdf +0 -0
- jrpyprogramming-0.2.4/jrpyprogramming/vignettes/solutions4.pdf +0 -0
- jrpyprogramming-0.2.4/jrpyprogramming/vignettes/solutions5.pdf +0 -0
- jrpyprogramming-0.2.4/jrpyprogramming/vignettes.py +0 -42
- {jrpyprogramming-0.2.4 → jrpyprogramming-0.2.6}/jrpyprogramming/data/data1.csv +0 -0
- {jrpyprogramming-0.2.4 → jrpyprogramming-0.2.6}/jrpyprogramming/data/data2.csv +0 -0
- {jrpyprogramming-0.2.4 → jrpyprogramming-0.2.6}/jrpyprogramming/data/data2.xlsx +0 -0
- {jrpyprogramming-0.2.4 → jrpyprogramming-0.2.6}/jrpyprogramming/data/data3.csv +0 -0
- {jrpyprogramming-0.2.4 → jrpyprogramming-0.2.6}/jrpyprogramming/data/data3.txt +0 -0
- {jrpyprogramming-0.2.4 → jrpyprogramming-0.2.6}/jrpyprogramming/data/data4.csv +0 -0
- {jrpyprogramming-0.2.4 → jrpyprogramming-0.2.6}/jrpyprogramming/data/data5.csv +0 -0
- {jrpyprogramming-0.2.4 → jrpyprogramming-0.2.6}/jrpyprogramming/data/experiment.csv +0 -0
- {jrpyprogramming-0.2.4 → jrpyprogramming-0.2.6}/jrpyprogramming/data/genome.csv +0 -0
- {jrpyprogramming-0.2.4 → jrpyprogramming-0.2.6}/jrpyprogramming/data/movies.zip +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
2
|
Name: jrpyprogramming
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.6
|
|
4
4
|
Summary: Jumping Rivers: Programming with Python
|
|
5
5
|
Author: Jumping Rivers
|
|
6
6
|
Author-email: info@jumpingrivers.com
|
|
@@ -10,8 +10,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
10
10
|
Classifier: Programming Language :: Python :: 3.10
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.11
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
-
|
|
14
|
-
Requires-Dist: jrpyintroduction (>=0.2.2)
|
|
13
|
+
Requires-Dist: jrpyintroduction (>=0.3.8)
|
|
15
14
|
Requires-Dist: matplotlib (>=3.5,<4.0)
|
|
16
|
-
Requires-Dist: numpy (>=
|
|
17
|
-
Requires-Dist: pandas (>=
|
|
15
|
+
Requires-Dist: numpy (>=2.0,<3.0)
|
|
16
|
+
Requires-Dist: pandas (>=2.2.0,<3.0.0)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.6"
|
|
Binary file
|
|
Binary file
|
|
@@ -46,3 +46,17 @@ def populate_examples():
|
|
|
46
46
|
abs_path = data_path / file
|
|
47
47
|
copyfile(abs_path, file)
|
|
48
48
|
print(f'\nCreated file {file} in current directory.\n')
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def populate_sectors():
|
|
52
|
+
# Get absolute path to the per-sector example files
|
|
53
|
+
examples_path = resources.files("jrpyprogramming") / "examples"
|
|
54
|
+
|
|
55
|
+
# List the example files shipped with the package
|
|
56
|
+
files = os.listdir(examples_path)
|
|
57
|
+
|
|
58
|
+
# Copy files to current dir
|
|
59
|
+
for file in files:
|
|
60
|
+
abs_path = examples_path / file
|
|
61
|
+
copyfile(abs_path, file)
|
|
62
|
+
print(f'\nCreated file {file} in current directory.\n')
|
jrpyprogramming-0.2.6/jrpyprogramming/data_raw/ccc_data/residential_buildings_archetype_dataset.zip
ADDED
|
Binary file
|
jrpyprogramming-0.2.6/jrpyprogramming/data_raw/ccc_data/seventh_carbon_budget_full_dataset.zip
ADDED
|
Binary file
|
|
File without changes
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This non-exported module creates the `buildings` dataset used by the climate
|
|
3
|
+
variant of the course, in chapter 0.
|
|
4
|
+
|
|
5
|
+
The source is the Seventh Carbon Budget residential-buildings archetype dataset
|
|
6
|
+
published by the Climate Change Committee (CCC), downloaded from:
|
|
7
|
+
https://www.theccc.org.uk/publication/methodology-report-uk-northern-ireland-wales-and-scotland-carbon-budget-advice/
|
|
8
|
+
The raw workbook is stored zipped in
|
|
9
|
+
`jrpyprogramming/data_raw/ccc_data/` so that the build is reproducible.
|
|
10
|
+
|
|
11
|
+
We keep a subset of columns that mirrors the teaching operations the base
|
|
12
|
+
course previously performed on the `movies` dataset (boolean/conditional
|
|
13
|
+
filtering, compound conditions, summary statistics and counting with 0/1 flag
|
|
14
|
+
columns), themed around residential-building archetypes. It is the same
|
|
15
|
+
dataset that students meet in the Introduction to Python course.
|
|
16
|
+
|
|
17
|
+
Run with:
|
|
18
|
+
|
|
19
|
+
python -m jrpyprogramming.dev.buildings
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
import zipfile
|
|
23
|
+
from io import BytesIO
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
|
|
26
|
+
import pandas as pd
|
|
27
|
+
|
|
28
|
+
# ---- #
|
|
29
|
+
|
|
30
|
+
PACKAGE_ROOT = Path(__file__).resolve().parents[1]
|
|
31
|
+
|
|
32
|
+
PATHS = {
|
|
33
|
+
"raw": PACKAGE_ROOT
|
|
34
|
+
/ "data_raw"
|
|
35
|
+
/ "ccc_data"
|
|
36
|
+
/ "residential_buildings_archetype_dataset.zip",
|
|
37
|
+
"out": PACKAGE_ROOT / "data" / "buildings.zip",
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
SHEET = "Archetype Dataset"
|
|
41
|
+
|
|
42
|
+
# Mapping from raw CCC column name -> teaching column name
|
|
43
|
+
COLUMNS = {
|
|
44
|
+
"Final archetype number": "archetype_number",
|
|
45
|
+
"Region": "region",
|
|
46
|
+
"Country": "country",
|
|
47
|
+
"Property type": "property_type",
|
|
48
|
+
"Age band": "age_band",
|
|
49
|
+
"Tenure": "tenure",
|
|
50
|
+
"Heating system": "heating_system",
|
|
51
|
+
"Floor area": "floor_area",
|
|
52
|
+
"Stock": "stock",
|
|
53
|
+
"Annual space heating demand": "space_heating_demand",
|
|
54
|
+
"Space heating fuel consumption": "space_heating_fuel",
|
|
55
|
+
"Space heating CO2 (direct)": "space_heating_co2",
|
|
56
|
+
"Solar PV": "solar_pv",
|
|
57
|
+
"Fuel poverty": "fuel_poverty",
|
|
58
|
+
"Hot water tank": "hot_water_tank",
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
# Yes/No columns that we store as 0/1 integer flags (like the movies genre
|
|
62
|
+
# columns) so that counting exercises work with `.sum()` and multiplication.
|
|
63
|
+
FLAG_COLUMNS = ["solar_pv", "fuel_poverty", "hot_water_tank"]
|
|
64
|
+
|
|
65
|
+
# ---- #
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def build_buildings(raw_path):
|
|
69
|
+
"""
|
|
70
|
+
Read the CCC residential-buildings archetype workbook and return the
|
|
71
|
+
teaching subset as a tidy DataFrame.
|
|
72
|
+
"""
|
|
73
|
+
# The zip holds a single workbook named after the archive; extract it to
|
|
74
|
+
# memory since read_excel cannot open zipped files directly.
|
|
75
|
+
with zipfile.ZipFile(raw_path) as archive:
|
|
76
|
+
workbook = BytesIO(archive.read(raw_path.with_suffix(".xlsx").name))
|
|
77
|
+
raw = pd.read_excel(workbook, sheet_name=SHEET)
|
|
78
|
+
|
|
79
|
+
subset = raw[list(COLUMNS.keys())].rename(columns=COLUMNS)
|
|
80
|
+
|
|
81
|
+
for column in FLAG_COLUMNS:
|
|
82
|
+
subset[column] = (subset[column] == "Yes").astype(int)
|
|
83
|
+
|
|
84
|
+
# Sort by the unique archetype identifier for a clean, stable ordering.
|
|
85
|
+
subset = subset.sort_values("archetype_number").reset_index(drop=True)
|
|
86
|
+
|
|
87
|
+
return subset
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
# ---- #
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def main():
|
|
94
|
+
buildings = build_buildings(PATHS["raw"])
|
|
95
|
+
buildings.to_csv(
|
|
96
|
+
PATHS["out"],
|
|
97
|
+
index=False,
|
|
98
|
+
compression={"method": "zip", "archive_name": "buildings.csv"},
|
|
99
|
+
)
|
|
100
|
+
print(f"Wrote {len(buildings)} rows to {PATHS['out']}")
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
# ---- #
|
|
104
|
+
|
|
105
|
+
if __name__ == "__main__":
|
|
106
|
+
main()
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This non-exported module creates the `energy_demand` dataset used by the
|
|
3
|
+
climate variant of the course, in the chapter 3
|
|
4
|
+
exercises.
|
|
5
|
+
|
|
6
|
+
The source is the Seventh Carbon Budget full dataset published by the Climate
|
|
7
|
+
Change Committee (CCC). The raw workbook is stored zipped in
|
|
8
|
+
`jrpyprogramming/data_raw/ccc_data/` so that the build is reproducible.
|
|
9
|
+
|
|
10
|
+
We take the economy-wide primary energy demand (substitution method) from the
|
|
11
|
+
`Economy-wide data` sheet and reshape it so that each row is a single
|
|
12
|
+
(source, year) observation. Only the Balanced Pathway scenario reports this
|
|
13
|
+
breakdown, so the scenario is dropped. The result is a tidy table of UK primary
|
|
14
|
+
energy demand (TWh) by source and year - a fresh, non-sector theme (the energy
|
|
15
|
+
mix) that still supports the group-by and summary exercises the students have
|
|
16
|
+
just learned. It maps onto the base course `experiment` dataset: `source` is
|
|
17
|
+
the grouping column (like `treat`), `year` is the ordered index (like `time`)
|
|
18
|
+
and `demand` is the numeric measure (like `measure`).
|
|
19
|
+
|
|
20
|
+
The output is written as a zipped CSV in `jrpyprogramming/data/`, loadable with
|
|
21
|
+
`jrpy.data.load("energy_demand")`.
|
|
22
|
+
|
|
23
|
+
Run with:
|
|
24
|
+
|
|
25
|
+
python -m jrpyprogramming.dev.energy_demand
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
import zipfile
|
|
29
|
+
from io import BytesIO
|
|
30
|
+
from pathlib import Path
|
|
31
|
+
|
|
32
|
+
import pandas as pd
|
|
33
|
+
|
|
34
|
+
# ---- #
|
|
35
|
+
|
|
36
|
+
PACKAGE_ROOT = Path(__file__).resolve().parents[1]
|
|
37
|
+
|
|
38
|
+
PATHS = {
|
|
39
|
+
"raw": PACKAGE_ROOT
|
|
40
|
+
/ "data_raw"
|
|
41
|
+
/ "ccc_data"
|
|
42
|
+
/ "seventh_carbon_budget_full_dataset.zip",
|
|
43
|
+
"out": PACKAGE_ROOT / "data" / "energy_demand.zip",
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
SHEET = "Economy-wide data"
|
|
47
|
+
|
|
48
|
+
# We keep the primary-demand-by-source variables (substitution method), which
|
|
49
|
+
# together make up the energy mix.
|
|
50
|
+
PREFIX = "Energy: primary demand "
|
|
51
|
+
SUFFIX = " (substitution method)"
|
|
52
|
+
|
|
53
|
+
COLUMN_ORDER = ["source", "year", "demand"]
|
|
54
|
+
|
|
55
|
+
# ---- #
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def build_energy_demand(raw_path):
|
|
59
|
+
"""
|
|
60
|
+
Read the CCC economy-wide sheet and return a tidy table with one row per
|
|
61
|
+
(scenario, source, year) giving primary energy demand in TWh.
|
|
62
|
+
"""
|
|
63
|
+
# The zip holds a single workbook named after the archive; extract it to
|
|
64
|
+
# memory since read_excel cannot open zipped files directly.
|
|
65
|
+
with zipfile.ZipFile(raw_path) as archive:
|
|
66
|
+
workbook = BytesIO(archive.read(raw_path.with_suffix(".xlsx").name))
|
|
67
|
+
raw = pd.read_excel(workbook, sheet_name=SHEET)
|
|
68
|
+
|
|
69
|
+
is_primary = raw["variable"].str.startswith(PREFIX) & raw[
|
|
70
|
+
"variable"
|
|
71
|
+
].str.endswith(SUFFIX)
|
|
72
|
+
subset = raw[is_primary].copy()
|
|
73
|
+
|
|
74
|
+
# Turn the variable name into a plain source name, eg.
|
|
75
|
+
# "Energy: primary demand wind (substitution method)" -> "wind".
|
|
76
|
+
subset["source"] = (
|
|
77
|
+
subset["variable"].str.replace(PREFIX, "", regex=False).str.replace(
|
|
78
|
+
SUFFIX, "", regex=False
|
|
79
|
+
)
|
|
80
|
+
)
|
|
81
|
+
subset = subset.rename(columns={"value": "demand"})
|
|
82
|
+
|
|
83
|
+
tidy = subset[COLUMN_ORDER]
|
|
84
|
+
tidy = tidy.sort_values(["source", "year"]).reset_index(drop=True)
|
|
85
|
+
|
|
86
|
+
return tidy
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
# ---- #
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def main():
|
|
93
|
+
energy_demand = build_energy_demand(PATHS["raw"])
|
|
94
|
+
energy_demand.to_csv(
|
|
95
|
+
PATHS["out"],
|
|
96
|
+
index=False,
|
|
97
|
+
compression={"method": "zip", "archive_name": "energy_demand.csv"},
|
|
98
|
+
)
|
|
99
|
+
print(f"Wrote {len(energy_demand)} rows to {PATHS['out']}")
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
# ---- #
|
|
103
|
+
|
|
104
|
+
if __name__ == "__main__":
|
|
105
|
+
main()
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This non-exported module creates the per-sector example CSV files used by the
|
|
3
|
+
climate variant of the course, in the chapter 1 and
|
|
4
|
+
chapter 3 file-concatenation and comprehension material.
|
|
5
|
+
|
|
6
|
+
It reads the Seventh Carbon Budget full dataset published by the Climate Change
|
|
7
|
+
Committee (CCC) directly. The raw workbook is stored zipped in
|
|
8
|
+
`jrpyprogramming/data_raw/ccc_data/` so that the build is reproducible. From the
|
|
9
|
+
tidy `Sector-level data` sheet we keep the direct-emissions variables (total
|
|
10
|
+
and CO2), pivot them into columns, keep the `Balanced Pathway` scenario, and
|
|
11
|
+
write one CSV per selected sector into `jrpyprogramming/examples/`. Each file is
|
|
12
|
+
named after its sector, has the `scenario` and `sector` columns removed (the
|
|
13
|
+
sector is encoded in the filename), and holds a tidy `year`, `total_emissions`,
|
|
14
|
+
`co2_emissions` time series (MtCO2e).
|
|
15
|
+
|
|
16
|
+
These files stand in for the base course's `data1.csv` - `data5.csv`: the
|
|
17
|
+
students list them, filter by extension, and concatenate them back together
|
|
18
|
+
(re-adding the sector from the filename). A single non-CSV file (`source.txt`)
|
|
19
|
+
is written alongside so that the `.endswith(".csv")` filtering has something to
|
|
20
|
+
exclude, exactly as the base course's `.xlsx`/`.txt` files did.
|
|
21
|
+
|
|
22
|
+
They are copied into a student's working directory by
|
|
23
|
+
`jrpyprogramming.data.populate_sectors()`.
|
|
24
|
+
|
|
25
|
+
Run with:
|
|
26
|
+
|
|
27
|
+
python -m jrpyprogramming.dev.sectors
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
import zipfile
|
|
31
|
+
from io import BytesIO
|
|
32
|
+
from pathlib import Path
|
|
33
|
+
|
|
34
|
+
import pandas as pd
|
|
35
|
+
|
|
36
|
+
# ---- #
|
|
37
|
+
|
|
38
|
+
PACKAGE_ROOT = Path(__file__).resolve().parents[1]
|
|
39
|
+
|
|
40
|
+
PATHS = {
|
|
41
|
+
"raw": PACKAGE_ROOT
|
|
42
|
+
/ "data_raw"
|
|
43
|
+
/ "ccc_data"
|
|
44
|
+
/ "seventh_carbon_budget_full_dataset.zip",
|
|
45
|
+
"out_dir": PACKAGE_ROOT / "examples",
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
SHEET = "Sector-level data"
|
|
49
|
+
|
|
50
|
+
SCENARIO = "Balanced Pathway"
|
|
51
|
+
|
|
52
|
+
# Keep the direct-emissions variables, giving each a concise column name.
|
|
53
|
+
VARIABLES = {
|
|
54
|
+
"Emissions: direct emissions total": "total_emissions",
|
|
55
|
+
"Emissions: direct emissions CO2": "co2_emissions",
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
# Sectors to write out as individual files, with the filename stem to use.
|
|
59
|
+
SECTORS = {
|
|
60
|
+
"Surface transport": "surface_transport",
|
|
61
|
+
"Electricity supply": "electricity_supply",
|
|
62
|
+
"Aviation": "aviation",
|
|
63
|
+
"Industry": "industry",
|
|
64
|
+
"Agriculture": "agriculture",
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
KEEP_COLUMNS = ["year", "total_emissions", "co2_emissions"]
|
|
68
|
+
|
|
69
|
+
SOURCE_NOTE = (
|
|
70
|
+
"Per-sector emissions (MtCO2e), Balanced Pathway scenario.\n"
|
|
71
|
+
"Source: Climate Change Committee, Seventh Carbon Budget.\n"
|
|
72
|
+
"Each CSV is named after its sector; the sector column has been removed.\n"
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
# ---- #
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def build_sector_emissions(raw_path):
|
|
79
|
+
"""
|
|
80
|
+
Read the CCC sector-level sheet and return a tidy table with one row per
|
|
81
|
+
(sector, year) for the Balanced Pathway, with the two emissions variables
|
|
82
|
+
as columns.
|
|
83
|
+
"""
|
|
84
|
+
# The zip holds a single workbook named after the archive; extract it to
|
|
85
|
+
# memory since read_excel cannot open zipped files directly.
|
|
86
|
+
with zipfile.ZipFile(raw_path) as archive:
|
|
87
|
+
workbook = BytesIO(archive.read(raw_path.with_suffix(".xlsx").name))
|
|
88
|
+
raw = pd.read_excel(workbook, sheet_name=SHEET)
|
|
89
|
+
|
|
90
|
+
subset = raw[raw["variable"].isin(VARIABLES.keys())].copy()
|
|
91
|
+
subset["variable"] = subset["variable"].map(VARIABLES)
|
|
92
|
+
|
|
93
|
+
wide = subset.pivot_table(
|
|
94
|
+
index=["scenario", "sector", "year"],
|
|
95
|
+
columns="variable",
|
|
96
|
+
values="value",
|
|
97
|
+
).reset_index()
|
|
98
|
+
wide.columns.name = None
|
|
99
|
+
|
|
100
|
+
return wide[wide["scenario"] == SCENARIO]
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def build_sector_files(out_dir):
|
|
104
|
+
"""
|
|
105
|
+
Write one CSV per selected sector, plus a non-CSV source note. Returns the
|
|
106
|
+
list of files written.
|
|
107
|
+
"""
|
|
108
|
+
emissions = build_sector_emissions(PATHS["raw"])
|
|
109
|
+
|
|
110
|
+
out_dir.mkdir(exist_ok=True)
|
|
111
|
+
|
|
112
|
+
# Remove any previously generated example files so the build is clean.
|
|
113
|
+
for stale in list(out_dir.glob("*.csv")) + list(out_dir.glob("*.txt")):
|
|
114
|
+
stale.unlink()
|
|
115
|
+
|
|
116
|
+
written = []
|
|
117
|
+
for sector, stem in SECTORS.items():
|
|
118
|
+
sector_data = (
|
|
119
|
+
emissions[emissions["sector"] == sector][KEEP_COLUMNS]
|
|
120
|
+
.sort_values("year")
|
|
121
|
+
.reset_index(drop=True)
|
|
122
|
+
)
|
|
123
|
+
out_path = out_dir / f"{stem}.csv"
|
|
124
|
+
sector_data.to_csv(out_path, index=False)
|
|
125
|
+
written.append(out_path)
|
|
126
|
+
|
|
127
|
+
note_path = out_dir / "source.txt"
|
|
128
|
+
note_path.write_text(SOURCE_NOTE)
|
|
129
|
+
written.append(note_path)
|
|
130
|
+
|
|
131
|
+
return written
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
# ---- #
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def main():
|
|
138
|
+
written = build_sector_files(PATHS["out_dir"])
|
|
139
|
+
print(f"Wrote {len(written)} files to {PATHS['out_dir']}:")
|
|
140
|
+
for path in written:
|
|
141
|
+
print(f" {path.name}")
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
# ---- #
|
|
145
|
+
|
|
146
|
+
if __name__ == "__main__":
|
|
147
|
+
main()
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
year,total_emissions,co2_emissions
|
|
2
|
+
2025,47.04431879231096,7.11195142881007
|
|
3
|
+
2026,46.55971791769261,7.023718730759533
|
|
4
|
+
2027,44.91961444729086,6.56837380452751
|
|
5
|
+
2028,43.08119057340664,6.107754047068191
|
|
6
|
+
2029,41.07062128163186,5.640581135648146
|
|
7
|
+
2030,39.2427769198489,5.176830072219891
|
|
8
|
+
2031,37.46240643359306,4.819954797741994
|
|
9
|
+
2032,35.79183758704355,4.463896837292482
|
|
10
|
+
2033,34.30362690434493,4.116596727741165
|
|
11
|
+
2034,32.97088627962682,3.77314366224367
|
|
12
|
+
2035,31.88870113630172,3.430093892074354
|
|
13
|
+
2036,31.30582464597946,3.116219661603278
|
|
14
|
+
2037,30.85804840096916,2.802758170501625
|
|
15
|
+
2038,30.32960145784595,2.489499473287159
|
|
16
|
+
2039,29.78846069070192,2.176314463032735
|
|
17
|
+
2040,29.24745296064348,1.863204831562803
|
|
18
|
+
2041,28.9372814742712,1.804917014168791
|
|
19
|
+
2042,28.52645035035353,1.74665634658448
|
|
20
|
+
2043,28.22708686768913,1.688420161238338
|
|
21
|
+
2044,27.92657749070909,1.630193354965281
|
|
22
|
+
2045,27.62604337338858,1.572003315436226
|
|
23
|
+
2046,27.37569122099639,1.562232204515042
|
|
24
|
+
2047,27.12588924398758,1.552483057234836
|
|
25
|
+
2048,26.87912952128276,1.54285338761824
|
|
26
|
+
2049,26.63070678801907,1.533134803808428
|
|
27
|
+
2050,26.38987159012214,1.524031830032308
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
year,total_emissions,co2_emissions
|
|
2
|
+
2025,36.73092377300829,36.41693106698673
|
|
3
|
+
2026,35.82018879855322,35.51423624912584
|
|
4
|
+
2027,35.00742550819214,34.70893024921723
|
|
5
|
+
2028,34.00178520559492,33.71284523357664
|
|
6
|
+
2029,33.67295409587235,33.38754490125839
|
|
7
|
+
2030,33.49469016774837,33.21167610810286
|
|
8
|
+
2031,32.51765107111196,32.2445676931948
|
|
9
|
+
2032,31.98026143205675,31.71388757830032
|
|
10
|
+
2033,31.54017292637023,31.27932211828804
|
|
11
|
+
2034,31.15116485647634,30.89600687731529
|
|
12
|
+
2035,30.13455308348728,29.89100051346249
|
|
13
|
+
2036,30.04547641932908,29.80502798088056
|
|
14
|
+
2037,29.96476684818071,29.72742640000849
|
|
15
|
+
2038,29.6612303597675,29.42971764444973
|
|
16
|
+
2039,29.71971799127217,29.49097946843761
|
|
17
|
+
2040,29.53945662930248,29.31602496204097
|
|
18
|
+
2041,28.80931109424303,28.60007655299749
|
|
19
|
+
2042,27.91913517762153,27.72578687428328
|
|
20
|
+
2043,27.45474016880508,27.27373996335709
|
|
21
|
+
2044,26.90365477915237,26.73750382489026
|
|
22
|
+
2045,25.94155768732015,25.79614781431329
|
|
23
|
+
2046,25.44564450586888,25.31673961647436
|
|
24
|
+
2047,24.74520842183633,24.63621389966453
|
|
25
|
+
2048,24.16286024271848,24.07368980782465
|
|
26
|
+
2049,23.54229515901582,23.47545768393051
|
|
27
|
+
2050,22.66831879088747,22.62882756821037
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
year,total_emissions,co2_emissions
|
|
2
|
+
2025,32.50725713374266,32.44196100652248
|
|
3
|
+
2026,29.83790830913824,29.77797400434832
|
|
4
|
+
2027,27.16855948453379,27.11398700217416
|
|
5
|
+
2028,24.49921065992936,24.45
|
|
6
|
+
2029,17.13942733489128,17.105
|
|
7
|
+
2030,9.77964400985319,9.759999999999998
|
|
8
|
+
2031,8.64235958862539,8.625
|
|
9
|
+
2032,7.505075167397589,7.490000000000002
|
|
10
|
+
2033,6.857106950897744,6.843333333333334
|
|
11
|
+
2034,6.209138734397911,6.196666666666665
|
|
12
|
+
2035,5.56117051789807,5.549999999999997
|
|
13
|
+
2036,5.36878407835998,5.357999999999997
|
|
14
|
+
2037,5.176397638821882,5.165999999999997
|
|
15
|
+
2038,4.984011199283785,4.973999999999997
|
|
16
|
+
2039,4.79162475974568,4.781999999999996
|
|
17
|
+
2040,4.59923832020759,4.589999999999996
|
|
18
|
+
2041,4.038111204888153,4.030000000000001
|
|
19
|
+
2042,3.476984089568695,3.469999999999999
|
|
20
|
+
2043,2.915856974249259,2.909999999999997
|
|
21
|
+
2044,2.354729858929822,2.350000000000001
|
|
22
|
+
2045,1.793602743610371,1.789999999999999
|
|
23
|
+
2046,1.635284736073807,1.631999999999998
|
|
24
|
+
2047,1.476966728537256,1.474000000000004
|
|
25
|
+
2048,1.318648721000699,1.316000000000003
|
|
26
|
+
2049,1.160330713464148,1.158000000000001
|
|
27
|
+
2050,1.002012705927584,1.0
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
year,total_emissions,co2_emissions
|
|
2
|
+
2025,44.58577948677008,44.05894839030271
|
|
3
|
+
2026,41.76215491141179,41.25758933951977
|
|
4
|
+
2027,39.70567192073906,39.23765240655013
|
|
5
|
+
2028,37.26010561856675,36.83431447995322
|
|
6
|
+
2029,34.19785316556313,33.81117841957851
|
|
7
|
+
2030,31.43245031291405,31.07353635510041
|
|
8
|
+
2031,28.69997029599952,28.36819676278073
|
|
9
|
+
2032,26.59501095792233,26.28617230178295
|
|
10
|
+
2033,24.84076273628184,24.55131752501302
|
|
11
|
+
2034,22.94586216257986,22.67464332054091
|
|
12
|
+
2035,21.14735223607432,20.89904650039935
|
|
13
|
+
2036,19.27633788073949,19.05109559649581
|
|
14
|
+
2037,15.7653474545877,15.59620736142275
|
|
15
|
+
2038,12.9384589438616,12.80140603563029
|
|
16
|
+
2039,12.08381263593697,11.95654097216175
|
|
17
|
+
2040,11.15047714637436,11.03178833357156
|
|
18
|
+
2041,9.187758972035972,9.083599662502756
|
|
19
|
+
2042,8.161045397245623,8.068761566542541
|
|
20
|
+
2043,7.122371590722622,7.040473951764909
|
|
21
|
+
2044,6.340010755308043,6.266324996154999
|
|
22
|
+
2045,5.598491109906249,5.532365132638375
|
|
23
|
+
2046,4.791837461554515,4.731966528251405
|
|
24
|
+
2047,4.383266305448885,4.329026897175616
|
|
25
|
+
2048,3.977737419529227,3.929071887534263
|
|
26
|
+
2049,3.774533739035476,3.72590477210364
|
|
27
|
+
2050,3.565474949937183,3.516870745882208
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
year,total_emissions,co2_emissions
|
|
2
|
+
2025,99.12272664305519,98.25403855675562
|
|
3
|
+
2026,94.00545196720526,93.18324933151627
|
|
4
|
+
2027,88.46829694145109,87.692118829643
|
|
5
|
+
2028,81.9631670476133,81.24051515232904
|
|
6
|
+
2029,75.54235046364245,74.87020128594503
|
|
7
|
+
2030,68.55089525927193,67.93090887662072
|
|
8
|
+
2031,62.00366564071578,61.43432616860417
|
|
9
|
+
2032,55.49538901005911,54.97921156162987
|
|
10
|
+
2033,49.35226948036563,48.88829574478177
|
|
11
|
+
2034,43.29431972460326,42.88441284920134
|
|
12
|
+
2035,36.9826117147182,36.62787683374223
|
|
13
|
+
2036,31.70591627163367,31.40105788566954
|
|
14
|
+
2037,26.91955426062552,26.66063915889774
|
|
15
|
+
2038,22.56536583866087,22.34890270709492
|
|
16
|
+
2039,18.61995627199961,18.44222160728471
|
|
17
|
+
2040,14.86378564829454,14.72182848513786
|
|
18
|
+
2041,11.69090865447991,11.57930543734517
|
|
19
|
+
2042,9.037940995623742,8.951534692161857
|
|
20
|
+
2043,6.870212520242049,6.804186723328982
|
|
21
|
+
2044,5.149414108151774,5.099362380047054
|
|
22
|
+
2045,3.820839623560758,3.782803243875009
|
|
23
|
+
2046,2.834962923360678,2.805657916263755
|
|
24
|
+
2047,2.130571272650968,2.107463740688843
|
|
25
|
+
2048,1.63534027428399,1.616550287951554
|
|
26
|
+
2049,1.294459934736096,1.278532401102467
|
|
27
|
+
2050,1.07020023620143,1.056053934053608
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "jrpyprogramming"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.6"
|
|
4
4
|
description = "Jumping Rivers: Programming with Python"
|
|
5
5
|
authors = ["Jumping Rivers <info@jumpingrivers.com>"]
|
|
6
6
|
|
|
7
7
|
[tool.poetry.dependencies]
|
|
8
8
|
python = ">=3.9"
|
|
9
|
-
pandas = "^
|
|
10
|
-
numpy = "^
|
|
9
|
+
pandas = "^2.2.0"
|
|
10
|
+
numpy = "^2.0"
|
|
11
11
|
matplotlib = "^3.5"
|
|
12
|
-
jrpyintroduction = ">=0.
|
|
12
|
+
jrpyintroduction = ">=0.3.8"
|
|
13
13
|
|
|
14
14
|
[build-system]
|
|
15
15
|
requires = ["poetry-core>=1.0.0"]
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.2.4"
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import webbrowser
|
|
2
|
-
from pkg_resources import resource_listdir
|
|
3
|
-
from pkg_resources import resource_filename
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def browse():
|
|
7
|
-
"""
|
|
8
|
-
List all of the vignettes available for this package.
|
|
9
|
-
"""
|
|
10
|
-
outs = _get_vignette_titles()
|
|
11
|
-
|
|
12
|
-
if len(outs) > 0:
|
|
13
|
-
print("\nAvailable documents: \n")
|
|
14
|
-
print("\n".join(outs))
|
|
15
|
-
print(f"\nTo open use e.g load('{outs[0]}')\n")
|
|
16
|
-
else:
|
|
17
|
-
print("\nNo documents available\n")
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def load(name):
|
|
21
|
-
"""
|
|
22
|
-
Open a particular vignette from the package.
|
|
23
|
-
"""
|
|
24
|
-
outs = _get_vignette_titles()
|
|
25
|
-
if name in outs:
|
|
26
|
-
path = resource_filename("jrpyprogramming", f"vignettes/{name}")
|
|
27
|
-
webbrowser.open_new(path)
|
|
28
|
-
else:
|
|
29
|
-
print(f"\nVignette '{name}' not found")
|
|
30
|
-
browse()
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def _get_vignette_titles():
|
|
34
|
-
x = resource_listdir("jrpyprogramming", "vignettes")
|
|
35
|
-
# grab only those which are pdfs or html
|
|
36
|
-
pdfs = [file for file in x if file.endswith(".pdf")]
|
|
37
|
-
htmls = [file for file in x if file.endswith(".html")]
|
|
38
|
-
# Concat pdfs and htmls
|
|
39
|
-
outs = pdfs + htmls
|
|
40
|
-
# Return in some legible order
|
|
41
|
-
outs.sort()
|
|
42
|
-
return outs
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|