Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traduction one one #19

Merged
merged 28 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bdaa88e
change the name translation to find mistakes
Tristan22400 Jul 23, 2024
86b210e
change in subscript dict for the automatic translation
Tristan22400 Jul 23, 2024
dca482f
creation of the first dictionnary of translation
Tristan22400 Jul 23, 2024
6876f80
Merge branch 'main' into traduction-one-one
Tristan22400 Jul 23, 2024
1abd208
update the dictionnary of translation
Tristan22400 Jul 25, 2024
6a66754
update the creation of the first dictionary of translation
Tristan22400 Jul 25, 2024
1b6a59c
change naming of variable for the first dictionnary
Tristan22400 Jul 25, 2024
e4bcada
add script to run translation
Tristan22400 Jul 25, 2024
374ad3a
add the final script to do the translation
Tristan22400 Jul 25, 2024
2740280
add a translation helpers to translate new variables
Tristan22400 Jul 25, 2024
edac6ca
update the creation of the global dict
Tristan22400 Jul 25, 2024
d1aff11
change the organization and correct bugs
Tristan22400 Jul 25, 2024
717fde1
variable name dict
Tristan22400 Jul 25, 2024
a3a50e6
Merge pull request #21 from Tristan22400/create-script
Tristan22400 Jul 26, 2024
3bb1b7d
add correction and create script to update the variable translation d…
Tristan22400 Jul 26, 2024
9ec0d13
Merge pull request #24 from Tristan22400/correction_script
Tristan22400 Jul 26, 2024
21c6cf2
add the correction in the translation process
Tristan22400 Jul 26, 2024
332285b
add aggregation in the translation file
Tristan22400 Jul 27, 2024
9eaf5e1
create the dictionary for the subcript
Tristan22400 Jul 27, 2024
48eaa52
update report
Tristan22400 Jul 27, 2024
0b26c53
change to direct translation of missing variables
Tristan22400 Jul 27, 2024
646ca16
change script to handle direct translation
Tristan22400 Jul 27, 2024
5eecdfa
change dict name
Tristan22400 Jul 29, 2024
cb97903
update list of greenhouses gases
Tristan22400 Jul 29, 2024
5739f40
create multiples types of plot
Tristan22400 Jul 29, 2024
2f1029b
Merge pull request #26 from Tristan22400/improve-timeseries-plotting
Tristan22400 Jul 29, 2024
6bfecf2
Merge pull request #27 from Tristan22400/direct-missing-translation
Tristan22400 Jul 29, 2024
3477cea
merge_conflict
Tristan22400 Jul 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 98 additions & 28 deletions Conversion-Script/Convert_Wiliam_result_IAMC-format.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,24 @@
"metadata": {},
"outputs": [],
"source": [
"# Check for duplicate rows\n",
"duplicate_rows = scenario_variable_df[scenario_variable_df.duplicated()]\n",
"\n",
"# Display duplicate rows\n",
"print(\"Duplicate Rows:\")\n",
"print(duplicate_rows)\n",
"\n",
"# Count the number of duplicate rows\n",
"num_duplicate_rows = duplicate_rows.shape[0]\n",
"print(\"Number of Duplicate Rows:\", num_duplicate_rows)\n",
"\n",
"# Read the CSV file into a pandas DataFrame\n",
"data_name_df = pd.read_excel('Variable_Reference/Variable_name_IAMC.xlsx')\n",
"data_name_df = pd.read_excel(\"Variable_Reference/Variable_name_IAMC.xlsx\")\n",
"# Remplacer les tirets du bas par des espaces dans la colonne\n",
"# data_name_df['WILIAM_variable'] = data_name_df['WILIAM_variable'].str.replace('_', ' ')\n",
"# Drop rows with NaN values which corresponds to values not conserv for the final upload of data in IAMC format\n",
"data_name_df.dropna(subset=['IAMC_variable'],inplace=True)\n",
"data_name_df"
"data_name_df.dropna(subset=[\"IAMC_variable\"], inplace=True)\n",
"data_name_df\n"
]
},
{
Expand All @@ -184,7 +195,7 @@
"\n",
"# Keep only the rows where the value in column 'Variable' belongs to the list of wanted values \n",
"variable_required_list = data_name_df['IAMC_variable'].to_list()\n",
"scenario_variable_df = scenario_variable_df[scenario_variable_df['Variable'].isin(variable_required_list)]"
"# scenario_variable_df = scenario_variable_df[scenario_variable_df['Variable'].isin(variable_required_list)]\n"
]
},
{
Expand Down Expand Up @@ -273,39 +284,79 @@
"outputs": [],
"source": [
"# Dict used to check if the subscripts are a country\n",
"country_dict= {'EU27':1, 'UK':1,'CHINA':1,'EASOC':1,'INDIA':1,'LATAM':1,'RUSSIA':1,'USMCA':1,'LROW':1,'AUSTRIA':1,'BELGIUM':1,'BULGARIA':1,'CROATIA':1,'CYPRUS':1,'CZECH_REPUBLIC':1,'DENMARK':1,'ESTONIA':1,'FINLAND':1,'FRANCE':1,'GERMANY':1,'GREECE':1,'HUNGARY':1,'IRELAND':1,'ITALY':1,'LATVIA':1,'LITHUANIA':1,'LUXEMBOURG':1,'MALTA':1,'NETHERLANDS':1,'POLAND':1,'PORTUGAL':1,'ROMANIA':1,'SLOVAKIA':1,'SLOVENIA':1,'SPAIN':1,'SWEDEN':1}\n",
"\n",
"# Aggregate the subscripts at the end of the variable \n",
"country_dict = {\n",
" \"EU27\": 1,\n",
" \"UK\": 1,\n",
" \"CHINA\": 1,\n",
" \"EASOC\": 1,\n",
" \"INDIA\": 1,\n",
" \"LATAM\": 1,\n",
" \"RUSSIA\": 1,\n",
" \"USMCA\": 1,\n",
" \"LROW\": 1,\n",
" \"AUSTRIA\": 1,\n",
" \"BELGIUM\": 1,\n",
" \"BULGARIA\": 1,\n",
" \"CROATIA\": 1,\n",
" \"CYPRUS\": 1,\n",
" \"CZECH_REPUBLIC\": 1,\n",
" \"DENMARK\": 1,\n",
" \"ESTONIA\": 1,\n",
" \"FINLAND\": 1,\n",
" \"FRANCE\": 1,\n",
" \"GERMANY\": 1,\n",
" \"GREECE\": 1,\n",
" \"HUNGARY\": 1,\n",
" \"IRELAND\": 1,\n",
" \"ITALY\": 1,\n",
" \"LATVIA\": 1,\n",
" \"LITHUANIA\": 1,\n",
" \"LUXEMBOURG\": 1,\n",
" \"MALTA\": 1,\n",
" \"NETHERLANDS\": 1,\n",
" \"POLAND\": 1,\n",
" \"PORTUGAL\": 1,\n",
" \"ROMANIA\": 1,\n",
" \"SLOVAKIA\": 1,\n",
" \"SLOVENIA\": 1,\n",
" \"SPAIN\": 1,\n",
" \"SWEDEN\": 1,\n",
"}\n",
"\n",
"\n",
"\n",
"\n",
"# Aggregate the subscripts at the end of the variable\n",
"def aggregate_variable_name(row, counter):\n",
" for k in range(counter):\n",
" subscript=row[\"Subscript \"+str(k)]\n",
" \n",
" if k==0 :\n",
" if country_dict.get(subscript)==1: \n",
" #Give the name of the region for that variable\n",
" row[\"Region\"]=subscript\n",
" \n",
" row[\"Subscript 0\"]=np.nan\n",
" subscript = row[\"Subscript \" + str(k)]\n",
"\n",
" if k == 0:\n",
" if country_dict.get(subscript) == 1:\n",
" # Give the name of the region for that variable\n",
" row[\"Region\"] = subscript\n",
"\n",
" row[\"Subscript 0\"] = np.nan\n",
" continue\n",
" \n",
"\n",
" if not pd.isnull(subscript):\n",
" \n",
" if energy_dict.get(subscript, None) is not None:\n",
" \n",
" subscript = energy_dict[subscript]\n",
" elif rest_dict.get(subscript,None): \n",
" elif rest_dict.get(subscript, None):\n",
" subscript = rest_dict[subscript]\n",
" \n",
" row[\"Variable\"]=row[\"Variable\"]+\"|\"+subscript\n",
" \n",
" return row \n",
"\n",
" row[\"Variable\"] = row[\"Variable\"] + \"|\" + subscript\n",
"\n",
" return row\n",
"\n",
"# Apply the previous function on all the lines \n",
"scenario_variable_df= scenario_variable_df.apply(aggregate_variable_name, args=(counter,),axis=1)\n",
"\n",
"# Apply the previous function on all the lines\n",
"scenario_variable_df = scenario_variable_df.apply(\n",
" aggregate_variable_name, args=(counter,), axis=1\n",
")\n",
"\n",
"# Remove the subscript columns once they have been added at the end of the variable name\n",
"drop_columns_list=[\"Subscript \" + str(k) for k in range(counter)]\n",
"drop_columns_list = [\"Subscript \" + str(k) for k in range(counter)]\n",
"scenario_variable_df.drop(columns=drop_columns_list, inplace=True)\n",
"\n",
"scenario_variable_df"
Expand Down Expand Up @@ -359,7 +410,26 @@
"\n",
"# Capitalize each variable's name\n",
"scenario_variable_df['Variable'] = scenario_variable_df['Variable'].apply(transform_string)\n",
"scenario_variable_df"
"scenario_variable_df.head(60)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import csv\n",
"\n",
"\n",
"# Step 1: Write to the first column\n",
"data_first_column = scenario_variable_df[\"Variable\"].to_list()\n",
"\n",
"# Open the CSV file in write mode and write the first column\n",
"with open(\"example.csv\", \"w\", newline=\"\") as csvfile:\n",
" csvwriter = csv.writer(csvfile)\n",
" for row in data_first_column:\n",
" csvwriter.writerow([row])\n"
]
},
{
Expand Down Expand Up @@ -645,7 +715,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.1"
"version": "3.10.14"
}
},
"nbformat": 4,
Expand Down
4 changes: 4 additions & 0 deletions Conversion-Script/Create_Variable_Dict/aggregation.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
('world_PE_by_commodity|PE_waste', 'world_PE_by_commodity|PE_solar'): 'Primary Energy|New',
('C', 'D', 'E'): 'Y'
}
37 changes: 37 additions & 0 deletions Conversion-Script/Create_Variable_Dict/economy_dashboard_dict.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{'DB CAPITAL STOCK': 'Capital Stock',
'DB CONSUMPTION FIXED CAPITAL': 'Value Added|Consumption Fixed Capital',
'DB DISPOSABLE INCOME PER CAPITA': 'Households|Consumer Price [index]',
'DB EMPLOYMENT': 'Employment',
'DB EXPORTS': 'Trade|Value|Exports',
'DB GDP': 'GDP|PPP',
'DB GDP PER CAPITA': 'Revenue|Households|Disposable [per capita]',
'DB GOV BALANCE': 'Government|Budget Balance',
'DB GOV BALANCE TO GDP': 'Government|Budget Balance to GDP',
'DB GOV CONSUMPTION': 'Public Consumption',
'DB GOV DEBT': 'Debt|Public',
'DB GOV DEBT TO GDP': 'Revenues|Households|Disposable income',
'DB GOV EXPENDITURE': 'Expenditure|Government',
'DB GOV REVENUE': 'Revenue|Government',
'DB GROSS FIXED CAPITAL FORMATION': 'Capital Formation',
'DB GVA AGRICULTURE': 'Value Added|Agriculture',
'DB GVA ENERGY': 'Value Added|Industry|Energy',
'DB GVA EXTRACTION': 'Value Added|Extraction',
'DB GVA INDUSTRY': 'Value Added|Industry',
'DB GVA SERVICES': 'Value Added|Services',
'DB GVA TAXES PRODUCTS TOTAL': 'Value Added|Taxes on products',
'DB HH CONSUMPTION': 'Expenditure|Household',
'DB HH CONSUMPTION COICOP': 'Households|Savings|Real',
'DB HH CONSUMPTION COICOP NOMINAL': 'Households|Savings',
'DB HH DISPOSABLE INCOME': 'Households|Consumption|COICOP',
'DB HH DISPOSABLE INCOME NOMINAL': 'Households|Consumption nominal|COICOP',
'DB HH SAVINGS': 'Revenues|Households|Disposable income|Nominal',
'DB HH SAVINGS NOMINAL': 'GDP|Country [per capita]',
'DB IMPORTS': 'Trade|Value|Imports',
'DB LABOUR COMPENSATION': 'Value Added|Labour Compensation',
'DB LABOUR FORCE': 'Labour Supply',
'DB NET OPERATING SURPLUS': 'Value Added|Net Operating Surplus',
'DB OTHER FINAL DEMAND': 'Final Demand|Other',
'DB OUTPUT': 'Output',
'DB TAXES PRODUCTION': 'Value Added|Taxes on production',
'DB TRADE BALANCE': 'Trade|Value|Balance',
'DB UNEMPLOYMENT RATE': 'Unemployment|Rate'}
86 changes: 43 additions & 43 deletions Conversion-Script/Create_Variable_Dict/energy_dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
'FE_gas': 'Gas',
'FE_heat': 'Heat',
'FE_hydrogen': 'Hydrogen',
'FE_liquid': 'Liquid',
'FE_solid_bio': 'Solid|Biomass',
'FE_solid_fossil': 'Solid|Fossil',
'FE_liquid': 'Liquids',
'FE_solid_bio': 'Solids|Biomass',
'FE_solid_fossil': 'Solids|Fossil',
'PE_agriculture_products': 'Agriculture Products',
'PE_coal': 'Coal',
'PE_forestry_products': 'Forestry Products',
Expand All @@ -17,44 +17,44 @@
'PE_solar': 'Solar',
'PE_waste': 'Waste',
'PE_wind': 'Wind',
'PROTRA_CHP_gas_fuels': 'Electricity and Heat|gas fuels|w/o CCS',
'PROTRA_CHP_gas_fuels_CCS': 'Electricity and Heat|gas fuels|w/ CCS',
'PROTRA_CHP_gas_fuels': 'Electricity and Heat|Gas fuels|w/o CCS',
'PROTRA_CHP_gas_fuels_CCS': 'Electricity and Heat|Gas fuels|w/ CCS',
'PROTRA_CHP_geothermal_DEACTIVATED': 'Electricity and '
'Heat|geothermal|DEACTIVATED',
'PROTRA_CHP_liquid_fuels': 'Electricity and Heat|liquid fuels|w/o CCS',
'PROTRA_CHP_liquid_fuels_CCS': 'Electricity and Heat|liquid fuels|w/ CCS',
'PROTRA_CHP_solid_bio': 'Electricity and Heat|solid|biomass|w/o CCS',
'PROTRA_CHP_solid_bio_CCS': 'Electricity and Heat|solid|biomass|w/ CCS',
'PROTRA_CHP_solid_fossil': 'Electricity and Heat|solid|fossil|w/o CCS',
'PROTRA_CHP_solid_fossil_CCS': 'Electricity and Heat|solid|fossil|w/ CCS',
'PROTRA_CHP_waste': 'Electricity and Heat|waste',
'PROTRA_HP_gas_fuels': 'Heat|gas fuels',
'PROTRA_HP_geothermal': 'Heat|geothermal',
'PROTRA_HP_liquid_fuels': 'Heat|liquid fuels',
'PROTRA_HP_solar_DEACTIVATED': 'Heat|solar|DEACTIVATED',
'PROTRA_HP_solid_bio': 'Heat|solid|biomass',
'PROTRA_HP_solid_fossil': 'Heat|solid|fossil',
'PROTRA_HP_waste': 'Heat|waste',
'PROTRA_PP_gas_fuels': 'Electricity|gas fuels|w/o CCS',
'PROTRA_PP_gas_fuels_CCS': 'Electricity|gas fuels|w/ CCS',
'PROTRA_PP_geothermal': 'Electricity|geothermal',
'PROTRA_PP_hydropower_dammed': 'Electricity|hydro|dammed',
'PROTRA_PP_hydropower_run_of_river': 'Electricity|hydro|run of river',
'PROTRA_PP_liquid_fuels': 'Electricity|liquid fuels|w/o CCS',
'PROTRA_PP_liquid_fuels_CCS': 'Electricity|liquid fuels|w/ CCS',
'PROTRA_PP_nuclear': 'Electricity|nuclear',
'PROTRA_PP_oceanic': 'Electricity|ocean',
'PROTRA_PP_solar_CSP': 'Electricity|solar|CSP',
'PROTRA_PP_solar_open_space_PV': 'Electricity|solar|open space|PV',
'PROTRA_PP_solar_urban_PV': 'Electricity|solar|urban|PV',
'PROTRA_PP_solid_bio': 'Electricity|solid|biomass|w/o CCS',
'PROTRA_PP_solid_bio_CCS': 'Electricity|solid|biomass|w/ CCS',
'PROTRA_PP_solid_fossil': 'Electricity|solid|fossil|w/o CCS',
'PROTRA_PP_solid_fossil_CCS': 'Electricity|solid|fossil|w/ CCS',
'PROTRA_PP_waste': 'Electricity|waste|w/o CCS',
'PROTRA_PP_waste_CCS': 'Electricity|waste|w/ CCS',
'PROTRA_PP_wind_offshore': 'Electricity|wind|offshore',
'PROTRA_PP_wind_onshore': 'Electricity|wind|onshore',
'Heat|Geothermal|Deactivated',
'PROTRA_CHP_liquid_fuels': 'Electricity and Heat|Liquid fuels|w/o CCS',
'PROTRA_CHP_liquid_fuels_CCS': 'Electricity and Heat|Liquid fuels|w/ CCS',
'PROTRA_CHP_solid_bio': 'Electricity and Heat|Solid|Biomass|w/o CCS',
'PROTRA_CHP_solid_bio_CCS': 'Electricity and Heat|Solid|Biomass|w/ CCS',
'PROTRA_CHP_solid_fossil': 'Electricity and Heat|Solid|Fossil|w/o CCS',
'PROTRA_CHP_solid_fossil_CCS': 'Electricity and Heat|Solid|Fossil|w/ CCS',
'PROTRA_CHP_waste': 'Electricity and Heat|Waste',
'PROTRA_HP_gas_fuels': 'Heat|Gas fuels',
'PROTRA_HP_geothermal': 'Heat|Geothermal',
'PROTRA_HP_liquid_fuels': 'Heat|Liquid fuels',
'PROTRA_HP_solar_DEACTIVATED': 'Heat|Solar|Deactivated',
'PROTRA_HP_solid_bio': 'Heat|Solid|Biomass',
'PROTRA_HP_solid_fossil': 'Heat|Solid|Fossil',
'PROTRA_HP_waste': 'Heat|Waste',
'PROTRA_PP_gas_fuels': 'Electricity|Gas fuels|w/o CCS',
'PROTRA_PP_gas_fuels_CCS': 'Electricity|Gas fuels|w/ CCS',
'PROTRA_PP_geothermal': 'Electricity|Geothermal',
'PROTRA_PP_hydropower_dammed': 'Electricity|Hydro|Dammed',
'PROTRA_PP_hydropower_run_of_river': 'Electricity|Hydro|Run of River',
'PROTRA_PP_liquid_fuels': 'Electricity|Liquid fuels|w/o CCS',
'PROTRA_PP_liquid_fuels_CCS': 'Electricity|Liquid fuels|w/ CCS',
'PROTRA_PP_nuclear': 'Electricity|Nuclear',
'PROTRA_PP_oceanic': 'Electricity|Ocean',
'PROTRA_PP_solar_CSP': 'Electricity|Solar|Csp',
'PROTRA_PP_solar_open_space_PV': 'Electricity|Solar|PV|Open Land',
'PROTRA_PP_solar_urban_PV': 'Electricity|Solar|PV|Urban',
'PROTRA_PP_solid_bio': 'Electricity|Solid|Biomass|w/o CCS',
'PROTRA_PP_solid_bio_CCS': 'Electricity|Solid|Biomass|w/ CCS',
'PROTRA_PP_solid_fossil': 'Electricity|Solid|Fossil|w/o CCS',
'PROTRA_PP_solid_fossil_CCS': 'Electricity|Solid|Fossil|w/ CCS',
'PROTRA_PP_waste': 'Electricity|Waste|w/o CCS',
'PROTRA_PP_waste_CCS': 'Electricity|Waste|w/ CCS',
'PROTRA_PP_wind_offshore': 'Electricity|Wind|Offshore',
'PROTRA_PP_wind_onshore': 'Electricity|Wind|Onshore',
'PROTRA_blending_gas_fuels': 'Gas Fuels',
'PROTRA_blending_liquid_fuels': 'Liquid Fuels',
'PROTRA_no_process_TI_hydrogen': 'Hydrogen',
Expand All @@ -64,6 +64,6 @@
'TO_gas': 'Gas',
'TO_heat': 'Heat',
'TO_hydrogen': 'Hydrogen',
'TO_liquid': 'Liquid',
'TO_solid_bio': 'Solid Biomass',
'TO_solid_fossil': 'Solid Fossil'}
'TO_liquid': 'Liquids',
'TO_solid_bio': 'Solids|Biomass',
'TO_solid_fossil': 'Solids|Fossil'}
12 changes: 12 additions & 0 deletions Conversion-Script/Create_Variable_Dict/land_dict.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{'CROPLAND IRRIGATED': 'Cropland|Irrigated',
'CROPLAND RAINFED': 'Cropland|Rainfed',
'FOREST MANAGED': 'Forest|Managed',
'FOREST PLANTATIONS': 'Forest|Forestry|Harvested Area',
'FOREST PRIMARY': 'Forest|Natural Forest',
'GRASSLAND': 'Grassland',
'OTHER LAND': 'Other',
'SHRUBLAND': 'Shrubland',
'SNOW ICE WATERBODIES': 'Snow and Ice Land',
'SOLAR LAND': 'Built-up Area|Solar',
'URBAN LAND': 'Built-up Area',
'WETLAND': 'Water Ecosystems|Wetlands'}
Loading