def _get_axes(*arrays): """ find list of axes from a list of axis-aligned DimArray objects """ dims = get_dims(*arrays) # all dimensions present in objects axes = Axes() for dim in dims: common_axis = None for o in arrays: # skip missing dimensions if dim not in o.dims: continue axis = o.axes[dim] # update values if common_axis is None or (common_axis.size==1 and axis.size > 1): common_axis = axis # Test alignment for non-singleton axes if not (axis.size == 1 or np.all(axis.values==common_axis.values)): raise ValueError("axes are not aligned") # append new axis axes.append(common_axis) return axes
def add_axes(self, *args, **kwargs): """ Add an a axes with axes rect [left, bottom, width, height] where all quantities are in fractions of figure width and height. kwargs are legal Axes kwargs plus "polar" which sets whether to create a polar axes rect = l,b,w,h add_axes(rect) add_axes(rect, frameon=False, axisbg='g') add_axes(rect, polar=True) add_axes(ax) # add an Axes instance If the figure already has an axes with key *args, *kwargs then it will simply make that axes current and return it. If you do not want this behavior, eg you want to force the creation of a new axes, you must use a unique set of args and kwargs. The artist "label" attribute has been exposed for this purpose. Eg, if you want two axes that are otherwise identical to be added to the figure, make sure you give them unique labels: add_axes(rect, label='axes1') add_axes(rect, label='axes2') The Axes instance will be returned The following kwargs are supported: %(Axes)s """ key = self._make_key(*args, **kwargs) if self._seen.has_key(key): ax = self._seen[key] self.sca(ax) return ax if not len(args): return if isinstance(args[0], Axes): a = args[0] assert (a.get_figure() is self) else: rect = args[0] ispolar = kwargs.pop('polar', False) if ispolar: a = PolarAxes(self, rect, **kwargs) else: a = Axes(self, rect, **kwargs) self.axes.append(a) self._axstack.push(a) self.sca(a) self._seen[key] = a return a
def add_axes(self, rect, axisbg=None, frameon=True): """ Add an a axes with axes rect [left, bottom, width, height] where all quantities are in fractions of figure width and height. The Axes instance will be returned """ if axisbg is None: axisbg = rcParams['axes.facecolor'] a = Axes(self, rect, axisbg, frameon) self.axes.append(a) return a
def add_axes(self, rect, axisbg=None, frameon=True, **kwargs): """ Add an a axes with axes rect [left, bottom, width, height] where all quantities are in fractions of figure width and height. The Axes instance will be returned """ if axisbg is None: axisbg = rcParams['axes.facecolor'] ispolar = kwargs.get('polar', False) if ispolar: a = PolarAxes(self, rect, axisbg, frameon) else: a = Axes(self, rect, axisbg, frameon) self.axes.append(a) return a
def subplot(i, j, **kwargs): fig = gcf() if not (fig.axes and isinstance(fig.axes[0], AxesGrid)): # create new axis grid fig.axes = [AxesGrid(**kwargs)] # get axis grid grid = fig.axes[0] if not (i, j) in grid.keys(): # create new axis in axis grid grid[i, j] = Axes(fig=fig, **kwargs) # make axis active; TODO: find a less hacky solution fig._ca = grid[i, j]
def add_axes(self, *args, **kwargs): """ Add an a axes with axes rect [left, bottom, width, height] where all quantities are in fractions of figure width and height. kwargs are legal Axes kwargs plus"polar" which sets whether to create a polar axes add_axes((l,b,w,h)) add_axes((l,b,w,h), frameon=False, axisbg='g') add_axes((l,b,w,h), polar=True) add_axes(ax) # add an Axes instance If the figure already has an axed with key *args, *kwargs then it will simply make that axes current and return it The Axes instance will be returned """ if iterable(args[0]): key = tuple(args[0]), tuple(kwargs.items()) else: key = args[0], tuple(kwargs.items()) if self._seen.has_key(key): ax = self._seen[key] self.sca(ax) return ax if not len(args): return if isinstance(args[0], Axes): a = args[0] a.set_figure(self) else: rect = args[0] ispolar = popd(kwargs, 'polar', False) if ispolar: a = PolarAxes(self, rect, **kwargs) else: a = Axes(self, rect, **kwargs) self.axes.append(a) self._axstack.push(a) self.sca(a) self._seen[key] = a return a
def new_axes(self, *args, **kwargs): ''' Add an axes to the figure. :param position: (*list*) Optional, axes position specified by *position=* [left, bottom, width height] in normalized (0, 1) units. Default is [0.13, 0.11, 0.775, 0.815]. :param outerposition: (*list*) Optional, axes size and location, including labels and margin. :param aspect: (*string*) ['equal' | 'auto'] or a number. If a number the ratio of x-unit/y-unit in screen-space. Default is 'auto'. :param bgcolor: (*Color*) Optional, axes background color. :param axis: (*boolean*) Optional, set all axis visible or not. Default is ``True`` . :param bottomaxis: (*boolean*) Optional, set bottom axis visible or not. Default is ``True`` . :param leftaxis: (*boolean*) Optional, set left axis visible or not. Default is ``True`` . :param topaxis: (*boolean*) Optional, set top axis visible or not. Default is ``True`` . :param rightaxis: (*boolean*) Optional, set right axis visible or not. Default is ``True`` . :param xaxistype: (*string*) Optional, set x axis type as 'normal', 'lon', 'lat' or 'time'. :param xreverse: (*boolean*) Optional, set x axis reverse or not. Default is ``False`` . :param yreverse: (*boolean*) Optional, set yaxis reverse or not. Default is ``False`` . :returns: The axes. ''' axestype = kwargs.pop('axestype', 'cartesian') polar = kwargs.pop('polar', False) if polar: axestype = 'polar' kwargs['figure'] = self if axestype == 'polar': ax = PolarAxes(*args, **kwargs) #self.__set_axes(ax, **kwargs) elif axestype == 'map': ax = MapAxes(*args, **kwargs) #self.__set_axesm(ax, **kwargs) elif axestype == '3d': ax = Axes3D(*args, **kwargs) #self.__set_axes3d(ax, **kwargs) else: ax = Axes(*args, **kwargs) #self.__set_axes(ax, **kwargs) #self.__set_axes_common(ax, *args, **kwargs) return ax
def __create_axes(self, *args, **kwargs): """ Create an axes. :param position: (*list*) Optional, axes position specified by *position=* [left, bottom, width height] in normalized (0, 1) units. Default is [0.13, 0.11, 0.775, 0.815]. :param outerposition: (*list*) Optional, axes size and location, including labels and margin. :returns: The axes. """ if len(args) > 0: position = args[0] else: position = kwargs.pop('position', None) outerposition = kwargs.pop('outerposition', None) axestype = kwargs.pop('axestype', 'cartesian') polar = kwargs.pop('polar', False) if polar: axestype = 'polar' if axestype == 'polar': ax = PolarAxes() elif axestype == 'map': ax = MapAxes() elif axestype == '3d': ax = Axes3D() else: ax = Axes() if position is None: position = [0.13, 0.11, 0.775, 0.815] ax.active_outerposition(True) else: ax.active_outerposition(False) ax.set_position(position) if not outerposition is None: ax.set_outerposition(outerposition) ax.active_outerposition(True) return ax
def drawSidebar(self): layout = wx.BoxSizer(wx.HORIZONTAL) tabs = wx.Notebook(self) self.designSidebarPanel = scrolled.ScrolledPanel(tabs) self.designSidebar = wx.BoxSizer(wx.VERTICAL) self.content = content = wx.BoxSizer(wx.VERTICAL) self.grid = BitMapGrid(self) self.canvas = AtomsCanvas(self) #Grid size self.sizeBox = wx.StaticBox(self.designSidebarPanel, label='Grid size') self.sizeBoxSizer = wx.StaticBoxSizer(self.sizeBox, wx.VERTICAL) self.sizeBoxGrid = wx.GridSizer(1, 4, 10, 10) self.sizeBoxWidthLabel = wx.StaticText(self.designSidebarPanel, label="Width") self.sizeBoxWidthCtrl = wx.SpinCtrl(self.designSidebarPanel, value=str(self.grid.cols), initial=self.grid.cols, min=0, size=(50, 20)) self.sizeBoxHeightLabel = wx.StaticText(self.designSidebarPanel, label="Height") self.sizeBoxHeightCtrl = wx.SpinCtrl(self.designSidebarPanel, value=str(self.grid.rows), initial=self.grid.rows, min=0, size=(50, 20)) self.sizeBoxGrid.AddMany([ (self.sizeBoxWidthLabel, 0, wx.EXPAND), (self.sizeBoxWidthCtrl, 0, wx.EXPAND), (self.sizeBoxHeightLabel, 0, wx.EXPAND), (self.sizeBoxHeightCtrl, 0, wx.EXPAND) ]) self.sizeBoxWidthCtrl.Bind(wx.EVT_SPINCTRL, self.updateGridSize) self.sizeBoxHeightCtrl.Bind(wx.EVT_SPINCTRL, self.updateGridSize) self.sizeBoxSizer.Add(self.sizeBoxGrid) #Object parameters self.configBox = wx.StaticBox(self.designSidebarPanel, label='Object parameters') self.configBoxSizer = wx.StaticBoxSizer(self.configBox, wx.VERTICAL) self.configBoxGrid = wx.GridSizer(10, 2, 5, 5) # Number of layers self.configBoxLayersLabel = wx.StaticText(self.designSidebarPanel, label="Layers", size=(70,20)) self.configBoxLayersCtrl = wx.SpinCtrl(self.designSidebarPanel, value="3", initial=10, min=1, size=(50, 20)) # Avoid bug on OS X that auto-focus on first field and hides the default value wx.CallAfter(self.configBoxLayersCtrl.SetFocus) self.configBoxLayersCtrl.Bind(wx.EVT_SPINCTRL, self.updateParametersProxy) # Type of structure self.configBoxCellTypeLabel = wx.StaticText(self.designSidebarPanel, label="Structure") self.configBoxCellTypeSCRadio = wx.RadioButton(self.designSidebarPanel, label='SC', style=wx.RB_GROUP) self.configBoxCellTypeBCCRadio = wx.RadioButton(self.designSidebarPanel, label='BCC') self.configBoxCellTypeFCCRadio = wx.RadioButton(self.designSidebarPanel, label='FCC') self.configBoxCellTypeSCRadio.SetValue(True) self.type = "SC" self.configs['type'] = self.type self.configBoxCellTypeSCRadio.Bind(wx.EVT_RADIOBUTTON, self.updateType) self.configBoxCellTypeBCCRadio.Bind(wx.EVT_RADIOBUTTON, self.updateType) self.configBoxCellTypeFCCRadio.Bind(wx.EVT_RADIOBUTTON, self.updateType) # Net constant self.configBoxNetConstantLabel = wx.StaticText(self.designSidebarPanel, label="Lattice constant") self.configBoxNetConstantCtrl = FS.FloatSpin(self.designSidebarPanel, -1, min_val=0, increment=0.1, value=0.28, agwStyle=FS.FS_LEFT) self.configBoxNetConstantCtrl.SetFormat("%f") self.configBoxNetConstantCtrl.SetDigits(5) self.configBoxNetConstantCtrl.Bind(FS.EVT_FLOATSPIN, self.updateParametersProxy) # Size self.configBoxHeightLabel = wx.StaticText(self.designSidebarPanel, label="Height (nm)", size=(70, 20)) self.configBoxHeightCtrl = FS.FloatSpin(self.designSidebarPanel, -1, min_val=0.1, increment=0.1, value=10, agwStyle=FS.FS_LEFT) self.configBoxHeightCtrl.SetFormat("%f") self.configBoxHeightCtrl.SetDigits(2) self.configBoxHeightCtrl.Bind(FS.EVT_FLOATSPIN, self.updateParametersProxy) # Sizes self.configBoxWidthLabel = wx.StaticText(self.designSidebarPanel, label="Width (nm)", size=(70, 20)) self.configBoxWidthValue = wx.StaticText(self.designSidebarPanel, label="--", size=(70, 20)) self.configBoxLengthLabel = wx.StaticText(self.designSidebarPanel, label="Length (nm)", size=(70, 20)) self.configBoxLengthValue = wx.StaticText(self.designSidebarPanel, label="--", size=(70, 20)) # Scaling self.configBoxEtaLabel = wx.StaticText(self.designSidebarPanel, label="Eta", size=(70, 20)) self.configBoxEtaCtrl = FS.FloatSpin(self.designSidebarPanel, -1, min_val=0, increment=0.1, value=0.55, agwStyle=FS.FS_LEFT) self.configBoxEtaCtrl.SetFormat("%f") self.configBoxEtaCtrl.SetDigits(5) self.configBoxEtaCtrl.Bind(FS.EVT_FLOATSPIN, self.updateParametersProxy) self.configBoxXLabel = wx.StaticText(self.designSidebarPanel, label="X", size=(70, 20)) self.configBoxXValue = wx.StaticText(self.designSidebarPanel, label="--", size=(50, 20)) self.configBoxGrid.AddMany([ (self.configBoxLayersLabel, 0, wx.EXPAND), (self.configBoxLayersCtrl, 0, wx.EXPAND), (self.configBoxCellTypeLabel, 0, wx.EXPAND), (self.configBoxCellTypeSCRadio, 0, wx.EXPAND), (wx.StaticText(self, -1, ''), 0, wx.EXPAND), #Blank space (self.configBoxCellTypeBCCRadio, 0, wx.EXPAND), (wx.StaticText(self, -1, ''), 0, wx.EXPAND), #Blank space (self.configBoxCellTypeFCCRadio, 0, wx.EXPAND), (self.configBoxNetConstantLabel, 0, wx.EXPAND), (self.configBoxNetConstantCtrl, 0, wx.EXPAND), (self.configBoxHeightLabel, 0, wx.EXPAND), (self.configBoxHeightCtrl, 0, wx.EXPAND), (self.configBoxWidthLabel, 0, wx.EXPAND), (self.configBoxWidthValue, 0, wx.EXPAND), (self.configBoxLengthLabel, 0, wx.EXPAND), (self.configBoxLengthValue, 0, wx.EXPAND), (self.configBoxEtaLabel, 0, wx.EXPAND), (self.configBoxEtaCtrl, 0, wx.EXPAND), (self.configBoxXLabel, 0, wx.EXPAND), (self.configBoxXValue, 0, wx.EXPAND) ]) self.configBoxSizer.Add(self.configBoxGrid) # Figures self.figuresBox = wx.StaticBox(self.designSidebarPanel, label='Figures') self.figuresBoxSizer = wx.StaticBoxSizer(self.figuresBox, wx.VERTICAL) self.figuresBoxGrid = wx.FlexGridSizer(2, 1, 10, 10) # Quadrilateral self.figuresQuadPane = wx.CollapsiblePane(self.designSidebarPanel, label="Quadrilateral", style=wx.CP_DEFAULT_STYLE|wx.CP_NO_TLW_RESIZE) self.figuresQuadPane.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.quadToggled) self.figuresQuadSizer = wx.GridSizer(1, 4, 10, 10) self.figuresQuadPaneWin = self.figuresQuadPane.GetPane() self.figuresQuadWidthLabel = wx.StaticText(self.figuresQuadPaneWin, label="Width") self.figuresQuadWidthCtrl = wx.SpinCtrl(self.figuresQuadPaneWin, value="1", initial=1, min=1, size=(50,20)) self.figuresQuadHeightLabel = wx.StaticText(self.figuresQuadPaneWin, label="Height") self.figuresQuadHeightCtrl = wx.SpinCtrl(self.figuresQuadPaneWin, value="1", initial=1, min=1, size=(50,20)) self.figuresQuadSizer.AddMany([ (self.figuresQuadWidthLabel, 0, wx.EXPAND), (self.figuresQuadWidthCtrl, 0, wx.EXPAND), (self.figuresQuadHeightLabel, 0, wx.EXPAND), (self.figuresQuadHeightCtrl, 0, wx.EXPAND) ]) self.figuresQuadPaneWin.SetSizer(self.figuresQuadSizer) # Circle self.figuresCirclePane = wx.CollapsiblePane(self.designSidebarPanel, label="Circle", style=wx.CP_DEFAULT_STYLE|wx.CP_NO_TLW_RESIZE) self.figuresCirclePane.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.circleToggled) self.figuresCircleSizer = wx.GridSizer(2, 2, 10, 10) self.figuresCirclePaneWin = self.figuresCirclePane.GetPane() self.figuresCircleRadiusLabel = wx.StaticText(self.figuresCirclePaneWin, label="Radius") self.figuresCircleRadiusCtrl = wx.SpinCtrl(self.figuresCirclePaneWin, value="1", initial=1, min=1, size=(50,20)) self.figuresCircleRadiusCtrl.Bind(wx.EVT_SPINCTRL, self.updateCircleWidth) self.figuresCircleWidthLabel = wx.StaticText(self.figuresCirclePaneWin, label="Width (nm)") self.figuresCircleWidthValue = wx.StaticText(self.figuresCirclePaneWin, label="--") self.figuresCircleSizer.AddMany([ (self.figuresCircleRadiusLabel, 0, wx.EXPAND), (self.figuresCircleRadiusCtrl, 0, wx.EXPAND), (self.figuresCircleWidthLabel, 0, wx.EXPAND), (self.figuresCircleWidthValue, 0, wx.EXPAND) ]) self.figuresCirclePaneWin.SetSizer(self.figuresCircleSizer) self.figuresBoxGrid.AddMany([ (self.figuresQuadPane, 0, wx.EXPAND), (self.figuresCirclePane, 0, wx.EXPAND) ]) self.figuresBoxSizer.Add(self.figuresBoxGrid) self.clearButton = wx.Button(self.designSidebarPanel, label="Clear grid") self.clearButton.Bind(wx.EVT_BUTTON, self.clearGrid) self.exportFileButton = wx.Button(self.designSidebarPanel, label="Export Data") self.exportFileButton.Bind(wx.EVT_BUTTON, self.checkParametersTrigger) self.exportImagesButtonD = wx.Button(self.designSidebarPanel, label="Export Images") self.exportImagesButtonD.Bind(wx.EVT_BUTTON, self.exportImagesD) self.exportImagesButtonD.Show(False) self.previewButton = wx.Button(self.designSidebarPanel, label="Show/hide preview") self.previewButton.Bind(wx.EVT_BUTTON, self.togglePreview) self.axesBoxD = wx.StaticBox(self.designSidebarPanel, label='Axes') self.axesBoxSizerD = wx.StaticBoxSizer(self.axesBoxD, wx.VERTICAL) self.axesD = Axes(self.designSidebarPanel) self.axesBoxSizerD.Add(self.axesD) self.designSidebar.Add(self.sizeBoxSizer, 0, wx.EXPAND | wx.ALL, 5) self.designSidebar.Add(self.configBoxSizer, 0, wx.EXPAND | wx.ALL, 5) self.designSidebar.Add(self.figuresBoxSizer, 0, wx.EXPAND | wx.ALL, 5) self.designSidebar.Add(self.clearButton, 0, wx.EXPAND | wx.ALL, 5) self.designSidebar.Add(self.exportFileButton, 0, wx.EXPAND | wx.ALL, 5) self.designSidebar.Add(self.exportImagesButtonD, 0, wx.EXPAND | wx.ALL, 5) self.designSidebar.Add(self.previewButton, 0, wx.EXPAND | wx.ALL, 5) self.designSidebar.Add(self.axesBoxSizerD, 0, wx.EXPAND | wx.ALL, 5) self.designSidebarPanel.SetSizer(self.designSidebar) wx.CallAfter(self.axesBoxD.Show, False) wx.CallAfter(self.axesD.Show, False) self.visualizationSidebarPanel = scrolled.ScrolledPanel(tabs) visualizationSidebar = wx.BoxSizer(wx.VERTICAL) inputDirBtn = wx.Button(self.visualizationSidebarPanel, -1, "Select Atoms file") self.Bind(wx.EVT_BUTTON, self.openFileDialog, inputDirBtn) self.statsBox = wx.StaticBox(self.visualizationSidebarPanel, label='Input Stats') self.statsSizer = wx.StaticBoxSizer(self.statsBox, wx.VERTICAL) self.statsGrid = wx.GridSizer(2, 2, 5, 5) self.statsValidPathLabel = wx.StaticText(self.visualizationSidebarPanel, label="Valid Atom file") self.statsValidPathValue = wx.StaticText(self.visualizationSidebarPanel, label="--") self.statsNumberDataFilesLabel = wx.StaticText(self.visualizationSidebarPanel, label="# of Data files") self.statsNumberDataFilesValue = wx.StaticText(self.visualizationSidebarPanel, label="--") self.statsGrid.AddMany([ (self.statsValidPathLabel, 0, wx.EXPAND), (self.statsValidPathValue, 0, wx.EXPAND), (self.statsNumberDataFilesLabel, 0, wx.EXPAND), (self.statsNumberDataFilesValue, 0, wx.EXPAND) ]) self.statsSizer.Add(self.statsGrid) self.readInputBtn = wx.Button(self.visualizationSidebarPanel, label="Read Input files") # Enable only if we have a valid directory self.readInputBtn.Enable(False) self.readInputBtn.Bind(wx.EVT_BUTTON, self.readInputFiles) viewModeBox = wx.StaticBox(self.visualizationSidebarPanel, label='View layer') self.viewModeSizer = wx.StaticBoxSizer(viewModeBox, wx.VERTICAL) viewModeGrid = wx.FlexGridSizer(2, 4, 5, 5) self.viewModeAllLayers = wx.RadioButton(self.visualizationSidebarPanel, label='All', style=wx.RB_GROUP) self.viewModeLayerX = wx.RadioButton(self.visualizationSidebarPanel, label='X') self.viewLayerX = wx.ComboBox(self.visualizationSidebarPanel, choices=["0.000"], style=wx.CB_DROPDOWN|wx.CB_READONLY, size=(60, 27)) self.viewModeLayerY = wx.RadioButton(self.visualizationSidebarPanel, label='Y') self.viewLayerY = wx.ComboBox(self.visualizationSidebarPanel, choices=["0.000"], style=wx.CB_DROPDOWN|wx.CB_READONLY, size=(60, 27)) self.viewModeLayerZ = wx.RadioButton(self.visualizationSidebarPanel, label='Z') self.viewLayerZ = wx.ComboBox(self.visualizationSidebarPanel, choices=["0.000"], style=wx.CB_DROPDOWN|wx.CB_READONLY, size=(60, 27)) self.viewModeAllLayers.SetValue(True) self.viewModeAllLayers.Enable(False) self.viewModeLayerX.Enable(False) self.viewModeLayerY.Enable(False) self.viewModeLayerZ.Enable(False) self.viewLayerX.Enable(False) self.viewLayerY.Enable(False) self.viewLayerZ.Enable(False) self.viewModeAllLayers.Bind(wx.EVT_RADIOBUTTON, self.updateViewMode) self.viewModeLayerX.Bind(wx.EVT_RADIOBUTTON, self.updateViewMode) self.viewModeLayerY.Bind(wx.EVT_RADIOBUTTON, self.updateViewMode) self.viewModeLayerZ.Bind(wx.EVT_RADIOBUTTON, self.updateViewMode) self.viewLayerX.Bind(wx.EVT_COMBOBOX, self.updateViewMode) self.viewLayerY.Bind(wx.EVT_COMBOBOX, self.updateViewMode) self.viewLayerZ.Bind(wx.EVT_COMBOBOX, self.updateViewMode) viewModeGrid.AddMany([ (self.viewModeAllLayers, 0, wx.EXPAND), (self.viewModeLayerX, 0, wx.EXPAND), (self.viewModeLayerY, 0, wx.EXPAND), (self.viewModeLayerZ, 0, wx.EXPAND), ((1,1)), #Blank space (self.viewLayerX, 0, wx.EXPAND), (self.viewLayerY, 0, wx.EXPAND), (self.viewLayerZ, 0, wx.EXPAND) ]) self.viewModeSizer.Add(viewModeGrid, flag=wx.ALL, border=1) self.exportImagesButtonV = wx.Button(self.visualizationSidebarPanel, label="Export Images") self.exportImagesButtonV.Bind(wx.EVT_BUTTON, self.exportImagesV) self.exportImagesButtonV.Show(False) self.exportVideoButton = wx.Button(self.visualizationSidebarPanel, label="Export Video") self.exportVideoButton.Bind(wx.EVT_BUTTON, self.exportVideo) self.exportVideoButton.Show(False) controlsBox = wx.StaticBox(self.visualizationSidebarPanel, label='Controls') self.controlsSizer = wx.StaticBoxSizer(controlsBox, wx.VERTICAL) controlsGrid = wx.FlexGridSizer(1, 6, 5, 5) self.playBitmap = wx.Bitmap("images/play.png", wx.BITMAP_TYPE_ANY) self.stopBitmap = wx.Bitmap("images/pause.png", wx.BITMAP_TYPE_ANY) self.backBitmap = wx.Bitmap("images/back.png", wx.BITMAP_TYPE_ANY) self.forwardBitmap = wx.Bitmap("images/forward.png", wx.BITMAP_TYPE_ANY) self.previousBitmap = wx.Bitmap("images/previous.png", wx.BITMAP_TYPE_ANY) self.nextBitmap = wx.Bitmap("images/next.png", wx.BITMAP_TYPE_ANY) self.backBtn = wx.BitmapButton(self.visualizationSidebarPanel, -1, self.backBitmap, (0,0), ((30,30))) self.previousBtn = wx.BitmapButton(self.visualizationSidebarPanel, -1, self.previousBitmap, (0,0), ((30,30))) self.playStopBtn = wx.BitmapButton(self.visualizationSidebarPanel, -1, self.playBitmap, (0,0), ((30,30))) self.nextBtn = wx.BitmapButton(self.visualizationSidebarPanel, -1, self.nextBitmap, (0,0), ((30,30))) self.forwardBtn = wx.BitmapButton(self.visualizationSidebarPanel, -1, self.forwardBitmap, (0,0), ((30,30))) self.previousBtn.Bind(wx.EVT_BUTTON, self.previousT) self.backBtn.Bind(wx.EVT_BUTTON, self.backT) self.playStopBtn.Bind(wx.EVT_BUTTON, self.playStop) self.forwardBtn.Bind(wx.EVT_BUTTON, self.forwardT) self.nextBtn.Bind(wx.EVT_BUTTON, self.nextT) self.backBtn.Enable(False) self.previousBtn.Enable(False) self.playStopBtn.Enable(False) self.forwardBtn.Enable(False) self.nextBtn.Enable(False) self.currentTCtrl = wx.TextCtrl(self.visualizationSidebarPanel, value="0", style=wx.TE_CENTRE, size=(70, 10)) font = wx.Font(18, wx.SWISS, wx.NORMAL, wx.NORMAL) self.currentTCtrl.SetFont(font) self.currentTCtrl.Enable(False) self.currentTCtrl.Bind(wx.EVT_TEXT, self.startCurrentTTimer) self.currentTTimer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.setCurrentT, self.currentTTimer) controlsGrid.AddMany([ (self.backBtn, 0, wx.EXPAND), (self.previousBtn, 0, wx.EXPAND), (self.playStopBtn, 0, wx.EXPAND), (self.nextBtn, 0, wx.EXPAND), (self.forwardBtn, 0, wx.EXPAND), (self.currentTCtrl, 0, wx.EXPAND) ]) self.controlsSizer.Add(controlsGrid) axesBoxV = wx.StaticBox(self.visualizationSidebarPanel, label='Axes') axesBoxSizerV = wx.StaticBoxSizer(axesBoxV, wx.VERTICAL) self.axesV = Axes(self.visualizationSidebarPanel) axesBoxSizerV.Add(self.axesV) self.plotBox = wx.StaticBox(self.visualizationSidebarPanel, label='Plot') plotSizer = wx.StaticBoxSizer(self.plotBox, wx.VERTICAL) self.plotter = plot.PlotCanvas(self.visualizationSidebarPanel) self.plotter.SetInitialSize(size=(220, 220)) plotSizer.Add(self.plotter) self.plotBox.Show(False) self.plotter.Show(False) visualizationSidebar.AddMany([ (inputDirBtn, 0, wx.EXPAND | wx.ALL, 5), (self.statsSizer, 0, wx.EXPAND | wx.ALL, 5), (self.readInputBtn, 0, wx.EXPAND | wx.ALL, 5), (self.controlsSizer, 0, wx.EXPAND | wx.ALL, 5), (self.viewModeSizer, 0, wx.EXPAND | wx.ALL, 5), (self.exportImagesButtonV, 0, wx.EXPAND | wx.ALL, 5), (self.exportVideoButton, 0, wx.EXPAND | wx.ALL, 5), (axesBoxSizerV, 0, wx.EXPAND | wx.ALL, 5), (plotSizer, 0, wx.EXPAND | wx.ALL, 5) ]) self.visualizationSidebarPanel.SetSizer(visualizationSidebar) self.viewModeSizer.ShowItems(False) self.controlsSizer.ShowItems(False) tabs.AddPage(self.designSidebarPanel, "Design") tabs.AddPage(self.visualizationSidebarPanel, "Visualization") tabs.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged) content.Add(self.grid, 1, wx.EXPAND) content.Add(self.canvas, 1, wx.EXPAND) self.grid.Show() self.canvas.Hide() self.togglePreviewStatus = 0 layout.Add(tabs, 0, wx.EXPAND) layout.Add(content, 1, wx.EXPAND) self.designSidebarPanel.SetupScrolling(scroll_x=False) self.visualizationSidebarPanel.SetupScrolling(scroll_x=False) self.SetSizer(layout) self.Layout() self.Refresh() self.grid.updateSize() self.updateParameters()
def subplots(self, nrows=1, ncols=1, position=None, sharex=False, sharey=False, \ wspace=None, hspace=None, axestype='Axes', **kwargs): ''' Create a figure and a set of subplots. :param nrows: (*int*) Number of rows. :param ncols: (*int*) Number of cols. :param position: (*list*) All axes' position specified by *position=* [left, bottom, width height] in normalized (0, 1) units. Default is [0,0,1,1]. :param sharex: (*boolean*) If share x axis. :param sharey: (*boolean*) If share y axis. :param subplot_kw: (*dict*) Subplot key words. :param wspace: (*float*) The amount of width reserved for blank space between subplots, expressed as a fraction of the average axis width. :param hspace: (*float*) The amount of height reserved for blank space between subplots, expressed as a fraction of the average axis height. :param axestype: (*string*) Axes type [Axes | Axes3D | MapAxes | PolarAxes]. :returns: The figure and the axes tuple. ''' if position is None: if wspace is None and hspace is None: position = [0, 0, 1, 1] else: position = [0.13, 0.11, 0.775, 0.815] left = float(position[0]) bottom = float(position[1]) width = float(position[2]) height = float(position[3]) chart = self.getChart() chart.setRowNum(nrows) chart.setColumnNum(ncols) axs = [] ax2d = nrows > 1 and ncols > 1 w = width / ncols h = height / nrows iswspace = False ishspace = False if not wspace is None and ncols > 1: w = (width - wspace * (ncols - 1)) / ncols iswspace = True if not hspace is None and nrows > 1: h = (height - hspace * (nrows - 1)) / nrows ishspace = True axestype = axestype.lower() y = bottom + height - h for i in range(nrows): if ax2d: axs2d = [] x = left if ishspace: if i > 0: y -= hspace for j in range(ncols): if axestype == 'axes3d': ax = Axes3D() self.__set_axes3d(ax, **kwarg) elif axestype == 'mapaxes': ax = MapAxes() self.__set_axesm(ax, **kwargs) elif axestype == 'polaraxes': ax = PolarAxes() else: ax = Axes() self.__set_axes(ax, **kwargs) ax.axes.isSubPlot = True if not iswspace and not ishspace: x = left + w * j y = (bottom + height) - h * (i + 1) ax.set_position([x, y, w, h]) ax.set_outerposition([x, y, w, h]) ax.active_outerposition(True) else: if iswspace: if j > 0: x += wspace ax.set_position([x, y, w, h]) ax.active_outerposition(False) x += w if sharex: if i < nrows - 1: ax.axes.getAxis( Location.BOTTOM).setDrawTickLabel(False) if sharey: if j > 0: ax.axes.getAxis(Location.LEFT).setDrawTickLabel(False) chart.addPlot(ax.axes) if ax2d: axs2d.append(ax) else: axs.append(ax) if ax2d: axs.append(tuple(axs2d)) y -= h chart.setCurrentPlot(0) return tuple(axs)
def subplot(self, nrows, ncols, plot_number, **kwargs): """ Returen a subplot axes positioned by the given grid definition. :param nrows, nrows: (*int*) Whree *nrows* and *ncols* are used to notionally spli the figure into ``nrows * ncols`` sub-axes. :param plot_number: (*int) Is used to identify the particular subplot that this function is to create within the notional gird. It starts at 1, increments across rows first and has a maximum of ``nrows * ncols`` . :returns: Current axes specified by ``plot_number`` . """ chart = self.getChart() chart.setRowNum(nrows) chart.setColumnNum(ncols) polar = kwargs.pop('polar', False) isnew = True if isnew: polar = kwargs.pop('polar', False) if polar: ax = PolarAxes() else: ax = Axes() ax.axes.isSubPlot = True else: chart.setCurrentPlot(plot_number - 1) position = kwargs.pop('position', None) if position is None: if isnew: if isinstance(plot_number, (list, tuple)): i = 0 for pnum in plot_number: pnum -= 1 rowidx = pnum / ncols colidx = pnum % ncols width = 1. / ncols height = 1. / nrows x = width * colidx y = 1. - height * (rowidx + 1) if i == 0: minx = x miny = y maxx = x + width maxy = y + height else: minx = min(x, minx) miny = min(y, miny) maxx = max(x + width, maxx) maxy = max(y + height, maxy) i += 1 x = minx y = miny width = maxx - minx height = maxy - miny else: plot_number -= 1 rowidx = plot_number / ncols colidx = plot_number % ncols width = 1. / ncols height = 1. / nrows x = width * colidx y = 1. - height * (rowidx + 1) ax.set_position([x, y, width, height]) ax.set_outerposition([x, y, width, height]) ax.active_outerposition(True) else: ax.set_position(position) ax.active_outerposition(False) outerposition = kwargs.pop('outerposition', None) if not outerposition is None: ax.set_outerposition(outerposition) ax.active_outerposition(True) if isinstance(ax, MapAxes): self.__set_axesm(ax, **kwargs) else: self.__set_axes(ax, **kwargs) if isnew: chart.addPlot(ax.axes) chart.setCurrentPlot(chart.getPlots().size() - 1) return ax
def _take_broadcast(a, indices): """ broadcast array-indices & integers, numpy's classical Examples: --------- >>> a = da.zeros(shape=(3,4,5,6)) >>> a[:,[0, 1],:,2].shape (2, 3, 5) >>> a[:,[0, 1],2,:].shape (3, 2, 6) """ # new values newval = a.values[indices] # if the new values is a scalar, then just return it if np.isscalar(newval): return newval # new axes: broacast indices (should do the same as above, since integers are just broadcast) indices2 = broadcast_indices(indices) # assert np.all(newval == a.values[indices2]) # make a multi-axis with tuples is_array2 = np.array([np.iterable(ix) for ix in indices2]) nb_array2 = is_array2.sum() # If none or one array is present, easy if nb_array2 <= 1: newaxes = [ a.axes[i][ix] for i, ix in enumerate(indices) if not np.isscalar(ix) ] # indices or indices2, does not matter # else, finer check needed else: # same stats but on original indices is_array = np.array([np.iterable(ix) for ix in indices]) array_ix_pos = np.where(is_array)[0] # Determine where the axis will be inserted # - need to consider the integers as well (broadcast as arrays) # - if two indexed dimensions are not contiguous, new axis placed at first position... # a = zeros((3,4,5,6)) # a[:,[1,2],:,0].shape ==> (2, 3, 5) # a[:,[1,2],0,:].shape ==> (3, 2, 6) array_ix_pos2 = np.where(is_array2)[0] if np.any(np.diff(array_ix_pos2) > 1 ): # that mean, if two indexed dimensions are not contiguous insert = 0 else: insert = array_ix_pos2[0] # Now determine axis value # ...if originally only one array was provided, use these values correspondingly if len(array_ix_pos) == 1: i = array_ix_pos[0] values = a.axes[i].values[indices[i]] name = a.axes[i].name # ...else use a list of tuples else: values = zip( *[a.axes[i].values[indices2[i]] for i in array_ix_pos]) name = ",".join([a.axes[i].name for i in array_ix_pos]) broadcastaxis = Axis(values, name) newaxes = Axes() for i, ax in enumerate(a.axes): # axis is already part of the broadcast axis: skip if is_array2[i]: continue else: newaxis = ax[indices2[i]] ## do not append axis if scalar #if np.isscalar(newaxis): # continue newaxes.append(newaxis) # insert the right new axis at the appropriate position newaxes.insert(insert, broadcastaxis) return a._constructor(newval, newaxes, **a._metadata)
def __init__(self, url, chart_id): self.url = url self.chart_id = chart_id self.axes = Axes() self.graphics = Graphic() self.layout = Layout()
def aggregate(arrays, check_overlap=True): """ like a multi-dimensional concatenate input: arrays: sequence of DimArrays check_overlap, optional: if True, check that arrays do not overlap (to avoid data loss) If any two elements overlap, keep the one which is not NaN, if applicable or raise an error if two valid values overlap Default is True to reduce the risk of errors, but this makes the operation less performant since every time a copy of the subarray is extracted and tested for NaNs. Consider setting check_overlap to False for large arrays for a well-tested problems, if the valid-nan selection is not required. Note: Probably a bad idea to have duplicate axis values (not tested) TODO: add support for missing values other than np.nan Examples: --------- >>> a = DimArray([[1.,2,3]],axes=[('line',[0]), ('col',['a','b','c'])]) >>> b = DimArray([[4],[5]], axes=[('line',[1,2]), ('col',['d'])]) >>> c = DimArray([[22]], axes=[('line',[2]), ('col',['b'])]) >>> d = DimArray([-99], axes=[('line',[4])]) >>> aggregate((a,b,c,d)) dimarray: 10 non-null elements (6 null) dimensions: 'line', 'col' 0 / line (4): 0 to 4 1 / col (4): a to d array([[ 1., 2., 3., nan], [ nan, nan, nan, 4.], [ nan, 22., nan, 5.], [-99., -99., -99., -99.]]) But beware of overlapping arrays. The following will raise an error: >>> a = DimArray([[1.,2,3]],axes=[('line',[0]), ('col',['a','b','c'])]) >>> b = DimArray([[4],[5]], axes=[('line',[0,1]), ('col',['b'])]) >>> try: ... aggregate((a,b)) ... except ValueError, msg: ... print msg Overlapping arrays: set check_overlap to False to suppress this error. Can set check_overlap to False to let it happen anyway (the latter array wins) >>> aggregate((a,b), check_overlap=False) dimarray: 4 non-null elements (2 null) dimensions: 'line', 'col' 0 / line (2): 0 to 1 1 / col (3): a to c array([[ 1., 4., 3.], [ nan, 5., nan]]) Note that if NaNs are present on overlapping, the valid data are kept >>> a = DimArray([[1.,2,3]],axes=[('line',[1]), ('col',['a','b','c'])]) >>> b = DimArray([[np.nan],[5]], axes=[('line',[1,2]), ('col',['b'])]) >>> aggregate((a,b)) # does not overwrite `2` at location (1, 'b') dimarray: 4 non-null elements (2 null) dimensions: 'line', 'col' 0 / line (2): 1 to 2 1 / col (3): a to c array([[ 1., 2., 3.], [ nan, 5., nan]]) """ # list of common dimensions dims = get_dims(*arrays) # build a common Axes object axes = Axes() for d in dims: newaxis = concatenate_axes([a.axes[d] for a in arrays if d in a.dims]) newaxis.values = np.unique(newaxis.values) # unique values axes.append(newaxis) # Fill in an array newarray = arrays[0]._constructor(None, axes=axes, dtype=arrays[0].dtype) for a in arrays: indices = {ax.name:ax.values for ax in a.axes} if check_overlap: # look for nans in replaced and replacing arrays subarray = newarray.take(indices, broadcast_arrays=False).values subarray_is_nan = np.isnan(subarray) newvalues_is_nan = np.isnan(a.values) # check overlapping overlap_values = ~subarray_is_nan & ~newvalues_is_nan if np.any(overlap_values): raise ValueError("Overlapping arrays: set check_overlap to False to suppress this error.") # only take new non-nan values newvalues = np.where(newvalues_is_nan, subarray, a.values) else: newvalues = a.values # The actual operation is done by put newarray.put(newvalues, indices=indices, inplace=True, convert=True, broadcast_arrays=False) # That's it ! return newarray