Python numpy.hypot() Examples
The following are 30
code examples of numpy.hypot().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example #1
Source File: test_ufunc.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_NotImplemented_not_returned(self): # See gh-5964 and gh-2091. Some of these functions are not operator # related and were fixed for other reasons in the past. binary_funcs = [ np.power, np.add, np.subtract, np.multiply, np.divide, np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or, np.bitwise_xor, np.left_shift, np.right_shift, np.fmax, np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2, np.logical_and, np.logical_or, np.logical_xor, np.maximum, np.minimum, np.mod ] # These functions still return NotImplemented. Will be fixed in # future. # bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal] a = np.array('1') b = 1 for f in binary_funcs: assert_raises(TypeError, f, a, b)
Example #2
Source File: data_browser.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def onpick(self, event): if event.artist != line: return True N = len(event.ind) if not N: return True # the click locations x = event.mouseevent.xdata y = event.mouseevent.ydata distances = np.hypot(x - xs[event.ind], y - ys[event.ind]) indmin = distances.argmin() dataind = event.ind[indmin] self.lastind = dataind self.update()
Example #3
Source File: test_ufunc.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_NotImplemented_not_returned(self): # See gh-5964 and gh-2091. Some of these functions are not operator # related and were fixed for other reasons in the past. binary_funcs = [ np.power, np.add, np.subtract, np.multiply, np.divide, np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or, np.bitwise_xor, np.left_shift, np.right_shift, np.fmax, np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2, np.logical_and, np.logical_or, np.logical_xor, np.maximum, np.minimum, np.mod, np.greater, np.greater_equal, np.less, np.less_equal, np.equal, np.not_equal] a = np.array('1') b = 1 c = np.array([1., 2.]) for f in binary_funcs: assert_raises(TypeError, f, a, b) assert_raises(TypeError, f, c, a)
Example #4
Source File: rectify.py From facade-segmentation with MIT License | 6 votes |
def _vlines(lines, ctrs=None, lengths=None, vecs=None, angle_lo=20, angle_hi=160, ransac_options=RANSAC_OPTIONS): ctrs = ctrs if ctrs is not None else lines.mean(1) vecs = vecs if vecs is not None else lines[:, 1, :] - lines[:, 0, :] lengths = lengths if lengths is not None else np.hypot(vecs[:, 0], vecs[:, 1]) angles = np.degrees(np.arccos(vecs[:, 0] / lengths)) points = np.column_stack([ctrs[:, 0], angles]) point_indices, = np.nonzero((angles > angle_lo) & (angles < angle_hi)) points = points[point_indices] if len(points) > 2: model_ransac = linear_model.RANSACRegressor(**ransac_options) model_ransac.fit(points[:, 0].reshape(-1, 1), points[:, 1].reshape(-1, 1)) inlier_mask = model_ransac.inlier_mask_ valid_lines = lines[point_indices[inlier_mask], :, :] else: valid_lines = [] return valid_lines
Example #5
Source File: pmlib.py From sea_ice_drift with GNU General Public License v3.0 | 6 votes |
def get_hessian(ccm, hes_norm=True, hes_smth=False, **kwargs): """ Find Hessian of the input cross correlation matrix <ccm> Parameters ---------- ccm : 2D numpy array, cross-correlation matrix hes_norm : bool, normalize Hessian by AVG and STD? hes_smth : bool, smooth Hessian? """ if hes_smth: ccm2 = nd.filters.gaussian_filter(ccm, 1) else: ccm2 = ccm # Jacobian components dcc_dy, dcc_dx = np.gradient(ccm2) # Hessian components d2cc_dx2 = np.gradient(dcc_dx)[1] d2cc_dy2 = np.gradient(dcc_dy)[0] hes = np.hypot(d2cc_dx2, d2cc_dy2) if hes_norm: hes = (hes - np.median(hes)) / np.std(hes) return hes
Example #6
Source File: rectify.py From facade-segmentation with MIT License | 6 votes |
def _hlines(lines, ctrs=None, lengths=None, vecs=None, angle_lo=20, angle_hi=160, ransac_options=RANSAC_OPTIONS): ctrs = ctrs if ctrs is not None else lines.mean(1) vecs = vecs if vecs is not None else lines[:, 1, :] - lines[:, 0, :] lengths = lengths if lengths is not None else np.hypot(vecs[:, 0], vecs[:, 1]) angles = np.degrees(np.arccos(vecs[:, 1] / lengths)) points = np.column_stack([ctrs[:, 1], angles]) point_indices, = np.nonzero((angles > angle_lo) & (angles < angle_hi)) points = points[point_indices] if len(points) > 2: model_ransac = linear_model.RANSACRegressor(**ransac_options) model_ransac.fit(points[:, 0].reshape(-1, 1), points[:, 1].reshape(-1, 1)) inlier_mask = model_ransac.inlier_mask_ valid_lines = lines[point_indices[inlier_mask], :, :] else: valid_lines = [] return valid_lines
Example #7
Source File: grid.py From pysheds with GNU General Public License v3.0 | 6 votes |
def facet_flow(self, e0, e1, e2, d1=1, d2=1): s1 = (e0 - e1)/d1 s2 = (e1 - e2)/d2 r = np.arctan2(s2, s1) s = np.hypot(s1, s2) diag_angle = np.arctan2(d2, d1) diag_distance = np.hypot(d1, d2) b0 = (r < 0) b1 = (r > diag_angle) r[b0] = 0 s[b0] = s1[b0] if isinstance(diag_angle, np.ndarray): r[b1] = diag_angle[b1] else: r[b1] = diag_angle s[b1] = ((e0 - e2)/diag_distance)[b1] return r, s
Example #8
Source File: test_ufunc.py From vnpy_crypto with MIT License | 6 votes |
def test_NotImplemented_not_returned(self): # See gh-5964 and gh-2091. Some of these functions are not operator # related and were fixed for other reasons in the past. binary_funcs = [ np.power, np.add, np.subtract, np.multiply, np.divide, np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or, np.bitwise_xor, np.left_shift, np.right_shift, np.fmax, np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2, np.logical_and, np.logical_or, np.logical_xor, np.maximum, np.minimum, np.mod ] # These functions still return NotImplemented. Will be fixed in # future. # bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal] a = np.array('1') b = 1 for f in binary_funcs: assert_raises(TypeError, f, a, b)
Example #9
Source File: test_ufunc.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def test_NotImplemented_not_returned(self): # See gh-5964 and gh-2091. Some of these functions are not operator # related and were fixed for other reasons in the past. binary_funcs = [ np.power, np.add, np.subtract, np.multiply, np.divide, np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or, np.bitwise_xor, np.left_shift, np.right_shift, np.fmax, np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2, np.logical_and, np.logical_or, np.logical_xor, np.maximum, np.minimum, np.mod ] # These functions still return NotImplemented. Will be fixed in # future. # bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal] a = np.array('1') b = 1 for f in binary_funcs: assert_raises(TypeError, f, a, b)
Example #10
Source File: test_ufunc.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_NotImplemented_not_returned(self): # See gh-5964 and gh-2091. Some of these functions are not operator # related and were fixed for other reasons in the past. binary_funcs = [ np.power, np.add, np.subtract, np.multiply, np.divide, np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or, np.bitwise_xor, np.left_shift, np.right_shift, np.fmax, np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2, np.logical_and, np.logical_or, np.logical_xor, np.maximum, np.minimum, np.mod, np.greater, np.greater_equal, np.less, np.less_equal, np.equal, np.not_equal] a = np.array('1') b = 1 c = np.array([1., 2.]) for f in binary_funcs: assert_raises(TypeError, f, a, b) assert_raises(TypeError, f, c, a)
Example #11
Source File: test_ufunc.py From pySINDy with MIT License | 6 votes |
def test_NotImplemented_not_returned(self): # See gh-5964 and gh-2091. Some of these functions are not operator # related and were fixed for other reasons in the past. binary_funcs = [ np.power, np.add, np.subtract, np.multiply, np.divide, np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or, np.bitwise_xor, np.left_shift, np.right_shift, np.fmax, np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2, np.logical_and, np.logical_or, np.logical_xor, np.maximum, np.minimum, np.mod ] # These functions still return NotImplemented. Will be fixed in # future. # bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal] a = np.array('1') b = 1 for f in binary_funcs: assert_raises(TypeError, f, a, b)
Example #12
Source File: turbine.py From FLORIS with Apache License 2.0 | 6 votes |
def _create_swept_area_grid(self): # TODO: add validity check: # rotor points has a minimum in order to always include points inside # the disk ... 2? # # the grid consists of the y,z coordinates of the discrete points which # lie within the rotor area: [(y1,z1), (y2,z2), ... , (yN, zN)] # update: # using all the grid point because that how roald did it. # are the points outside of the rotor disk used later? # determine the dimensions of the square grid num_points = int(np.round(np.sqrt(self.grid_point_count))) # syntax: np.linspace(min, max, n points) horizontal = np.linspace(-self.rotor_radius, self.rotor_radius, num_points) vertical = np.linspace(-self.rotor_radius, self.rotor_radius, num_points) # build the grid with all of the points grid = [(h, vertical[i]) for i in range(num_points) for h in horizontal] # keep only the points in the swept area grid = [point for point in grid if np.hypot(point[0], point[1]) < self.rotor_radius] return grid
Example #13
Source File: test_kdtree.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_max_one_side(self): assert_almost_equal(self.rect.max_distance_point([0.5,1.5]),np.hypot(0.5,1.5))
Example #14
Source File: quiver.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def set_UVC(self, U, V, C=None): self.u = ma.masked_invalid(U, copy=False).ravel() self.v = ma.masked_invalid(V, copy=False).ravel() if C is not None: c = ma.masked_invalid(C, copy=False).ravel() x, y, u, v, c = delete_masked_points(self.x.ravel(), self.y.ravel(), self.u, self.v, c) _check_consistent_shapes(x, y, u, v, c) else: x, y, u, v = delete_masked_points(self.x.ravel(), self.y.ravel(), self.u, self.v) _check_consistent_shapes(x, y, u, v) magnitude = np.hypot(u, v) flags, barbs, halves, empty = self._find_tails(magnitude, self.rounding, **self.barb_increments) # Get the vertices for each of the barbs plot_barbs = self._make_barbs(u, v, flags, barbs, halves, empty, self._length, self._pivot, self.sizes, self.fill_empty, self.flip) self.set_verts(plot_barbs) # Set the color array if C is not None: self.set_array(c) # Update the offsets in case the masked data changed xy = np.column_stack((x, y)) self._offsets = xy self.stale = True
Example #15
Source File: main_ui.py From innstereo with GNU General Public License v2.0 | 5 votes |
def draw_angelier(self, values): """ Draws the Angelier arrows for a fault plane layer. Receives the data as a list. Iterates over arrow-position and the sense and displays the resulting arrow. """ lyr_obj, plane_dir, plane_dip, strikes, \ line_dir, line_dip, lp_plane_dir, lp_plane_dip, sense = values lon, lat = mplstereonet.line(line_dip, line_dir) for x, y, sns in zip(lon, lat, sense): mag = np.hypot(x, y) u, v = x / mag, y / mag if sns == "up": self.ax_stereo.quiver(x, y, -u, -v, width=1.5, headwidth=4, units="dots", pivot="middle", color=lyr_obj.get_arrow_color()) elif sns == "dn": self.ax_stereo.quiver(x, y, u, v, width=1.5, headwidth=4, units="dots", pivot="middle", color=lyr_obj.get_arrow_color()) elif sns == "sin": pass elif sns == "dex": pass else: pass return None
Example #16
Source File: axes3d.py From opticspy with MIT License | 5 votes |
def format_coord(self, xd, yd): """ Given the 2D view coordinates attempt to guess a 3D coordinate. Looks for the nearest edge to the point and then assumes that the point is at the same z location as the nearest point on the edge. """ if self.M is None: return '' if self.button_pressed in self._rotate_btn: return 'azimuth=%d deg, elevation=%d deg ' % (self.azim, self.elev) # ignore xd and yd and display angles instead p = (xd, yd) edges = self.tunit_edges() #lines = [proj3d.line2d(p0,p1) for (p0,p1) in edges] ldists = [(proj3d.line2d_seg_dist(p0, p1, p), i) for \ i, (p0, p1) in enumerate(edges)] ldists.sort() # nearest edge edgei = ldists[0][1] p0, p1 = edges[edgei] # scale the z value to match x0, y0, z0 = p0 x1, y1, z1 = p1 d0 = np.hypot(x0-xd, y0-yd) d1 = np.hypot(x1-xd, y1-yd) dt = d0+d1 z = d1/dt * z0 + d0/dt * z1 x, y, z = proj3d.inv_transform(xd, yd, z, self.M) xs = self.format_xdata(x) ys = self.format_ydata(y) zs = self.format_zdata(z) return 'x=%s, y=%s, z=%s' % (xs, ys, zs)
Example #17
Source File: windmap.py From windmap with BSD 2-Clause "Simplified" License | 5 votes |
def _detectLoop(self, xVals, yVals): """ Detect closed loops and nodes in a streamline. """ x = xVals[-1] y = yVals[-1] D = np.array([np.hypot(x-xj, y-yj) for xj,yj in zip(xVals[:-1],yVals[:-1])]) return (D < 0.9 * self.dr).any()
Example #18
Source File: quiver.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _angles_lengths(self, U, V, eps=1): xy = self.ax.transData.transform(self.XY) uv = np.column_stack((U, V)) xyp = self.ax.transData.transform(self.XY + eps * uv) dxy = xyp - xy angles = np.arctan2(dxy[:, 1], dxy[:, 0]) lengths = np.hypot(*dxy.T) / eps return angles, lengths
Example #19
Source File: CoordTransforms3.py From PyGPS with GNU Affero General Public License v3.0 | 5 votes |
def xy2angles(x,y): elout = 90-np.hypot(x,y) azout = np.degrees(np.arctan2(x,y)) return (azout,elout)
Example #20
Source File: axes3d.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def format_coord(self, xd, yd): """ Given the 2D view coordinates attempt to guess a 3D coordinate. Looks for the nearest edge to the point and then assumes that the point is at the same z location as the nearest point on the edge. """ if self.M is None: return '' if self.button_pressed in self._rotate_btn: return 'azimuth=%d deg, elevation=%d deg ' % (self.azim, self.elev) # ignore xd and yd and display angles instead # nearest edge p0, p1 = min(self.tunit_edges(), key=lambda edge: proj3d.line2d_seg_dist( edge[0], edge[1], (xd, yd))) # scale the z value to match x0, y0, z0 = p0 x1, y1, z1 = p1 d0 = np.hypot(x0-xd, y0-yd) d1 = np.hypot(x1-xd, y1-yd) dt = d0+d1 z = d1/dt * z0 + d0/dt * z1 x, y, z = proj3d.inv_transform(xd, yd, z, self.M) xs = self.format_xdata(x) ys = self.format_ydata(y) zs = self.format_zdata(z) return 'x=%s, y=%s, z=%s' % (xs, ys, zs)
Example #21
Source File: _continuous_distns.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _pdf(self, x, a, b): gamma = np.sqrt(a**2 - b**2) fac1 = a / np.pi * np.exp(gamma) sq = np.hypot(1, x) # reduce overflows return fac1 * sc.k1e(a * sq) * np.exp(b*x - a*sq) / sq
Example #22
Source File: poly_editor.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_ind_under_point(self, event): 'get the index of the vertex under point if within epsilon tolerance' # display coords xy = np.asarray(self.poly.xy) xyt = self.poly.get_transform().transform(xy) xt, yt = xyt[:, 0], xyt[:, 1] d = np.hypot(xt - event.x, yt - event.y) indseq, = np.nonzero(d == d.min()) ind = indseq[0] if d[ind] >= self.epsilon: ind = None return ind
Example #23
Source File: quiver.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def set_UVC(self, U, V, C=None): self.u = ma.masked_invalid(U, copy=False).ravel() self.v = ma.masked_invalid(V, copy=False).ravel() if C is not None: c = ma.masked_invalid(C, copy=False).ravel() x, y, u, v, c = delete_masked_points(self.x.ravel(), self.y.ravel(), self.u, self.v, c) _check_consistent_shapes(x, y, u, v, c) else: x, y, u, v = delete_masked_points(self.x.ravel(), self.y.ravel(), self.u, self.v) _check_consistent_shapes(x, y, u, v) magnitude = np.hypot(u, v) flags, barbs, halves, empty = self._find_tails(magnitude, self.rounding, **self.barb_increments) # Get the vertices for each of the barbs plot_barbs = self._make_barbs(u, v, flags, barbs, halves, empty, self._length, self._pivot, self.sizes, self.fill_empty, self.flip) self.set_verts(plot_barbs) # Set the color array if C is not None: self.set_array(c) # Update the offsets in case the masked data changed xy = np.column_stack((x, y)) self._offsets = xy self.stale = True
Example #24
Source File: quiver.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _dots_per_unit(self, units): """ Return a scale factor for converting from units to pixels """ ax = self.ax if units in ('x', 'y', 'xy'): if units == 'x': dx0 = ax.viewLim.width dx1 = ax.bbox.width elif units == 'y': dx0 = ax.viewLim.height dx1 = ax.bbox.height else: # 'xy' is assumed dxx0 = ax.viewLim.width dxx1 = ax.bbox.width dyy0 = ax.viewLim.height dyy1 = ax.bbox.height dx1 = np.hypot(dxx1, dyy1) dx0 = np.hypot(dxx0, dyy0) dx = dx1 / dx0 else: if units == 'width': dx = ax.bbox.width elif units == 'height': dx = ax.bbox.height elif units == 'dots': dx = 1.0 elif units == 'inches': dx = ax.figure.dpi else: raise ValueError('unrecognized units') return dx
Example #25
Source File: contour.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def locate_label(self, linecontour, labelwidth): """ Find good place to draw a label (relatively flat part of the contour). """ # Number of contour points nsize = len(linecontour) if labelwidth > 1: xsize = int(np.ceil(nsize / labelwidth)) else: xsize = 1 if xsize == 1: ysize = nsize else: ysize = int(labelwidth) XX = np.resize(linecontour[:, 0], (xsize, ysize)) YY = np.resize(linecontour[:, 1], (xsize, ysize)) # I might have fouled up the following: yfirst = YY[:, :1] ylast = YY[:, -1:] xfirst = XX[:, :1] xlast = XX[:, -1:] s = (yfirst - YY) * (xlast - xfirst) - (xfirst - XX) * (ylast - yfirst) L = np.hypot(xlast - xfirst, ylast - yfirst) # Ignore warning that divide by zero throws, as this is a valid option with np.errstate(divide='ignore', invalid='ignore'): dist = np.sum(np.abs(s) / L, axis=-1) x, y, ind = self.get_label_coords(dist, XX, YY, ysize, labelwidth) # There must be a more efficient way... lc = [tuple(l) for l in linecontour] dind = lc.index((x, y)) return x, y, dind
Example #26
Source File: quiver.py From neural-network-animation with MIT License | 5 votes |
def set_UVC(self, U, V, C=None): self.u = ma.masked_invalid(U, copy=False).ravel() self.v = ma.masked_invalid(V, copy=False).ravel() if C is not None: c = ma.masked_invalid(C, copy=False).ravel() x, y, u, v, c = delete_masked_points(self.x.ravel(), self.y.ravel(), self.u, self.v, c) else: x, y, u, v = delete_masked_points(self.x.ravel(), self.y.ravel(), self.u, self.v) magnitude = np.hypot(u, v) flags, barbs, halves, empty = self._find_tails(magnitude, self.rounding, **self.barb_increments) # Get the vertices for each of the barbs plot_barbs = self._make_barbs(u, v, flags, barbs, halves, empty, self._length, self._pivot, self.sizes, self.fill_empty, self.flip) self.set_verts(plot_barbs) # Set the color array if C is not None: self.set_array(c) # Update the offsets in case the masked data changed xy = np.hstack((x[:, np.newaxis], y[:, np.newaxis])) self._offsets = xy
Example #27
Source File: quiver.py From neural-network-animation with MIT License | 5 votes |
def _dots_per_unit(self, units): """ Return a scale factor for converting from units to pixels """ ax = self.ax if units in ('x', 'y', 'xy'): if units == 'x': dx0 = ax.viewLim.width dx1 = ax.bbox.width elif units == 'y': dx0 = ax.viewLim.height dx1 = ax.bbox.height else: # 'xy' is assumed dxx0 = ax.viewLim.width dxx1 = ax.bbox.width dyy0 = ax.viewLim.height dyy1 = ax.bbox.height dx1 = np.hypot(dxx1, dyy1) dx0 = np.hypot(dxx0, dyy0) dx = dx1 / dx0 else: if units == 'width': dx = ax.bbox.width elif units == 'height': dx = ax.bbox.height elif units == 'dots': dx = 1.0 elif units == 'inches': dx = ax.figure.dpi else: raise ValueError('unrecognized units') return dx
Example #28
Source File: test_delaunay.py From neural-network-animation with MIT License | 5 votes |
def cosine_peak(x, y): circle = np.hypot(80*x-40.0, 90*y-45.) f = np.exp(-0.04*circle) * np.cos(0.15*circle) return f
Example #29
Source File: testfuncs.py From neural-network-animation with MIT License | 5 votes |
def plot_cc(tri, edgecolor=None): import matplotlib as mpl from matplotlib import pylab as pl if edgecolor is None: edgecolor = (0, 0, 1, 0.2) dxy = (np.array([(tri.x[i], tri.y[i]) for i, j, k in tri.triangle_nodes]) - tri.circumcenters) r = np.hypot(dxy[:, 0], dxy[:, 1]) ax = pl.gca() for i in xrange(len(r)): p = mpl.patches.Circle(tri.circumcenters[i], r[i], resolution=100, edgecolor=edgecolor, facecolor=(1, 1, 1, 0), linewidth=0.2) ax.add_patch(p) pl.draw_if_interactive()
Example #30
Source File: surface_profiles.py From hcipy with MIT License | 5 votes |
def conical_surface_sag(radius_of_curvature, conic_constant=0): r'''Makes a Field generator for the surface sag of a conical surface. The surface profile is defined as: .. math:: z = \frac{cr^2}{1 + \sqrt{1-\left(1+k\right)c^2r^2}} with `z` the surface sag, `c` the curvature and `k` the conic constant. Parameters ---------- radius_of_curvature : scalar The radius of curvature of the surface. conic_constant : scalar The conic constant of the surface Returns ------- Field generator This function can be evaluated on a grid to get the sag profile. ''' def func(grid): x = grid.x y = grid.y r = np.hypot(x, y) curvature = 1 / radius_of_curvature alpha = (1 + conic_constant) * curvature**2 * r**2 sag = r**2 / (radius_of_curvature * (1 + np.sqrt(1 - alpha))) return Field(sag, grid) return func