dpest package
Subpackages
Submodules
dpest. setup module
dpest.functions module
- dpest.functions.adjust_days_dict(days_dict)[source]
Adjusts the days dictionary to calculate differences between consecutive days.
Parameters: days_dict (dict): Dictionary mapping DOY to a list with days and variable names.
Returns: dict: Adjusted days dictionary with differences calculated and variable names preserved.
- dpest.functions.calculate_days_dict(dates_dict, date_first_sim)[source]
Calculates a dictionary of days from the first simulation date to each date in the dictionary.
Parameters: dates_dict (dict): Dictionary mapping DOY values to variable names. date_first_sim (datetime): The first simulation date.
Returns: dict: A dictionary mapping each date to its adjusted day count.
- dpest.functions.extract_all_params(*parameter_dicts)[source]
Extract all parameters from one or more dictionaries.
- dpest.functions.extract_element_positions(line)[source]
Extracts the first and last character positions of each element in a single line, including spaces between elements.
- Args:
line (str): The text line to process.
- Returns:
list of tuples: A list where each tuple contains the start and end positions of an element.
- dpest.functions.extract_simulation_data(file_path)[source]
Extracts simulation data for each cultivar, including the experiment information, and returns a DataFrame with all the data.
Parameters: file_path (str): The path to the text file containing the growth aspects data.
Returns: pd.DataFrame: A DataFrame containing the parsed data for all cultivars, including the experiment info.
- dpest.functions.extract_treatment_info_plantgrowth(file_path, treatment_dict)[source]
Extracts treatment information and their corresponding codes from a file.
- Args:
file_path (str): Path to the input file. treatment_dict (dict): A dictionary with treatment names as keys and their line ranges as values.
- Returns:
dict: A dictionary where keys are treatment names and values are treatment codes.
- dpest.functions.filter_dataframe(dataframe, treatment, treatment_number_name, variables)[source]
Filters a DataFrame based on the treatment and returns a dictionary of DATE and variables where values are not -99.
Parameters: dataframe (pd.DataFrame): Input DataFrame. treatment (str): Treatment name to filter by. treatment_number_name (dict): Mapping of treatments to their corresponding TRNO values. variables (list): List of variable names to check in the dataset.
Returns: dict: A dictionary containing filtered data with DATE as keys and variables as values.
- dpest.functions.find_cultivar(file_content, head_line, cultivar, cultivar_cul_file)[source]
Find the line containing the specified cultivar in the DSSAT cultivar file.
Args: file_content (str): The content of the DSSAT cultivar file. cultivar (str): The cultivar to search for (VAR# or VAR-NAME).
Returns: int: The line number containing the cultivar if found, or a message if not found.
- dpest.functions.find_ecotype(file_content, head_line, ecotype, ecotype_file)[source]
Find the line containing the specified ecotype in the DSSAT ecotype file.
Args: file_content (str): The content of the DSSAT ecotype file. head_line (str): The line that starts the header of the ecotype table. ecotype (str): The ecotype to search for (ECO#). ecotype_file (str): The name of the ecotype file.
Returns: int: The line number containing the ecotype if found, or a message if not found.
- dpest.functions.find_parameter_position(line, parameter=None)[source]
Extracts the first and last character positions of each element in a single line, including spaces between elements. If a specific parameter is provided, returns its start and end positions.
- Args:
line (str): The text line to process. parameter (str, optional): The element to search for. Defaults to None.
- Returns:
- list of tuples or list: A list of start and end positions for all elements,
or the start and end positions of the specific parameter if provided.
- dpest.functions.find_variable_position(header_line, variables)[source]
Counts space groups until the specified variables. Count starts at 1.
Arguments: header_line (str): The header line containing variable names. variables (list): A list of variable names to find.
Returns: dict: A dictionary with variables as keys and their positions as values.
- dpest.functions.get_header_and_first_sim(file_path)[source]
Reads the header line and the first simulation date from the PlantGro.OUT file.
Parameters: file_path (str): The path to the PlantGro.OUT file.
Returns: tuple: A header line and the first simulation date as a datetime object.
- dpest.functions.process_treatment_file(file_path, treatment_mapping, season_mapping)[source]
Reads the treatment file, extracts the treatment data, and adds ‘treatment’ and ‘season’ columns.
Parameters: - file_path: Path to the treatment file. - treatment_mapping: A dictionary for mapping treatment codes (e.g., ‘WW’ to ‘Well-watered’). - season_mapping: A dictionary for mapping season codes (e.g., ‘22’ to ‘Winter 2021-2022’).
Returns: - DataFrame with ‘N’, ‘TNAME’, ‘CU’, ‘treatment’, and ‘season’ columns.
- dpest.functions.read_growth_file(file_path, treatment_range)[source]
Reads a growth aspects output file and converts it into a pandas DataFrame.
Arguments: file_path (str): The path to the text file containing the growth aspects data. treatment_range (tuple): A tuple containing the start and end line numbers for the treatment data.
Returns: pd.DataFrame: A DataFrame containing the parsed data.
- dpest.functions.simulations_lines(file_path)[source]
Identifies and extracts the line ranges associated with specific treatments in the OVERVIEW output file.
Parameters: file_path (str): The path to the text file containing tOVERVIEW output file.
Returns: dict: A dictionary where the keys are TREATMENT names and the values are
tuples containing the start and end line numbers.
- dpest.functions.validate_file(file_path, file_extension)[source]
Validates that the input file path exists and the file extension is correct.
- dpest.functions.validate_marker(marker, marker_name)[source]
Validate the marker delimiter for the INS files according to the specified rules.
dpest.pst module
- dpest.pst.pst(cultivar_parameters=None, ecotype_parameters=None, dataframe_observations=None, output_path=None, model_comand_line=None, noptmax=1000, pst_filename='PEST_CONTROL.pst', input_output_file_pairs=None)[source]
Create and update a PEST control file (PST) for CERES wheat model calibration.
- Args:
bounds, and groupings. It should include:
- cultivar_parameters (dict): Dictionary containing model parameters with their values,
‘cultivar_parameters’: Current parameter values for the specified cultivar.
‘minima_parameters’: Minima values for all parameters.
‘maxima_parameters’: Maxima values for all parameters.
‘parameters_grouped’: Grouping of parameters.
- dataframe_observations (pd.DataFrame or list): DataFrame or list of DataFrames containing observations to include in the PST file.
Each DataFrame must include columns: ‘variable_name’, ‘value_measured’, and ‘group’
output_path (str): Directory to save the PST file. Defaults to the current working directory if not provided. model_comand_line (str): Command line for running the model executable. noptmax (int): Maximum number of iterations for the optimization process. Default is 1000. pst_filename (str): The name of the PST file to create or update. Default is ‘pest_control_ceres_wheat.pst’. input_output_file_pairs (list): List of tuples where each tuple contains an input and output file pair.
- Returns:
- None: This function creates the PST file at the specified output_path with the provided name
(pst_filename). It performs validation on inputs, processes observation data, sets up parameters, and writes the resulting PST file.
Raises: ValueError: If required arguments are missing or invalid values are encountered. FileNotFoundError: If the specified CUL file does not exist. Exception: For any other unexpected errors.