|
| 1 | +# Crop Type and Tillage Projections |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This workflow uses historical LandIQ crop and tillage observations to generate |
| 6 | +county-level transition matrices and project parcel-level crop and tillage |
| 7 | +states through 2045. |
| 8 | + |
| 9 | +The workflow consists of four main scripts: |
| 10 | + |
| 11 | +1. `transition_matrix.R` |
| 12 | +2. `tillage.R` |
| 13 | +3. `scenarios.R` |
| 14 | +4. `predict_and_store.R` |
| 15 | + |
| 16 | +Reusable transition-matrix functions are stored in |
| 17 | +`modules/data.remote/R/transition_functions.R`. |
| 18 | + |
| 19 | +## Workflow |
| 20 | +```text |
| 21 | +Historical LandIQ crop records |
| 22 | + | |
| 23 | + v |
| 24 | + transition_matrix.R |
| 25 | + / \ |
| 26 | + v v |
| 27 | +crop_year_states tillage.R |
| 28 | +_cleaned.csv | |
| 29 | + | v |
| 30 | + | all_data.csv |
| 31 | + | | |
| 32 | + v | |
| 33 | + scenarios.R | |
| 34 | + | | |
| 35 | + v | |
| 36 | +optimized crop matrices | |
| 37 | ++ BAU/NBS tillage targets |
| 38 | + \ / |
| 39 | + \ / |
| 40 | + v v |
| 41 | + predict_and_store.R |
| 42 | + | |
| 43 | + v |
| 44 | + 2024-2045 parcel predictions |
| 45 | +``` |
| 46 | + |
| 47 | +## 1. Crop transition matrices |
| 48 | + |
| 49 | +`transition_matrix.R` reads harmonized LandIQ crop records from 2018-2023. |
| 50 | + |
| 51 | +Agricultural records are identified using the LandIQ crop lookup table. Parcel |
| 52 | +centroids are spatially joined to California counties so that transition |
| 53 | +matrices can later be created separately for each county. |
| 54 | + |
| 55 | +A parcel can have multiple crop observations within the same year because of |
| 56 | +multiple seasons. These observations are reduced to one annual crop state. |
| 57 | + |
| 58 | +### a. Handling unknown crop states |
| 59 | + |
| 60 | +LandIQ crop class `X` represents an unknown or unresolved crop state. Short |
| 61 | +runs of `X` are corrected only when neighboring observations provide enough |
| 62 | +information to make a reasonable replacement. Longer or unresolved runs remain |
| 63 | +as `X`. |
| 64 | + |
| 65 | +### b. Annual crop state and uncertainty |
| 66 | + |
| 67 | +For each parcel-year, the dominant crop class is selected. If more than one |
| 68 | +crop class occurs within the year, `non_dom_prob` records the fraction of |
| 69 | +observations that do not match the dominant class. |
| 70 | + |
| 71 | +This uncertainty is later used to down-weight less certain transitions. |
| 72 | + |
| 73 | +### c. Outputs |
| 74 | + |
| 75 | +The script writes: |
| 76 | +- `crops_full_counties.csv`: preserves historical crop subclass information for |
| 77 | +later subclass assignment in predict_and_store.R. |
| 78 | + |
| 79 | +- `crop_year_states_cleaned.csv`: contains the full crop population and is the |
| 80 | +main historical crop input used by `scenarios.R` and crop prediction. |
| 81 | + |
| 82 | +- one county crop transition matrix per county |
| 83 | + |
| 84 | + |
| 85 | +## 2. Tillage transition matrices |
| 86 | + |
| 87 | +`tillage.R` combines historical tillage observations with the annual crop |
| 88 | +states. |
| 89 | + |
| 90 | +Tillage intensity is classified as: |
| 91 | +- `no_till`: NDTI percent change less than or equal to 30 |
| 92 | +- `low_till`: NDTI percent changes in between 30 and 70 |
| 93 | +- `high_till`: NDTI percent change greater than or equal to 70 |
| 94 | + |
| 95 | +When multiple tillage observations occur within a parcel-year, the dominant |
| 96 | +tillage class is used. |
| 97 | + |
| 98 | +The script writes: |
| 99 | +- `all_data.csv`: represents the crop/tillage matched subset. It is used to |
| 100 | +calculate the historical tillage baseline for future tillage projections. |
| 101 | + |
| 102 | +It is not used as the full crop population for crop-matrix optimization or |
| 103 | +crop prediction because only parcels with usable tillage observations are |
| 104 | +included. |
| 105 | + |
| 106 | +- county tillage transition matrices |
| 107 | + |
| 108 | + |
| 109 | +## 3. Scenario optimization |
| 110 | + |
| 111 | +`scenarios.R` reads scenario inputs from: |
| 112 | +- `BAU_Targets.csv` |
| 113 | +- `NBS_Targets.csv` |
| 114 | + |
| 115 | +The historical county crop transition matrices (created in `transition_matrix.R`) are optimized toward the |
| 116 | +2045 crop distribution specified by the configured matrix target scenario. |
| 117 | + |
| 118 | +The default matrix target scenario is: |
| 119 | + |
| 120 | +```r |
| 121 | +matrix_target_scenario_name = "BAU_Targets" |
| 122 | +``` |
| 123 | + |
| 124 | +Scenario crop acreage is rescaled to the total acreage represented by the |
| 125 | +observed starting crop population. Therefore, the optimization targets the |
| 126 | +scenario crop distribution and direction of change rather than requiring the |
| 127 | +optimized projection to reproduce the scenario's absolute acreage exactly. |
| 128 | + |
| 129 | +The crop starting distribution is constructed from |
| 130 | +`crop_year_states_cleaned.csv` using each parcel's latest observed crop state |
| 131 | +up to the starting year. |
| 132 | + |
| 133 | +The script optimizes the crop matrix once per county and also produces |
| 134 | +scenario-specific tillage targets for both `BAU_Targets` and `NBS_Targets` |
| 135 | + |
| 136 | +## 4. Parcel projections |
| 137 | + |
| 138 | +`predict_and_store.R` uses the optimized crop matrices and scenario-specific |
| 139 | +tillage targets to generate annual parcel-level projections. |
| 140 | + |
| 141 | +Crop and tillage projections use different historical inputs: |
| 142 | + |
| 143 | +- `crop_year_states_cleaned.csv` provides the full crop population used for |
| 144 | + crop prediction and parcel metadata. |
| 145 | +- `all_data.csv` provides the historical crop/tillage matched subset used to |
| 146 | + calculate baseline tillage distributions. |
| 147 | + |
| 148 | +Crop states are projected from each parcel's historical crop state using the |
| 149 | +optimized county transition matrix. |
| 150 | + |
| 151 | +Projected crop classes are then translated to parcel-level assignments while |
| 152 | +preserving the acreage distribution implied by the optimized matrix as closely |
| 153 | +as possible. The optimized crop matrix is shared between prediction scenarios. |
| 154 | +BAU and NBS differ through their scenario-specific tillage targets rather than through |
| 155 | +separately optimized crop matrices. |
| 156 | + |
| 157 | +Historical tillage shares are gradually shifted toward the scenario-specific |
| 158 | +2045 tillage targets. This produces separate BAU and NBS tillage trajectories. |
| 159 | + |
| 160 | + |
| 161 | +Predictions are produced annually for 2024-2045. |
| 162 | + |
| 163 | +## Transition functions |
| 164 | +Reusable transition functions are defined in: |
| 165 | + |
| 166 | +```text |
| 167 | +modules/data.remote/R/transition_functions.R |
| 168 | +``` |
| 169 | + |
| 170 | +The main functions are: |
| 171 | +- `make_transitions()` |
| 172 | +- `make_transition_matrix()` |
| 173 | +- `make_grouped_transition_matrices()` |
| 174 | + |
| 175 | +These functions are exported from `PEcAn.data.remote` and are called from the |
| 176 | +workflow scripts using the package namespace. |
| 177 | + |
| 178 | +## Configuration |
| 179 | + |
| 180 | +The scripts use the environment variable: |
| 181 | +```r |
| 182 | +CCMMF_WORK_ROOT |
| 183 | +``` |
| 184 | + |
| 185 | +Set this variable to the workspace where intermediate files and workflow |
| 186 | +outputs should be stored. For example: |
| 187 | + |
| 188 | +```r |
| 189 | +Sys.setenv(CCMMF_WORK_ROOT = "/projectnb/dietzelab/ananyak") |
| 190 | +``` |
| 191 | +Or, more generally, |
| 192 | + |
| 193 | +```r |
| 194 | +Sys.setenv(CCMMF_WORK_ROOT = "/path/to/your/folder") |
| 195 | +``` |
| 196 | + |
| 197 | +Shared CCMMF inputs default to: |
| 198 | + |
| 199 | +```text |
| 200 | +/projectnb/dietzelab/ccmmf |
| 201 | +``` |
| 202 | + |
| 203 | +where applicable. |
| 204 | + |
| 205 | +## Running the workflow |
| 206 | + |
| 207 | +Run the scripts in this order: |
| 208 | + |
| 209 | +```text |
| 210 | +transition_matrix.R |
| 211 | +tillage.R |
| 212 | +scenarios.R |
| 213 | +predict_and_store.R |
| 214 | +``` |
| 215 | + |
| 216 | +Each script depends on outputs generated by earlier stages of the workflow. |
| 217 | +If a required upstream file is missing, the script stops with a message |
| 218 | +indicating which earlier step should be run first. |
| 219 | + |
| 220 | +## Validation |
| 221 | + |
| 222 | +The workflow includes checks for: |
| 223 | + |
| 224 | +- required input columns |
| 225 | +- valid transition probabilities |
| 226 | +- transition-matrix row sums |
| 227 | +- negative or greater-than-one probabilities |
| 228 | +- scenario mapping totals |
| 229 | +- optimizer status |
| 230 | +- optimized scenario fit |
| 231 | +- parcel acreage assignment differences |
| 232 | + |
| 233 | +Optimized crop matrices are expected to move projected crop distributions |
| 234 | +toward the configured scenario targets. Exact equality with scenario acreage |
| 235 | +is not expected. |
0 commit comments