コード例 #1
0
def get_pop():

    lspop = pd.read_csv(
        files.sharedpath('social/processed/LandScan2011/gcpregions.csv'),
        header=17)

    dfir = metacsv.read_csv(files.sharedpath("regions/hierarchy_metacsv.csv"))
    dfir = dfir.loc[dfir.is_terminal].reset_index(drop=True)
    dfir.drop([
        'parent-key', 'name', 'alternatives', 'is_terminal', 'gadmid',
        'agglomid', 'notes'
    ],
              axis=1,
              inplace=True)
    dfir.rename(columns={'region-key': 'region'}, inplace=True)
    dfir['iso'] = dfir.region.apply(lambda x: x[:3])

    df = pd.read_csv(
        files.sharedpath(
            'social/baselines/population/merged/population-merged.all.csv'))

    df.rename(columns={'value': 'pop'}, inplace=True)
    df['iso'] = df.region.apply(lambda x: x[:3])
    df.drop(['index'], axis=1, inplace=True)
    df = df.loc[df.year > 2005]

    dff = df.append(get_missing_pop(df, dfir, lspop),
                    sort=False).sort_values(['region',
                                             'year']).reset_index(drop=True)

    return dff
コード例 #2
0
    def __init__(self, iam, ssp):
        """iam and ssp should be as described in the files (e.g., iam = 'low', ssp = 'SSP3')"""

        super(GDPpcProvider, self).__init__(iam, ssp, baseline_year)

        # Load the baseline values, and split by priority of data
        df = metacsv.read_csv(files.sharedpath(baseline_filepath))
        self.df_baseline_this = df.loc[(df.model == iam) & (df.scenario == ssp)
                                       & (df.year == baseline_year)]
        self.df_baseline_anyiam = df.loc[(df.scenario == ssp) & (
            df.year == baseline_year)].groupby('iso').median()
        self.baseline_global = df.loc[(df.scenario == ssp)
                                      & (df.year == baseline_year)].median()

        # Load the growth rates, and split by priority of data
        df_growth = metacsv.read_csv(files.sharedpath(growth_filepath))
        df_growth['yearindex'] = np.int_((df_growth.year - baseline_year) / 5)
        self.df_growth_this = df_growth.loc[(df_growth.model == iam)
                                            & (df_growth.scenario == ssp)]
        self.df_growth_anyiam = df_growth.loc[(
            df_growth.scenario == ssp)].groupby(['iso', 'year']).median()
        self.growth_global = df_growth.loc[(df_growth.scenario == ssp)
                                           & (df_growth.model == iam)].groupby(
                                               ['year']).median()

        # Load the nightlights
        self.df_nightlights = metacsv.read_csv(
            files.sharedpath(nightlights_filepath))

        # Cache for ISO-level GDPpc series
        self.cached_iso_gdppcs = {}
コード例 #3
0
def get_gdppc_all_regions(model, ssp):

    print(model + " " + ssp)
    os.chdir(os.getenv("HOME") + '/repos/impact-calculations')
    moddict = {'high': 'OECD Env-Growth', 'low': 'IIASA GDP'}
    df = metacsv.read_csv(files.sharedpath("regions/hierarchy_metacsv.csv"))
    tmplist = []
    yvect = np.arange(2010, 2101)
    svect = np.repeat(ssp, yvect.size)
    mvect = np.repeat(moddict[model], yvect.size)
    provider = gdppc.GDPpcProvider(model, ssp)

    for ii in np.where(df.is_terminal)[0]:
        series = provider.get_timeseries(df['region-key'][ii])
        rvect = np.repeat(df['region-key'][ii], yvect.size)
        tmp = pd.DataFrame({
            'region': rvect,
            'year': yvect,
            'gdppc': series,
            'ssp': svect,
            'model': mvect
        })
        tmplist.append(tmp)

    dfg = pd.concat(tmplist, sort=False)

    return dfg
コード例 #4
0
def test_xyz_high():
    if files.sharedpath('testing')[:11] == '/shares/gcp':
        helper(provider_high, 'XYZ.1.2', 7065.37128841, 15837.3384374,
               16024.4588895)
    else:
        helper(provider_high, 'XYZ.1.2', 415.320976851, 1653.5117662281498,
               1711.9155483103712)
コード例 #5
0
def test_xyz_low():
    if files.sharedpath('testing')[:11] == '/shares/gcp':
        helper(provider_low, 'XYZ.1.2', 7065.37128841, 12309.8299344,
               12417.4055742)
    else:
        helper(provider_low, 'XYZ.1.2', 415.320976851, 1254.179869326625,
               1269.0353748748823)
コード例 #6
0
        if df.shape[0] > 0:
            return df

        if iso in df_anyiam.index:
            df = df_anyiam.loc[iso]
            if df.shape[0] > 0:
                return df

        return df_global


if __name__ == '__main__':
    # Test the provider
    import time

    time0 = time.time()
    provider = GDPpcProvider('low', 'SSP3')
    df = metacsv.read_csv(files.sharedpath("regions/hierarchy_metacsv.csv"))
    time1 = time.time()
    print "Load time: %s seconds" % (time1 - time0)

    for ii in np.where(df.is_terminal)[0]:
        xx = provider.get_timeseries(df.iloc[ii, 0])
    time2 = time.time()
    print "First pass: %s seconds" % (time2 - time1)

    for ii in np.where(df.is_terminal)[0]:
        xx = provider.get_timeseries(df.iloc[ii, 0])
    time3 = time.time()
    print "Second pass: %s seconds" % (time3 - time2)