Skip to content
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

Abg/update metadata #76

Merged
merged 12 commits into from
Dec 8, 2023
Prev Previous commit
Next Next commit
Update psr_metadata database and seed
Input example data now comes from a JSON file since that
allows adding the nested PSR metadata in a simple and
human-readable way

Signed-off-by: Andre <andberna@outlook.es>
  • Loading branch information
AndBerna committed Nov 22, 2023
commit 59f765401c23b2c9c7e99fa0ac33360e67e110fc
159 changes: 159 additions & 0 deletions power_systems_data_api_demonstrator/data/example/psr_metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
[
{
"id": "US-WECC-BANC",
"topology_level": 1,
"transmission_capacity": [
{
"connectedPSR": "US-WECC-CISO",
"unit": "MW",
"value": 700
}
],
"fuelSource_capacity": [
{
"type": "Renewable-Heat-Solar-Unespecified",
"technology": "Solar-Photovoltaic-Classic silicon",
"unit": "MW",
"capacity": [
{
"value": 500,
"startDatetime": "10/10/2017"
}
]
},
{
"type": "Renewable-Mechanical source or other-Wind-Unespecified",
"technology": "Wind-Offshore-Unespecified",
"unit": "MW",
"capacity": [
{
"value": 500,
"startDatetime": "28/02/2016"
}
]
}
]
},
{
"id": "US-WECC-PACW",
"topology_level": 1,
"transmission_capacity": [
{
"connectedPSR": "US-WECC-CISO",
"unit": "MW",
"value": 1000
}
],
"fuelSource_capacity": [
{
"type": "Renewable-Mechanical source or other-Wind-Unespecified",
"technology": "Wind-Onshore-Unespecified",
"unit": "MW",
"capacity": [
{
"value": 1000,
"startDatetime": "1/1/2017"
}
]
},
{
"type": "Nuclear-Solid-Radiactive fuel-UOX",
"technology": "Thermal-Steam Turbine with condensation turbine-Unespecified",
"unit": "MW",
"capacity": [
{
"value": 800,
"startDatetime": "10/15/1975",
"endDatetime": "31/12/2016"
}
]
}
]
},
{
"id": "US-WECC-CISO",
"topology_level": 1,
"transmission_capacity": [
{
"connectedPSR": "US-WECC-BANC",
"unit": "MW",
"value": 700
},
{
"connectedPSR": "US-WECC-PACW",
"unit": "MW",
"value": 1000
}
],
"fuelSource_capacity": [
{
"type": "Renewable-Heat-Solar-Unespecified",
"technology": "Solar-Photovoltaic-Classic silicon",
"unit": "MW",
"capacity": [
{
"value": 500,
"startDatetime": "10/15/2020"
}
]
},
{
"type": "Fossil-Solid-Hard Coal-Antracite",
"technology": "Thermal-Steam Turbine with condensation turbine-Unespecified",
"unit": "MW",
"capacity": [
{
"value": 1000,
"startDatetime": "13/12/1999"
},
{
"value": 500,
"startDatetime": "15/10/1980",
"endDatetime": "12/12/1999"
}
]
}
]
},
{
"id": "US-WECC-AZPS",
"topology_level": 2,
"parent": "US-WECC-CISO",
"fuelSource_capacity": [
{
"type": "Renewable-Heat-Solar-Unespecified",
"technology": "Solar-Photovoltaic-Classic silicon",
"unit": "MW",
"capacity": [
{
"value": 500,
"startDatetime": "10/15/2020"
}
]
}
]
},
{
"id": "US-WECC-CEN",
"topology_level": 2,
"parent": "US-WECC-CISO",
"fuelSource_capacity": [
{
"type": "Fossil-Solid-Hard Coal-Antracite",
"technology": "Thermal-Steam Turbine with condensation turbine-Unespecified",
"unit": "MW",
"capacity": [
{
"value": 1000,
"startDatetime": "13/12/1999"
},
{
"value": 500,
"startDatetime": "15/10/1980",
"endDatetime": "12/12/1999"
}
]
}
]
}
]
38 changes: 29 additions & 9 deletions power_systems_data_api_demonstrator/src/api/seed.py
Original file line number Diff line number Diff line change
@@ -85,22 +85,42 @@ def seed_fuelsource(session: Session) -> None:

def seed_psr(session: Session) -> None:
for grid_source in ["example"]:
df = pd.read_csv(os.path.join(DATA_DIR, grid_source, "psr_metadata.csv"))
df = pd.read_json(os.path.join(DATA_DIR, grid_source, "psr_metadata.json"))

psr_data = []
psr_list = df.groupby(["Grid Node"]).first().reset_index()

for index, row in psr_list.iterrows():
psr_data.extend([PSRList(id=row["Grid Node"], level=row["Topology Level"])])
for index, row in df.iterrows():
psr_data.extend([PSRList(id=row["id"], level=row["topology_level"])])

# extract transmission data from the dataframe dict
transmission_capacity = []
for index, row in df.iterrows():
# select only the rows with transmission capacity data
df_transmission = df.dropna(subset=["transmission_capacity"]).copy()
df_transmission = df_transmission[["id", "transmission_capacity"]]
# explode the transmission capacity list
df_transmission = df_transmission.explode("transmission_capacity")
# convert the dict to columns
transmission_data = (
df_transmission["transmission_capacity"].apply(pd.Series).reset_index(drop=True)
)
# remove the transmission_capacity column
df_transmission = df_transmission.drop("transmission_capacity", axis=1)
df_transmission = df_transmission.reset_index(drop=True)
# join the two dataframes
df_transmission = df_transmission.join(transmission_data)
print(df_transmission)

for index, row in df_transmission.iterrows():
print(row)
print(row["value"])
print(type(row["value"]))
transmission_capacity.extend(
[
PSRInterconnectionTable(
id=row["Grid Node"],
connectedPSR=row["Connected Node"],
unit=row["Unit"],
value=row["Capacity"],
id=row["id"],
unit=row["unit"],
connectedPSR=row["connectedPSR"],
value=row["value"],
)
]
)