@@ -235,6 +235,7 @@ def incorporate_stats(self,stats):
235235
236236
237237 def apply (self ,shot ):
238+ apply_positivity (shot )
238239 m = shot .machine
239240 assert self .means [m ] is not None and self .stds [m ] is not None , "self.means or self.stds not initialized"
240241 means = np .median (self .means [m ],axis = 0 )
@@ -277,6 +278,7 @@ def load_stats(self):
277278
278279class VarNormalizer (MeanVarNormalizer ):
279280 def apply (self ,shot ):
281+ apply_positivity (shot )
280282 assert self .means is not None and self .stds is not None , "self.means or self.stds not initialized"
281283 m = shot .machine
282284 stds = np .median (self .stds [m ],axis = 0 )
@@ -301,6 +303,7 @@ def __str__(self):
301303class AveragingVarNormalizer (VarNormalizer ):
302304
303305 def apply (self ,shot ):
306+ apply_positivity (shot )
304307 super (AveragingVarNormalizer ,self ).apply (shot )
305308 window_decay = self .conf ['data' ]['window_decay' ]
306309 window_size = self .conf ['data' ]['window_size' ]
@@ -366,6 +369,7 @@ def incorporate_stats(self,stats):
366369
367370
368371 def apply (self ,shot ):
372+ apply_positivity (shot )
369373 assert (self .minimums is not None and self .maximums is not None )
370374 m = shot .machine
371375 curr_range = (self .maximums [m ] - self .minimums [m ])
@@ -403,3 +407,10 @@ def load_stats(self):
403407
404408def get_individual_shot_file (prepath ,shot_num ,ext = '.txt' ):
405409 return prepath + str (shot_num ) + ext
410+
411+
412+ def apply_positivity (shot ):
413+ for (i ,sig ) in enumerate (shot .signals ):
414+ if sig .is_strictly_positive :
415+ print ('Applying positivity constraint to {} signal' .format (sig .description ))
416+ shot .signals_dict [sig ]= np .clip (shot .signals_dict [sig ],0 ,np .inf )
0 commit comments