Beispiel #1
0
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)
Beispiel #2
0
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)
Beispiel #3
0
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)
Beispiel #4
0
    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]))
vals = np.zeros(size)
x.get_value('daily_maximum_temperature', vals)
print(np.nanmin(vals))
print(np.nanmax(vals))
print_times(x)
x.update()
print_times(x)
tmp = 0
x.finalize()
# 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: