goblin_lite.scenario_analysis.data_grapher
The Data Grapher module is an experimental tool designed to visualize various environmental data sets. It primarily serves as a visualization aid, assisting users in interpreting complex environmental data through graphical representations. The module leverages data obtained from the DataFetcher class and provides functionalities to create diverse plots for different scenarios.
This module is still under development and may not function as intended in all situations. Users are encouraged to use this module as a basis for further customization and to adapt it to their specific data visualization needs.
Class Overview
The DataGrapher class offers methods to plot data related to crop and livestock life cycle assessment (LCA) emissions, land use emissions, forest carbon flux, and more. Each method is tailored to visualize specific types of data, providing insights into environmental impacts across various scenarios.
The class is designed to be flexible and user-friendly, allowing for easy integration with existing data analysis workflows. It is particularly useful for environmental researchers, policy makers, and analysts who require visual representations of data to support their work.
- - None
- Type:
The class does not require initialization with specific attributes.
- - plot_crop_livestock_lca_emissions_by_category(path): Visualizes combined crop and livestock LCA emissions by category for different scenarios.
- - plot_crop_lca_emissions_by_category(path): Displays crop LCA emissions by category for various scenarios.
- - plot_animal_lca_emissions_by_category(path): Shows livestock LCA emissions by category across different scenarios.
- - plot_land_use_emissions(path): Creates plots for land-use emissions by gas for each scenario.
- - plot_forest_flux(path, detail=False): Visualizes forest carbon annual flux for different scenarios.
- - plot_forest_aggregate(path, detail=False): Depicts aggregated forest carbon data over time.
- - plot_forest_flux_subplot(path): Generates subplots of forest carbon annual flux for each scenario.
- - get_combined_crop_and_livestock_pathway_frames(): Retrieves combined dataframes for crop and livestock pathway emissions.
- - rank_chart(target, gas, path): Creates a scatter plot showing the ranking and percentage change in GHG, ammonia, eutrophication, and protein output from the baseline.
- goblin_lite.scenario_analysis.data_grapher.Usage()
- -----
- To use the DataGrapher class, simply create an instance of the class and call the desired plotting method with the appropriate parameters.
- The methods will generate plots based on the provided data and save them to the specified file path.
- Example:
>>> data_grapher = DataGrapher() >>> data_grapher.plot_crop_livestock_lca_emissions_by_category("output/path")
Note
This module is experimental and may not cover all possible scenarios or data types. Users may need to modify or extend the module’s capabilities to suit their specific requirements.
The module relies on data provided by the DataFetcher class. Ensure that the data is correctly formatted and available before using the plotting methods.
The plots generated by this module are intended for data visualization and should be interpreted cautiously, especially in the context of complex environmental data.
Module Contents
Classes
A class used to organize methods for data visualization. The current collection is relatively limited, however, utilization of the |
- class goblin_lite.scenario_analysis.data_grapher.DataGrapher(DATABASE_PATH=None)[source]
A class used to organize methods for data visualization. The current collection is relatively limited, however, utilization of the DataFetcher class will allow users to output dataframes and easily construct their plots.
Though this class is still very much in development, it should still provide inspiration for various plotting pathways.
- DATABASE_PATH
Path to the external database, if None, default internal database used.
- Type:
str, optional
- plot_crop_livestock_lca_emissions_by_category(path):
Plot combined crop and livestock life cycle assessment (LCA) emissions by category for different scenarios.
- plot_crop_lca_emissions_by_category(path):
Plot crop LCA emissions by category (CO2E, NH3, and PO4E) for different scenarios.
- plot_animal_lca_emissions_by_category(path):
Plot livestock LCA emissions by category (CO2E, NH3, and PO4E) for different scenarios.
- plot_land_use_emissions(path):
Plot land-use emissions by gas (CO2, CH4, N2O) for different scenarios.
- plot_forest_flux(path, detail=False):
Plot forest carbon annual flux (tons of carbon) for different scenarios.
- plot_forest_aggregate(path, detail=False):
Plot aggregated forest carbon (tons of carbon) for different scenarios.
- plot_forest_flux_subplot(path):
Plot multiple subplots of forest carbon annual flux (tons of carbon) for each scenario.
- get_combined_crop_and_livestock_pathway_frames():
Get combined dataframes for crop and livestock pathway emissions.
- rank_chart(target, gas, path):
Plot a scatter plot of ranking and percentage change in greenhouse gas (GHG), ammonia, eutrophication, and protein output from the baseline.
- plot_crop_livestock_lca_emissions_by_category(path)[source]
Plot combined crop and livestock life cycle assessment (LCA) emissions by category for different scenarios.
This method generates a bar plot to visualize the emissions from combined crop and livestock activities for different scenarios. The emissions are categorized into different components, such as manure management, enteric emissions, emissions from grassland soils, and emissions from crop soils. Each component is represented by a different color for easy identification.
The bar plot is organized into three subplots, each corresponding to a different environmental impact category: climate change, air quality, and eutrophication.
- Parameters:
path (str) – The file path where the plot will be saved, including the file name and a legal format (e.g., png, jpg).
- Returns:
The plot is saved as an image file in the specified file path.
- Return type:
None
Note
The method utilizes the DataFetcher class to retrieve dataframes containing emissions data. It calls the get_combined_crop_and_livestock_pathway_frames() method to obtain the necessary data for plotting.
Example
>>> data_grapher = DataGrapher() >>> data_grapher.plot_crop_livestock_lca_emissions_by_category("path/to/directory")
- plot_crop_lca_emissions_by_category(path)[source]
Plot crop life cycle assessment (LCA) emissions by category for different scenarios.
This method generates a bar plot to visualize the emissions from crop activities for different scenarios. The emissions are categorized into different components, such as emissions from soils. Each component is represented by a different color for easy identification.
The bar plot is organized into three subplots, each corresponding to a different environmental impact category: climate change, air quality, and eutrophication.
- Parameters:
path (str) – The file path where the plot will be saved, including the file name and a legal format (e.g., png, jpg).
- Returns:
The plot is saved as an image file in the specified file path.
- Return type:
None
Note
The method utilizes the DataFetcher class to retrieve dataframes containing emissions data. It calls the necessary methods from DataFetcher (e.g., get_crop_emissions_by_category_co2e, get_eutrophication_crop_emissions_by_category, and get_air_quality_crop_emissions_by_category) to obtain the necessary data for plotting.
Example
>>> data_grapher = DataGrapher() >>> data_grapher.plot_crop_lca_emissions_by_category("path/to/directory")
- plot_animal_lca_emissions_by_category(path)[source]
Plot animal life cycle assessment (LCA) emissions by category for different scenarios.
This method generates a bar plot to visualize the emissions from animal-related activities for different scenarios. The emissions are categorized into different components, such as emissions from manure management and enteric fermentation. Each component is represented by a different color for easy identification.
The bar plot is organized into three subplots, each corresponding to a different environmental impact category: climate change, air quality, and eutrophication.
- Parameters:
path (str) – The file path where the plot will be saved, including the file name and a legal format (e.g., png, jpg).
- Returns:
The plot is saved as an image file in the specified file path.
- Return type:
None
Note
The method utilizes the DataFetcher class to retrieve dataframes containing emissions data. It calls the necessary methods from DataFetcher (e.g., get_animal_emissions_by_category_co2e, get_eutrophication_animal_emissions_by_category, and get_air_quality_animal_emissions_by_category) to obtain the necessary data for plotting.
Example
>>> data_grapher = DataGrapher() >>> data_grapher.plot_animal_lca_emissions_by_category("path/to/directory")
- plot_land_use_emissions(path)[source]
Plot land use emissions for different gases and scenarios.
This method generates a set of stacked bar plots to visualize the land use emissions for different gases and scenarios. The emissions are categorized by different land use types (e.g., forests, croplands, grasslands).
The bar plots are organized in a 2x2 grid, with each plot representing a different gas: CO2, CH4, N2O, and F-gases.
- Parameters:
path (str) – The file path where the plot will be saved, including the file name and a legal format (e.g., png, jpg).
- Returns:
The plot is saved as an image file in the specified file path.
- Return type:
None
Note
The method utilizes the DataFetcher class to retrieve dataframes containing land use emissions data. It calls the necessary methods from DataFetcher (e.g., get_landuse_emissions_totals) to obtain the necessary data for plotting.
Example
>>> data_grapher = DataGrapher() >>> data_grapher.plot_land_use_emissions("path/to/directory")
- plot_forest_flux(path, detail=False)[source]
Plot forest carbon flux over time.
This method generates a line plot to visualize the forest carbon flux over time. The forest carbon flux represents the net change in carbon stored in forests over different years and scenarios.
- Parameters:
path (str) – The file path where the plot will be saved, including the file name and a legal format (e.g., png, jpg).
detail (bool, optional) – If True, the plot will include additional details by plotting individual variables along with different scenarios. If False, the plot will only show scenarios without individual variables.
- Returns:
The plot is saved as an image file in the specified file path.
- Return type:
None
Note
The method utilizes the DataFetcher class to retrieve the forest carbon flux data. It calls the necessary methods from DataFetcher (e.g., get_forest_flux) to obtain the necessary data for plotting.
Example
>>> data_grapher = DataGrapher() >>> data_grapher.plot_forest_flux("path/to/directory", detail=True)
- plot_forest_aggregate(path, detail=False)[source]
Plot aggregated forest carbon data over time.
This method generates a line plot to visualize the aggregated forest carbon data over time. The aggregated forest carbon data represents the total carbon stored in forests over different years and scenarios.
- Parameters:
path (str) – The file path where the plot will be saved, including the file name and a legal format (e.g., png, jpg).
detail (bool, optional) – If True, the plot will include additional details by plotting individual variables along with different scenarios. If False, the plot will only show scenarios without individual variables.
- Returns:
The plot is saved as an image file in the specified file path.
- Return type:
None
Note
The method utilizes the DataFetcher class to retrieve the aggregated forest carbon data. It calls the necessary methods from DataFetcher (e.g., get_forest_aggregate) to obtain the necessary data for plotting.
Example
>>> data_grapher = DataGrapher() >>> data_grapher.plot_forest_aggregate("path/to/directory", detail=True)
- plot_forest_flux_subplot(path)[source]
Plot forest carbon flux data for multiple scenarios using subplots.
This method generates a set of line plots arranged in subplots to visualize the forest carbon flux data for multiple scenarios over time. Each subplot represents a different scenario, and the lines in each subplot represent the carbon flux values for different variables.
- Parameters:
path (str) – The file path where the plot will be saved, including the file name and a legal format (e.g., png, jpg).
- Raises:
Exception – If there are more than 20 scenarios present in the data, as it may lead to an overcrowded plot.
- Returns:
The plot is saved as an image file in the specified file path.
- Return type:
None
Note
The method utilizes the DataFetcher class to retrieve the forest carbon flux data for multiple scenarios. It calls the necessary methods from DataFetcher (e.g., get_forest_flux) to obtain the necessary data for plotting.
Example
>>> data_grapher = DataGrapher() >>> data_grapher.plot_forest_flux_subplot("path/to/directory")
- get_combined_crop_and_livestock_pathway_frames()[source]
Retrieve and combine the data related to combined crop and livestock pathway frames.
This method fetches data from different sources for livestock and crop emissions related to various environmental factors. It then combines the data into three distinct dataframes: one for climate change, one for eutrophication, and one for air quality. The data is collected from the DataFetcher class, which provides separate methods to obtain livestock and crop emissions data for different environmental factors.
- Returns:
- A list of three dataframes containing combined crop and livestock pathway data for climate change, eutrophication,
and air quality, respectively.
- Return type:
list
Note
The DataFetcher class is utilized to fetch the necessary data for livestock and crop emissions. The dataframe columns represent different environmental factors and pathways, such as “manure_management,” “enteric,” “grassland_soils,” and “crop_soils.” The data is combined appropriately into each of the three dataframes, with common columns for the respective environmental factors.
Example
>>> data_grapher = DataGrapher() >>> combined_frames = data_grapher.get_combined_crop_and_livestock_pathway_frames() >>> climate_change_frame = combined_frames[0] >>> eutrophication_frame = combined_frames[1] >>> air_quality_frame = combined_frames[2]
- rank_chart(target, gas, path)[source]
Produces a scatter plot that visualizes the data output from the Filter_results.search() method. The data returned from Filter_results.search() is plotted along the x and y axes. The y-axis represents the percentage change in the specific variable from the baseline, and the x-axis represents the ranking of scenarios based on the “cost” calculated in the Filter_results.search() method. The “cost” is determined by the overall impact on total livestock output (beef and milk) from the baseline.
- Parameters:
target (str) – The target scenario or variable to compare. It can be “ghg” (Greenhouse Gas emissions), “ammonia” (ammonia emissions), “eutrophication” (eutrophication emissions), or “production” (protein output).
gas (str) – The selected gas emissions to consider. This can be “CO2e” (Carbon Dioxide Equivalent), “NH3” (ammonia), or “PO4” (eutrophication).
path (str) – The file path where the scatter plot will be saved, including the file name and a legal format (e.g., png, jpg).
- Returns:
A scatter plot representing the ranking of scenarios on the x-axis and the percentage change in the specified variable (e.g., greenhouse gas emissions, ammonia emissions, eutrophication emissions, or protein output) from the baseline on the y-axis.
- Return type:
Scatter Plot
Examples
>>> data_grapher = DataGrapher() >>> target_variable = "ghg" >>> selected_gas = "CO2e" >>> plot_path = "path/to/directory" >>> data_grapher.rank_chart(target_variable, selected_gas, plot_path)
Note
The method utilizes the DataFetcher class to fetch data related to climate change, eutrophication, air quality, and protein output.
It then combines the fetched data into a dictionary containing the scenario and relevant values for ranking, percentage changes in
greenhouse gas emissions, ammonia emissions, eutrophication emissions, and protein output from the baseline. - The scatter plot is generated with each scenario’s rank on the x-axis and the percentage change in the specified variable on the y-axis. - The plot includes multiple scatter plots, each representing one of the selected variables (e.g., gas emissions, eutrophication, ammonia, and protein output) to compare changes across different scenarios. - The scenarios are displayed on the secondary x-axis (ax2) with their corresponding ranks.