def _cef_piij(self, i, j): dmu_t = self._dmus_t[i] dmu_t1 = self._dmus_t1[i] if dmu_t.co2[j] != 0.0 and dmu_t1.co2[j] != 0.0: number1 = dmu_t.co2[j] / self._lmdi.co2_sum_t number2 = dmu_t1.co2[j] / self._lmdi.co2_sum_t1 numerator1 = Lmdi.l_function(number1, number2) / self._lmdi.ll cef_i_j_t = self._cef_t[i][j] cef_i_j_t1 = self._cef_t1[i][j] denumnerator1 = Lmdi.l_function(cef_i_j_t1, cef_i_j_t * self.cef) return numerator1 * cef_i_j_t / denumnerator1 else: return 0.0
def _peiij(self, i, j): dmu_t = self._dmus_t[i] dmu_t1 = self._dmus_t1[i] if dmu_t.co2[j] != 0.0 and dmu_t1.co2[j] != 0.0: sij_t = dmu_t.energy[j] / dmu_t.energy.total sij_t1 = dmu_t1.energy[j] / dmu_t1.energy.total __l = Lmdi.l_function(sij_t1, sij_t * exp(sum(list(self._lmdi.emx())))) __L = Lmdi.l_function(dmu_t1.co2[j] / self._lmdi.co2_sum_t1, dmu_t.co2[j] / self._lmdi.co2_sum_t) return __L * sij_t / self._lmdi.ll / __l elif dmu_t.co2[j] != 0.0 and dmu_t1.co2[j] == 0.0: cijt = dmu_t.co2[j] / self._lmdi.co2_sum_t return cijt / self._lmdi.ll / exp(sum(list(self._lmdi.emx()))) else: return 0.0
def __init__(self, dmus_t, dmus_t1, name, global_dmus, cefs): self._dmus_t = dmus_t self._dmus_t1 = dmus_t1 self._cefs = cefs self._name = name self._format() self._cache = {} self._lmdi = Lmdi.build(self._dmus_t, self._dmus_t1, self._name, global_dmus, cefs)
def _wi(self, idx): result = 0.0 dmu_t = self._dmus_t[idx] dmu_t1 = self._dmus_t1[idx] for j in range(self._lmdi.energy_count): if dmu_t.co2[j] != 0.0 and dmu_t1.co2[j] != 0.0: number1 = dmu_t.co2[j] / self._lmdi.co2_sum_t number2 = dmu_t1.co2[j] / self._lmdi.co2_sum_t1 result += Lmdi.l_function(number1, number2) return result / self._lmdi.ll
def _rij(self, i, j, emx): dmu_t = self._dmus_t[i] dmu_t1 = self._dmus_t1[i] if dmu_t.co2[j] != 0.0 and dmu_t1.co2[j] != 0.0: sij_t = dmu_t.energy[j] / dmu_t.energy.total sij_t1 = dmu_t1.energy[j] / dmu_t1.energy.total l_upper = Lmdi.l_function(dmu_t1.co2[j] / self._lmdi.co2_sum_t1, dmu_t.co2[j] / self._lmdi.co2_sum_t) l_low = Lmdi.l_function(sij_t1, sij_t * emx) return (1.0 / self._LL) * (1.0 / self._lmdi.ll) \ * (l_upper / l_low) * (sij_t1 - sij_t) elif dmu_t.co2[j] != 0.0 and dmu_t1.co2[j] == 0.0: cij_t = dmu_t.co2[j] / self._lmdi.co2_sum_t return -1.0 * (1.0 / self._lmdi.ll) * (1.0 / self._LL) * (cij_t / (emx)) elif dmu_t.co2[j] == 0.0 and dmu_t1.co2[j] != 0.0: cij_t = dmu_t1.co2[j] / self._lmdi.co2_sum_t1 return (1.0 / self._lmdi.ll) * (1.0 / self._LL) * cij_t else: return 0.0
def _attribution_r(self, func, index): index_key = 'r' + index if index_key not in self._cache: result = [] for idx, dmu_t_t1 in enumerate(zip(self._dmus_t, self._dmus_t1)): __wi = self._wi(idx) value_t = func(dmu_t_t1[0], idx) value_t1 = func(dmu_t_t1[1], idx, False) pii = __wi / Lmdi.l_function(value_t1, value_t * getattr(self, index)) result.append(pii * value_t) total = sum(result) self._cache[index_key] = [item / total for item in result] return self._cache[index_key]
def __init__(self, config): reader = ExcelReader(config) dmus_2006 = reader.read_dmus("2006") dmus_2007 = reader.read_dmus("2007") dmus_2008 = reader.read_dmus("2008") dmus_2009 = reader.read_dmus("2009") dmus_2010 = reader.read_dmus("2010") dmus_2011 = reader.read_dmus("2011") dmus_2012 = reader.read_dmus("2012") dmus_2013 = reader.read_dmus("2013") dmus_2014 = reader.read_dmus("2014") cefs = reader.read_cef("2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", '2014') global_dmus = [dmus_2006, dmus_2007, dmus_2008, dmus_2009, dmus_2010, dmus_2011, dmus_2012, dmus_2013, dmus_2014] self.lmdi_2006_2007 = Lmdi.build(dmus_2006, dmus_2007, '2006-2007', global_dmus, cefs) self.lmdi_2007_2008 = Lmdi.build(dmus_2007, dmus_2008, '2007-2008', global_dmus, cefs) self.lmdi_2008_2009 = Lmdi.build(dmus_2008, dmus_2009, '2008-2009', global_dmus, cefs) self.lmdi_2009_2010 = Lmdi.build(dmus_2009, dmus_2010, '2009-2010', global_dmus, cefs) self.lmdi_2010_2011 = Lmdi.build(dmus_2010, dmus_2011, '2010-2011', global_dmus, cefs) self.lmdi_2011_2012 = Lmdi.build(dmus_2011, dmus_2012, '2011-2012', global_dmus, cefs) self.lmdi_2012_2013 = Lmdi.build(dmus_2012, dmus_2013, '2012-2013', global_dmus, cefs) self.lmdi_2013_2014 = Lmdi.build(dmus_2013, dmus_2014, '2013-2014', global_dmus, cefs) self.spaam_2006_2007 = Spaam.build(dmus_2006, dmus_2007, '2006-2007', global_dmus, cefs) self.spaam_2007_2008 = Spaam.build(dmus_2007, dmus_2008, '2007-2008', global_dmus, cefs) self.spaam_2008_2009 = Spaam.build(dmus_2008, dmus_2009, '2008-2009', global_dmus, cefs) self.spaam_2009_2010 = Spaam.build(dmus_2009, dmus_2010, '2009-2010', global_dmus, cefs) self.spaam_2010_2011 = Spaam.build(dmus_2010, dmus_2011, '2010-2011', global_dmus, cefs) self.spaam_2011_2012 = Spaam.build(dmus_2011, dmus_2012, '2011-2012', global_dmus, cefs) self.spaam_2012_2013 = Spaam.build(dmus_2012, dmus_2013, '2012-2013', global_dmus, cefs) self.spaam_2013_2014 = Spaam.build(dmus_2013, dmus_2014, '2013-2014', global_dmus, cefs) years = { 0: '2006', 1: '2007', 2: '2008', 3: '2009', 4: '2010', 5: '2011', 6: '2012', 7: '2013', 8: '2014', } self.mpaam_2006_2007 = Mpaam([dmus_2006, dmus_2007], '2006-2007', global_dmus, cefs, years) self.mpaam_2006_2008 = Mpaam([dmus_2006, dmus_2007, dmus_2008], '2006-2008', global_dmus, cefs, years) self.mpaam_2006_2009 = Mpaam([dmus_2006, dmus_2007, dmus_2008, dmus_2009, ], '2006-2009', global_dmus, cefs, years) self.mpaam_2006_2010 = Mpaam([dmus_2006, dmus_2007, dmus_2008, dmus_2009, dmus_2010], '2006-2010', global_dmus, cefs, years) self.mpaam_2006_2011 = Mpaam([dmus_2006, dmus_2007, dmus_2008, dmus_2009, dmus_2010, dmus_2011], '2006-2011', global_dmus, cefs, years) self.mpaam_2006_2012 = Mpaam([dmus_2006, dmus_2007, dmus_2008, dmus_2009, dmus_2010, dmus_2011, dmus_2012], '2006-2012', global_dmus, cefs, years) self.mpaam_2006_2013 = Mpaam([dmus_2006, dmus_2007, dmus_2008, dmus_2009, dmus_2010, dmus_2011, dmus_2012, dmus_2013], '2006-2013', global_dmus, cefs, years) self.mpaam_2006_2014 = Mpaam([dmus_2006, dmus_2007, dmus_2008, dmus_2009, dmus_2010, dmus_2011, dmus_2012, dmus_2013, dmus_2014], '2006-2014', global_dmus, cefs, years) self.province_names = self.lmdi_2006_2007.province_names