Skip to content

Assortments


Warning

This library is under development, none of the presented solutions are available for download.

Obtain the products generated by the forest inventory based on a product table. Use fitted taper functions to estimate commercial and non-commercial volume generated by the forest. Estimate volumes using fitted volumetric equations.


Class Parameters

Assortments(df, assortments_priority=None)
Parameters Description
df The dataframe containing the assortments data.
assortments_priority (Optional) The name of the column who defines the assortments priority. If None, uses the default order from the dataframe.

Class Functions

functions and parameters
  Assortments.get_assortments(model, model_path, trees_df, tree_dbh, tree_height,
                              stump=0.1, initial_height=None)#(1)!

  Assortments.get_taper_volumes(model, model_path, trees_df, tree_dbh,
                                tree_height, bark_factor=None, stump=0.1)#(2)!

  Assortments.get_volumes(model, model_path, trees_df, tree_dbh,
                          tree_height, bark_factor=None)#(3)!

  1. model = The name of the taper function or 'ann' to be used to calculate the assortments.
    model_path = Path to the .json file containing the coefficients of the fitted models or the .pkl file containing the fitted artificial neural network.
    trees_df = Pandas DataFrame containing the inventory for which the assortments should be calculated.
    tree_dbh = The name of the column containing the diameter at breast height (DBH) values in centimeters.
    tree_height = The name of the column containing the total height values of the trees in meters.
    stump = (Optional) Stump height value (meters) to be considered in the assortment calculation. If stump==None, it defaults to 0.1.
    initial_height = (Optional) Height (meters) at which the products begin to be generated. Useful for cases where the base of the tree was damaged by fire or used for resin extraction.

  2. model = The name of the taper function or taper 'ann' to be used to calculate the volume.
    model_path = Path to the .json file containing the coefficients of the fitted models or the .pkl file containing the fitted artificial neural network.
    trees_df = Pandas DataFrame containing the inventory for which the volumes should be calculated.
    tree_dbh = The name of the column containing the diameter at breast height (DBH) values in centimeters.
    tree_height = The name of the column containing the total height values of the trees in meters.
    bark_factor = (Optional) Value of the bark factor to be used to calculate volumes without bark.
    stump = (Optional) Stump height value (meters) to be considered in the volumes calculation. If stump==None, it defaults to 0.1.

  3. model = The name of the volumetric function or volumetric 'ann' to be used to calculate the volume.
    model_path = Path to the .json file containing the coefficients of the fitted models or the .pkl file containing the fitted artificial neural network.
    trees_df = Pandas DataFrame containing the inventory for which the volumes should be calculated.
    tree_dbh = The name of the column containing the diameter at breast height (DBH) values in centimeters.
    tree_height = The name of the column containing the total height values of the trees in meters.
    bark_factor = (Optional) Value of the bark factor to be used to calculate volumes without bark.

Methods Description
.get_assortments() Returns the trees_df dataframe with additional columns indicating the number of products generated for each assortment, as well as the volume generated for each assortment in each tree. Calculates also the comercial volume, the total volume of the tree and also the wasted volume.
.get_taper_volumes() Returns the trees_df with the volumes calculated based on the integration of taper functions. It calculates the total volume with bark and without bark.
.get_volumes() Returns the trees_df with the volumes calculated based on the fitted volumetric functions. It calculates the total volume with bark and without bark.

Example Usage

Consider a forest inventory dataset composed of 50 Eucalyptus trees, for which diameter at breast height (DBH) and total height were measured.

Download the file.

First 5 rows of the file:

Fazenda Árvore DAP (cm) HT (m)
Fazenda 1 1 24.8 28.0
Fazenda 1 2 21.2 27.1
Fazenda 1 3 26.8 37.8
Fazenda 1 4 37.6 43.0
Fazenda 1 5 35.7 42.8

For this module to work, it is necessary to specify a DataFrame containing the description of the products to be extracted from each tree. This table must include, for each product, the following information: product name, minimum and maximum length, minimum diameter, cutting loss (caused by the equipment saw), and optionally, a column defining the extraction priority for each product.

Example of assortments table

Product Length min (m) Length max (m) D min (cm) Loss (cm) Priority
Prod. 1 4.5 5 15 0.5 1
Prod. 2 2 2 8 0.5 2
Prod. 3 1 1 3 0.5 3

The column order must be followed.

taper_functions_example.py
1
2
3
from fptools.assortments import Assortments#(1)!

import pandas as pd#(2)!

  1. Import Assortments class.
  2. Import pandas for data manipulation.

For this example, we will use the equations fitted for the iterator "Fazenda 1". Thus, we will filter the data to calculate products only for the trees from "Fazenda 1". We will use the files generated by the Volumetrics module.

Download the file taper_functions_coefficients_Fazenda 1.json.

Download the file volumetrics_functions_coefficients_Fazenda 1.json.

taper_functions_example.py
assortments_df = pd.read_excel(r'C:\your\path\sortimentos.xlsx')#(1)!

inventory_df = pd.read_excel(r'C:\your\path\dados_inventario.xlsx')#(2)!

inventory_df = inventory_df[inventory_df['Fazenda'] == "Fazenda 1"]#(3)!

Prod = Assortments(assortments_df)#(4)!

assortments = Prod.get_assortments('kozak',
                                   r"D:\Your\path\for\taper_functions_coefficients_Fazenda 1.json",
                                   inventory_df, "DAP", "HT")#(5)!

taper_volumes = Prod.get_taper_volumes('bi',
                                       r"D:\Your\path\for\taper_functions_coefficients_Fazenda 1.json",
                                       inventario, "DAP", "HT", .9)#(6)!  

volumes = Prod.get_volumes('meyer', 
                           r"D:\Your\path\for\volumetrics_functions_coefficients_Fazenda 1.json",
                           inventario, "DAP", "HT", .85)#(7)!

  1. Loads the assortments_df DataFrame from an xlsx file.
  2. Loads the inventory_df DataFrame from an xlsx file.
  3. Filters the data to include only rows where the Fazenda column is equal to Fazenda 1.
  4. Creates the Prod variable containing the Assortments class using the assortments_df DataFrame as the products.
  5. Calculates assortments for each tree in the inventory_df using the kozak model, the DAP column for DBH values, and the HT column for tree height values, storing the result in the assortments variable.
  6. Calculates volumes by integrating the bi function for each tree in the inventory_df using the bi model, the DAP column for DBH values, and the HT column for tree height values. A bark factor of 90% is also applied.
  7. Calculates volumes using the volumetric function for each tree in the inventory_df using the meyer model, the DAP column for DBH values, and the HT column for tree height values. A bark factor of 85% is also applied.

Outputs

Tables

assortments(1)

  1. Initial DataFrame with the following additional columns:
    For each product defined in the assortments_df table, two columns will be created: one indicating the number of products extracted per tree and another showing the total volume generated (in cubic meters) for that product.
    Additionally, the DataFrame will include the columns commercial_volume, tree_volume, and wasted_volume, which represent, respectively, the utilized commercial volume, the total tree volume, and the volume of wasted wood.
Fazenda Árvore DAP HT Prod. 1_quantity Prod. 1_volume Prod. 2_quantity Prod. 2_volume Prod. 3_quantity Prod. 3_volume commercial_volume tree_volume wasted_volume
Fazenda 1 1 24.84076433 28 2 0.36529298 5 0.160465831 6 0.022446226 0.548205036 0.548793726 0.00058869
Fazenda 1 2 21.17834395 27.1 1 0.15662905 7 0.205798888 5 0.016228224 0.378656162 0.379971069 0.001314907
Fazenda 1 3 26.81528662 37.8 4 0.738422477 5 0.129884459 5 0.016047425 0.884354362 0.88558894 0.001234578
Fazenda 1 4 37.57961783 43 6 1.899253966 3 0.090801352 5 0.021413892 2.01146921 2.01247906 0.00100985
Fazenda 1 5 35.66878981 42.8 6 1.705021305 3 0.07966354 5 0.018106349 1.802791194 1.803503982 0.000712789

taper_volumes(1)

  1. Initial DataFrame with the following additional columns:
    Tree_volume: Total tree volume calculated by integrating the specified taper function.
    Tree_volume_without_bark: Tree_volume multiplied by the specified bark factor.
Fazenda Árvore DAP HT Tree_volume Tree_volume_without_bark
Fazenda 1 1 24.84076433 28 0.545157869 0.490642083
Fazenda 1 2 21.17834395 27.1 0.38299769 0.344697921
Fazenda 1 3 26.81528662 37.8 0.870697291 0.783627562
Fazenda 1 4 37.57961783 43 2.005436616 1.804892954
Fazenda 1 5 35.66878981 42.8 1.790646854 1.611582169

volumes(1)

  1. Initial DataFrame with the following additional columns:
    Tree_volume: Total tree volume calculated using the specified volumetric equation.
    Tree_volume_without_bark: Tree_volume multiplied by the specified bark factor.
Fazenda Árvore DAP HT Tree_volume Tree_volume_without_bark
Fazenda 1 1 24.84076433 28 0.545157869 0.490642083
Fazenda 1 2 21.17834395 27.1 0.38299769 0.344697921
Fazenda 1 3 26.81528662 37.8 0.870697291 0.783627562
Fazenda 1 4 37.57961783 43 2.005436616 1.804892954
Fazenda 1 5 35.66878981 42.8 1.790646854 1.611582169

If the user wants to use one of the neural network models trained for each function, simply replace the model name with ann and specify the directory of the .pkl file containing the parameters of the trained neural network.

Download the file taper_model_ann_Fazenda 1.pkl.

Download the file volumetric_ann_Fazenda 1.pkl.

taper_functions_example.py
assortments = Prod.get_assortments('ann',
                                   r"D:\Your\path\for\taper_model_ann_Fazenda 1.pkl",
                                   inventory_df, "DAP", "HT")#(1)!

taper_volumes = Prod.get_taper_volumes('ann',
                                       r"D:\diretorio\para\taper_model_ann_Fazenda 1.pkl",
                                       inventario, "DAP", "HT", .9)#(2)!  

volumes = Prod.get_volumes('ann', 
                           r"D:\Your\path\for\volumetric_ann_Fazenda 1.pkl",
                           inventario, "DAP", "HT", .85)#(3)!

  1. Calculates assortments for each tree in the inventory_df using artificial neural networks, the DAP column for DBH values, and the HT column for tree height values, saving the result in the assortments variable.
  2. Calculates volumes by integrating the artificial neural network for each tree in the inventory_df, using the DAP column for DBH values and the HT column for tree height values. A bark factor of 90% is also applied.
  3. Calculates volumes using a volumetric artificial neural network for each tree in the inventory_df, using the DAP column for DBH values and the HT column for tree height values. A bark factor of 85% is also applied.