Skip to contents

This function processes the output of `model_clean()`. It widens the dataframe, calculates the error for each timestamp, assigns seasons based on month, calculates average error per season, and the percent error against PPT. It then joins the seasonal data with the `NewDivides` dataset to create a spatial dataframe, which is split into four seasonal datasets. The final output is a list containing seasonal data that can be used for generating Percent Error Plots based on the season. Additionally, the function assigns the processed data to the global environment.

Usage

process_model_data(data, NewDivides)

Arguments

data

A data frame resulting from the `model_clean()` function. It should contain columns such as `divide_id`, `var`, `date`, `value`, and `source`.

NewDivides

A spatial dataframe containing divide information, which should be read from the `nextgen_hydrofabric.gpkg` file.

Value

A list containing four data frames: `Winter`, `Spring`, `Summer`, and `Fall`. Each dataframe includes average seasonal error and percent error data, joined with spatial information from `NewDivides`.

Details

The `process_model_data` function performs the following steps:

  • **Pivot Wider**: Reshapes the data to have separate columns for each variable and calculates the error (ERR) as the difference between predicted and actual values.

  • **Assign to Global Environment**: Stores the wide-format data in the global environment under the name `cabcm_data_wide` or `terra_data_wide`, depending on the dataset.

  • **Season Assignment**: Adds a season column to the data based on the month extracted from the date.

  • **Calculate Seasonal Error**: Computes average seasonal error and percentage error.

  • **Join and Split**: Joins the error data with `NewDivides`, and splits the data into seasonal dataframes.