daquinterop / Py_DSSATTools

A Python library for crop modeling using DSSAT
GNU General Public License v3.0
54 stars 19 forks source link

How to set the fertilization table #21

Closed agronomofiorentini closed 1 year ago

agronomofiorentini commented 1 year ago

Dear Creator, First of all I want to thank you for developing this library, it is really very well done.

I report below a fully reproducible example that allows you to understand my problem in this regard in manually setting the fertilization table

from DSSATTools import (
    Crop, 
    SoilProfile, 
    Weather, 
    Management, 
    DSSAT, 
    SoilLayer,
    available_cultivars
)
import pandas as pd
from datetime import datetime
from pynasapower.get_data import query_power
from pynasapower.geometry import point, bbox
import datetime
from matplotlib import pyplot as plt

gpoint = point(13.390599, 43.611384, "EPSG:4326")

start = datetime.date(2023, 1, 1)

end = datetime.date(2023, 11, 10)

data = query_power(geometry = gpoint, 
                   start = start, 
                   end = end, 
                   to_file = False, 
                   community = "ag", 
                   parameters = ["TOA_SW_DWN", 
                                 "T2M_MIN", 
                                 "T2M_MAX", 
                                 "PRECTOTCORR",
                                 "T2MDEW", 
                                 "WS2M",
                                 "ALLSKY_SFC_PAR_TOT",
                                 #"EVAP",
                                 "RH2M"], 
                   temporal_api = "daily", 
                   spatial_api = "point")

data['DATE'] = data['YEAR'].astype(str) + data['DOY'].astype(str)

# Convert the 'Date' column to a datetime format
data['DATE'] = pd.to_datetime(data['DATE'], format='%Y%j')

# If you want to keep only the date part and drop the time part
data['DATE'] = data['DATE'].dt.date

data = pd.DataFrame(data, columns=['YEAR','DOY','DATE','TOA_SW_DWN','T2M_MIN','T2M_MAX','PRECTOTCORR','T2MDEW','WS2M','ALLSKY_SFC_PAR_TOT','RH2M'])
data['DATE'] = pd.to_datetime(data['DATE'])
data.set_index('DATE', inplace=True)

wth = Weather(df=data, 
              pars={'TOA_SW_DWN':'SRAD',
                    'T2M_MAX':'TMAX',
                    'T2M_MIN':'TMIN',
                    'PRECTOTCORR':'RAIN',
                    'T2MDEW':'DEWP',
                    'WS2M':'WIND',
                    'ALLSKY_SFC_PAR_TOT':'PAR',
                    'RH2M':'RHUM'}, 
              lat=23.727539, 
              lon=37.983810, 
              elev=100)

soil = SoilProfile(default_class='C')

crop = Crop(crop_name="sunflower", 
            cultivar_code="IB0018")

man = Management(planting_date=data.index[120],
                 emergence_date=data.index[130],
                 irrigation="A",
                 fertilization="R",
                 harvest="M",
                 organic_matter="G")

Now it will start the issue that i am facing.

I don't know how to set two different fertilization like at data.index[150] i would like to provide 100 of N and 200 P at data.index[190] i would like to provide 200 of N and 100 P

Can you show me how to set it? Thanks

agronomofiorentini commented 1 year ago

I have found the way to do so.

Anyway great library


schedule = pd.DataFrame([
    (date1, "FE001", "AP001", 20, 300, 300, 300, 0,0,  None, None),
    (date2, "FE001", "AP001", 20, 100, 100, 150, 0,0, None, None),
], columns = ['FDATE', 'FMCD', 'FACD', 'FDEP', 'FAMN', 'FAMP', 'FAMK', 'FAMC', 'FAMO', 'FOCD', "FERNAME"])

man.fertilizers['table'] = TabularSubsection(schedule)

dssat = DSSAT()
dssat.setup()
dssat.run(soil=soil, weather=wth, crop=crop, management=man)
dssat.close()