Functions
openyieldtables.yieldtables
get_yield_table(id)
Reads the yield table data for a specific yield table ID from
data/yield_tables.csv and returns a YieldTable instance.
The CSV file is expected to be in a specific format, with columns for
id, yield_class, age, dominant_height, average_height, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id |
int
|
The ID of the yield table to get the data for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
YieldTable |
YieldTable
|
A |
get_yield_table_from_df(id, meta_data, data)
Filters the yield table data for a specific yield table ID from a pandas DataFrame and returns a YieldTable instance.
The DataFrame is expected to be in a specific format, with columns for
id, yield_class, age, dominant_height, average_height, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id |
int
|
The ID of the yield table to get the data for. |
required |
meta_data |
pandas.DataFrame
|
DataFrame containing yield tables metadata. |
required |
data |
pandas.DataFrame
|
DataFrame containing yield tables data. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
YieldTable |
YieldTable
|
A |
get_yield_table_meta(id)
Reads the yield table metadata for a specific yield table ID from
data/yield_tables_meta.csv and returns a YieldTableMeta instance.
The CSV file is expected to be in a specific format, with columns for id,
title, country_codes, type, source, link, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id |
int
|
The ID of the yield table to get the metadata for. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the yield table with the specified ID is not found. |
Returns:
| Name | Type | Description |
|---|---|---|
YieldTableMeta |
YieldTableMeta
|
A |
get_yield_table_meta_from_df(id, meta_data)
Filters the yield table metadata from a pandas DataFrame for a specific yield table ID and returns a YieldTableMeta instance.
The DataFrame is expected to be in a specific format, with columns for
id, title, country_codes, type, source, link, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id |
int
|
The ID of the yield table to get the metadata for. |
required |
meta_data |
pandas.DataFrame
|
DataFrame containing yield tables metadata. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the yield table with the specified ID is not found. |
Returns:
| Name | Type | Description |
|---|---|---|
YieldTableMeta |
YieldTableMeta
|
A |
get_yield_tables_meta()
Reads the yield tables metadata from data/yield_tables_meta.csv and
returns a list of YieldTableMeta instances.
The CSV file is expected to be in a specific format, with columns for id,
title, country_codes, type, source, link, etc.
Returns:
| Type | Description |
|---|---|
List[YieldTableMeta]
|
List[YieldTableMeta]: A list of |
get_yield_tables_meta_from_df(meta_data)
Processes the yield tables metadata from a pandas DataFrame and returns a list of YieldTableMeta instances.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meta_data |
pandas.DataFrame
|
DataFrame containing yield tables
metadata with columns for |
required |
data |
pandas.DataFrame
|
DataFrame used to find available columns
based on |
required |
Returns:
| Type | Description |
|---|---|
List[YieldTableMeta]
|
List[YieldTableMeta]: A list of |
List[YieldTableMeta]
|
each row in the DataFrame. |
Usage
Get the metadata of all available yield tables
from openyieldtables.yieldtables import get_yield_tables_meta
# Get the metadata of all available yield tables
yield_tables_meta = get_yield_tables_meta() # Returns a list of `YieldTableMeta` objects
# Get the first yield table as dictionary
yield_table_meta = yield_tables_meta[0].model_dump()
#> {'id': 1, 'title': 'Fichte Hochgebirge', 'country_codes': ['AT', 'DE'],...}
Get the metadata of one specific yield table
from openyieldtables.yieldtables import get_yield_table_meta
# Get the metadata of a yield table by its ID
yield_table_meta = get_yield_table_meta(1) # Returns a `YieldTableMeta` object
# Get the yield table metadata as dictionary
yield_table_meta_dict = yield_table_meta.model_dump()
#> {'id': 1, 'title': 'Fichte Hochgebirge', 'country_codes': ['AT', 'DE'],...}
Get the data of one specific yield table
from openyieldtables.yieldtables import get_yield_table
# Get the data of a yield table by its ID
yield_table_data = get_yield_table(1) # Returns a `YieldTable` object
# Get one row of the yield table data as dictionary
yield_table_data.data[0].yield_classes[0].rows[0].model_dump()
#> {'age': 20, 'dominant_height': 5.9, 'average_height': 5.3, 'dbh': 11.5, 'taper': 0.396,...}