diff --git a/dev/generate datapackages.ipynb b/dev/generate datapackages.ipynb index 7fdab39..60b141e 100644 --- a/dev/generate datapackages.ipynb +++ b/dev/generate datapackages.ipynb @@ -78,17 +78,17 @@ "- Extracting source database\n", "- Extracting inventories\n", "- Fetching IAM data\n", - "Reading /Users/romain/Library/CloudStorage/Dropbox/Notebooks/IAM-ecoinvent/new image/full data/image_SSP2-RCP19.xlsx as excel file\n", - "Reading /Users/romain/Library/CloudStorage/Dropbox/Notebooks/IAM-ecoinvent/new image/full data/image_SSP2-RCP19.xlsx as excel file\n", - "Reading /Users/romain/Library/CloudStorage/Dropbox/Notebooks/IAM-ecoinvent/new image/full data/image_SSP2-RCP19.xlsx as excel file\n", - "Reading /Users/romain/Library/CloudStorage/Dropbox/Notebooks/IAM-ecoinvent/new image/full data/image_SSP2-RCP19.xlsx as excel file\n", - "Reading /Users/romain/Library/CloudStorage/Dropbox/Notebooks/IAM-ecoinvent/new image/full data/image_SSP2-RCP19.xlsx as excel file\n", - "Reading /Users/romain/Library/CloudStorage/Dropbox/Notebooks/IAM-ecoinvent/new image/full data/image_SSP2-RCP19.xlsx as excel file\n", - "Reading /Users/romain/Library/CloudStorage/Dropbox/Notebooks/IAM-ecoinvent/new image/full data/image_SSP2-RCP19.xlsx as excel file\n", - "Reading /Users/romain/Library/CloudStorage/Dropbox/Notebooks/IAM-ecoinvent/new image/full data/image_SSP2-RCP19.xlsx as excel file\n", - "Reading /Users/romain/Library/CloudStorage/Dropbox/Notebooks/IAM-ecoinvent/new image/full data/image_SSP2-RCP19.xlsx as excel file\n", - "Reading /Users/romain/Library/CloudStorage/Dropbox/Notebooks/IAM-ecoinvent/new image/full data/image_SSP2-RCP19.xlsx as excel file\n", - "Reading /Users/romain/Library/CloudStorage/Dropbox/Notebooks/IAM-ecoinvent/new image/full data/image_SSP2-RCP19.xlsx as excel file\n", + "Reading /Users/romain/Dropbox/Notebooks/IAM-ecoinvent/new image/full data/image_SSP2-RCP19.xlsx as excel fileReading /Users/romain/Dropbox/Notebooks/IAM-ecoinvent/new image/full data/image_SSP2-RCP19.xlsx as excel file\n", + "\n", + "Reading /Users/romain/Dropbox/Notebooks/IAM-ecoinvent/new image/full data/image_SSP2-RCP19.xlsx as excel file\n", + "Reading /Users/romain/Dropbox/Notebooks/IAM-ecoinvent/new image/full data/image_SSP2-RCP19.xlsx as excel file\n", + "Reading /Users/romain/Dropbox/Notebooks/IAM-ecoinvent/new image/full data/image_SSP2-RCP19.xlsx as excel file\n", + "Reading /Users/romain/Dropbox/Notebooks/IAM-ecoinvent/new image/full data/image_SSP2-RCP19.xlsx as excel file\n", + "Reading /Users/romain/Dropbox/Notebooks/IAM-ecoinvent/new image/full data/image_SSP2-RCP19.xlsx as excel file\n", + "Reading /Users/romain/Dropbox/Notebooks/IAM-ecoinvent/new image/full data/image_SSP2-RCP19.xlsx as excel file\n", + "Reading /Users/romain/Dropbox/Notebooks/IAM-ecoinvent/new image/full data/image_SSP2-RCP19.xlsx as excel file\n", + "Reading /Users/romain/Dropbox/Notebooks/IAM-ecoinvent/new image/full data/image_SSP2-RCP19.xlsx as excel file\n", + "Reading /Users/romain/Dropbox/Notebooks/IAM-ecoinvent/new image/full data/image_SSP2-RCP19.xlsx as excel file\n", "Done!\n" ] } @@ -97,12 +97,13 @@ "from premise import *\n", "import bw2data\n", "from datapackage import Package\n", + "\n", "bw2data.projects.set_current(\"ei39\")\n", "ndb = PathwaysDataPackage(\n", " scenarios=[\n", " {\"model\": \"image\",\n", " \"pathway\": \"SSP2-RCP19\",\n", - " \"filepath\": \"/Users/romain/Library/CloudStorage/Dropbox/Notebooks/IAM-ecoinvent/new image/full data\"\n", + " \"filepath\": \"/Users/romain/Dropbox/Notebooks/IAM-ecoinvent/new image/full data\"\n", " },\n", " ],\n", " years=[2005, 2010, 2020, 2030, 2040, 2050, 2060, 2070, 2080, 2090, 2100],\n", @@ -130,7 +131,126 @@ "name": "stderr", "output_type": "stream", "text": [ - "Updating: external: 91%|██████████▉ | 10/11 [35:31<03:33, 213.11s/it]\n" + "Updating: metals: 55%|████████▏ | 6/11 [26:47<35:21, 424.38s/it]" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal rare earth carbonate concentrate not found in alternative names. Skipping transport.\n", + "Metal rare earth carbonate concentrate not found in alternative names. Skipping transport.\n", + "Metal rare earth carbonate concentrate not found in alternative names. Skipping transport.\n", + "Metal rare earth carbonate concentrate not found in alternative names. Skipping transport.\n", + "Metal rare earth carbonate concentrate not found in alternative names. Skipping transport.\n", + "Metal rare earth carbonate concentrate not found in alternative names. Skipping transport.\n", + "Metal rare earth carbonate concentrate not found in alternative names. Skipping transport.\n", + "Metal rare earth carbonate concentrate not found in alternative names. Skipping transport.\n", + "Metal rare earth carbonate concentrate not found in alternative names. Skipping transport.\n", + "Metal rare earth carbonate concentrate not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal titanium tetrachloride not found in alternative names. Skipping transport.\n", + "Metal titanium tetrachloride not found in alternative names. Skipping transport.\n", + "Metal titanium tetrachloride not found in alternative names. Skipping transport.\n", + "Metal titanium tetrachloride not found in alternative names. Skipping transport.\n", + "Metal titanium tetrachloride not found in alternative names. Skipping transport.\n", + "Metal titanium sponge not found in alternative names. Skipping transport.\n", + "Metal titanium sponge not found in alternative names. Skipping transport.\n", + "Metal titanium sponge not found in alternative names. Skipping transport.\n", + "Metal titanium sponge not found in alternative names. Skipping transport.\n", + "Metal titanium sponge not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal spodumene not found in alternative names. Skipping transport.\n", + "Metal rare earth carbonate concentrate not found in alternative names. Skipping transport.\n", + "Metal rare earth carbonate concentrate not found in alternative names. Skipping transport.\n", + "Metal rare earth carbonate concentrate not found in alternative names. Skipping transport.\n", + "Metal rare earth carbonate concentrate not found in alternative names. Skipping transport.\n", + "Metal rare earth carbonate concentrate not found in alternative names. Skipping transport.\n", + "Metal rare earth carbonate concentrate not found in alternative names. Skipping transport.\n", + "Metal rare earth carbonate concentrate not found in alternative names. Skipping transport.\n", + "Metal rare earth carbonate concentrate not found in alternative names. Skipping transport.\n", + "Metal rare earth carbonate concentrate not found in alternative names. Skipping transport.\n", + "Metal rare earth carbonate concentrate not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal sand not found in alternative names. Skipping transport.\n", + "Metal titanium tetrachloride not found in alternative names. Skipping transport.\n", + "Metal titanium tetrachloride not found in alternative names. Skipping transport.\n", + "Metal titanium tetrachloride not found in alternative names. Skipping transport.\n", + "Metal titanium tetrachloride not found in alternative names. Skipping transport.\n", + "Metal titanium tetrachloride not found in alternative names. Skipping transport.\n", + "Metal titanium sponge not found in alternative names. Skipping transport.\n", + "Metal titanium sponge not found in alternative names. Skipping transport.\n", + "Metal titanium sponge not found in alternative names. Skipping transport.\n", + "Metal titanium sponge not found in alternative names. Skipping transport.\n", + "Metal titanium sponge not found in alternative names. Skipping transport.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Updating: external: 91%|█████████ | 10/11 [2:32:34<15:15, 915.42s/it]\n" ] }, { @@ -150,9 +270,9 @@ "Remove uncertainty data.\n", "Extracted 1 worksheets in 0.02 seconds\n", "Remove uncertainty data.\n", - "Extracted 1 worksheets in 0.02 seconds\n", + "Extracted 1 worksheets in 0.03 seconds\n", "Remove uncertainty data.\n", - "Extracted 1 worksheets in 0.02 seconds\n", + "Extracted 1 worksheets in 0.03 seconds\n", "Remove uncertainty data.\n", "Extracted 1 worksheets in 0.02 seconds\n", "Remove uncertainty data.\n", @@ -169,20 +289,28 @@ "Anomalies found: check the change report.\n", "Running all checks...\n", "Anomalies found: check the change report.\n", - "Matrices saved in /Users/romain/GitHub/pathways/dev/pathways/inventories/image/SSP2-RCP19/2030.\n", - "Matrices saved in /Users/romain/GitHub/pathways/dev/pathways/inventories/image/SSP2-RCP19/2040.\n", - "Matrices saved in /Users/romain/GitHub/pathways/dev/pathways/inventories/image/SSP2-RCP19/2050.\n", - "Matrices saved in /Users/romain/GitHub/pathways/dev/pathways/inventories/image/SSP2-RCP19/2005.\n", - "Matrices saved in /Users/romain/GitHub/pathways/dev/pathways/inventories/image/SSP2-RCP19/2080.\n", - "Matrices saved in /Users/romain/GitHub/pathways/dev/pathways/inventories/image/SSP2-RCP19/2070.\n", - "Matrices saved in /Users/romain/GitHub/pathways/dev/pathways/inventories/image/SSP2-RCP19/2060.\n", - "Matrices saved in /Users/romain/GitHub/pathways/dev/pathways/inventories/image/SSP2-RCP19/2010.\n", - "Matrices saved in /Users/romain/GitHub/pathways/dev/pathways/inventories/image/SSP2-RCP19/2090.\n", + "Running all checks...\n", + "Anomalies found: check the change report.\n", + "Running all checks...\n", + "Anomalies found: check the change report.\n", + "Running all checks...\n", + "Anomalies found: check the change report.\n", + "Running all checks...\n", + "Anomalies found: check the change report.\n", + "Matrices saved in /Users/romain/Github/pathways/dev/pathways/inventories/image/SSP2-RCP19/2030.\n", + "Matrices saved in /Users/romain/Github/pathways/dev/pathways/inventories/image/SSP2-RCP19/2040.\n", + "Matrices saved in /Users/romain/Github/pathways/dev/pathways/inventories/image/SSP2-RCP19/2050.\n", + "Matrices saved in /Users/romain/Github/pathways/dev/pathways/inventories/image/SSP2-RCP19/2005.\n", + "Matrices saved in /Users/romain/Github/pathways/dev/pathways/inventories/image/SSP2-RCP19/2080.\n", + "Matrices saved in /Users/romain/Github/pathways/dev/pathways/inventories/image/SSP2-RCP19/2060.\n", + "Matrices saved in /Users/romain/Github/pathways/dev/pathways/inventories/image/SSP2-RCP19/2010.\n", + "Matrices saved in /Users/romain/Github/pathways/dev/pathways/inventories/image/SSP2-RCP19/2090.\n", + "Matrices saved in /Users/romain/Github/pathways/dev/pathways/inventories/image/SSP2-RCP19/2070.\n", "Generate scenario report.\n", - "Report saved under /Users/romain/GitHub/pathways/dev/export/scenario_report.\n", + "Report saved under /Users/romain/Github/pathways/dev/export/scenario_report.\n", "Generate change report.\n", - "Report saved under /Users/romain/GitHub/pathways/dev.\n", - "Data package saved at /Users/romain/GitHub/pathways/dev/pathways/image-SSP2-RCP19.zip\n" + "Report saved under /Users/romain/Github/pathways/dev.\n", + "Data package saved at /Users/romain/Github/pathways/dev/pathways/image-SSP2-RCP19.zip\n" ] } ], @@ -214,7 +342,7 @@ ], "source": [ "from pathways import Pathways\n", - "p = Pathways(datapackage=\"./image-SSP2-RCP19/datapackage.json\")" + "p = Pathways(datapackage=\"/Users/romain/Downloads/image-SSP2-RCP19/datapackage.json\")" ] }, { @@ -237,7 +365,7 @@ "output_type": "stream", "text": [ "0% [##########################] 100% | ETA: 00:00:00\n", - "Total time elapsed: 00:08:59\n" + "Total time elapsed: 00:06:06\n" ] }, { @@ -252,7 +380,7 @@ "output_type": "stream", "text": [ "0% [##########################] 100% | ETA: 00:00:00\n", - "Total time elapsed: 00:09:20\n" + "Total time elapsed: 00:06:30\n" ] }, { @@ -269,7 +397,7 @@ "output_type": "stream", "text": [ "0% [##########################] 100% | ETA: 00:00:00\n", - "Total time elapsed: 00:09:14\n" + "Total time elapsed: 00:06:22\n" ] }, { @@ -286,7 +414,7 @@ "output_type": "stream", "text": [ "0% [##########################] 100% | ETA: 00:00:00\n", - "Total time elapsed: 00:06:54\n" + "Total time elapsed: 00:04:45\n" ] }, { @@ -303,7 +431,7 @@ "output_type": "stream", "text": [ "0% [##########################] 100% | ETA: 00:00:00\n", - "Total time elapsed: 00:04:35\n" + "Total time elapsed: 00:03:08\n" ] }, { @@ -320,7 +448,7 @@ "output_type": "stream", "text": [ "0% [##########################] 100% | ETA: 00:00:00\n", - "Total time elapsed: 00:04:49\n" + "Total time elapsed: 00:03:25\n" ] }, { @@ -335,7 +463,7 @@ "output_type": "stream", "text": [ "0% [##########################] 100% | ETA: 00:00:00\n", - "Total time elapsed: 00:06:30\n" + "Total time elapsed: 00:04:29\n" ] }, { @@ -350,7 +478,7 @@ "output_type": "stream", "text": [ "0% [##########################] 100% | ETA: 00:00:00\n", - "Total time elapsed: 00:08:32\n" + "Total time elapsed: 00:05:29\n" ] }, { @@ -365,7 +493,7 @@ "output_type": "stream", "text": [ "0% [##########################] 100% | ETA: 00:00:00\n", - "Total time elapsed: 00:08:39\n" + "Total time elapsed: 00:05:31\n" ] }, { @@ -380,7 +508,7 @@ "output_type": "stream", "text": [ "0% [##########################] 100% | ETA: 00:00:00\n", - "Total time elapsed: 00:09:35\n" + "Total time elapsed: 00:05:47\n" ] }, { @@ -395,7 +523,7 @@ "output_type": "stream", "text": [ "0% [##########################] 100% | ETA: 00:00:00\n", - "Total time elapsed: 00:10:13\n" + "Total time elapsed: 00:21:44\n" ] } ], @@ -403,16 +531,14 @@ "import numpy as np\n", "p.calculate(\n", " methods=[\n", + " # #'EF v3.1 - acidification - accumulated exceedance (AE)',\n", " 'EF v3.1 - climate change - global warming potential (GWP100)',\n", " 'RELICS - metals extraction - Lithium',\n", " ],\n", " regions=[r for r in p.scenarios.coords[\"region\"].values if r!=\"World\"],\n", " #regions=[\"WEU\",],\n", " scenarios=[\"SSP2-RCP19\",],\n", - " variables=[\n", - " v for v in p.scenarios.coords[\"variables\"].values\n", - " if any(i in v for i in [\"Industry\", \"Transport\", \"Heating\"])\n", - " ],\n", + " variables=[x for x in p.scenarios.coords[\"variables\"].values if any(x.startswith(y) for y in [\"Heating\", \"Industry\", \"Transport\"])],\n", " #years=[2005, 2020, 2050, 2070, 2100],\n", " characterization=True,\n", " #flows=[\"Lithium - natural resource - in ground - kilogram\",],\n", @@ -424,79 +550,144 @@ }, { "cell_type": "code", - "execution_count": null, - "id": "c744f278-aaa9-408a-bfbf-5dbc1f692285", + "execution_count": 4, + "id": "4d72753f-9af7-41ea-b3fa-962ae9145f95", "metadata": {}, "outputs": [], "source": [ - "arr = p.display_results()" + "p.lca_results.to_netcdf('p data.nc')" ] }, { "cell_type": "code", - "execution_count": null, - "id": "dc1903c8-9e0a-43ce-ac5b-cef7952eb152", + "execution_count": 3, + "id": "3afde6b6-645f-4566-97e2-4b39b8045465", "metadata": {}, "outputs": [], "source": [ - "arr = arr.sum(dim=\"act_category\")" + "import xarray as xr\n", + "lca_results = xr.open_dataarray(\"p data.nc\")" ] }, { "cell_type": "code", - "execution_count": null, - "id": "0e32dc3c-9f0b-4a45-b2a0-114c314f2771", + "execution_count": 4, + "id": "fae5d299-95ab-4f6a-a815-58f449c71aee", "metadata": {}, "outputs": [], "source": [ - "arr.to_netcdf('data.nc')" + "lca_results = lca_results.sum(dim=\"act_category\")" ] }, { "cell_type": "code", - "execution_count": 1, - "id": "9958409e-1e04-4548-a08b-49b111a7c114", + "execution_count": 8, + "id": "4983e0c7-3ac9-4cdc-8d5a-c6fb39ee967f", "metadata": {}, "outputs": [], "source": [ - "import xarray as xr" + "import numpy as np\n", + "lca_results.loc[dict(year=[2015, 2025, 2035, 2045])] = np.nan" ] }, { "cell_type": "code", - "execution_count": 2, - "id": "0d02f286-cb21-4b46-94f4-022e3ae4c9ae", + "execution_count": 11, + "id": "f31b4d24-42e3-46de-aa0e-29ddfd5b95da", "metadata": {}, "outputs": [], "source": [ - "arr = xr.open_dataarray(\"data.nc\")" + "lca_results = lca_results.interpolate_na(dim=\"year\")" ] }, { "cell_type": "code", - "execution_count": 142, - "id": "042f9ee7-ce2e-4ed3-8e4f-d519a0f952db", + "execution_count": 12, + "id": "383cea1f-bd89-4911-a3e3-0085e95a8b71", "metadata": {}, "outputs": [], "source": [ - "import numpy as np\n", - "arr.loc[dict(year=[2015, 2025, 2035, 2045])] = np.nan" + "lca_results = lca_results.interp(\n", + " year=np.arange(lca_results.year.min(), lca_results.year.max() + 1,),\n", + " kwargs={\"fill_value\": \"interpolate\"},\n", + " method=\"linear\",\n", + ")" ] }, { "cell_type": "code", - "execution_count": 145, - "id": "f594565c-a15a-43b3-961e-3965038e482a", + "execution_count": 14, + "id": "0f4bde54-2c75-46f0-94c0-07014a3e9054", "metadata": {}, "outputs": [], "source": [ - "arr = arr.interpolate_na(dim=\"year\")" + "df = lca_results.to_dataframe(\"value\")" ] }, { "cell_type": "code", - "execution_count": 147, - "id": "e6f53dde-ee00-4a35-bc51-a1b6a7ebe08f", + "execution_count": 1, + "id": "c744f278-aaa9-408a-bfbf-5dbc1f692285", + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'p' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[1], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m arr \u001b[38;5;241m=\u001b[39m \u001b[43mp\u001b[49m\u001b[38;5;241m.\u001b[39mdisplay_results()\n", + "\u001b[0;31mNameError\u001b[0m: name 'p' is not defined" + ] + } + ], + "source": [ + "arr = p.display_results()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dc1903c8-9e0a-43ce-ac5b-cef7952eb152", + "metadata": {}, + "outputs": [], + "source": [ + "arr = arr.sum(dim=\"act_category\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0e32dc3c-9f0b-4a45-b2a0-114c314f2771", + "metadata": {}, + "outputs": [], + "source": [ + "arr.to_netcdf('data.nc')" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "9958409e-1e04-4548-a08b-49b111a7c114", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "0d02f286-cb21-4b46-94f4-022e3ae4c9ae", + "metadata": {}, + "outputs": [], + "source": [ + "arr = xr.open_dataarray(\"data.nc\")" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "5a6e946a-0b6a-4059-ae06-6d25dcc94c9a", "metadata": {}, "outputs": [], "source": [ @@ -509,7 +700,7 @@ }, { "cell_type": "code", - "execution_count": 148, + "execution_count": 6, "id": "21434870-34fa-434c-91ec-40cbc8aea39c", "metadata": {}, "outputs": [], @@ -519,17 +710,17 @@ }, { "cell_type": "code", - "execution_count": 149, + "execution_count": 15, "id": "9e187610-3d3d-4998-a5de-9a88049ae031", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "13372032" + "173836416" ] }, - "execution_count": 149, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -540,7 +731,7 @@ }, { "cell_type": "code", - "execution_count": 150, + "execution_count": 16, "id": "7a8e3d53-89f2-4cd3-b957-516c0206b653", "metadata": {}, "outputs": [], @@ -551,17 +742,17 @@ }, { "cell_type": "code", - "execution_count": 151, + "execution_count": 17, "id": "10253a05-a90d-4cc6-851b-d28ce89188cb", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "1215571" + "1823094" ] }, - "execution_count": 151, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -572,7 +763,7 @@ }, { "cell_type": "code", - "execution_count": 152, + "execution_count": 18, "id": "aff3301d-4731-4802-97c0-ed88226cd58b", "metadata": {}, "outputs": [], @@ -582,7 +773,7 @@ }, { "cell_type": "code", - "execution_count": 153, + "execution_count": 19, "id": "998d8893-98af-4299-b1eb-10ef3a8c7c7c", "metadata": {}, "outputs": [ @@ -620,87 +811,80 @@ " \n", " \n", " 0\n", - " Industry_Food and Tobacco_Electricity\n", + " Industry_Food and Tobacco_Solid biomass\n", " 2005\n", " BRA\n", - " Europe, without Russia and Turkey\n", + " ME\n", " image\n", " SSP2-RCP19\n", " EF v3.1 - climate change - global warming pote...\n", - " 1.043825e+06\n", + " 2.439076e+06\n", " \n", " \n", " 1\n", - " Industry_Food and Tobacco_Electricity\n", + " Industry_Food and Tobacco_Solid biomass\n", " 2005\n", " BRA\n", - " TZ\n", + " SAF\n", " image\n", " SSP2-RCP19\n", " EF v3.1 - climate change - global warming pote...\n", - " 1.149504e+06\n", + " 1.882817e+06\n", " \n", " \n", " 2\n", - " Industry_Food and Tobacco_Electricity\n", + " Industry_Food and Tobacco_Solid biomass\n", " 2005\n", " BRA\n", - " IN-DL\n", + " KZ\n", " image\n", " SSP2-RCP19\n", " EF v3.1 - climate change - global warming pote...\n", - " 1.264347e+04\n", + " 3.977986e+05\n", " \n", " \n", " 3\n", - " Industry_Food and Tobacco_Electricity\n", + " Industry_Food and Tobacco_Solid biomass\n", " 2005\n", " BRA\n", - " BR-TO\n", + " CN-QH\n", " image\n", " SSP2-RCP19\n", " EF v3.1 - climate change - global warming pote...\n", - " 1.652670e+02\n", + " 2.453483e+05\n", " \n", " \n", " 4\n", - " Industry_Food and Tobacco_Electricity\n", + " Industry_Food and Tobacco_Solid biomass\n", " 2005\n", " BRA\n", - " MR\n", + " PT\n", " image\n", " SSP2-RCP19\n", " EF v3.1 - climate change - global warming pote...\n", - " 1.881197e+03\n", + " 1.288394e+07\n", " \n", " \n", "\n", "" ], "text/plain": [ - " variable year region \\\n", - "0 Industry_Food and Tobacco_Electricity 2005 BRA \n", - "1 Industry_Food and Tobacco_Electricity 2005 BRA \n", - "2 Industry_Food and Tobacco_Electricity 2005 BRA \n", - "3 Industry_Food and Tobacco_Electricity 2005 BRA \n", - "4 Industry_Food and Tobacco_Electricity 2005 BRA \n", - "\n", - " location model scenario \\\n", - "0 Europe, without Russia and Turkey image SSP2-RCP19 \n", - "1 TZ image SSP2-RCP19 \n", - "2 IN-DL image SSP2-RCP19 \n", - "3 BR-TO image SSP2-RCP19 \n", - "4 MR image SSP2-RCP19 \n", - "\n", - " impact_category value \n", - "0 EF v3.1 - climate change - global warming pote... 1.043825e+06 \n", - "1 EF v3.1 - climate change - global warming pote... 1.149504e+06 \n", - "2 EF v3.1 - climate change - global warming pote... 1.264347e+04 \n", - "3 EF v3.1 - climate change - global warming pote... 1.652670e+02 \n", - "4 EF v3.1 - climate change - global warming pote... 1.881197e+03 " + " variable year region location model \\\n", + "0 Industry_Food and Tobacco_Solid biomass 2005 BRA ME image \n", + "1 Industry_Food and Tobacco_Solid biomass 2005 BRA SAF image \n", + "2 Industry_Food and Tobacco_Solid biomass 2005 BRA KZ image \n", + "3 Industry_Food and Tobacco_Solid biomass 2005 BRA CN-QH image \n", + "4 Industry_Food and Tobacco_Solid biomass 2005 BRA PT image \n", + "\n", + " scenario impact_category value \n", + "0 SSP2-RCP19 EF v3.1 - climate change - global warming pote... 2.439076e+06 \n", + "1 SSP2-RCP19 EF v3.1 - climate change - global warming pote... 1.882817e+06 \n", + "2 SSP2-RCP19 EF v3.1 - climate change - global warming pote... 3.977986e+05 \n", + "3 SSP2-RCP19 EF v3.1 - climate change - global warming pote... 2.453483e+05 \n", + "4 SSP2-RCP19 EF v3.1 - climate change - global warming pote... 1.288394e+07 " ] }, - "execution_count": 153, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -711,36 +895,7 @@ }, { "cell_type": "code", - "execution_count": 154, - "id": "5f2c4b3b-b26c-47ee-8c36-582feb027f58", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array([2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015,\n", - " 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026,\n", - " 2027, 2028, 2029, 2030, 2031, 2032, 2033, 2034, 2035, 2036, 2037,\n", - " 2038, 2039, 2040, 2041, 2042, 2043, 2044, 2045, 2046, 2047, 2048,\n", - " 2049, 2050, 2051, 2052, 2053, 2054, 2055, 2056, 2057, 2058, 2059,\n", - " 2060, 2061, 2062, 2063, 2064, 2065, 2066, 2067, 2068, 2069, 2070,\n", - " 2071, 2072, 2073, 2074, 2075, 2076, 2077, 2078, 2079, 2080, 2081,\n", - " 2082, 2083, 2084, 2085, 2086, 2087, 2088, 2089, 2090, 2091, 2092,\n", - " 2093, 2094, 2095, 2096, 2097, 2098, 2099, 2100])" - ] - }, - "execution_count": 154, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df[\"year\"].unique()" - ] - }, - { - "cell_type": "code", - "execution_count": 155, + "execution_count": 20, "id": "1de1d921-4156-46b8-9113-f94214320f50", "metadata": {}, "outputs": [], @@ -751,7 +906,7 @@ }, { "cell_type": "code", - "execution_count": 156, + "execution_count": 21, "id": "57b097ed-0108-4d62-8aaf-0a3d7c76fc48", "metadata": {}, "outputs": [], @@ -764,7 +919,7 @@ }, { "cell_type": "code", - "execution_count": 157, + "execution_count": 22, "id": "c0b92aed-c162-4f5a-b200-512452d5157e", "metadata": {}, "outputs": [], @@ -774,7 +929,7 @@ }, { "cell_type": "code", - "execution_count": 158, + "execution_count": 23, "id": "829eef08-5bc8-4ee3-8d51-fd55e2beb2b0", "metadata": {}, "outputs": [], @@ -784,7 +939,7 @@ }, { "cell_type": "code", - "execution_count": 159, + "execution_count": 24, "id": "11c1861f-1a2b-49f6-a1be-94680d5a6b30", "metadata": {}, "outputs": [], @@ -796,17 +951,17 @@ }, { "cell_type": "code", - "execution_count": 160, + "execution_count": 25, "id": "9acd0483-a477-4250-a28a-aa0d2f510509", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "125945" + "189038" ] }, - "execution_count": 160, + "execution_count": 25, "metadata": {}, "output_type": "execute_result" } @@ -817,7 +972,7 @@ }, { "cell_type": "code", - "execution_count": 161, + "execution_count": 26, "id": "5b5dde7a-3eb9-4f1d-997e-3c6310e76580", "metadata": {}, "outputs": [], @@ -828,17 +983,17 @@ }, { "cell_type": "code", - "execution_count": 162, + "execution_count": 27, "id": "3361c4c8-c006-4f09-85f4-9d50c10f327f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "125945" + "189038" ] }, - "execution_count": 162, + "execution_count": 27, "metadata": {}, "output_type": "execute_result" } @@ -849,7 +1004,7 @@ }, { "cell_type": "code", - "execution_count": 163, + "execution_count": 28, "id": "87646c30-91c9-4dcf-b4a0-a52471634580", "metadata": {}, "outputs": [ @@ -868,10 +1023,10 @@ " " ], "text/plain": [ - "" + "" ] }, - "execution_count": 163, + "execution_count": 28, "metadata": {}, "output_type": "execute_result" } @@ -884,484 +1039,102 @@ }, { "cell_type": "code", - "execution_count": 135, + "execution_count": 38, "id": "1a20734d-fa1f-4daa-99c7-ac57ad5deb4f", "metadata": {}, - "outputs": [], - "source": [ - "q = p.lca_results.sum(dim=\"act_category\")" - ] - }, - { - "cell_type": "code", - "execution_count": 138, - "id": "2da8f7d0-22b7-422d-8cc7-ae2fd20037b3", - "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "Coordinates:\n", - " * variable (variable) 10\u001b[0m \u001b[43mlca\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mredo_lci\u001b[49m\u001b[43m(\u001b[49m\u001b[43m{\u001b[49m\u001b[43mds\u001b[49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m}\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/anaconda3/envs/premise/lib/python3.10/site-packages/bw2calc/lca.py:515\u001b[0m, in \u001b[0;36mLCA.redo_lci\u001b[0;34m(self, demand)\u001b[0m\n\u001b[1;32m 513\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbuild_demand_array(demand)\n\u001b[1;32m 514\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdemand \u001b[38;5;241m=\u001b[39m demand\n\u001b[0;32m--> 515\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlci_calculation\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 516\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlogger\u001b[38;5;241m.\u001b[39minfo(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mRedoing LCI\u001b[39m\u001b[38;5;124m\"\u001b[39m, extra\u001b[38;5;241m=\u001b[39m{\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdemand\u001b[39m\u001b[38;5;124m'\u001b[39m: wrap_functional_unit(demand \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdemand)})\n", + "File \u001b[0;32m~/anaconda3/envs/premise/lib/python3.10/site-packages/bw2calc/lca.py:350\u001b[0m, in \u001b[0;36mLCA.lci_calculation\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 344\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mlci_calculation\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[1;32m 345\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"The actual LCI calculation.\u001b[39;00m\n\u001b[1;32m 346\u001b[0m \n\u001b[1;32m 347\u001b[0m \u001b[38;5;124;03m Separated from ``lci`` to be reusable in cases where the matrices are already built, e.g. ``redo_lci`` and Monte Carlo classes.\u001b[39;00m\n\u001b[1;32m 348\u001b[0m \n\u001b[1;32m 349\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 350\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msupply_array \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msolve_linear_system\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 351\u001b[0m \u001b[38;5;66;03m# Turn 1-d array into diagonal matrix\u001b[39;00m\n\u001b[1;32m 352\u001b[0m count \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mactivity_dict)\n", + "File \u001b[0;32m~/anaconda3/envs/premise/lib/python3.10/site-packages/bw2calc/lca.py:314\u001b[0m, in \u001b[0;36mLCA.solve_linear_system\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 301\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 302\u001b[0m \u001b[38;5;124;03mMaster solution function for linear system :math:`Ax=B`.\u001b[39;00m\n\u001b[1;32m 303\u001b[0m \n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 311\u001b[0m \n\u001b[1;32m 312\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m 313\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mhasattr\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124msolver\u001b[39m\u001b[38;5;124m\"\u001b[39m):\n\u001b[0;32m--> 314\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msolver\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdemand_array\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 315\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 316\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m spsolve(\n\u001b[1;32m 317\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtechnosphere_matrix,\n\u001b[1;32m 318\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdemand_array)\n", + "File \u001b[0;32m~/anaconda3/envs/premise/lib/python3.10/site-packages/scipy/sparse/linalg/_dsolve/linsolve.py:596\u001b[0m, in \u001b[0;36mfactorized..solve\u001b[0;34m(b)\u001b[0m\n\u001b[1;32m 593\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21msolve\u001b[39m(b):\n\u001b[1;32m 594\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m np\u001b[38;5;241m.\u001b[39merrstate(divide\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mignore\u001b[39m\u001b[38;5;124m\"\u001b[39m, invalid\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mignore\u001b[39m\u001b[38;5;124m\"\u001b[39m):\n\u001b[1;32m 595\u001b[0m \u001b[38;5;66;03m# Ignoring warnings with numpy >= 1.23.0, see gh-16523\u001b[39;00m\n\u001b[0;32m--> 596\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[43mumf\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msolve\u001b[49m\u001b[43m(\u001b[49m\u001b[43mumfpack\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mUMFPACK_A\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mA\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mb\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mautoTranspose\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m\n\u001b[1;32m 598\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m result\n", + "File \u001b[0;32m~/anaconda3/envs/premise/lib/python3.10/site-packages/scikits/umfpack/umfpack.py:709\u001b[0m, in \u001b[0;36mUmfpackContext.solve\u001b[0;34m(self, sys, mtx, rhs, autoTranspose)\u001b[0m\n\u001b[1;32m 707\u001b[0m rhs \u001b[38;5;241m=\u001b[39m rhs\u001b[38;5;241m.\u001b[39mastype(np\u001b[38;5;241m.\u001b[39mfloat64)\n\u001b[1;32m 708\u001b[0m sol \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mzeros((mtx\u001b[38;5;241m.\u001b[39mshape[\u001b[38;5;241m1\u001b[39m],), dtype\u001b[38;5;241m=\u001b[39mnp\u001b[38;5;241m.\u001b[39mfloat64)\n\u001b[0;32m--> 709\u001b[0m status \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfuns\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msolve\u001b[49m\u001b[43m(\u001b[49m\u001b[43msys\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmtx\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mindptr\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mindx\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmtx\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43msol\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrhs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 710\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_numeric\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcontrol\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minfo\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 711\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 712\u001b[0m rhs \u001b[38;5;241m=\u001b[39m rhs\u001b[38;5;241m.\u001b[39mastype(np\u001b[38;5;241m.\u001b[39mcomplex128)\n", + "File \u001b[0;32m~/anaconda3/envs/premise/lib/python3.10/site-packages/scikits/umfpack/_umfpack.py:412\u001b[0m, in \u001b[0;36mumfpack_dl_solve\u001b[0;34m(sys, Ap, Ai, Ax, X, B, Numeric, Control, Info)\u001b[0m\n\u001b[1;32m 410\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mumfpack_dl_solve\u001b[39m(sys, Ap, Ai, Ax, X, B, Numeric, Control, Info):\n\u001b[1;32m 411\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124;03m\"\"\"umfpack_dl_solve(SuiteSparse_long sys, SuiteSparse_long const [] Ap, SuiteSparse_long const [] Ai, double const [] Ax, double [] X, double const [] B, void * Numeric, double const [20] Control, double [90] Info) -> SuiteSparse_long\"\"\"\u001b[39;00m\n\u001b[0;32m--> 412\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m__umfpack\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mumfpack_dl_solve\u001b[49m\u001b[43m(\u001b[49m\u001b[43msys\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mAp\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mAi\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mAx\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mX\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mB\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mNumeric\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mControl\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mInfo\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[0;31mKeyboardInterrupt\u001b[0m: " + ] } ], "source": [ - "q.coords" + "import bw2io, bw2data, bw2calc\n", + "import pyprind\n", + "\n", + "bw2data.projects.set_current(\"ei39\")\n", + "\n", + "lca = bw2calc.LCA({bw2data.Database(\"ecoinvent 3.9.1 cutoff\").random():1})\n", + "lca.lci(factorize=True)\n", + "\n", + "for ds in pyprind.prog_percent(bw2data.Database(\"ecoinvent 3.9.1 cutoff\")):\n", + " lca.redo_lci({ds: 1})\n", + " " ] }, { "cell_type": "code", - "execution_count": 139, + "execution_count": 30, "id": "701b3907-31d8-4329-9693-fdbf66ccffd2", "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "
<xarray.DataArray (year: 15)> Size: 120B\n",
-       "array([4.66647340e+11, 5.45472829e+11, 0.00000000e+00, 5.78179822e+11,\n",
-       "       0.00000000e+00, 3.76307206e+11, 0.00000000e+00, 2.61900232e+11,\n",
-       "       0.00000000e+00, 2.25585623e+11, 2.05201143e+11, 1.67034370e+11,\n",
-       "       1.53310853e+11, 1.36826240e+11, 1.28377224e+11])\n",
-       "Coordinates:\n",
-       "  * year             (year) int64 120B 2005 2010 2015 2020 ... 2080 2090 2100\n",
-       "    impact_category  <U60 240B 'EF v3.1 - climate change - global warming pot...
" - ], - "text/plain": [ - " Size: 120B\n", - "array([4.66647340e+11, 5.45472829e+11, 0.00000000e+00, 5.78179822e+11,\n", - " 0.00000000e+00, 3.76307206e+11, 0.00000000e+00, 2.61900232e+11,\n", - " 0.00000000e+00, 2.25585623e+11, 2.05201143e+11, 1.67034370e+11,\n", - " 1.53310853e+11, 1.36826240e+11, 1.28377224e+11])\n", - "Coordinates:\n", - " * year (year) int64 120B 2005 2010 2015 2020 ... 2080 2090 2100\n", - " impact_category 6\u001b[0m \u001b[43mlca\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlci\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/anaconda3/envs/premise/lib/python3.10/site-packages/bw2calc/lca.py:342\u001b[0m, in \u001b[0;36mLCA.lci\u001b[0;34m(self, factorize, builder)\u001b[0m\n\u001b[1;32m 340\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m factorize:\n\u001b[1;32m 341\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdecompose_technosphere()\n\u001b[0;32m--> 342\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlci_calculation\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/anaconda3/envs/premise/lib/python3.10/site-packages/bw2calc/lca.py:350\u001b[0m, in \u001b[0;36mLCA.lci_calculation\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 344\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mlci_calculation\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[1;32m 345\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"The actual LCI calculation.\u001b[39;00m\n\u001b[1;32m 346\u001b[0m \n\u001b[1;32m 347\u001b[0m \u001b[38;5;124;03m Separated from ``lci`` to be reusable in cases where the matrices are already built, e.g. ``redo_lci`` and Monte Carlo classes.\u001b[39;00m\n\u001b[1;32m 348\u001b[0m \n\u001b[1;32m 349\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 350\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msupply_array \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msolve_linear_system\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 351\u001b[0m \u001b[38;5;66;03m# Turn 1-d array into diagonal matrix\u001b[39;00m\n\u001b[1;32m 352\u001b[0m count \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mactivity_dict)\n", + "File \u001b[0;32m~/anaconda3/envs/premise/lib/python3.10/site-packages/bw2calc/lca.py:316\u001b[0m, in \u001b[0;36mLCA.solve_linear_system\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 314\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msolver(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdemand_array)\n\u001b[1;32m 315\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 316\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mspsolve\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 317\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtechnosphere_matrix\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 318\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdemand_array\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/anaconda3/envs/premise/lib/python3.10/site-packages/scipy/sparse/linalg/_dsolve/linsolve.py:276\u001b[0m, in \u001b[0;36mspsolve\u001b[0;34m(A, b, permc_spec, use_umfpack)\u001b[0m\n\u001b[1;32m 274\u001b[0m umf_family, A \u001b[38;5;241m=\u001b[39m _get_umf_family(A)\n\u001b[1;32m 275\u001b[0m umf \u001b[38;5;241m=\u001b[39m umfpack\u001b[38;5;241m.\u001b[39mUmfpackContext(umf_family)\n\u001b[0;32m--> 276\u001b[0m x \u001b[38;5;241m=\u001b[39m \u001b[43mumf\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlinsolve\u001b[49m\u001b[43m(\u001b[49m\u001b[43mumfpack\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mUMFPACK_A\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mA\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mb_vec\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 277\u001b[0m \u001b[43m \u001b[49m\u001b[43mautoTranspose\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m\n\u001b[1;32m 278\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 279\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m b_is_vector \u001b[38;5;129;01mand\u001b[39;00m b_is_sparse:\n", + "File \u001b[0;32m~/anaconda3/envs/premise/lib/python3.10/site-packages/scikits/umfpack/umfpack.py:771\u001b[0m, in \u001b[0;36mUmfpackContext.linsolve\u001b[0;34m(self, sys, mtx, rhs, autoTranspose)\u001b[0m\n\u001b[1;32m 768\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124msys must be in\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;241m%\u001b[39m umfSys)\n\u001b[1;32m 770\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_numeric \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m--> 771\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mnumeric\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmtx\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 772\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 773\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmtx \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m mtx:\n", + "File \u001b[0;32m~/anaconda3/envs/premise/lib/python3.10/site-packages/scikits/umfpack/umfpack.py:565\u001b[0m, in \u001b[0;36mUmfpackContext.numeric\u001b[0;34m(self, mtx)\u001b[0m\n\u001b[1;32m 562\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m 563\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39misReal:\n\u001b[1;32m 564\u001b[0m status, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_numeric\\\n\u001b[0;32m--> 565\u001b[0m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfuns\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mnumeric\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmtx\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mindptr\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mindx\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmtx\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 566\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_symbolic\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 567\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcontrol\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minfo\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 568\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 569\u001b[0m real, imag \u001b[38;5;241m=\u001b[39m mtx\u001b[38;5;241m.\u001b[39mdata\u001b[38;5;241m.\u001b[39mreal\u001b[38;5;241m.\u001b[39mcopy(), mtx\u001b[38;5;241m.\u001b[39mdata\u001b[38;5;241m.\u001b[39mimag\u001b[38;5;241m.\u001b[39mcopy()\n", + "File \u001b[0;32m~/anaconda3/envs/premise/lib/python3.10/site-packages/scikits/umfpack/_umfpack.py:588\u001b[0m, in \u001b[0;36mumfpack_dl_numeric\u001b[0;34m(Ap, Ai, Ax, Symbolic, Control, Info)\u001b[0m\n\u001b[1;32m 586\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mumfpack_dl_numeric\u001b[39m(Ap, Ai, Ax, Symbolic, Control, Info):\n\u001b[1;32m 587\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124;03m\"\"\"umfpack_dl_numeric(SuiteSparse_long const [] Ap, SuiteSparse_long const [] Ai, double const [] Ax, void * Symbolic, double const [20] Control, double [90] Info) -> SuiteSparse_long\"\"\"\u001b[39;00m\n\u001b[0;32m--> 588\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m__umfpack\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mumfpack_dl_numeric\u001b[49m\u001b[43m(\u001b[49m\u001b[43mAp\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mAi\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mAx\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mSymbolic\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mControl\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mInfo\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[0;31mKeyboardInterrupt\u001b[0m: " + ] } ], "source": [ - "[r for r in p.scenarios.coords[\"region\"].values if r!=\"World\"]" + "\n", + "\n" ] }, { "cell_type": "code", "execution_count": null, - "id": "7d7bca9c-dd8c-418c-84de-ea2473be14b8", + "id": "97a206b1-e1d6-4d49-9cd3-5bbe5147edee", "metadata": {}, "outputs": [], "source": [] @@ -1383,7 +1156,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.10.13" } }, "nbformat": 4, diff --git a/dev/program.prof b/dev/program.prof index b0db1db..dfe566b 100644 Binary files a/dev/program.prof and b/dev/program.prof differ diff --git a/pathways/lcia.py b/pathways/lcia.py index aa97a47..c0bb586 100644 --- a/pathways/lcia.py +++ b/pathways/lcia.py @@ -68,4 +68,5 @@ def fill_characterization_factors_matrix(biosphere_flows: list, methods) -> np.n except KeyError: continue + return cf_matrix