From f34d894b04c821c56874ae2d26f013a1f6856ccc Mon Sep 17 00:00:00 2001 From: romainsacchi Date: Wed, 15 May 2024 21:15:42 -0400 Subject: [PATCH] Version bump --- dev/Untitled.ipynb | 135 ++++++++++++++++++++++++++++++++++++++++ dev/test_premise.ipynb | 53 ++++++++++++---- premise/__init__.py | 2 +- premise/new_database.py | 18 ++++++ 4 files changed, 195 insertions(+), 13 deletions(-) diff --git a/dev/Untitled.ipynb b/dev/Untitled.ipynb index d95a77b6..cea91032 100644 --- a/dev/Untitled.ipynb +++ b/dev/Untitled.ipynb @@ -1,5 +1,140 @@ { "cells": [ + { + "cell_type": "code", + "execution_count": 9, + "id": "9072abc3-ba48-4b33-945e-7696686bb30d", + "metadata": {}, + "outputs": [], + "source": [ + "import bw2data\n", + "bw2data.projects.set_current(\"ei39\")" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "fbe36131-cd47-4a6a-ba7c-bf85b170740c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Brightway2 projects manager with 3 objects:\n", + "\tdefault\n", + "\tei39\n", + "\tnew4\n", + "Use `projects.report()` to get a report on all projects." + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "bw2data.projects" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "2969f3c0-1073-44ef-9beb-5e31989b2c2b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n", + "Vacuuming database \n" + ] + } + ], + "source": [ + "import bw2data\n", + "bw2data.projects.set_current(\"ei39\")\n", + "\n", + "dbs = [\n", + " db for db in bw2data.databases if db not in [\n", + " \"biosphere3\",\n", + " \"ecoinvent 3.9.1 cutoff\"\n", + " ]\n", + "]\n", + "for db in dbs:\n", + " del bw2data.databases[db]" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "c23776c7-6f4b-4d34-bb2a-fa148340c62c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['biosphere3', 'ecoinvent 3.9.1 cutoff']" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(bw2data.databases)" + ] + }, { "cell_type": "code", "execution_count": 1, diff --git a/dev/test_premise.ipynb b/dev/test_premise.ipynb index 7818036c..f5c255b2 100644 --- a/dev/test_premise.ipynb +++ b/dev/test_premise.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 4, + "execution_count": 1, "id": "df75ca49-bab1-486b-9a5e-4bf7e4259180", "metadata": {}, "outputs": [], @@ -74,7 +74,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "premise v.(2, 1, 0, 'dev2')\n", + "premise v.(2, 1, 0)\n", "+------------------------------------------------------------------+\n", "| Warning |\n", "+------------------------------------------------------------------+\n", @@ -116,7 +116,12 @@ "- Importing additional inventories\n", "\n", "//////////////// IMPORTING USER-DEFINED INVENTORIES ////////////////\n", - "Extracted 1 worksheets in 0.81 seconds\n", + "Extracted 1 worksheets in 0.36 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", "The following datasets to import already exist in the source database. They will not be imported\n", @@ -246,19 +251,42 @@ "| electricity production, photov | electricity, low voltage | GB | lci-PV.xlsx |\n", "| electricity production, photov | electricity, low voltage | US | lci-PV.xlsx |\n", "+--------------------------------+--------------------------------+----------+-------------+\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", "- Fetching IAM data\n", "Done!\n", "#############################################################################################################\n", - "3.8 brightway superstructure\n" + "3.9.1 brightway matrices\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "Updating: fuels: 38%|██████▌ | 5/13 [00:50<01:20, 10.04s/it]" + "Processing scenarios: 100%|█████████████| 2/2 [03:16<00:00, 98.22s/it]\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Done!\n", + "\n", + "Write new database(s) to matrix.\n", + "Running all checks...\n", + "Minor anomalies found: check the change report.\n", + "Matrices saved in /Users/romain/GitHub/premise/dev/export/remind/SSP2-Base/2050.\n", + "Running all checks...\n", + "Minor anomalies found: check the change report.\n", + "Matrices saved in /Users/romain/GitHub/premise/dev/export/image/SSP2-RCP19/2048.\n", + "Generate scenario report.\n", + "Report saved under /Users/romain/GitHub/premise/dev/export/scenario_report.\n", + "Generate change report.\n" ] } ], @@ -277,14 +305,14 @@ " #\"3.6\",\n", " #\"3.7\",\n", " #\"3.7.1\",\n", - " \"3.8\",\n", + " #\"3.8\",\n", " #\"3.9\",\n", " \"3.9.1\"\n", "\n", " ]:\n", " \n", " if ei not in [\"3.9\", \"3.9.1\"]:\n", - " bw2data.projects.set_current(\"ei38\")\n", + " bw2data.projects.set_current(\"new4\")\n", " else:\n", " bw2data.projects.set_current(\"ei39\")\n", "\n", @@ -294,8 +322,8 @@ " ]:\n", " for export in [\n", " #\"brightway\",\n", - " \"superstructure\",\n", - " \"simapro\",\n", + " #\"superstructure\",\n", + " #\"simapro\",\n", " \"matrices\",\n", " \"datapackage\"\n", " ]:\n", @@ -309,7 +337,6 @@ " key='tUePmX_S5B8ieZkkM7WUU2CnO8SmShwmAeWK9x2rTFo=',\n", " system_model=model,\n", " system_args=combinations[0],\n", - " use_multiprocessing=False,\n", " additional_inventories= [ # <-- this is NEW\n", " {\"filepath\": \"/Users/romain/GitHub/premise/premise/data/additional_inventories/lci-PV.xlsx\", \"ecoinvent version\": \"3.7\"}, # <-- this is NEW\n", " ] # <-- this is NEW\n", @@ -341,7 +368,9 @@ " else:\n", " ndb.write_datapackage(name=\"test\")\n", " u = Unfold(\"export/datapackage/test.zip\")\n", - " u.unfold(dependencies={\"ecoinvent\": f\"ecoinvent {ei} {model}\", \"biosphere3\": \"biosphere3\"}, superstructure=True)" + " u.unfold(dependencies={\"ecoinvent\": f\"ecoinvent {ei} {model}\", \"biosphere3\": \"biosphere3\"}, superstructure=True)\n", + "\n", + " del ndb" ] }, { @@ -401,7 +430,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.13" + "version": "3.11.8" } }, "nbformat": 4, diff --git a/premise/__init__.py b/premise/__init__.py index 5b04a317..c38fccfa 100644 --- a/premise/__init__.py +++ b/premise/__init__.py @@ -1,5 +1,5 @@ __all__ = ("NewDatabase", "clear_cache", "get_regions_definition") -__version__ = (2, 1, 0, "dev8") +__version__ = (2, 1, 0) from premise.new_database import NewDatabase diff --git a/premise/new_database.py b/premise/new_database.py index 6e8968e1..549c59c6 100644 --- a/premise/new_database.py +++ b/premise/new_database.py @@ -972,6 +972,9 @@ def write_superstructure_db_to_brightway( for scenario in self.scenarios: del scenario["database"] + if "applied functions" in scenario: + del scenario["applied functions"] + def write_db_to_brightway(self, name: [str, List[str]] = None): """ Register the new database into an open brightway project. @@ -1023,6 +1026,9 @@ def write_db_to_brightway(self, name: [str, List[str]] = None): # delete the database from the scenario del scenario["database"] + if "applied functions" in scenario: + del scenario["applied functions"] + # generate scenario report self.generate_scenario_report() # generate change report from logs @@ -1083,6 +1089,9 @@ def scenario_name(scenario): ) Export(scenario, filepath[s], self.version).export_db_to_matrices() + if "applied functions" in scenario: + del scenario["applied functions"] + # generate scenario report self.generate_scenario_report() # generate change report from logs @@ -1115,6 +1124,9 @@ def write_db_to_simapro(self, filepath: str = None): Export(scenario, filepath, self.version).export_db_to_simapro() del scenario["database"] + if "applied functions" in scenario: + del scenario["applied functions"] + # generate scenario report self.generate_scenario_report() # generate change report from logs @@ -1149,6 +1161,9 @@ def write_db_to_olca(self, filepath: str = None): ) del scenario["database"] + if "applied functions" in scenario: + del scenario["applied functions"] + # generate scenario report self.generate_scenario_report() # generate change report from logs @@ -1189,6 +1204,9 @@ def write_datapackage( for scenario in self.scenarios: del scenario["database"] + if "applied functions" in scenario: + del scenario["applied functions"] + cached_inventories.extend(extra_inventories) list_scenarios = ["original"] + list_scenarios