Skip to content

Commit

Permalink
Specify BW 2 & 2.5 installations
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi authored and romainsacchi committed Dec 20, 2024
1 parent fbc1a54 commit a481e88
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 69 deletions.
70 changes: 2 additions & 68 deletions dev/test pathways with multiple scenarios.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"id": "87ecc69b-2469-495c-930f-7a5291ab4d73",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -83,73 +83,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Warning: No activities found for Gas ST -- revise mapping.\n",
"Extracted 1 worksheets in 0.20 seconds\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Processing scenarios for 2 sectors: 50%|▌| 1/2 [00:28<00:28, 28.36s/i"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Warning: No activities found for Gas ST -- revise mapping.\n",
"Extracted 1 worksheets in 0.23 seconds\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Processing scenarios for 2 sectors: 100%|█| 2/2 [00:58<00:00, 29.09s/i\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done!\n",
"\n",
"Extracted 1 worksheets in 0.02 seconds\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n",
"Extracted 1 worksheets in 0.03 seconds\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\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/pathways/inventories/remind/SSP2-PkBudg500-Business As Usual - remind-Ambitious/2030.\n",
"Running all checks...\n",
"Minor anomalies found: check the change report.\n",
"Matrices saved in /Users/romain/Github/premise/dev/pathways/inventories/remind/SSP2-PkBudg500-Business As Usual - remind-Ambitious/2050.\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"
]
},
{
"ename": "ValueError",
"evalue": "conflicting sizes for dimension 'scenario': length 6 on <this-array> and length 4 on {'region': 'region', 'variables': 'variables', 'year': 'year', 'scenario': 'scenario'}",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[2], line 25\u001b[0m\n\u001b[1;32m 10\u001b[0m scenarios \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 11\u001b[0m {\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmodel\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mremind\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpathway\u001b[39m\u001b[38;5;124m\"\u001b[39m:\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSSP2-PkBudg500\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124myear\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;241m2050\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mexternal scenarios\u001b[39m\u001b[38;5;124m\"\u001b[39m: external_scenarios},\n\u001b[1;32m 12\u001b[0m \u001b[38;5;66;03m#{\"model\": \"image\", \"pathway\":\"SSP2-RCP26\", \"year\": 2035, \"external scenarios\": external_scenarios},\u001b[39;00m\n\u001b[1;32m 13\u001b[0m ]\n\u001b[1;32m 16\u001b[0m ndb \u001b[38;5;241m=\u001b[39m PathwaysDataPackage(\n\u001b[1;32m 17\u001b[0m scenarios \u001b[38;5;241m=\u001b[39m scenarios, \n\u001b[1;32m 18\u001b[0m source_db\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mecoinvent-3.10-cutoff\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 22\u001b[0m years\u001b[38;5;241m=\u001b[39m[\u001b[38;5;241m2030\u001b[39m, \u001b[38;5;241m2050\u001b[39m]\n\u001b[1;32m 23\u001b[0m )\n\u001b[0;32m---> 25\u001b[0m \u001b[43mndb\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcreate_datapackage\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 26\u001b[0m \u001b[43m \u001b[49m\u001b[43mtransformations\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m[\u001b[49m\n\u001b[1;32m 27\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43melectricity\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 28\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mexternal\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n\u001b[1;32m 29\u001b[0m \u001b[43m \u001b[49m\u001b[43m]\u001b[49m\n\u001b[1;32m 30\u001b[0m \u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/Github/premise/premise/pathways.py:94\u001b[0m, in \u001b[0;36mPathwaysDataPackage.create_datapackage\u001b[0;34m(self, name, contributors, transformations)\u001b[0m\n\u001b[1;32m 91\u001b[0m energy\u001b[38;5;241m.\u001b[39mimport_heating_inventories()\n\u001b[1;32m 92\u001b[0m scenario[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdatabase\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m energy\u001b[38;5;241m.\u001b[39mdatabase\n\u001b[0;32m---> 94\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mexport_datapackage\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 95\u001b[0m \u001b[43m \u001b[49m\u001b[43mname\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mname\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 96\u001b[0m \u001b[43m \u001b[49m\u001b[43mcontributors\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcontributors\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 97\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/Github/premise/premise/pathways.py:112\u001b[0m, in \u001b[0;36mPathwaysDataPackage.export_datapackage\u001b[0;34m(self, name, contributors)\u001b[0m\n\u001b[1;32m 108\u001b[0m \u001b[38;5;66;03m# create matrices in current directory\u001b[39;00m\n\u001b[1;32m 109\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdatapackage\u001b[38;5;241m.\u001b[39mwrite_db_to_matrices(\n\u001b[1;32m 110\u001b[0m filepath\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mstr\u001b[39m(Path\u001b[38;5;241m.\u001b[39mcwd() \u001b[38;5;241m/\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpathways\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m/\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124minventories\u001b[39m\u001b[38;5;124m\"\u001b[39m),\n\u001b[1;32m 111\u001b[0m )\n\u001b[0;32m--> 112\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43madd_scenario_data\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 113\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39madd_variables_mapping()\n\u001b[1;32m 114\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbuild_datapackage(name, contributors)\n",
"File \u001b[0;32m~/Github/premise/premise/pathways.py:324\u001b[0m, in \u001b[0;36mPathwaysDataPackage.add_scenario_data\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 321\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mscenario_names\u001b[38;5;241m.\u001b[39mappend(name)\n\u001b[1;32m 322\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mscenario_names\u001b[38;5;241m.\u001b[39mappend(name)\n\u001b[0;32m--> 324\u001b[0m \u001b[43marray\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcoords\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mscenario\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mscenario_names\n\u001b[1;32m 326\u001b[0m \u001b[38;5;66;03m# make sure pathways/scenario_data directory exists\u001b[39;00m\n\u001b[1;32m 327\u001b[0m (Path\u001b[38;5;241m.\u001b[39mcwd() \u001b[38;5;241m/\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpathways\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m/\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mscenario_data\u001b[39m\u001b[38;5;124m\"\u001b[39m)\u001b[38;5;241m.\u001b[39mmkdir(parents\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m, exist_ok\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n",
"File \u001b[0;32m~/anaconda3/envs/premise/lib/python3.10/site-packages/xarray/core/coordinates.py:528\u001b[0m, in \u001b[0;36mCoordinates.__setitem__\u001b[0;34m(self, key, value)\u001b[0m\n\u001b[1;32m 527\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__setitem__\u001b[39m(\u001b[38;5;28mself\u001b[39m, key: Hashable, value: Any) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m--> 528\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mupdate\u001b[49m\u001b[43m(\u001b[49m\u001b[43m{\u001b[49m\u001b[43mkey\u001b[49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mvalue\u001b[49m\u001b[43m}\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/anaconda3/envs/premise/lib/python3.10/site-packages/xarray/core/coordinates.py:566\u001b[0m, in \u001b[0;36mCoordinates.update\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m 560\u001b[0m \u001b[38;5;66;03m# special case for PandasMultiIndex: updating only its dimension coordinate\u001b[39;00m\n\u001b[1;32m 561\u001b[0m \u001b[38;5;66;03m# is still allowed but depreciated.\u001b[39;00m\n\u001b[1;32m 562\u001b[0m \u001b[38;5;66;03m# It is the only case where we need to actually drop coordinates here (multi-index levels)\u001b[39;00m\n\u001b[1;32m 563\u001b[0m \u001b[38;5;66;03m# TODO: remove when removing PandasMultiIndex's dimension coordinate.\u001b[39;00m\n\u001b[1;32m 564\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_drop_coords(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_names \u001b[38;5;241m-\u001b[39m coords_to_align\u001b[38;5;241m.\u001b[39m_names)\n\u001b[0;32m--> 566\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_update_coords\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcoords\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mindexes\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/anaconda3/envs/premise/lib/python3.10/site-packages/xarray/core/coordinates.py:842\u001b[0m, in \u001b[0;36mDataArrayCoordinates._update_coords\u001b[0;34m(self, coords, indexes)\u001b[0m\n\u001b[1;32m 840\u001b[0m coords_plus_data \u001b[38;5;241m=\u001b[39m coords\u001b[38;5;241m.\u001b[39mcopy()\n\u001b[1;32m 841\u001b[0m coords_plus_data[_THIS_ARRAY] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_data\u001b[38;5;241m.\u001b[39mvariable\n\u001b[0;32m--> 842\u001b[0m dims \u001b[38;5;241m=\u001b[39m \u001b[43mcalculate_dimensions\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcoords_plus_data\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 843\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mset\u001b[39m(dims) \u001b[38;5;241m<\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;28mset\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdims):\n\u001b[1;32m 844\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[1;32m 845\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcannot add coordinates with new dimensions to a DataArray\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 846\u001b[0m )\n",
"File \u001b[0;32m~/anaconda3/envs/premise/lib/python3.10/site-packages/xarray/core/variable.py:3008\u001b[0m, in \u001b[0;36mcalculate_dimensions\u001b[0;34m(variables)\u001b[0m\n\u001b[1;32m 3006\u001b[0m last_used[dim] \u001b[38;5;241m=\u001b[39m k\n\u001b[1;32m 3007\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m dims[dim] \u001b[38;5;241m!=\u001b[39m size:\n\u001b[0;32m-> 3008\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[1;32m 3009\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mconflicting sizes for dimension \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mdim\u001b[38;5;132;01m!r}\u001b[39;00m\u001b[38;5;124m: \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 3010\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlength \u001b[39m\u001b[38;5;132;01m{\u001b[39;00msize\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m on \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mk\u001b[38;5;132;01m!r}\u001b[39;00m\u001b[38;5;124m and length \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mdims[dim]\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m on \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mlast_used\u001b[38;5;132;01m!r}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 3011\u001b[0m )\n\u001b[1;32m 3012\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m dims\n",
"\u001b[0;31mValueError\u001b[0m: conflicting sizes for dimension 'scenario': length 6 on <this-array> and length 4 on {'region': 'region', 'variables': 'variables', 'year': 'year', 'scenario': 'scenario'}"
"Warning: No activities found for Gas ST -- revise mapping.\n"
]
}
],
Expand Down
5 changes: 4 additions & 1 deletion premise/pathways.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,16 @@ def add_scenario_data(self):

array = xr.concat(scenario_data, dim="scenario")

print(array.coords)
print(array.shape)

# add scenario data to the xarray
for s, scenario in enumerate(self.datapackage.scenarios):
name = f"{scenario['model'].upper()} - {scenario['pathway']}"
if "external scenarios" in scenario:
for external in scenario["external scenarios"]:
name += f"-{external['scenario']}"
self.scenario_names.append(name)
#self.scenario_names.append(name)
self.scenario_names.append(name)

array.coords["scenario"] = self.scenario_names
Expand Down

0 comments on commit a481e88

Please sign in to comment.