Main
View or edit on GitHub
This page is synchronized from trase/models/brazil/soy_supply_sheds/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).
from trase.tools.sps import SupplyChain
sc = SupplyChain("brazil/soy_supply_sheds", year=2023)
sc.preparation()
sc.load()
df_supply, df_demand, df_lp_solution = sc.run()
# sc.export_results()
# sc.upload_results()
Extracting data from source ...[0m [97m took 0.1 seconds[0m
[97mSkipping re-process of TrainFlows[0m
supply from production 152144238.0
supply from train flows 34282087.0
total supply 186426325.0
demand from train flows 34282087.0
demand from silos 99038871.4
demand from crushing facilities 53105366.599999994
total demand 186426325.0
Total demand 186426325.0
⚐ WARNING Use the validate option with pd.merge or pass validate=None to suppress this warning
/home/sagemaker-user/.admin/repos/TRASE/trase/models/brazil/soy_supply_sheds/model.py:47
⚐ WARNING Use the validate option with pd.merge or pass validate=None to suppress this warning
/home/sagemaker-user/.admin/repos/TRASE/trase/models/brazil/soy_supply_sheds/model.py:86
⚐ WARNING Use the validate option with pd.merge or pass validate=None to suppress this warning
/home/sagemaker-user/.admin/repos/TRASE/trase/models/brazil/soy_supply_sheds/model.py:89
import pandas as pd
df_supply = pd.read_csv("df_supply.csv").rename(
columns={"municipality_supply": "municipality"}
)
df_demand = (
pd.read_csv("df_demand.csv")
.rename(columns={"municipality_demand": "municipality"})
.drop(columns="_id")
)
df_supply_to_lp = df.groupby("municipality_production")["vol_lp"].sum().reset_index()
df_supply_to_lp = pd.merge(
df_supply_to_lp,
df_supply,
left_on="municipality_production",
right_on="municipality",
)
df_supply_to_lp
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[1], line 12
3 df_supply = pd.read_csv("df_supply.csv").rename(
4 columns={"municipality_supply": "municipality"}
5 )
6 df_demand = (
7 pd.read_csv("df_demand.csv")
8 .rename(columns={"municipality_demand": "municipality"})
9 .drop(columns="_id")
10 )
---> 12 df_supply_to_lp = df.groupby("municipality_production")["vol_lp"].sum().reset_index()
13 df_supply_to_lp = pd.merge(
14 df_supply_to_lp,
15 df_supply,
16 left_on="municipality_production",
17 right_on="municipality",
18 )
19 df_supply_to_lp
NameError: name 'df' is not defined
# import sys
# import subprocess
# subprocess.check_call([sys.executable, "-m", "pip", "install", "contextily"])
import pandas as pd
import geopandas as gpd
import shapely
import contextily as cx
from matplotlib import pyplot as plt
df_mun = pd.read_csv("df_mun.csv")
df_mun = pd.merge(df_mun, df, left_on="trase_id", right_on="municipality")
df_mun["geometry"] = df_mun["geometry"].apply(lambda x: shapely.from_wkt(x))
df_mun = gpd.GeoDataFrame(df_mun).set_geometry("geometry")
fig, (ax1, ax2) = plt.subplots(1, 2)
fig.set_figheight(10)
fig.set_figwidth(16)
df_mun.plot(ax=ax1, column="quantity_remaining", cmap="Greens", legend=True)
ax1.set_title("Quantity remaining", fontsize=20)
# cx.add_basemap(ax1, crs=df_mun.crs)#, source=cx.providers.CartoDB.Positron)
df_mun.plot(ax=ax2, column="fraction_remaining", cmap="Purples", legend=True)
ax2.set_title("Fraction remaining", fontsize=20)
# cx.add_basemap(ax1, crs=df_mun.crs)#, source=cx.providers.CartoDB.Positron)
fig.savefig("remaining.png")
