def extract(my_path_folder,file, my_start_month, my_start_day, my_end_month, my_end_day):
    my_extraction=DaisyDlf(my_path_folder+'\\'+'%s.dlf' %file)
    my_extraction=my_extraction.Data
    years=np.unique([my_extraction.index[i].year for i in range(len(my_extraction.index))])
    my_extraction['Date']=my_extraction.index
    my_extraction.index=np.arange(0,len(my_extraction))
    my_start, my_end = [], []
    for i in range(len(years)-1):
        my_start.append(my_extraction['Date'][my_extraction['Date'] == datetime.strptime('%0d-%02d-%02d 00:00:00'%(years[i+1], my_start_month, my_start_day), "%Y-%m-%d %H:%M:%S")].index[0])
        my_end.append(my_extraction['Date'][my_extraction['Date'] == datetime.strptime('%0d-%02d-%02d 00:00:00'%(years[i+1], my_end_month, my_end_day), "%Y-%m-%d %H:%M:%S")].index[0])            
    return my_extraction, my_start, my_end
Esempio n. 2
0
def get_allYields(path):
    items = os.walk(path)
    allresults = {}

    for root, dirs, filenames in items:
        for d in dirs:
            cropyield = {}
            if os.path.isfile(os.path.join(root, d, "harvest.dlf")):
                harvest = DaisyDlf(os.path.join(root, d, "harvest.dlf"))
                df = harvest.Data
                DMharv = df[['crop', 'leaf_DM', 'stem_DM', 'sorg_DM']]
                DMS = DMharv.groupby('crop')
                for cropname in silo:
                    if cropname in DMS.groups.keys():
                        rg = DMS.get_group(cropname).sum(axis=1)
                        cropyield[cropname] = list(rg.resample('Y').sum())

                DMharvG = df[['crop', 'sorg_DM']]
                DMG = DMharvG.groupby('crop')

                for cropname in grain:
                    if cropname in DMG.groups.keys():
                        gr = DMG.get_group(cropname).sum(axis=1)
                        cropyield[cropname] = list(gr.resample('Y').sum())
                allresults[d] = cropyield
        #average = round(v[v!=0].mean(), 2)
        #result.append({k:average})
        return (allresults)
Esempio n. 3
0
def getSOMspinup(path):

    #path=r'../RunSpinup5'

    MotherFolder = path  #r'..\RunSpinup5'
    items = os.walk(MotherFolder)
    index = 1
    init = {}
    for root, dirs, filenames in items:
        for d in dirs:
            C_inital = DaisyDlf(os.path.join(root, d, "SC100-M.dlf"))
            initialValues = {}
            df = C_inital.Data
            diff_years = relativedelta(df.index[len(df) - 1],
                                       df.index[0]).years + 1
            #print(diff_years)
            inputC = int(
                (df['Residuals_C_top'].sum(axis=0) +
                 df['Residuals_C_root'].sum(axis=0) + df['Fertilizer_C'].sum(
                     axis=0) - df['Bioinc_C-Soil'].sum(axis=0)) / diff_years)
            roots = int(df['Residuals_C_root'].sum(axis=0) / diff_years)
            fertilizerC = int(df['Fertilizer_C'].sum(axis=0) / diff_years)
            initialValues = [inputC, roots, fertilizerC]
            init[d] = initialValues

        return init
Esempio n. 4
0
def extract(crop_name, filnavn, output):
    harvest=DaisyDlf(filnavn)
    df=harvest.Data
    # summere og plot af udbytte i tørstof DM       
    harv= df[['crop', 'leaf_'+output, 'stem_'+output,'sorg_'+output]]
    DMG =harv.groupby('crop')
    rg = DMG.get_group(crop_name).sum(axis=1)
    return(rg)
def extract(crop_name, filnavn, output): # output altid være N?
    harvest=DaisyDlf(filnavn)
    df=harvest.Data
    # summere og plot af udbytte i tørstof DM       
    harv_grain = df[['crop', 'sorg_'+output]]
    harv_grass = df[['crop', 'leaf_'+output, 'stem_'+output,'sorg_'+output]]
    grain =harv_grain.groupby('crop')
    cereal = grain.get_group(crop_name).sum(axis=1)
    return(cereal)
Esempio n. 6
0
def get_allSOM(path):
    items = os.walk(path)
    allSOMresults = {}

    for root, dirs, filenames in items:
        for d in dirs:
            cropyield = {}
            if os.path.isfile(os.path.join(root, d, "Annual-OM.dlf")):
                anOM = DaisyDlf(os.path.join(root, d, "Annual-OM.dlf"))
                df = anOM.Data
                filter_colC = [col for col in df if col.endswith('-C')]
                SOC_col = df[filter_colC].sum(axis=1)
                dSOC = round((SOC_col[len(SOC_col) - 1] - SOC_col[1]) /
                             (len(SOC_col) - 1), 2)
                filter_colN = [col for col in df if col.endswith('-N')]
                SON_col = df[filter_colN].sum(axis=1)
                dSON = round((SON_col[len(SON_col) - 1] - SON_col[1]) /
                             (len(SON_col) - 1), 2)
                allSOMresults[d] = [dSON]

        return (allSOMresults)
Esempio n. 7
0
    str) + '_' + xl['field']


def rmse(pred, obs):
    return np.sqrt(((pred - obs)**2).mean())


MotherFolder = '..\RunDaisy16opt'
items = os.walk(MotherFolder)
index = 1
fig = plt.figure(figsize=(15, 10))

for root, dirs, filenames in items:
    for d in dirs:
        print(d)
        harvest = DaisyDlf(os.path.join(root, d, "DailyP-harvest.dlf"))
        df = harvest.Data
        # summere og plot af udbytte i tørstof DM
        DMharv = df[['crop', 'leaf_DM', 'stem_DM', 'sorg_DM']]
        DMG = DMharv.groupby('crop')
        rg = DMG.get_group('Ryegrass').sum(axis=1)
        wc = DMG.get_group('Wclover').sum(axis=1)
        # Laver et subplot, som derefter bliver det aktive som de næste plt virker på
        ax = plt.subplot(3, 4, index)
        index += 1
        df22 = pd.DataFrame([rg, wc]).T
        df22.columns = ['Ryegrass', 'Wclover']
        df22['sim-totalDM'] = df22['Ryegrass'] + df22['Wclover']
        df2 = df22.loc['2006-1-1':'2011-1-1', :]
        s1 = xl.loc[xl['id'] == d]
        meas = (s1.groupby(s1.index)['grassDM'].mean(),
Esempio n. 8
0
            for depth in ['OLOH', 'ILD00', 'ILD08', 'ILD16', 'IHD00', 'IHD08']:
                print(threshold, space, col, depth)
                # store the yearly load of pesticides and water
                yearly_leaching_sources, yearly_wflow_sources = defaultdict(
                    list), defaultdict(list)
                # find simulated data in corresponding folder
                for my_start_year, folder in enumerate(
                        sensitivity_analysis['%d' % threshold + '_' +
                                             '%d' % space]):

                    print('extraction from folder nb:', my_start_year)
                    # store the pesticide outputs from Daisy
                    field_chemicals = defaultdict()
                    for chem in chemicals:
                        field_chemicals[chem] = DaisyDlf(
                            path_folder + '\\' + folder + '\\' +
                            '%s-%s_%s_field_%s.dlf' %
                            (prefix, depth, col, chem)).Data
                        field_chemicals[chem]['Date'] = field_chemicals[
                            chem].index
                        field_chemicals[chem].index = np.arange(
                            0, len(field_chemicals[chem]))

                    # use the harvest file to select find starting and ending
                    # index of 3-month monitoring period each year
                    harvest = DaisyDlf(path_folder + '\\' + folder + '\\' +
                                       '%s-harvest.dlf' % prefix)
                    harvest = harvest.Data
                    harvest['Date'] = harvest.index
                    harvest.index = np.arange(0, len(harvest))
                    start_harvest = (np.where(
                        harvest['Date'] == datetime.strptime(
Esempio n. 9
0
sys.path.append(r'..\..\..\.')

from pydaisy.Daisy import *

# Plot tørstofsudbytte for kløver, græs og samlet i søjlediagram

MotherFolder = '..\RunDaisy1'
items = os.walk(MotherFolder)

index = 1
fig = plt.figure(figsize=(15, 8))
#fig, axes = plt.subplots(nrows=2, ncols=3)
for root, dirs, filenames in items:
    for d in dirs:
        print(d)
        harvest = DaisyDlf(os.path.join(root, d, "DailyP-Ryegrass.dlf"))
        df = harvest.Data
        # summere og plot af udbytte i tørstof DM
        Nharv = df[['crop', 'leaf_N', 'stem_N', 'sorg_N']]
        N = Nharv.groupby('crop')
        rg = DMG.get_group('Ryegrass').sum(axis=1)
        wc = DMG.get_group('Wclover').sum(axis=1)
        Nrg = N.get_group('Ryegrass').sum(axis=1)
        Nwc = N.get_group('Wclover').sum(axis=1)
        # Laver et subplot, som derefter bliver det aktive som de næste plt virker på
        ax = plt.subplot(4, 3, index)
        index += 1
        df22 = pd.DataFrame([rg, wc]).T
        df22.columns = ['Ryegrass', 'Wclover']
        df2 = df22.loc['2006-1-1':'2011-1-1', :]
        df2.index = df2.index.strftime("%Y-%m")
Esempio n. 10
0
from pydaisy.Daisy import *

xl = pd.read_excel(r'..\Meas_yields.xlsx', 'data')
xl.set_index('date', inplace=True)
xl['id'] = 'T'+xl['treatment'].map(str)+'_S'+xl['block'].map(str)+'_'+xl['field']

MotherFolder='..\RunDaisy2.1'
items = os.walk(MotherFolder)
index=1
fig = plt.figure(figsize=(15, 8))
#fig, axes = plt.subplots(nrows=2, ncols=3)
for root, dirs, filenames in items:
    for d in dirs:
        print(d)
        harvestR=DaisyDlf(os.path.join(root, d, "DailyP-Ryegrass.dlf"))
        harvestW=DaisyDlf(os.path.join(root, d, "DailyP-Wclover.dlf"))
        rg=harvestR.Data.loc['2006-1-1':'2011-1-1',:]
        wc=harvestW.Data.loc['2006-1-1':'2011-1-1',:]
        rg['Ntot'] = ['NLeaf']+rg['NDead']+rg['NStem']+rg['NSOrg']
        wc['Ntot'] = wc['NLeaf']+wc['NStem']+wc['NSOrg']
        wc['Nfix'] = wc['Fixated']
        ax=plt.subplot(4,3,index)
        index+=1
        plt.plot(rg.index, (rg['Ntot']),  c='black', label= 'grass')
        plt.plot(wc.index, (wc['Ntot']), c='red', label = 'clover_Ntot')
        plt.plot(wc.index, (wc['Nfix']), c='green', label = 'clover_Nfix')
        plt.legend()
        plt.title(d, position = (0.6, 0.8), fontweight="bold", fontsize=10)
        ax.set(ylabel=('kg N /ha'))
        plt.show()