Skip to content

Commit 6db9bd6

Browse files
authored
Merge branch 'develop' into automated-reporting-and-visualization
2 parents eeec791 + d9d5380 commit 6db9bd6

184 files changed

Lines changed: 17794 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docker/depends/pecan_package_dependencies.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,6 @@
636636
"testthat","*","base/logger","Suggests",FALSE
637637
"testthat","*","base/remote","Suggests",FALSE
638638
"testthat","*","base/workflow","Suggests",FALSE
639-
"testthat","*","modules/assim.sequential","Suggests",FALSE
640639
"testthat","*","modules/priors","Suggests",FALSE
641640
"testthat",">= 1.0.2","base/visualization","Suggests",FALSE
642641
"testthat",">= 1.0.2","models/basgra","Suggests",FALSE
@@ -672,6 +671,7 @@
672671
"testthat",">= 3.0.4","base/qaqc","Suggests",FALSE
673672
"testthat",">= 3.1.0","modules/data.land","Suggests",FALSE
674673
"testthat",">= 3.1.7","modules/data.atmosphere","Suggests",FALSE
674+
"testthat",">= 3.1.9","modules/assim.sequential","Suggests",FALSE
675675
"tibble","*","base/db","Imports",FALSE
676676
"tibble","*","models/ed","Imports",FALSE
677677
"tibble","*","models/fates","Imports",FALSE

modules/assim.sequential/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Suggests:
6464
sp,
6565
stats,
6666
terra,
67-
testthat,
67+
testthat (>= 3.1.9),
6868
tictoc,
6969
tidyr,
7070
utils,

modules/data.remote/.Rbuildignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
^.*\.Rproj$
22
^\.Rproj\.user$
33
^docs$
4+
# Lookup parquets and county matrices stay in git for the clone workflow;
5+
# omit them from the install tarball (path length + package size).
6+
^inst/ccmmf/landiq-gapfill/outputs/
7+
^inst/ccmmf/landiq-gapfill/data/county_transition_matrices/
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# California Cropland Monitoring
2+
3+
This is the **monitoring** part of the California Cropland Monitoring and Modeling Framework (CCMMF) -- specifically the **Management Tracking** pipeline inside [PEcAn](https://pecanproject.github.io).
4+
5+
CCMMF uses the ecosystem model SIPNET to simulate California cropland carbon stocks and greenhouse-gas fluxes. That modeling needs a consistent picture of each field over time: which crop was grown, and what management happened (planting, harvest, tillage, fertilizer, irrigation, and related timing). Management Tracking produces those **management events** as inputs to the MAGiC annual inventory and scenario projections.
6+
7+
The sections below list the products, how they fit together, and where to run each part of the workflow.
8+
9+
## Products
10+
11+
The workflow is built in layers across three sessions. Session 1 establishes crop identity: the fields and seasons. Session 2 uses that crop identity to define phenology for each season, and also produces tillage. Session 3 produces fertilization and irrigation. Tillage, fertilization, and irrigation are all conditional on crop identity and phenology.
12+
13+
```mermaid
14+
flowchart TB
15+
CROP["Crop identity"]
16+
PHENO["Phenology / planting / harvest"]
17+
TILL["Tillage"]
18+
FERT["N fertilization + organic amendments"]
19+
IRR["Irrigation"]
20+
21+
CROP --> PHENO
22+
CROP --> TILL
23+
CROP --> FERT
24+
CROP --> IRR
25+
PHENO --> TILL
26+
PHENO --> FERT
27+
PHENO --> IRR
28+
```
29+
30+
31+
32+
33+
| Product | Description | Main source | Session |
34+
| ------------------ | -------------------------------------------------- | ------------------------------------------------------------------ | ------- |
35+
| Crop identity | Crop type of each field each season | LandIQ + CDL | 1 |
36+
| Planting | Crop start date and initial C/N pools | HLS phenology + plant traits | 2 |
37+
| Harvest | Biomass removal date and fractions | HLS phenology + plant traits | 2 |
38+
| Phenology | Leaf-on / leaf-off timing | HLS phenology | 2 |
39+
| Tillage | Soil/residue disturbance in fallow windows | HLS phenology + tillage index | 2 |
40+
| N fertilization | Synthetic nitrogen applications by crop | California crop guidelines | 3 |
41+
| Organic amendments | Manure, compost, biochar, and similar applications | Literature-derived amendment rates | 3 |
42+
| Irrigation | Water applications over the season | Precip (CHIRPS), reference ET (CIMIS), soil water holding (SSURGO) | 3 |
43+
44+
45+
46+
47+
## Run order by session
48+
49+
50+
51+
### Session 1 - Crop identity
52+
53+
Why: before we can say how a field was managed, we need to know which fields exist and what crop was grown on each one. LandIQ is California's statewide crop map. This session aligns successive LandIQ years onto stable field IDs and fills missing crop information so the rest of the pipeline can use them.
54+
55+
56+
| Output | Source |
57+
| ------------------------------------- | -------------------------------------------------------------------------------------- |
58+
| Annual LandIQ shapefiles | [CNRA Statewide Crop Mapping](https://data.cnra.ca.gov/dataset/statewide-crop-mapping) |
59+
| Harmonized parcels + multi-year crops | [cadwr-landuse](https://github.com/ccmmf/cadwr-landuse) |
60+
| Gap-filled crop identity | [landiq-gapfill](landiq-gapfill/README.md) |
61+
62+
63+
Commands: [Session 1](documentation/sessions/01-landiq.md).
64+
65+
### Session 2 - Phenology, planting, harvest, tillage
66+
67+
Why: we also need to know when each field was planted, when leaves came on and off, when it was harvested, and when the soil was disturbed. This session extracts those dates from HLS phenology, sets planting C/N pools and harvest fractions from crop-specific literature, and detects tillage in the fallow period between crop seasons.
68+
69+
70+
| Output | Source |
71+
| -------------------------------------- | -------------------------------------------- |
72+
| Parcel-tile map | [hls](hls/README.md) |
73+
| LandIQ seasons matched to MSLSP cycles | [phenology/match](phenology/match/README.md) |
74+
| Planting / harvest / phenology events | [events](events/README.md) |
75+
| Tillage events | [events](events/README.md) |
76+
| Plant trait lookups | [traits](traits/README.md) |
77+
78+
79+
Commands: [Session 2](documentation/sessions/02-phenology.md).
80+
81+
### Session 3 - Fertilizer, organic amendments, and irrigation
82+
83+
Why: finally, we need nitrogen fertilization, organic amendments, and irrigation on each field. Timing for these depends on the phenology from Session 2. This session sets N rates from California crop guidelines, sets organic amendment rates from literature-derived values, and computes irrigation with a simple water-bucket balance from precip, reference ET, and soil water holding capacity.
84+
85+
86+
| Output | Source |
87+
| ------------------------ | -------------------------------------------------------------------------------------------- |
88+
| N fertilization events | [fertilization-statewide](../../../../workflows/fertilization-statewide/README.md) |
89+
| Organic amendment events | [ncc-statewide](../../../../workflows/ncc-statewide/README.md) |
90+
| Irrigation events | [irrigation-statewide](../../../../workflows/irrigation-statewide/README.md) |
91+
92+
93+
Commands: [Session 3](documentation/sessions/03-fertilizer-irrigation.md).
94+
95+
Together these products give MAGiC a wall-to-wall management record for California cropland: what grew on each field, when it was managed, and what was applied.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Product metadata (column dictionaries)
2+
3+
Column definitions live **with each product component**.
4+
This page indexes the dictionaries saved in `inst/ccmmf`.
5+
Session I/O tables in [tree README](../README.md) and
6+
[sessions/](sessions/) link here instead of duplicating full schemas.
7+
8+
Fertilization and irrigation column docs live with those separate workflows
9+
([Session 3](sessions/03-fertilizer-irrigation.md); not listed below yet).
10+
11+
| Product | File | Writer component |
12+
|---------|------|----------------|
13+
| Harmonized / gap-filled LandIQ `crops_all_years.parq` | [landiq-gapfill/data/crops_all_years_metadata.csv](../landiq-gapfill/data/crops_all_years_metadata.csv) | cadwr-landuse + landiq-gapfill |
14+
| CDL parcel fractions | [landiq-gapfill/data/cdl_fractions_metadata.csv](../landiq-gapfill/data/cdl_fractions_metadata.csv) | landiq-gapfill |
15+
| Upstream LandIQ (cadwr) | [crops_all_years_metadata.csv](https://github.com/ccmmf/cadwr-landuse/blob/main/data/crops_all_years_metadata.csv) | [cadwr-landuse](https://github.com/ccmmf/cadwr-landuse) |
16+
| MSLSP parcel extract | [phenology/extract/data/mslsp_year_metadata.csv](../phenology/extract/data/mslsp_year_metadata.csv) | phenology/extract |
17+
| NDTI parcel extract | [tillage/extract/data/ndti_year_metadata.csv](../tillage/extract/data/ndti_year_metadata.csv) | tillage/extract |
18+
| LandIQ<->MSLSP match | [phenology/match/data/assigned_year_metadata.csv](../phenology/match/data/assigned_year_metadata.csv) | phenology/match |
19+
| Planting events | [events/data/planting_statewide_metadata.csv](../events/data/planting_statewide_metadata.csv) | events |
20+
| Harvest events | [events/data/harvest_statewide_metadata.csv](../events/data/harvest_statewide_metadata.csv) | events |
21+
| Phenology events | [events/data/phenology_statewide_metadata.csv](../events/data/phenology_statewide_metadata.csv) | events |
22+
| Tillage events | [events/data/tillage_statewide_metadata.csv](../events/data/tillage_statewide_metadata.csv) | events |
23+
24+
Trait lookup CSVs (`planting_lookup.csv`, `harvest_lookup.csv`) are documented in
25+
[traits/README.md](../traits/README.md) (harvest includes `destructive`).
26+
27+
After statewide event parquet exist, model drivers are documented in the
28+
unofficial [SIPNET handoff appendix](sessions/sipnet-handoff.md).
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Session 0 - Setup
2+
3+
**What this session is for.** Later sessions assume a working software stack, the pipeline code on disk, and a data workspace with known path names. This session gets that ready, including what to run every time you open a new shell.
4+
5+
---
6+
7+
## 0.1 Environment (once)
8+
9+
Use conda env `pecan-all-1.14` for all sessions. Activate it and confirm the packages later sessions need. If either check fails, stop and fix the environment before continuing.
10+
11+
```bash
12+
conda activate <ENV_PATH_OR_NAME> # pecan-all-1.14
13+
14+
Rscript -e 'stopifnot(
15+
requireNamespace("arrow"),
16+
requireNamespace("dplyr"),
17+
requireNamespace("data.table"),
18+
requireNamespace("sf"),
19+
requireNamespace("terra"),
20+
requireNamespace("exactextractr"),
21+
requireNamespace("readr"),
22+
requireNamespace("stringr"),
23+
requireNamespace("lubridate"),
24+
requireNamespace("jsonlite")
25+
)'
26+
27+
python - <<'PY'
28+
import dask
29+
import fiona
30+
import geopandas
31+
import numpy
32+
import pandas
33+
import pyarrow
34+
import shapely
35+
import tqdm
36+
PY
37+
```
38+
39+
---
40+
41+
## 0.2 Clone (once)
42+
43+
Set `$CCMMF_BASE` to the directory that will hold your clones (`$CCMMF_BASE/src`) and data (`$CCMMF_BASE/ccmmf`).
44+
45+
You also need two git repos: PEcAn and [cadwr-landuse](https://github.com/ccmmf/cadwr-landuse). Later sessions assume those repos live at `$CCMMF_BASE/src/pecan` and `$CCMMF_BASE/src/cadwr-landuse`.
46+
47+
**New clones**
48+
49+
```bash
50+
export CCMMF_BASE=/path/to/workdir
51+
52+
mkdir -p "$CCMMF_BASE/src"
53+
cd "$CCMMF_BASE/src"
54+
55+
# pecan -- develop
56+
git clone https://github.com/PecanProject/pecan.git
57+
cd pecan
58+
git checkout develop
59+
60+
# cadwr-landuse -- main
61+
cd "$CCMMF_BASE/src"
62+
git clone https://github.com/ccmmf/cadwr-landuse.git
63+
cd cadwr-landuse
64+
git checkout main
65+
```
66+
67+
**Already cloned elsewhere.**
68+
69+
```bash
70+
export CCMMF_BASE=/path/to/workdir
71+
mkdir -p "$CCMMF_BASE/src"
72+
73+
# ln -s <existing clone> <tutorial path>
74+
ln -s /actual/path/to/pecan "$CCMMF_BASE/src/pecan"
75+
ln -s /actual/path/to/cadwr-landuse "$CCMMF_BASE/src/cadwr-landuse"
76+
77+
ls -ld "$CCMMF_BASE/src/pecan" "$CCMMF_BASE/src/cadwr-landuse"
78+
```
79+
80+
---
81+
82+
## 0.3 Every new shell
83+
84+
Activate the conda env from 0.1, set the same `$CCMMF_BASE` as in 0.2, pull the repo you need, and source `setup_env`.
85+
86+
```bash
87+
conda activate <ENV_PATH_OR_NAME> # same env as 0.1
88+
89+
export CCMMF_BASE=/path/to/workdir # same as 0.2
90+
91+
# Pull only the repo you are using this session:
92+
git -C "$CCMMF_BASE/src/pecan" pull origin develop
93+
git -C "$CCMMF_BASE/src/cadwr-landuse" pull origin main
94+
95+
# Optional overrides (only if you do not want the BASE defaults):
96+
# export CCMMF_ROOT=/path/to/data
97+
# export PRIOR_YEAR=2023 TARGET_YEAR=2024
98+
99+
source "$CCMMF_BASE/src/pecan/modules/data.remote/inst/ccmmf/documentation/setup_env.sh"
100+
```
101+
102+
---
103+
104+
## 0.4 Workspace (once)
105+
106+
`setup_env` only stored the path strings. Create these folders once. Later sessions use the vars and assume the tree exists.
107+
108+
```text
109+
$CCMMF_ROOT/
110+
LandIQ/
111+
raw/ # LANDIQ_RAW
112+
work/ # CADWR_WORK_DIR
113+
03-final/ # LANDIQ_HARMONIZED
114+
gapfilled/ # LANDIQ_GAPFILLED
115+
HLS/
116+
imagery/ # HLS_IMAGERY_ROOT
117+
MSLSP/ # MSLSP_NETCDF_ROOT
118+
CDL/ # CDL_DIR
119+
climate/
120+
CHIRPS/ # CHIRPS_DIR
121+
CIMIS/ # CIMIS_DIR
122+
soils/
123+
SSURGO/ # SSURGO_DIR
124+
lookups/
125+
plant_traits/ # PLANT_TRAITS_DIR
126+
fertilization/ # FERTILIZATION_LOOKUPS
127+
products/
128+
inventory/ # PRODUCTS_INVENTORY
129+
phenology/
130+
tillage/
131+
fertilization/
132+
irrigation/
133+
event_files/
134+
```
135+
136+
Create the dirs:
137+
138+
```bash
139+
mkdir -p "$LANDIQ_ROOT"/{raw,gapfilled}
140+
mkdir -p "$CADWR_WORK_DIR" "$LANDIQ_HARMONIZED" # 03-final; S3 skip or cadwr both land here
141+
mkdir -p "$HLS_ROOT"/{imagery,MSLSP}
142+
mkdir -p "$CDL_DIR"
143+
mkdir -p "$CLIMATE_ROOT"/{CHIRPS,CIMIS}
144+
mkdir -p "$SOILS_ROOT"/SSURGO
145+
mkdir -p "$LOOKUPS_ROOT"/{plant_traits,fertilization}
146+
mkdir -p "$PRODUCTS_INVENTORY"/{phenology,tillage,fertilization,irrigation,event_files}
147+
```
148+
149+
---
150+
151+
## 0.5 Confirm setup
152+
153+
Confirm the code and data roots are real on disk.
154+
155+
```bash
156+
ls "$CCMMF_CODE" # pipeline scripts and documentation
157+
# documentation events hls landiq-gapfill phenology tillage ...
158+
159+
ls "$CCMMF_ROOT" # data workspace
160+
# CDL HLS LandIQ climate lookups products soils
161+
```
162+
163+
If you do not see the directories you made, go back and fix the section above before Session 1.
164+
165+
---
166+
167+
## 0.6 NASA Earthdata
168+
169+
Create an Earthdata Login account and store credentials in `~/.netrc` for HLS downloads (Session 2).
170+
171+
1. Create a free account at [https://urs.earthdata.nasa.gov/](https://urs.earthdata.nasa.gov/)
172+
2. Store credentials in `~/.netrc`:
173+
174+
```bash
175+
# Replace USERNAME and PASSWORD with your Earthdata Login values
176+
echo "machine urs.earthdata.nasa.gov login USERNAME password PASSWORD" > ~/.netrc
177+
chmod 0600 ~/.netrc
178+
```
179+
180+
**Next:** [Session 1 - LandIQ crop identity](01-landiq.md).
181+
182+
**Spine:** [tree README](../../README.md).

0 commit comments

Comments
 (0)