Skip to content

View or edit on GitHub

This page is synchronized from trase/models/brazil/beef/qa_beef/archive/qa_phase2_specific_plots.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).

%%HTML 
<script>
    function luc21893_refresh_cell(cell) {
        if( cell.luc21893 ) return;
        cell.luc21893 = true;
        console.debug('New code cell found...' );

        var div = document.createElement('DIV');            
        cell.parentNode.insertBefore( div, cell.nextSibling );
        div.style.textAlign = 'right';
        var a = document.createElement('A');
        div.appendChild(a);
        a.href='#'
        a.luc21893 = cell;
        a.setAttribute( 'onclick', "luc21893_toggle(this); return false;" );

        cell.style.visibility='hidden';
        cell.style.position='absolute';
        a.innerHTML = '[show code]';        

    }
    function luc21893_refresh() {                
        if( document.querySelector('.code_cell .input') == null ) {            
            // it apeears that I am in a exported html
            // hide this code
            var codeCells = document.querySelectorAll('.jp-InputArea')
            codeCells[0].style.visibility = 'hidden';
            codeCells[0].style.position = 'absolute';                        
            for( var i = 1; i < codeCells.length; i++ ) {
                if (i % 2 == 0){
                luc21893_refresh_cell(codeCells[i].parentNode)}
                else {}

            }
            window.onload = luc21893_refresh;
        }                 
        else {
            // it apperas that I am in a jupyter editor
            var codeCells = document.querySelectorAll('.code_cell .input')
            for( var i = 0; i < codeCells.length; i++ ) {
                if ([1,3,4,5,7].includes(i)){
                luc21893_refresh_cell(codeCells[i])}
                else {}
            }            
            window.setTimeout( luc21893_refresh, 1000 )
        }        
    }

    function luc21893_toggle(a) {
        if( a.luc21893.style.visibility=='hidden' ) {
            a.luc21893.style.visibility='visible';        
            a.luc21893.style.position='';
            a.innerHTML = '[hide code]';
        }
        else {
            a.luc21893.style.visibility='hidden';        
            a.luc21893.style.position='absolute';
            a.innerHTML = '[show code]';
        }
    }

    luc21893_refresh()
</script>

Brazilian beef SEI-PCS 2.2.0 QA

Yan Prada Moro 31/03/2023

Introduction

We carry out a more extensive QA check on:

  1. Country of Import;
  2. Port of export;
  3. Exporter group;
  4. Importer group;
  5. State
  6. Biome.
from trase.models.brazil.beef.qa_beef.imports.reader import load_downloaded_data_s3
from trase.models.brazil.beef.qa_beef.imports.plots_specific import (
    plot_grouped_by_dumbbell_comparision,
    plot_market_share,
    plot_state_grouped_by,
    plot_number_lh,
    plot_hs4_grouped_by,
    plot_grouped_by_dumbbell_comparision,
)
from trase.models.brazil.beef.qa_beef.imports.functions import *
from trase.models.brazil.beef.qa_beef.imports.constants import PATH

import plotly.io as pio

pio.renderers.default = "plotly_mimetype+notebook"

dfs = load_downloaded_data_s3()
sei_pcs_s3 = dfs["sei_pcs_s3"]
sei_old_s3 = dfs["sei_old_s3"]
mdic_port = dfs["mdic_port"]
cd = dfs["cd"]
merged_df = dfs["merged_df"]

Country of import

In a supply chain mapping, the country of import refers to the country where the beef produced in Brazil is being shipped or transported to. This means that once the beef is processed and packaged in Brazil, it is then exported to another country where it will be sold or consumed.

The country of import is an important part of the supply chain mapping exercise because it helps to identify the different countries that are involved in the production and distribution of beef, as well as the various stages of the supply chain where potential risks or issues may arise. By understanding the country of import, we can adress the exposure to deforestation and emissions to countries.

It is important to mention that after 2018 the country of import is the country of first import, not the destination one. This is due to the change in the datasets where the country is coming from.

What is the difference between Customs Declaration and SEI-PCS version 2.2 in terms of volume per country of import?

After 2018, Customs Declaration changed from MDIC port to Bills of Lading (BoL) dataset. So this check is important to see how well our model is performing.

group_by = "COUNTRY_OF_IMPORT"
color_discrete_map = COLORS[group_by]
plot_grouped_by_dumbbell_comparision(sei_pcs_s3, cd, group_by)

Market Share - Country of import

Mapping the market share of countries that are buying the exported production of beef products from Brazil is important to analyze the link between deforestation, emissions, and the global beef supply chain. Market share refers to the percentage of total sales within a particular industry or market that a particular company, product, or country holds. In the context of countries buying beef products from Brazil, market share would refer to the percentage of total exports that are being bought by each individual country.

Calculating the market share of countries buying beef exports from Brazil involves determining the volume of beef products that each country purchases from Brazil and then comparing it to the total volume of beef exports from Brazil. This allows researchers to identify the countries that are the largest consumers of Brazilian beef products and their corresponding market share. Countries with higher market share are likely to have a more significant impact on the Brazilian beef industry's practices and policies, including land-use practices, cattle breeding, and feed production.

In the point of view of QA, the analyzis of the dinamycs of the market share over time can provide insights on what is happening on our model. For example, if a country's market share follows a certain trajectory, and in one year there is an outlier behavior, it is likely that there is something happening on the model. However, it is important to keep in mind that after 2018, the country of import is no longer the country of destination of the export, but rather the country of first import.

plot_market_share(group_by, color_discrete_map, sei_pcs_s3)

Which brazilian regions are countries importing beef?

Analyzing which Brazilian states are countries importing beef from is a crucial step in assessing the quality of the model that maps the supply chain of beef produced in Brazil. This analysis is important because it helps to verify the accuracy and completeness of the data used in the model and to validate the underlying assumptions and hypotheses of the model.

Mapping the import destinations of Brazilian beef to the specific states that are producing the beef can help to identify potential gaps or inconsistencies in the data used in the model. For example, if the model is suggesting that a particular state is exporting a large amount of beef to a particular country, but the actual data shows that the state is not a major producer of beef, this could indicate an error or omission in the data used in the model (specially the solver between the municipality of production and the port of export). This type of analysis can help to identify data quality issues that need to be addressed in order to improve the accuracy of the model.

Also, this type of analysis allow us to identify the level of unknown flows per country present in our data. If some country has a large amount of unknown flows if compared to the other countries, then we can identify problems in the solver.

plot_state_grouped_by(sei_pcs_s3, group_by)

Port

Understanding the ports of exports is important when mapping the supply chain for beef production from Brazil because it provides valuable information about the logistics and transportation involved in exporting the product.

Ports play a crucial role in the supply chain as they are the primary point of departure for products being shipped to international markets. By understanding which ports are used to export beef from Brazil, we can gain insights into the transportation routes, shipping methods, and shipping companies involved in getting the product from the farms and processing facilities to the final destination.

The port analysis can be usefull for quality assurance, to understand which logistic hubs and municipality of production are sourcing to each port.

Volume product per port comparision between SEI-pcs and CD over the years

Compare difference in volume product between Customs Declaration and SEI-PCS model for port of export.

group_by = "PORT"
color_discrete_map = COLORS[group_by]
plot_grouped_by_dumbbell_comparision(sei_pcs_s3, cd, group_by)

Market share per Port over the years

The market share is calculated on the same way it was for country of import. But instead of calculating the volume per country of import divided by the total volume exported, we calculateD the volume exported per port divided by the total volume exported.

plot_market_share(group_by, color_discrete_map, sei_pcs_s3)

Volume percentage per state per year for port of export

Checking which states are exporting through each export port can be an important aspect of tracking the beef supply chain and ensuring quality assurance. If a port is exporting a higher percentage of states far from the port, it is a point of attention to check.

plot_state_grouped_by(sei_pcs_s3, group_by)

Export percentage per port per product over the years

Based on the HS6 codes, we can calculate the amount of products that are being exported over the years.

plot_hs4_grouped_by(group_by, color_discrete_map)

Exporter

Market share over the years

group_by = "EXPORTER_GROUP"
color_discrete_map = COLORS[group_by]
plot_market_share(group_by, color_discrete_map)

Number of logistic Hubs sourcing to exporter groups over the year

plot_number_lh(group_by, color_discrete_map)

Export percentage per exporter group per product over the years

plot_hs4_grouped_by(group_by, color_discrete_map)

Biome

Market share over the years

group_by = "BIOME"
color_discrete_map = COLORS[group_by]
plot_market_share(group_by, color_discrete_map)

Export percentage per biome per product over the years

plot_hs4_grouped_by(group_by, color_discrete_map)

Importer

Volume product between SEI-pcs and CD per importer over the years

group_by = "IMPORTER_GROUP"
color_discrete_map = COLORS[group_by]
plot_grouped_by_dumbbell_comparision(sei_pcs_s3, cd, group_by)