def __init__(self, parent): wx.Dialog.__init__(self, parent, wx.ID_ANY, 'Cluster Center Chooser', size=(550, 550)) self.CenterOnParent() self.centers = [] # set up the plotting panel self.dataPanel = CenterChooserPanel(self, self.OnClick) (self.dataSelectors, self.selectorSizer) = customsizers.ChannelSelectorSizer(self) if DataStore.getCurrentIndex() is not None: self.dataPanel.addData(DataStore.getCurrentIndex()) # filter the list of labels to include only user-selected ones selDims = DataStore.getCurrentDataSet().selDims labels = [DataStore.getCurrentDataSet().labels[i] for i in selDims] customsizers.populateSelectors(self.dataSelectors, labels, selDims) self.dataPanel.updateAxes((selDims[0],selDims[1])) # main sizer self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.dataPanel, True, wx.EXPAND | wx.BOTTOM | wx.TOP, -20) self.sizer.AddSpacer(20) self.sizer.Add(self.selectorSizer, False, wx.EXPAND | wx.TOP, 20) self.sizer.Add(self.CreateButtonSizer(wx.OK | wx.CANCEL), False, wx.EXPAND) self.SetSizer(self.sizer) self.SetBackgroundColour("white")
def isolateClusters(selection, datasetName): """ Create a new data set from a selection of clusters. @type selection: list @var selection: The indices of the clusters to be merged. @type datasetName: str @var datasetName: The display name for the new data set. """ if (len(selection) > 0): currFCData = DataStore.getCurrentDataSet() if (datasetName == ""): datasetName = currFCData.displayname clusters = separate(currFCData.data, currFCData.getCurrentClustering()) # merge selected clusters newData = dh.mergeData(selection, clusters) # assign new data set to the store newFCData = FacsData('', currFCData.labels, newData, parent=currFCData.ID) newFCData.displayname = datasetName newFCData.selDims = currFCData.selDims # add basic text annotations textAnn = {'parent': currFCData.displayname} textAnn['events'] = len(newFCData.data) newFCData.annotations['text'] = textAnn DataStore.add(newFCData)
def AddChosenCenter(self, point): cbxSelected = self._GetSelectedAxes() dims = DataStore.getCurrentDataSet().labels if (DataStore.getCurrentDataSet().selDims): dims = DataStore.getCurrentDataSet().selDims retPoint = [0 for i in dims] for i in range(len(cbxSelected)): retPoint[cbxSelected[i]] = point[i] self.centers.append(retPoint) self.dataPanel.addCenter(retPoint)
def addSubplot(self): cds = DataStore.getCurrentDataSet() if cds is None: return try: clusteringIndex = cds.clustering.keys()[-1] except IndexError: self.facsPlotPanel.addSubplot(DataStore.getCurrentIndex()) else: self.facsPlotPanel.addSubplot(DataStore.getCurrentIndex(), clusteringIndex)
def OnExport(self, event): if DataStore.getCurrentIndex() is None: wx.MessageBox("Please load a dataset before attempting to export", "Data Missing", wx.OK | wx.ICON_ERROR) return format = io.getMethod(event.GetId())().FileType dlg = wx.FileDialog(self, "Save File", "", "", format, wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT|wx.FD_CHANGE_DIR) if dlg.ShowModal() == wx.ID_OK: io.exportDataFile(event.GetId(), dlg.Path, DataStore.getCurrentDataSet(), window=self) dlg.Destroy()
def deleteSelection(self): """ Delete the data object referenced by the current tree selection. """ item = self.getSanitizedItemSelectionData() if item is None: return if item[0] is DATA_SET_ITEM: ids = (item[1], None) if len(item) < 3 else (item[1], item[2]) self.Parent.TopLevelParent.facsPlotPanel.deleteAssociatedSubplots(ids) self.applyToSelection(DataStore.remove, FacsData.removeClustering) # if all data deleted, clear axes selectors if len(DataStore.getData()) == 0: self.Parent.TopLevelParent.updateAxesList([]) if item[0] is FIGURE_SET_ITEM: id = item[1] #TODO: figure out if this is a good shortcut for clearing the figure of subplots if id == FigureStore.getSelectedIndex(): wx.MessageBox('The currently selected Figure cannot be deleted.', 'Invalid Action', wx.OK | wx.ICON_WARNING) else: FigureStore.remove(id) self.updateTree()
def updateTree(self): """ Rebuilds the tree from the current state of the DataStore. """ self.tree.DeleteAllItems() self.root = self.tree.AddRoot("Project") self.tree.SetPyData(self.root, None) self.tree.SetItemImage(self.root, self.fldridx, wx.TreeItemIcon_Normal) self.tree.SetItemImage(self.root, self.fldropenidx, wx.TreeItemIcon_Expanded) dataTree = self.tree.AppendItem(self.root, "Data Sets") self.tree.SetPyData(dataTree, DATA_SET_ITEM) self.tree.SetItemImage(dataTree, self.fldridx, wx.TreeItemIcon_Normal) self.tree.SetItemImage(dataTree, self.fldropenidx, wx.TreeItemIcon_Expanded) figsTree = self.tree.AppendItem(self.root, "Figure Sets") self.tree.SetPyData(figsTree, FIGURE_SET_ITEM) self.tree.SetItemImage(figsTree, self.fldridx, wx.TreeItemIcon_Normal) self.tree.SetItemImage(figsTree, self.fldropenidx, wx.TreeItemIcon_Expanded) # create tree self.buildDataTree(dataTree, DataStore.getData(), []) self.buildFigureTree(figsTree, FigureStore.getFigures()) self.tree.Expand(self.root) if self.dataTreeExpanded: self.tree.Expand(dataTree) if self.figureTreeExpanded: self.tree.Expand(figsTree)
def __init__(self, parent): wx.Dialog.__init__(self, parent, wx.ID_ANY, "Select clusterings to match colors", style=wx.RESIZE_BORDER|wx.DEFAULT_DIALOG_STYLE, size=(400, 150)) self.CenterOnParent() allData = DataStore.getData() self.choices = [] self.choiceIDs = [] # Populate the choices list with string, and populate the # choiceIDs list with (dataID, clusteringID) tuples so the # combo box selection can be tied to the data for didx in allData: fcData = allData[didx] for cidx in fcData.clustering: self.choices.append(fcData.displayname + ": " + getStringRepr(fcData.methodIDs[cidx]) + " " + str(cidx+1)) self.choiceIDs.append((fcData.ID, cidx)) self.cbxSourceClustering = wx.ComboBox(self, choices=self.choices, style=wx.CB_READONLY) self.cbxDestClustering = wx.ComboBox(self, choices=self.choices, style=wx.CB_READONLY) self.formSizer = wx.FlexGridSizer(2, 2, vgap=5, hgap=5) self.formSizer.FlexibleDirection = wx.HORIZONTAL self.formSizer.AddF(wx.StaticText(self, -1, 'First Clustering:'), wx.SizerFlags(1).Expand()) self.formSizer.AddF(self.cbxSourceClustering, wx.SizerFlags(2).Expand()) self.formSizer.AddF(wx.StaticText(self, -1, 'Second Clustering:'), wx.SizerFlags(1).Expand()) self.formSizer.AddF(self.cbxDestClustering, wx.SizerFlags(2).Expand()) self.Sizer = wx.BoxSizer(wx.VERTICAL) self.Sizer.AddF(self.formSizer, wx.SizerFlags(1).Expand().Border(wx.ALL, 10)) self.Sizer.AddF(self.CreateButtonSizer(wx.OK|wx.CANCEL), wx.SizerFlags().Expand().Border(wx.BOTTOM, 10))
def renameItem(self): """ Give a new display name to the currently selected data item """ item = self.getSanitizedItemSelectionData() if item is None: return if (item[0] is DATA_SET_ITEM): data = DataStore.get(item[1]) dlg = EditNameDialog(self.Parent, data.displayname) if dlg.ShowModal() == wx.ID_OK: data.displayname = dlg.Text dlg.Destroy() if (item[0] is FIGURE_SET_ITEM): figure = FigureStore.get(item[1]) dlg = EditNameDialog(self.Parent, figure.name) if dlg.ShowModal() == wx.ID_OK: figure.name = dlg.Text dlg.Destroy() item = self.tree.GetSelection() item.SetText(dlg.Text) self.tree.RefreshSelected() item.SetHilight(False) item.SetHilight(True)
def setExpanded(self, item, flag): #item = self.getItemSelectionData() data = self.tree.GetItemPyData(item) if isinstance(data, int): if data is DATA_SET_ITEM: self.dataTreeExpanded = flag if data is FIGURE_SET_ITEM: self.figureTreeExpanded = flag if isinstance(data, tuple): if data[0] is DATA_SET_ITEM: if len(data) == 2: DataStore.getData()[data[1]].nodeExpanded = flag if len(data) > 3: DataStore.getData()[data[1]].infoExpanded[data[2]] = flag
def OnCluster(self, event): """ Handles all clustering requests. Clustering requests are handled in the following method: 1. Passes the requested clustering method to L{cluster.dialogs.ClusterOptionsDialog.showDialog} method 2. Passes the data and the returned method options to L{cluster.methods.cluster} 3. Passes the returned cluster membership list to the FacsPlotPanel for display """ dlg = cDlgs.getClusterDialog(event.GetId(), self) if dlg.ShowModal() == wx.ID_OK: if (DataStore.getCurrentDataSet() is not None): self.statusbar.SetStatusText('Running %s clustering...' % cMthds.methods[event.GetId()][1], 0) fcs = DataStore.getCurrentDataSet() data = fcs.data # Remove columns from analysis as specified by the user if len(fcs.selDims) > 0: data = dh.filterData(data, fcs.selDims) clusterIDs, msg = cMthds.cluster(event.GetId(), data, **dlg.getMethodArgs()) DataStore.addClustering(event.GetId(), clusterIDs, dlg.getMethodArgs()) clusteringIndex = DataStore.getCurrentDataSet().clustering.keys()[-1] self.statusbar.SetStatusText(msg, 0) if (dlg.isApplyChecked()): if self.facsPlotPanel.SelectedSubplotIndex is not None: self.facsPlotPanel.CurrentSubplot = dv.Subplot(self.facsPlotPanel.SelectedSubplotIndex, DataStore.getCurrentIndex(), clusteringIndex) self.facsPlotPanel.draw() else: self.facsPlotPanel.addSubplot(DataStore.getCurrentIndex(), clusteringIndex) self.treeCtrlPanel.updateTree() dlg.Destroy()
class Analyzer: def __init__(self, games, previous_length): self.previous_length = previous_length self.data_store = DataStore(previous_length) self.games = [Attributes(game) for game in games] def run(self): games_dict = {} for game in self.games: away_team = self.data_store.get_data(game.away_team) home_team = self.data_store.get_data(game.home_team) if not away_team or not home_team: self.add_game_data(game) continue enough_away_stats = len( away_team.previous_stats) == self.previous_length enough_home_stats = len( home_team.previous_stats) == self.previous_length enough_previous_stats = enough_away_stats and enough_home_stats if not enough_previous_stats: self.add_game_data(game) continue away_pred = predict_score(away_team, home_team) home_pred = predict_score(home_team, away_team) games_dict[game.id] = (away_pred, home_pred) return games_dict def add_game_data(self, game): self.data_store.add_data(game.away_team) self.data_store.add_data(game.home_team) for player in game.away_players: self.data_store.add_data(player) for player in game.home_players: self.data_store.add_data(player)
def OnLoadState(self, event): from data.io import loadState if len(DataStore.getData()) > 0: dlgWarn = wx.MessageDialog(self, 'This action may overwrite currently loaded datasets and/or plots.\n\nContinue anyway?', 'Warning', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_WARNING) if dlgWarn.ShowModal() == wx.ID_NO: dlgWarn.Destroy() return dlgWarn.Destroy() formats = "FIND Project File (*.find)|*.find" dlg = wx.FileDialog(self, "Select saved project", self.dirname, "", formats, wx.FD_OPEN) if dlg.ShowModal() == wx.ID_OK: try: loadState(dlg.Directory, dlg.Filename) except error.ProjectLoadingError: return # Load all Figures with Subplot instances from the stored dicts for fID in FigureStore.getFigures(): fig = FigureStore.get(fID) splots = [] for plot in fig.subplots: s = dv.Subplot() s.load(plot) s.parent = self.facsPlotPanel.figure splots.append(s) fig.subplots = splots currFigure = FigureStore.getSelectedFigure() self.facsPlotPanel.subplots = currFigure.subplots self.facsPlotPanel.SelectedSubplotIndex = currFigure.selectedSubplot self.facsPlotPanel.updateAxes(currFigure.axes, False) self.facsPlotPanel.updateSubplotGrid(currFigure.grid[0], currFigure.grid[1], True) self.chkLinked.Value = self.facsPlotPanel.CurrentSubplotLinked labels = DataStore.getCurrentDataSet().labels if DataStore.getCurrentDataSet() is not None else [] self.updateAxesList(labels, currFigure.axes) self.treeCtrlPanel.updateTree() self.statusbar.SetStatusText("Project loaded from %s" % dlg.Path, 0) dlg.Destroy()
def OnEditChannelNames(self, event): """ Allow users to modify the descriptors for each channel (dimension) """ fcData = DataStore.getCurrentDataSet() if fcData is not None: dgridDlg = displayDialogs.SampleDataDisplayDialog(self, fcData.data[0:10,:], fcData.labels, 'Edit Channel Labels', False, False) if (dgridDlg.ShowModal() == wx.ID_OK): # reassign FacsData instance labels for fcd in DataStore.getData().values(): labels = [item[1] for item in sorted(dgridDlg.ColumnLabels.iteritems(), key=itemgetter(0))] fcd.labels = labels # update channel selection cbxs self.updateAxesList(labels, self.facsPlotPanel.SelectedAxes) # refresh plot window self.facsPlotPanel.draw() dgridDlg.Destroy() else: wx.MessageBox("There are no data currently loaded.", "Error", wx.OK | wx.ICON_ERROR)
def reassignClusterIDs(src, dst): """ Given the cluster centers for two clusterings, determine the centers most similar to each other and reassign the cluster ids to match. """ srcFCS = DataStore.getData()[src[0]] dstFCS = DataStore.getData()[dst[0]] srcdata = srcFCS.data if srcFCS.selDims: srcdata = dh.filterData(srcFCS.data, srcFCS.selDims) srcids = srcFCS.clustering[src[1]] srccenters = pc.clustercentroids(srcdata, clusterid=srcids)[0] dstdata = dstFCS.data if dstFCS.selDims: dstdata = dh.filterData(dstFCS.data, dstFCS.selDims) dstids = dstFCS.clustering[dst[1]] dstcenters = pc.clustercentroids(dstdata, clusterid=dstids)[0] srcsep = separate(srcdata, srcids) dstsep = separate(dstdata, dstids) centerEQ = {} taken = [] # Fill the map with the closest source center for each destination center for i,dc in enumerate(dstcenters): bestDist = -1 for j,sc in enumerate(srccenters): if (j not in taken): dist = nonSymmetricClusterDistance(dstsep[i], srcsep[j]) if (bestDist < 0) or (dist < bestDist): bestDist = dist centerEQ[i] = j taken.append(centerEQ[i]) # Renumber the cluster IDs in the destination to match the IDs of the closest src center tmp = [centerEQ[id] for id in dstids] DataStore.getData()[dst[0]].clustering[dst[1]] = tmp
def scatterplot2D(subplot, figure, dims): # set default plot options if necessary opts = subplot.opts if len(opts) == 0: opts['xRange'] = () opts['xRangeAuto'] = True opts['yRange'] = () opts['yRangeAuto'] = True opts['xTransform'] = '' opts['yTransform'] = '' opts['transformAuto'] = True # Set axes transforms if (opts['transformAuto']): fcData = DataStore.get(subplot.dataIndex) tf = ('xTransform', 'yTransform') for i, dim in enumerate(dims): t = fcData.getDefaultTransform(dim) if (t is not None) and ('log' in t.lower()): opts[tf[i]] = 'log' else: opts[tf[i]] = 'linear' if opts['xRangeAuto']: opts['xRange'] = (1, np.max(subplot.Data[:,dims[0]])*1.5) if opts['yRangeAuto']: opts['yRange'] = (1, np.max(subplot.Data[:,dims[1]])*1.5) # create the subplot and set its attributes subplot.axes = figure.add_subplot(subplot.mnp, xlim=opts['xRange'], ylim=opts['yRange'], autoscale_on=False) subplot.axes.set_xscale(opts['xTransform'], nonposx='clip') subplot.axes.set_yscale(opts['yTransform'], nonposy='clip') subplot.axes.set_xlabel(subplot.Labels[dims[0]]) subplot.axes.set_ylabel(subplot.Labels[dims[1]]) subplot.axes.set_title(subplot.Title) # draw the supplied FACS data if (not subplot.isDataClustered()): subplot.axes.plot(subplot.Data[:,dims[0]], subplot.Data[:,dims[1]], '.', ms=1, color='black') else: data = separate(subplot.Data, subplot.Clustering) for i in range(len(data)): xs = data[i][:,dims[0]] ys = data[i][:,dims[1]] subplot.axes.plot(xs, ys, '.', ms=1, color=methods.plotColors[i])
def buildDataTree(self, parent, dataDict, visited): for dIndex, fData in dataDict.iteritems(): # add tree node for the FACS data set if fData.ID in visited: return child = self.tree.AppendItem(parent, fData.displayname) if (DataStore.getCurrentIndex() == dIndex): self.tree.SetItemBold(child, True) self.tree.SetPyData(child, (DATA_SET_ITEM, dIndex)) self.tree.SetItemImage(child, self.fldridx, wx.TreeItemIcon_Normal) self.tree.SetItemImage(child, self.fldropenidx, wx.TreeItemIcon_Expanded) # add nodes for all the clusterings of the current data set for cIndex in fData.clustering: clust = self.tree.AppendItem(child, cluster.methods.getStringRepr(fData.methodIDs[cIndex]) + " " + str(cIndex+1)) if ((fData.selectedClustering == cIndex) and (fData.ID == DataStore.getCurrentIndex())): self.tree.SetItemBold(clust, True) toolTip = clusteringInfo(fData, cIndex) self.tree.SetPyData(clust, (DATA_SET_ITEM, dIndex, cIndex, toolTip)) #(data index, cluster index, tooltip) self.tree.SetItemImage(clust, self.fldridx, wx.TreeItemIcon_Normal) self.tree.SetItemImage(clust, self.fldropenidx, wx.TreeItemIcon_Expanded) # set clustering options for line in toolTip.split('\n'): if (line != ''): info = self.tree.AppendItem(clust, line) self.tree.SetPyData(info, None) if (fData.infoExpanded[cIndex]): self.tree.Expand(clust) # recursive call to build the tree for any children visited.append(fData.ID) self.buildDataTree(child, dict([(i,DataStore.getData()[i]) for i in fData.children]), visited) if (fData.nodeExpanded and self.tree.GetChildrenCount(child) > 0): self.tree.Expand(child)
def OnAnalyze(self, event): """ Handles all requests for analysis methods; built-in and plugins. Currently, analysis methods expect data, a list of dimensions available to use in analysis, and a window ref in order to display a subwindow/dialog with results or options. Analysis methods are expected to return data and/or a status message. Currently returned data is only used when called from code, not from the menu; which this method represents. """ if (DataStore.getCurrentDataSet() is not None): strID = aMthds.strID(event.GetId()) self.statusbar.SetStatusText('Running %s...' % aMthds.AvailableMethods()[strID][2], 0) fcs = DataStore.getCurrentDataSet() data = fcs.data # Remove columns from analysis as specified by the user if len(fcs.selDims) > 0: data = dh.filterData(data, fcs.selDims) args = {'parentWindow': self} _, msg = aMthds.getMethod(strID)(data, **args) self.statusbar.SetStatusText(msg, 0)
def OnAddFigure(self, event): if len(DataStore.getData()) == 0: return nameDlg = displayDialogs.EditNameDialog(self, '') if (nameDlg.ShowModal() == wx.ID_OK): newFig = Figure(nameDlg.Text, [dv.Subplot()], 1, (1,1), (0,1)) currFig = FigureStore.getSelectedFigure() FigureStore.add(newFig) dv.switchFigures(self.facsPlotPanel, currFig, newFig) self.facsPlotPanel.subplots = [] self.addSubplot() self.treeCtrlPanel.updateTree() nameDlg.Destroy()
def barplot(subplot, figure, dims=None): """ Create a bar chart with one bar for each cluster, and the bar height equal to the percent of events contained within the cluster. Some techniques borrowed from: http://www.scipy.org/Cookbook/Matplotlib/BarCharts """ clusters = separate(subplot.Data, subplot.Clustering) # set default plot options opts = subplot.opts if len(opts) == 0: opts['labelAngle'] = 0 if len(clusters) < 5 else -20 opts['view'] = 'percent' # correcting for previous version if 'view' not in opts: opts['view'] = 'percent' dataSize = len(subplot.Data) if opts['view'] == 'toplevel': dataSize = len(DataStore.getToplevelParent(subplot.dataIndex).data) if opts['view'] in ['percent', 'toplevel']: displayNums = [float(len(cluster))/dataSize*100 for cluster in clusters] else: displayNums = [len(cluster) for cluster in clusters] numBars = len(displayNums) width = 0.5 xlocs = na.array(range(len(displayNums)))+0.5 subplot.axes = figure.add_subplot(subplot.mnp, title=subplot.Title, autoscale_on=False) subplot.axes.set_xticks(xlocs + width/2) if opts['view'] == 'counts': subplot.axes.set_xticklabels(map(lambda x: "%i" % x, displayNums), rotation=opts['labelAngle']) subplot.axes.set_ylim(0, max(displayNums)*1.2) else: subplot.axes.set_xticklabels(map(lambda x: "%.2f%%" % x, displayNums), rotation=opts['labelAngle']) subplot.axes.set_ylim(0, 100) subplot.axes.set_xlim(0, xlocs[-1] + width*2) subplot.axes.xaxis.tick_bottom() subplot.axes.yaxis.tick_left() subplot.axes.bar(xlocs, displayNums, width=width, color=methods.plotColors[:numBars])
def applyToSelection(self, dataFunc, clustFunc): """ Apply a function to the data selection depending on whether it refers to a FacsData object or a clustering of a FacsData object. @type dataFunc: function @param dataFunc: A function to apply to the FacsData object selected. @type clustFunc: function @param clustFunc: A function to apply to the clustering of the FacsData object selected. """ data = self.getSanitizedItemSelectionData() if data is not None and data[0] is DATA_SET_ITEM: # determine if item is a data set or a clustering and select it if len(data) == 2: dataFunc(data[1]) if len(data) == 3: clustFunc(DataStore.selectDataSet(data[1]), data[2])
def OnOpen(self, event): """ Opens a FACS data file, parses it, and updates the FacsPlotPanel instance. """ # retrieve the I/O methods for inputting files inputMethods = [m[2]() for m in io.AvailableMethods().values()] formats = '|'.join([m.FileType for m in inputMethods if io.FILE_INPUT in m.register()]) allLabels = [] allColArr = [] allDims = [] fColsMoved = False numLoaded = 0 # keep track of the common number of dimensions for datasets numDims = DataStore.getCurrentDataSet() if numDims is not None: numDims = len(numDims.labels) dlg = wx.FileDialog(self, "Choose a file", self.dirname, "", formats, wx.FD_OPEN|wx.FD_MULTIPLE|wx.FD_CHANGE_DIR) if dlg.ShowModal() == wx.ID_OK: #TODO: move to data.io module? # process each file selected for n, path in enumerate(dlg.Paths): self.statusbar.SetStatusText('loading: ' + path, 0) try: (labels, data, annotations) = io.loadDataFile(path, window=self) except TypeError: # if there was an error loading the file, # loadDataFile should return None, so skip this file continue # make sure the new file matches dimensions of loaded files if numDims is None: numDims = len(labels) elif len(labels) != numDims: wx.MessageBox("Error loading file: %s\n\nThe number of channels does not match those in currently loaded datasets. \n\nThis file will not be loaded." % dlg.Filenames[n], "File Error", wx.OK | wx.ICON_ERROR) continue # Give the user a brief preview of the data (10 rows) and allow # column rearrangement and renaming if (not allLabels): dgridDlg = displayDialogs.SampleDataDisplayDialog(self, data[0:10,:], labels) if (dgridDlg.ShowModal() == wx.ID_OK): ca = dgridDlg.ColumnArrangement lbls = dgridDlg.ColumnLabels # Reassign the column labels labels = [lbls[i] for i in ca] if dgridDlg.ApplyToAll: allLabels = list(labels) allColArr = list(ca) # Rearrange the data columns if (dgridDlg.ColumnsMoved): fColsMoved = True data = dh.reorderColumns(data, ca) else: dgridDlg.Destroy() continue dgridDlg.Destroy() else: labels = list(allLabels) if fColsMoved: data = dh.reorderColumns(data, allColArr) # update the DataStore DataStore.add(FacsData(dlg.Filenames[n], labels, data, annotations=annotations)) numLoaded += 1 if n == 0: self.updateAxesList(labels) if (not allDims): # Allow the user to choose columns for use in analysis dimDlg = displayDialogs.DimensionExclusionDialog(self, labels) dimDlg.Size=(dimDlg.Size[0]*.75, dimDlg.Size[1]*.8) if (dimDlg.ShowModal() == wx.ID_OK): DataStore.getCurrentDataSet().selDims = dimDlg.SelectedDimensions if (dimDlg.ApplyToAll): allDims = list(dimDlg.SelectedDimensions) dimDlg.Destroy() else: DataStore.getCurrentDataSet().selDims = list(allDims) # update the panel self.facsPlotPanel.updateAxes([0,1]) if (len(self.facsPlotPanel.subplots) == 0 or len(dlg.Paths) > 1): self.facsPlotPanel.addSubplot(DataStore.getCurrentIndex()) # Create an n/2 x 2 grid for the n selected data files if (numLoaded > 1): self.facsPlotPanel.updateSubplotGrid(int(math.ceil(numLoaded/2.0)), 2) self.statusbar.SetStatusText('All data files loaded.') if FigureStore.isEmpty(): fig = Figure('Default', self.facsPlotPanel.subplots, 1, self.facsPlotPanel.Grid, self.facsPlotPanel.SelectedAxes) FigureStore.add(fig) self.treeCtrlPanel.updateTree() dlg.Destroy()
def displayDataInfo(self): item = self.getSanitizedItemSelectionData() if item is not None and item[0] is DATA_SET_ITEM: data = DataStore.get(item[1]) dlg = DataInfoDialog(self.Parent, data) dlg.Show()
def clearClusteringSelection(self): item = self.getSanitizedItemSelectionData() if item is not None and item[0] is DATA_SET_ITEM: DataStore.get(item[1]).selectedClustering = None self.updateTree()
def loadState(dir, filename): """ Restore the system state as stored to disk. @type dir: string @param path: The directory under which the the saved system state is stored @type filename: str @param filename: The name of the saved project file (.find) @rtype: tuple @return: A list of subplot settings (dicts) retrieved from the file, The index of the currently selected subplot, The currently selected axes, The number of rows and columns in the figure (grid size) """ store = shelve.open(os.path.join(dir, filename)) #store = dbopen(os.path.join(dir, filename)) datakeys = store['data'] try: bindata = np.load(os.path.join(dir,store['binfile'])) except IOError: bindata = None except BadZipfile: wx.MessageBox('The file \'%s\' may have become corrupted. Project loading has been cancelled' % store['binfile'], 'Data Loading Error', wx.OK|wx.ICON_ERROR) raise ProjectLoadingError('BadZipfile: %s' % os.path.join(dir,store['binfile'])) # Parse data sets for dID in datakeys: dStr = 'data-%s' % dID dsett = store[dStr] ann = dsett['annotations'] if 'annotations' in dsett else {} ana = dsett['analysis'] if 'analysis' in dsett else {} fdata = FacsData(dsett['filename'], dsett['labels'], bindata[dStr], annotations=ann, analysis=ana, parent=dsett['parent']) fdata.displayname = dsett['displayname'] fdata.ID = dsett['ID'] fdata.children = dsett['children'] fdata.selDims = dsett['selDims'] fdata.nodeExpanded = dsett['nodeExpanded'] # Parse clusterings for cID in dsett['clustering']: cStr = 'clust-%i-%i' % (dID, cID) csett = store[cStr] clusterIDs = bindata[cStr] fdata.addClustering(csett['method'], clusterIDs, csett['opts'], cID) fdata.clusteringSelDims[cID] = csett['clusteringSelDims'] fdata.infoExpanded[cID] = csett['infoExpanded'] DataStore.add(fdata) DataStore.selectDataSet(store['current-data']) # Figures if 'figures' in store: for fStr in store['figures']: fDict = store[fStr] splots = [] for pStr in fDict['subplots']: splots.append(store[pStr]) fDict['subplots'] = splots f = Figure() f.load(fDict) FigureStore.add(f) # handle older save files w/o Figure support else: # load the saved subplots into a new 'Default' Figure plots = [] for pStr in store['plots']: plots.append(store[pStr]) defFig = Figure('Default', plots, store['current-subplot'], store['grid'], store['selected-axes']) FigureStore.add(defFig) if 'current-figure' in store: FigureStore.setSelectedFigure(store['current-figure']) else: FigureStore.setSelectedFigure(0)
def saveState(dir, filename): """ Save a representation of the system state: All the loaded data sets, their clusterings, any transformations or analyses (future), and all plots. The state is saved in JSON format based on a dict of the following form: data: list of IDs binfile: the filename of the binary file used to store all the actual data data-dID: dict of settings belonging to a FacsData instance clust-dID-cID: a dict of attributes belonging to a clustering figures: list of figureID strings fig-ID: A dict for each figure keyed on the ID. The subplot attribute here is replaced with a list of fig-ID-p-ID strings for locating subplot dicts fig-ID-p-ID: A dict for each subplot in each figure keyed on fig ID and plot ID. current-data: data ID current-figure: figure ID """ store = shelve.open(os.path.join(dir, filename)) #store = dbopen(os.path.join(dir, filename), 'c', format='csv') # The actual numeric data will be stored in a separate binary file using # the numpy savez() method allowing for efficient storage/retrieval of data binfile = '%s.npz' % filename bindata = {} store['data'] = DataStore.getData().keys() store['binfile'] = binfile for dID in DataStore.getData(): fdata = DataStore.get(dID) dStr = 'data-%i' % dID dfname = fdata.filename if (fdata.filename is not '') else binfile bindata[dStr] = fdata.data store[dStr] = {'filename': dfname, 'displayname': fdata.displayname, 'labels': fdata.labels, 'annotations': fdata.annotations, 'analysis': fdata.analysis, 'ID': fdata.ID, 'parent': fdata.parent, 'children': fdata.children, 'selDims': fdata.selDims, 'clustering': fdata.clustering.keys(), 'nodeExpanded': fdata.nodeExpanded, 'selectedClustering': fdata.selectedClustering} # clusterings for cID in fdata.clustering: cStr = 'clust-%i-%i' % (dID, cID) csett = {'method': fdata.methodIDs[cID], 'opts': fdata.clusteringOpts[cID], 'clusteringSelDims': fdata.clusteringSelDims[cID], 'infoExpanded': fdata.infoExpanded[cID]} store[cStr] = csett bindata[cStr] = fdata.clustering[cID] # figures sfigs = [] for figID in FigureStore.getFigures(): fig = FigureStore.get(figID) fStr = 'fig-%i' % figID d = dict(fig.__dict__) splots = packSubplots(store, figID, fig.subplots) d['subplots'] = splots store[fStr] = d sfigs.append(fStr) store['figures'] = list(sfigs) # other store['current-data'] = DataStore.getCurrentIndex() store['current-figure'] = FigureStore.getSelectedIndex() # write out settings data store.close() # write out numeric data to binary file np.savez(os.path.join(dir, binfile), **bindata)
def __init__(self, games, previous_length): self.previous_length = previous_length self.data_store = DataStore(previous_length) self.games = [Attributes(game) for game in games]