コード例 #1
0
def assessBuddyDistance(p, buddy):
    """
    given a profile <p> and a possible buddy profile <buddy>,
    return None if <buddy> is not a valid buddy, or the distance
    to <p> if it is.
    """

    # Check that it is not the same profile and that they
    # are near in time. The time criteria matches the EN
    # processing but would probably be better if it checked
    # that the profiles were within a time threshold. The
    # cruise is compared as two profiles from the same instrument
    # should not be compared.
    if (buddy[0] == p.uid() or buddy[1] != p.year() or buddy[2] != p.month()
            or buddy[3] == p.cruise()):
        return None
    lat = p.latitude()
    lon = p.longitude()
    latComp = buddy[4]
    lonComp = buddy[5]
    # Do a rough check of distance.
    latDiff = np.abs(latComp - lat)
    if latDiff > 5: return None
    # Do a more detailed check of distance.
    # Check in case they are either side of the edge of the map.
    if np.abs(lonComp - lon) > 180:
        if lonComp < lon:
            lonComp += 360.0
        else:
            lonComp -= 360.0
    # Calculate distance and return.
    return haversine(lat, lon, latComp, lonComp)
コード例 #2
0
def assessBuddyDistance(p, buddy):
    """
    given a profile <p> and a possible buddy profile <buddy>,
    return None if <buddy> is not a valid buddy, or the distance
    to <p> if it is.
    """

    # Check that it is not the same profile and that they
    # are near in time. The time criteria matches the EN 
    # processing but would probably be better if it checked
    # that the profiles were within a time threshold. The
    # cruise is compared as two profiles from the same instrument
    # should not be compared.
    if (buddy[0] == p.uid() or
        buddy[1] != p.year() or
        buddy[2] != p.month() or
        buddy[3] == p.cruise()): return None
    lat = p.latitude()
    lon = p.longitude()
    latComp = buddy[4]
    lonComp = buddy[5]
    # Do a rough check of distance.
    latDiff = np.abs(latComp - lat)
    if latDiff > 5: return None
    # Do a more detailed check of distance.
    # Check in case they are either side of the edge of the map.
    if np.abs(lonComp - lon) > 180:
        if lonComp < lon:
            lonComp += 360.0
        else:
            lonComp -= 360.0
    # Calculate distance and return.
    return haversine(lat, lon, latComp, lonComp)
コード例 #3
0
def test_assessBuddyDistance_haversine():
    '''
    make sure haversine calculation is consistent with rest of package
    '''

    p1 = util.testingProfile.fakeProfile([0,0,0],[0,0,0], 0, 0, date=[1900, 1, 1, 12], uid=0, cruise=1)
    p2 = util.testingProfile.fakeProfile([0,0,0],[0,0,0], 1, 1, date=[1900, 1, 1, 13], uid=1, cruise=2)
    assert qctests.EN_std_lev_bkg_and_buddy_check.assessBuddyDistance(p1, p2) == haversine(0,0,1,1), 'haversine calculation inconsistent with cotede.qctests.possible_speed.haversine'
コード例 #4
0
    def test_assessBuddyDistance_haversine(self):
        '''
        make sure haversine calculation is consistent with rest of package
        '''

        p1 = util.testingProfile.fakeProfile([0, 0, 0], [0, 0, 0],
                                             0,
                                             0,
                                             date=[1900, 1, 1, 12],
                                             uid=0,
                                             cruise=1)
        p2 = util.testingProfile.fakeProfile([0, 0, 0], [0, 0, 0],
                                             1,
                                             1,
                                             date=[1900, 1, 1, 13],
                                             uid=1,
                                             cruise=2)
        assert qctests.EN_std_lev_bkg_and_buddy_check.assessBuddyDistance(
            p1, profile_to_info_list(p2)
        ) == haversine(
            0, 0, 1, 1
        ), 'haversine calculation inconsistent with cotede.qctests.possible_speed.haversine'