Skip to content

Commit

Permalink
Align wrt pathways
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi authored and romainsacchi committed Aug 26, 2024
1 parent 2187107 commit 9caf94e
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 64 deletions.
46 changes: 41 additions & 5 deletions dev/Untitled1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
" #{\"model\":\"remind\", \"pathway\":\"SSP2-Base\", \"year\":2010},\n",
" #{\"model\":\"image\", \"pathway\":\"SSP2-Base\", \"year\":2020},\n",
" #{\"model\":\"image\", \"pathway\":\"SSP2-Base\", \"year\":2050},\n",
" {\"model\":\"remind\", \"pathway\":\"SSP2-Base\", \"year\":2048},\n",
" {\"model\":\"remind\", \"pathway\":\"SSP2-Base\", \"year\":2050},\n",
" #{\"model\":\"image\", \"pathway\":\"SSP2-Base\", \"year\":2060},\n",
" #{\"model\":\"image\", \"pathway\":\"SSP2-Base\", \"year\":2050},\n",
Expand All @@ -110,23 +111,42 @@
},
{
"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: 100%|█████████████| 2/2 [00:16<00:00, 8.10s/it]"
"Processing scenarios: 0%| | 0/2 [00:00<?, ?it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done!\n",
"\n"
"{2020: {'min': 160, 'max': 383, 'mean': 272}, 2030: {'min': 134, 'max': 300, 'mean': 217}, 2040: {'min': 120, 'max': 267, 'mean': 194}, 2050: {'min': 108, 'max': 236, 'mean': 172}}\n",
"{2020: {'min': 272, 'max': 639, 'mean': 456}, 2030: {'min': 203, 'max': 479, 'mean': 341}, 2040: {'min': 182, 'max': 479, 'mean': 330}, 2050: {'min': 168, 'max': 370, 'mean': 269}}\n",
"{2020: {'min': 394, 'max': 1110, 'mean': 752}, 2030: {'min': 323, 'max': 802, 'mean': 562}, 2040: {'min': 296, 'max': 726, 'mean': 511}, 2050: {'min': 273, 'max': 666, 'mean': 470}}\n",
"{2020: {'min': 509, 'max': 1291, 'mean': 900}, 2030: {'min': 390, 'max': 978, 'mean': 684}, 2040: {'min': 362, 'max': 906, 'mean': 634}, 2050: {'min': 360, 'max': 845, 'mean': 603}}\n",
"{2020: {'min': 660, 'max': 1515, 'mean': 1088}, 2030: {'min': 550, 'max': 1207, 'mean': 879}, 2040: {'min': 530, 'max': 1124, 'mean': 827}, 2050: {'min': 490, 'max': 1038, 'mean': 764}}\n",
"{2020: {'min': 665, 'max': 1542, 'mean': 1104}, 2030: {'min': 550, 'max': 1200, 'mean': 875}, 2040: {'min': 530, 'max': 1123, 'mean': 826}, 2050: {'min': 490, 'max': 1067, 'mean': 779}}\n",
"{2020: {'min': 835, 'max': 1804, 'mean': 1320}, 2030: {'min': 670, 'max': 1349, 'mean': 1010}, 2040: {'min': 630, 'max': 1255, 'mean': 942}, 2050: {'min': 603, 'max': 1188, 'mean': 896}}\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Processing scenarios: 50%|██████▌ | 1/2 [00:13<00:13, 13.59s/it]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{2020: {'min': 160, 'max': 383, 'mean': 272}, 2030: {'min': 134, 'max': 300, 'mean': 217}, 2040: {'min': 120, 'max': 267, 'mean': 194}, 2050: {'min': 108, 'max': 236, 'mean': 172}}\n"
]
},
{
Expand All @@ -135,10 +155,26 @@
"text": [
"\n"
]
},
{
"ename": "KeyError",
"evalue": "'min'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[5], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mndb\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mupdate\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mtrucks\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/Github/premise/premise/new_database.py:963\u001b[0m, in \u001b[0;36mNewDatabase.update\u001b[0;34m(self, sectors)\u001b[0m\n\u001b[1;32m 961\u001b[0m update_func \u001b[38;5;241m=\u001b[39m sector_update_methods[sector][\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfunc\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n\u001b[1;32m 962\u001b[0m fixed_args \u001b[38;5;241m=\u001b[39m sector_update_methods[sector][\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124margs\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n\u001b[0;32m--> 963\u001b[0m scenario \u001b[38;5;241m=\u001b[39m \u001b[43mupdate_func\u001b[49m\u001b[43m(\u001b[49m\u001b[43mscenario\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mfixed_args\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 965\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mapplied functions\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m scenario:\n\u001b[1;32m 966\u001b[0m scenario[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mapplied functions\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m []\n",
"File \u001b[0;32m~/Github/premise/premise/transport.py:52\u001b[0m, in \u001b[0;36m_update_vehicles\u001b[0;34m(scenario, vehicle_type, version, system_model)\u001b[0m\n\u001b[1;32m 49\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 50\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;124mUnknown vehicle type.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m---> 52\u001b[0m trspt \u001b[38;5;241m=\u001b[39m \u001b[43mTransport\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 53\u001b[0m \u001b[43m \u001b[49m\u001b[43mdatabase\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mscenario\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mdatabase\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 54\u001b[0m \u001b[43m \u001b[49m\u001b[43myear\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mscenario\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43myear\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 55\u001b[0m \u001b[43m \u001b[49m\u001b[43mmodel\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mscenario\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mmodel\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 56\u001b[0m \u001b[43m \u001b[49m\u001b[43mpathway\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mscenario\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mpathway\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 57\u001b[0m \u001b[43m \u001b[49m\u001b[43miam_data\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mscenario\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43miam data\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 58\u001b[0m \u001b[43m \u001b[49m\u001b[43mversion\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mversion\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 59\u001b[0m \u001b[43m \u001b[49m\u001b[43msystem_model\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43msystem_model\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 60\u001b[0m \u001b[43m \u001b[49m\u001b[43mvehicle_type\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mvehicle_type\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 61\u001b[0m \u001b[43m \u001b[49m\u001b[43mrelink\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 62\u001b[0m \u001b[43m \u001b[49m\u001b[43mhas_fleet\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mhas_fleet\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 63\u001b[0m \u001b[43m \u001b[49m\u001b[43mindex\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mscenario\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mindex\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 64\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 66\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 trspt\u001b[38;5;241m.\u001b[39mdatabase\n\u001b[1;32m 67\u001b[0m scenario[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcache\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m trspt\u001b[38;5;241m.\u001b[39mcache\n",
"File \u001b[0;32m~/Github/premise/premise/transport.py:397\u001b[0m, in \u001b[0;36mTransport.__init__\u001b[0;34m(self, database, iam_data, model, pathway, year, version, system_model, relink, vehicle_type, has_fleet, index)\u001b[0m\n\u001b[1;32m 394\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mVehicle map is empty for \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mvehicle_type\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 396\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhas_fleet:\n\u001b[0;32m--> 397\u001b[0m fleet_datasets \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcreate_vehicle_markets\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 398\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdatabase\u001b[38;5;241m.\u001b[39mextend(fleet_datasets)\n\u001b[1;32m 399\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39madd_to_index(fleet_datasets)\n",
"File \u001b[0;32m~/Github/premise/premise/transport.py:485\u001b[0m, in \u001b[0;36mTransport.create_vehicle_markets\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 478\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mvehicle_type \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtruck\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[1;32m 479\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m ds \u001b[38;5;129;01min\u001b[39;00m ws\u001b[38;5;241m.\u001b[39mget_many(\n\u001b[1;32m 480\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdatabase,\n\u001b[1;32m 481\u001b[0m ws\u001b[38;5;241m.\u001b[39mcontains(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mname\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mbattery electric\u001b[39m\u001b[38;5;124m\"\u001b[39m),\n\u001b[1;32m 482\u001b[0m ws\u001b[38;5;241m.\u001b[39mcontains(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mname\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtruck\u001b[39m\u001b[38;5;124m\"\u001b[39m),\n\u001b[1;32m 483\u001b[0m ws\u001b[38;5;241m.\u001b[39mequals(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124munit\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124munit\u001b[39m\u001b[38;5;124m\"\u001b[39m),\n\u001b[1;32m 484\u001b[0m ):\n\u001b[0;32m--> 485\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43madjust_battery_size\u001b[49m\u001b[43m(\u001b[49m\u001b[43mds\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 487\u001b[0m \u001b[38;5;66;03m# if trucks, need to reconnect everything\u001b[39;00m\n\u001b[1;32m 488\u001b[0m \u001b[38;5;66;03m# loop through datasets that use truck transport\u001b[39;00m\n\u001b[1;32m 489\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mvehicle_type \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtruck\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n",
"File \u001b[0;32m~/Github/premise/premise/transport.py:646\u001b[0m, in \u001b[0;36mTransport.adjust_battery_size\u001b[0;34m(self, ds)\u001b[0m\n\u001b[1;32m 642\u001b[0m max_battery_size \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbattery_size[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtruck\u001b[39m\u001b[38;5;124m\"\u001b[39m][size][\n\u001b[1;32m 643\u001b[0m \u001b[38;5;28mmin\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbattery_size[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtruck\u001b[39m\u001b[38;5;124m\"\u001b[39m][size][\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39myear]\u001b[38;5;241m.\u001b[39mkeys())\n\u001b[1;32m 644\u001b[0m ][\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmax\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n\u001b[1;32m 645\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39myear \u001b[38;5;241m>\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;28mmax\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbattery_size[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtruck\u001b[39m\u001b[38;5;124m\"\u001b[39m][size]\u001b[38;5;241m.\u001b[39mkeys()):\n\u001b[0;32m--> 646\u001b[0m mean_battery_size \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbattery_size\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mtruck\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m[\u001b[49m\u001b[43msize\u001b[49m\u001b[43m]\u001b[49m\u001b[43m[\u001b[49m\n\u001b[1;32m 647\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mmax\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbattery_size\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mtruck\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m[\u001b[49m\u001b[43msize\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[43myear\u001b[49m\u001b[43m]\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mkeys\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 648\u001b[0m \u001b[43m \u001b[49m\u001b[43m]\u001b[49m[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmean\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n\u001b[1;32m 649\u001b[0m min_battery_size \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbattery_size[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtruck\u001b[39m\u001b[38;5;124m\"\u001b[39m][size][\n\u001b[1;32m 650\u001b[0m \u001b[38;5;28mmax\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbattery_size[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtruck\u001b[39m\u001b[38;5;124m\"\u001b[39m][size][\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39myear]\u001b[38;5;241m.\u001b[39mkeys())\n\u001b[1;32m 651\u001b[0m ][\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmin\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n\u001b[1;32m 652\u001b[0m max_battery_size \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbattery_size[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtruck\u001b[39m\u001b[38;5;124m\"\u001b[39m][size][\n\u001b[1;32m 653\u001b[0m \u001b[38;5;28mmax\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbattery_size[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtruck\u001b[39m\u001b[38;5;124m\"\u001b[39m][size][\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39myear][\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmax\u001b[39m\u001b[38;5;124m\"\u001b[39m]\u001b[38;5;241m.\u001b[39mkeys())\n\u001b[1;32m 654\u001b[0m ][\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmax\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n",
"\u001b[0;31mKeyError\u001b[0m: 'min'"
]
}
],
"source": [
"ndb.update()"
"ndb.update(\"trucks\")"
]
},
{
Expand Down
Binary file modified premise/data/additional_inventories/lci-trucks.xlsx
Binary file not shown.
Loading

0 comments on commit 9caf94e

Please sign in to comment.