コード例 #1
0
def test_frost_number_implements_update_until():
    fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
    fng.initialize()

    fng.update_until(fng.get_end_time())
    assert_true(fng._model._date_current, fng._model._end_date)

    fng.finalize()  # Must have this or get IOError later
コード例 #2
0
def test_frost_number_initialize_sets_year(tmpdir):
    with tmpdir.as_cwd():
        fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
        fng.initialize(cfg_file=config_filename)

        # Assert the values from the cfg file
        assert fng._model._date_current.year == 1901
        fng.finalize()  # Must have this or get IOError later
コード例 #3
0
def test_FNGeo_get_grid_size():
    fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
    fng.initialize()

    airtemp_gridid = fng.get_var_grid('atmosphere_bottom_air__temperature')
    assert_equal(6, fng.get_grid_size(airtemp_gridid))

    fng.finalize()  # Must have this or get IOError later
コード例 #4
0
def test_frost_number_update_increments_time():
    fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
    fng.initialize()
    fng.update()

    assert_equal(fng._model._date_current,
                 fng._model._start_date + \
                 relativedelta(years=fng._model._timestep_duration))
    fng.finalize()  # Must have this or get IOError later
コード例 #5
0
def test_FNGeo_get_grid_spacing(tmpdir):
    with tmpdir.as_cwd():
        fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
        fng.initialize()

        airtemp_gridid = fng.get_var_grid("atmosphere_bottom_air__temperature")
        assert np.all(np.array([1.0, 1.0]) == fng.get_grid_spacing(airtemp_gridid))

        fng.finalize()  # Must have this or get IOError later
コード例 #6
0
def test_frost_number_implements_update_until(tmpdir):
    with tmpdir.as_cwd():
        fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
        fng.initialize()

        fng.update_until(fng.get_end_time())
        assert fng._model._date_current == fng._model._end_date

        fng.finalize()  # Must have this or get IOError later
コード例 #7
0
def test_frost_number_initialize_sets_air_min_and_max():
    fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
    fng.initialize(cfg_file=config_filename)

    # The temperature arrays are initialized to all NaNs
    nan_array = np.zeros((3, 2), dtype=np.float32)
    nan_array.fill(np.nan)
    assert_array_equal(fng._model.T_air_min, nan_array)
    assert_array_equal(fng._model.T_air_max, nan_array)
    fng.finalize()  # Must have this or get IOError later
コード例 #8
0
def test_FNGeo_get_set_value():
    fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
    fng.initialize()

    airtempval = fng.get_value('atmosphere_bottom_air__temperature')
    airtempnew = 123 * np.ones_like(airtempval)
    fng.set_value('atmosphere_bottom_air__temperature', airtempnew)
    assert_raises(AssertionError, assert_array_equal, airtempval, airtempnew)

    fng.finalize()  # Must have this or get IOError later
コード例 #9
0
def test_FNGeo_get_attribute():
    fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
    fng.initialize()
    # Check an attribute that exists
    this_att = fng.get_attribute('time_units')
    assert_equal(this_att, 'years')

    # Check an attribute that doesn't exist
    assert_raises(KeyError, fng.get_attribute, 'not_an_attribute')

    fng.finalize()  # Must have this or get IOError later
コード例 #10
0
def test_FNGeo_get_set_value(tmpdir):
    with tmpdir.as_cwd():
        fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
        fng.initialize()

        airtempval = fng.get_value("atmosphere_bottom_air__temperature")
        airtempnew = 123 * np.ones_like(airtempval)
        fng.set_value("atmosphere_bottom_air__temperature", airtempnew)
        assert not np.all(airtempval == approx(airtempnew))

        fng.finalize()  # Must have this or get IOError later
コード例 #11
0
def test_FNGeo_update_zero_fraction_does_not_change_time():
    """ Test that running update_frac(0) does not change the time """
    fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
    fng.initialize()
    init_time = fng.get_current_time()
    fng.update_frac(0)
    plus_zero_time = fng.get_current_time()
    assert_equal(init_time, plus_zero_time)
    fng.update()
    one_update_time = fng.get_current_time()
    assert_not_equal(init_time, one_update_time)

    fng.finalize()  # Must have this or get IOError later
コード例 #12
0
def test_FNGeo_get_attribute(tmpdir):
    with tmpdir.as_cwd():
        fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
        fng.initialize()
        # Check an attribute that exists
        this_att = fng.get_attribute("time_units")
        assert this_att == "years"

        # Check an attribute that doesn't exist
        with pytest.raises(KeyError):
            fng.get_attribute("not_an_attribute")

        fng.finalize()  # Must have this or get IOError later
コード例 #13
0
def test_FNGeo_jan_and_jul_temperatures_are_grids():
    """ Test that FNGeo BMI has input variables for jan and jul data """
    fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
    fng.initialize()

    airtemp_gridid = fng.get_var_grid('atmosphere_bottom_air__temperature')
    jan_airtemp_gridid = \
            fng.get_var_grid('atmosphere_bottom_air__temperature_mean_jan')
    assert_true(jan_airtemp_gridid is not None)
    jul_airtemp_gridid = \
            fng.get_var_grid('atmosphere_bottom_air__temperature_mean_jul')
    assert_true(jul_airtemp_gridid is not None)

    fng.finalize()  # Must have this or get IOError later
コード例 #14
0
def test_frost_number_update_changes_air_frost_number(tmpdir):
    with tmpdir.as_cwd():
        fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
        fng.initialize()

        afn0 = fng._model.air_frost_number_Geo.copy()
        fng.update()
        afn1 = fng._model.air_frost_number_Geo.copy()
        assert np.any(afn0 != afn1)
        fng.update_until(1.0)
        afn2 = fng._model.air_frost_number_Geo.copy()
        assert np.all(afn1 == afn2)

        fng.finalize()  # Must have this or get IOError later
コード例 #15
0
def test_FNGeo_update_zero_fraction_does_not_change_time(tmpdir):
    """ Test that running update_frac(0) does not change the time """
    with tmpdir.as_cwd():
        fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
        fng.initialize()
        init_time = fng.get_current_time()
        fng.update_frac(0)
        plus_zero_time = fng.get_current_time()
        assert init_time == plus_zero_time
        fng.update()
        one_update_time = fng.get_current_time()
        assert not np.all(init_time == one_update_time)

        fng.finalize()  # Must have this or get IOError later
コード例 #16
0
def test_frost_number_update_changes_air_frost_number():
    fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
    fng.initialize()

    fng.update()
    afn0 = fng._model.air_frost_number_Geo
    fng.update_until(fng._model._date_current + datetime.timedelta(days=370))
    afn1 = fng._model.air_frost_number_Geo
    try:
        # If this is none, then the first array was all NaNs
        assert_true(assert_array_equal(afn0, afn1) is None)
    except AssertionError:
        # If this is raised, then the arrays are different, which is nood
        pass
    fng.finalize()  # Must have this or get IOError later
コード例 #17
0
def test_FNGeo_jan_and_jul_temperatures_are_grids(tmpdir):
    """ Test that FNGeo BMI has input variables for jan and jul data """
    with tmpdir.as_cwd():
        fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
        fng.initialize()

        airtemp_gridid = fng.get_var_grid("atmosphere_bottom_air__temperature")
        jan_airtemp_gridid = fng.get_var_grid(
            "atmosphere_bottom_air__temperature_mean_jan"
        )
        assert jan_airtemp_gridid is not None
        jul_airtemp_gridid = fng.get_var_grid(
            "atmosphere_bottom_air__temperature_mean_jul"
        )
        assert jul_airtemp_gridid is not None

        fng.finalize()  # Must have this or get IOError later
コード例 #18
0
def test_FNGeo_computes_default_values():
    fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
    fng.initialize()
    for n in range(5):
        if (fng._model.T_air_min[0, 0] + fng._model.T_air_max[0, 0]) == 0:
            assert_equal(fng._values['frostnumber__air'][0, 0], 0.5)
        if (fng._model.T_air_min[0, 0] <= 0.0) and \
           (fng._model.T_air_max[0, 0] <= 0.0):
            assert_equal(fng._values['frostnumber__air'][0, 0], 1.0)
        if (fng._model.T_air_min[0, 0] > 0.0) and \
           (fng._model.T_air_max[0, 0] > 0.0):
            assert_equal(fng._values['frostnumber__air'][0, 0], 0.0)
        #print("FNGeo frostnumber__air: %d" % n)
        #print(fng._model.T_air_min)
        #print(fng._model.T_air_max)
        #print(fng._values['frostnumber__air'])
        fng.update()
    fng.finalize()  # Must have this or get IOError later
コード例 #19
0
def test_FNGeo_can_set_current_and_jan_temperatures():
    """ Test that FNGeo BMI can set jan temperature field """
    fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
    fng.initialize()

    airtemp_values = fng.get_value('atmosphere_bottom_air__temperature')
    airtemp_values = np.ones_like(airtemp_values)
    fng.set_value('atmosphere_bottom_air__temperature', airtemp_values)

    jan_airtemp_values = \
        fng.get_value('atmosphere_bottom_air__temperature_mean_jan')
    jan_airtemp_values = np.ones_like(jan_airtemp_values)
    fng.set_value('atmosphere_bottom_air__temperature_mean_jan',
                  jan_airtemp_values)
    assert_array_equal(
        fng.get_value('atmosphere_bottom_air__temperature'),
        fng.get_value('atmosphere_bottom_air__temperature_mean_jan'))

    fng.finalize()  # Must have this or get IOError later
コード例 #20
0
def test_FNGeo_can_set_current_and_jan_temperatures(tmpdir):
    """ Test that FNGeo BMI can set jan temperature field """
    with tmpdir.as_cwd():
        fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
        fng.initialize()

        airtemp_values = fng.get_value("atmosphere_bottom_air__temperature")
        airtemp_values = np.ones_like(airtemp_values)
        fng.set_value("atmosphere_bottom_air__temperature", airtemp_values)

        jan_airtemp_values = fng.get_value(
            "atmosphere_bottom_air__temperature_mean_jan"
        )
        jan_airtemp_values = np.ones_like(jan_airtemp_values)
        fng.set_value("atmosphere_bottom_air__temperature_mean_jan", jan_airtemp_values)
        assert np.all(
            fng.get_value("atmosphere_bottom_air__temperature")
            == fng.get_value("atmosphere_bottom_air__temperature_mean_jan")
        )

        fng.finalize()  # Must have this or get IOError later
コード例 #21
0
def test_FNGeo_computes_default_values(tmpdir):
    with tmpdir.as_cwd():
        fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
        fng.initialize()
        for n in range(5):
            if (fng._model.T_air_min[0, 0] + fng._model.T_air_max[0, 0]) == 0:
                assert fng._values["frostnumber__air"][0, 0] == 0.5
            if (fng._model.T_air_min[0, 0] <= 0.0) and (
                fng._model.T_air_max[0, 0] <= 0.0
            ):
                assert fng._values["frostnumber__air"][0, 0] == 1.0
            if (fng._model.T_air_min[0, 0] > 0.0) and (
                fng._model.T_air_max[0, 0] > 0.0
            ):
                assert fng._values["frostnumber__air"][0, 0] == 0.0
            # print("FNGeo frostnumber__air: %d" % n)
            # print(fng._model.T_air_min)
            # print(fng._model.T_air_max)
            # print(fng._values['frostnumber__air'])
            fng.update()
        fng.finalize()  # Must have this or get IOError later
コード例 #22
0
def test_frost_number_Geo_has_initialize():
    # Can we call an initialize function?
    fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
    fng.initialize(cfg_file=config_filename)
    fng.finalize()  # Must have this or get IOError later
コード例 #23
0
def test_FNGeo_get_input_var_names():
    fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
    fng.initialize()
    assert_in('atmosphere_bottom_air__temperature', fng.get_input_var_names())

    fng.finalize()  # Must have this or get IOError later
コード例 #24
0
def test_FNGeo_get_output_var_names():
    fng = bmi_frost_number_Geo.BmiFrostnumberGeoMethod()
    fng.initialize()
    assert_in('frostnumber__air', fng.get_output_var_names())

    fng.finalize()  # Must have this or get IOError later