Main
View or edit on GitHub
This page is synchronized from trase/models/brazil/corn/main.ipynb. Last modified on 2025-12-14 23:19 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).
%configure_logging
import pandas as pd
from trase.tools import sps
from trase.models.brazil.decision_tree import get_remaining_mdic
for year in [
2015,
2016,
2017,
2019,
]: # trade data missing for 2018, production missing for 2020
supplychain = sps.SupplyChain("brazil/corn", year=year)
supplychain.preparation()
# supplychain.load()
# suffix = supplychain.run()
# supplychain.flow_report_by_attribute("vol", ["branch"], 8)
# supplychain.flow_report_by_attribute("vol", ["exporter_type"], 8)
# supplychain.export_results()#suffix=suffix)
# supplychain.upload_results(
# country="BRAZIL",
# commodity="CORN",
# #suffix=suffix,
# )
# on = [
# "country_of_destination_name",
# "port_of_export_group",
# "product_type",
# "state_trase_id",
# ]
# df = (
# supplychain.get("flows")
# .drop(columns="state_trase_id")
# .rename(columns={"mdic_overflow_state": "state_trase_id"})
# )
# df = df[df["mdic_overflow"]]
# df = (
# df.groupby(on)["vol"]
# .sum()
# .reset_index()
# .rename(columns={"vol": "overflow_vol"})
# )
# df_mdic = get_remaining_mdic(supplychain)
# df_mdic = (
# df_mdic.groupby(on)["vol"]
# .sum()
# .reset_index()
# .rename(columns={"vol": "remaining_vol"})
# )
# df = pd.merge(df, df_mdic, on=on, how="outer").fillna(0)
# df = df.sort_values("port_of_export_group")
# print(df)
# df.to_csv("mdic_overflow.csv")
df