예제 #1
0
def pop_frac_reimbursement_costs():
    refresh_country_comparison()

    df = pd.read_csv('output/reverse_engineering/all_policies.csv').set_index(
        'Policy').sort_index()

    #df = pd.read_csv('output/reverse_engineering/all_policies.csv').set_index(['Policy','Net beneficiaries']).sort_index()
    try:
        df = df.drop('Median')
    except:
        pass
    try:
        df = df.drop('Median', axis=1)
    except:
        pass

    df.columns.name = 'Social spending to offset carbon tax'
    df.index.name = '(as % of total carbon revenue)'
    df = df.fillna('-')
    #df = df.astype('int')

    for _c in df.columns:
        if _c == 'Net beneficiaries': continue
        df = df.rename(columns={_c: iso_to_name[_c.lower()]})

    df = df[['Net beneficiaries'] +
            sorted([_c for _c in df.columns if _c != 'Net beneficiaries'])]
    df = df.sort_index(ascending=True)

    #df = df.sort_values(df.columns[0],ascending=False,na_position='last')
    df = df.fillna('-')
    df = df.round(1)

    df.insert(
        1, 'Median',
        df.median(axis=1, skipna=True).round(0).astype('int').fillna('-'))

    for _c in df.columns:
        if _c == 'Net beneficiaries' or _c == 'Median': continue
        df[_c] = df[_c].apply(lambda x: force_round(x))
        #for _c in df.columns:
        #    df.loc[df[_c].values.dtype=='float',_c].dtype = 'int'

    #df = df.sort_values('Median',ascending=True)
    df.to_latex('output/reverse_engineering/_all_policies.tex',
                column_format='@{}l' + col_form[3:])

    with open('output/reverse_engineering/_all_policies.tex', 'r') as f:
        with open('output/reverse_engineering/all_policies.tex', 'w') as f2:

            f2.write(r'\documentclass[preview=true]{standalone}' + '\n')
            f2.write(r'\usepackage{amssymb} %maths' + '\n')
            f2.write(r'\usepackage{amsmath} %maths' + '\n')
            f2.write(r'\usepackage{booktabs}' + '\n')
            f2.write(r'\usepackage{rotating}' + '\n')
            f2.write(r'\begin{document}' + '\n')

            reading_is_fundamental = f.read()

            reading_is_fundamental = reading_is_fundamental.replace(
                'Median', r'\rotatebox{90}{Median}').replace(
                    '(as \% of total carbon revenue) &',
                    '(as \% of total carbon revenue) & (\% of population)')
            for _n in iso_to_name:
                if _n == 'chi': continue
                reading_is_fundamental = reading_is_fundamental.replace(
                    iso_to_name[_n],
                    r'\rotatebox{90}{' + iso_to_name[_n] + '}')
            f2.write(reading_is_fundamental)

            f2.write(r'\end{document}')
            f2.close()

    subprocess.call(
        'cd ~/Box\ Sync/stranded\ jobs\ and\ distributional\ impacts/output/reverse_engineering/; pdflatex all_policies.tex',
        shell=True)

    for f in glob.glob('output/reverse_engineering/*.aux'):
        os.remove(f)
    for f in glob.glob('output/reverse_engineering/*.log'):
        os.remove(f)
    for f in glob.glob('output/reverse_engineering/_*.tex'):
        os.remove(f)
예제 #2
0
def q12_reimbursement_costs():
    refresh_country_comparison()

    df = pd.read_csv(
        'output/all_countries_sp/redistribution_expenditures_by_country.csv'
    ).set_index('sp')  #.fillna('-')
    try:
        df = df.drop('Median')
    except:
        pass
    try:
        df = df.drop('Median', axis=1)
    except:
        pass

    #df.columns.name = 'Cost to reimburse bottom 40%'
    #df.index.name = '(as % of total carbon revenue)'
    df.index.name = 'Rebate program'

    df = df.fillna(-1)
    #df = df.astype('int')

    for _c in df.columns:
        df = df.rename(columns={_c: iso_to_name[_c.lower()]})
    df = df.reindex(sorted(df.columns), axis=1)
    df = df.sort_values(df.columns[0], ascending=False, na_position='last')
    df = df.fillna('-')
    df = df.round(1)

    df.insert(
        0, 'Median',
        df.median(axis=1, skipna=True).round(0).astype('int').fillna('-'))
    df = df.round(0).astype('int')

    df = df.sort_values('Median', ascending=True)
    df.to_latex(
        'output/all_countries_sp/_redist_exp_fractional_spending_Q12_compensated.tex',
        column_format=col_form)

    with open(
            'output/all_countries_sp/_redist_exp_fractional_spending_Q12_compensated.tex',
            'r') as f:
        with open(
                'output/all_countries_sp/redist_exp_fractional_spending_Q12_compensated.tex',
                'w') as f2:

            f2.write(r'\documentclass[preview=true]{standalone}' + '\n')
            f2.write(r'\usepackage{amssymb} %maths' + '\n')
            f2.write(r'\usepackage{amsmath} %maths' + '\n')
            f2.write(r'\usepackage{booktabs}' + '\n')
            f2.write(r'\usepackage{rotating}' + '\n')
            f2.write(r'\begin{document}' + '\n')

            reading_is_fundamental = f.read()
            reading_is_fundamental = reading_is_fundamental.replace(
                'Median', r'\rotatebox{90}{Median}')
            for _n in iso_to_name:
                if _n == 'chi': continue
                reading_is_fundamental = reading_is_fundamental.replace(
                    iso_to_name[_n],
                    r'\rotatebox{90}{' + iso_to_name[_n] + '}')
            f2.write(reading_is_fundamental)

            f2.write(r'\end{document}')
            f2.close()

    subprocess.call(
        'cd ~/Box\ Sync/stranded\ jobs\ and\ distributional\ impacts/output/all_countries_sp/; pdflatex redist_exp_fractional_spending_Q12_compensated.tex',
        shell=True)

    for f in glob.glob('output/all_countries_sp/*.aux'):
        os.remove(f)
    for f in glob.glob('output/all_countries_sp/*.log'):
        os.remove(f)
    for f in glob.glob('output/all_countries_sp/_*.tex'):
        os.remove(f)