Source code for hestia_earth.calculation.emissions.n2OToAirFertilizerAndExcretaDirectIpcc2006

from hestia_earth.calculation.abstract_model import Model
from hestia_earth.calculation.utils import summation
from hestia_earth.utils.api import download_hestia
from hestia_earth.calculation.data.constants.generic import ATOMIC_WEIGHT_CONVERSIONS

MODEL_KEY = 'n2OToAirFertilizerAndExcretaDirectAndIndirectIpcc2006'


[docs]class N2OToAirFertilizerAndExcretaDirectIpcc2006(Model): def __init__(self): # Define model tier self.tier = 1 self.term = download_hestia(MODEL_KEY) # Define model requirements self.inorgN_total = None self.orgN_total = None self.products = None # Instantiate variables self.n2OToAirInorganicFertilizerDirect = None self.n2OToAirOrganicFertilizerDirect = None # Define model coeffients self.N2ON_Fert = 0.01 # 1% of N in fertilizer emitted as N2O-N self.N2ON_FertPaddy = 0.003 # 0.3% in paddy fields self.ConvMol_N2ON_N2O = ATOMIC_WEIGHT_CONVERSIONS['Conv_Mol_N2ON_N2O'] def calculate_n2OToAirInorganicFertilizerDirect(self): # If the cycle is producing rice if 'riceGrain' in self.products: self.n2OToAirInorganicFertilizerDirect = self.inorgN_total \ * self.N2ON_FertPaddy * self.ConvMol_N2ON_N2O else: self.n2OToAirInorganicFertilizerDirect = self.inorgN_total \ * self.N2ON_Fert * self.ConvMol_N2ON_N2O return self.n2OToAirInorganicFertilizerDirect def calculate_n2OToAirOrganicFertilizerDirect(self): # If the cycle is producing rice if 'riceGrain' in self.products: self.n2OToAirOrganicFertilizerDirect = self.orgN_total \ * self.N2ON_FertPaddy * self.ConvMol_N2ON_N2O else: self.n2OToAirOrganicFertilizerDirect = self.orgN_total \ * self.N2ON_Fert * self.ConvMol_N2ON_N2O return self.n2OToAirOrganicFertilizerDirect def complete(self, completeness): self.inorgN_total = 0 if self.inorgN_total == {} and completeness['fertilizer'] else self.inorgN_total self.orgN_total = 0 if self.orgN_total == {} and completeness['fertilizer'] else self.orgN_total def check_n2OToAirInorganicFertilizerDirect(self, cycle): # Calculate total inorganic N fertilizer input inputs = cycle['inputs'].evalues() self.inorgN_total = summation([sum(input['value']) if 'units' in input['term'] and input['term']['units'] == 'kg N' and input['term']['termType'] == 'inorganicFertilizer' else 0 for input in inputs]) self.products = cycle['products'] self.complete(cycle['dataCompleteness']) return self.inorgN_total != {} and len(self.products) > 0 def check_n2OToAirOrganicFertilizerDirect(self, cycle): # Calculate total organic N fertilizer input inputs = cycle['inputs'].evalues() self.orgN_total = summation([sum(input['value']) if 'units' in input['term'] and input['term']['units'] == 'kg N' and input['term']['termType'] == 'organicFertilizer' else 0 for input in inputs]) self.products = cycle['products'] self.complete(cycle['dataCompleteness']) return self.orgN_total != {} and len(self.products) > 0