# Path: fluids/design_climate.py
# def geopy_geolocator():
# def geopy_cache():
#     def __init__(self, file_name):
#     def cached_address(self, address):
#     def cache_address(self, address, latitude, longitude):
# def geocode(address):
# def heating_degree_days(T, T_base=291.4833333333333, truncate=True):
# def cooling_degree_days(T, T_base=283.15, truncate=True):
# def get_clean_isd_history(dest=os.path.join(folder, 'isd-history-cleaned.tsv'),
#                           url="ftp://ftp.ncdc.noaa.gov/pub/data/noaa/isd-history.csv"): # pragma: no cover
#     def __repr__(self):
#     def __init__(self, USAF, WBAN, NAME, CTRY, ST, ICAO, LAT, LON, ELEV, BEGIN,
#                  END):
#     def __init__(self, station, data_dir_override=None):
#     def load_empty_vectors(self):
#     def download_data(self):
#     def parse_data(self):
#     def coldest_month(self, older_year=None, newer_year=None, minimum_days=23):
#     def warmest_month(self, older_year=None, newer_year=None, minimum_days=23):
#     def month_average_temperature(self, older_year=None, newer_year=None,
#                                   include_yearly=False, minimum_days=23):
#     def month_average_windspeed(self, older_year=None, newer_year=None,
#                                   include_yearly=False, minimum_days=23):
#     def percentile_extreme_condition(self, older_year=None, newer_year=None,
#                                   include_yearly=False, minimum_days=23, attr='WDSP'):
# def get_closest_station(latitude, longitude, minumum_recent_data=20140000,
#                         match_max=100):
# def get_station_year_text(WMO, WBAN, year, data_dir_override=None):
# def gsod_day_parser(line, SI=True, to_datetime=True):
# class SimpleGeolocatorCache(object):
# class IntegratedSurfaceDatabaseStation(object):
# class StationDataGSOD(object):
#                 T = day.TEMP
#         WMO = 999999
#         WBAN = 99999


from numpy.testing import assert_allclose
from fluids.numerics import assert_close, assert_close1d
from fluids.design_climate import *
from fluids.design_climate import _latlongs, stations
import pytest
import numpy as np
import os
    import geopy
def test_cooling_degree_days():

    assert_close( cooling_degree_days(250), 33.15)
    assert 0 == cooling_degree_days(300)
    assert_close(cooling_degree_days(300, truncate=False), -16.85)
    assert_close(cooling_degree_days(250, T_base=300), 50)


@pytest.mark.slow
def test_month_average_temperature():
    station = get_closest_station(38.8572, -77.0369)
    station_data = StationDataGSOD(station, data_dir_override=data_dir_override)
    Ts_calc = station_data.month_average_temperature(1990, 2000, include_yearly=False, minimum_days=23)
    Ts_expect = [276.1599380905833, 277.5375516246206, 281.1881231671554, 286.7367003367004, 291.8689638318671, 296.79545454545456, 299.51868686868687, 298.2097914630174, 294.4116161616162, 288.25883023786247, 282.3188552188553, 277.8282339524275]
    assert_close1d(Ts_calc, Ts_expect, rtol=1E-3)

    assert station_data.warmest_month(1990, 2000) == 6
    assert station_data.coldest_month(1990, 2000) == 0



def test_IntegratedSurfaceDatabaseStation():

    # Information confirmed elsewhere i.e. https://geographic.org/global_weather/not_specified_canada/calgary_intl_cs_713930_99999.html
    values = [713930.0, 99999.0, 'CALGARY INTL CS', 'CA', None, None, 51.1, -114.0, 1081.0, 20040921.0, 20150831.0]
    test_station = IntegratedSurfaceDatabaseStation(*values)
    for value, attr in zip(values, test_station.__slots__):
        assert value == getattr(test_station, attr)

def test_data():

# Path: fluids/design_climate.py
# def geopy_geolocator():
# def geopy_cache():
#     def __init__(self, file_name):
#     def cached_address(self, address):
#     def cache_address(self, address, latitude, longitude):
# def geocode(address):
# def heating_degree_days(T, T_base=291.4833333333333, truncate=True):
# def cooling_degree_days(T, T_base=283.15, truncate=True):
# def get_clean_isd_history(dest=os.path.join(folder, 'isd-history-cleaned.tsv'),
#                           url="ftp://ftp.ncdc.noaa.gov/pub/data/noaa/isd-history.csv"): # pragma: no cover
#     def __repr__(self):
#     def __init__(self, USAF, WBAN, NAME, CTRY, ST, ICAO, LAT, LON, ELEV, BEGIN,
#                  END):
#     def __init__(self, station, data_dir_override=None):
#     def load_empty_vectors(self):
#     def download_data(self):
#     def parse_data(self):
#     def coldest_month(self, older_year=None, newer_year=None, minimum_days=23):
#     def warmest_month(self, older_year=None, newer_year=None, minimum_days=23):
#     def month_average_temperature(self, older_year=None, newer_year=None,
#                                   include_yearly=False, minimum_days=23):
#     def month_average_windspeed(self, older_year=None, newer_year=None,
#                                   include_yearly=False, minimum_days=23):
#     def percentile_extreme_condition(self, older_year=None, newer_year=None,
#                                   include_yearly=False, minimum_days=23, attr='WDSP'):
# def get_closest_station(latitude, longitude, minumum_recent_data=20140000,
#                         match_max=100):
# def get_station_year_text(WMO, WBAN, year, data_dir_override=None):
# def gsod_day_parser(line, SI=True, to_datetime=True):
# class SimpleGeolocatorCache(object):
# class IntegratedSurfaceDatabaseStation(object):
# class StationDataGSOD(object):
#                 T = day.TEMP
#         WMO = 999999
#         WBAN = 99999


# Path: tests/test_design_climate.py
from numpy.testing import assert_allclose
from fluids.numerics import assert_close, assert_close1d
from fluids.design_climate import *
from fluids.design_climate import _latlongs, stations
import pytest
import numpy as np
import os
    import geopy

def test_cooling_degree_days():

    assert_close( cooling_degree_days(250), 33.15)
    assert 0 == cooling_degree_days(300)
    assert_close(cooling_degree_days(300, truncate=False), -16.85)
    assert_close(cooling_degree_days(250, T_base=300), 50)


@pytest.mark.slow
def test_month_average_temperature():
    station = get_closest_station(38.8572, -77.0369)
    station_data = StationDataGSOD(station, data_dir_override=data_dir_override)
    Ts_calc = station_data.month_average_temperature(1990, 2000, include_yearly=False, minimum_days=23)
    Ts_expect = [276.1599380905833, 277.5375516246206, 281.1881231671554, 286.7367003367004, 291.8689638318671, 296.79545454545456, 299.51868686868687, 298.2097914630174, 294.4116161616162, 288.25883023786247, 282.3188552188553, 277.8282339524275]
    assert_close1d(Ts_calc, Ts_expect, rtol=1E-3)

    assert station_data.warmest_month(1990, 2000) == 6
    assert station_data.coldest_month(1990, 2000) == 0



def test_IntegratedSurfaceDatabaseStation():

    # Information confirmed elsewhere i.e. https://geographic.org/global_weather/not_specified_canada/calgary_intl_cs_713930_99999.html
    values = [713930.0, 99999.0, 'CALGARY INTL CS', 'CA', None, None, 51.1, -114.0, 1081.0, 20040921.0, 20150831.0]
    test_station = IntegratedSurfaceDatabaseStation(*values)
    for value, attr in zip(values, test_station.__slots__):
        assert value == getattr(test_station, attr)

def test_data():

    assert _latlongs.shape[0] >= 27591