forked from ProjectDrawdown/solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathn2ocalcs.py
69 lines (55 loc) · 2.47 KB
/
n2ocalcs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""N2O Calcs module.
"""
from functools import lru_cache
import numpy as np
import pandas as pd
from model.data_handler import DataHandler
from model.decorators import data_func
from model import emissionsfactors
class N2OCalcs(DataHandler):
"""N2O Calcs module.
Arguments:
ac: advanced_cost.py object, storing settings to control model operation.
soln_net_annual_funits_adopted: annual functional/land units
soln_pds_direct_n2o_co2_emissions_saved: direct n2o emissions avoided per land unit
(not used for RRS).
"""
def __init__(self, ac, soln_net_annual_funits_adopted,
soln_pds_direct_n2o_co2_emissions_saved=None):
self.ac = ac
self.soln_net_annual_funits_adopted = soln_net_annual_funits_adopted
self.soln_pds_direct_n2o_co2_emissions_saved = soln_pds_direct_n2o_co2_emissions_saved
@lru_cache()
def n2o_tons_reduced(self):
"""n2o reduced from the RRS model, in tons n2o per year.
"""
if self.ac.n2o_is_co2eq:
ef = emissionsfactors.CO2Equiv(self.ac.co2eq_conversion_source)
result = (self.soln_net_annual_funits_adopted * self.ac.n2o_co2_per_funit)/ef.N2Omultiplier
else:
result = self.soln_net_annual_funits_adopted * self.ac.n2o_co2_per_funit
result.loc[:self.ac.report_start_year - 1] = 0.0
result.loc[self.ac.report_end_year + 1:] = 0.0
result.name = "n2o_tons_reduced"
return result
@lru_cache()
def avoided_direct_emissions_n2o_land(self):
"""n2o emissions avoided, in tons per year
"""
ef = emissionsfactors.CO2Equiv(self.ac.co2eq_conversion_source)
result = self.soln_pds_direct_n2o_co2_emissions_saved.copy(deep=True) / ef.N2Omultiplier
result.loc[:self.ac.report_start_year - 1] = 0.0
result.loc[self.ac.report_end_year + 1:] = 0.0
result.name = "avoided_direct_emissions_n2o_land"
return result
@lru_cache()
def n2o_megatons_avoided_or_reduced(self):
"""n2o emissions avoided or reduced, Mega in tons per year (units needed for the FaIR model)
"""
if self.soln_pds_direct_n2o_co2_emissions_saved is not None:
n2o_tons = self.avoided_direct_emissions_n2o_land()
else:
n2o_tons = self.n2o_tons_reduced()
result = n2o_tons * 0.000001
result.name = "n2o_megatons_avoided_or_reduced"
return result