Пример #1
0
def test_hsCaribu():
    g = potted_syrah()
    # sample values copied from data.json_parameters
    unit_scene_length = 'cm'
    # Attaching optical properties to MTG elements
    g = optical_prop(g)

    # simple run
    assert 'Ei' not in g.property_names()
    assert 'Eabs' not in g.property_names()
    g, cs = hsCaribu(g, unit_scene_length)
    assert 'Ei' in g.property_names()
    assert 'Eabs' in g.property_names()
    assert len(g.property('Ei')) == len(cs.scene)
    assert len(g.property('Eabs')) == len(cs.scene)
    assert sum(g.property('Ei').values()) > 0

    # simple run during night
    g, cs = hsCaribu(g, unit_scene_length, source=[(0, (0, -1, 0))])
    assert sum(g.property('Ei').values()) == 0

    # reproduce scene filtering as done in model.py
    g = potted_syrah()
    unit_scene_length = 'cm'
    g = optical_prop(g)
    ng = len(g.property('geometry'))
    label = g.property('label')
    g.properties()['radiative_geometry'] = {
        k: v
        for k, v in g.property('geometry').iteritems()
        if label[k].startswith(('L', 'other', 'soil'))
    }
    assert len(g.property('radiative_geometry')) < ng
    g, cs = hsCaribu(g, unit_scene_length, geometry='radiative_geometry')
    assert len(g.property('Ei')) == len(cs.scene)
    assert len(g.property('Ei')) == len(g.property('radiative_geometry'))
    assert len(g.property('geometry')) == ng
    # non regression test
    ei_sum = sum(g.property('Ei').values())
    assert_almost_equal(ei_sum, 14.83, 2)

    # test consider option
    g = potted_syrah()
    unit_scene_length = 'cm'
    g = optical_prop(g)
    ng = len(g.property('geometry'))
    label = g.property('label')
    consider = [
        vid for vid in g.property('geometry')
        if label[vid].startswith(('L', 'other', 'soil'))
    ]
    assert len(consider) < ng
    g, cs = hsCaribu(g, unit_scene_length, consider=consider)
    assert len(g.property('Ei')) == len(cs.scene)
    assert len(g.property('Ei')) == len(consider)
    assert len(g.property('geometry')) == ng
    # non regression test
    ei_sum = sum(g.property('Ei').values())
    assert_almost_equal(ei_sum, 14.83, 2)
Пример #2
0
def test_heat_boundary_layer_conductance():
    g = potted_syrah()
    met = meteo().iloc[[12], :]
    l = energy.get_leaves_length(g)
    gbH = energy.heat_boundary_layer_conductance(l, met.u[0])
    assert len(gbH) == 46
    assert_almost_equal(sum(gbH.values()) / len(gbH), 47, 0)
Пример #3
0
def test_hydraulic_prop_attributes_the_right_properties_to_the_different_organs(
):
    simple_shoot = potted_syrah()
    simple_shoot.node(simple_shoot.root).vid_base = architecture.mtg_base(
        simple_shoot, vtx_label='inT')

    vid_base = simple_shoot.node(simple_shoot.root).vid_base
    for vtx_id in traversal.post_order2(simple_shoot, vid_base):
        n = simple_shoot.node(vtx_id)
        if n.label.startswith('LI'):
            n.E = 0.
            n.An = 0.

    hydraulic.hydraulic_prop(simple_shoot,
                             mass_conv=18.01528,
                             length_conv=1.e-2,
                             a=2.6,
                             b=2.0,
                             min_kmax=0.)

    for vtx_id in traversal.post_order2(simple_shoot, vid_base):
        n = simple_shoot.node(vtx_id)
        assert hasattr(n, 'Flux')
        assert hasattr(n, 'FluxC')
        if n.label.startswith(('in', 'cx', 'Pet')):
            assert hasattr(n, 'Kmax')
Пример #4
0
def test_potted_grapevine():
    g = non_regression_data.potted_syrah()
    results = model.run(g,
                        join(non_regression_data.sources_dir, ''),
                        write_result=False,
                        psi_soil=-0.5,
                        gdd_since_budbreak=1000.)
    ref = non_regression_data.reference_time_series_output()
    # do not compare date index
    assert_array_almost_equal(ref.iloc[0, 1:],
                              results.reset_index(drop=True).iloc[0, :],
                              decimal=0)
Пример #5
0
def test_pgl_scene():
    g = potted_syrah()
    bc = pgl.BBoxComputer(pgl.Tesselator())

    s = energy.pgl_scene(g)
    bc.process(s)
    bbox = bc.boundingbox
    zmin, zmax = bbox.getZMin(),bbox.getZMax()
    assert zmax > zmin > 0

    s = energy.pgl_scene(g, flip=True)
    bc.process(s)
    bbox = bc.boundingbox
    zmin, zmax = bbox.getZMin(),bbox.getZMax()
    assert 0 > zmax > zmin

    # check that original scene is still z >0
    s = energy.pgl_scene(g)
    bc.process(s)
    bbox = bc.boundingbox
    zmin, zmax = bbox.getZMin(), bbox.getZMax()
    assert zmax > zmin > 0
Пример #6
0
def test_leaf_temperature():
    g = potted_syrah()
    met = meteo().iloc[[12], :]
    tsoil = 20
    tsky = 2

    tleaf, it = leaf_temperature(g, met, tsoil, tsky)
    assert len(tleaf) == 46
    first = tleaf.keys()[0]
    for vid in tleaf:
        assert tleaf[vid] == tleaf[first]
        assert tleaf[vid] != met.Tac[0]

    l = energy.get_leaves_length(g)
    u = energy.leaf_wind_as_air_wind(g, met)
    gbH = energy.heat_boundary_layer_conductance(l, u)
    tleaf, it = leaf_temperature(g, met, tsoil, tsky, gbh=gbH)
    first = tleaf.keys()[0]
    assert len(tleaf) == 46
    for vid in tleaf:
        assert tleaf[vid] != met.Tac[0]
        if vid != first:
            assert tleaf[vid] != tleaf[first]
Пример #7
0
def test_form_factors_simplified():
    g = potted_syrah()
    k_soil, k_sky, k_leaves = form_factors_simplified(g, icosphere_level=0)
    # non regression test
    assert_almost_equal(sum(k_leaves.values()), 147.7, 1)
Пример #8
0
def test_get_leaves():
    g = potted_syrah()
    leaves = energy.get_leaves(g, leaf_lbl_prefix='L')
    assert len(leaves) == 46