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
2 changes: 1 addition & 1 deletion pypsa-earth
20 changes: 10 additions & 10 deletions scripts/build_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ def create_microgrid_shapes(microgrids_list, output_path, country_code):
# Extract the bounds of the rectangle for the current microgrid
values = microgrids_list_df.iloc[:, col]
# Define the vertices of the rectangle
Top_left = (values[0], values[3])
Top_right = (values[1], values[3])
Bottom_right = (values[1], values[2])
Bottom_left = (values[0], values[2])
Top_left = (values.iloc[0], values.iloc[3])
Top_right = (values.iloc[1], values.iloc[3])
Bottom_right = (values.iloc[1], values.iloc[2])
Bottom_left = (values.iloc[0], values.iloc[2])
# Create a Polygon shape from the rectangle's vertices
microgrid_shape = Polygon(
[Top_left, Top_right, Bottom_right, Bottom_left, Top_left]
Expand Down Expand Up @@ -93,10 +93,10 @@ def create_bus_regions(microgrids_list, output_path, country_code):
microgrid_name = microgrids_list_df.columns[col] + "_gen_bus"

# Define the vertices of the rectangle
Top_left = (values[0], values[3])
Top_right = (values[1], values[3])
Bottom_right = (values[1], values[2])
Bottom_left = (values[0], values[2])
Top_left = (values.iloc[0], values.iloc[3])
Top_right = (values.iloc[1], values.iloc[3])
Bottom_right = (values.iloc[1], values.iloc[2])
Bottom_left = (values.iloc[0], values.iloc[2])

# Create a Polygon shape from the rectangle's vertices
microgrid_shape = Polygon(
Expand All @@ -108,8 +108,8 @@ def create_bus_regions(microgrids_list, output_path, country_code):
microgrid_names.append(microgrid_name)

# Calculate the center of the rectangle
x = (values[0] + values[1]) / 2
y = (values[2] + values[3]) / 2
x = (values.iloc[0] + values.iloc[1]) / 2
y = (values.iloc[2] + values.iloc[3]) / 2
microgrid_x.append(x) # Append the x-coordinate of the center
microgrid_y.append(y) # Append the y-coordinate of the center

Expand Down
13 changes: 13 additions & 0 deletions scripts/create_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
from itertools import combinations

import xarray as xr
import geopandas as gpd
import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -244,6 +245,13 @@ def create_microgrid_network(
df.index = df["line_name"]
df.drop("line_name", axis=1, inplace=True)
n.import_components_from_dataframe(df, "Line")
for c in n.iterate_components():
# Cast all column data
c.df[:] = c.df.apply(lambda s: s.astype(object) if str(s.dtype) == "string" else s)
# Cast index
c.df.index = c.df.index.astype(object)
# Cast column names
c.df.columns = c.df.columns.astype(object)


# def add_bus_at_center(n, number_microgrids, voltage_level, line_type):
Expand Down Expand Up @@ -352,4 +360,9 @@ def create_microgrid_network(
snakemake.input["load"],
)
a = 12
print("PyPSA version:", pypsa.__version__)
print("python :", __import__("sys").version)
print("pandas :", pd.__version__)
print("numpy :", np.__version__)
print("xarray :", xr.__version__)
n.export_to_netcdf(snakemake.output[0])
4 changes: 2 additions & 2 deletions scripts/ramp_build_demand_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def create_demand_profile(

profile = pd.DataFrame(
data=data,
index=pd.date_range(start=date_start, periods=1440 * n_days, freq="T"),
index=pd.date_range(start=date_start, periods=1440 * n_days, freq="min"),
)

# Reshape to obtain hourly average values:
Expand All @@ -79,7 +79,7 @@ def create_demand_profile(
daily_profile = pd.DataFrame(
daily_profile, columns=[f"Day_{i+1}" for i in range(num_groups)]
)
date_index = pd.date_range(start="00:00", periods=24, freq="1H").time
date_index = pd.date_range(start="00:00", periods=24, freq="h").time
daily_profile.index = date_index

# Calculation of the mean value and standard deviation to represent a typical day
Expand Down
Loading