Skip to content

Commit

Permalink
Fix to_array_vlf
Browse files Browse the repository at this point in the history
  • Loading branch information
cwasicki committed Sep 16, 2024
1 parent 0648090 commit 75fc40d
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions py/frequenz/client/weather/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,36 +192,48 @@ def to_ndarray_vlf(
# get the location indexes of the proto for the filtered locations
if locations:
for location in locations:
found = False
for l_index, location_forecast in enumerate(
self._forecasts_pb.location_forecasts
):
if location == Location.from_pb(location_forecast.location):
location_indexes.append(l_index)
found = True
break
if not found:
location_indexes.append(-1)
else:
location_indexes = list(range(num_locations))

# get the val indexes of the proto for the filtered validity times
if validity_times:
for req_validitiy_time in validity_times:
found = False
for t_index, val_time in enumerate(
self._forecasts_pb.location_forecasts[0].forecasts
):
if req_validitiy_time == val_time.valid_at_ts.ToDatetime():
validity_times_indexes.append(t_index)
found = True
break
if not found:
validity_times_indexes.append(-1)
else:
validity_times_indexes = list(range(num_times))

# get the feature indexes of the proto for the filtered features
if features:
for req_feature in features:
found = False
for f_index, feature in enumerate(
self._forecasts_pb.location_forecasts[0].forecasts[0].features
):
if req_feature == ForecastFeature.from_pb(feature.feature):
feature_indexes.append(f_index)
found = True
break
if not found:
feature_indexes.append(-1)
else:
feature_indexes = list(range(num_features))

Expand All @@ -243,12 +255,13 @@ def to_ndarray_vlf(
array_f_index = 0

for f_index in feature_indexes:
array[array_t_index, array_l_index, array_f_index] = (
self._forecasts_pb.location_forecasts[l_index]
.forecasts[t_index]
.features[f_index]
.value
)
if l_index >= 0 and t_index >= 0 and f_index >= 0:
array[array_t_index, array_l_index, array_f_index] = (
self._forecasts_pb.location_forecasts[l_index]
.forecasts[t_index]
.features[f_index]
.value
)
array_f_index += 1

array_t_index += 1
Expand Down

0 comments on commit 75fc40d

Please sign in to comment.