<s> """<STR_LIT>""" <EOL> import copy <EOL> from functools import partial <EOL> import time <EOL> import numpy as np <EOL> import wx <EOL> import wx . lib . colourselect as csel <EOL> from wxutils import ( SimpleText , FloatCtrl , Choice , Font , pack , Button , <EOL> Check , HyperText , HLine , GridPanel , CEN , LEFT , RIGHT ) <EOL> try : <EOL> from wxmplot . colors import hexcolor <EOL> except : <EOL> pass <EOL> import larch <EOL> from larch_plugins . xrf import ( xrf_background , xrf_calib_fitrois , <EOL> xrf_calib_compute , xrf_calib_apply ) <EOL> class CalibrationFrame ( wx . Frame ) : <EOL> def __init__ ( self , parent , mca , larch = None , size = ( - <NUM_LIT:1> , - <NUM_LIT:1> ) , callback = None ) : <EOL> self . mca = mca <EOL> self . larch = larch <EOL> self . callback = callback <EOL> wx . Frame . __init__ ( self , parent , - <NUM_LIT:1> , '<STR_LIT>' , <EOL> size = size , style = wx . DEFAULT_FRAME_STYLE ) <EOL> self . SetFont ( Font ( <NUM_LIT:8> ) ) <EOL> panel = GridPanel ( self ) <EOL> self . calib_updated = False <EOL> panel . AddText ( "<STR_LIT>" , <EOL> colour = '<STR_LIT>' , dcol = <NUM_LIT:7> ) <EOL> panel . AddText ( "<STR_LIT>" , newrow = True , style = CEN ) <EOL> panel . AddText ( "<STR_LIT>" , style = CEN ) <EOL> panel . AddText ( "<STR_LIT>" , dcol = <NUM_LIT:3> , style = CEN ) <EOL> panel . AddText ( "<STR_LIT>" , dcol = <NUM_LIT:3> , style = CEN ) <EOL> panel . AddText ( "<STR_LIT:Name>" , newrow = True , style = CEN ) <EOL> panel . AddText ( "<STR_LIT>" , style = CEN ) <EOL> panel . AddText ( "<STR_LIT>" , style = CEN ) <EOL> panel . AddText ( "<STR_LIT>" , style = CEN ) <EOL> panel . AddText ( "<STR_LIT>" , style = CEN ) <EOL> panel . AddText ( "<STR_LIT>" , style = CEN ) <EOL> panel . AddText ( "<STR_LIT>" , style = CEN ) <EOL> panel . AddText ( "<STR_LIT>" , style = CEN ) <EOL> panel . AddText ( "<STR_LIT>" , style = CEN ) <EOL> panel . Add ( HLine ( panel , size = ( <NUM_LIT> , <NUM_LIT:3> ) ) , dcol = <NUM_LIT:9> , newrow = True ) <EOL> self . wids = [ ] <EOL> xrf_calib_fitrois ( mca , _larch = self . larch ) <EOL> for roi in self . mca . rois : <EOL> eknown , ecen , fwhm , amp , fit = mca . init_calib [ roi . name ] <EOL> diff = ecen - eknown <EOL> name = ( '<STR_LIT:U+0020>' + roi . name + '<STR_LIT:U+0020>' * <NUM_LIT:10> ) [ : <NUM_LIT:10> ] <EOL> opts = { '<STR_LIT>' : CEN , '<STR_LIT:size>' : ( <NUM_LIT> , - <NUM_LIT:1> ) } <EOL> w_name = SimpleText ( panel , name , ** opts ) <EOL> w_pred = SimpleText ( panel , "<STR_LIT>" % ( <NUM_LIT:1000> * eknown ) , ** opts ) <EOL> w_ccen = SimpleText ( panel , "<STR_LIT>" % ( <NUM_LIT:1000> * ecen ) , ** opts ) <EOL> w_cdif = SimpleText ( panel , "<STR_LIT>" % ( <NUM_LIT:1000> * diff ) , ** opts ) <EOL> w_cwid = SimpleText ( panel , "<STR_LIT>" % ( <NUM_LIT:1000> * fwhm ) , ** opts ) <EOL> w_ncen = SimpleText ( panel , "<STR_LIT>" , ** opts ) <EOL> w_ndif = SimpleText ( panel , "<STR_LIT>" , ** opts ) <EOL> w_nwid = SimpleText ( panel , "<STR_LIT>" , ** opts ) <EOL> w_use = Check ( panel , label = '<STR_LIT>' , size = ( <NUM_LIT> , - <NUM_LIT:1> ) , default = fwhm < <NUM_LIT> ) <EOL> panel . Add ( w_name , style = LEFT , newrow = True ) <EOL> panel . AddMany ( ( w_pred , w_ccen , w_cdif , w_cwid , <EOL> w_ncen , w_ndif , w_nwid , w_use ) ) <EOL> self . wids . append ( ( roi . name , eknown , ecen , w_ncen , w_ndif , w_nwid , w_use ) ) <EOL> panel . Add ( HLine ( panel , size = ( <NUM_LIT> , <NUM_LIT:3> ) ) , dcol = <NUM_LIT:9> , newrow = True ) <EOL> offset = <NUM_LIT> * self . mca . offset <EOL> slope = <NUM_LIT> * self . mca . slope <EOL> panel . AddText ( "<STR_LIT>" , dcol = <NUM_LIT:2> , newrow = True ) <EOL> panel . AddText ( "<STR_LIT>" ) <EOL> panel . AddText ( "<STR_LIT>" % ( offset ) , dcol = <NUM_LIT:1> , style = RIGHT ) <EOL> panel . AddText ( "<STR_LIT>" ) <EOL> panel . AddText ( "<STR_LIT>" % ( slope ) , dcol = <NUM_LIT:1> , style = RIGHT ) <EOL> panel . AddText ( "<STR_LIT>" , dcol = <NUM_LIT:2> , newrow = True ) <EOL> self . new_offset = FloatCtrl ( panel , value = offset , precision = <NUM_LIT:3> , <EOL> size = ( <NUM_LIT> , - <NUM_LIT:1> ) ) <EOL> self . new_slope = FloatCtrl ( panel , value = slope , precision = <NUM_LIT:3> , <EOL> size = ( <NUM_LIT> , - <NUM_LIT:1> ) ) <EOL> panel . AddText ( "<STR_LIT>" ) <EOL> panel . Add ( self . new_offset , dcol = <NUM_LIT:1> , style = RIGHT ) <EOL> panel . AddText ( "<STR_LIT>" ) <EOL> panel . Add ( self . new_slope , dcol = <NUM_LIT:1> , style = RIGHT ) <EOL> panel . Add ( Button ( panel , '<STR_LIT>' , <EOL> size = ( <NUM_LIT> , - <NUM_LIT:1> ) , action = self . onCalibrate ) , <EOL> dcol = <NUM_LIT:2> , newrow = True ) <EOL> panel . Add ( Button ( panel , '<STR_LIT>' , <EOL> size = ( <NUM_LIT> , - <NUM_LIT:1> ) , action = self . onUseCalib ) , <EOL> dcol = <NUM_LIT:2> , style = RIGHT ) <EOL> panel . Add ( Button ( panel , '<STR_LIT>' , <EOL> size = ( <NUM_LIT> , - <NUM_LIT:1> ) , action = self . onClose ) , <EOL> dcol = <NUM_LIT:2> , style = RIGHT ) <EOL> panel . pack ( ) <EOL> a = panel . GetBestSize ( ) <EOL> self . SetSize ( ( a [ <NUM_LIT:0> ] + <NUM_LIT> , a [ <NUM_LIT:1> ] + <NUM_LIT:50> ) ) <EOL> self . Show ( ) <EOL> self . Raise ( ) <EOL> def onCalibrate ( self , event = None ) : <EOL> x , y = [ ] , [ ] <EOL> mca = self . mca <EOL> old_calib = mca . offset , mca . slope <EOL> init_calib = copy . deepcopy ( mca . init_calib ) <EOL> for roiname , eknown , ecen , w_ncen , w_ndif , w_nwid , w_use in self . wids : <EOL> if not w_use . IsChecked ( ) : <EOL> mca . init_calib . pop ( roiname ) <EOL> xrf_calib_compute ( mca , apply = True , _larch = self . larch ) <EOL> offset , slope = mca . new_calib <EOL> self . calib_updated = True <EOL> self . new_offset . SetValue ( "<STR_LIT>" % ( <NUM_LIT:1000> * offset ) ) <EOL> self . new_slope . SetValue ( "<STR_LIT>" % ( <NUM_LIT:1000> * slope ) ) <EOL> xrf_calib_fitrois ( mca , _larch = self . larch ) <EOL> for roi in self . mca . rois : <EOL> eknown , ecen , fwhm , amp , fit = mca . init_calib [ roi . name ] <EOL> diff = ecen - eknown <EOL> for roiname , eknown , ocen , w_ncen , w_ndif , w_nwid , w_use in self . wids : <EOL> if roiname == roi . name : <EOL> w_ncen . SetLabel ( "<STR_LIT>" % ( <NUM_LIT:1000> * ecen ) ) <EOL> w_ndif . SetLabel ( "<STR_LIT>" % ( <NUM_LIT:1000> * diff ) ) <EOL> w_nwid . SetLabel ( "<STR_LIT>" % ( <NUM_LIT:1000> * fwhm ) ) <EOL> break <EOL> xrf_calib_apply ( mca , offset = old_calib [ <NUM_LIT:0> ] , slope = old_calib [ <NUM_LIT:1> ] , <EOL> _larch = self . larch ) <EOL> mca . init_calib = init_calib <EOL> tsize = self . GetSize ( ) <EOL> self . SetSize ( ( tsize [ <NUM_LIT:0> ] + <NUM_LIT:1> , tsize [ <NUM_LIT:1> ] ) ) <EOL> self . SetSize ( ( tsize [ <NUM_LIT:0> ] , tsize [ <NUM_LIT:1> ] ) ) <EOL> def onUseCalib ( self , event = None ) : <EOL> mca = self . mca <EOL> offset = float ( self . new_offset . GetValue ( ) ) <EOL> slope = float ( self . new_slope . GetValue ( ) ) <EOL> mca . new_calib = offset , slope <EOL> xrf_calib_apply ( mca , offset = offset , slope = slope , _larch = self . larch ) <EOL> if hasattr ( self . callback , '<STR_LIT>' ) : <EOL> self . callback ( offset , slope , mca = mca ) <EOL> self . Destroy ( ) <EOL> def onClose ( self , event = None ) : <EOL> self . Destroy ( ) <EOL> class ColorsFrame ( wx . Frame ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent , size = ( <NUM_LIT> , <NUM_LIT> ) , ** kws ) : <EOL> self . parent = parent <EOL> conf = parent . conf <EOL> kws [ '<STR_LIT>' ] = wx . DEFAULT_FRAME_STYLE <EOL> wx . Frame . __init__ ( self , parent , - <NUM_LIT:1> , size = size , <EOL> title = '<STR_LIT>' , ** kws ) <EOL> panel = GridPanel ( self ) <EOL> panel . SetFont ( Font ( <NUM_LIT:11> ) ) <EOL> def add_color ( panel , name ) : <EOL> cval = hexcolor ( getattr ( conf , name ) ) <EOL> c = csel . ColourSelect ( panel , - <NUM_LIT:1> , "<STR_LIT>" , cval , size = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> c . Bind ( csel . EVT_COLOURSELECT , partial ( self . onColor , item = name ) ) <EOL> return c <EOL> SX = <NUM_LIT> <EOL> def scolor ( txt , attr , ** kws ) : <EOL> panel . AddText ( txt , size = ( SX , - <NUM_LIT:1> ) , style = LEFT , font = Font ( <NUM_LIT:11> ) , ** kws ) <EOL> panel . Add ( add_color ( panel , attr ) , style = LEFT ) <EOL> panel . AddText ( '<STR_LIT>' , dcol = <NUM_LIT:4> , colour = '<STR_LIT>' ) <EOL> panel . Add ( HLine ( panel , size = ( <NUM_LIT> , <NUM_LIT:3> ) ) , dcol = <NUM_LIT:4> , newrow = True ) <EOL> scolor ( '<STR_LIT>' , '<STR_LIT>' , newrow = True ) <EOL> scolor ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> scolor ( '<STR_LIT>' , '<STR_LIT>' , newrow = True ) <EOL> scolor ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> scolor ( '<STR_LIT>' , '<STR_LIT>' , newrow = True ) <EOL> scolor ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> scolor ( '<STR_LIT>' , '<STR_LIT>' , newrow = True ) <EOL> scolor ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> scolor ( '<STR_LIT>' , '<STR_LIT>' , newrow = True ) <EOL> scolor ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> panel . Add ( HLine ( panel , size = ( <NUM_LIT> , <NUM_LIT:3> ) ) , dcol = <NUM_LIT:4> , newrow = True ) <EOL> panel . Add ( Button ( panel , '<STR_LIT>' , size = ( <NUM_LIT> , - <NUM_LIT:1> ) , action = self . onDone ) , <EOL> dcol = <NUM_LIT:2> , newrow = True ) <EOL> panel . pack ( ) <EOL> self . SetMinSize ( panel . GetBestSize ( ) ) <EOL> self . Show ( ) <EOL> self . Raise ( ) <EOL> def onColor ( self , event = None , item = None ) : <EOL> color = hexcolor ( event . GetValue ( ) ) <EOL> setattr ( self . parent . conf , item , color ) <EOL> if item == '<STR_LIT>' : <EOL> self . parent . panel . conf . set_trace_color ( color , trace = <NUM_LIT:0> ) <EOL> elif item == '<STR_LIT>' : <EOL> self . parent . panel . conf . set_trace_color ( color , trace = <NUM_LIT:1> ) <EOL> elif item == '<STR_LIT>' : <EOL> for lmark in self . parent . cursor_markers : <EOL> if lmark is not None : <EOL> lmark . set_color ( color ) <EOL> elif item == '<STR_LIT>' and self . parent . roi_patch is not None : <EOL> self . parent . roi_patch . set_color ( color ) <EOL> elif item == '<STR_LIT>' : <EOL> for l in self . parent . major_markers : <EOL> l . set_color ( color ) <EOL> elif item == '<STR_LIT>' : <EOL> for l in self . parent . minor_markers : <EOL> l . set_color ( color ) <EOL> elif item == '<STR_LIT>' : <EOL> for l in self . parent . hold_markers : <EOL> l . set_color ( color ) <EOL> self . parent . panel . canvas . draw ( ) <EOL> self . parent . panel . Refresh ( ) <EOL> def onDone ( self , event = None ) : <EOL> self . Destroy ( ) <EOL> class XrayLinesFrame ( wx . Frame ) : <EOL> """<STR_LIT>""" <EOL> k1lines = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> k2lines = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> l1lines = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> l2lines = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> l3lines = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> mlines = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , parent , size = ( <NUM_LIT> , <NUM_LIT> ) , ** kws ) : <EOL> self . parent = parent <EOL> conf = parent . conf <EOL> kws [ '<STR_LIT>' ] = wx . DEFAULT_FRAME_STYLE <EOL> wx . Frame . __init__ ( self , parent , - <NUM_LIT:1> , size = size , <EOL> title = '<STR_LIT>' , ** kws ) <EOL> panel = GridPanel ( self ) <EOL> self . checkbox = { } <EOL> def add_elines ( panel , lines , checked ) : <EOL> for i in lines : <EOL> cb = Check ( panel , '<STR_LIT>' % i , default = i in checked , <EOL> action = partial ( self . onLine , label = i , lines = checked ) ) <EOL> self . checkbox [ i ] = cb <EOL> panel . Add ( cb , style = LEFT ) <EOL> hopts = { '<STR_LIT:size>' : ( <NUM_LIT> , - <NUM_LIT:1> ) , '<STR_LIT>' : ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:200> ) } <EOL> labopts = { '<STR_LIT>' : True , '<STR_LIT>' : LEFT } <EOL> self . linedata = { '<STR_LIT>' : self . k1lines , <EOL> '<STR_LIT>' : self . k2lines , <EOL> '<STR_LIT>' : self . l1lines , <EOL> '<STR_LIT>' : self . l2lines + self . l3lines , <EOL> '<STR_LIT>' : self . mlines } <EOL> panel . AddText ( '<STR_LIT>' , dcol = <NUM_LIT:4> , colour = '<STR_LIT>' ) <EOL> panel . Add ( HLine ( panel , size = ( <NUM_LIT> , <NUM_LIT:3> ) ) , dcol = <NUM_LIT:5> , newrow = True ) <EOL> panel . Add ( HyperText ( panel , '<STR_LIT>' , <EOL> action = partial ( self . ToggleLines , lines = conf . K_major ) , <EOL> ** hopts ) , ** labopts ) <EOL> add_elines ( panel , self . k1lines , conf . K_major ) <EOL> panel . Add ( HyperText ( panel , '<STR_LIT>' , <EOL> action = partial ( self . ToggleLines , lines = conf . K_minor ) , <EOL> ** hopts ) , ** labopts ) <EOL> add_elines ( panel , self . k2lines , conf . K_minor ) <EOL> panel . Add ( HyperText ( panel , '<STR_LIT>' , <EOL> action = partial ( self . ToggleLines , lines = conf . L_major ) , <EOL> ** hopts ) , ** labopts ) <EOL> add_elines ( panel , self . l1lines , conf . L_major ) <EOL> panel . Add ( HyperText ( panel , '<STR_LIT>' , <EOL> action = partial ( self . ToggleLines , lines = conf . L_minor ) , <EOL> ** hopts ) , ** labopts ) <EOL> add_elines ( panel , self . l2lines , conf . L_minor ) <EOL> panel . AddText ( '<STR_LIT:U+0020>' , ** labopts ) <EOL> add_elines ( panel , self . l3lines , conf . L_minor ) <EOL> panel . Add ( HyperText ( panel , '<STR_LIT>' , <EOL> action = partial ( self . ToggleLines , lines = conf . M_major ) , <EOL> ** hopts ) , ** labopts ) <EOL> add_elines ( panel , self . mlines , conf . M_major ) <EOL> panel . AddText ( '<STR_LIT>' , ** labopts ) <EOL> fopts = { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:1000> , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT:size>' : ( <NUM_LIT> , - <NUM_LIT:1> ) } <EOL> panel . Add ( FloatCtrl ( panel , value = conf . e_min , <EOL> action = partial ( self . onErange , is_max = False ) , <EOL> ** fopts ) , dcol = <NUM_LIT:2> , style = LEFT ) <EOL> panel . AddText ( '<STR_LIT>' ) <EOL> panel . Add ( FloatCtrl ( panel , value = conf . e_max , <EOL> action = partial ( self . onErange , is_max = True ) , <EOL> ** fopts ) , dcol = <NUM_LIT:2> , style = LEFT ) <EOL> panel . Add ( HLine ( panel , size = ( <NUM_LIT> , <NUM_LIT:3> ) ) , dcol = <NUM_LIT:5> , newrow = True ) <EOL> panel . Add ( Button ( panel , '<STR_LIT>' , size = ( <NUM_LIT> , - <NUM_LIT:1> ) , action = self . onDone ) , <EOL> newrow = True , style = LEFT ) <EOL> panel . pack ( ) <EOL> self . Show ( ) <EOL> self . Raise ( ) <EOL> def ToggleLines ( self , label = None , event = None , lines = [ ] , ** kws ) : <EOL> if not event . leftIsDown : <EOL> self . parent . Freeze ( ) <EOL> for line in self . linedata . get ( label , [ ] ) : <EOL> check = not self . checkbox [ line ] . IsChecked ( ) <EOL> self . checkbox [ line ] . SetValue ( { True : <NUM_LIT:1> , False : <NUM_LIT:0> } [ check ] ) <EOL> self . onLine ( checked = check , label = line , lines = lines ) <EOL> self . parent . Thaw ( ) <EOL> def onLine ( self , event = None , checked = None , label = None , lines = [ ] ) : <EOL> if checked is None : <EOL> try : <EOL> checked = event . IsChecked ( ) <EOL> except : <EOL> pass <EOL> if checked is None : checked = False <EOL> if label in lines and not checked : <EOL> lines . remove ( label ) <EOL> elif label not in lines and checked : <EOL> lines . append ( label ) <EOL> if self . parent . selected_elem is not None : <EOL> self . parent . onShowLines ( elem = self . parent . selected_elem ) <EOL> def onErange ( self , event = None , value = None , is_max = True ) : <EOL> if value is None : return <EOL> val = float ( value ) <EOL> if is_max : <EOL> self . parent . conf . e_max = val <EOL> else : <EOL> self . parent . conf . e_min = val <EOL> if self . parent . selected_elem is not None : <EOL> self . parent . onShowLines ( elem = self . parent . selected_elem ) <EOL> def onDone ( self , event = None ) : <EOL> self . Destroy ( ) <EOL> class XRFDisplayConfig : <EOL> emph_elinecolor = '<STR_LIT>' <EOL> major_elinecolor = '<STR_LIT>' <EOL> minor_elinecolor = '<STR_LIT>' <EOL> hold_elinecolor = '<STR_LIT>' <EOL> marker_color = '<STR_LIT>' <EOL> roi_fillcolor = '<STR_LIT>' <EOL> roi_color = '<STR_LIT>' <EOL> spectra_color = '<STR_LIT>' <EOL> spectra2_color = '<STR_LIT>' <EOL> bgr_color = '<STR_LIT>' <EOL> K_major = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> K_minor = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> K_minor = [ ] <EOL> L_major = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> L_minor = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> L_minor = [ ] <EOL> M_major = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> e_min = <NUM_LIT> <EOL> e_max = <NUM_LIT> <EOL> class ROI_Averager ( ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , nsamples = <NUM_LIT:11> ) : <EOL> self . clear ( nsamples = nsamples ) <EOL> def clear ( self , nsamples = <NUM_LIT:11> ) : <EOL> self . nsamples = nsamples <EOL> self . index = - <NUM_LIT:1> <EOL> self . lastval = <NUM_LIT:0> <EOL> self . toffset = time . time ( ) <EOL> self . data = np . zeros ( self . nsamples , dtype = np . float32 ) <EOL> self . times = - np . ones ( self . nsamples , dtype = np . float32 ) <EOL> def append ( self , value ) : <EOL> "<STR_LIT>" <EOL> idx = self . index = ( self . index + <NUM_LIT:1> ) % self . data . size <EOL> self . data [ idx ] = max ( <NUM_LIT:0> , value - self . lastval ) <EOL> self . lastval = value <EOL> dt = time . time ( ) - self . toffset <EOL> if ( idx == <NUM_LIT:0> and max ( self . times ) < <NUM_LIT:0> ) : <EOL> dt = <NUM_LIT:0> <EOL> self . times [ idx ] = dt <EOL> def update ( self , value ) : <EOL> self . append ( value ) <EOL> def get_mean ( self ) : <EOL> valid = np . where ( self . times > <NUM_LIT:0> ) [ <NUM_LIT:0> ] <EOL> return self . data [ valid ] . mean ( ) <EOL> def get_cps ( self ) : <EOL> valid = np . where ( self . times > <NUM_LIT:0> ) [ <NUM_LIT:0> ] <EOL> if len ( valid ) < <NUM_LIT:1> or self . times [ valid ] . ptp ( ) < <NUM_LIT:0.5> : <EOL> return <NUM_LIT:0> <EOL> return self . data [ valid ] . sum ( ) / self . times [ valid ] . ptp ( ) </s>
