

def _find_nearby_station(self, station):
    if (self.stations is None):
        self.stations = self._load_stations()
    if (self.station_to_lat_lng is None):
        self.station_to_lat_lng = self._load_station_locations()
    try:
        (lat, lng) = self.station_to_lat_lng[station]
    except KeyError:
        warnings.warn('Could not locate station {}; nearby station look-up failed'.format(station))
        return None
    else:
        index_list = list(self.station_to_lat_lng.items())
        dists = [haversine(lat, lng, stat_lat, stat_lng) for (_, (stat_lat, stat_lng)) in index_list]
    for (dist, (nearby_station, _)) in zip(dists, index_list):
        if (nearby_station in self.stations):
            warnings.warn('Using station {} instead'.format(nearby_station))
            return nearby_station
    return None

dataset/ETHPy150Open impactlab/eemeter/eemeter/weather.py TMY3Client._find_nearby_station/original