Example #1
0
def test_circum_center_radius():
    '''
    circum_center_radius(): boundary, near lon=0, big triangle
    '''
    from numpy import pi
    from circumcircle import circum_center_radius
    from sphere import angle
    from convert_coord.cart_ll import latlon2xyz


    # boundary
    ll1, ll2, ll3 = (0,pi/3), (0,2/3*pi), (pi/6,pi/2)
    xyz1, xyz2, xyz3 = [latlon2xyz(*ll) for ll in [ll1,ll2,ll3]]
    center, radius = circum_center_radius(xyz1, xyz2, xyz3)
    equal(center, (0,1,0))


    # near lon=0
    ll1, ll2, ll3 = (pi/5, 2*pi-pi/6), (0,pi/7), (pi/7,pi/6)
    xyz1, xyz2, xyz3 = [latlon2xyz(*ll) for ll in [ll1,ll2,ll3]]
    center, radius = circum_center_radius(xyz1, xyz2, xyz3)

    d1 = angle(center, xyz1)
    d2 = angle(center, xyz2)
    d3 = angle(center, xyz3)
    aa_equal(d1, radius, 15)
    aa_equal(d2, radius, 15)
    aa_equal(d3, radius, 15)


    # big triangle
    ll1, ll2, ll3 = (pi/2,0), (0,0), (0,pi/2)
    xyz1, xyz2, xyz3 = [latlon2xyz(*ll) for ll in [ll1,ll2,ll3]]
    center, radius = circum_center_radius(xyz1, xyz2, xyz3)
    aa_equal(center, latlon2xyz(0.61547970867038737,pi/4), 15)
Example #2
0
def test_intersect_two_polygons():
    '''
    intersect_two_polygons(): inclusion, partial
    '''

    from sphere import intersect_two_polygons
    from math import pi
    from convert_coord.cart_ll import latlon2xyz


    # inclusion
    ll_poly1 = [(pi/2,0), (0,0), (0,pi/2)]
    ll_poly2 = [(pi/6,pi/6), (pi/6,pi/3), (pi/3,pi/3), (pi/3,pi/6)]
    xyz_poly1 = [latlon2xyz(*ll) for ll in ll_poly1]
    xyz_poly2 = [latlon2xyz(*ll) for ll in ll_poly2]
    ret = intersect_two_polygons(xyz_poly1, xyz_poly2)
    a_equal(ret, xyz_poly2)


    # partial
    ll_poly1 = [(pi/2,0), (0,0), (0,pi/2)]
    ll_poly2 = [(pi/2,0), (0,pi/3), (0,2*pi/3)]
    xyz_poly1 = [latlon2xyz(*ll) for ll in ll_poly1]
    xyz_poly2 = [latlon2xyz(*ll) for ll in ll_poly2]
    ret = intersect_two_polygons(xyz_poly1, xyz_poly2)

    ll_expect = [(pi/2,0), (0,pi/3), (0,pi/2)]
    xyz_expect = [latlon2xyz(*ll) for ll in ll_expect]
    a_equal(ret, xyz_expect)
Example #3
0
def test_intersect_two_greatcircles():
    '''
    intersect_two_greatcircles(): axis circles, oblique circles, identical
    '''

    from sphere import plane_origin, intersect_two_greatcircles
    from convert_coord.cart_ll import latlon2xyz


    #---------------------------------------
    # axis circles
    #---------------------------------------
    xyz1 = (1,0,0)
    xyz2 = (0,1,0)
    xyz3 = (0,0,1)

    # x axis
    plane1 = plane_origin(xyz1, xyz2)
    plane2 = plane_origin(xyz1, xyz3)
    ret = intersect_two_greatcircles(plane1, plane2)
    equal(ret, [(1,0,0), (-1,0,0)])

    # y axis
    plane1 = plane_origin(xyz1, xyz2)
    plane2 = plane_origin(xyz2, xyz3)
    ret = intersect_two_greatcircles(plane1, plane2)
    equal(ret, [(0,1,0), (0,-1,0)])

    # z axis
    plane1 = plane_origin(xyz1, xyz3)
    plane2 = plane_origin(xyz2, xyz3)
    ret = intersect_two_greatcircles(plane1, plane2)
    equal(ret, [(0,0,1), (0,0,-1)])


    #---------------------------------------
    # oblique circles
    #---------------------------------------
    xyz1 = (0, 0, 1)
    xyz2 = latlon2xyz(pi/4, pi/4)
    xyz3 = (1,0,0)

    plane1 = plane_origin(xyz1, xyz2)
    plane2 = plane_origin(xyz2, xyz3)

    ret = intersect_two_greatcircles(plane1, plane2)
    aa_equal(ret, [xyz2, latlon2xyz(-pi/4, 5*pi/4)], 15)


    #---------------------------------------
    # identical
    #---------------------------------------
    xyz1 = (0, 0, 1)
    xyz2 = latlon2xyz(pi/4, pi/4)
    plane = plane_origin(xyz1, xyz2)
    ret = intersect_two_greatcircles(plane, plane)
    equal(ret, [None, None])
Example #4
0
    def __init__(self, latlon1, latlon2):
        self.latlon1 = latlon1
        self.latlon2 = latlon2
        self.xyz1 = latlon2xyz(*latlon1)
        self.xyz2 = latlon2xyz(*latlon2)

        self.max_angle = angle(self.xyz1, self.xyz2)

        # pt3 which is perpendicular with pt1 on the great circle pt1_pt2
        self.xyz3 = self.get_xyz3()
        self.latlon3 = xyz2latlon(*self.xyz3)
Example #5
0
def test_pt_in_polygon():
    '''
    pt_in_polygon(): out, border, in
    '''

    from sphere import pt_in_polygon
    from convert_coord.cart_ll import latlon2xyz


    # out
    polygon = [latlon2xyz(*ll) for ll in [(pi/2,0), (0,0), (0,pi/4)]]
    point = latlon2xyz(pi/4,2*pi/6)
    ret = pt_in_polygon(polygon, point)
    equal(ret, 'out')


    polygon = [latlon2xyz(*ll) for ll in [(pi/2,0), (0,0), (0,pi/4)]]
    point = latlon2xyz(-pi/6,pi/4)
    ret = pt_in_polygon(polygon, point)
    equal(ret, 'out')


    # border
    polygon = [latlon2xyz(*ll) for ll in [(pi/2,0), (0,0), (0,pi/4)]]
    point = latlon2xyz(pi/4,pi/4)
    ret = pt_in_polygon(polygon, point)
    equal(ret, 'border')


    # in
    polygon = [latlon2xyz(*ll) for ll in [(pi/2,0), (0,0), (0,pi/4)]]
    point = latlon2xyz(pi/4,pi/6)
    ret = pt_in_polygon(polygon, point)
    equal(ret, 'in')
Example #6
0
    def get_voronoi(self, idx):
        nlat, nlon = self.nlat, self.nlon
        dlat, dlon = self.dlat, self.dlon
        padded_lats, padded_lons = self.padded_lats, self.padded_lons

        lj = idx//nlon
        li = idx%nlon

        lat = padded_lats[lj+1]
        lon = padded_lons[li]

        lat1, lat2 = lat-dlat/2, lat+dlat/2
        lon1 = lon - dlon/2 if li != 0 else 2*pi - dlon/2
        lon2 = lon + dlon/2

        if lj == 0:
            ll_vertices = [(-pi/2,0), (lat2,lon2), (lat2,lon1)]

        elif lj == nlat-1:
            ll_vertices = [(pi/2,0), (lat1,lon1), (lat1,lon2)]

        else:
            ll_vertices = [(lat1,lon1), (lat1,lon2), (lat2,lon2), (lat2,lon1)]

        return [latlon2xyz(*ll) for ll in ll_vertices]
Example #7
0
    def __init__(self, nlat, nlon, ll_type):
        '''
        Note: The latlon grid should not include the pole.
        Support ll_type: regular, gaussian, include_pole with shift_lon
        '''
        self.nlat = nlat
        self.nlon = nlon
        self.nsize = nlat*nlon

        ll_type, padded_lats, padded_lons = \
                make_padded_lats_lons(nlat, nlon, ll_type)

        latlons = np.zeros((self.nsize,2), 'f8')
        xyzs = np.zeros((self.nsize,3), 'f8')

        sli = slice(None,None) if ll_type=='include_pole' else slice(1,-1)
        seq = 0
        for lat in padded_lats[sli]:
            for lon in padded_lons[:-1]:
                latlons[seq,:] = (lat,lon)
                xyzs[seq,:] = latlon2xyz(lat,lon)
                seq += 1


        self.ll_type = ll_type
        self.grid_type = '%s latlon'%ll_type
        self.padded_lats = padded_lats
        self.padded_lons = padded_lons
        self.dlat = padded_lats[2] - padded_lats[1]
        self.dlon = padded_lons[2] - padded_lons[1]
        self.latlons = latlons
        self.xyzs = xyzs
Example #8
0
    def __init__(self, center_latlon, latlon, R=1):
        center_xyz = np.array( latlon2xyz(*center_latlon) )
        xyz = np.array( latlon2xyz(*latlon) )

        d = np.linalg.norm(center_xyz-xyz)
        pc = (R-0.5*d*d/R)*center_xyz       # plane_center_xyz 
        v1 = xyz - pc
        nv1 = v1/np.linalg.norm(v1)
        v2 = np.cross(pc, v1)
        nv2 = v2/np.linalg.norm(v2)


        self.r = np.linalg.norm(pc-xyz)
        self.pc = pc
        self.nv1 = nv1
        self.nv2 = nv2
Example #9
0
def test_sort_ccw_idxs():
    '''
    sort_ccw_idxs(): normal case, straight line, duplicated
    '''

    from sphere import sort_ccw_idxs
    from duplicate import remove_duplicates
    from convert_coord.cart_ll import latlon2xyz


    # normal
    lls = [(0.79,0.79), (0.78,0.77), (0.78,0.79), (0.79,0.77), (0.80,0.78)]
    xyzs = [latlon2xyz(*ll) for ll in lls]
    ret = sort_ccw_idxs(xyzs)
    a_equal(ret, [0,4,3,1,2])


    # straight line
    lls = [(0.79,0.79), (0.78,0.77), (0.78,0.79), \
           (0.79,0.77), (0.80,0.78), (0.78,0.78)]
    xyzs = [latlon2xyz(*ll) for ll in lls]
    ret = sort_ccw_idxs(xyzs)
    a_equal(ret, [0,4,3,1,5,2])


    #-----------------------------------------------------
    # duplicated
    #-----------------------------------------------------
    lls = [(-0.34784230590688509, 6.1959188445798699), 
           (-0.3478423059068852,  0.08726646259971646),
           (-0.52194946399942688, 0.08726646259971646),
           (-0.52194946399942688, 6.1959188445798699),
           (-0.52194946399942688, 6.1959188445798699)]
    xyzs = [latlon2xyz(*ll) for ll in lls]
    unique_xyzs = remove_duplicates(xyzs)
    ret = sort_ccw_idxs(unique_xyzs)
    a_equal(ret, [0,3,2,1])

    #-----------------------------------------------------
    lls = [(-1.3956102462281967, 0.43633231299858227),
           (-1.3956102462281967, 0.26179938779914985),
           (-1.5707963267948966, 0),
           (-1.5707963267948966, 0)]
    xyzs = [latlon2xyz(*ll) for ll in lls]
    unique_xyzs = remove_duplicates(xyzs)
    ret = sort_ccw_idxs(unique_xyzs)
    a_equal(ret, [0,1,2])
Example #10
0
def test_normal_vector():
    '''
    normal_vector(): yz plane circle, oblique circle
    '''

    from sphere import normal_vector
    from convert_coord.cart_ll import latlon2xyz


    #---------------------------------------
    # yz plane circle, +x direction
    #---------------------------------------
    vec1 = (0, 1, 0)
    vec2 = (0, 1/sqrt(2), 1/sqrt(2))
    nvec = normal_vector(vec1, vec2)
    equal(nvec, (sin(pi/4),0,0))

    unit_nvec = normal_vector(vec1, vec2, normalize=True)
    equal(unit_nvec, (1,0,0))


    #---------------------------------------
    # yz plane circle, -x direction
    #---------------------------------------
    vec1 = (0, -1, 0)
    vec2 = (0, 1/sqrt(2), 1/sqrt(2))
    nvec = normal_vector(vec1, vec2)
    equal(nvec, (-sin(pi/4),0,0))

    unit_nvec = normal_vector(vec1, vec2, normalize=True)
    equal(unit_nvec, (-1,0,0))


    #---------------------------------------
    # oblique circle
    #---------------------------------------
    vec1 = (0, 0, 1)
    vec2 = latlon2xyz(pi/4,pi/4)
    nvec = normal_vector(vec1, vec2)
    aa_equal(nvec, latlon2xyz(0,3*pi/4,R=sin(pi/4)), 15)

    unit_nvec = normal_vector(vec1, vec2, normalize=True)
    aa_equal(unit_nvec, (-1/sqrt(2),1/sqrt(2),0), 15)
Example #11
0
def test_area_polygon():
    '''
    area_polygon(): 1/8, 1/16, 1/24, 1/48
    '''

    from sphere import area_polygon
    from convert_coord.cart_ll import latlon2xyz
    from convert_coord.cs_ll import abp2latlon


    # 1/8 sphere area
    latlons = [(0,0), (0,pi/2), (pi/2,0)]
    xyzs = [latlon2xyz(*latlon) for latlon in latlons]
    ret = area_polygon(xyzs)
    aa_equal(ret, 4*pi/8, 15)


    # 1/16 sphere area
    latlons = [(0,0), (0,pi/4), (pi/2,0)]
    xyzs = [latlon2xyz(*latlon) for latlon in latlons]
    ret = area_polygon(xyzs)
    aa_equal(ret, 4*pi/16, 15)


    # 1/24 sphere area
    latlon1 = (0,0)
    latlon2 =  abp2latlon(-pi/4,0,1)
    latlon3 =  abp2latlon(-pi/4,-pi/4,1)
    latlon4 =  abp2latlon(0,-pi/4,1) 
    latlons = [latlon1, latlon2, latlon3, latlon4]
    xyzs = [latlon2xyz(*latlon) for latlon in latlons]
    ret = area_polygon(xyzs)
    aa_equal(ret, 4*pi/24, 15)


    # 1/48 sphere area
    latlons = [latlon1, latlon3, latlon4]
    xyzs = [latlon2xyz(*latlon) for latlon in latlons]
    ret = area_polygon(xyzs)
    aa_equal(ret, 4*pi/48, 15)
Example #12
0
    def __init__(self, ne, ngq, rotated=False, is_print=False):
        self.ne = ne
        self.ngq = ngq
        self.rotated = rotated
        self.is_print = is_print

        # EP(Entire Point), UP(Unique Point)
        ep_size = ngq*ngq*ne*ne*6
        up_size = 4*(ngq-1)*ne*((ngq-1)*ne + 1) + \
                   2*((ngq-1)*(ne-1) + (ngq-2))**2


        #-----------------------------------------------------
        # allocations
        #-----------------------------------------------------
        # Gauss-qudrature point index (panel,ei,ej,gi,gj)
        gq_indices = np.zeros((ep_size,5), 'i4')
        ij2seq_dict = dict()    # {(panel,ei,ej,gi,gj):seq,...}

        # sequential index
        mvps = np.ones((ep_size,4), 'i4')*(-1) # overlapped points (gid or -1)
        is_uvps = np.zeros(ep_size, 'i2')      # unique-point (True/False)
        uids = np.ones(ep_size, 'i4')*(-1)     # unique index (seq)
        gids = np.ones(up_size, 'i4')*(-1)     # global index
        nbrs = np.ones((up_size,8), 'i4')*(-1) # neighbors, anti-clockwise (gid)

        # coordinates
        alpha_betas = np.zeros((ep_size,2), 'f8')   # different at each panel
        latlons = np.zeros((up_size,2), 'f8')
        xyzs = np.zeros((up_size,3), 'f8')


        #-----------------------------------------------------
        # (gi, gj, ei, ej, panel)
        #-----------------------------------------------------
        seq = 0
        for panel in range(1,7):
            for ej in range(1,ne+1):
                for ei in range(1,ne+1):
                    for gj in range(1,ngq+1):
                        for gi in range(1,ngq+1):
                            ij = (panel,ei,ej,gi,gj)
                            gq_indices[seq,:] = ij
                            ij2seq_dict[ij] = seq       # start from 0
                            seq += 1

        
        #-----------------------------------------------------
        # mvps (overlapped index)
        if is_print: print("Generate mvps (multi-valued points)")
        #-----------------------------------------------------
        abcd2ij_dict = {'A':(1,1,1,1), 'B':(ne,1,ngq,1), \
                        'C':(ne,ne,ngq,ngq), 'D':(1,ne,1,ngq)}

        for seq in range(ep_size):
            panel, ei, ej, gi, gj = gq_indices[seq]

            mvps[seq,0] = seq       # self index, start from 0

            #-----------------------------------
            # At the panel corner (3 points)
            #-----------------------------------
            if (ei,ej,gi,gj) in abcd2ij_dict.values():
                if   (ei,ej,gi,gj) == abcd2ij_dict['A']: tag1 = "{}A".format(panel)
                elif (ei,ej,gi,gj) == abcd2ij_dict['B']: tag1 = "{}B".format(panel)
                elif (ei,ej,gi,gj) == abcd2ij_dict['C']: tag1 = "{}C".format(panel)
                elif (ei,ej,gi,gj) == abcd2ij_dict['D']: tag1 = "{}D".format(panel)

                tag2 = panel_corner_tags[tag1]
                tag3 = panel_corner_tags[tag2]

                for k, tag in enumerate([tag2,tag3]):
                    p, abcd = int(tag[0]), tag[1]
                    ij = tuple( [p] + list(abcd2ij_dict[abcd]) )
                    mvps[seq,k+1] = ij2seq_dict[ij]

                #print(seq, mvps[seq,:])


            #-----------------------------------
            # At the panel side
            #-----------------------------------
            elif (ei,gi) in [(1,1),(ne,ngq)] or \
                 (ej,gj) in [(1,1),(ne,ngq)]:

                if   (ei,gi) == (1,1):    tag1 = "{}W".format(panel)
                elif (ei,gi) == (ne,ngq): tag1 = "{}E".format(panel)
                elif (ej,gj) == (1,1):    tag1 = "{}S".format(panel)
                elif (ej,gj) == (ne,ngq): tag1 = "{}N".format(panel)

                tag2 = panel_side_tags[tag1]
                p1, ewsn1 = int(tag1[0]), tag1[1]
                p2, ewsn2 = int(tag2[0]), tag2[1]

                ij0 = (p1,ei,ej,gi,gj)
                ij_across = get_across_ij_panel_side( \
                        ne, ngq, tag1, tag2, ei, ej, gi, gj)

                #-------------------------------------
                # 4 points
                #-------------------------------------
                if (gi,gj) in [(1,1),(ngq,1),(ngq,ngq),(1,ngq)]:
                    fb_next, ij_next = get_next_ij_panel_side(ewsn1, ngq, *ij0)
                    ij_a_next = get_next_ij_panel_side(ewsn2, ngq, *ij_across)[-1]

                    if fb_next == 'forward':
                        ijs = [ij_next, ij_a_next, ij_across]
                    else:
                        ijs = [ij_across, ij_a_next, ij_next]

                    for k, ij in enumerate(ijs):
                        mvps[seq,k+1] = ij2seq_dict[ij]


                #-------------------------------------
                # 2 points
                #-------------------------------------
                else:
                    mvps[seq,1] = ij2seq_dict[ij_across]


                #print(seq, mvps[seq,:])


            #-----------------------------------
            # 4 points inside the panel
            #-----------------------------------
            # corner 
            elif (gi,gj) in [(1,1),(ngq,1),(ngq,ngq),(1,ngq)]:
                if (gi,gj) == (1,1):
                    ij1 = (panel,ei-1,ej  ,ngq,  1)
                    ij2 = (panel,ei-1,ej-1,ngq,ngq)
                    ij3 = (panel,ei  ,ej-1,  1,ngq)

                elif (gi,gj) == (ngq,1):
                    ij1 = (panel,ei  ,ej-1,ngq,ngq)
                    ij2 = (panel,ei+1,ej-1,  1,ngq)
                    ij3 = (panel,ei+1,ej  ,  1,  1)

                elif (gi,gj) == (ngq,ngq):
                    ij1 = (panel,ei+1,ej  ,  1,ngq)
                    ij2 = (panel,ei+1,ej+1,  1,  1)
                    ij3 = (panel,ei  ,ej+1,ngq,  1)

                elif (gi,gj) == (1,ngq):
                    ij1 = (panel,ei  ,ej+1,  1,  1)
                    ij2 = (panel,ei-1,ej+1,ngq,  1)
                    ij3 = (panel,ei-1,ej  ,ngq,ngq)

                #print("(panel,ei,ej,gi,gj) = {}".format((panel,ei,ej,gi,gj)))
                mvps[seq,1] = ij2seq_dict[ij1]
                mvps[seq,2] = ij2seq_dict[ij2]
                mvps[seq,3] = ij2seq_dict[ij3]


            #-----------------------------------
            # 2 points inside the panel
            #-----------------------------------
            #  side
            elif gi in (1,ngq) or gj in (1,ngq):
                if   gj == 1:   ij1 = (panel,ei,ej-1,gi,ngq)
                elif gj == ngq: ij1 = (panel,ei,ej+1,gi,  1)
                elif gi == 1:   ij1 = (panel,ei-1,ej,ngq,gj)
                elif gi == ngq: ij1 = (panel,ei+1,ej,  1,gj)

                mvps[seq,1] = ij2seq_dict[ij1]


        #-----------------------------------------------------
        # is_uvps (unique-point, True/False)
        # uids (unique index), ep_size
        # gids (global index), up_size
        if is_print: print("Generate is_uvps, uids and gids")
        #-----------------------------------------------------
        u_seq = 0

        for seq in range(ep_size):
            valid_mvp = [k for k in mvps[seq] if k != -1]

            #print(seq, valid_mvp)
            if min(valid_mvp) == seq:
                is_uvps[seq] = True
                gids[u_seq] = seq

                for k in valid_mvp:
                    uids[k] = u_seq

                u_seq += 1

        is_up_size = np.count_nonzero(is_uvps)
        assert up_size == is_up_size, "Error: up_size={}, np.count_nonzero(is_uvp)={}".format(up_size, is_up_size)
        assert up_size == u_seq, "Error: up_size={}, u_seq={}".foramt(up_size, u_seq)
        assert -1 not in uids, "Error: -1 in uids"
        assert -1 not in gids, "Error: -1 in gids"



        #-----------------------------------------------------
        # nbrs (neighbors)
        if is_print: print("Generate nbrs (neighbors, anti-clockwise)")
        #-----------------------------------------------------
        for u_seq in range(up_size):
            gid = gids[u_seq]
            panel, ei, ej, gi, gj = gq_indices[gid]
            valid_mvp = [k for k in mvps[gid] if k != -1]

            if (gi,gj) in [(1,1),(ngq,1),(ngq,ngq),(1,ngq)]:
                if len(valid_mvp) == 3:     # panel corner
                    ij0, ij1, ij2 = [gq_indices[m] for m in valid_mvp]
                    nbrs[u_seq,:3] = get_neighbors(ngq, ij2seq_dict, *ij0)
                    nbrs[u_seq,3:5] = get_neighbors(ngq, ij2seq_dict, *ij1)[1:]
                    nbrs[u_seq,5] = get_neighbors(ngq, ij2seq_dict, *ij2)[1]

                elif len(valid_mvp) == 4:   # corner
                    ij0, ij1, ij2, ij3 = [gq_indices[m] for m in valid_mvp]
                    nbrs[u_seq,:3] = get_neighbors(ngq, ij2seq_dict, *ij0)
                    nbrs[u_seq,3:5] = get_neighbors(ngq, ij2seq_dict, *ij1)[1:]
                    nbrs[u_seq,5:7] = get_neighbors(ngq, ij2seq_dict, *ij2)[1:]
                    nbrs[u_seq,7] = get_neighbors(ngq, ij2seq_dict, *ij3)[1]


            elif (gi in [1,ngq]) or (gj in [1,ngq]):
                ij0, ij1 = [gq_indices[m] for m in valid_mvp]
                nbrs[u_seq,:5] = get_neighbors(ngq, ij2seq_dict, *ij0)
                nbrs[u_seq,5:] = get_neighbors(ngq, ij2seq_dict, *ij1)[1:-1]


            else:
                ij0 = gq_indices[valid_mvp[0]]
                nbrs[u_seq,:] = get_neighbors(ngq, ij2seq_dict, *ij0)

            #print(u_seq, gid, nbrs[u_seq])



        #-----------------------------------------------------
        # coordinates  (alpha,beta), (lat,lon), (x,y,z)
        if is_print: print("Generate coordinates (alpha,beta), (lat,lon), (x,y,z)")
        #-----------------------------------------------------
        for seq in range(ep_size):
            panel, ei, ej, gi, gj = gq_indices[seq]
            alpha, beta = ij2ab(ne, ngq, panel, ei, ej, gi, gj)
            alpha_betas[seq,:] = (alpha, beta)


        for u_seq in range(up_size):
            seq = gids[u_seq]
            panel, ei, ej, gi, gj = gq_indices[seq]

            alpha, beta = alpha_betas[seq]

            if rotated:
                rlat, rlon = np.deg2rad(38), np.deg2rad(127)  #korea centered
            else:
                rlat, rlon = 0, 0
            lat, lon = abp2latlon(alpha, beta, panel, rlat, rlon)
            latlons[u_seq,:] = (lat,lon)

            x, y, z = latlon2xyz(lat, lon)
            xyzs[u_seq,:] = (x, y, z)


        #-----------------------------------------------------
        # global variables
        #-----------------------------------------------------
        self.ep_size = ep_size
        self.up_size = up_size
        self.ij2seq_dict = ij2seq_dict
        self.gq_indices = gq_indices
        self.mvps = mvps
        self.is_uvps = is_uvps
        self.uids = uids
        self.gids = gids
        self.nbrs = nbrs
        self.alpha_betas = alpha_betas
        self.latlons = latlons
        self.xyzs = xyzs
        self.rlat = rlat
        self.rlon = rlon
Example #13
0
def test_intersect_two_arcs():
    '''
    intersect_two_arcs(): interset, end point, None
    '''

    from sphere import intersect_two_arcs
    from convert_coord.cart_ll import latlon2xyz, xyz2latlon


    #---------------------------------------
    # intersect
    #---------------------------------------
    xyz1 = latlon2xyz(pi/2,0)
    xyz2 = latlon2xyz(0,pi/4)
    xyz3 = latlon2xyz(0,0)
    xyz4 = latlon2xyz(pi/4,pi/2)
    ret = intersect_two_arcs(xyz1, xyz2, xyz3, xyz4)
    aa_equal(ret, latlon2xyz(0.61547970867038715,pi/4), 15)


    xyz1 = latlon2xyz(pi/4,pi/2)
    xyz2 = latlon2xyz(pi/4,3*pi/2)
    xyz3 = latlon2xyz(pi/4,0)
    xyz4 = latlon2xyz(pi/4,pi)
    ret = intersect_two_arcs(xyz1, xyz2, xyz3, xyz4)
    aa_equal(ret, latlon2xyz(pi/2,0), 15)


    #---------------------------------------
    # end point
    #---------------------------------------
    xyz1 = latlon2xyz(pi/2,0)
    xyz2 = latlon2xyz(pi/4,3*pi/2)
    xyz3 = latlon2xyz(pi/4,0)
    xyz4 = latlon2xyz(pi/4,pi)
    ret = intersect_two_arcs(xyz1, xyz2, xyz3, xyz4)
    equal(ret, 'pt1')


    xyz1 = latlon2xyz(pi/4,pi/2)
    xyz2 = latlon2xyz(pi/2,0)
    xyz3 = latlon2xyz(pi/4,0)
    xyz4 = latlon2xyz(pi/4,pi)
    ret = intersect_two_arcs(xyz1, xyz2, xyz3, xyz4)
    equal(ret, 'pt2')


    xyz1 = latlon2xyz(pi/4,pi/2)
    xyz2 = latlon2xyz(pi/4,3*pi/2)
    xyz3 = latlon2xyz(pi/2,0)
    xyz4 = latlon2xyz(pi/4,pi)
    ret = intersect_two_arcs(xyz1, xyz2, xyz3, xyz4)
    equal(ret, 'pt3')


    xyz1 = latlon2xyz(pi/4,pi/2)
    xyz2 = latlon2xyz(pi/4,3*pi/2)
    xyz3 = latlon2xyz(pi/4,0)
    xyz4 = latlon2xyz(pi/2,0)
    ret = intersect_two_arcs(xyz1, xyz2, xyz3, xyz4)
    equal(ret, 'pt4')


    #---------------------------------------
    # not intersect
    #---------------------------------------
    xyz1 = latlon2xyz(2*pi/6,3*pi/2)
    xyz2 = latlon2xyz(pi/4,3*pi/2)
    xyz3 = latlon2xyz(pi/4,0)
    xyz4 = latlon2xyz(pi/4,pi)
    ret = intersect_two_arcs(xyz1, xyz2, xyz3, xyz4)
    equal(ret, None)
Example #14
0
def test_angle():
    '''
    angle(): yz plane circle, oblique circle
    '''

    from sphere import angle
    from convert_coord.cart_ll import latlon2xyz


    ret = angle(latlon2xyz(pi/4,0), latlon2xyz(0,0))
    equal(ret, pi/4)

    ret = angle(latlon2xyz(pi/2,0), latlon2xyz(0,0))
    equal(ret, pi/2)

    ret = angle(latlon2xyz(0,0), latlon2xyz(0,0))
    equal(ret, 0)

    ret = angle(latlon2xyz(pi/4,0), latlon2xyz(-pi/4,0))
    aa_equal(ret, pi/2, 15)

    ret = angle(latlon2xyz(pi/2,0), latlon2xyz(-pi/4,0))
    aa_equal(ret, 3*pi/4, 15)

    ret = angle(latlon2xyz(pi/2,0), latlon2xyz(-pi/2,0))
    aa_equal(ret, pi, 15)
Example #15
0
def test_arc12_pt3():
    '''
    arc12_pt3(): between, out, pt1, pt2
    '''

    from sphere import arc12_pt3
    from convert_coord.cart_ll import latlon2xyz


    #---------------------------------------
    # oblique circle
    #---------------------------------------
    vec1 = (0, 0, 1)
    vec2 = latlon2xyz(pi/4, pi/4)


    # between
    vec3 = latlon2xyz(2*pi/6, pi/4)
    ret = arc12_pt3(vec1, vec2, vec3)
    equal(ret, 'between')


    # out
    vec3 = latlon2xyz(-pi/16, pi/4)
    ret = arc12_pt3(vec1, vec2, vec3)
    equal(ret, 'out')

    vec3 = latlon2xyz(-pi/2, pi/4)
    ret = arc12_pt3(vec1, vec2, vec3)
    equal(ret, 'out')

    vec3 = latlon2xyz(2*pi/6, 5*pi/4)
    ret = arc12_pt3(vec1, vec2, vec3)
    equal(ret, 'out')

    vec3 = latlon2xyz(-pi/4, 5*pi/4)
    ret = arc12_pt3(vec1, vec2, vec3)
    equal(ret, 'out')


    # pt1, pt2
    vec3 = (0,0,1)
    ret = arc12_pt3(vec1, vec2, vec3)
    equal(ret, 'pt1')

    vec3 = latlon2xyz(pi/4, pi/4)
    ret = arc12_pt3(vec1, vec2, vec3)
    equal(ret, 'pt2')


    #---------------------------------------
    # x=0 line
    #---------------------------------------
    xyz1 = latlon2xyz(pi/2-0.5,pi/2)
    xyz2 = latlon2xyz(pi/2-0.2,pi/2)
    xyz3 = latlon2xyz(pi/2-0.1,pi/2)

    ret = arc12_pt3(xyz1, xyz2, xyz3)
    equal(ret, 'out')


    #---------------------------------------
    # left, not straight (??)
    # straight
    #---------------------------------------
    latlons = [(-0.006213200654473781,  4.1626565784079901), 
               (-0.0061246818142171597, 4.1626102660064754),
               (-0.0061246818142039828, 4.1626102660064754)]
    xyz1, xyz2, xyz3 = [latlon2xyz(*latlon) for latlon in latlons]
    ret = arc12_pt3(xyz1, xyz2, xyz3)
    equal(ret, 'out')
    ret = arc12_pt3(xyz2, xyz3, xyz1)
    equal(ret, 'out')
    ret = arc12_pt3(xyz3, xyz1, xyz2)
    equal(ret, 'between')