Skip to content

Commit

Permalink
Fix unlinked exchange to DAC + version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Aug 8, 2023
1 parent a2eff88 commit 882bfbc
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 61 deletions.
254 changes: 199 additions & 55 deletions dev/Untitled.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "6d93e33a-b89e-4e56-bfb7-5a8a0a232053",
"metadata": {},
"outputs": [],
Expand All @@ -21,8 +21,8 @@
"source": [
"scenarios = [\n",
" {\"model\":\"remind\", \"pathway\":\"SSP1-PkBudg500\", \"year\":2030}, # optimistic renewable scenario, 2.3-2.8 °C\n",
" #{\"model\":\"image\", \"pathway\":\"SSP2-RCP26\", \"year\":2030}, # historical development, Paris Agreement, 1.6-1.8 °C\n",
" #{\"model\":\"remind\", \"pathway\":\"SSP5-NPi\", \"year\":2030}, # optimistic fossil, National policies, 4.0°C\n",
" {\"model\":\"image\", \"pathway\":\"SSP2-RCP26\", \"year\":2030}, # historical development, Paris Agreement, 1.6-1.8 °C\n",
" {\"model\":\"remind\", \"pathway\":\"SSP5-NPi\", \"year\":2030}, # optimistic fossil, National policies, 4.0°C\n",
"]"
]
},
Expand All @@ -36,7 +36,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"premise v.(1, 5, 9)\n",
"premise v.(1, 6, 0)\n",
"+------------------------------------------------------------------+\n",
"| Warning |\n",
"+------------------------------------------------------------------+\n",
Expand Down Expand Up @@ -109,7 +109,17 @@
"`update_all()` will skip the following steps:\n",
"update_two_wheelers(), update_cars(), and update_buses()\n",
"If you want to update these steps, please run them separately afterwards.\n",
"Extracted 1 worksheets in 7.27 seconds\n",
"Extracted 1 worksheets in 7.72 seconds\n",
"Migrating to 3.8 first\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n",
"Done!\n",
"Done!\n",
"Extracted 1 worksheets in 8.06 seconds\n",
"Migrating to 3.8 first\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n",
Expand All @@ -119,6 +129,138 @@
"Applying strategy: migrate_exchanges\n",
"Done!\n",
"Done!\n",
"Extracted 1 worksheets in 7.77 seconds\n",
"Migrating to 3.8 first\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n",
"Done!\n",
"No fuel market for market for hydrogen, gaseous in BRA\n",
"No fuel market for market for hydrogen, gaseous in CAN\n",
"No fuel market for market for hydrogen, gaseous in CEU\n",
"No fuel market for market for hydrogen, gaseous in EAF\n",
"No fuel market for market for hydrogen, gaseous in INDIA\n",
"No fuel market for market for hydrogen, gaseous in INDO\n",
"No fuel market for market for hydrogen, gaseous in JAP\n",
"No fuel market for market for hydrogen, gaseous in KOR\n",
"No fuel market for market for hydrogen, gaseous in ME\n",
"No fuel market for market for hydrogen, gaseous in MEX\n",
"No fuel market for market for hydrogen, gaseous in NAF\n",
"No fuel market for market for hydrogen, gaseous in OCE\n",
"No fuel market for market for hydrogen, gaseous in RCAM\n",
"No fuel market for market for hydrogen, gaseous in RSAF\n",
"No fuel market for market for hydrogen, gaseous in RSAM\n",
"No fuel market for market for hydrogen, gaseous in RSAS\n",
"No fuel market for market for hydrogen, gaseous in RUS\n",
"No fuel market for market for hydrogen, gaseous in SAF\n",
"No fuel market for market for hydrogen, gaseous in SEAS\n",
"No fuel market for market for hydrogen, gaseous in STAN\n",
"No fuel market for market for hydrogen, gaseous in UKR\n",
"No fuel market for market for hydrogen, gaseous in USA\n",
"No fuel market for market for hydrogen, gaseous in WAF\n",
"No fuel market for market for hydrogen, gaseous in WEU\n",
"Incorrect market share for market for hydrogen, gaseous in BRA\n",
"Incorrect market share for market for hydrogen, gaseous in CAN\n",
"Incorrect market share for market for hydrogen, gaseous in CEU\n",
"Incorrect market share for market for hydrogen, gaseous in CHN\n",
"Incorrect market share for market for hydrogen, gaseous in EAF\n",
"Incorrect market share for market for hydrogen, gaseous in INDIA\n",
"Incorrect market share for market for hydrogen, gaseous in INDO\n",
"Incorrect market share for market for hydrogen, gaseous in JAP\n",
"Incorrect market share for market for hydrogen, gaseous in KOR\n",
"Incorrect market share for market for hydrogen, gaseous in ME\n",
"Incorrect market share for market for hydrogen, gaseous in MEX\n",
"Incorrect market share for market for hydrogen, gaseous in NAF\n",
"Incorrect market share for market for hydrogen, gaseous in OCE\n",
"Incorrect market share for market for hydrogen, gaseous in RCAM\n",
"Incorrect market share for market for hydrogen, gaseous in RSAF\n",
"Incorrect market share for market for hydrogen, gaseous in RSAM\n",
"Incorrect market share for market for hydrogen, gaseous in RSAS\n",
"Incorrect market share for market for hydrogen, gaseous in RUS\n",
"Incorrect market share for market for hydrogen, gaseous in SAF\n",
"Incorrect market share for market for hydrogen, gaseous in SEAS\n",
"Incorrect market share for market for hydrogen, gaseous in STAN\n",
"Incorrect market share for market for hydrogen, gaseous in TUR\n",
"Incorrect market share for market for hydrogen, gaseous in UKR\n",
"Incorrect market share for market for hydrogen, gaseous in USA\n",
"Incorrect market share for market for hydrogen, gaseous in WAF\n",
"Incorrect market share for market for hydrogen, gaseous in WEU\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in BRA\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in CAN\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in CEU\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in EAF\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in INDIA\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in INDO\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in JAP\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in KOR\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in ME\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in MEX\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in NAF\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in OCE\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in RCAM\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in RSAF\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in RSAM\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in RSAS\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in RUS\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in SAF\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in SEAS\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in STAN\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in UKR\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in USA\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in WAF\n",
"No fuel market for market for hydrogen, gaseous, 20-year period in WEU\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in BRA\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in CAN\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in CEU\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in EAF\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in INDIA\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in INDO\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in JAP\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in KOR\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in ME\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in MEX\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in NAF\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in OCE\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in RCAM\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in RSAF\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in RSAM\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in RSAS\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in RUS\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in SAF\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in SEAS\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in STAN\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in UKR\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in USA\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in WAF\n",
"No fuel market for market for hydrogen, gaseous, 40-year period in WEU\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in BRA\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in CAN\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in CEU\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in EAF\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in INDIA\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in INDO\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in JAP\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in KOR\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in ME\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in MEX\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in NAF\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in OCE\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in RCAM\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in RSAF\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in RSAM\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in RSAS\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in RUS\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in SAF\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in SEAS\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in STAN\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in UKR\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in USA\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in WAF\n",
"No fuel market for market for hydrogen, gaseous, 60-year period in WEU\n",
"Done!\n",
"Done!\n",
"\n"
]
Expand All @@ -133,90 +275,92 @@
},
{
"cell_type": "code",
"execution_count": 5,
"id": "59bb023a-94c0-41c1-ae8e-060eecae91e0",
"execution_count": null,
"id": "a85ca090-8d49-42c2-8b21-ffc69fabc12d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"market for natural gas, high pressure JPN\n",
"Butane None\n",
"Carbon dioxide, fossil None\n",
"Ethane None\n",
"Mercury II None\n",
"Methane, fossil None\n",
"NMVOC, non-methane volatile organic compounds None\n",
"Propane None\n",
"market for electricity, medium voltage JP\n",
"market for heat, district or industrial, natural gas RoW\n",
"market for pipeline, natural gas, high pressure distribution network GLO\n",
"market for natural gas, liquefied GLO\n",
"market group for natural gas, high pressure GLO\n",
"biomethane production, from biogas upgrading, using amine scrubbing JPN\n"
"Write new database(s) to Brightway2.\n",
"Database ecoinvent_cutoff_3.9_remind_SSP1-PkBudg500_2030 already exists: it will be overwritten.\n"
]
}
],
"source": [
"for ds in ndb.scenarios[0][\"database\"]:\n",
" if ds[\"name\"] == \"market for natural gas, high pressure\" and ds[\"location\"] == \"JPN\":\n",
" for e in ds[\"exchanges\"]:\n",
" print(e[\"name\"], e.get(\"location\"))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "a85ca090-8d49-42c2-8b21-ffc69fabc12d",
"metadata": {},
"outputs": [
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Writing activities to SQLite3 database:\n",
"0% [##############################] 100% | ETA: 00:00:00\n",
"Total time elapsed: 00:00:56\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Write new database(s) to Brightway2.\n"
"Title: Writing activities to SQLite3 database:\n",
" Started: 08/08/2023 13:46:33\n",
" Finished: 08/08/2023 13:47:30\n",
" Total time elapsed: 00:00:56\n",
" CPU %: 99.20\n",
" Memory %: 23.54\n",
"Created database: ecoinvent_cutoff_3.9_remind_SSP1-PkBudg500_2030\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Writing activities to SQLite3 database:\n",
"0% [##############################] 100% | ETA: 00:00:00\n",
"Total time elapsed: 00:00:48\n"
"0% [########### ] 100% | ETA: 00:00:35"
]
},
}
],
"source": [
"ndb.write_db_to_brightway()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "1d863e7b-11ab-417b-96f7-3342529422ad",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Title: Writing activities to SQLite3 database:\n",
" Started: 08/04/2023 17:37:00\n",
" Finished: 08/04/2023 17:37:49\n",
" Total time elapsed: 00:00:48\n",
" CPU %: 99.10\n",
" Memory %: 8.54\n",
"Created database: test_sebastian4\n",
"Generate scenario report.\n",
"Report saved under /Users/romain/Github/premise/dev/export/scenario_report.\n",
"Generate change report.\n",
"Report saved under /Users/romain/Github/premise/dev.\n"
"methane, from electrochemical methanation, with carbon from atmospheric carbon dioxide capture RER\n",
"methane, from biological methanation, with carbon from atmospheric carbon dioxide capture RER\n"
]
}
],
"source": [
"ndb.write_db_to_brightway(\"test_sebastian4\")"
"for ds in ndb.scenarios[0][\"database\"]:\n",
" for e in ds[\"exchanges\"]:\n",
" if e[\"name\"] == \"carbon dioxide, captured from atmosphere, with a sorbent-based direct air capture system, 100ktCO2\":\n",
" print(ds[\"name\"], ds[\"location\"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"id": "407ea861-e723-4fda-9e23-d2c21f01d42a",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Generate change report.\n",
"Report saved under /Users/romain/Github/premise/dev.\n"
]
}
],
"source": [
"bw2data.databases"
"ndb.generate_change_report()"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion premise/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__all__ = ("NewDatabase", "clear_cache", "get_regions_definition")
__version__ = (1, 6, 0)
__version__ = (1, 6, 1)

from pathlib import Path

Expand Down
3 changes: 2 additions & 1 deletion premise/direct_air_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ def generate_dac_activities(self) -> None:
name=ds_name,
ref_prod="carbon dioxide",
relink=False,
delete_original_dataset=True,
delete_original_dataset=False,
empty_original_activity=False,
)

# loop through heat sources
Expand Down
6 changes: 3 additions & 3 deletions premise/fuels.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def __init__(
for sublist in list(self.fuel_groups.values())
for item in sublist
]
if g in self.iam_data.production_volumes.variables.values.tolist()
if g in self.iam_data.production_volumes.coords["variables"].values.tolist()
]
)

Expand Down Expand Up @@ -1926,8 +1926,7 @@ def fetch_fuel_share(
/ self.iam_fuel_markets.sel(
region=region, variables=relevant_variables
).sum(dim="variables")
)
.interp(
).fillna(0).interp(
year=np.arange(self.year, self.year + period + 1),
kwargs={"fill_value": "extrapolate"},
)
Expand Down Expand Up @@ -2212,6 +2211,7 @@ def generate_regional_fuel_market(
share = fuel_providers[prod_var]["find_share"](
prod_var, tuple(vars_map[fuel_category]), region, period
)

else:
share = 1.0

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def package_files(directory):

setup(
name="premise",
version="1.6.0",
version="1.6.1",
python_requires=">=3.9,<3.11",
packages=packages,
author="Romain Sacchi <[email protected]>, Alois Dirnaichner <[email protected]>, Chris Mutel "
Expand Down

0 comments on commit 882bfbc

Please sign in to comment.