Example #1
0
def test_temperature_conversion():
    """Check to see if input_functions.convert_units produces the expected values when converting temperature"""

    # Convert_units expects input in the form of numpy arrays
    temp_f = np.array([212.0
                       ])  # boiling point and freezing point of water in F
    temp_k = np.array([373.15
                       ])  # boiling point and freezing point of water in K
    temp_c = np.array([100.0
                       ])  # boiling point and freezing point of water in C

    config_dict_for_f = {'temp_f_flag': 1, 'temp_k_flag': 0}
    config_dict_for_k = {'temp_f_flag': 0, 'temp_k_flag': 1}
    config_dict_for_c = {'temp_f_flag': 0, 'temp_k_flag': 0}

    converted_temp_f_to_c = input_functions.convert_units(
        config_dict_for_f, temp_f, 'temperature')
    converted_temp_k_to_c = input_functions.convert_units(
        config_dict_for_k, temp_k, 'temperature')
    converted_temp_c_to_c = input_functions.convert_units(
        config_dict_for_c, temp_c, 'temperature')

    assert converted_temp_f_to_c[0] == pt.approx(temp_c[0], abs=1e-3),\
        'Temperature F to C and test value C are not equal.'
    assert converted_temp_k_to_c[0] == pt.approx(temp_c[0], abs=1e-3),\
        'Temperature K to C and test value C are not equal.'
    assert converted_temp_c_to_c[0] == pt.approx(temp_c[0], abs=1e-3),\
        'Temperature C to C and test value C are not equal.'
Example #2
0
def test_vapor_pressure_conversion():
    """Check to see if input_functions.convert_units produces the expected values when converting vapor pressure"""

    # Convert_units expects input in the form of numpy arrays
    ea_torr = np.array([7.5])  # Test vapor pressure in torr or mmhg
    ea_mbar = np.array([10.0])  # Test vapor pressure in millibars
    ea_kpa = np.array([1.0])  # Test vapor pressure in kilopascals

    config_dict_for_torr = {'ea_torr_flag': 1, 'ea_mbar_flag': 0}
    config_dict_for_mbar = {'ea_torr_flag': 0, 'ea_mbar_flag': 1}
    config_dict_for_kpa = {'ea_torr_flag': 0, 'ea_mbar_flag': 0}

    converted_ea_torr_to_kpa = input_functions.convert_units(
        config_dict_for_torr, ea_torr, 'vapor_pressure')
    converted_ea_mbar_to_kpa = input_functions.convert_units(
        config_dict_for_mbar, ea_mbar, 'vapor_pressure')
    converted_ea_kpa_to_kpa = input_functions.convert_units(
        config_dict_for_kpa, ea_kpa, 'vapor_pressure')

    assert converted_ea_torr_to_kpa[0] == pt.approx(ea_kpa[0], abs=1e-3), \
        'Ea torr to kpa and test value kpa are not equal.'
    assert converted_ea_mbar_to_kpa[0] == pt.approx(ea_kpa[0], abs=1e-3), \
        'Ea mbar to kpa and test value kpa are not equal.'
    assert converted_ea_kpa_to_kpa[0] == pt.approx(ea_kpa[0], abs=1e-3), \
        'Ea kpa to kpa and test value kpa are not equal.'
Example #3
0
def test_wind_speed_conversion():
    """Check to see if input_functions.convert_units produces the expected values when converting windspeed"""

    # Convert_units expects input in the form of numpy arrays
    uz_mph = np.array([15.66])  # Test wind in miles per hour
    uz_run_mi = np.array([375.8])  # Test speed in daily wind run (miles)
    uz_run_km = np.array([604.80])  # Test speed in daily wind run (kilometers)
    uz_ms = np.array([7.0])  # Test wind speed in meters per second

    config_dict_for_mph = {
        'uz_mph_flag': 1,
        'uz_wind_run_km_flag': 0,
        'uz_wind_run_mi_flag': 0
    }
    config_dict_for_run_km = {
        'uz_mph_flag': 0,
        'uz_wind_run_km_flag': 1,
        'uz_wind_run_mi_flag': 0
    }
    config_dict_for_run_mi = {
        'uz_mph_flag': 0,
        'uz_wind_run_km_flag': 0,
        'uz_wind_run_mi_flag': 1
    }
    config_dict_for_ms = {
        'uz_mph_flag': 0,
        'uz_wind_run_km_flag': 0,
        'uz_wind_run_mi_flag': 0
    }

    converted_uz_mph_to_ms = input_functions.convert_units(
        config_dict_for_mph, uz_mph, 'wind_speed')
    converted_uz_run_km_to_ms = input_functions.convert_units(
        config_dict_for_run_km, uz_run_km, 'wind_speed')
    converted_uz_run_mi_to_ms = input_functions.convert_units(
        config_dict_for_run_mi, uz_run_mi, 'wind_speed')
    converted_uz_ms_to_ms = input_functions.convert_units(
        config_dict_for_ms, uz_ms, 'wind_speed')

    assert converted_uz_mph_to_ms[0] == pt.approx(uz_ms[0], abs=1e-3), \
        'Wind mph to m/s and test value m/s are not equal.'
    assert converted_uz_run_km_to_ms[0] == pt.approx(uz_ms[0], abs=1e-3), \
        'Wind run_km to m/s and test value m/s are not equal.'
    assert converted_uz_run_mi_to_ms[0] == pt.approx(uz_ms[0], abs=1e-3), \
        'Wind run_mi to m/s and test value m/s are not equal.'
    assert converted_uz_ms_to_ms[0] == pt.approx(uz_ms[0], abs=1e-3), \
        'Wind m/s to m/s and test value m/s are not equal.'
Example #4
0
def test_relative_humidity_conversion():
    """Check to see if input_functions.convert_units produces the expected values when converting relative humidity"""

    # Convert_units expects input in the form of numpy arrays
    rh_fract = np.array([0.5])  # Test relative humidity as a fraction
    rh_perct = np.array([50.0])  # Test relative humidity as a percentage

    config_dict_for_fract = {'rh_fraction_flag': 1}
    config_dict_for_perct = {'rh_fraction_flag': 0}

    converted_rh_fract_to_perct = input_functions.convert_units(
        config_dict_for_fract, rh_fract, 'relative_humidity')
    converted_rh_perct_to_perct = input_functions.convert_units(
        config_dict_for_perct, rh_perct, 'relative_humidity')

    assert converted_rh_fract_to_perct[0] == pt.approx(rh_perct[0], abs=1e-3), \
        'Relative humidity fraction to percentage and test value percentage are not equal.'
    assert converted_rh_perct_to_perct[0] == pt.approx(rh_perct[0], abs=1e-3), \
        'Relative humidity percentage to percentage and test value percentage are not equal.'
Example #5
0
def test_precipitation_conversion():
    """Check to see if input_functions.convert_units produces the expected values when converting precipitation"""

    # Convert_units expects input in the form of numpy arrays
    pp_inch = np.array([1.0])  # Test precipitation in inches
    pp_mm = np.array([25.4])  # Test precipitation in millimeters

    config_dict_for_inch = {'pp_inch_flag': 1}
    config_dict_for_mm = {'pp_inch_flag': 0}

    converted_pp_inch_to_mm = input_functions.convert_units(
        config_dict_for_inch, pp_inch, 'precipitation')
    converted_pp_mm_to_mm = input_functions.convert_units(
        config_dict_for_mm, pp_mm, 'precipitation')

    assert converted_pp_inch_to_mm[0] == pt.approx(pp_mm[0], abs=1e-3), \
        'Precipitation inch to mm and test value mm are not equal.'
    assert converted_pp_mm_to_mm[0] == pt.approx(pp_mm[0], abs=1e-3), \
        'Precipitation mm to mm and test value mm are not equal.'
Example #6
0
def test_solar_radiation_conversion():
    """Check to see if input_functions.convert_units produces the expected values when converting solar radiation"""

    # Convert_units expects input in the form of numpy arrays
    rs_lang = np.array([206.363])  # Test radiation in langleys
    rs_mj = np.array([8.640])  # Test radiation in megajoules/m2
    rs_kwhr = np.array([2.4])  # Test radiation in kilowatt-hours/m2
    rs_w = np.array([100.0])  # Test radiation in watts/m2

    config_dict_for_lang = {
        'rs_lang_flag': 1,
        'rs_mj_flag': 0,
        'rs_kwhr_flag': 0
    }
    config_dict_for_mj = {
        'rs_lang_flag': 0,
        'rs_mj_flag': 1,
        'rs_kwhr_flag': 0
    }
    config_dict_for_kwhr = {
        'rs_lang_flag': 0,
        'rs_mj_flag': 0,
        'rs_kwhr_flag': 1
    }
    config_dict_for_w = {'rs_lang_flag': 0, 'rs_mj_flag': 0, 'rs_kwhr_flag': 0}

    converted_rs_lang_to_w = input_functions.convert_units(
        config_dict_for_lang, rs_lang, 'solar_radiation')
    converted_rs_mj_to_w = input_functions.convert_units(
        config_dict_for_mj, rs_mj, 'solar_radiation')
    converted_rs_kwhr_to_w = input_functions.convert_units(
        config_dict_for_kwhr, rs_kwhr, 'solar_radiation')
    converted_rs_w_to_w = input_functions.convert_units(
        config_dict_for_w, rs_w, 'solar_radiation')

    assert converted_rs_lang_to_w[0] == pt.approx(rs_w[0], abs=1e-3), \
        'Solar radiation lang to w/m2 and test value w/m2 are not equal.'
    assert converted_rs_mj_to_w[0] == pt.approx(rs_w[0], abs=1e-3), \
        'Solar radiation mj/m2 to w/m2 and test value w/m2 are not equal.'
    assert converted_rs_kwhr_to_w[0] == pt.approx(rs_w[0], abs=1e-3), \
        'Solar radiation kw-hr/m2 to w/m2 and test value w/m2 are not equal.'
    assert converted_rs_w_to_w[0] == pt.approx(rs_w[0], abs=1e-3), \
        'Solar radiation w/m2 to w/m2 and test value w/m2 are not equal.'