### Quick Start WOFOST Simulation with PCSE Source: https://context7.com/ajwdewit/pcse/llms.txt Demonstrates how to start a pre-configured WOFOST simulation for winter-wheat in Spain using the PCSE framework. It shows how to run the simulation for a specific number of days, retrieve variables like Leaf Area Index (LAI), run until crop maturity, and export results to an Excel file. ```python import pcse import pandas as pd # Start WOFOST for winter-wheat in Spain for year 2000 # mode='pp' for potential production, 'wlp' for water-limited wofost = pcse.start_wofost(grid=31031, crop=1, year=2000, mode='wlp') # Run simulation for specific number of days wofost.run(days=10) # Get current value of Leaf Area Index lai = wofost.get_variable('LAI') print(f"Current LAI: {lai}") # Run until crop maturity or harvest wofost.run_till_terminate() # Retrieve daily simulation output as list of dicts output = wofost.get_output() df = pd.DataFrame(output) df.to_excel("wofost_results.xlsx") # Get summary results at end of crop cycle summary = wofost.get_summary_output() print(f"Maturity: {summary[0]['DOM']}, Yield: {summary[0]['TWSO']:.0f} kg/ha") # Output: Maturity: 2000-05-31, Yield: 7180 kg/ha ``` -------------------------------- ### Dispatching Crop Cycle Signals Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Examples of sending CROP_START and CROP_FINISH signals to manage the lifecycle of a crop simulation. ```python self._send_signal(signal=signals.crop_start, day=, crop_name=, variety_name=, crop_start_type=, crop_end_type=) self._send_signal(signal=signals.crop_finish, day=, finish_type=, crop_delete=) ``` -------------------------------- ### Import PCSE and Initialize Database Source: https://github.com/ajwdewit/pcse/blob/master/doc/installing.md This snippet demonstrates how to start a Python interpreter and import the PCSE package. This action also triggers the automatic creation or update of the PCSE demo database if it doesn't exist. ```doscon (py3_pcse) C:\>python Python 3.10.14 | packaged by conda-forge | (main, Mar 20 2024, 12:40:08) [MSC v.1938 64 bit (AMD64)] Type 'copyright', 'credits' or 'license' for more information >>> import pcse Building PCSE demo database at: C:\Users\wit015\.pcse\pcse.db ... OK >>> ``` -------------------------------- ### LINTUL3 Model Simulation in PCSE Source: https://context7.com/ajwdewit/pcse/llms.txt Illustrates how to set up and run the LINTUL3 crop simulation model using the PCSE framework. This example demonstrates reading model parameters from PCSE format files, weather data from an Excel file, and agromanagement details from a YAML file. It shows the initialization of the LINTUL3 model and running the simulation until crop termination, followed by extracting and printing key output variables like DVS, LAI, TAGBM, and WSO. ```python from pcse.models import LINTUL3 from pcse.base import ParameterProvider from pcse.input import PCSEFileReader, ExcelWeatherDataProvider, YAMLAgroManagementReader import pandas as pd # Read parameters from PCSE format files crop = PCSEFileReader("lintul3_springwheat.crop") soil = PCSEFileReader("lintul3_springwheat.soil") site = PCSEFileReader("lintul3_springwheat.site") params = ParameterProvider(cropdata=crop, soildata=soil, sitedata=site) # Read weather from Excel file weather = ExcelWeatherDataProvider("nl1.xlsx") # Read agromanagement with nitrogen application schedule agro = YAMLAgroManagementReader("lintul3_springwheat.yaml") # Initialize and run LINTUL3 lintul3 = LINTUL3(params, weather, agro) lintul3.run_till_terminate() # Convert output to pandas DataFrame output = lintul3.get_output() df = pd.DataFrame(output).set_index("day") # Key output variables: DVS, LAI, TAGBM (total biomass), WSO (storage organs) print(df[['DVS', 'LAI', 'TAGBM', 'WSO']].tail()) ``` -------------------------------- ### POST /signals/crop_start Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Triggers the start of a new crop cycle in the simulation. ```APIDOC ## POST /signals/crop_start ### Description Indicates that a new crop cycle will start. ### Method POST ### Endpoint /signals/crop_start ### Parameters #### Request Body - **day** (date) - Required - Current date - **crop_name** (string) - Required - Identifying the crop - **variety_name** (string) - Required - Identifying the crop variety - **crop_start_type** (string) - Required - Either 'sowing' or 'emergence' - **crop_end_type** (string) - Required - Either 'maturity', 'harvest' or 'earliest' ### Request Example { "day": "2023-01-01", "crop_name": "wheat", "variety_name": "winter", "crop_start_type": "sowing", "crop_end_type": "maturity" } ``` -------------------------------- ### Install PCSE via Pip Source: https://github.com/ajwdewit/pcse/blob/master/doc/installing.md Installs the PCSE package from the Python Package Index (PyPI). This is the standard method for users who want to use the library in their scripts without modifying the source code. ```doscon pip install pcse ``` -------------------------------- ### Execute Complete WOFOST Simulation Workflow Source: https://context7.com/ajwdewit/pcse/llms.txt A comprehensive example showing the full lifecycle of a simulation: loading crop/soil/weather data, initializing the WOFOST model, running the simulation, processing results into a DataFrame, and visualizing output with matplotlib. ```python import os import pcse import pandas as pd import matplotlib.pyplot as plt from pcse.models import Wofost72_WLP_CWB from pcse.base import ParameterProvider from pcse.input import CABOFileReader, WOFOST72SiteDataProvider, NASAPowerWeatherDataProvider, YAMLAgroManagementReader params = ParameterProvider(cropdata=CABOFileReader('wheat.crop'), soildata=CABOFileReader('clay.soil'), sitedata=WOFOST72SiteDataProvider(WAV=100)) weather = NASAPowerWeatherDataProvider(latitude=52.0, longitude=5.0) agro = YAMLAgroManagementReader('wheat_calendar.yaml') wofost = Wofost72_WLP_CWB(params, weather, agro) wofost.run_till_terminate() output = wofost.get_output() df = pd.DataFrame(output).set_index('day') summary = wofost.get_summary_output()[0] print(f"Grain yield: {summary['TWSO']:.0f} kg/ha") df[['LAI', 'TAGP']].plot(subplots=True) plt.savefig('wofost_results.png') ``` -------------------------------- ### Dispatching System and Output Signals Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Examples of sending signals for system termination and state output saving. ```python self._send_signal(signal=signals.terminate) self._send_signal(signal=signals.output) ``` -------------------------------- ### WOFOST Model Variants Initialization in PCSE Source: https://context7.com/ajwdewit/pcse/llms.txt Shows how to import and initialize different WOFOST model variants within the PCSE framework. It covers models for potential production (PP), water-limited production (WLP) with different water balance configurations, and nitrogen-limited production (NWLP). The example demonstrates initializing WOFOST 8.1 for nitrogen-limited production using parameters, weather data, and agromanagement configurations. ```python from pcse.models import ( Wofost72_PP, Wofost72_WLP_CWB, Wofost73_PP, Wofost73_WLP_CWB, Wofost73_WLP_MLWB, Wofost81_PP, Wofost81_WLP_CWB, Wofost81_WLP_MLWB, Wofost81_NWLP_CWB_CNB, Wofost81_NWLP_MLWB_SNOMIN ) # All models take the same parameters: # model = Model(parameterprovider, weatherdataprovider, agromanagement) # Example with WOFOST 8.1 nitrogen-limited production from pcse.base import ParameterProvider from pcse.input import NASAPowerWeatherDataProvider, YAMLAgroManagementReader params = ParameterProvider(cropdata=crop, soildata=soil, sitedata=site) weather = NASAPowerWeatherDataProvider(latitude=52.0, longitude=5.0) agro = YAMLAgroManagementReader("wheat_management.yaml") wofost = Wofost81_NWLP_CWB_CNB(params, weather, agro) wofost.run_till_terminate() ``` -------------------------------- ### GET /agromanagement/dates Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Retrieves the start and end dates for the agromanagement simulation sequence. ```APIDOC ## GET /agromanagement/dates ### Description Retrieves the start_date and end_date properties of the agromanagement sequence. The end date is determined either by a trailing empty campaign or calculated from the crop calendar and timed events. ### Method GET ### Endpoint /agromanagement/dates ### Response #### Success Response (200) - **start_date** (date) - The first simulation date. - **end_date** (date) - The last simulation date. #### Response Example { "start_date": "1999-08-01", "end_date": "2001-01-01" } ``` -------------------------------- ### POST /pcse/start_wofost Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Initializes a WOFOST simulation instance using the internal demo database. ```APIDOC ## POST /pcse/start_wofost ### Description Provides a convenient interface for starting a WOFOST instance for the internal Demo DB. If started with no arguments, the routine will connect to the demo database and initialize WOFOST for winter-wheat in Spain for the year 2000 in water-limited production mode. ### Method POST ### Endpoint /pcse/start_wofost ### Parameters #### Query Parameters - **grid** (int) - Optional - Grid number, defaults to 31031 - **crop** (int) - Optional - Crop number, defaults to 1 - **year** (int) - Optional - Year to start, defaults to 2000 - **mode** (string) - Optional - Production mode ('pp' or 'wlp'), defaults to 'wlp' ### Request Example { "grid": 31031, "crop": 1, "year": 2000, "mode": "wlp" } ### Response #### Success Response (200) - **wofsim** (object) - Returns a configured PCSE model instance (e.g., Wofost71_WLP_FD) ``` -------------------------------- ### Get Start Date of Cycle - Python Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Retrieves the start date of the current agricultural cycle. This method is part of a class that manages crop-related data and returns a stored 'crop_start_date' attribute. ```python def get_start_date(): """Returns the start date of the cycle. This is always self.crop_start_date""" pass ``` -------------------------------- ### Combine Parameter Sources with ParameterProvider Source: https://github.com/ajwdewit/pcse/blob/master/doc/reference_guide.md Demonstrates how to load crop parameters from a CABO file, soil parameters from a PCSE file, and site data from a SQLite database. These sources are then consolidated into a single ParameterProvider instance for unified access. ```python import os import sqlalchemy as sa from pcse.input import CABOFileReader, PCSEFileReader from pcse.base import ParameterProvider from pcse.db.pcse import fetch_sitedata import pcse.settings # Retrieve crop data from a CABO file cropfile = os.path.join(data_dir, 'sug0601.crop') crop = CABOFileReader(cropfile) # Retrieve soildata from a PCSE file soilfile = os.path.join(data_dir, 'lintul3_springwheat.soil') soil = PCSEFileReader(soilfile) # Retrieve site data from the PCSE demo DB db_location = os.path.join(pcse.settings.PCSE_USER_HOME, "pcse.db") db_engine = sa.create_engine("sqlite:///" + db_location) db_metadata = sa.MetaData(db_engine) site = fetch_sitedata(db_metadata, grid=31031, year=2000) # Combine everything into one ParameterProvider object and print some values params = ParameterProvider(sitedata=site, soildata=soil, cropdata=crop) print(params["AMAXTB"]) # maximum leaf assimilation rate print(params["DRATE"]) # maximum soil drainage rate print(params["WAV"]) # site-specific initial soil water amount ``` -------------------------------- ### Validate Campaign Dates - Python Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Validates the agricultural campaign dates, ensuring internal consistency and adherence to specified intervals. It takes the current campaign's start date and the next campaign's start date as input. ```python def validate(campaign_start_date, next_campaign_start_date): """Validate the crop calendar internally and against the interval for the agricultural campaign. Parameters: campaign_start_date – start date of this campaign next_campaign_start_date – start date of the next campaign """ pass ``` -------------------------------- ### Initialize PCSE and Run Internal Tests Source: https://github.com/ajwdewit/pcse/blob/master/doc/user_guide.md This snippet demonstrates how to import the PCSE package to trigger the automatic creation of the demo database and how to execute the internal test suite to verify component integrity. ```doscon >>> import pcse >>> pcse.test() ``` -------------------------------- ### Validate Timed Events - Python Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Validates the timed events configuration against the agricultural campaign's date range. It ensures that all scheduled events fall within the valid period, accepting the campaign start and next campaign start dates as parameters. ```python def validate(campaign_start_date, next_campaign_start_date): """Validates the timed events given the campaign window Parameters: campaign_start_date – Start date of the campaign next_campaign_start_date – Start date of the next campaign, can be None """ pass ``` -------------------------------- ### Initialize and Run WOFOST Simulation (Python) Source: https://github.com/ajwdewit/pcse/blob/master/doc/quickstart.md Illustrates the process of initializing and running a WOFOST crop simulation model. It involves importing a specific model configuration (e.g., Wofost72_WLP_CWB), providing parameters, weather data, and agromanagement information, then executing the simulation. ```python >>> from pcse.models import Wofost72_WLP_CWB >>> wofsim = Wofost72_WLP_CWB(parameters, wdp, agromanagement) >>> wofsim.run_till_terminate() >>> output = wofsim.get_output() >>> len(output) 294 ``` -------------------------------- ### Initialize and Run WOFOST Model Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Demonstrates how to initialize a WOFOST simulation instance using the start_wofost interface and execute a simulation run for a specified number of days. ```python import pcse wofsim = pcse.start_wofost(grid=31031, crop=1, year=2000, mode='wlp') wofsim.run(days=300) print(wofsim.get_variable('tagp')) ``` -------------------------------- ### GET /soil/nitrogen/parameters Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Retrieves the simulation parameters for the soil nitrogen dynamics module. ```APIDOC ## GET /soil/nitrogen/parameters ### Description Returns the current configuration parameters for soil nitrogen dynamics, including base supply and background deposition rates. ### Method GET ### Endpoint /soil/nitrogen/parameters ### Response #### Success Response (200) - **NSOILBASE** (float) - Base soil supply of N (kg ha-1) - **NSOILBASE_FR** (float) - Daily mineralization fraction - **NAVAILI** (float) - Initial N available (kg ha-1) - **BG_N_SUPPLY** (float) - Background N deposition (kg ha-1 day-1) #### Response Example { "NSOILBASE": 20.0, "NSOILBASE_FR": 0.01, "NAVAILI": 50.0, "BG_N_SUPPLY": 0.1 } ``` -------------------------------- ### PCSE Signal Definition and Usage Example in Python Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md This Python code demonstrates how to define, send, and receive signals within the PCSE framework. It includes a custom SimulationObject that connects to a signal, defines a handler for it, and sends signals with various argument configurations. The example highlights the use of `_connect_signal` and `_send_signal` methods. ```python import sys, os import math sys.path.append('/home/wit015/Sources/python/pcse/') import datetime as dt import pcse from pcse.base import SimulationObject, VariableKiosk mysignal = "My first signal" class MySimObj(SimulationObject): def initialize(self, day, kiosk): self._connect_signal(self.handle_mysignal, mysignal) def handle_mysignal(self, arg1, arg2): print "Value of arg1,2: %s, %s" % (arg1, arg2) def send_signal_with_exact_arguments(self): self._send_signal(signal=mysignal, arg2=math.pi, arg1=None) def send_signal_with_more_arguments(self): self._send_signal(signal=mysignal, arg2=math.pi, arg1=None, extra_arg="extra") def send_signal_with_missing_arguments(self): self._send_signal(signal=mysignal, arg2=math.pi, extra_arg="extra") # Create an instance of MySimObj day = dt.date(2000,1,1) k = VariableKiosk() mysimobj = MySimObj(day, k) # This sends exactly the right amount of keyword arguments mysimobj.send_signal_with_exact_arguments() # this sends an additional keyword argument 'extra_arg' which is ignored. mysimobj.send_signal_with_more_arguments() # this sends the signal with a missing 'arg1' keyword argument which the handler ``` -------------------------------- ### Initialize PCSE Environment and Load Parameters Source: https://github.com/ajwdewit/pcse/blob/master/doc/quickstart.md Imports necessary PCSE modules and sets up the data directory for file access. ```python import os import pcse import matplotlib.pyplot as plt data_dir = r'D:\userdata\pcse_examples' ``` -------------------------------- ### GET /input/agromanagement Source: https://github.com/ajwdewit/pcse/blob/master/doc/user_guide.md Reads and parses YAML-formatted agro-management files to define simulation calendars and events. ```APIDOC ## GET /input/agromanagement ### Description Parses a YAML file containing crop calendar information, including start/end dates and event definitions. ### Method GET ### Endpoint /input/agromanagement ### Parameters #### Query Parameters - **filepath** (string) - Required - The path to the .agro YAML file. ### Request Example { "filepath": "/data/sugarbeet_calendar.agro" } ### Response #### Success Response (200) - **agromanagement** (object) - A structured object containing the crop calendar and event schedule. ``` -------------------------------- ### GET /pcse/util/reference_ET Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Calculates reference evapotranspiration values (E0, ES0, ET0) based on meteorological inputs. ```APIDOC ## GET /pcse/util/reference_ET ### Description Calculates reference evapotranspiration values E0, ES0 and ET0. Open water (E0) and bare soil (ES0) are calculated with the modified Penman approach, while canopy evapotranspiration (ET0) uses Penman or Penman-Monteith. ### Method GET ### Endpoint /pcse/util/reference_ET ### Parameters #### Query Parameters - **DAY** (date) - Required - Python datetime.date object - **LAT** (float) - Required - Latitude in degrees - **ELEV** (float) - Required - Elevation in meters - **TMIN** (float) - Required - Minimum temperature in C - **TMAX** (float) - Required - Maximum temperature in C - **IRRAD** (float) - Required - Daily shortwave radiation in J m-2 d-1 - **VAP** (float) - Required - 24-hour average vapour pressure in hPa - **WIND** (float) - Required - 24-hour average windspeed at 2 meter in m/s - **ANGSTA** (float) - Required - Empirical constant in Angstrom formula - **ANGSTB** (float) - Required - Empirical constant in Angstrom formula - **ETMODEL** (string) - Optional - 'PM' (Penman-Monteith) or 'P' (Penman) ### Response #### Success Response (200) - **E0** (float) - Penman potential evaporation from a free water surface [mm/d] - **ES0** (float) - Penman potential evaporation from a moist bare soil surface [mm/d] - **ET0** (float) - Potential evapotranspiration from a crop canopy [mm/d] ``` -------------------------------- ### Initialize YAMLCropDataProvider (Default) Source: https://github.com/ajwdewit/pcse/blob/master/doc/reference_guide.md Demonstrates initializing the YAMLCropDataProvider without parameters, which defaults to loading crop parameters from the WOFOS_crop_parameters GitHub repository. It shows how to print the provider and its initial state. ```python >>> from pcse.input import YAMLCropDataProvider >>> p = YAMLCropDataProvider() >>> print(p) YAMLCropDataProvider - crop and variety not set: no activate crop parameter set! ``` -------------------------------- ### Initialize and Run LINTUL3 Model Source: https://github.com/ajwdewit/pcse/blob/master/doc/downloads/running_LINTUL3.ipynb Instantiates the LINTUL3 model with required parameters, weather data, and agromanagement, then executes the simulation until termination. ```python from pcse.models import LINTUL3 lintul3 = LINTUL3(parameterprovider, weatherdataprovider, agromanagement) lintul3.run_till_terminate() ``` -------------------------------- ### GET /input/cabo-file Source: https://github.com/ajwdewit/pcse/blob/master/doc/user_guide.md Reads parameter files in CABO format for crop or soil data using the CABOFileReader. ```APIDOC ## GET /input/cabo-file ### Description Reads a CABO-formatted file and returns a dictionary containing parameter name/value pairs. ### Method GET ### Endpoint /input/cabo-file ### Parameters #### Query Parameters - **filepath** (string) - Required - The absolute path to the .crop or .soil file. ### Request Example { "filepath": "/data/sug0601.crop" } ### Response #### Success Response (200) - **data** (object) - A dictionary of parameter names and their corresponding values. #### Response Example { "TSUM1": 700.0, "IDSL": 1, "LAIEM": 0.2 } ``` -------------------------------- ### Define and Initialize State Variables using StatesTemplate Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Demonstrates how to define a class inheriting from StatesTemplate to manage state variables, register them with a VariableKiosk, and handle initial values and publishing. ```python import pcse from pcse.base import VariableKiosk, StatesTemplate from pcse.traitlets import Float, Integer, Instance from datetime import date k = VariableKiosk() class StateVariables(StatesTemplate): StateA = Float() StateB = Integer() StateC = Instance(date) s1 = StateVariables(k, StateA=0., StateB=78, StateC=date(2003,7,3), publish="StateC") print(s1.StateA, s1.StateB, s1.StateC) print(k) ``` -------------------------------- ### Dispatching Agricultural Management Signals Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Examples of sending signals for fertilization, irrigation, and mowing events within the PCSE framework. ```python self._send_signal(signal=signals.apply_n, N_amount=, N_recovery) self._send_signal(signal=signals.apply_n_snomin, amount=, application_depth=, cnratio=, initial_age=, f_NH4N=, f_NO3N=, f_orgmat=) self._send_signal(signal=signals.irrigate, amount=, efficiency=) self._send_signal(signal=signals.mowing, biomass_remaining=) ``` -------------------------------- ### POST /agromanager/initialize Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Initializes the AgroManager with a kiosk and agromanagement definition. ```APIDOC ## POST /agromanager/initialize ### Description Initializes the AgroManager instance using a PCSE variable Kiosk and a YAML-formatted agromanagement definition. ### Method POST ### Endpoint /agromanager/initialize ### Request Body - **kiosk** (object) - Required - The PCSE variable Kiosk instance. - **agromanagement** (string) - Required - YAML formatted agromanagement definition. ### Request Example { "kiosk": "...", "agromanagement": "Version: 1.0\nAgroManagement:\n- 1999-08-01: ..." } ``` -------------------------------- ### Define Agromanagement with State Events Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Example of an agromanagement configuration containing state events, which requires a trailing empty campaign to determine the simulation end date. ```yaml Version: 1.0 AgroManagement: - 2001-01-01: CropCalendar: crop_name: maize variety_name: fodder-maize crop_start_date: 2001-04-15 crop_start_type: sowing crop_end_date: crop_end_type: maturity max_duration: 200 TimedEvents: StateEvents: - event_signal: apply_n event_state: DVS zero_condition: rising name: DVS-based N application table comment: all fertilizer amounts in kg/ha events_table: - 0.3: {N_amount : 1, N_recovery: 0.7} - 0.6: {N_amount: 11, N_recovery: 0.7} - 1.12: {N_amount: 21, N_recovery: 0.7} ``` -------------------------------- ### Initialize N_Crop_Dynamics Class Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Demonstrates how to instantiate the N_Crop_Dynamics class within the PCSE framework. This class handles the nitrogen bookkeeping logic for crop simulation models. ```python from pcse.crop.lingra_ndynamics import N_Crop_Dynamics # Initialize the nitrogen crop dynamics module n_dynamics = N_Crop_Dynamics(**kwargs) ``` -------------------------------- ### Define Agromanagement with Trailing Empty Campaign Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Example of a YAML configuration for agromanagement that explicitly defines the simulation end date using a trailing empty campaign. ```yaml Version: 1.0 AgroManagement: - 1999-08-01: CropCalendar: crop_name: winter-wheat variety_name: winter-wheat crop_start_date: 1999-09-15 crop_start_type: sowing crop_end_date: crop_end_type: maturity max_duration: 300 TimedEvents: StateEvents: - 2001-01-01: ``` -------------------------------- ### POST /input/site-data Source: https://github.com/ajwdewit/pcse/blob/master/doc/user_guide.md Initializes site-specific parameters such as initial water balance conditions and CO2 concentration. ```APIDOC ## POST /input/site-data ### Description Creates a site data provider object with default values, allowing overrides for specific parameters like initial water content (WAV). ### Method POST ### Endpoint /input/site-data ### Parameters #### Request Body - **WAV** (float) - Optional - Initial soil moisture content. - **SSI** (float) - Optional - Initial surface storage. ### Request Example { "WAV": 100.0, "SSI": 0.0 } ### Response #### Success Response (200) - **sitedata** (object) - The initialized site parameter dictionary. ``` -------------------------------- ### Define Site Parameters and Aggregate with ParameterProvider Source: https://github.com/ajwdewit/pcse/blob/master/doc/quickstart.md Configures site-specific parameters using WOFOST72SiteDataProvider and combines all parameter sets into a single ParameterProvider object. ```python from pcse.input import WOFOST72SiteDataProvider sitedata = WOFOST72SiteDataProvider(WAV=100) print(sitedata) from pcse.base import ParameterProvider parameters = ParameterProvider(cropdata=cropdata, soildata=soildata, sitedata=sitedata) ``` -------------------------------- ### Define Soil Profile YAML Configuration Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Example of a YAML configuration for a soil profile in PCSE, defining layer thicknesses, organic matter fractions, and physical properties. ```yaml CNRatioSOMI: 9.0 RHOD: 1.406 Soil_pH: 7.4 SoilID: SubSoil_10 SoilProfileDescription: PFWiltingPoint: 4.2 PFFieldCapacity: 2.0 SurfaceConductivity: 70.0 SoilLayers: - <<: *TopSoil Thickness: 10 FSOMI: 0.02 - <<: *SubSoil Thickness: 45 FSOMI: 0.00 GroundWater: null ``` -------------------------------- ### Initialize and Use PCSE Timer Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Demonstrates the initialization of the Timer class and how to retrieve the current simulation date. The timer manages daily increments and signals for output generation. ```python timer = Timer(start_date, kiosk, final_date, mconf) CurrentDate = timer() ``` -------------------------------- ### Define Agromanagement via Crop Calendar and Timed Events Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Example of an agromanagement configuration where the simulation end date is derived from the crop calendar and scheduled timed events. ```yaml Version: 1.0 AgroManagement: - 1999-09-01: CropCalendar: crop_name: wheat variety_name: winter-wheat crop_start_date: 1999-10-01 crop_start_type: sowing crop_end_date: 2000-08-05 crop_end_type: harvest max_duration: 330 TimedEvents: - event_signal: irrigate name: Timed irrigation events comment: All irrigation amounts in cm events_table: - 2000-05-01: {irrigation_amount: 2, efficiency: 0.7} - 2000-06-21: {irrigation_amount: 5, efficiency: 0.7} - 2000-07-18: {irrigation_amount: 3, efficiency: 0.7} StateEvents: ``` -------------------------------- ### Initialize and Run WOFOST Crop Model Source: https://github.com/ajwdewit/pcse/blob/master/doc/user_guide.md Initializes and runs the WOFOST crop simulation model for water-limited conditions using a classic waterbalance. It takes parameters, weather data, and agromanagement as input. The simulation results can be retrieved and analyzed. ```python from pcse.models import Wofost72_WLP_CWB wofsim = Wofost72_WLP_CWB(parameters, wdp, agromanagement) wofsim.run_till_terminate() output = wofsim.get_output() print(len(output)) ``` -------------------------------- ### PCSE Crop Models: Lingra10_PP Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Convenience class for running the LINGRA grassland model for potential production. This class simplifies the setup for simulating potential growth of grasslands. ```python class Lingra10_PP(**kwargs): """Convenience class for running the LINGRA grassland model for potential production. see pcse.engine.Engine for description of arguments and keywords """ pass ``` -------------------------------- ### Define PCSE Agromanagement in YAML Source: https://github.com/ajwdewit/pcse/blob/master/doc/quickstart.md An example of a YAML configuration file for PCSE agromanagement. It defines a crop calendar for spring wheat and specifies timed nitrogen application events. ```yaml Version: 1.0.0 AgroManagement: - 2006-01-01: CropCalendar: crop_name: wheat variety_name: spring-wheat crop_start_date: 2006-03-31 crop_start_type: emergence crop_end_date: 2006-08-20 crop_end_type: earliest max_duration: 300 TimedEvents: - event_signal: apply_n name: Nitrogen application table comment: All nitrogen amounts in g N m-2 events_table: - 2006-04-10: {amount: 10, recovery: 0.7} - 2006-05-05: {amount: 5, recovery: 0.7} StateEvents: null ``` -------------------------------- ### Set up PCSE/WOFOST with Custom Input Data Directory Source: https://github.com/ajwdewit/pcse/blob/master/doc/user_guide.md Imports necessary modules and defines a data directory for running PCSE/WOFOST simulations with custom input data, such as model parameters, driving variables (weather), and agromanagement actions. ```python import os import pcse import matplotlib.pyplot as plt data_dir = r'D:\\userdata\\pcse_examples' ``` -------------------------------- ### Initialize PCSE Simulation Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Initializes a PCSE simulation instance. It requires the start date of the simulation (day), the kiosk object for variable management, and a ParameterProvider object containing simulation parameters. ```python initialize(day, kiosk, parvalues) ``` -------------------------------- ### LINTUL3 Crop Model Initialization Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Initializes the LINTUL3 crop model with various parameters related to development, nitrogen dynamics, and light interception. ```APIDOC ## LINTUL3 Crop Model Initialization ### Description Initializes the LINTUL3 crop model with parameters governing crop development, nitrogen dynamics, and light interception. ### Method POST ### Endpoint /ajwdewit/pcse/crop/lintul3/Lintul3 ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **DVSI** (float) - Required - Initial development stage. - **DVSDR** (float) - Required - Development stage above which deathOfLeaves of leaves and roots start. - **DVSNLT** (float) - Required - Development stage after which no nutrients are absorbed. - **DVSNT** (float) - Required - Development stage above which N translocation to storage organs does occur. - **FNTRT** (float) - Required - Nitrogen translocation from roots to storage organs as a fraction of total amount of nitrogen translocated from leaves and stem to storage organs. - **FRNX** (float) - Required - Critical N, as a fraction of maximum N concentration. - **K** (float) - Required - Light attenuation coefficient. - **LAICR** (float) - Required - Critical LAI above which mutual shading of leaves occurs. - **LRNR** (float) - Required - Maximum N concentration of root as fraction of that of leaves. - **LSNR** (float) - Required - Maximum N concentration of stem as fraction of that of leaves. ### Request Example ```json { "DVSI": 0.1, "DVSDR": 1.5, "DVSNLT": 2.0, "DVSNT": 2.5, "FNTRT": 0.5, "FRNX": 0.7, "K": 0.4, "LAICR": 3.0, "LRNR": 0.5, "LSNR": 0.8 } ``` ### Response #### Success Response (200) - **model_status** (string) - Indicates the status of the LINTUL3 model initialization. #### Response Example ```json { "model_status": "initialized" } ``` ``` -------------------------------- ### Define Parameters using ParamTemplate Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Demonstrates how to subclass ParamTemplate to define model parameters. It shows how to initialize parameters with a dictionary and how the class enforces the presence of required parameters. ```python from pcse.base import ParamTemplate from pcse.traitlets import Float class Parameters(ParamTemplate): A = Float() B = Float() C = Float() parvalues = {"A" :1., "B" :-99, "C":2.45} params = Parameters(parvalues) print(params.A) ``` -------------------------------- ### Get End Date of Timed Event - Python Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Retrieves the last date for which a timed event is registered within the system. This is useful for determining the operational window of specific timed agricultural actions. ```python def get_end_date(): """Returns the last date for which a timed event is given""" pass ``` -------------------------------- ### PCSE Crop Models: Wofost72_PP Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Convenience class for running WOFOST7.2 Potential Production. This class simplifies the setup for simulating potential crop growth using the WOFOST model version 7.2. ```python class Wofost72_PP(**kwargs): """Convenience class for running WOFOST7.2 Potential Production. see pcse.engine.Engine for description of arguments and keywords """ pass ``` -------------------------------- ### Implement Custom WeatherDataProvider Source: https://github.com/ajwdewit/pcse/blob/master/doc/code.md Shows how to create a custom weather data provider by subclassing WeatherDataProvider. This includes setting class variables like supports_ensembles to enable specific features. ```python from pcse.base import WeatherDataProvider class MyWeatherDataProviderWithEnsembles(WeatherDataProvider): supports_ensembles = True def __init__(self): WeatherDataProvider.__init__(self) ```