def test_lib_floatcanvas_fc_arc(self): fccanvas = fc.FloatCanvas(self.frame) obj = fc.Arc((10, 10), (20, 20), (5, 5)) fccanvas.AddObject(obj) fccanvas.Destroy()
def draw_wafer_outline(dia=150, excl=5, flat=None): """ Draw a wafer outline for a given radius, including any exclusion lines. Parameters ---------- dia : float, optional The wafer diameter in mm. Defaults to `150`. excl : float, optional The exclusion distance from the edge of the wafer in mm. Defaults to `5`. flat : float, optional The exclusion distance from the wafer flat in mm. If ``None``, uses the same value as ``excl``. Defaults to ``None``. Returns ------- :class:`wx.lib.floatcanvas.FloatCanvas.Group` A ``Group`` that can be added to any floatcanvas.FloatCanvas instance. """ rad = float(dia) / 2.0 if flat is None: flat = excl # Full wafer outline circle circ = FloatCanvas.Circle( (0, 0), dia, LineColor=wm_const.wm_OUTLINE_COLOR, LineWidth=1, ) # Calculate the exclusion Radius exclRad = 0.5 * (dia - 2.0 * excl) if dia in wm_const.wm_FLAT_LENGTHS: # A flat is defined, so we draw it. flat_size = wm_const.wm_FLAT_LENGTHS[dia] x = flat_size / 2 y = -math.sqrt(rad**2 - x**2) # Wfr Flat's Y Location arc = FloatCanvas.Arc( (x, y), (-x, y), (0, 0), LineColor=wm_const.wm_WAFER_EDGE_COLOR, LineWidth=3, ) # actually a wafer flat, but called notch notch = draw_wafer_flat(rad, wm_const.wm_FLAT_LENGTHS[dia]) # Define the arc angle based on the flat exclusion, not the edge # exclusion. Find the flat exclusion X and Y coords. FSSflatY = y + flat if exclRad < abs(FSSflatY): # Then draw a circle with no flat excl_arc = FloatCanvas.Circle( (0, 0), exclRad * 2, LineColor=wm_const.wm_WAFER_EDGE_COLOR, LineWidth=3, ) excl_group = FloatCanvas.Group([excl_arc]) else: FSSflatX = math.sqrt(exclRad**2 - FSSflatY**2) # Define the wafer arc excl_arc = FloatCanvas.Arc( (FSSflatX, FSSflatY), (-FSSflatX, FSSflatY), (0, 0), LineColor=wm_const.wm_WAFER_EDGE_COLOR, LineWidth=3, ) excl_notch = draw_wafer_flat(exclRad, FSSflatX * 2) excl_group = FloatCanvas.Group([excl_arc, excl_notch]) else: # Flat not defined, so use a notch to denote wafer orientation. ang = 2.5 start_xy, end_xy = calc_flat_coords(rad, ang) arc = FloatCanvas.Arc( start_xy, end_xy, (0, 0), LineColor=wm_const.wm_WAFER_EDGE_COLOR, LineWidth=3, ) notch = draw_wafer_notch(rad) # Flat not defined, so use a notch to denote wafer orientation. start_xy, end_xy = calc_flat_coords(exclRad, ang) excl_arc = FloatCanvas.Arc( start_xy, end_xy, (0, 0), LineColor=wm_const.wm_WAFER_EDGE_COLOR, LineWidth=3, ) excl_notch = draw_wafer_notch(exclRad) excl_group = FloatCanvas.Group([excl_arc, excl_notch]) # Group the outline arc and the orientation (flat / notch) together group = FloatCanvas.Group([circ, arc, notch, excl_group]) return group
def DrawRose(self, Rose): self.Rose = Rose wfs = Rose.binned_data vel_bins = Rose.vel_bins units = Rose.units title = Rose.title Canvas = self.Canvas Canvas.ClearAll() calm = wfs[0, :].sum() n_dir = wfs.shape[1] # number of direction bins # remove the calm row wfs = wfs[1:, :] n = wfs.shape[0] c = (8. / n * np.linspace(0, n, n) + 2)[::-1] cm = windtools.colormaps.ColorMap("jet") clrs = cm.get_colors(c, (0, 10)) wf = wfs.sum(axis=0) max_percent = wf.max() # max percent in all direction bins #sc = float(rsize)**2/mwf #scale factor, pts per number da = 2.0 * np.pi / n_dir dah = .45 * da theta = np.linspace(0, 2 * np.pi, n_dir + 1)[:-1] #now plot : line_width = 1 fill_color = "black" text_pos = 'cc' ## compute the locations of the circles if max_percent <= 12: circles = list(range(2, int(max_percent) + 3, 2)) elif max_percent <= 30: circles = [3] + list(range(5, int(max_percent) + 6, 5)) elif max_percent <= 60: circles = [5] + list(range(10, int(max_percent) + 11, 10)) else: circles = [5, 10] + list(range(20, int(max_percent) + 21, 20)) # compute the radius of the center calm circle r_center = np.sqrt(calm / n_dir) r_circles = np.sqrt(np.array(circles)) + r_center max_r = r_circles[-1] r_scale = 1 / max_r r_circles *= r_scale r_center *= r_scale # compute the radius of the center calm circle r_center = np.sqrt(calm / n_dir) * r_scale # generate the "petals" for i, a in enumerate(theta): percents = list(np.cumsum(wfs[:, i])) percents.reverse() for i, percent in enumerate(percents): if percent == 0: continue r = (np.sqrt((percent)) * r_scale + r_center) Canvas.AddObject( FloatCanvas.Arc( (r * np.sin(a + dah), r * np.cos(a + dah)), (r * np.sin(a - dah), r * np.cos(a - dah)), (0, 0), #LineColor = "Black", LineStyle=None, LineWidth=1, FillColor=tuple(clrs[i]), FillStyle="Solid", )) for r, percent in zip(r_circles, circles): # make the blue circles Canvas.AddCircle( (0, 0), r * 2, LineColor="blue", ) lab = "%i%%" % (percent) Canvas.AddScaledText(lab, (0, -r), Size=self.small_text, Family=self.font_family, BackgroundColor='white', Position='cc') # put the percent light and variable in the middle: Canvas.AddCircle( (0, 0), r_center * 2, #LineColor="red", LineColor=None, FillColor="White" #FillColor=None ) Canvas.AddScaledText("%.1f%%" % calm, (0, 0), Family=self.font_family, Position=text_pos, BackgroundColor="White", Size=self.small_text) # Add the compass points r = 1.05 text_style = { "Size": self.large_text, "Weight": wx.BOLD, "Family": self.font_family } Canvas.AddScaledText("N", (0, r), Position='bc', **text_style) Canvas.AddScaledText("S", (0, -r), Position='tc', **text_style) Canvas.AddScaledText("E", (r, 0), Position='cl', **text_style) Canvas.AddScaledText("W", (-r, 0), Position='cr', **text_style) # add the Title: if title is None: title = "Wind Rose" Canvas.AddScaledText( title, (0, 1.4), Size=self.med_text, Weight=wx.BOLD, Family=self.font_family, Position='tc', ) # Add the legend: #vel_bins = vel_bins[1:-1] n = len(vel_bins) W = 2.0 dw = W / n X0 = -W / 2.0 Y = -1.5 H = 0.1 for i, vel in enumerate(vel_bins): X = X0 + i * dw Canvas.AddRectangle( (X, Y), (dw * 1.03, 0.1), LineStyle=None, FillColor=tuple(clrs[-(i + 1)]), ) Canvas.AddScaledText( "%i" % vel, (X, Y + H), Size=self.small_text, Family=self.font_family, #Weight = wx.BOLD, Position='bc', ) Canvas.AddScaledText( units, (X + dw, Y + H), Size=self.small_text, Family=self.font_family, #Weight = wx.BOLD, Position='bl', ) # add an invisible box for the Bounding Box: #Canvas._ResetBoundingBox() #w = np.abs(Canvas.BoundingBox).max() * 2 #Canvas.AddRectangle((-w/2, -w/2), (w, w), LineStyle=None ) Canvas.ZoomToBB()