def test_grid_var_origin(): model = BmiGridmet() model.initialize() shape = np.empty(2, dtype=np.float) tmp2 = np.array([25.066667, -124.77]) npt.assert_almost_equal(model.get_grid_origin(grid_id, shape), tmp2, decimal=2)
def test_grid_var_spacing(): model = BmiGridmet() model.initialize() shape = np.empty(2, dtype=np.float) tmp2 = np.array([0.041667, 0.041667]) npt.assert_almost_equal(model.get_grid_spacing(grid_id, shape), tmp2, decimal=4)
def test_value_size(): model = BmiGridmet() model.initialize() grid_id = model.get_var_grid("daily_maximum_temperature") size = model.get_grid_size(grid_id) vals1 = np.empty(size) z = model.get_value("daily_maximum_temperature", vals1) assert model.get_grid_size(0) == z.size
def test_update(): model = BmiGridmet() model.initialize() for inc in range(6): model.update() npt.assert_almost_equal( model.get_current_time(), (inc + 1) * model.get_time_step() )
def test_initialize_defaults(): model = BmiGridmet() model.initialize() grid_id = model.get_var_grid("daily_maximum_temperature") size = model.get_grid_size(grid_id) vals = np.empty(size) model.get_value("daily_maximum_temperature", vals) min = np.nanmin(vals) max = np.nanmax(vals) npt.assert_almost_equal(min, 266.399, decimal=2) npt.assert_almost_equal(max, 305.0, decimal=1)
def test_get_value_copy(): model = BmiGridmet() model.initialize() grid_id = model.get_var_grid("daily_maximum_temperature") size = model.get_grid_size(grid_id) vals1 = np.empty(size) vals2 = np.empty(size) z0 = model.get_value("daily_maximum_temperature", vals1) z1 = model.get_value("daily_maximum_temperature", vals2) assert z0 is not z1 npt.assert_array_almost_equal(z0, z1)
def test_initialize_from_file(): import datetime import os import tempfile import yaml yamldict = { "_start_date": datetime.date(year=2020, month=1, day=1), "_end_date": datetime.date(year=2020, month=1, day=7), } with tempfile.NamedTemporaryFile("w", delete=False) as fp: fp.write((yaml.dump(yamldict, sort_keys=False))) name = fp.name model = BmiGridmet() model.initialize(name) os.remove(name) shape = np.empty(2, dtype=np.int) tmp = model.get_grid_shape(0, shape) tmp2 = np.array([585, 1386]) npt.assert_almost_equal(tmp, tmp2)
def test_grid_var_item_count(): model = BmiGridmet() model.initialize() count = model.get_input_item_count() assert count == 0 count = model.get_output_item_count() assert count == 3
def test_grid_var_names(): model = BmiGridmet() model.initialize() names = model.get_input_var_names() assert names == ("") names = model.get_output_var_names() assert names == ( "daily_maximum_temperature", "daily_minimum_temperature", "precipitation_amount", )
def test_grid_var_rank(): model = BmiGridmet() model.initialize() assert model.get_grid_rank(grid_id) == 2
import numpy as np import numpy.testing as npt import tempfile import yaml import datetime def print_times(x): print(x.get_start_time()) print(x.get_time_step()) print(x.get_time_units()) print(x.get_current_time()) print(x.get_end_time()) x = BmiGridmet() # x.initialize('gridmet_bmi.yaml') x.initialize() print(x.get_input_var_names()) print(x.get_output_var_names()) grid_id = x.get_var_grid('daily_maximum_temperature') size = x.get_grid_size(grid_id) shape = np.empty(2, dtype=np.int) origin = np.empty(2, dtype=np.float) delta = np.empty(2, dtype=np.float) x.get_grid_origin(grid_id, origin) x.get_grid_spacing(grid_id, spacing=delta) tmp = x.get_grid_shape(grid_id, shape) print(type(shape), shape[0], shape[1], shape) tmp2 = np.array([585, 1386]) npt.assert_almost_equal(shape, np.array([585, 1386]))
def test_end_time(): model = BmiGridmet() model.initialize() npt.assert_almost_equal(model.get_end_time(), 7.0)
def test_component_name(): model = BmiGridmet() name = model.get_component_name() assert name == "Gridmet_BMI" assert model.get_component_name() is name
def test_grid_var_shape_fail(): model = BmiGridmet() model.initialize() shape = np.empty(2, dtype=np.int) with pytest.raises(KeyError): model.get_grid_shape(invalid_grid_id, shape)
def test_grid_var_shape(): model = BmiGridmet() model.initialize() shape = np.empty(2, dtype=np.int) tmp2 = np.array([585, 1386]) npt.assert_equal(model.get_grid_shape(grid_id, shape), tmp2)
def test_grid_var_size_fail(): model = BmiGridmet() model.initialize() with pytest.raises(KeyError): model.get_grid_size(invalid_grid_id)
def test_grid_var_type(): model = BmiGridmet() model.initialize() assert model.get_var_type("daily_maximum_temperature") == "float32"
def test_grid_type(): model = BmiGridmet() model.initialize() assert model.get_grid_type(grid_id) == "uniform_rectilinear"
def test_grid_id(): model = BmiGridmet() model.initialize() assert model.get_var_grid("daily_maximum_temperature") == grid_id
def test_grid_var_units(): model = BmiGridmet() model.initialize() assert model.get_var_units("daily_maximum_temperature") == "K" assert model.get_var_units("precipitation_amount") == "mm"
def test_finalize(): model = BmiGridmet() model.initialize() model.update() model.finalize()
def test_grid_var_size(): model = BmiGridmet() model.initialize() assert model.get_grid_size(grid_id) == 810810