コード例 #1
0
ファイル: test_variants.py プロジェクト: tharen/testing
    def test_fsv_step_fvs_grow(self, name, variant):
        f = fvs.FVS(variant)
        p = './bg_test.key'
        with open(p, 'w') as foo:
            foo.write(nw_bg_test_kwds())
        f.fvs_step.fvs_init(p)

        for c in range(f.contrl_mod.ncyc):
            r = f.fvs_step.fvs_grow()

        r = f.fvs_step.fvs_end()
        print('FVS Return Code: %s' % r)
        self.assertEqual(r, 0, 'FVS Return Code: %s' % r)
コード例 #2
0
def test_load_variant(variant):
    """
    Test that variant libraries load and initialize.
    """
    try:
        f = fvs.FVS(variant)

    except ImportError:
        pytest.skip('No variant library: {}'.format(variant))
        return None

    except:
        raise

    assert f.variant == variant
    assert not f.fvslib is None
    f = None
コード例 #3
0
def test_bare_ground(variant, kwd_path, sum_path):
    try:
        f = fvs.FVS(variant)

    except ImportError:
        pytest.skip('No variant library: {}'.format(variant))
        return None

    except:
        raise

    f.init_projection(os.path.join(root, kwd_path))

    for c in range(f.contrl_mod.ncyc):
        r = f.grow_projection()

    r = f.end_projection()
    assert r == 0

    widths = [
        4, 4, 6, 4, 5, 4, 4, 5, 6, 6, 6, 6, 6, 6, 6, 4, 5, 4, 4, 5, 8, 5, 6, 8,
        4, 2, 1
    ]
    fldnames = ('year,age,tpa,baa,sdi,ccf,top_ht,qmd,total_cuft'
                ',merch_cuft,merch_bdft,rem_tpa,rem_total_cuft'
                ',rem_merch_cuft,rem_merch_bdft,res_baa,res_sdi'
                ',res_ccf,res_top_ht,resid_qmd,grow_years'
                ',annual_acc,annual_mort,mai_merch_cuft,for_type'
                ',size_class,stocking_class').split(',')

    # Read the sum file generated by the "official" FVS executable
    sum_check = pd.read_fwf(os.path.join(root, sum_path),
                            skiprows=1,
                            widths=widths)
    sum_check.columns = fldnames

    # Read the sum file produced by the pyfvs variant wrapper
    p = os.path.join(root, os.path.splitext(sum_path)[0])
    sum_test = pd.read_fwf(p, skiprows=1, widths=widths)
    sum_test.columns = fldnames

    for fld in fldnames[:18]:
        assert np.all(
            np.isclose(sum_check.loc[:, fld], sum_test.loc[:, fld], atol=1))
コード例 #4
0
ファイル: test_fvstrees.py プロジェクト: d-diaz/PyFVS
    def test_fsv_trees(self):
        try:
            f = fvs.FVS(fvs_variant)

        except ImportError:
            pytest.skip('No variant library: {}'.format(fvs_variant))
            return None

        except:
            raise

        p = './bg_test.key'
        kwds = bg_kwds()
        kwds.write(p)

        f.init_projection(p)

        for c in range(f.num_cycles):
            r = f.grow_projection()

        r = f.end_projection()
        print('FVS Return Code: %s' % r)
        self.assertEqual(r, 0, 'FVS Return Code: %s' % r)
コード例 #5
0
ファイル: test_pyfvs.py プロジェクト: tharen/testing
 def test_import_variants(self):
     print(self.variant)
     f = fvs.FVS(self.variant)
コード例 #6
0
ファイル: test_variants.py プロジェクト: tharen/testing
 def test_variant_name(self, name, variant):
     f = fvs.FVS(variant)
     self.assertEqual(f.variant, variant, 'Variant name failed')
コード例 #7
0
ファイル: test_variants.py プロジェクト: tharen/testing
 def test_load_variant(self, name, variant):
     f = fvs.FVS(variant)
コード例 #8
0
def test_tree_data(variant, kwd_path, sum_path):
    try:
        f = fvs.FVS(variant)

    except ImportError:
        pytest.skip('No variant library: {}'.format(variant))
        return None

    except:
        raise

    print('**', kwd_path)
    f.init_projection(os.path.join(root, kwd_path))
    f.tree_data.live_tpa[:, :] = 0.0

    for c in range(f.contrl_mod.ncyc):
        r = f.grow_projection()

    r = f.end_projection()
    assert r == 0

    widths = [
        4, 4, 6, 4, 5, 4, 4, 5, 6, 6, 6, 6, 6, 6, 6, 4, 5, 4, 4, 5, 8, 5, 6, 8,
        4, 2, 1
    ]
    fldnames = ('year,age,tpa,baa,sdi,ccf,top_ht,qmd,total_cuft'
                ',merch_cuft,merch_bdft,rem_tpa,rem_total_cuft'
                ',rem_merch_cuft,rem_merch_bdft,res_baa,res_sdi'
                ',res_ccf,res_top_ht,resid_qmd,grow_years'
                ',annual_acc,annual_mort,mai_merch_cuft,for_type'
                ',size_class,stocking_class').split(',')

    # Read the sum file generated by the "official" FVS executable
    sum_check = pd.read_fwf(os.path.join(root, sum_path),
                            skiprows=0,
                            widths=widths)
    sum_check.columns = fldnames

    ncyc = f.contrl_mod.ncyc

    # TPA +/- 1
    tpa = np.round(np.sum(f.tree_data.live_tpa[:, :ncyc + 1], axis=0),
                   0).astype(int)
    check_tpa = sum_check.loc[:, 'tpa'].values
    assert np.all(np.isclose(check_tpa, tpa, atol=1))

    # BAA +/- 1
    tpa = f.tree_data.live_tpa[:, :ncyc + 1]
    dbh = f.tree_data.live_dbh[:, :ncyc + 1]

    baa = tpa * dbh * dbh * 0.005454154
    baa = np.round(np.sum(baa, axis=0), 0).astype(int)
    check_baa = sum_check.loc[:, 'baa'].values
    assert np.all(np.isclose(check_baa, baa, atol=1))

    # Total CuFt +/- 1
    tpa = f.tree_data.live_tpa[:, :ncyc + 1]
    cuft = f.tree_data.cuft_total[:, :ncyc + 1]
    tot_cuft = np.round(np.sum(tpa * cuft, axis=0), 0).astype(int)
    check_cuft = sum_check.loc[:, 'total_cuft'].values
    assert np.all(np.isclose(check_cuft, tot_cuft, atol=1))

    # Total BdFt +/- 1
    tpa = f.tree_data.live_tpa[:, :ncyc + 1]
    bdft = f.tree_data.bdft_net[:, :ncyc + 1]
    tot_bdft = np.round(np.sum(tpa * bdft, axis=0), 0).astype(int)
    check_bdft = sum_check.loc[:, 'merch_bdft'].values
    assert np.all(np.isclose(check_bdft, tot_bdft, atol=1))