Esempio n. 1
0
 def get_mask(quant, rel, trend):
     pvalue = emission_diagnostic_batch[quant, "pval"]
     # pmask = ij.map_ij(lambda trend, pvalue: 1 if (pvalue > 0.5) else 0,
     #                     trend, pvalue)
     avg = absolute_emission_trends_batch.get_avg(quant)
     nmask = ij.map_ij(lambda a: 0 if a>=1e5 else 1, avg)
     return np.logical_or(h.na_ocean_mask, ij.ij_to_array(nmask))
Esempio n. 2
0
def totalled_values(spcs, year, iteration):
    pattern = search_pattern(spcs, ".+", iteration)
    datablocks = data[year].match(pattern).values()
    try:
        total_ems = map_ij(h.add, *datablocks)
    except TypeError as e: #in case of failure, print debugging info
        print pattern
        print datablocks
        raise e
    return total_ems
Esempio n. 3
0
 def __process__(self, year):
     bc, oc = self.bcoc_emissions(year)
     ra, rb = self.ra, self.rb
     an, bf = ij.map_ij(self.invert, ra, rb, bc, oc)
     return an, bf
Esempio n. 4
0
 def __process__(self, quant):
     ems = self.get_ems(quant)
     trend = ij.map_ij(self.trend, *ems)
     return trend
Esempio n. 5
0
 def __process__(self, quant):
     ems = self.get_ems(quant)
     trend = ij.map_ij(self.trend, *ems)
     avg = self.get_avg(quant)
     return ij.map_ij(lambda t,a: 100.0 * t / a, trend, avg)
Esempio n. 6
0
 def get_avg(self, quant):
     return ij.map_ij(lambda *a: self.avg(a), *self.get_ems(quant))
Esempio n. 7
0
 def __process__(self, quant, diag):
     ems = self.get_ems(quant)
     d = ij.map_ij(self.diag_getter(diag), *ems)
     return d
Esempio n. 8
0
import helpers.ij_tools as ij

from emissions import opt_ems_batch, get_totalled_ij
# Import bc and oc by:
#    [bc, oc]
#    [anth, biob, biof, biog, total]
#    years
#    iterations

raw_anth_bc = [get_totalled_ij("bc", yr, 1) for yr in years]
raw_anth_oc = [get_totalled_ij("oc", yr, 1) for yr in years]

def sub(a,b): return a - b

ast_biof_bc = [ij.map_ij(sub,
                         opt_ems_batch["bc", yr, 9],
                         rab) for yr, rab in zip(years, raw_anth_bc)]
ast_biof_oc = [ij.map_ij(sub,
                         opt_ems_batch["oc", yr, 9],
                         rab) for yr, rao in zip(years, raw_anth_oc)]

def fname(spcs, yr):
    name = "{}.{}.png".format(spcs, yr)
    return os.path.join("./plt/const_anth/", name)

if __name__ == "__main__":
    for bc, oc, year in zip(ast_biof_bc, ast_biof_oc, years):
        plot_ij(bc,
                filename=fname("bc", yr))
        plot_ij(oc,
                filename=fname("oc", yr))
Esempio n. 9
0
def search_pattern(spcs, sector, iteration):
    template = "{spcs}_{sector}.{long_spcs}.{iteration}.dat"
    vals = {"spcs": spcs, "sector": sector, "iteration": iteration,
            "long_spcs": {"bc":"blkc", "oc":"orgc"}[spcs]}
    return template.format(**vals)

def log_ratio(opt, prior):
    if prior == 0.0:
        return 0.0
    else:
        return np.log(opt/prior)


def plot(ij, spcs, sector, year):
    title = "Log(opt/prior) for {} {} {}".format(spcs, sector, year)
    filename = os.path.join(plt_dir,
                            "{}_{}_{}.png".format(spcs, sector, year))
    h.plot_ij(ij, filename, title, cblabel="log(opt/prior)",
              vmin=-2,vmax=2)


if __name__ == "__main__":
    for year, dd in zip(h.years, h.data_dirs):
        for spcs, sector in it.product(species, sectors):
            prior = dd.match(search_pattern(spcs, sector, "1")).values()
            opt = dd.match(search_pattern(spcs, sector, str(h.iterations[-1]))).values()
            assert len(prior)==1 and len(opt)==1
            prior, opt = prior[0], opt[0]
            ratio = map_ij(log_ratio, opt, prior)
            plot(ratio, spcs, sector, year)