View or edit on GitHub
This page is synchronized from trase/models/brazil/beef/Old vs New.ipynb. Last modified on 2026-03-21 22:30 CET by Trase Admin.
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).
Compare BR Beef SEI-PCS Model Results for V2.2.0 ("new") and V2.0.2 ("old")
import pandas as pd
from trase.tools.sps import *
from trase.tools.pandasdb import read
from trase.tools import CNX
from plotly import express as px
Read old and new supply chain data (2015 only, from Splitgraph)
df_new = pd.read_sql(
'select * from splitgraph."supply-chains-latest" where ref_id = 2779 and year = 2015',
CNX.cnx,
)
df_old = pd.read_sql(
'select * from splitgraph."supply-chains-concatenated" where ref_id = 2710 and year = 2015',
CNX.cnx,
)
Total volume per product - exact match :)
dumbbell_compare(
df_old, df_new, "volume", ["product_type"], labels=("_old", "_new"), label_width=50
)
Logistics hub
Noteably reduced unknowns. Three municipalities appear that didn't used to be there: Hulha Negra, Sao Paulo, Sao Sebastio do Cai. Noteable reduction from Bage.
dumbbell_compare(
df_old.assign(
logistics_hub=df_old["logistics_hub"].apply(
lambda x: "UNKNOWN" if "UNKNOWN" in x else x
)
),
df_new,
"volume",
["logistics_hub"],
labels=("_old", "_new"),
label_width=50,
)
Branches
Differences all over the place! Did we use the same naming scheme??
Increase in branch 1.1 (SIF Slaughterhouse). Branches 1.3, 1.4, 1.7, 2.2, 1.2 are in the new data but don't appear in the old data. Branches 1.2.1, 1.2.2.* were in the old data but disappeared in the new data.
dumbbell_compare(
df_old.assign(branch=df_old["branch"].replace({"LIVE_EXPORTS": "0."})),
df_new.assign(branch=df_new["branch"].apply(lambda x: x.split(" ")[0])),
"volume",
["branch"],
labels=("_old", "_new"),
label_width=50,
)
Production municipality
Lots of differences but they are all quite small
dumbbell_compare(
df_old,
df_new,
"volume",
["region_production_1"],
labels=("_old", "_new"),
)
Exporter
Only notable change is the rename of "JBS" to "JBS S/A".
dumbbell_compare(
df_old,
df_new,
"volume",
["exporter"],
labels=("_old", "_new"),
label_width=50,
max_rows=5,
)
Exporter supply chain (logistics hub)
Here we look at the top five exporters and ask how their logistics hub differ.
Some differences in JBS and Minerva - should we investigate?
top_five_exporters = (
consolidate(df_old, ["volume"], ["exporter"])
.sort_values("volume", ascending=False)[:5]["exporter"]
.values
)
print("Top five exporters", top_five_exporters)
for exporter in top_five_exporters:
exporter1 = exporter2 = exporter
if exporter == "JBS":
exporter2 = "JBS S/A"
display(
dumbbell_compare(
df_old[df_old["exporter"] == exporter1],
df_new[df_new["exporter"] == exporter2],
"volume",
["logistics_hub"],
labels=("_old", "_new"),
label_width=50,
max_rows=5,
title_text=f"Logistics hubs used by {exporter}",
)
)
Exporter supply chain (production municipality)
Here we look at the top five exporters and ask how their production municipality differs.
Some differences in JBS and Minerva but they are smaller differences compared to the logistics hubs, interestingly.
We now also see differences in the other five.
for exporter in top_five_exporters:
exporter1 = exporter2 = exporter
if exporter == "JBS":
exporter2 = "JBS S/A"
display(
dumbbell_compare(
df_old[df_old["exporter"] == exporter1],
df_new[df_new["exporter"] == exporter2],
"volume",
["region_production_1"],
labels=("_old", "_new"),
label_width=50,
max_rows=5,
title_text=f"Production municipality by {exporter}",
)
)