Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
- Using `NBVAL` as validation for jupyter notebooks [#351](https://github.com/ie3-institute/pypsdm/issues/351)
- Switch to `nb-clean` for removing metadata from jupyter notebooks [#365](https://github.com/ie3-institute/pypsdm/issues/365)
- Add example for Line Results to documentation [#341](https://github.com/ie3-institute/pypsdm/issues/341)
- Enrich an existing grid container by EVs and EVCS [#355](https://github.com/ie3-institute/pypsdm/issues/355)

### Changed
- Move `NBVAL` to dev dependencies [#374](https://github.com/ie3-institute/pypsdm/issues/374)
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
}
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])
Comment on lines +187 to +189
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add some documentation to this method to specify the order of the parameters.



def is_valid_uuid(uuid_string):
try:
uuid_obj = UUID(uuid_string)
return str(uuid_obj) == uuid_string
except ValueError:
return False
Loading
Loading