@@ -248,13 +248,28 @@ def handle(self, task_object: dict, **kwargs):
248248 .groupby ('id' ).agg (curve_p_min = ('p' , 'min' ), curve_p_max = ('p' , 'max' ))).reset_index ()
249249 curve_generators = generators .merge (curve_limits , on = 'id' )
250250 # low end can be zero
251- curve_generators = curve_generators [(curve_generators ['target_p' ] > curve_generators ['curve_p_max' ])]
251+ curve_generators = curve_generators [(curve_generators ['target_p' ] > curve_generators ['curve_p_max' ]) |
252+ ((curve_generators ['target_p' ] > 0 ) &
253+ (curve_generators ['target_p' ] < curve_generators ['curve_p_min' ]))]
252254 if not curve_generators .empty :
253255 logger .warning (f"Found { len (curve_generators .index )} generators for "
254- f"which p > max(reactive capacity curve(p))" )
255- # Solution 1: set max_p from curve max, it should contain p on target_p
256- # curve_generators['max_p'] = curve_generators['curve_p_max']
257- # network_pre_instance.update_generators(curve_generators[['id', 'max_p']].set_index('id'))
256+ f"which p > max(reactive capacity curve(p)) or p < min(reactive capacity curve(p))" )
257+ # in order this to work curve_p_min <= p_min <= target_p <= p_max <= curve_p_max
258+ # Solution 1: set max_p from curve max, it should contain p on target-p
259+ upper_limit_violated = curve_generators [
260+ (curve_generators ['max_p' ] > curve_generators ['curve_p_max' ])]
261+ if not upper_limit_violated .empty :
262+ logger .warning (f"Updating max p from curve for { len (upper_limit_violated .index )} generators" )
263+ upper_limit_violated ['max_p' ] = upper_limit_violated ['curve_p_max' ]
264+ network_pre_instance .update_generators (upper_limit_violated [['id' , 'max_p' ]].set_index ('id' ))
265+
266+ lower_limit_violated = curve_generators [
267+ (curve_generators ['min_p' ] < curve_generators ['curve_p_min' ])]
268+ if not lower_limit_violated .empty :
269+ logger .warning (f"Updating min p from curve for { len (lower_limit_violated .index )} generators" )
270+ lower_limit_violated ['min_p' ] = lower_limit_violated ['curve_p_min' ]
271+ network_pre_instance .update_generators (lower_limit_violated [['id' , 'min_p' ]].set_index ('id' ))
272+
258273 # Solution 2: discard generator from participating
259274 extensions = network_pre_instance .get_extensions ('activePowerControl' )
260275 remove_curve_generators = extensions .merge (curve_generators [['id' ]],
0 commit comments