Skip to content

Enrich an existing grid container by EVs and EVCS #356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.

### Added
- Add project-level `CLAUDE.md` file [#329](https://github.com/ie3-institute/pypsdm/issues/329)
- Enrich an existing grid container by EVs and EVCS [#355](https://github.com/ie3-institute/pypsdm/issues/355)

### Changed

Expand All @@ -14,7 +15,8 @@ All notable changes to this project will be documented in this file.

### Fixed
- Removed `q_characteristics` from `create_energy_management_systems_data` [#326](https://github.com/ie3-institute/pypsdm/issues/326)
- Fix emInput from parent_em to controlling_em [#333](https://github.com/ie3-institute/pypsdm/issues/333)
- Fix `emInput` from `parent_em` to `controlling_e` [#333](https://github.com/ie3-institute/pypsdm/issues/333)
- Fix also from `em` to `controlling_em` for all `SystemParticipants` [#337](https://github.com/ie3-institute/pypsdm/issues/337)


## 0.0.6
Expand Down
16 changes: 8 additions & 8 deletions nbs/create_grid.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
" \"control_strategy\": [\"PRIORITIZED\", \"PRIORITIZED\", \"PRIORITIZED\"],\n",
"}\n",
"\n",
"emss = create_energy_management_systems(data_dict)"
"controlling_emss = create_energy_management_systems(data_dict)"
]
},
{
Expand All @@ -97,7 +97,7 @@
" \"s_rated\": pv_s_rated,\n",
" \"azimuth\": [90, 0, -90],\n",
" \"elevation_angle\": [40, 45, 30],\n",
" \"em\": em_uuids,\n",
" \"controlling_em\": em_uuids,\n",
"}\n",
"\n",
"pvs = create_pvs(data_dict)"
Expand All @@ -116,7 +116,7 @@
" \"id\": [\"BS_NS_02\", \"BS_NS_03\", \"BS_NS_04\"],\n",
" \"node\": [node_2, node_3, node_4],\n",
" \"e_storage\": [1.5 * pv_power for pv_power in pv_s_rated],\n",
" \"em\": em_uuids,\n",
" \"controlling_em\": em_uuids,\n",
"}\n",
"\n",
"bs = create_storages(data_dict)"
Expand Down Expand Up @@ -163,7 +163,7 @@
" EvcsLocationType.HOME.value,\n",
" ],\n",
" \"s_rated\": [10, 10, 10],\n",
" \"em\": em_uuids,\n",
" \"controlling_em\": em_uuids,\n",
"}\n",
"\n",
"evcs = create_ev_charging_stations(data_dict)"
Expand Down Expand Up @@ -208,7 +208,7 @@
" \"node\": [node_2, node_3, node_4],\n",
" \"thermal_bus\": list(tbs.uuid),\n",
" \"s_rated\": [4, 3, 6],\n",
" \"em\": em_uuids,\n",
" \"controlling_em\": em_uuids,\n",
"}\n",
"\n",
"hps = create_heat_pumps(data_dict)"
Expand Down Expand Up @@ -248,7 +248,7 @@
" \"s_rated\": [3, 3, 3],\n",
" \"e_cons_annual\": [3000, 3500, 4000],\n",
" \"load_profile\": [\"h0\", \"h0\", \"h0\"],\n",
" \"em\": em_uuids,\n",
" \"controlling_em\": em_uuids,\n",
"}\n",
"\n",
"loads = create_loads(load_data_dict)"
Expand All @@ -268,7 +268,7 @@
"\n",
"\n",
"participants = SystemParticipantsContainer(\n",
" ems=EnergyManagementSystems.create_empty(),\n",
" controlling_ems=EnergyManagementSystems.create_empty(),\n",
" loads=loads,\n",
" pvs=pvs,\n",
" storages=bs,\n",
Expand Down Expand Up @@ -313,7 +313,7 @@
"outputs": [],
"source": [
"updated_participants = SystemParticipantsContainer(\n",
" emss,\n",
" controlling_emss,\n",
" participants.loads,\n",
" participants.fixed_feed_ins,\n",
" participants.pvs,\n",
Expand Down
162 changes: 162 additions & 0 deletions nbs/enrich_grid_with_ev_and_evcs.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "initial_id",
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Some jupyter notebook magic to reload modules automatically when they change\n",
"# not necessary for this specific notebook but useful in general\n",
"%load_ext autoreload\n",
"%autoreload 2\n",
"\n",
"# Gives you high resolution images within the notebook\n",
"%config InlineBackend.figure_format = 'retina'"
]
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": [
"from definitions import ROOT_DIR\n",
"import os\n",
"from pypsdm import GridContainer\n",
"\n",
"# The PSDM specific input models can be imported from the pypsdm.models.input and\n",
"# pypsdm.models.result. The `GridWithResults` container is located in pypsdm.models.gwr\n",
"from pypsdm.models.gwr import GridWithResults\n",
"\n",
"grid_path = os.path.join(ROOT_DIR, \"tests\", \"resources\", \"simple_grid\", \"input\")\n",
"# IO data models in general have a from_csv method to parse psdm files\n",
"gwr = GridContainer.from_csv(grid_path)\n",
"\n",
"# Output directory\n",
"target_grid_path = os.path.join(ROOT_DIR, \"output\", \"enriched_grid\")\n",
"if not os.path.exists(target_grid_path):\n",
" os.makedirs(target_grid_path)"
],
"id": "8a6d151463bebeff"
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": [
"from pypsdm.io.utils import delete_all_files_in_directory\n",
"\n",
"delete_all_files_in_directory(target_grid_path)"
],
"id": "ece5d5686f9eda0c"
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": [
"# input parameter, so far we only support to sample p_rated of the EVs in a normal distribution.\n",
"# EVs will have a storage size of 120.0 kWh and a consumption of 0.18 kWh/km each\n",
"# The EVCS will have a charging power of 22.0 kW and two charging points.\n",
"ev_p_rated_mean = 22.0\n",
"ev_p_rated_sigma = 0.0\n",
"ev_p_rated_min = 22.0\n",
"ev_p_rated_max = 22.0\n",
"ev_p_rated_params = [ev_p_rated_mean, ev_p_rated_sigma, ev_p_rated_min, ev_p_rated_max]\n",
"evcs_v2g = False"
],
"id": "dfd54ffa547aa7a6"
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": [
"# identify nodes to which should be connected. For example, customer nodes most probably have an existing load. So we're looking for nodes in lv grids with an existing load\n",
"lv_nodes = gwr.nodes.data[gwr.nodes.data[\"v_rated\"] <= 1.0]\n",
"household_nodes = lv_nodes[lv_nodes.index.isin(gwr.loads.node)]\n",
"household_nodes.head()"
],
"id": "5e5143be50696313"
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": [
"from pypsdm.models.input.create.enrich_grid import enrich_grid_by_evs_and_evcs\n",
"from pypsdm.models.input.create.participants import create_electric_vehicles\n",
"from pypsdm.models.input.create.participants import create_ev_charging_stations\n",
"\n",
"# get dictionaries for the ev and evcs as well as DataFrames for POIs and POI Mapping\n",
"ev_dict, evcs_dict, df_poi, df_poi_map = enrich_grid_by_evs_and_evcs(\n",
" nodes=household_nodes,\n",
" ev_p_rated_params=ev_p_rated_params,\n",
" evcs_v2g=evcs_v2g,\n",
" controlling_em=False,\n",
")\n",
"\n",
"# with these the EVs and EVCSs can be created\n",
"evs = create_electric_vehicles(ev_dict)\n",
"evcs = create_ev_charging_stations(evcs_dict)"
],
"id": "6e0ba8c8222b49cf"
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": [
"from pypsdm.models.input.container.grid import GridContainer\n",
"from pypsdm.models.input.create.enrich_grid import add_pois_of_enriched_evcs\n",
"\n",
"# we now can create an updated SystemParticipantsContainer and an updated node_participants_map\n",
"updated_participants = gwr.participants.copy(evs=evs, evcs=evcs)\n",
"node_participants = updated_participants.build_node_participants_map(gwr.raw_grid.nodes)\n",
"node_participants_map = updated_participants.build_node_participants_map(\n",
" gwr.raw_grid.nodes\n",
")\n",
"\n",
"# with this we can build our updated grid containing the updated participants.\n",
"updated_grid = GridContainer(\n",
" gwr.raw_grid, updated_participants, gwr.primary_data, node_participants_map\n",
")\n",
"\n",
"# Finally, we can write the updated grid as well as the updated POI and POI Mapping data to our output path\n",
"updated_grid.to_csv(target_grid_path, include_primary_data=True)\n",
"add_pois_of_enriched_evcs(df_poi, df_poi_map, target_grid_path)"
],
"id": "adfcb8863d6ca0b3"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
14 changes: 7 additions & 7 deletions nbs/enrich_simbench_grid.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3104,7 +3104,7 @@
" \"s_rated\": load_input_params[3],\n",
" \"e_cons_annual\": load_input_params[4],\n",
" \"load_profile\": load_input_params[5],\n",
" \"em\": load_input_params[6],\n",
" \"controlling_em\": load_input_params[6],\n",
"}\n",
"\n",
"loads = create_loads(load_data_dict)"
Expand All @@ -3131,7 +3131,7 @@
" \"azimuth\": pv_input_params[2],\n",
" \"elevation_angle\": pv_input_params[3],\n",
" \"uuid\": pv_input_params[5],\n",
" \"em\": pv_input_params[6],\n",
" \"controlling_em\": pv_input_params[6],\n",
"}\n",
"\n",
"pvs = create_pvs(data_dict)"
Expand Down Expand Up @@ -3172,7 +3172,7 @@
" \"s_rated\": evcs_params[4],\n",
" \"uuid\": evcs_params[1],\n",
" \"v2g_support\": evcs_params[5],\n",
" \"em\": evcs_params[6],\n",
" \"controlling_em\": evcs_params[6],\n",
"}\n",
"\n",
"evcs = create_ev_charging_stations(data_dict)"
Expand All @@ -3197,7 +3197,7 @@
" \"uuid\": storage_params[1],\n",
" \"node\": storage_params[2],\n",
" \"e_storage\": storage_params[3],\n",
" \"em\": storage_params[4],\n",
" \"controlling_em\": storage_params[4],\n",
"}\n",
"\n",
"bs = create_storages(data_dict)"
Expand All @@ -3224,7 +3224,7 @@
" \"control_strategy\": em_params[3],\n",
"}\n",
"\n",
"emss = create_energy_management_systems(data_dict)"
"controlling_emss = create_energy_management_systems(data_dict)"
],
"id": "40b9651a2b2602fb",
"outputs": [],
Expand All @@ -3246,7 +3246,7 @@
"from pypsdm.models.input.participant.hp import HeatPumps\n",
"\n",
"participants = SystemParticipantsContainer(\n",
" ems=emss,\n",
" controlling_ems=controlling_emss,\n",
" loads=loads,\n",
" pvs=pvs,\n",
" storages=bs,\n",
Expand Down Expand Up @@ -3283,7 +3283,7 @@
" participant_uuids.extend(list(current.uuid))\n",
" node_connected_assets[node] = participant_uuids\n",
"updated_participants = SystemParticipantsContainer(\n",
" emss,\n",
" controlling_emss,\n",
" participants.loads,\n",
" participants.fixed_feed_ins,\n",
" participants.pvs,\n",
Expand Down
31 changes: 31 additions & 0 deletions pypsdm/io/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import os
import shutil
from datetime import datetime
from enum import Enum
from pathlib import Path
from random import normalvariate
from typing import Optional, Union
from uuid import UUID

import pandas as pd
from pandas import DataFrame
Expand Down Expand Up @@ -64,6 +67,21 @@ def read_csv(
return pd.read_csv(full_path, delimiter=delimiter, quotechar='"')


def delete_all_files_in_directory(directory_path):
if os.path.exists(directory_path) and os.path.isdir(directory_path):
for filename in os.listdir(directory_path):
file_path = os.path.join(directory_path, filename)
try:
if os.path.isfile(file_path) or os.path.islink(file_path):
os.unlink(file_path)
elif os.path.isdir(file_path):
shutil.rmtree(file_path)
except Exception as e:
print(f"Failed to delete {file_path}. Reason: {e}")
else:
print(f"Directory {directory_path} does not exist or is not a directory.")


def to_date_time(zoned_date_time: str) -> datetime:
"""
Converts zoned date time string with format: "yyyy-MM-dd'T'HH:mm:ss[.S[S][S]]'Z'"
Expand Down Expand Up @@ -164,3 +182,16 @@ def bool_converter(maybe_bool):
return maybe_bool.lower() == "true"
else:
raise ValueError("Cannot convert to bool: " + str(maybe_bool))


def normaldistribution(dist_params):
normal_variant = normalvariate(dist_params[0], dist_params[1])
return max(min(normal_variant, dist_params[3]), dist_params[2])


def is_valid_uuid(uuid_string):
try:
uuid_obj = UUID(uuid_string)
return str(uuid_obj) == uuid_string
except ValueError:
return False
4 changes: 2 additions & 2 deletions pypsdm/models/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_result_dict_type(self) -> Type["EntitiesResultDictMixin"]:
from pypsdm.models.result.grid.switch import SwitchesResult
from pypsdm.models.result.grid.transformer import Transformers2WResult
from pypsdm.models.result.participant.dict import (
EmsResult,
ControllingEmsResult,
EvcsResult,
EvsResult,
FixedFeedInsResult,
Expand Down Expand Up @@ -115,7 +115,7 @@ def get_result_dict_type(self) -> Type["EntitiesResultDictMixin"]:
case SystemParticipantsEnum.STORAGE:
return StoragesResult
case SystemParticipantsEnum.ENERGY_MANAGEMENT:
return EmsResult
return ControllingEmsResult
case SystemParticipantsEnum.HEAT_PUMP:
return HpsResult
case SystemParticipantsEnum.FLEX_OPTIONS:
Expand Down
Loading
Loading