Skip to content

Commit

Permalink
Fix linking issue with metal markets.
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Aug 5, 2023
1 parent 3d26994 commit 1807e33
Show file tree
Hide file tree
Showing 13 changed files with 324 additions and 225 deletions.
170 changes: 92 additions & 78 deletions dev/Untitled.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -85,7 +85,7 @@
"source": [
"ndb = NewDatabase(\n",
" scenarios = scenarios,\n",
" source_db= \"ecoinvent cutoff 3.9.1\",\n",
" source_db= \"ecoinvent 3.9.1 cutoff\",\n",
" source_version=\"3.9.1\",\n",
" #source_type=source,\n",
" #source_file_path=f\"/Users/romain/Documents/ecoinvent {ei}_cutoff_ecoSpold02/datasets\" if source == \"ecospold\" else None, # <-- this is NEW\n",
Expand All @@ -106,68 +106,88 @@
"name": "stdout",
"output_type": "stream",
"text": [
"`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",
"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",
"\n",
"////////////////////////////// METALS ///////////////////////////////\n",
"Creating metal markets\n",
"... for stibnite concentrate.\n",
"... for antimony.\n",
"... for Bauxite.\n",
"... for aluminium oxide, metallurgical.\n",
"... for aluminium, primary, ingot.\n",
"... for beryllium.\n",
"... for calcium borates.\n",
"... for sodium borates.\n",
"... for Cadmium.\n",
"... for chromite ore concentrate.\n",
"... for Cobalt, mine.\n",
"... for cobalt sulfate.\n",
"... for copper concentrate, sulfide ore.\n",
"... for copper, anode.\n",
"... for copper, cathode.\n",
"... for gallium, semiconductor-grade.\n",
"... for germanium, concentrate.\n",
"... for Gold.\n",
"... for natural graphite, coated.\n",
"... for Indium production.\n",
"... for iron ore concentrate.\n",
"... for pig iron.\n",
"... for lead concentrate.\n",
"... for lead.\n",
"... for lithium carbonate, battery grade.\n",
"... for spodumene.\n",
"... for dolomite.\n",
"... for magnesium.\n",
"... for manganese concentrate.\n",
"... for manganese.\n",
"... for molybdenite.\n",
"... for molybdenum.\n",
"... for nickel concentrate.\n",
"... for nickel, class 1.\n",
"... for phosphate rock, beneficiated.\n",
"New location CX for Christmas Island not found\n",
"... for Palladium .\n",
"... for Platinum .\n",
"... for potash salt.\n",
"... for rare earth carbonate concentrate.\n",
"... for Rhenium.\n",
"... for Selenium.\n",
"... for silica sand.\n",
"... for silicon, metallurgical grade.\n",
"... for Silver.\n",
"... for strontium sulfate, 90% SrSO4.\n",
"... for sulfur.\n",
"... for ferroniobium, 66% Nb.\n",
"... for tantalum concentrate, 30% Ta2O5.\n",
"... for tellurium, semiconductor-grade.\n",
"... for tin concentrate.\n",
"... for tin.\n",
"... for ilmenite, 54% titanium dioxide.\n",
"... for rutile, 95% titanium dioxide.\n",
"... for titanium.\n",
"... for tungsten concentrate.\n",
"... for uranium ore, as U.\n",
"... for vanadium pentoxide.\n",
"... for vanadium bearing magnetite.\n",
"New location not found for European Union not found\n",
"... for zinc concentrate.\n",
"... for zinc.\n",
"... for zircon.\n",
"Creating additional mining processes\n",
"Done!\n",
"\n"
]
}
],
"source": [
"#ndb.update_electricity()\n",
"ndb.update_all()\n",
"#ndb.update_metals()\n",
"#ndb.update_all()\n",
"ndb.update_metals()\n",
"#ndb.update_fuels()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "59bb023a-94c0-41c1-ae8e-060eecae91e0",
"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"
]
}
],
"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": [
Expand All @@ -184,56 +204,50 @@
"text": [
"Writing activities to SQLite3 database:\n",
"0% [##############################] 100% | ETA: 00:00:00\n",
"Total time elapsed: 00:00:48\n"
"Total time elapsed: 00:00:36\n"
]
},
{
"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",
" Started: 08/05/2023 14:30:24\n",
" Finished: 08/05/2023 14:31:01\n",
" Total time elapsed: 00:00:36\n",
" CPU %: 87.60\n",
" Memory %: 12.16\n",
"Created database: test_metals3\n",
"Generate scenario report.\n",
"Report saved under /Users/romain/Github/premise/dev/export/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"
"Report saved under /Users/romain/GitHub/premise/dev.\n"
]
}
],
"source": [
"ndb.write_db_to_brightway(\"test_sebastian4\")"
"ndb.write_db_to_brightway(\"test_metals3\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 5,
"id": "407ea861-e723-4fda-9e23-d2c21f01d42a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Databases dictionary with 6 object(s):\n",
"\tbiosphere3\n",
"\tecoinvent cutoff 3.9.1\n",
"\tecoinvent_cutoff_3.9_remind_SSP1-PkBudg500_2030\n",
"\tmy_dp\n",
"\tsebastian_test\n",
"\ttest_sebastian2"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
"name": "stdout",
"output_type": "stream",
"text": [
"yes\n"
]
}
],
"source": [
"bw2data.databases"
"key = ('market for sulfur', 'sulfur', 'GLO', 'kilogram')\n",
"for ds in ndb.scenarios[0][\"database\"]:\n",
" if (ds[\"name\"], ds[\"reference product\"], ds[\"location\"], ds[\"unit\"]) == key:\n",
" print(\"yes\")"
]
},
{
Expand Down Expand Up @@ -1626,7 +1640,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.0"
"version": "3.9.12"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion dev/test_premise.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.15"
"version": "3.9.12"
}
},
"nbformat": 4,
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, 5, 9)
__version__ = (1, 6, 0)

from pathlib import Path

Expand Down
8 changes: 6 additions & 2 deletions premise/cement.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
logger = create_logger("cement")


def _update_cement(scenario, version, system_model, modified_datasets):
def _update_cement(scenario, version, system_model, modified_datasets, cache):
cement = Cement(
database=scenario["database"],
model=scenario["model"],
Expand All @@ -31,16 +31,18 @@ def _update_cement(scenario, version, system_model, modified_datasets):
version=version,
system_model=system_model,
modified_datasets=modified_datasets,
cache=cache
)

if scenario["iam data"].cement_markets is not None:
cement.add_datasets_to_database()
scenario["database"] = cement.database
modified_datasets = cement.modified_datasets
cache = cement.cache
else:
print("No cement markets found in IAM data. Skipping.")

return scenario, modified_datasets
return scenario, modified_datasets, cache


class Cement(BaseTransformation):
Expand Down Expand Up @@ -74,6 +76,7 @@ def __init__(
version: str,
system_model: str,
modified_datasets: dict,
cache: dict = None
):
super().__init__(
database,
Expand All @@ -84,6 +87,7 @@ def __init__(
version,
system_model,
modified_datasets,
cache
)
self.version = version

Expand Down
8 changes: 6 additions & 2 deletions premise/direct_air_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def fetch_mapping(filepath: str) -> dict:
return mapping


def _update_dac(scenario, version, system_model, modified_datasets):
def _update_dac(scenario, version, system_model, modified_datasets, cache=None):
dac = DirectAirCapture(
database=scenario["database"],
iam_data=scenario["iam data"],
Expand All @@ -47,16 +47,18 @@ def _update_dac(scenario, version, system_model, modified_datasets):
version=version,
system_model=system_model,
modified_datasets=modified_datasets,
cache=cache
)

if scenario["iam data"].dac_markets is not None:
dac.generate_dac_activities()
scenario["database"] = dac.database
modified_datasets = dac.modified_datasets
cache = dac.cache
else:
print("No DAC markets found in IAM data. Skipping.")

return scenario, modified_datasets
return scenario, modified_datasets, cache


class DirectAirCapture(BaseTransformation):
Expand All @@ -75,6 +77,7 @@ def __init__(
version: str,
system_model: str,
modified_datasets: dict,
cache: dict = None,
):
super().__init__(
database,
Expand All @@ -85,6 +88,7 @@ def __init__(
version,
system_model,
modified_datasets,
cache
)
self.database = database
self.iam_data = iam_data
Expand Down
Loading

0 comments on commit 1807e33

Please sign in to comment.