Skip to content

Commit

Permalink
Merge pull request #287 from openego/features/#218-simbev-map-function
Browse files Browse the repository at this point in the history
Changed read in of SimBEV CSVs
  • Loading branch information
khelfen committed Sep 26, 2022
2 parents 04805fb + fbc4c3d commit 298801f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
40 changes: 17 additions & 23 deletions edisgo/io/electromobility_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,42 +208,36 @@ def read_csvs_charging_processes(csv_path, mode="frugal", csv_dir="simbev_run"):

files.sort()

charging_processes_df_list = []

for car_id, f in enumerate(files):
# wrapper function for csv files read in with map_except function
def rd_csv(file):
ags = int(file[1].parts[-2])
car_id = file[0]
try:
df = pd.read_csv(f, index_col=[0])

if mode == "frugal":
df = df.loc[df.chargingdemand_kWh > 0]

df = df.rename(columns={"location": "destination"})
return pd.read_csv(file[1]).assign(ags=ags, car_id=car_id)
except Exception:
logger.warning(
f"File '{str(file[1]).split('/')[-1]}' couldn't be read and is skipped."
)

df = df.assign(ags=int(f.parts[-2]), car_id=car_id)
return pd.DataFrame()

df = df[COLUMNS["charging_processes_df"]].astype(
DTYPES["charging_processes_df"]
)
df = pd.concat(map(rd_csv, list(enumerate(files))), ignore_index=True)

charging_processes_df_list.append(df)
if mode == "frugal":
df = df.loc[df.chargingdemand_kWh > 0]

except Exception:
logger.warning(f"File {f} couldn't be read and is skipped.")
df = df.rename(columns={"location": "destination"})

charging_processes_df = pd.concat(charging_processes_df_list, ignore_index=True)[
COLUMNS["charging_processes_df"]
].astype(DTYPES["charging_processes_df"])
df = df[COLUMNS["charging_processes_df"]].astype(DTYPES["charging_processes_df"])

charging_processes_df = pd.merge(
charging_processes_df,
return pd.merge(
df,
pd.DataFrame(columns=COLUMNS["matching_demand_and_location"]),
how="outer",
left_index=True,
right_index=True,
)

return charging_processes_df


def read_simbev_config_df(
path, edisgo_obj, simbev_config_file="metadata_simbev_run.json"
Expand Down
1 change: 0 additions & 1 deletion edisgo/network/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

if "READTHEDOCS" not in os.environ:
from shapely.geometry import Point

from edisgo.io.electromobility_import import determine_grid_connection_capacity
from edisgo.tools.geo import find_nearest_bus

Expand Down

0 comments on commit 298801f

Please sign in to comment.