Exemple #1
0
def latlong2osgbgrid_cupy(lat, long, input_degrees=True):
    '''
    Converts latitude and longitude (ellipsoidal) coordinates into northing and easting (grid) coordinates, using a Transverse Mercator projection.
    
    Inputs:
    lat: latitude coordinate (north)
    long: longitude coordinate (east)
    input_degrees: if True (default), interprets the coordinates as degrees; otherwise, interprets coordinates as radians
    
    Output:
    (northing, easting)
    '''

    if input_degrees:
        lat = lat * cp.pi / 180
        long = long * cp.pi / 180

    a = 6377563.396
    b = 6356256.909
    e2 = (a**2 - b**2) / a**2

    N0 = -100000  # northing of true origin
    E0 = 400000  # easting of true origin
    F0 = .9996012717  # scale factor on central meridian
    phi0 = 49 * cp.pi / 180  # latitude of true origin
    lambda0 = -2 * cp.pi / 180  # longitude of true origin and central meridian

    sinlat = cp.sin(lat)
    coslat = cp.cos(lat)
    tanlat = cp.tan(lat)

    latdiff = lat - phi0
    longdiff = long - lambda0

    n = (a - b) / (a + b)
    nu = a * F0 * (1 - e2 * sinlat**2)**-.5
    rho = a * F0 * (1 - e2) * (1 - e2 * sinlat**2)**-1.5
    eta2 = nu / rho - 1
    M = b * F0 * (
        (1 + n + 5 / 4 * (n**2 + n**3)) * latdiff -
        (3 *
         (n + n**2) + 21 / 8 * n**3) * cp.sin(latdiff) * cp.cos(lat + phi0) +
        15 / 8 * (n**2 + n**3) * cp.sin(2 * (latdiff)) * cp.cos(2 *
                                                                (lat + phi0)) -
        35 / 24 * n**3 * cp.sin(3 * (latdiff)) * cp.cos(3 * (lat + phi0)))
    I = M + N0
    II = nu / 2 * sinlat * coslat
    III = nu / 24 * sinlat * coslat**3 * (5 - tanlat**2 + 9 * eta2)
    IIIA = nu / 720 * sinlat * coslat**5 * (61 - 58 * tanlat**2 + tanlat**4)
    IV = nu * coslat
    V = nu / 6 * coslat**3 * (nu / rho - cp.tan(lat)**2)
    VI = nu / 120 * coslat**5 * (5 - 18 * tanlat**2 + tanlat**4 + 14 * eta2 -
                                 58 * tanlat**2 * eta2)

    northing = I + II * longdiff**2 + III * longdiff**4 + IIIA * longdiff**6
    easting = E0 + IV * longdiff + V * longdiff**3 + VI * longdiff**5

    return (northing, easting)
def get_phase(num_of_vort, pos, x_pts, y_pts, grid_x, grid_y, grid_len_x,
              grid_len_y, component):
    """ Gets phase distribution of N dipoles."""

    # Phase initialisation
    theta_tot = cp.empty((x_pts, y_pts))

    # Scale pts:
    x_tilde = 2 * cp.pi * ((grid_x - grid_x.min()) / grid_len_x)
    y_tilde = 2 * cp.pi * ((grid_y - grid_y.min()) / grid_len_y)

    if component == '2':
        switch = True
    else:
        switch = False

    for i in range(num_of_vort // 2):
        theta_k = cp.zeros((x_pts, y_pts))

        if i % 24 == 0 and i > 0:
            switch ^= True

        if switch:
            x_p, y_p = next(pos)
            x_m, y_m = next(pos)

        else:
            x_m, y_m = next(pos)
            x_p, y_p = next(pos)

        # Scaling vortex positions:
        x_m_tilde = 2 * cp.pi * ((x_m - grid_x.min()) / grid_len_x)
        y_m_tilde = 2 * cp.pi * ((y_m - grid_y.min()) / grid_len_y)
        x_p_tilde = 2 * cp.pi * ((x_p - grid_x.min()) / grid_len_x)
        y_p_tilde = 2 * cp.pi * ((y_p - grid_y.min()) / grid_len_y)

        # Aux variables
        Y_minus = y_tilde - y_m_tilde
        X_minus = x_tilde - x_m_tilde
        Y_plus = y_tilde - y_p_tilde
        X_plus = x_tilde - x_p_tilde

        heav_xp = cp.asarray(np.heaviside(cp.asnumpy(X_plus), 1.))
        heav_xm = cp.asarray(np.heaviside(cp.asnumpy(X_minus), 1.))

        for nn in cp.arange(-5, 6):
            theta_k += cp.arctan(cp.tanh((Y_minus + 2 * cp.pi * nn) / 2) * cp.tan((X_minus - cp.pi) / 2)) \
                                - cp.arctan(cp.tanh((Y_plus + 2 * cp.pi * nn) / 2) * cp.tan((X_plus - cp.pi) / 2)) \
                                + cp.pi * (heav_xp - heav_xm)

        theta_k -= y_tilde * (x_p_tilde - x_m_tilde) / (2 * cp.pi)
        theta_tot += theta_k

    return theta_tot
Exemple #3
0
def get_phase(num_of_vort, pos, grid_x, grid_y):
    """
    num_of_vort: number of vortices to imprint
    pos: iterable of positions to imprint the vortices
    grid_x: X-meshgrid
    grid_y: Y-meshgrid
    """

    # Constructing necessary grid parameters:
    x_pts, y_pts = len(grid_x[:, 0]), len(grid_y[0, :])
    dx, dy = grid_x[0, 1] - grid_x[0, 0], grid_y[1, 0] - grid_y[0, 0]
    grid_len_x, grid_len_y = x_pts * dx, y_pts * dy

    # Phase initialisation
    theta_tot = cp.empty((x_pts, y_pts))

    # Scale pts:
    x_tilde = 2 * cp.pi * ((grid_x - grid_x.min()) / grid_len_x)
    y_tilde = 2 * cp.pi * ((grid_y - grid_y.min()) / grid_len_y)

    for _ in range(num_of_vort // 2):
        theta_k = cp.zeros((x_pts, y_pts))

        x_m, y_m = next(pos)
        x_p, y_p = next(pos)

        # Scaling vortex positions:
        x_m_tilde = 2 * cp.pi * ((x_m - grid_x.min()) / grid_len_x)
        y_m_tilde = 2 * cp.pi * ((y_m - grid_y.min()) / grid_len_y)
        x_p_tilde = 2 * cp.pi * ((x_p - grid_x.min()) / grid_len_x)
        y_p_tilde = 2 * cp.pi * ((y_p - grid_y.min()) / grid_len_y)

        # Aux variables
        Y_minus = y_tilde - y_m_tilde
        X_minus = x_tilde - x_m_tilde
        Y_plus = y_tilde - y_p_tilde
        X_plus = x_tilde - x_p_tilde

        heav_xp = cp.asarray(np.heaviside(cp.asnumpy(X_plus), 1.))
        heav_xm = cp.asarray(np.heaviside(cp.asnumpy(X_minus), 1.))

        for nn in cp.arange(-5, 6):
            theta_k += cp.arctan(cp.tanh((Y_minus + 2 * cp.pi * nn) / 2) * cp.tan((X_minus - cp.pi) / 2)) \
                                - cp.arctan(cp.tanh((Y_plus + 2 * cp.pi * nn) / 2) * cp.tan((X_plus - cp.pi) / 2)) \
                                + cp.pi * (heav_xp - heav_xm)

        theta_k -= y_tilde * (x_p_tilde - x_m_tilde) / (2 * cp.pi)
        theta_tot += theta_k

    return theta_tot
Exemple #4
0
def jackson(
    num_moments,
    precision=32,
):
    """
    This function generates the Jackson kernel for a given  number of
    Chebyscev moments

    Parameters
    ----------
        num_moments: (uint)
            number of Chebyshev moments
    Return
    ------
        jackson_kernel: cupy array(shape=(num_moments,), dtype=tf_float)

    Note
    ----
        See .. _The Kernel Polynomial Method:
        https://arxiv.org/pdf/cond-mat/0504627.pdf for more details
    """
    cp_float = cp.float64
    if precision == 32:
        cp_float = cp.float32

    kernel_moments = cp.arange(num_moments, dtype=cp_float)
    norm = cp.pi / (num_moments + 1)
    phase_vec = norm * kernel_moments
    kernel = (num_moments - kernel_moments + 1) * cp.cos(phase_vec)
    kernel = kernel + cp.sin(phase_vec) / cp.tan(norm)
    kernel = kernel / (num_moments + 1)

    return kernel
Exemple #5
0
    def standard_cauchy(self, size=None, dtype=float):
        """Returns an array of samples drawn from the standard cauchy distribution.

        .. seealso::
            :func:`cupy.random.standard_cauchy` for full documentation,
            :meth:`numpy.random.RandomState.standard_cauchy`
        """
        x = self.uniform(size=size, dtype=dtype)
        return cupy.tan(cupy.pi * (x - 0.5))
def tan(x: Array, /) -> Array:
    """
    Array API compatible wrapper for :py:func:`np.tan <numpy.tan>`.

    See its docstring for more information.
    """
    if x.dtype not in _floating_dtypes:
        raise TypeError("Only floating-point dtypes are allowed in tan")
    return Array._new(np.tan(x._array))
Exemple #7
0
def get_phase(num_of_vort, pos, x_pts, y_pts, grid_x, grid_y, grid_len_x,
              grid_len_y):
    # Phase initialisation
    theta_tot = cp.empty((x_pts, y_pts))

    # Scale pts:
    x_tilde = 2 * cp.pi * ((grid_x - grid_x.min()) / grid_len_x)
    y_tilde = 2 * cp.pi * ((grid_y - grid_y.min()) / grid_len_y)

    for _ in range(num_of_vort // 2):
        theta_k = cp.zeros((x_pts, y_pts))

        x_m, y_m = next(pos)
        x_p, y_p = next(pos)

        # Scaling vortex positions:
        x_m_tilde = 2 * cp.pi * ((x_m - grid_x.min()) / grid_len_x)
        y_m_tilde = 2 * cp.pi * ((y_m - grid_y.min()) / grid_len_y)
        x_p_tilde = 2 * cp.pi * ((x_p - grid_x.min()) / grid_len_x)
        y_p_tilde = 2 * cp.pi * ((y_p - grid_y.min()) / grid_len_y)

        # Aux variables
        Y_minus = y_tilde - y_m_tilde
        X_minus = x_tilde - x_m_tilde
        Y_plus = y_tilde - y_p_tilde
        X_plus = x_tilde - x_p_tilde

        heav_xp = cp.asarray(np.heaviside(cp.asnumpy(X_plus), 1.))
        heav_xm = cp.asarray(np.heaviside(cp.asnumpy(X_minus), 1.))

        for nn in cp.arange(-5, 6):
            theta_k += cp.arctan(cp.tanh((Y_minus + 2 * cp.pi * nn) / 2) * cp.tan((X_minus - cp.pi) / 2)) \
                                - cp.arctan(cp.tanh((Y_plus + 2 * cp.pi * nn) / 2) * cp.tan((X_plus - cp.pi) / 2)) \
                                + cp.pi * (heav_xp - heav_xm)

        theta_k -= y_tilde * (x_p_tilde - x_m_tilde) / (2 * cp.pi)
        theta_tot += theta_k

    return theta_tot
    def __init__(self, lookfrom, lookat, vup, vfov, aspect_ratio, aperture, focus_dist):
        theta = degrees_to_radians(vfov)
        h = cp.tan(theta / 2)
        viewport_height = 2 * h
        viewport_width = aspect_ratio * viewport_height

        self.w = (lookfrom - lookat).unit_vector()
        self.u = vup.cross(self.w).unit_vector()
        self.v = self.w.cross(self.u)

        self.origin = lookfrom
        self.horizontal = self.u * viewport_width * focus_dist
        self.vertical = self.v * viewport_height * focus_dist
        self.top_left_corner = self.origin - self.horizontal / 2 + self.vertical / 2 - self.w * focus_dist
        self.lens_radius = aperture / 2
Exemple #9
0
    def __init__(self, lookfrom: Point3, lookat: Point3, vup: Vec3,
                 vfov: float, aspect_ratio: float, aperture: float,
                 focus_dist: float) -> None:
        """
        vfov: vertical field-of-view in degress
        """
        theta: float = degrees_to_radians(vfov)
        h: float = cp.tan(theta / 2)
        viewport_height: float = 2 * h
        viewport_width: float = aspect_ratio * viewport_height

        self.w: Vec3 = (lookfrom - lookat).unit_vector()
        self.u: Vec3 = vup.cross(self.w).unit_vector()
        self.v: Vec3 = self.w.cross(self.u)

        self.origin: Point3 = lookfrom
        self.horizontal: Vec3 = self.u * viewport_width * focus_dist
        self.vertical: Vec3 = self.v * viewport_height * focus_dist
        self.lower_left_corner: Point3 = (self.origin - self.horizontal / 2 -
                                          self.vertical / 2 -
                                          self.w * focus_dist)
        self.lens_radius: float = aperture / 2
Exemple #10
0
def _hs(k, cs, rho, omega):
    c0 = (cs * cs * (1 + rho * rho) / (1 - rho * rho) /
          (1 - 2 * rho * rho * cos(2 * omega) + rho**4))
    gamma = (1 - rho * rho) / (1 + rho * rho) / tan(omega)
    ak = abs(k)
    return c0 * rho**ak * (cos(omega * ak) + gamma * sin(omega * ak))
Exemple #11
0
def cot__(z):
    return 1.0/cp.tan(z)
Exemple #12
0
def RenderingUserViewLF_AllinOne5K(LF=None,
                                   LFDisparity=None,
                                   FB=None,
                                   viewpoint=None,
                                   DIR=None):

    sphereW = Params.WIDTH
    sphereH = Params.HEIGHT

    CENTERx = viewpoint.lon
    CENTERy = viewpoint.lat

    # output view is 3:4 ratio
    new_imgW = cp.floor(viewpoint.diag * 4 / 5 + 0.5)
    new_imgH = cp.floor(viewpoint.diag * 3 / 5 + 0.5)

    new_imgW = int(new_imgW)
    new_imgH = int(new_imgH)

    OutView = cp.zeros((new_imgH, new_imgW, 3))
    TYwarp, TXwarp = cp.mgrid[0:new_imgH, 0:new_imgW]

    TX = TXwarp
    TY = TYwarp
    TX = (TX - 0.5 - new_imgW / 2)
    TY = (TY - 0.5 - new_imgH / 2)

    #의심

    TX = TX + 1
    TY = TY + 1

    r = (viewpoint.diag / 2) / cp.tan(viewpoint.fov / 2)
    R = cp.sqrt(TY**2 + r**2)
    # Calculate LF_n
    ANGy = cp.arctan(-TY / r)
    ANGy = ANGy + CENTERy

    if (FB == 1):
        ANGn = cp.cos(ANGy) * cp.arctan(TX / r)
        ANGn = ANGn + CENTERx
        Pn = (Params.LFU_W / 2 - viewpoint.pos_y
              ) * cp.tan(ANGn) + viewpoint.pos_x + (3 * Params.LFU_W / 2)
    elif (FB == 2):
        ANGn = cp.cos(ANGy) * cp.arctan(-TX / r)
        ANGn = ANGn - CENTERx
        Pn = (Params.LFU_W / 2 + viewpoint.pos_y
              ) * cp.tan(ANGn) + viewpoint.pos_x + (3 * Params.LFU_W / 2)

    X = cp.sin(ANGy) * R
    Y = -cp.cos(ANGy) * R
    Z = TX

    ANGx = cp.arctan2(Z, -Y)
    RZY = cp.sqrt(Z**2 + Y**2)
    ANGy = cp.arctan(X / RZY)  #or ANGy = atan2(X, RZY);

    RATIO = 1
    ANGy = ANGy * RATIO

    ANGx = ANGx + CENTERx

    ANGx[abs(ANGy) > pi / 2] = ANGx[abs(ANGy) > pi / 2] + pi
    ANGx[ANGx > pi] = ANGx[ANGx > pi] - 2 * pi

    ANGy[ANGy > pi / 2] = pi / 2 - (ANGy[ANGy > pi / 2] - pi / 2)
    ANGy[ANGy < -pi / 2] = -pi / 2 + (ANGy[ANGy < -pi / 2] + pi / 2)

    Px = (ANGx + pi) / (2 * pi) * sphereW + 0.5
    Py = ((-ANGy) + pi / 2) / pi * sphereH + 0.5

    if (DIR == 2):
        Px = Px + Params.WIDTH / 4
    elif (DIR == 3):
        Px = Px + Params.WIDTH / 2
    elif (DIR == 4):
        Px = Px - Params.WIDTH / 4

    Px[Px < 1] = Px[Px < 1] + Params.WIDTH
    Px[Px > Params.WIDTH] = Px[Px > Params.WIDTH] - Params.WIDTH

    INDxx = cp.argwhere(Px < 1)
    Px[INDxx] = Px[INDxx] + sphereW

    Pn0 = cp.floor(Pn)
    Pn1 = cp.ceil(Pn)
    Pnr = Pn - Pn0

    Px0 = cp.floor(Px)
    Px1 = cp.ceil(Px)
    Pxr = Px - Px0

    Py0 = cp.floor(Py)
    Py1 = cp.ceil(Py)
    Pyr = Py - Py0

    Pnr = cp.rint((Pnr * 10000))
    Pnr = Pnr / 10000

    Pxr = cp.rint((Pxr * 10000))
    Pxr = Pxr / 10000

    Pyr = cp.rint((Pyr * 10000))
    Pyr = Pyr / 10000

    #210->012 rgb
    #cv2 사용 안하면 그대로
    OutView[:, :, 2] = inter8_mat5K(LF, Pnr, Pn0, Pn1, Pxr, Px0, Px1, Pyr, Py0,
                                    Py1, 1)
    OutView[:, :, 1] = inter8_mat5K(LF, Pnr, Pn0, Pn1, Pxr, Px0, Px1, Pyr, Py0,
                                    Py1, 2)
    OutView[:, :, 0] = inter8_mat5K(LF, Pnr, Pn0, Pn1, Pxr, Px0, Px1, Pyr, Py0,
                                    Py1, 3)
    OutFlow = inter8_mat_flow5K(LFDisparity, Pnr, Pn0, Pn1, Pxr, Px0, Px1, Pyr,
                                Py0, Py1)

    Py = cp.pad(Py, [(1, 1), (0, 0)], mode='edge')
    Py = cp.ceil((Py * 10000))
    Py = Py / 10000

    My = 2 / (Py[2:cp.size(Py, 0), :] - Py[0:(cp.size(Py, 0) - 2), :])

    My[0, :] = My[0, :] / 2

    My[cp.size(My, 0) - 1, :] = My[cp.size(My, 0) - 1, :] / 2

    OutFlow = My * OutFlow

    return OutView, OutFlow