def chooseVariables(self): """Opens a dialog asking user to select columns from a data File that has been selected. THese are then returned as a string suitable for Y cols input""" columns = self.physics.variables.keys() columns.sort() values = zip(range(0, len(columns)), columns) checklist_group = traitsui.Group( '10', # insert vertical space traitsui.Label('Select the additional variables you wish to log'), traitsui.UItem('columns', style='custom', editor=traitsui.CheckListEditor(values=values, cols=6)), traitsui.UItem('selectAllButton')) traits_view = traitsui.View(checklist_group, title='CheckListEditor', buttons=['OK'], resizable=True, kind='livemodal') col = ColumnEditor(numberOfColumns=len(columns)) try: col.columns = [ columns.index(varName) for varName in self.xmlLogVariables ] except Exception as e: logger.error( "couldn't selected correct variable names. Returning empty selection" ) logger.error("%s " % e.message) col.columns = [] col.edit_traits(view=traits_view) logger.debug("value of columns selected = %s ", col.columns) logger.debug("value of columns selected = %s ", [columns[i] for i in col.columns]) return [columns[i] for i in col.columns]
class ADC(traits.HasTraits): refreshTime = traits.Float( 0.1, desc="how often to update the frequencies in seconds") logFile = traits.File rpiADCLogFolder = traits.String averageN = traits.Int(100) VMax = traits.Enum(3.3, 5.0) channelList = traits.List( [1, 3, 5, 6], desc="list of channels to show frequencies for and query") channelValues = [(0, 'Ch 0'), (1, 'Ch 1'), (2, 'Ch 2'), (3, 'Ch 3'), (4, 'Ch 4'), (5, 'Ch 5'), (6, 'Ch 6'), (7, 'Ch 7')] #THIS ONLY WORKS IF PyHWI can be found! it is in the python path manager for lab-Monitoring-0 connection = rpiADCClient.Connection() #if there are problems check the server is running on 192.168.0.111 icon_trait = pyface.image_resource.ImageResource('icons/wavemeter.png') #oscilloscope = None currentLocalTime = time.localtime() currentYear = currentLocalTime.tm_year currentMonth = currentLocalTime.tm_mon currentDay = currentLocalTime.tm_mday channel0 = ADCChannel(channelNumber=0, connection=connection, channelName="Na Cavity Lock", channelMessageHigh="Na Cavity Locked", channelMessageLow="Na Cavity Out of Lock", criticalValue=1.5, highIsGood=True, highSoundFile="NaLocked.wav", lowSoundFile="NaOutOfLock.wav") channel1 = ADCChannel(channelNumber=1, connection=connection, channelName="Li MOT Fluorescence", channelMessageHigh="MOT Loading", channelMessageLow="No MOT", criticalValue=0.1) channel2 = ADCChannel( channelNumber=2, connection=connection, channelName="Li MOT Power (stable)") #changed by Martin channel3 = ADCChannel(channelNumber=3, connection=connection, channelName="Li MOT (unstable)") channel4 = ADCChannel(channelNumber=4, connection=connection, channelName="Na MOT Power (stable)") channel5 = ADCChannel(channelNumber=5, connection=connection, channelName="Na MOT Flourescence") channel6 = ADCChannel(channelNumber=6, connection=connection, channelName="ZS light Power") channel7 = ADCChannel(channelNumber=7, connection=connection, channelName="disconnected") channels = { 0: channel0, 1: channel1, 2: channel2, 3: channel3, 4: channel4, 5: channel5, 6: channel6, 7: channel7 } def __init__(self, **traitsDict): """Called when object initialises. Starts timer etc. """ print "Instantiating GUI.." super(ADC, self).__init__(**traitsDict) self.connection.connect() self.oscilloscope = Oscilloscope(connection=self.connection, resolution=self.refreshTime, visibleChannels=self.channelList) self.start_timer() def start_timer(self): """Called in init if user selected live update mode, otherwise called from menu action. Every self.wizard.updateRateSeconds, self._refresh_data_action will be called""" print "Timer Object Started. Will update ADC Information every %s seconds" % self.refreshTime self.timer = Timer( float(self.refreshTime) * 1000, self._refresh_Visible_channels) def _refreshTime_changed(self): self.timer.setInterval(float(self.refreshTime) * 1000) print "will update ADC every %s seconds" % (float(self.refreshTime)) self.oscilloscope.resolution = self.refreshTime #use refresh time to set resolution of oscilloscope def _logFile_changed(self): self._create_log_file() def _channelList_changed(self): """push changes to visible channels in oscilloscope """ self.oscilloscope.visibleChannels = self.channelList def _logFile_default(self): """default log file has date stamp. log file is changed once a day """ print "choosing default log file" return os.path.join( self.rpiADCLogFolder, time.strftime("rpiADC-%Y-%m-%d.csv", self.currentLocalTime)) def getGroupFolder(self): """returns the location of the group folder. supports both linux and windows. assumes it is mounted to /media/ursa/AQOGroupFolder for linux""" if platform.system() == "Windows": groupFolder = os.path.join("\\\\ursa", "AQOGroupFolder") if platform.system() == "Linux": groupFolder = os.path.join("/media", "ursa", "AQOGroupFolder") return groupFolder def _rpiADCLogFolder_default(self): return os.path.join(self.getGroupFolder(), "Experiment Humphry", "Experiment Control And Software", "rpiADC", "data") def _create_log_file(self): if not os.path.exists(os.path.join(self.rpiADCLogFolder, self.logFile)): with open(self.logFile, 'a+') as csvFile: csvWriter = csv.writer(csvFile) csvWriter.writerow([ "epochSeconds", "Channel 0", "Channel 1", "Channel 2", "Channel 3", "Channel 4", "Channel 5", "Channel 6", "Channel 7" ]) def checkDateForFileName(self): """gets current date and time and checks if we should change file name if we should it creates the new file and the name""" #self.currentLocalTime was already changed in log Temperatures if self.currentLocalTime.tm_mday != self.currentDay: #the day has changed we should start a new log file! self.logFile = self._logFile_default() self._create_log_file() def _log_channels(self): self.currentLocalTime = time.localtime() self.checkDateForFileName() self.currentMonth = self.currentLocalTime.tm_mon self.currentDay = self.currentLocalTime.tm_mday if not os.path.exists(os.path.join(self.rpiADCLogFolder, self.logFile)): self._create_log_file() voltages = [self.channels[i]._voltage_get() for i in range(0, 8)] with open(self.logFile, 'a+') as csvFile: csvWriter = csv.writer(csvFile) csvWriter.writerow([time.time()] + voltages) def _refresh_Visible_channels(self): self.connection.getResults() #updates dictionary in connection object for channelNumber in self.channelList: channel = self.channels[channelNumber] channel._voltage_update() self.oscilloscope.updateArrays() self.oscilloscope.updateArrayPlotData() self._log_channels() settingsGroup = traitsui.VGroup( traitsui.Item("logFile", label="Log File"), traitsui.HGroup( traitsui.Item('refreshTime', label='refreshTime'), traitsui.Item( 'averageN', label='averaging Number', tooltip= "Number of measurements taken and averaged for value shown"), traitsui.Item('VMax', label='Maximum Voltage Setting', tooltip="Whether the box is set to 3.3V or 5V max")), ) selectionGroup = traitsui.Group( traitsui.Item('channelList', editor=traitsui.CheckListEditor(values=channelValues, cols=4), style='custom', label='Show')) groupLeft = traitsui.VGroup( traitsui.Item('channel0', editor=traitsui.InstanceEditor(), style='custom', show_label=False, visible_when="(0 in channelList)"), traitsui.Item('channel1', editor=traitsui.InstanceEditor(), style='custom', show_label=False, visible_when="(1 in channelList)"), traitsui.Item('channel2', editor=traitsui.InstanceEditor(), style='custom', show_label=False, visible_when="(2 in channelList)"), traitsui.Item('channel3', editor=traitsui.InstanceEditor(), style='custom', show_label=False, visible_when="(3 in channelList)")) groupRight = traitsui.VGroup( traitsui.Item('channel4', editor=traitsui.InstanceEditor(), style='custom', show_label=False, visible_when="(4 in channelList)"), traitsui.Item('channel5', editor=traitsui.InstanceEditor(), style='custom', show_label=False, visible_when="(5 in channelList)"), traitsui.Item('channel6', editor=traitsui.InstanceEditor(), style='custom', show_label=False, visible_when="(6 in channelList)"), traitsui.Item('channel7', editor=traitsui.InstanceEditor(), style='custom', show_label=False, visible_when="(7 in channelList)")) groupOscilloscope = traitsui.Group( traitsui.Item('oscilloscope', editor=traitsui.InstanceEditor(), style='custom', show_label=False)) groupAll = traitsui.VGroup( settingsGroup, selectionGroup, traitsui.VSplit(traitsui.HGroup(groupLeft, groupRight), groupOscilloscope)) traits_view = traitsui.View(groupAll, resizable=True, title="ADC Monitor", handler=ADCHandler(), icon=icon_trait)
style='custom'), title='Conjoint warning', height=300, width=600, resizable=True, buttons=[_traitsui.OKButton], ) selection_view = _traitsui.Group( _traitsui.Group( _traitsui.Group( _traitsui.Label('Design:'), _traitsui.Item( 'controller.selected_design', editor=_traitsui.CheckListEditor( name='controller.available_design_sets'), style='simple', show_label=False, ), _traitsui.Label('Variables:'), _traitsui.Item( 'controller.sel_design_var', editor=_traitsui.CheckListEditor( name='controller.design_vars'), style='custom', show_label=False, ), show_border=True, ), _traitsui.Group( _traitsui.Label('Consumer characteristics:'),
def _show_missing_warning(self): dlg = ErrorMessage() dlg.err_msg = 'This matrix has missing values' dlg.err_val = ( "At the current version of ConsumerCheck PCA does not handle missing values. There are three options to work around this problem:\n" " 1. Impute the missing values with the imputation method of your choice outside ConsumerCheck and re-import the data\n" " 2. Remove the column with the missing values and re-import the data\n" " 3. Remove the row with the missing values and re-import the data" ) dlg.edit_traits(parent=self.win_handle, kind='modal') selection_view = _traitsui.Group( _traitsui.Item( 'controller.selected_ds', editor=_traitsui.CheckListEditor(name='controller.available_ds'), style='custom', show_label=False, width=200, height=200, ), label='Select data set', show_border=True, ) pca_plugin_view = make_plugin_view('Pca', pca_nodes, selection_view, pca_view) if __name__ == '__main__': print("PCA GUI test start") from tests.conftest import iris_ds, synth_dsc, zero_var_ds one_branch = False
class ComponentFit(SpanSelectorInSignal1D): fit = t.Button() only_current = t.List(t.Bool(True)) view = tu.View( tu.Item('fit', show_label=False), tu.Item('only_current', show_label=False, style='custom', editor=tu.CheckListEditor(values=[(True, 'Only current')])), buttons=[OurCloseButton], title='Fit single component', handler=SpanSelectorInSignal1DHandler, ) def __init__(self, model, component, signal_range=None, estimate_parameters=True, fit_independent=False, only_current=True, **kwargs): if model.signal.axes_manager.signal_dimension != 1: raise SignalDimensionError( model.signal.axes_manager.signal_dimension, 1) self.signal = model.signal self.axis = self.signal.axes_manager.signal_axes[0] self.span_selector = None self.only_current = [True] if only_current else [] # CheckListEditor self.model = model self.component = component self.signal_range = signal_range self.estimate_parameters = estimate_parameters self.fit_independent = fit_independent self.fit_kwargs = kwargs if signal_range == "interactive": if not hasattr(self.model, '_plot'): self.model.plot() elif self.model._plot is None: self.model.plot() elif self.model._plot.is_active() is False: self.model.plot() self.span_selector_switch(on=True) def _fit_fired(self): if (self.signal_range != "interactive" and self.signal_range is not None): self.model.set_signal_range(*self.signal_range) elif self.signal_range == "interactive": self.model.set_signal_range(self.ss_left_value, self.ss_right_value) # Backup "free state" of the parameters and fix all but those # of the chosen component if self.fit_independent: active_state = [] for component_ in self.model: active_state.append(component_.active) if component_ is not self.component: component_.active = False else: component_.active = True else: free_state = [] for component_ in self.model: for parameter in component_.parameters: free_state.append(parameter.free) if component_ is not self.component: parameter.free = False # Setting reasonable initial value for parameters through # the components estimate_parameters function (if it has one) only_current = len(self.only_current) > 0 # CheckListEditor if self.estimate_parameters: if hasattr(self.component, 'estimate_parameters'): if (self.signal_range != "interactive" and self.signal_range is not None): self.component.estimate_parameters( self.signal, self.signal_range[0], self.signal_range[1], only_current=only_current) elif self.signal_range == "interactive": self.component.estimate_parameters( self.signal, self.ss_left_value, self.ss_right_value, only_current=only_current) if only_current: self.model.fit(**self.fit_kwargs) else: self.model.multifit(**self.fit_kwargs) # Restore the signal range if self.signal_range is not None: self.model.channel_switches = ( self.model.backup_channel_switches.copy()) self.model.update_plot() if self.fit_independent: for component_ in self.model: component_.active = active_state.pop(0) else: # Restore the "free state" of the components for component_ in self.model: for parameter in component_.parameters: parameter.free = free_state.pop(0) def apply(self): self._fit_fired()
view = func(res) loop = owner.plots_act owner.calcc.open_window(view, loop, res) elif isinstance(owner, IndDiffController): func = getattr(owner, pfn) func() no_view = _traitsui.View() ind_diff_view = _traitsui.View( _traitsui.Group( _traitsui.Group( _traitsui.Item( 'dummify_variables', editor=_traitsui.CheckListEditor(name='consumer_variables'), style='custom', show_label=False), label="Dummify consumer characteristics used in PLSR", ), _traitsui.Group( _traitsui.Item('selected_liking_pc', editor=_traitsui.CheckListEditor(name='n_Y_pc'), style='custom', show_label=False), label="Principal components of consumer liking used in PLSR", ), _traitsui.Item('ev_export_dummified', show_label=False), label="Settings for 'Study idividual differences' models", show_border=True, ),