This function transforms the input data from wide to long format, calculates errors, adjusts variable values as needed, and filters the data based on the variables used in water balance calculations. Specifically, it makes AET, RCH, and RUN negative so they can be subtracted from PPT rather than added. The processed data is then saved to the global environment under specific names depending on the variables present.
Arguments
- x
A data frame in wide format, typically containing columns for `divide_id`, `date`, `source`, and various water balance variables (e.g., `ppt`, `aet`, `rch`, `run`, `str`, `ERR`). The data should be the result of a previous processing step such as `model_clean()`.
Value
This function does not return a value. It saves the processed data to the global environment with the following names:
**"cabcm_TimeSeries"**: Contains data with variables relevant to CABCM, including `aet`, `rch`, `run`, and `str` where applicable.
**"terra_TimeSeries"**: Contains data with variables relevant to TerraClim, excluding `rch`.
Details
The `balance_data` function performs the following operations:
**Convert to Long Format**: Uses `pivot_longer` to transform the wide-format data into long format.
**Filter and Adjust Data**: Filters the data to keep only the relevant variables and multiplies values for specific variables by -1 to facilitate subtraction from `ppt`.
**Save to Global Environment**: Depending on the presence of the `rch` variable, the function saves the processed data to the global environment with an appropriate name for future use.