Example #1
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
Example #2
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
    warnings : list
        List of warnings for the returned station (includes distance warnings)
    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.
    lat, lon = zcta_to_lat_long(zcta)
    finding_station = True
    rank = 0
    while finding_station:
        rank = rank + 1
        station_ranking = _rank_stations_by_distance_and_quality(lat, lon)
        station, warnings = select_station(station_ranking, rank=rank)

        # Ignore stations that begin with A
        if str(station)[0] != 'A':
            finding_station = False

    return station, warnings, lat, lon
Example #3
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
Example #4
0
def test_select_station_with_second_level_dates(
        cz_candidates, monkeypatch_load_isd_hourly_temp_data, snapshot):
    # dates don't fall exactly on the hour
    start = datetime(2017, 1, 1, 2, 3, 4, tzinfo=pytz.UTC)
    end = datetime(2018, 1, 1, 12, 13, 14, tzinfo=pytz.UTC)

    station, warnings = select_station(cz_candidates,
                                       coverage_range=(start, end))
    snapshot.assert_match(station.usaf_id, "station_id")
Example #5
0
def test_select_station_with_empty_tempC(
        cz_candidates, monkeypatch_load_isd_hourly_temp_data_with_empty):
    start = datetime(2017, 1, 1, tzinfo=pytz.UTC)
    end = datetime(2018, 1, 1, tzinfo=pytz.UTC)

    # 1st misses qualification because data not available
    station, warnings = select_station(cz_candidates,
                                       coverage_range=(start, end),
                                       min_fraction_coverage=0.8)
    assert station.usaf_id == '747020'
Example #6
0
def test_select_station_full_data(cz_candidates,
                                  monkeypatch_load_isd_hourly_temp_data):
    start = datetime(2017, 1, 1, tzinfo=pytz.UTC)
    end = datetime(2018, 1, 1, tzinfo=pytz.UTC)

    # 1st misses qualification
    station, warnings = select_station(cz_candidates,
                                       coverage_range=(start, end))
    assert station.usaf_id == "723895"

    # 1st meets qualification
    station, warnings = select_station(cz_candidates,
                                       coverage_range=(start, end),
                                       min_fraction_coverage=0.8)
    assert station.usaf_id == "723890"

    # none meet qualification
    station, warnings = select_station(cz_candidates,
                                       coverage_range=(start, end),
                                       min_fraction_coverage=0.99)
    assert station is None
Example #7
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
Example #8
0
def test_select_station_no_station_warnings_check():
    df = pd.DataFrame()
    station, warnings = select_station(df)
    assert warnings[
        0].qualified_name == 'eeweather.no_weather_station_selected'
    assert warnings[0].data == {'rank': 1, 'min_fraction_coverage': 0.9}
Example #9
0
def test_select_station_no_coverage_check(cz_candidates):
    station, warnings = select_station(cz_candidates)
    assert station.usaf_id == '723890'
Example #10
0
def test_select_station_no_station_warnings_check():
    df = pd.DataFrame()
    station, warnings = select_station(df)
    assert warnings[
        0].qualified_name == "eeweather.no_weather_station_selected"
    assert warnings[0].data == {"rank": 1, "min_fraction_coverage": 0.9}
Example #11
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')