def plane(self, obj, *args, **kwargs): """Draw Fol as great circle""" assert obj.type is Fol, "Only Fol instance could be plotted as plane." if "zorder" not in kwargs: kwargs["zorder"] = 5 animate = kwargs.pop("animate", False) if isinstance(obj, Group): x = [] y = [] for azi, inc in obj.dd.T: xx, yy = self._cone( p2v(azi, inc), l2v(azi, inc), limit=89.9999, res=int(cosd(inc) * 179 + 2) ) x = np.hstack((x, xx, np.nan)) y = np.hstack((y, yy, np.nan)) x = x[:-1] y = y[:-1] else: azi, inc = obj.dd x, y = self._cone( p2v(azi, inc), l2v(azi, inc), limit=89.9999, res=int(cosd(inc) * 179 + 2) ) h = self.fig.axes[self.active].plot(x, y, *args, **kwargs) if animate: self.artists.append(tuple(h)) self.draw()
def plane(self, obj, *args, **kwargs): """Draw Fol as great circle""" assert obj.type is Fol, "Only Fol instance could be plotted as plane." if "zorder" not in kwargs: kwargs["zorder"] = 5 animate = kwargs.pop("animate", False) if isinstance(obj, Group): x = [] y = [] for azi, inc in obj.dd.T: xx, yy = self._cone( p2v(azi, inc), l2v(azi, inc), limit=89.9999, res=cosd(inc) * 179 + 2 ) x = np.hstack((x, xx, np.nan)) y = np.hstack((y, yy, np.nan)) x = x[:-1] y = y[:-1] else: azi, inc = obj.dd x, y = self._cone( p2v(azi, inc), l2v(azi, inc), limit=89.9999, res=cosd(inc) * 179 + 2 ) h = self.fig.axes[self.active].plot(x, y, *args, **kwargs) if animate: self.artists.append(tuple(h)) self.draw()
def initgrid(self, **kwargs): # parse options grid = kwargs.get("grid", "radial") if grid == "radial": ctn_points = int( np.round(np.sqrt(kwargs.get("npoints", 1800)) / 0.280269786)) # calc grid self.xg = 0 self.yg = 0 for rho in np.linspace(0, 1, int(np.round(ctn_points / 2 / np.pi))): theta = np.linspace(0, 360, int(np.round(ctn_points * rho + 1)))[:-1] self.xg = np.hstack((self.xg, rho * sind(theta))) self.yg = np.hstack((self.yg, rho * cosd(theta))) elif grid == "ortho": n = int( np.round( np.sqrt(kwargs.get("npoints", 1800) - 4) / 0.8685725142)) x, y = np.meshgrid(np.linspace(-1, 1, n), np.linspace(-1, 1, n)) d2 = (x**2 + y**2) <= 1 self.xg = np.hstack((0, 1, 0, -1, x[d2])) self.yg = np.hstack((1, 0, -1, 0, y[d2])) else: raise TypeError("Wrong grid type!") self.dcgrid = l2v(*getldd(self.xg, self.yg)).T self.n = self.dcgrid.shape[0] self.values = np.zeros(self.n, dtype=np.float) self.triang = self._buildtrig_workaround(self.xg, self.yg)
def from_axis(cls, vector, theta): """Return ``DefGrad`` representing rotation around axis. Args: vector: Rotation axis as ``Vec3`` like object theta: Angle of rotation in degrees Example: >>> F = DefGrad.from_axis(Lin(120, 30), 45) """ x, y, z = vector.uv c, s = cosd(theta), sind(theta) xs, ys, zs = x * s, y * s, z * s xc, yc, zc = x * (1 - c), y * (1 - c), z * (1 - c) xyc, yzc, zxc = x * yc, y * zc, z * xc return cls([ [x * xc + c, xyc - zs, zxc + ys], [xyc + zs, y * yc + c, yzc - xs], [zxc - ys, yzc + xs, z * zc + c], ])
def from_axis(cls, vector, theta): """Return ``DefGrad`` representing rotation around axis. Args: vector: Rotation axis as ``Vec3`` like object theta: Angle of rotation in degrees Example: >>> F = DefGrad.from_axis(Lin(120, 30), 45) """ x, y, z = vector.uv c, s = cosd(theta), sind(theta) xs, ys, zs = x * s, y * s, z * s xc, yc, zc = x * (1 - c), y * (1 - c), z * (1 - c) xyc, yzc, zxc = x * yc, y * zc, z * xc return cls( [ [x * xc + c, xyc - zs, zxc + ys], [xyc + zs, y * yc + c, yzc - xs], [zxc - ys, yzc + xs, z * zc + c], ] )
def cla(self): """Clear axes and draw empty projection""" def lat(a, phi): return self._cone(l2v(a, 0), l2v(a, phi), limit=89.9999, res=91) def lon(a, theta): return self._cone(p2v(a, theta), l2v(a, theta), limit=80, res=91) # recreate default Axes self.fig.clear() self.ax = self.fig.subplots(ncols=self.ncols) for ax in self.fig.axes: ax.cla() ax.format_coord = self.format_coord ax.set_aspect("equal") ax.set_autoscale_on(False) ax.axis([-1.05, 1.05, -1.05, 1.05]) ax.set_axis_off() # Projection circle ax.text(0, 1.02, "N", ha="center", va="baseline", fontsize=16) ax.add_artist(plt.Circle((0, 0), 1, color="w", zorder=0)) ax.add_artist(plt.Circle((0, 0), 1, color="None", ec="k", zorder=3)) if self.grid: # Main cross ax.plot( [-1, 1, np.nan, 0, 0], [0, 0, np.nan, -1, 1], self.grid_style, zorder=3, lw=self.gridlw, ) # Latitudes lat_n = np.array([lat(0, phi) for phi in range(10, 90, 10)]) ax.plot( lat_n[:, 0, :].T, lat_n[:, 1, :].T, self.grid_style, zorder=3, lw=self.gridlw, ) lat_s = np.array([lat(180, phi) for phi in range(10, 90, 10)]) ax.plot( lat_s[:, 0, :].T, lat_s[:, 1, :].T, self.grid_style, zorder=3, lw=self.gridlw, ) # Longitudes le = np.array([lon(90, theta) for theta in range(10, 90, 10)]) ax.plot( le[:, 0, :].T, le[:, 1, :].T, self.grid_style, zorder=3, lw=self.gridlw, ) lw = np.array([lon(270, theta) for theta in range(10, 90, 10)]) ax.plot( lw[:, 0, :].T, lw[:, 1, :].T, self.grid_style, zorder=3, lw=self.gridlw, ) # ticks if self.ticks: a = np.arange(0, 360, 30) tt = np.array([0.98, 1]) x = np.outer(tt, sind(a)) y = np.outer(tt, cosd(a)) ax.plot(x, y, "k", zorder=4) # Middle cross ax.plot( [-0.02, 0.02, np.nan, 0, 0], [0, 0, np.nan, -0.02, 0.02], "k", zorder=4 ) self.draw()