示例#1
0
def test_ofe():
    """Read an OFE please"""
    df = dep.read_ofe(get_path('ofe.txt'))
    assert abs(df['precip'].max() - 107.56) < 0.01

    df = dep.read_ofe(get_path('ofe2.txt'))
    print(df['sedleave'].sum())
    assert abs(df['sedleave'].sum() - 400257.48) < 0.01
示例#2
0
    def test_ofe(self):
        """Read an OFE please"""
        df = dep.read_ofe(get_path('ofe.txt'))
        self.assertAlmostEquals(df['precip'].max(), 107.56, 2)

        df = dep.read_ofe(get_path('ofe2.txt'))
        print(df['sedleave'].sum())
        self.assertAlmostEquals(df['sedleave'].sum(), 400257.48, 2)
示例#3
0
文件: test_dep.py 项目: xoxo143/pyIEM
def test_ofe():
    """Read an OFE please"""
    df = dep.read_ofe(get_path("ofe.txt"))
    assert abs(df["precip"].max() - 107.56) < 0.01

    df = dep.read_ofe(get_path("ofe2.txt"))
    print(df["sedleave"].sum())
    assert abs(df["sedleave"].sum() - 400257.48) < 0.01
示例#4
0
文件: test_dep.py 项目: akrherz/pyIEM
def test_ofe():
    """Read an OFE please"""
    df = dep.read_ofe(get_path('ofe.txt'))
    assert abs(df['precip'].max() - 107.56) < 0.01

    df = dep.read_ofe(get_path('ofe2.txt'))
    print(df['sedleave'].sum())
    assert abs(df['sedleave'].sum() - 400257.48) < 0.01
示例#5
0
def main():
    """Go Main Go"""
    # 272m slope length?  database says 200m, prj has 266m and 6m
    ofe = read_ofe("/i/0/ofe/07040006/0203/070400060203_213.ofe")
    print("OFETOT %s" % (ofe["sedleave"].sum(), ))
    print("1 %s" % (ofe[ofe["ofe"] == 1]["sedleave"].sum(), ))
    print("2 %s" % (ofe[ofe["ofe"] == 2]["sedleave"].sum(), ))
    env = read_env("/i/0/env/07040006/0203/070400060203_213.env")
    print(env["sed_del"].sum())
示例#6
0
def main():
    """Go Main Go"""
    # 272m slope length?  database says 200m, prj has 266m and 6m
    ofe = read_ofe('/i/0/ofe/07040006/0203/070400060203_213.ofe')
    print("OFETOT %s" % (ofe['sedleave'].sum(), ))
    print("1 %s" % (ofe[ofe['ofe'] == 1]['sedleave'].sum(), ))
    print("2 %s" % (ofe[ofe['ofe'] == 2]['sedleave'].sum(), ))
    env = read_env('/i/0/env/07040006/0203/070400060203_213.env')
    print(env['sed_del'].sum())
示例#7
0
def main():
    """Go Main Go"""
    # ['id', 'CropRotationString', 'slope',
    #                           'rainfall', 'runoff', 'detach', 'delivery'])
    rows = []
    for root, _dirs, files in tqdm(os.walk("/i/0/ofe")):
        for filename in files:
            ofedf = read_ofe("%s/%s" % (root, filename))
            # Drop any 2007 or 2018+ data
            ofedf = ofedf[(ofedf['date'] < datetime.date(2018, 1, 1))
                          & (ofedf['date'] >= datetime.date(2008, 1, 1))]
            # Figure out the crop string
            man = "%s/%s" % (root.replace(
                "ofe", "man"), filename.replace("ofe", "man"))
            try:
                manres = read_man(man)
            except Exception as exp:
                print("failure reading %s\n%s" % (man, exp))
                continue

            slp = "%s/%s" % (root.replace(
                "ofe", "slp"), filename.replace("ofe", "slp"))
            slpres = read_slp(slp)
            soils = get_soils(slp.replace('slp', 'prj'))
            for ofe in ofedf['ofe'].unique():
                myofe = ofedf[ofedf['ofe'] == ofe]
                length = slpres[ofe - 1]['x'][-1] - slpres[ofe - 1]['x'][0]
                slp = ((slpres[ofe - 1]['y'][0] - slpres[ofe - 1]['y'][-1]) /
                       length)
                rows.append({
                    'id':
                    "%s_%s" % (filename[:-4], ofe),
                    'huc12':
                    filename[:12],
                    'fpath':
                    filename.split("_")[1][:-4],
                    'ofe':
                    ofe,
                    'CropRotationString': (get_rotation_string(manres, ofe)),
                    'slope[1]':
                    slp,
                    'soil_mukey':
                    soils[ofe - 1],
                    'rainfall':
                    -1,
                    'runoff[mm/yr]':
                    myofe['runoff'].sum() / YEARS,
                    'detach':
                    -1,
                    'length[m]':
                    length,
                    'delivery[t/a/yr]':
                    (myofe['sedleave'].sum() / YEARS / length * 4.463)
                })

    df = pd.DataFrame(rows)
    df.to_csv('results.csv', index=False)
示例#8
0
def main():
    """Go Main Go"""
    # ['id', 'CropRotationString', 'slope',
    #                           'rainfall', 'runoff', 'detach', 'delivery'])
    rows = []
    for root, _dirs, files in tqdm(os.walk("/i/0/ofe")):
        for filename in files:
            ofedf = read_ofe("%s/%s" % (root, filename))
            # Drop any 2007 or 2018+ data
            ofedf = ofedf[(ofedf['date'] < datetime.date(2018, 1, 1)) &
                          (ofedf['date'] >= datetime.date(2008, 1, 1))]
            # Figure out the crop string
            man = "%s/%s" % (root.replace("ofe", "man"),
                             filename.replace("ofe", "man"))
            try:
                manres = read_man(man)
            except Exception as exp:
                print("failure reading %s\n%s" % (man, exp))
                continue

            slp = "%s/%s" % (root.replace("ofe", "slp"),
                             filename.replace("ofe", "slp"))
            slpres = read_slp(slp)
            soils = get_soils(slp.replace('slp', 'prj'))
            for ofe in ofedf['ofe'].unique():
                myofe = ofedf[ofedf['ofe'] == ofe]
                length = slpres[ofe - 1]['x'][-1] - slpres[ofe - 1]['x'][0]
                slp = ((slpres[ofe - 1]['y'][0] - slpres[ofe - 1]['y'][-1]) /
                       length)
                rows.append({
                    'id': "%s_%s" % (filename[:-4], ofe),
                    'huc12': filename[:12],
                    'fpath': filename.split("_")[1][:-4],
                    'ofe': ofe,
                    'CropRotationString': (
                        get_rotation_string(manres, ofe)),
                    'slope[1]': slp,
                    'soil_mukey': soils[ofe - 1],
                    'rainfall': -1,
                    'runoff[mm/yr]': myofe['runoff'].sum() / YEARS,
                    'detach': -1,
                    'length[m]': length,
                    'delivery[t/a/yr]': (
                        myofe['sedleave'].sum() / YEARS / length * 4.463)
                    })

    df = pd.DataFrame(rows)
    df.to_csv('results.csv', index=False)