Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.

Commit c025bb4

Browse files
committed
fix for database
1 parent d8668d6 commit c025bb4

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

ocf_datapipes/load/gsp/database.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,11 @@ def __iter__(self) -> xr.DataArray:
5959
gsp_id_to_shape = get_gsp_shape_from_eso(return_filename=False)
6060

6161
# Ensure the centroids have the same GSP ID index as the GSP PV power:
62-
logger.debug(gsp_pv_power_mw_df.columns)
63-
logger.debug(gsp_pv_power_mw_df)
64-
logger.debug(gsp_id_to_shape)
6562
gsp_id_to_shape = gsp_id_to_shape.loc[gsp_pv_power_mw_df.columns]
6663

6764
data_array = put_gsp_data_into_an_xr_dataarray(
6865
gsp_pv_power_mw=gsp_pv_power_mw_df.astype(np.float32),
69-
time_utc=gsp_pv_power_mw_df.index,
66+
time_utc=gsp_pv_power_mw_df.index.values,
7067
gsp_id=gsp_pv_power_mw_df.columns,
7168
# TODO: Try using `gsp_id_to_shape.geometry.envelope.centroid`. See issue #76.
7269
x_osgb=gsp_id_to_shape.geometry.centroid.x.astype(np.float32),
@@ -76,6 +73,7 @@ def __iter__(self) -> xr.DataArray:
7673

7774
del gsp_id_to_shape, gsp_pv_power_mw_df
7875
while True:
76+
logger.debug(data_array)
7977
yield data_array
8078

8179

@@ -98,6 +96,8 @@ def get_gsp_power_from_database(
9896

9997
logger.info("Loading GSP data from database")
10098
logger.debug(f"{history_duration=}")
99+
logger.debug(f"{interpolate_minutes=}")
100+
logger.debug(f"{load_extra_minutes=}")
101101

102102
extra_duration = timedelta(minutes=load_extra_minutes)
103103
now = pd.to_datetime(datetime.now(tz=timezone.utc)).floor("30T")
@@ -153,10 +153,12 @@ def get_gsp_power_from_database(
153153
["datetime_utc", "gsp_id", "solar_generation_mw", "installed_capacity_mw"]
154154
]
155155
logger.debug(gsp_yields_df.columns)
156+
logger.debug(gsp_yields_df.index)
156157
gsp_yields_df.drop_duplicates(
157158
["datetime_utc", "gsp_id", "solar_generation_mw"], keep="last", inplace=True
158159
)
159160
logger.debug(gsp_yields_df.columns)
161+
logger.debug(gsp_yields_df.index)
160162
gsp_power_df = gsp_yields_df.pivot(
161163
index="datetime_utc", columns="gsp_id", values="solar_generation_mw"
162164
)

ocf_datapipes/production/power_perceiver.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ def power_perceiver_production_datapipe(configuration_filename: Union[Path, str]
8484
interpolate_minutes=configuration.input_data.gsp.live_interpolate_minutes,
8585
load_extra_minutes=configuration.input_data.gsp.live_load_extra_minutes,
8686
)
87-
8887
logger.debug("Normalize GSP data")
8988
gsp_datapipe = gsp_datapipe.normalize(
9089
normalize_fn=lambda x: x / x.capacity_megawatt_power

tests/config/test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ git: null
55
input_data:
66
gsp:
77
gsp_zarr_path: tests/data/gsp/test.zarr
8+
history_minutes: 120
89
nwp:
910
nwp_channels:
1011
- t

tests/conftest.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,17 +227,19 @@ def pv_yields_and_systems(db_session):
227227
def gsp_yields(db_session):
228228
"""Make fake GSP data"""
229229

230-
gsp_sql_1: LocationSQL = Location(gsp_id=1, label="GSP_1", installed_capacity_mw=1).to_orm()
231-
232230
gsp_yield_sqls = []
233-
for hour in range(0, 8):
234-
for minute in range(0, 60, 30):
235-
gsp_yield_1 = GSPYield(
236-
datetime_utc=datetime(2022, 1, 1, hour, minute), solar_generation_kw=hour + minute
237-
)
238-
gsp_yield_1_sql = gsp_yield_1.to_orm()
239-
gsp_yield_1_sql.location = gsp_sql_1
240-
gsp_yield_sqls.append(gsp_yield_1_sql)
231+
for gsp_id in range(1,3):
232+
gsp_sql_1: LocationSQL = Location(gsp_id=gsp_id, label="GSP_1", installed_capacity_mw=1).to_orm()
233+
234+
gsp_yield_sqls = []
235+
for hour in range(0, 8):
236+
for minute in range(0, 60, 30):
237+
gsp_yield_1 = GSPYield(
238+
datetime_utc=datetime(2022, 1, 1, hour, minute), solar_generation_kw=hour + minute
239+
)
240+
gsp_yield_1_sql = gsp_yield_1.to_orm()
241+
gsp_yield_1_sql.location = gsp_sql_1
242+
gsp_yield_sqls.append(gsp_yield_1_sql)
241243

242244
# add to database
243245
db_session.add_all(gsp_yield_sqls)

tests/production/test_pp_production.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_pp_production_datapipe(pv_yields_and_systems, gsp_yields):
2121
assert len(batch[BatchKey.nwp_target_time_utc][0]) == 3
2222
assert len(batch[BatchKey.nwp_init_time_utc][0]) == 3
2323
assert len(batch[BatchKey.pv_time_utc][0]) == 19
24-
assert len(batch[BatchKey.gsp_time_utc][0]) == 4 # 1 history + now + 2 future = 4
24+
assert len(batch[BatchKey.gsp_time_utc][0]) == 7 # 4 history + now + 2 future = 4
2525

2626
assert batch[BatchKey.hrvsatellite_actual].shape == (
2727
4,
@@ -32,5 +32,5 @@ def test_pp_production_datapipe(pv_yields_and_systems, gsp_yields):
3232
) # 2nd dim is 6 history + now
3333
assert batch[BatchKey.nwp].shape == (4, 3, 1, 2, 2) # 2nd dim is 1 history + now + 1 future
3434
assert batch[BatchKey.pv].shape == (4, 7, 32) # 2nd dim is 6 history + now
35-
assert batch[BatchKey.gsp].shape == (4, 2, 1) # 2nd dim is 1 history + now
35+
assert batch[BatchKey.gsp].shape == (4, 5, 1) # 2nd dim is 4 history + now
3636
assert batch[BatchKey.hrvsatellite_surface_height].shape == (4, 64, 64)

0 commit comments

Comments
 (0)