RUFAS.routines.EEE.emissions module#
- RUFAS.routines.EEE.emissions.FINAL_DAY_SLICE_START = -1#
These are constants for calculating the embedded emissions of synthetic nitrogen and phosphorus fertilizer. Their units are in kg CO2e / kg N and kg CO2e / kg P, respectively. The nitrogen and phosphorus constants reference IPCC 2021, GWP 100, the potassium constant references BASF’s Eco-efficiency analysis tool.
- class RUFAS.routines.EEE.emissions.EmissionsEstimator#
Bases:
object
Estimates emissions associated with purchased feeds used for animals.
Attributes#
- imInputManager
An instance of the InputManager class.
- omOutputManager
An instance of the OutputManager class.
- crop_species_to_purchased_feed_iddict[str, list[str]]
A dictionary mapping crop species to their corresponding RuFaS feed IDs.
- __init__() None #
- estimate_emissions() None #
- _calculate_purchased_feed_emissions(homegrown_feeds: list[dict[str, Any]]) None #
- _gather_homegrown_feeds_and_fertilizer_apps() dict[str, list[dict[str, Any]]] #
Gathers the yields that were harvested and fertilizer applications that were applied in the last 365 days of the simulation.
- _gather_ration_feed_totals() dict[str, float] #
Collects totals of feeds from rations given to animals in the last 365 days of the simulation and collapses them into single set of numbers.
- _transform_outputs_to_list_of_dicts(data: dict[str, Any]) list[dict[str, Any]] #
Transforms dictionary of lists collected from the Output Manager into list of dictionaries.
Examples#
>>> a = {'one': {'values': [1, 2, 3]}, 'two': {'values': [4, 5, 6]}} >>> _transform_outputs_to_list_of_dicts(a) [{'one': 1, 'two': 4}, {'one': 2, 'two': 5}, {'one': 3, 'two': 6}]
- _calculate_actual_purchased_feeds(homegrown_feeds: list[dict[str, Any]], purchased_feeds: dict[str, float]) dict[str, float] #
Calculates the difference between the purchased feeds and feeds grown on the farm.
- _calculate_total_homegrown_feed_amounts_by_crop_type(homegrown_feeds: list[dict[str, Any]]) dict[str, float] #
Calculates the total amount of each crop species grown on the farm.
- _calculate_actual_purchased_feed_emissions(actual_purchased_feeds: dict[str, float]) tuple[dict[str, float], dict[str, float]] #
Calculates the emissions from feeds that were actually purchased during the simulation.
- _get_feed_emissions_data(county_code: int, feed_emissions_data: dict[str, list[float]]) dict[str, float] #
Grabs the appropriate list of emissions for purchased feeds for the location of the simulation.
- _calculate_homegrown_feed_emissions(homegrown_feeds: list[dict[str, Any]], fertilizer_applications: list[dict[str, Any]], manure_applications: list[dict[str, Any]], manure_requests: list[dict[str, Any]]) None #
Calculates the emissions associated with feeds grown on the farm.
- _collect_target_soil_characteristics(field_names: list[str]) dict[str, dict[str, Any]] #
Collects the emissions and soil carbon characteristics used to calculate farm-grown feed emissions.
- _calculate_emissions_by_field(field_name: str, feeds_grown: list[dict[str, Any]], field_emissions: dict[str, float], manure_applications: dict[str, float], manure_requests: dict[str, float], fertilizer_applications_data: list[dict[str, Any]]) list[dict[str, Any]] #
Partitions emissions from the field where crops/feeds were grown to those crops.
- _partition_applied_crop_fertilizer_emissions(fertilizer_application: dict[str, float], applied_crops: list[dict[str, Any]]) None #
Partitions synthetic emissions from fertilizer applications to crop(s) whose planting and harvesting dates encompass the fertilizer application date.
- _filter_results(filters: dict[str, Any], date_cutoff: date, year_key: str, day_key: str) list[dict[str, Any]] #
This method help with filtering data based on the timeframe provided.
Parameters#
- filters: dict[str, Any]
A filter to collect the desired data from OutputManager.
- date_cutoff: datetime
Date before which all data collected from the Output Manager is filtered out.
- year_key: str
How the key is named for the year data retrieved from OM.
- day_key: str
How the key is named for the day data retrieved from OM.
Returns#
- list[dict[str, Any]]
Filtered result of the retrieved data.
- _aggregate_data(operations: list[dict[str, Any]], all_fields: list[str], nutrients: list[str]) dict[str, dict[str, float]] #
Aggregate nutrient data for different types of applications (fertilizer, manure, etc.).
Parameters#
- operationslist[dict[str, Any]]
A list of application dictionaries. Each dictionary contains the field name and nutrient amounts. Example: {“field_name”: “Field1”, “nitrogen”: 50.0, “phosphorus”: 20.0}
- all_fieldslist[str]
A list of field names to aggregate data for, usually combining fields with crops and fields with applications.
- nutrientslist[str]
A list of nutrient keys to aggregate (e.g., [“nitrogen”, “phosphorus”, “potassium”]).
Returns#
- dict
A dictionary where keys are field names and values are dictionaries of aggregated nutrient values.
- _apply_fertilizer_to_next_crop(fertilizer_application: dict[str, Any], sorted_crops: list[dict[str, Any]], fertilizer_application_date: date) bool #
Applies fertilizer to the next available crop after harvest and before the next planting. Returns True if fertilizer was applied, False otherwise.
- _extract_applied_crops(sorted_crops: list[dict[str, Any]], fertilizer_application_date: date) list[dict[str, Any]] #
Extracts a list of crops that had fertilizer applied to them between their planting and harvesting dates.
Parameters#
- sorted_cropslist[dict[str, Any]]
The list of crops in the field sorted by planting date.
- fertilizer_application_datedate
The date of the fertilizer applciation.
Returns#
- list[dict[str, Any]]
A list of the crops whose planting and harvesting dates encompass the fertilizer application date.
- _soil_data_update(filters: dict[str, dict[str, Any]]) dict[str, int | Literal[0]] #
This method will update the soil data update according to data extracted using the filters.
Parameters#
- filters: dict[str, dict[str, Any]]
A dictionary of filters to retrieve data from the OM.
Return#
- dict[str, int | Literal[0]]
The updated soil data.