diff --git a/dev/Untitled.ipynb b/dev/Untitled.ipynb index e0dc9cc7..d71ebf27 100644 --- a/dev/Untitled.ipynb +++ b/dev/Untitled.ipynb @@ -4,7 +4,9 @@ "cell_type": "code", "execution_count": 1, "id": "6d93e33a-b89e-4e56-bfb7-5a8a0a232053", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "from premise import *\n", @@ -16,7 +18,9 @@ "cell_type": "code", "execution_count": 2, "id": "10b37313-f780-4102-a6d4-7a813dad9d3f", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "scenarios = [\n", @@ -47,13 +51,15 @@ "cell_type": "code", "execution_count": 3, "id": "bc61f1aa-81d4-4a83-b7c5-0b10ad1a5b65", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "premise v.(1, 7, 1)\n", + "premise v.(1, 7, 5)\n", "+------------------------------------------------------------------+\n", "| Warning |\n", "+------------------------------------------------------------------+\n", @@ -110,17 +116,19 @@ " #source_type=\"ecospold\",\n", " #source_file_path=f\"/Users/romain/Documents/ecoinvent 3.9.1_cutoff_ecoSpold02/datasets\", # <-- this is NEW\n", " key='tUePmX_S5B8ieZkkM7WUU2CnO8SmShwmAeWK9x2rTFo=',\n", - " system_model=\"consequential\",\n", - " use_multiprocessing=False\n", + " #system_model=\"consequential\",\n", + " #use_multiprocessing=False\n", " #system_args=combinations[0]\n", ")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "c7996c75-e3e7-42ba-9ecb-c016b6462109", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [ { "name": "stdout", @@ -129,7 +137,7 @@ "`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 4.56 seconds\n", + "Extracted 1 worksheets in 4.53 seconds\n", "Migrating to 3.8 first\n", "Applying strategy: migrate_datasets\n", "Applying strategy: migrate_exchanges\n", @@ -139,7 +147,7 @@ "Applying strategy: migrate_exchanges\n", "Done!\n", "Done!\n", - "Extracted 1 worksheets in 4.96 seconds\n", + "Extracted 1 worksheets in 4.51 seconds\n", "Migrating to 3.8 first\n", "Applying strategy: migrate_datasets\n", "Applying strategy: migrate_exchanges\n", @@ -149,14 +157,8 @@ "Applying strategy: migrate_exchanges\n", "Done!\n", "Done!\n", - "Extracted 1 worksheets in 4.91 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", + "\n" ] } ], @@ -174,12 +176,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "a85ca090-8d49-42c2-8b21-ffc69fabc12d", - "metadata": {}, - "outputs": [], + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Building superstructure database...\n", + "Dropped 0 duplicate(s).\n", + "Scenario difference file exported to /Users/romain/GitHub/premise/dev/export/scenario diff files!\n", + "Database test already exists: it will be overwritten.\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:50\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Title: Writing activities to SQLite3 database:\n", + " Started: 10/09/2023 10:04:44\n", + " Finished: 10/09/2023 10:05:34\n", + " Total time elapsed: 00:00:50\n", + " CPU %: 95.40\n", + " Memory %: 24.03\n", + "Created database: test\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" + ] + } + ], "source": [ - "ndb.write_db_to_brightway()" + "ndb.write_superstructure_db_to_brightway(\"test\")" ] }, { diff --git a/premise/data/consequential/leadtimes.yaml b/premise/data/consequential/leadtimes.yaml index d0107f0a..b2cce2f1 100644 --- a/premise/data/consequential/leadtimes.yaml +++ b/premise/data/consequential/leadtimes.yaml @@ -37,6 +37,8 @@ Solar PV Residential: 2 Wind Onshore: 2 Wind Offshore: 3 Wave: 3 +Storage, Hydrogen: 3 +Storage, Flow Battery: 3 diesel: 3 gasoline: 3 diesel, synthetic, from wood: 3 diff --git a/premise/ecoinvent_modification.py b/premise/ecoinvent_modification.py index 1f261504..71be8813 100644 --- a/premise/ecoinvent_modification.py +++ b/premise/ecoinvent_modification.py @@ -1347,6 +1347,11 @@ def write_superstructure_db_to_brightway( modified_datasets=self.modified_datasets, ) + if hasattr(self, "datapackages"): + list_scenarios = create_scenario_list(self.scenarios, self.datapackages) + else: + list_scenarios = create_scenario_list(self.scenarios) + self.database = generate_superstructure_db( origin_db=self.database, scenarios=self.scenarios, @@ -1354,6 +1359,7 @@ def write_superstructure_db_to_brightway( filepath=filepath, version=self.version, format=format, + scenario_list=list_scenarios, ) write_brightway2_database( diff --git a/premise/export.py b/premise/export.py index 284c22c5..d42fa111 100644 --- a/premise/export.py +++ b/premise/export.py @@ -861,7 +861,7 @@ def generate_scenario_difference_file( def generate_superstructure_db( - origin_db, scenarios, db_name, filepath, version, format="excel" + origin_db, scenarios, db_name, filepath, version, scenario_list, format="excel", ) -> List[dict]: """ Build a superstructure database from a list of databases @@ -878,7 +878,11 @@ def generate_superstructure_db( # create the dataframe df, new_db, _ = generate_scenario_difference_file( - origin_db=origin_db, scenarios=scenarios, db_name=db_name, version=version + origin_db=origin_db, + scenarios=scenarios, + db_name=db_name, + version=version, + scenario_list=scenario_list ) # remove unneeded columns "to unit"