-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2. Add sectors.py
66 lines (56 loc) · 2.61 KB
/
2. Add sectors.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
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
#%% -*- coding: utf-8 -*-
"""
Created on Tue Apr 18 2023
@authors:
Lorenzo Rinaldi, Department of Energy, Politecnico di Milano
Nicolò Golinucci, PhD, Department of Energy, Politecnico di Milano
Emanuele Mainardi, Department of Energy, Politecnico di Milano
Prof. Matteo Vincenzo Rocco, PhD, Department of Energy, Politecnico di Milano
Prof. Emanuela Colombo, PhD, Department of Energy, Politecnico di Milano
"""
import mario
import pandas as pd
user = "LR"
sN = slice(None)
years = range(2011,2020)
paths = 'Paths.xlsx'
#%% Parse aggregated database from excel
world = {}
for year in years:
world[year] = mario.parse_from_txt(f"{pd.read_excel(paths, index_col=[0]).loc['Database',user]}\\a. Aggregated_SUT\\{year}\\flows", table='SUT', mode="flows")
#%% Define new commodities
new_sectors = {
'commodities': [
'Photovoltaic plants',
'Photovoltaic modules',
'Mono-Si and poli-Si cells',
'Raw silicon',
'Onshore wind plants',
'DFIG generators',
'Offshore wind plants',
'PMG generators',
'Neodymium',
'Dysprosium',
],
'activities': [
'Production of photovoltaic plants',
'Production of photovoltaic modules',
'Production of mono-Si and poli-Si cells',
'Production of onshore wind plants',
'Production of DFIG generators',
'Production of offshore wind plants',
'Production of PMG generators'
]
}
#%% Getting excel templates to add new commodities
path_commodities = f"{pd.read_excel(paths, index_col=[0]).loc['Add Sectors',user]}\\new_commodities.xlsx"
path_activities = f"{pd.read_excel(paths, index_col=[0]).loc['Add Sectors',user]}\\new_activities.xlsx"
# world[year].get_add_sectors_excel(new_sectors = new_sectors['commodities'],regions= world.get_index('Region'),path=path_commodities, item='Commodity')
# world[year].get_add_sectors_excel(new_sectors = new_sectors['activities'],regions= world.get_index('Region'),path=path_activities, item='Activity')
#%% Adding new commodities and activities
for year in years:
world[year].add_sectors(io=path_commodities, new_sectors= new_sectors['commodities'], regions= world[year].get_index('Region'), item= 'Commodity', inplace=True)
world[year].add_sectors(io=path_activities, new_sectors= new_sectors['activities'], regions= world[year].get_index('Region'), item= 'Activity', inplace=True)
#%% Aggregated database with new sectors to excel
for year in years:
world[year].to_txt(f"{pd.read_excel(paths, index_col=[0]).loc['Database',user]}\\b. Aggregated & new sectors SUT\\{year}", flows=False, coefficients=True)