V2 7
View or edit on GitHub
This page is synchronized from trase/models/brazil/soy/v2_7/README.md. Last modified on 2026-11-26 10:57 CET by Mike Lathuilliere.
Please view or edit the original file there; changes should be reflected here after a midnight build (CET time),
or manually triggering it with a GitHub action (link).
Brazil soy v2.7.0
This directory holds the SEI-PCS Brazil soy v2.7.0 model, which covers the export years from 2022 onwards.
| Folder or file | What it holds |
|---|---|
main.py |
Runs the whole model: the decision tree, then the supply-shed model, then reconciles the two and publishes the result |
trade_export_decision_tree/ |
Stage 1: the trade export decision tree, with its tests |
supply_sheds/ |
Stage 2: the supply-shed model |
post_processing.py, output_format.py, logistics_assets.py, constants.py |
Reconciling the two stages, the published output format, the logistics-asset registry, and constants shared across the model |
qa/ |
QA notebooks |
methodology.qmd |
The methodology, rendered to methodology.pdf and methodology.md |
DECISIONS.md |
Decisions made while building and running the model |
Keep preparation.py and quality_assurance.py out of this folder: SupplyChain also runs those scripts from a model's parent folder, so here they would run for both stages.
Changes to the model output are recorded in the Brazil soy changelog.
Ideas for improving this model (part of the 2027 R&D workplan) are in Brazil soy supply sheds V2 - ideas.
Running the model and refreshing outputs
Re-running the whole model and deploying it to the website takes seven steps. Each one reads the previous step's output from S3, so they run in this order:
| Step | What it does | Key output |
|---|---|---|
| 1. Run the model | Decision tree and supply-shed model, per year | sei_pcs/v2.7.0/SEI_PCS_BRAZIL_SOY_<year>_TMP_1000.parquet |
| 2. Run the embedding | Adds deforestation, emissions and commitments, 2013-2025 | sei_pcs/v2.7.0/SEIPCS_BRAZIL_SOY_<year>_WITH_EXPORTER_POST_EMBEDDING.parquet |
| 3. Build the data package | One file of every year, in the shape the website reads | data_packages/brazil_soy_v2_7_0/supply_chain.parquet |
| 4. Ingest the indicators | The standalone indicators into PostgreSQL, for the impact indicators map | BRAZIL SOY INDICATORS V<version> FULL in PostgreSQL |
| 5. Release to trase.earth | PostgreSQL, then the review site | review.trase.earth |
| 6. Update the QA notebooks | Re-render the notebooks on the new results | qa/*.md |
| 7. Update the explainer | Refresh the explainer's charts from the review site | Datawrapper charts |
All S3 paths are under s3://trase-storage/brazil/soy/.
1. Run the model
Runs the bills-of-lading decision tree and the supply-shed model in supply_sheds/, and reconciles the two. Before running, open main.py and edit the years you wish to run for.
Run
python trase/models/brazil/soy/v2_7/main.py
UPLOAD_TO_S3 = Falseat the top ofmain.pyis a dry run: it writes the branch assignments locally and stops, because every later step reads its input back from S3 and would otherwise run against the last upload.
Output data
s3://trase-storage/brazil/soy/sei_pcs/v2.7.0/
SEI_PCS_BRAZIL_SOY_<year>_TMP_1000.parquet # trade data with additional columns, 2022-2025
logistics_assets_<year>.geojson # the logistics assets the decision tree and the supply-shed model used in each year
Tests
poetry run trase/data_pipeline/dbt test \
--select seipcs_brazil_soy_partial_by_year_branches_v27 sei_pcs_brazil_soy_by_year_tmp_1000 \
--exclude "*post_embedding*"
The post-embedding tests also hang off these models and necessarily fail between this step and step 2, which runs them.
2. Run the embedding
Adds various metrics, such as deforestation and emissions, to the data. Three R scripts, run in order.
The metrics come from the q3 2026 indicators file,
indicators/out/q3_2026/soy_deforestation_emission_norm_2014_2025_q3_2026_multilevel.parquet,
which the scripts in trase/data/brazil/soy/indicators/
(in/q3_2026/, then out/q3_2026/) build from the Google Earth Engine export. Its columns
are named as the database attributes they are ingested to in step 4. If the indicators
themselves change, re-run those scripts first; the embedding reads whatever is on S3.
The exporter groups' commitments come from
indicators/out/q3_2026/zdc/br_soy_zdcs_all_14_25.parquet and the Soy Moratorium
signatories from br_soy_zdcs_all_Amazon_biome_14_25.parquet. Both are written by
br_soy_zdcs_all_14_25.r
from a dated copy of the v3 (used in Nov 2026 soy update) tab of the assessment's Google
Sheet, which
zdc_brazil_soy_assessment_done_2026_v3_used_in_nov_2026_soy_update_accessed_yyyy_mm.r
saves under indicators/out/q3_2026/zdc/raw/. If the commitments change, run the download
script, point accessed in br_soy_zdcs_all_14_25.r and the raw model's name and location in
trase/data_pipeline/models/brazil/soy/indicators/out/q3_2026/zdc/raw/_schema.yml at the
new copy, re-run br_soy_zdcs_all_14_25.r, test the two files with
poetry run trase/data_pipeline/dbt test --select brazil_soy_indicators_out_q3_2026_zdc_br_soy_zdcs_all_14_25 brazil_soy_indicators_out_q3_2026_zdc_br_soy_zdcs_all_amazon_biome_14_25 --indirect-selection cautious,
then re-run c_embedding_biomes_zdcs.R and x_consolidating_embedding.r (not
a_embedding_quants.R) and every step after this one. That includes step 4, because the
share of soy exported under a commitment is computed from the post-embedding files.
c_embedding_biomes_zdcs.R writes matching reports to
sei_pcs/v2.7.0/post_embedding/zdc_reports/: check them for exporter groups that no
longer match, and add any name variants to its alias table.
Run
Rscript trase/runbook/brazil/soy/indicators/embedding/a_embedding_quants.R
Rscript trase/runbook/brazil/soy/indicators/embedding/c_embedding_biomes_zdcs.R
Rscript trase/runbook/brazil/soy/indicators/embedding/x_consolidating_embedding.r
Output data
s3://trase-storage/brazil/soy/sei_pcs/v2.7.0/
SEIPCS_BRAZIL_SOY_<year>_WITH_EXPORTER_POST_EMBEDDING.parquet # 2013-2025
Tests
poetry run trase/data_pipeline/dbt test \
--select "path:models/brazil/soy/sei_pcs/v2_7_0/post_embedding" "tag:brazil_soy_embedding_did_not_alter_data_2_7_0"
3. Build the data package
Combines the post-embedding files into a single file, which is what gets deployed to the website.
Run
poetry run trase/data_pipeline/dbt run --select brazil_soy_v2_7_0_supply_chain
Output data
s3://trase-storage/brazil/soy/data_packages/brazil_soy_v2_7_0/supply_chain.parquet
Tests
poetry run trase/data_pipeline/dbt test --select brazil_soy_v2_7_0_supply_chain
4. Ingest the indicators
The indicators also stand on their own on the website, as the "spatial metrics" of the impact indicators map and the download page: soy production, area and yield from IBGE; soy deforestation and emissions, total and per tonne; and the share of soy exported under a zero-deforestation commitment. They are ingested into PostgreSQL as a node attributes dataset, separately from the supply chain.
Two of the three files are already on S3: the IBGE file from the q2 2026 update, and the deforestation and emissions file that step 2 embeds. The third, the share of soy exported under a commitment, is computed from the post-embedding files of step 2, so this step runs after it.
Run
Rscript trase/data/brazil/soy/indicators/out/q3_2026/OUT_zdc_perc.r
poetry run python trase/runbook/brazil/soy/indicators/a_ingest_full_indicators.py
The ingestion writes the dataset BRAZIL SOY INDICATORS V<VERSION> FULL, with VERSION
set at the top of the script, and deletes the previous ingestion of that version first, so
re-running it replaces the dataset in place. The website finds the dataset by this title:
if you bump VERSION, update reference_title (and last_updated_at) in the pipeline's
seeds/spatial_metrics/review_spatial_metrics_metadata.csv to match, and the staging_
seed when the release goes to staging. The script ends by printing a report of every
metric and year it ingested; check the sums against the files.
Input data
s3://trase-storage/brazil/soy/indicators/out/
q2_2026/soy_production_IBGE_2003_2025_multilevel.parquet # IBGE area, production and yield
q3_2026/soy_deforestation_emission_norm_2014_2025_q3_2026_multilevel.parquet # deforestation and emissions, as embedded in step 2
q3_2026/territorial_ZDC_perc_2013_2025_q3_2026_multilevel.parquet # written by OUT_zdc_perc.r
Output data
The BRAZIL SOY INDICATORS V<VERSION> FULL node attributes dataset in PostgreSQL.
Tests
The deforestation and emissions indicators are compared with the previous release in
trase/data/brazil/soy/indicators/out/q3_2026/qa/comparing_to_previous_results.qmd;
re-render it when the indicators change. The dbt tests cover the IBGE file and the
commitment assessment the embedding and OUT_zdc_perc.r read:
poetry run trase/data_pipeline/dbt test \
--select "path:models/brazil/soy/indicators/out/q2_2026" "path:models/brazil/soy/indicators/out/q3_2026"
5. Release to trase.earth
Ingests the package into PostgreSQL, then runs the trase.earth data pipeline to the review environment. The runbook names the package and the table it writes (brazil_soy_v2_7_0_supply_chain), and the pipeline's supply_chains_datasets/brazil_soy_v2_7_0.sql and the review_* seeds describe it to the website. The release script excludes the datasets models, so the dataset is run on its own first. The same release builds the website's spatial_metrics table from the dataset ingested in step 4, through the review_spatial_metrics_metadata seed.
Run
poetry run python trase/runbook/brazil/soy/trade/a_ingest_full_dataset.py
cd trase/database/trase_earth_data_pipeline
export PGUSER=<your user>
poetry run "$(realpath ./dbt)" seed --target review --full-refresh
poetry run "$(realpath ./dbt)" run --target review --select brazil_soy_v2_7_0
bash release_to_staging_or_review.sh --target review
./dbt is a wrapper that reads PGUSER's password from ~/.pgpass. Name it by its full
path, as above: poetry run ./dbt runs the dbt executable of the Poetry environment
instead, which then fails with password authentication failed.
Output data
The brazil_soy_v2_7_0_supply_chain table in PostgreSQL, and the data on review.trase.earth.
The pipeline's README has the rest: staging, and from staging to production.
6. Update the QA notebooks
The notebooks in qa/ read the model's results and the datasets around them, so they are re-rendered after a run.
Run
cd trase/models/brazil/soy/v2_7/qa
for notebook in *model*.qmd; do echo $notebook; quarto render "$notebook"; done
Output data
The rendered .md file next to each notebook. Commit and push any changes in a pull request.
7. Update the explainer
The explainer Brazilian soy exports and deforestation reads the data released to the review site in step 5. Its charts are in Datawrapper and are not connected to the data: its queries are re-run into CSVs, its notebook re-rendered, and the CSVs uploaded into the charts.
Run
From the root of the repository:
bash trase/products/analysis/explainers/brazil_soy_2025/update.sh
The script first pulls the queries from their Metabase collection into sql/, which is the source of truth for them, then runs every query into data/*.csv and renders the notebook. Add --skip-pull to run the queries already in the repository instead.
It needs Google Cloud credentials for trase-396112 (gcloud auth application-default login) and AWS credentials that can read s3://trase-storage/. Pulling the queries also needs Metabase access: see Metabase Configuration. Without it, the pull fails and the script suggests --skip-pull.
Output data
sql/*.sql, data/*.csv and the rendered brazil_soy_exports_and_deforestation.md in the explainer's folder. Check git diff, commit them together in a pull request, then upload each chart's CSV into its Datawrapper chart and republish it. The explainer's README has the details.
Updating the methodology
The methodology is written in methodology.qmd. methodology.pdf and methodology.md, which is for reading on GitHub, are rendered from it, so edit the .qmd and re-render both. The repository's general Quarto setup is in doc/Quarto.md.
Citations
Data sources and other references are cited as [@citation_key]. Each citation is an item in the Trase-references Zotero group library, exported as CSL JSON to references.json, where its id is the citation key. apa-numeric-superscript.csl sets the citation style: APA 7th edition references, numbered in the order they are first cited, with superscript numbers in the text that link to them.
To add a citation, add the item to the Trase-references library in Zotero, export it as CSL JSON (right-click it, then Export Item…), add it to references.json with a readable id, and cite it in methodology.qmd as [@id].
Rendering
The PDF needs, once per machine:
- LuaLaTeX:
quarto install tinytex, which fetches any other LaTeX packages the first time they are needed; - Chrome or Chromium, for the Mermaid diagrams (set
QUARTO_CHROMIUMto its path if Quarto does not find it); rsvg-convert, for SVG images:brew install librsvgon macOS.
Then, from this folder:
quarto render methodology.qmd
This renders both methodology.pdf and methodology.md. To render just one of them, add --to trase-pdf or --to gfm. Commit both files with the .qmd.