예제 #1
0
def test_rank_stations_is_cz2010(lat_long_fresno, snapshot):
    lat, lng = lat_long_fresno
    df = rank_stations(lat, lng, is_cz2010=True)
    snapshot.assert_match(df.shape, "is_cz2010=True")

    df = rank_stations(lat, lng, is_cz2010=False)
    snapshot.assert_match(df.shape, "is_cz2010=False")
예제 #2
0
def lat_lng_to_station_using_eeweather(lat, lng, is_cz2010=False):

    ranked_stations = eeweather.rank_stations(lat,
                                              lng,
                                              match_iecc_climate_zone=True,
                                              match_iecc_moisture_regime=True,
                                              match_ba_climate_zone=True,
                                              match_ca_climate_zone=True,
                                              minimum_quality='high',
                                              is_tmy3=True,
                                              is_cz2010=is_cz2010)

    naive_ranked_stations = eeweather.rank_stations(
        lat,
        lng,
        minimum_quality='high',
        is_tmy3=True,
        is_cz2010=is_cz2010,
    )

    ranked_stations = eeweather.combine_ranked_stations(
        [ranked_stations, naive_ranked_stations])

    curr = datetime.now()
    curr = datetime(curr.year, curr.month, curr.day, tzinfo=pytz.utc)
    start = curr - timedelta(days=(365 * 5))

    primary_match_station, warning_descs = eeweather.select_station(
        ranked_stations,
        coverage_range=(start, curr),
        min_fraction_coverage=0.9,
        rank=1,
    )

    return primary_match_station.usaf_id if primary_match_station else None
예제 #3
0
def test_rank_stations_max_difference_elevation_meters(lat_long_fresno,
                                                       snapshot):
    lat, lng = lat_long_fresno

    # no site_elevation
    df = rank_stations(lat, lng, max_difference_elevation_meters=200)
    snapshot.assert_match(df.shape, 'max_difference_elevation_meters=200')

    df = rank_stations(lat,
                       lng,
                       site_elevation=0,
                       max_difference_elevation_meters=200)
    snapshot.assert_match(
        df.shape, 'site_elevation=0, max_difference_elevation_meters=200')

    df = rank_stations(lat,
                       lng,
                       site_elevation=0,
                       max_difference_elevation_meters=50)
    snapshot.assert_match(
        df.shape, 'site_elevation=0, max_difference_elevation_meters=50')

    df = rank_stations(lat,
                       lng,
                       site_elevation=1000,
                       max_difference_elevation_meters=50)
    snapshot.assert_match(
        df.shape, 'site_elevation=1000, max_difference_elevation_meters=50')
예제 #4
0
def test_rank_stations_is_tmy3(lat_long_fresno, snapshot):
    lat, lng = lat_long_fresno
    df = rank_stations(lat, lng, is_tmy3=True)
    snapshot.assert_match(df.shape, 'is_tmy3=True')

    df = rank_stations(lat, lng, is_tmy3=False)
    snapshot.assert_match(df.shape, 'is_tmy3=False')
예제 #5
0
def test_rank_stations_max_distance_meters(lat_long_fresno, snapshot):
    lat, lng = lat_long_fresno

    df = rank_stations(lat, lng, max_distance_meters=200000)
    snapshot.assert_match(df.shape, 'max_distance_meters=200000')

    df = rank_stations(lat, lng, max_distance_meters=50000)
    snapshot.assert_match(df.shape, 'max_distance_meters=50000')
예제 #6
0
def test_rank_stations_minimum_quality(lat_long_fresno, snapshot):
    lat, lng = lat_long_fresno
    df = rank_stations(lat, lng, minimum_quality="low")
    snapshot.assert_match(df.shape, "minimum_quality=low")

    df = rank_stations(lat, lng, minimum_quality="medium")
    snapshot.assert_match(df.shape, "minimum_quality=medium")

    df = rank_stations(lat, lng, minimum_quality="high")
    snapshot.assert_match(df.shape, "minimum_quality=high")
예제 #7
0
def test_rank_stations_minimum_quality(lat_long_fresno, snapshot):
    lat, lng = lat_long_fresno
    df = rank_stations(lat, lng, minimum_quality='low')
    snapshot.assert_match(df.shape, 'minimum_quality=low')

    df = rank_stations(lat, lng, minimum_quality='medium')
    snapshot.assert_match(df.shape, 'minimum_quality=medium')

    df = rank_stations(lat, lng, minimum_quality='high')
    snapshot.assert_match(df.shape, 'minimum_quality=high')
예제 #8
0
def test_rank_stations_match_state(lat_long_fresno, snapshot):
    lat, lng = lat_long_fresno
    df = rank_stations(lat, lng, site_state='CA')
    snapshot.assert_match(df.shape, 'site_state=CA, match_state=False')

    df = rank_stations(lat, lng, site_state='CA', match_state=True)
    snapshot.assert_match(df.shape, 'site_state=CA, match_state=True')

    df = rank_stations(lat, lng, site_state=None, match_state=True)
    snapshot.assert_match(df.shape, 'site_state=None, match_state=True')
예제 #9
0
def test_rank_stations_minimum_tmy3_class(lat_long_fresno, snapshot):
    lat, lng = lat_long_fresno
    df = rank_stations(lat, lng, minimum_tmy3_class='III')
    snapshot.assert_match(df.shape, 'minimum_tmy3_class=III')

    df = rank_stations(lat, lng, minimum_tmy3_class='II')
    snapshot.assert_match(df.shape, 'minimum_tmy3_class=II')

    df = rank_stations(lat, lng, minimum_tmy3_class='I')
    snapshot.assert_match(df.shape, 'minimum_tmy3_class=I')
예제 #10
0
def test_rank_stations_match_climate_zones_null(lat_long_africa, snapshot):
    lat, lng = lat_long_africa
    df = rank_stations(lat, lng, match_iecc_climate_zone=True)
    snapshot.assert_match(df.shape, 'match_iecc_climate_zone')

    df = rank_stations(lat, lng, match_iecc_moisture_regime=True)
    snapshot.assert_match(df.shape, 'match_iecc_moisture_regime')

    df = rank_stations(lat, lng, match_ba_climate_zone=True)
    snapshot.assert_match(df.shape, 'match_ba_climate_zone')

    df = rank_stations(lat, lng, match_ca_climate_zone=True)
    snapshot.assert_match(df.shape, 'match_ca_climate_zone')
예제 #11
0
def test_rank_stations_match_climate_zones_not_null(lat_long_fresno, snapshot):
    lat, lng = lat_long_fresno
    df = rank_stations(lat, lng, match_iecc_climate_zone=True)
    snapshot.assert_match(df.shape, "match_iecc_climate_zone")

    df = rank_stations(lat, lng, match_iecc_moisture_regime=True)
    snapshot.assert_match(df.shape, "match_iecc_moisture_regime")

    df = rank_stations(lat, lng, match_ba_climate_zone=True)
    snapshot.assert_match(df.shape, "match_ba_climate_zone")

    df = rank_stations(lat, lng, match_ca_climate_zone=True)
    snapshot.assert_match(df.shape, "match_ca_climate_zone")
예제 #12
0
def naive_candidates(lat_long_fresno):
    lat, lng = lat_long_fresno
    return rank_stations(lat,
                         lng,
                         minimum_quality="high",
                         is_tmy3=True,
                         is_cz2010=True).head()
예제 #13
0
def test_select_station_distance_warnings_check(lat_long_africa):
    lat, lng = lat_long_africa
    df = rank_stations(lat, lng)
    station, warnings = select_station(df)
    assert len(warnings) == 2
    assert warnings[0].qualified_name == 'eeweather.exceeds_maximum_distance'
    assert warnings[1].qualified_name == 'eeweather.exceeds_maximum_distance'
    assert warnings[0].data['max_distance_meters'] == 50000
    assert warnings[1].data['max_distance_meters'] == 200000
예제 #14
0
def cz_candidates(lat_long_fresno):
    lat, lng = lat_long_fresno
    return rank_stations(
        lat,
        lng,
        match_iecc_climate_zone=True,
        match_iecc_moisture_regime=True,
        match_ba_climate_zone=True,
        match_ca_climate_zone=True,
        minimum_quality='high',
        is_tmy3=True,
        is_cz2010=True,
    )
예제 #15
0
def _get_closest_station_by_zcta_ranked(zcta):
    """Selects the nth ranked station from a list of ranked stations

    Parameters
    ----------
    zcta : string
        ZIP Code Tabulation Area (ZCTA)

    Returns
    -------
    station : string
        Station that was found
    lat : float
        latitude for the search
    lon : float
        longitude for the search
    """

    zcta = zcta.zfill(
        5
    )  # Ensure that we have 5 characters, and if not left-pad it with zeroes.
    try:
        lat, lon = zcta_to_lat_long(zcta)
    except UnrecognizedZCTAError:
        warnings.warn(
            "%s is not recognized as a ZCTA. Treating as a ZIP Code instead." % zcta
        )
        lat, lon = _zip_to_lat_long(zcta)

    station = None

    for min_quality, max_distance_meters in METHOD:
        station_ranking = rank_stations(
            lat,
            lon,
            minimum_quality=min_quality,
            max_distance_meters=max_distance_meters,
        )
        # Remove airport stations like A00008
        if len(station_ranking) > 0:
            station_ranking = station_ranking[
                station_ranking.index.str.contains("^[0-9]")
            ]

            station, _ = select_station(station_ranking)
            if station:
                break

    return station, lat, lon
예제 #16
0
def _rank_stations_by_distance_and_quality(lat, lon):
    """ Ranks the stations by distance and quality based on latitude / longitude

    Parameters
    ----------
    lat : float
        latitude for the search
    lon : float
        longitude for the search

    Returns
    -------
    station_ranking : Pandas.DataFrame
    """

    station_ranking = rank_stations(lat, lon)
    station_ranking['enumerated_quality'] = station_ranking['rough_quality'].map(QUALITY_SORT)
    station_ranking = station_ranking.sort_values(by=['distance_meters', 'enumerated_quality'])
    return station_ranking
예제 #17
0
def convert_coor_to_stations(sample, n_stations):
    """
    Converts coordinates to nearest, high quality weather stations, removing duplicates

    :param array sample: sample of coordinates to be converted to nearest station
    :param integer n_stations: number of stations to grab per sample point
    :return: array of coordinates for n_stations nearest weather stations
    :rtype: array
    """
    station_lat = []
    station_lon = []

    for i in sample:
        x = eeweather.rank_stations(i[0], i[1])
        for n in range(n_stations):
            station_lat.append(x[x['rough_quality'] == 'high']['latitude'][n])
            station_lon.append(x[x['rough_quality'] == 'high']['longitude'][n])

    station_coor = np.column_stack((station_lat, station_lon))
    station_coor = np.unique(station_coor, axis=0)
    return station_coor
예제 #18
0
def test_rank_stations_no_filter(lat_long_fresno, snapshot):
    lat, lng = lat_long_fresno
    df = rank_stations(lat, lng)
    snapshot.assert_match(df.shape, 'df.shape')
    assert list(df.columns) == [
        'rank',
        'distance_meters',
        'latitude',
        'longitude',
        'iecc_climate_zone',
        'iecc_moisture_regime',
        'ba_climate_zone',
        'ca_climate_zone',
        'rough_quality',
        'elevation',
        'state',
        'tmy3_class',
        'is_tmy3',
        'is_cz2010',
        'difference_elevation_meters',
    ]
    assert round(df.distance_meters.iloc[0]) == 3008.0
    assert round(df.distance_meters.iloc[-10]) == 9614514.0
    assert pd.isnull(df.distance_meters.iloc[-1]) is True
예제 #19
0
def test_rank_stations_no_filter(lat_long_fresno, snapshot):
    lat, lng = lat_long_fresno
    df = rank_stations(lat, lng)
    snapshot.assert_match(df.shape, "df.shape")
    assert list(df.columns) == [
        "rank",
        "distance_meters",
        "latitude",
        "longitude",
        "iecc_climate_zone",
        "iecc_moisture_regime",
        "ba_climate_zone",
        "ca_climate_zone",
        "rough_quality",
        "elevation",
        "state",
        "tmy3_class",
        "is_tmy3",
        "is_cz2010",
        "difference_elevation_meters",
    ]
    assert round(df.distance_meters.iloc[0]) == 3008.0
    assert round(df.distance_meters.iloc[-10]) == 9614514.0
    assert pd.isnull(df.distance_meters.iloc[-1]) is True
예제 #20
0
import eeweather
import datetime
import pytz

latitude = 33.8688
longitude = 151.2093
# for documentation read https://eeweather.readthedocs.io/en/latest/api.html#summaries
ranked_stations = eeweather.rank_stations(latitude, longitude, is_tmy3=True)
station, warnings = eeweather.select_station(ranked_stations)
print(ranked_stations.loc[station.usaf_id])
start_date = datetime.datetime(2016, 6, 1, tzinfo=pytz.UTC)
end_date = datetime.datetime(2016, 6, 15, tzinfo=pytz.UTC)
tempC = station.load_isd_hourly_temp_data(
    start_date, end_date)  #Integrated Surface Database (ISD)
tempC = station.load_isd_hourly_pcp24_data(
    start_date, end_date)  #Integrated Surface Database (ISD)

# tempC = station.load_gsod_daily_temp_data(start_date, end_date) #GSOD : Global Surface Summary Of Day
# eeweather.plot_station_mapping(latitude, longitude, station, distance_meters=ranked_stations.loc[station.usaf_id][1])#, target='91104')