Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Oct 15, 2024
2 parents b0fb808 + 2f9f4d3 commit d3f0612
Show file tree
Hide file tree
Showing 5 changed files with 417 additions and 115 deletions.
2 changes: 1 addition & 1 deletion dev/Untitled.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5227,7 +5227,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.10.13"
}
},
"nbformat": 4,
Expand Down
224 changes: 129 additions & 95 deletions dev/Untitled1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
"execution_count": 1,
"id": "5018b7ee-0169-49d7-9455-2f1aea562e9e",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"USER_DATA_BASE_DIR: test\n"
]
}
],
"source": [
"from premise import *\n",
"from datapackage import Package\n",
Expand All @@ -28,14 +36,22 @@
"execution_count": 3,
"id": "e408d76b-8288-4661-9089-f8c3f6191743",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Inventory cache cleared!\n"
]
}
],
"source": [
"# clear_inventory_cache()"
"clear_inventory_cache()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"id": "bee86950-ac96-49e0-8a9c-43920ae26096",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -78,60 +94,11 @@
"Hide these messages?\n",
"NewDatabase(..., quiet=True)\n",
"- Extracting source database\n",
"Cannot find cached database. Will create one now for next time...\n",
"Getting activity data\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|█████████████████████████████████| 23523/23523 [00:00<00:00, 384646.56it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Adding exchange data to activities\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|████████████████████████████████| 743409/743409 [00:32<00:00, 23010.63it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Filling out exchange data\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|███████████████████████████████████| 23523/23523 [00:02<00:00, 9800.02it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Set missing location of datasets to global scope.\n",
"Set missing location of production exchanges to scope of dataset.\n",
"Correct missing location of technosphere exchanges.\n",
"Correct missing flow categories for biosphere exchanges\n",
"Remove empty exchanges.\n",
"Remove uncertainty data.\n",
"- Extracting inventories\n",
"Cannot find cached inventories. Will create them now for next time...\n",
"Importing default inventories...\n",
"\n",
"Extracted 1 worksheets in 0.11 seconds\n",
"Extracted 1 worksheets in 0.09 seconds\n",
"Migrating to 3.8 first\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n",
Expand Down Expand Up @@ -201,7 +168,7 @@
"Extracted 1 worksheets in 0.01 seconds\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n",
"Extracted 1 worksheets in 0.29 seconds\n",
"Extracted 1 worksheets in 0.30 seconds\n",
"Migrating to 3.8 first\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n",
Expand Down Expand Up @@ -364,15 +331,15 @@
"Extracted 1 worksheets in 0.02 seconds\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n",
"Extracted 1 worksheets in 0.00 seconds\n",
"Extracted 1 worksheets in 0.01 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",
"Extracted 5 worksheets in 0.13 seconds\n",
"Extracted 5 worksheets in 0.16 seconds\n",
"Migrating to 3.8 first\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n",
Expand Down Expand Up @@ -428,7 +395,7 @@
"Applying strategy: migrate_exchanges\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n",
"Extracted 1 worksheets in 0.04 seconds\n",
"Extracted 1 worksheets in 0.03 seconds\n",
"Migrating to 3.8 first\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n",
Expand Down Expand Up @@ -461,34 +428,34 @@
"Extracted 1 worksheets in 0.04 seconds\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n",
"Extracted 1 worksheets in 0.07 seconds\n",
"Extracted 1 worksheets in 0.02 seconds\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n",
"Extracted 19 worksheets in 0.29 seconds\n",
"Extracted 19 worksheets in 0.30 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",
"Extracted 1 worksheets in 1.43 seconds\n",
"Extracted 1 worksheets in 0.21 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",
"Extracted 1 worksheets in 0.15 seconds\n",
"Extracted 1 worksheets in 0.16 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",
"Extracted 1 worksheets in 0.81 seconds\n",
"Extracted 1 worksheets in 0.80 seconds\n",
"Migrating to 3.8 first\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n",
Expand All @@ -499,24 +466,12 @@
"Extracted 1 worksheets in 0.03 seconds\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n",
"Extracted 1 worksheets in 0.01 seconds\n",
"Extracted 1 worksheets in 0.02 seconds\n",
"Extracted 1 worksheets in 0.02 seconds\n",
"Data cached. It is advised to restart your workflow at this point.\n",
"This allows premise to use the cached data instead, which results in\n",
"a faster workflow.\n",
"- Fetching IAM data\n",
"The following variables are missing from the IAM file:\n",
"+-------------------------------------+\n",
"| Variable |\n",
"+-------------------------------------+\n",
"| ES|Transport|Pass|Road|Bus|Gasoline |\n",
"+-------------------------------------+\n",
"The following variables are missing from the IAM file:\n",
"+-------------------------------------+\n",
"| Variable |\n",
"+-------------------------------------+\n",
"| ES|Transport|Pass|Road|Bus|Gasoline |\n",
"+-------------------------------------+\n",
"Done!\n"
]
}
Expand All @@ -529,16 +484,18 @@
" #{\"model\":\"image\", \"pathway\":\"SSP2-Base\", \"year\":2020},\n",
" #{\"model\":\"image\", \"pathway\":\"SSP2-Base\", \"year\":2050},\n",
" #{\"model\":\"remind\", \"pathway\":\"SSP5-NDC\", \"year\":2050},\n",
" {\"model\":\"remind\", \"pathway\":\"SSP5-NDC\", \"year\":2100},\n",
" #{\"model\":\"image\", \"pathway\":\"SSP2-Base\", \"year\":2060},\n",
" #{\"model\":\"remind\", \"pathway\":\"SSP5-NDC\", \"year\":2100},\n",
" {\"model\":\"image\", \"pathway\":\"SSP2-Base\", \"year\":2050},\n",
" {\"model\":\"image\", \"pathway\":\"SSP2-Base\", \"year\":2060},\n",
" #{\"model\":\"image\", \"pathway\":\"SSP2-Base\", \"year\":2050},\n",
" #{\"model\":\"image\", \"pathway\":\"SSP2-Base\", \"year\":2050},\n",
" ],\n",
" source_db=\"ecoinvent-3.10-cutoff\", # <-- name of the database in the BW2 project. Must be a string.\n",
" source_version=\"3.10\", # <-- version of ecoinvent. Can be \"3.5\", \"3.6\", \"3.7\" or \"3.8\". Must be a string.\n",
" key=\"tUePmX_S5B8ieZkkM7WUU2CnO8SmShwmAeWK9x2rTFo=\",\n",
" biosphere_name=\"biosphere3\",\n",
" biosphere_name=\"ecoinvent-3.10-biosphere\",\n",
" keep_imports_uncertainty=True\n",
" \n",
" #external_scenarios=[FE2050,]\n",
" #use_multiprocessing=True,\n",
" #system_model=\"consequential\"\n",
Expand All @@ -548,56 +505,133 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"id": "a324c189-26bd-4a65-885c-bba4683e9ed1",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Processing scenarios: 0%| | 0/1 [00:00<?, ?it/s]"
"Processing scenarios for sector 'cement': 100%|█| 2/2 [00:21<00:00, 10"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'uncertainty type': 0, 'loc': 0.780778322, 'scale': nan, 'amount': 0.780778322, 'pedigree': {'reliability': 4, 'completeness': 4, 'temporal correlation': 5, 'geographical correlation': 2, 'further technological correlation': 4}, 'type': 'biosphere', 'production volume': 0.0, 'input': ('biosphere3', '2404b41a-2eed-4e9d-8ab6-783946fdf5d6'), 'name': 'Water', 'unit': 'cubic meter', 'database': 'biosphere3', 'categories': ('water',), 'shape': nan, 'minimum': nan, 'maximum': nan}\n",
"0.80825\n",
"{'uncertainty type': 0, 'loc': 0.029221678, 'scale': nan, 'amount': 0.029221678, 'pedigree': {'reliability': 2, 'completeness': 2, 'temporal correlation': 4, 'geographical correlation': 1, 'further technological correlation': 1}, 'type': 'biosphere', 'production volume': 0.0, 'input': ('biosphere3', '075e433b-4be4-448e-9510-9a5029c1ce94'), 'name': 'Water', 'unit': 'cubic meter', 'database': 'biosphere3', 'categories': ('air',), 'shape': nan, 'minimum': nan, 'maximum': nan}\n",
"0.00175\n",
"{'uncertainty type': 0, 'loc': 0.780778322, 'scale': nan, 'amount': 0.780778322, 'pedigree': {'reliability': 4, 'completeness': 4, 'temporal correlation': 5, 'geographical correlation': 2, 'further technological correlation': 4}, 'type': 'biosphere', 'production volume': 0.0, 'input': ('biosphere3', '2404b41a-2eed-4e9d-8ab6-783946fdf5d6'), 'name': 'Water', 'unit': 'cubic meter', 'database': 'biosphere3', 'categories': ('water',), 'shape': nan, 'minimum': nan, 'maximum': nan}\n",
"0.80825\n",
"{'uncertainty type': 0, 'loc': 0.029221678, 'scale': nan, 'amount': 0.029221678, 'pedigree': {'reliability': 2, 'completeness': 2, 'temporal correlation': 4, 'geographical correlation': 1, 'further technological correlation': 1}, 'type': 'biosphere', 'production volume': 0.0, 'input': ('biosphere3', '075e433b-4be4-448e-9510-9a5029c1ce94'), 'name': 'Water', 'unit': 'cubic meter', 'database': 'biosphere3', 'categories': ('air',), 'shape': nan, 'minimum': nan, 'maximum': nan}\n",
"0.00175\n"
"Done!\n",
"\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"ndb.update(\"cement\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "b7a838c3-b655-4918-ae99-40cb24d22659",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Running all checks...\n",
"Minor anomalies found: check the change report.\n",
"Running all checks...\n",
"Minor anomalies found: check the change report.\n",
"Building superstructure database...\n",
"Dropped 20760 duplicate(s).\n",
"Scenario difference file exported to /Users/romain/Github/premise/dev/export/scenario diff files!\n",
"Running all checks...\n",
"Minor anomalies found: check the change report.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Processing scenarios: 100%|█████████████| 1/1 [00:21<00:00, 21.46s/it]"
"Writing activities to SQLite3 database:\n",
"0% [##############################] 100% | ETA: 00:00:00\n",
"Total time elapsed: 00:00:23\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done!\n",
"\n"
"Title: Writing activities to SQLite3 database:\n",
" Started: 10/03/2024 13:01:12\n",
" Finished: 10/03/2024 13:01:36\n",
" Total time elapsed: 00:00:23\n",
" CPU %: 95.90\n",
" Memory %: 14.96\n",
"Created database: super_db_03-10-2024\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_superstructure_db_to_brightway()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "dc7e4a89-9bd4-4e25-93db-1ec2b9c7de6d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Write new database(s) to Brightway.\n",
"Running all checks...\n",
"Minor anomalies found: check the change report.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
"Writing activities to SQLite3 database:\n",
"0% [##############################] 100% | ETA: 00:00:00\n",
"Total time elapsed: 00:00:24\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Title: Writing activities to SQLite3 database:\n",
" Started: 10/03/2024 12:05:52\n",
" Finished: 10/03/2024 12:06:17\n",
" Total time elapsed: 00:00:24\n",
" CPU %: 94.20\n",
" Memory %: 13.59\n",
"Created database: cement_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.update(\"electricity\")"
"ndb.write_db_to_brightway(\"cement_test\")"
]
},
{
Expand Down Expand Up @@ -3629,7 +3663,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
"version": "3.10.13"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit d3f0612

Please sign in to comment.