Main

View or edit on GitHub

This page is synchronized from trase/models/indonesia/wood_pulp/main.ipynb. Last modified on 2025-12-13 00: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).

from typing import List
import pandas as pd
from trase.tools.jupyter.observable import _notebook_html_string, Sankey
from trase.tools.sps import consolidate


def html_sankey(
    df: pd.DataFrame,
    value_column: str,
    categorical_columns: List[str],
    file_name="SEIPCS_sankey",
):
    df = df.rename(columns={value_column: Sankey.VALUE_COLUMN}, errors="raise")
    df = df.astype({c: str for c in categorical_columns})  # force columns to be strings
    df = consolidate(
        df,
        numerical_columns=[Sankey.VALUE_COLUMN],
        categorical_columns=categorical_columns,
    )
    df = df[[*categorical_columns, Sankey.VALUE_COLUMN]]  # set desired column order
    sankey_html = _notebook_html_string(
        Sankey.NOTEBOOK,
        cells_to_import=[Sankey.CHART_CELL],
        cell_redefinitions={Sankey.DATA_CELL: df.to_dict("records")},
    )
    f = open(f"./{file_name}.html", "w")
    f.write(sankey_html)
    f.close()
import sys
from pathlib import Path

sys.path.append(str(Path.cwd().parent.parent))

from trase.tools.sps import SupplyChain

for year in [2015, 2016, 2017, 2018, 2019]:
    sc = SupplyChain("indonesia/wood_pulp", year=year, bucket="trase-storage")
    sc.preparation()
    sc.load()
    sc.export_results()
    df = sc.to_df()
    sc.upload_results()

    # html_sankey(df, "VOLUME_RAW", ["SUPPLIER_GROUP", "EXPORTER_GROUP","IMPORTER_GROUP","DESTINATION"], f"SEI-PCS-sankey-{year}")
from trase.tools.aws import *

df = get_pandas_df(
    "indonesia/wood_pulp/production/out/INDONESIA_WOOD_PULP_RESULT_2015_2019.csv",
    sep=",",
)
df[df["SUPPLIER_GROUP"].isna()]
from trase.tools.jupyter.observable import notebook, sankey

sankey(df, "VOLUME_RAW", ["SUPPLIER_GROUP", "EXPORTER_GROUP", "DESTINATION"])
df["HS6"].unique()
from trase.tools.aws import *

for year in range(2015, 2020):
    print(year)
    df = get_pandas_df(
        f"indonesia/wood_pulp/sei_pcs/SEIPCS_INDONESIA_WOOD_PULP_{year}.csv", sep=";"
    )
    df["PORT_OF_EXPORT"].unique()
    print("Vol:", df["VOLUME_RAW"].sum())
    print("Length:", len(df))
    print(
        "Dom mand:", df[df["COUNTRY_OF_DESTINATION"] == "INDONESIA"]["VOLUME_RAW"].sum()
    )