Esempio n. 1
0
 def testTwoStations(self):
     """According to jan.ucc.nau.edu/~cvm/latlongdist, the distance
     between Ithaca and Brewton is 1576.7066 km
     """
     dist1 = compute_arc_dist(self.STATION_A, self.STATION_B)
     dist2 = compute_arc_dist(self.STATION_B, self.STATION_A)
     self.assertAlmostEquals(dist1, 1576.7066, delta=self.DELTA)
     self.assertAlmostEquals(dist2, 1576.7066, delta=self.DELTA)
Esempio n. 2
0
def find_neighborhood(station, stations_list, numsrt=40, mindist=200.0, **kwargs):
    """
    Determines the neighborhood comprised of the closes numsrt neighbors located
    around a given station. 
    
    :Param stations:
        The candidate *Station* object.
    :Param stations_list:
        A list of *Station* objects to use to determine the neighborhood.
    :Param numsrt:
        The number of *Station* objects which should comprise the resulting 
        neighberhood.
    :Param mindist: 
        The minimum distance to use while searching through the *Station* objects
        iteratively. Most likely will not be used.
    
    :Return:
        The neighborhood as a list of two-element tuples. The tuples will each
        be of the form (Station.coop_id, computed distance from candidate), and
        the list will be sorted in descending order based on the computed
        distance.
    """

    neighbors = dict()
    for other in stations_list:

        if not station.coop_id == other.coop_id:
            dist = compute_arc_dist(station, other)
            neighbors[other.coop_id] = dist

    # Sort the dictionary of neighbors into a list, sorting from least
    # distance to greatest distances. Only take numsrt neighbors maximum.
    sorted_neighbors = sorted(neighbors.iteritems(), key=itemgetter(1))[: numsrt - 1]
    """
    # This code is actually superfluous, but it loops through the list of
    # sorted neighbors, and finds only the neighbors which are within a maximum
    # distance from the candidate station. When its done, it sees if there are
    # enough neighbors, and if not, ups the threshold for distance and tries 
    # again.
    close_neighbors = []
    iter = 1
    hidist = mindist
    print "...searching for neighbors within %4.1fkm" % mindist
    while (len(close_neighbors) < numsrt-1):
        print "......iteration %d, %d neighbors found" % (iter, 
                                                          len(close_neighbors))
        for (coop_id, dist) in sorted_neighbors:
            if dist < hidist:
                sorted_neighbors.remove((coop_id, dist))
                close_neighbors.append((coop_id, dist))
        hidist = hidist+distinc
        print ".........distance now %4.1fkm" % mindist    
        iter = iter+1
    print "......ultimately found %d neighbors" % len(close_neighbors)
    all_neighbors[coop_id1] = close_neighbors
    """

    return sorted_neighbors
Esempio n. 3
0
 def testQuarterArc(self):
     dist1 = compute_arc_dist(self.STATION_C, self.STATION_D)
     dist2 = compute_arc_dist(self.STATION_D, self.STATION_C)
     quarter_arc = (2.*pi*RADIUS_EARTH)/4.0
     self.assertAlmostEquals(dist1, quarter_arc, delta=self.DELTA)
     self.assertAlmostEquals(dist2, quarter_arc, delta=self.DELTA)
Esempio n. 4
0
 def testSameStation(self):
     """Distance between the same station should round off to 0."""
     dist = compute_arc_dist(self.STATION_A, self.STATION_A)
     self.assertAlmostEquals(dist, 0., delta=self.DELTA)