diff --git a/py/frequenz/client/weather/_types.py b/py/frequenz/client/weather/_types.py index deb1809..1501496 100644 --- a/py/frequenz/client/weather/_types.py +++ b/py/frequenz/client/weather/_types.py @@ -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)) @@ -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