diff --git a/dev/Untitled1.ipynb b/dev/Untitled1.ipynb index ad7f18a3..57671bf9 100644 --- a/dev/Untitled1.ipynb +++ b/dev/Untitled1.ipynb @@ -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", @@ -110,7 +111,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "id": "a324c189-26bd-4a65-885c-bba4683e9ed1", "metadata": {}, "outputs": [ @@ -118,15 +119,34 @@ "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 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\")" ] }, { diff --git a/premise/data/additional_inventories/lci-trucks.xlsx b/premise/data/additional_inventories/lci-trucks.xlsx index a6148b1f..c1f86834 100644 Binary files a/premise/data/additional_inventories/lci-trucks.xlsx and b/premise/data/additional_inventories/lci-trucks.xlsx differ diff --git a/premise/electricity.py b/premise/electricity.py index 4aca29db..c57cb6ee 100644 --- a/premise/electricity.py +++ b/premise/electricity.py @@ -1442,69 +1442,81 @@ def update_efficiency_of_solar_pv(self) -> None: if len(pv_tech) > 0: pv_tech = pv_tech[0] - for exc in ws.technosphere( - dataset, - ws.contains("name", "photovoltaic"), - ws.equals("unit", "square meter"), - ): - surface = float(exc["amount"]) - max_power = surface # in kW, since we assume a constant 1,000W/m^2 - current_eff = power / max_power - - if self.year in module_eff.coords["year"].values: - new_mean_eff = module_eff.sel( - technology=pv_tech, year=self.year, efficiency_type="mean" - ).values - new_min_eff = module_eff.sel( - technology=pv_tech, year=self.year, efficiency_type="min" - ).values - new_max_eff = module_eff.sel( - technology=pv_tech, year=self.year, efficiency_type="max" - ).values - else: - new_mean_eff = ( - module_eff.sel(technology=pv_tech, efficiency_type="mean") - .interp(year=self.year, kwargs={"fill_value": "extrapolate"}) - .values - ) - new_min_eff = ( - module_eff.sel(technology=pv_tech, efficiency_type="min") - .interp(year=self.year, kwargs={"fill_value": "extrapolate"}) - .values - ) - new_max_eff = ( - module_eff.sel(technology=pv_tech, efficiency_type="max") - .interp(year=self.year, kwargs={"fill_value": "extrapolate"}) - .values - ) + if pv_tech: - # in case self.year <10 or >2050 - new_mean_eff = np.clip(new_mean_eff, 0.1, 0.30) - new_min_eff = np.clip(new_min_eff, 0.1, 0.30) - new_max_eff = np.clip(new_max_eff, 0.1, 0.30) - - # We only update the efficiency if it is higher than the current one. - if new_mean_eff.sum() > current_eff: - exc["amount"] *= float(current_eff / new_mean_eff) - exc["uncertainty type"] = 5 - exc["loc"] = exc["amount"] - exc["minimum"] = exc["amount"] * (new_min_eff / new_mean_eff) - exc["maximum"] = exc["amount"] * (new_max_eff / new_mean_eff) - - dataset["comment"] = ( - f"`premise` has changed the efficiency " - f"of this photovoltaic installation " - f"from {int(current_eff * 100)} pct. to {int(new_mean_eff * 100)} pt." - ) + for exc in ws.technosphere( + dataset, + ws.contains("name", "photovoltaic"), + ws.equals("unit", "square meter"), + ): + surface = float(exc["amount"]) + max_power = surface # in kW, since we assume a constant 1,000W/m^2 + current_eff = power / max_power + + if self.year in module_eff.coords["year"].values: + new_mean_eff = module_eff.sel( + technology=pv_tech, year=self.year, efficiency_type="mean" + ).values + new_min_eff = module_eff.sel( + technology=pv_tech, year=self.year, efficiency_type="min" + ).values + new_max_eff = module_eff.sel( + technology=pv_tech, year=self.year, efficiency_type="max" + ).values + else: + new_mean_eff = ( + module_eff.sel(technology=pv_tech, efficiency_type="mean") + .interp( + year=self.year, kwargs={"fill_value": "extrapolate"} + ) + .values + ) + new_min_eff = ( + module_eff.sel(technology=pv_tech, efficiency_type="min") + .interp( + year=self.year, kwargs={"fill_value": "extrapolate"} + ) + .values + ) + new_max_eff = ( + module_eff.sel(technology=pv_tech, efficiency_type="max") + .interp( + year=self.year, kwargs={"fill_value": "extrapolate"} + ) + .values + ) - if "log parameters" not in dataset: - dataset["log parameters"] = {} + # in case self.year <10 or >2050 + new_mean_eff = np.clip(new_mean_eff, 0.1, 0.30) + new_min_eff = np.clip(new_min_eff, 0.1, 0.30) + new_max_eff = np.clip(new_max_eff, 0.1, 0.30) + + # We only update the efficiency if it is higher than the current one. + if new_mean_eff.sum() >= current_eff: + exc["amount"] *= float(current_eff / new_mean_eff) + exc["uncertainty type"] = 5 + exc["loc"] = exc["amount"] + exc["minimum"] = exc["amount"] * (new_min_eff / new_mean_eff) + exc["maximum"] = exc["amount"] * (new_max_eff / new_mean_eff) + + dataset["comment"] = ( + f"`premise` has changed the efficiency " + f"of this photovoltaic installation " + f"from {int(current_eff * 100)} pct. to {int(new_mean_eff * 100)} pt." + ) - dataset["log parameters"].update({"old efficiency": current_eff}) - dataset["log parameters"].update({"new efficiency": new_mean_eff}) + if "log parameters" not in dataset: + dataset["log parameters"] = {} - # add to log - self.write_log(dataset=dataset, status="updated") + dataset["log parameters"].update( + {"old efficiency": current_eff} + ) + dataset["log parameters"].update( + {"new efficiency": new_mean_eff} + ) + + # add to log + self.write_log(dataset=dataset, status="updated") def create_region_specific_power_plants(self): """