Beispiel #1
0
def make_simonrobertsdata(S, U, Y, stressor, allyears, meta):

    data = np.zeros(shape=[meta['use_dd']['len_col'], len(allyears) + 1])
    count = 0
    for yr in allyears:
        Z = io.make_Z_from_S_U(S[yr], U[yr])
        bigY = np.zeros(shape=[np.size(Y[yr], 0) * 2, np.size(Y[yr], 1)])
        bigY[np.size(Y[yr], 0):np.size(Y[yr], 0) * 2, :] = Y[yr]
        x = io.make_x(Z, bigY)
        L = io.make_L(Z, x)
        bigstressor = np.zeros(shape=[np.size(Y[yr], 0) * 2, 1])
        bigstressor[0:np.size(Y[yr], 0), :] = stressor[yr]
        e = np.sum(bigstressor, 1) / x

        temp = np.dot(np.dot(np.diag(e), L), np.diag(np.sum(bigY[:, 0:7], 1)))

        for a in range(0, meta['use_dd']['len_col']):
            temp2 = 0
            for b in range(1, meta['reg']['len']):
                temp2 = temp2 + np.sum(temp[b * meta['use_dd']['len_col'] + a,
                                            424:848])

            data[a, count] = temp2
        count = count + 1

    return data
Beispiel #2
0
def make_exp_mult_LCF(S_d, U_d, Y_d, nrg, years, yhh_prop, yhh_wide, lcf_136):
    #  e = {}
    nrg_CC_mult = {}
    file = '/Users/earao/Source Data/IEA/direct_from_ons.xlsx'
    direct = pd.read_excel(file, sheet_name='direct')
    lcf_exp = {}
    foots = np.zeros(shape=[len(years), 1])
    count = 0
    eL = {}
    # L = {}
    nrg_prod_mult = np.zeros(shape=[136, 106, len(years)])
    for yr in years:

        Z = io.make_Z_from_S_U(S_d[yr], U_d[yr])
        bigY = np.zeros(shape=[2120, 8])
        bigY[1060:2120, 0:8] = Y_d[yr]
        x = io.make_x(Z, bigY)
        L = io.make_L(Z, x)
        bignrg = np.zeros(shape=[2120, 1])
        bignrg[0:1060, :] = nrg[yr]
        e = np.sum(bignrg, 1) / x
        eL[yr] = np.dot(e, L)

        tempyprop = np.zeros(shape=(len(Z)))
        tempyprop[len(S_d[yr]):] = yhh_prop[yr]
        temp_nrg_prod_mult = np.zeros(shape=[106])
        nrg_prod_big = np.multiply(eL[yr], tempyprop)
        for a in range(0, 10):
            temp_nrg_prod_mult = temp_nrg_prod_mult + nrg_prod_big[
                (a * 106) + 1060:((a + 1) * 106) + 1060]

        nrg_prod_mult[:, :, count] = np.tile(temp_nrg_prod_mult, [136, 1])

        foot = np.multiply(np.transpose(nrg_prod_mult[:, :, count]),
                           yhh_wide[yr])
        foot = np.nan_to_num(foot)
        foot = np.sum(foot, 0) + (direct.loc[:, int(yr)] * 1000000)
        foots[count, 0] = np.sum(foot, 0) / 1000000

        nrg_CC_mult[yr] = np.divide(foot, np.sum(yhh_wide[yr], 0)) / 1000000

        np.nan_to_num(nrg_CC_mult[yr], copy=False)

        temp = np.divide(np.sum(yhh_wide[yr], 0), np.sum(lcf_136[yr], 1))
        lcf_exp[yr] = df(np.dot(np.diag(temp), lcf_136[yr]),
                         index=lcf_136[yr].index,
                         columns=lcf_136[yr].columns)

        np.nan_to_num(lcf_exp[yr], copy=False)
        count = count + 1
    return (lcf_exp, nrg_CC_mult)
Beispiel #3
0
def makefoot(S,U,Y,stressor,years):
    footbyCOICOP = {}
    for yr in years:
        temp = np.zeros(shape = 307)
        Z = io.make_Z_from_S_U(S[yr],U[yr]) 
        bigY = np.zeros(shape = [np.size(Y[yr],0)*2,np.size(Y[yr],1)])
        bigY[np.size(Y[yr],0):np.size(Y[yr],0)*2,0:] = Y[yr]     
        x = io.make_x(Z,bigY)
        L = io.make_L(Z,x)
        bigstressor = np.zeros(shape = [np.size(Y[yr],0)*2,1])
        bigstressor[0:np.size(Y[yr],0),:] = stressor[yr]
        e = np.sum(bigstressor,1)/x
        eL = np.dot(e,L)
        for a in range(0,307):
            temp[a] = np.dot(eL,bigY[:,a])
        footbyCOICOP[yr] = temp  

    return footbyCOICOP
Beispiel #4
0
def make_footprint(S, U, Y, nrg, allyears):
    footprint = np.zeros(shape=[10, len(allyears)])
    count = 0
    for yr in allyears:
        Z = io.make_Z_from_S_U(S[yr], U[yr])
        bigY = np.zeros(
            shape=[np.size(Y['1997'], 0) *
                   2, np.size(Y['1997'], 1)])
        bigY[np.size(Y['1997'], 0):np.size(Y['1997'], 0) * 2, 0:8] = Y[yr]
        x = io.make_x(Z, bigY)
        L = io.make_L(Z, x)
        bignrg = np.zeros(shape=[np.size(Y['1997'], 0) * 2, 1])
        bignrg[0:np.size(Y['1997'], 0), :] = nrg[yr]
        e = np.sum(bignrg, 1) / x

        temp = np.dot(np.dot(np.diag(e), L), np.diag(np.sum(bigY[:, 0:7], 1)))

        for a in range(0, 4):
            footprint[a, count] = np.sum(temp[a * 106:(a + 1) * 106, :])
        count = count + 1
    return footprint
Beispiel #5
0
def make_hhfootprint(S, U, Y, stressor, allyears, meta):

    footprint = np.zeros(shape=[meta['reg']['len'], len(allyears)])
    count = 0
    for yr in allyears:
        Z = io.make_Z_from_S_U(S[yr], U[yr])
        bigY = np.zeros(shape=[np.size(Y[yr], 0) * 2, np.size(Y[yr], 1)])
        bigY[np.size(Y[yr], 0):np.size(Y[yr], 0) * 2, :] = Y[yr]
        x = io.make_x(Z, bigY)
        L = io.make_L(Z, x)
        bigstressor = np.zeros(shape=[np.size(Y[yr], 0) * 2, 1])
        bigstressor[0:np.size(Y[yr], 0), :] = stressor[yr]
        e = np.sum(bigstressor, 1) / x

        temp = np.dot(np.dot(np.diag(e), L), np.diag(np.sum(bigY[:, 0:36], 1)))

        for a in range(0, meta['reg']['len']):
            footprint[a, count] = np.sum(temp[a * 106:(a + 1) * 106, :])
        count = count + 1

    return footprint
Beispiel #6
0
def make_defra_foot(S, U, Y, stressor, years):
    defra_foot = {}
    for yr in years:
        Z = io.make_Z_from_S_U(S[yr], U[yr])
        bigY = np.zeros(
            shape=[np.size(Y['1997'], 0) *
                   2, np.size(Y['1997'], 1)])
        bigY[np.size(Y['1997'], 0):np.size(Y['1997'], 0) * 2, 0:8] = Y[yr]
        x = io.make_x(Z, bigY)
        L = io.make_L(Z, x)
        bigstressor = np.zeros(shape=[np.size(Y['1997'], 0) * 2, 1])
        bigstressor[0:np.size(Y['1997'], 0), :] = stressor[yr]
        e = np.sum(bigstressor, 1) / x
        hhold = np.dot(np.dot(np.diag(e), L), np.diag(bigY[:, 0]))
        npish = np.dot(np.dot(np.diag(e), L), np.diag(bigY[:, 1]))
        cgovr = np.dot(np.dot(np.diag(e), L), np.diag(bigY[:, 2]))
        lgovr = np.dot(np.dot(np.diag(e), L), np.diag(bigY[:, 3]))
        gfcap = np.dot(np.dot(np.diag(e), L), np.diag(bigY[:, 4]))
        valua = np.dot(np.dot(np.diag(e), L), np.diag(bigY[:, 5]))
        chinv = np.dot(np.dot(np.diag(e), L), np.diag(bigY[:, 6]))
        temp = np.zeros(shape=[106, 49])
        temp[:, 0] = np.sum(hhold[0:106, 424:530], 0) + np.sum(
            hhold[0:106, 530:636], 0) + np.sum(
                hhold[0:106, 636:742], 0) + np.sum(hhold[0:106, 742:848], 0)
        temp[:, 1] = np.sum(npish[0:106, 424:530], 0) + np.sum(
            npish[0:106, 530:636], 0) + np.sum(
                npish[0:106, 636:742], 0) + np.sum(npish[0:106, 742:848], 0)
        temp[:, 2] = np.sum(cgovr[0:106, 424:530], 0) + np.sum(
            cgovr[0:106, 530:636], 0) + np.sum(
                cgovr[0:106, 636:742], 0) + np.sum(cgovr[0:106, 742:848], 0)
        temp[:, 3] = np.sum(lgovr[0:106, 424:530], 0) + np.sum(
            lgovr[0:106, 530:636], 0) + np.sum(
                lgovr[0:106, 636:742], 0) + np.sum(lgovr[0:106, 742:848], 0)
        temp[:, 4] = np.sum(gfcap[0:106, 424:530], 0) + np.sum(
            gfcap[0:106, 530:636], 0) + np.sum(
                gfcap[0:106, 636:742], 0) + np.sum(gfcap[0:106, 742:848], 0)
        temp[:, 5] = np.sum(valua[0:106, 424:530], 0) + np.sum(
            valua[0:106, 530:636], 0) + np.sum(
                valua[0:106, 636:742], 0) + np.sum(valua[0:106, 742:848], 0)
        temp[:, 6] = np.sum(chinv[0:106, 424:530], 0) + np.sum(
            chinv[0:106, 530:636], 0) + np.sum(
                chinv[0:106, 636:742], 0) + np.sum(chinv[0:106, 742:848], 0)
        temp[:, 7] = np.sum(hhold[106:212, 424:530], 0)
        temp[:, 8] = np.sum(npish[106:212, 424:530], 0)
        temp[:, 9] = np.sum(cgovr[106:212, 424:530], 0)
        temp[:, 10] = np.sum(lgovr[106:212, 424:530], 0)
        temp[:, 11] = np.sum(gfcap[106:212, 424:530], 0)
        temp[:, 12] = np.sum(valua[106:212, 424:530], 0)
        temp[:, 13] = np.sum(chinv[106:212, 424:530], 0)
        temp[:, 14] = np.sum(hhold[212:318, 424:530], 0)
        temp[:, 15] = np.sum(npish[212:318, 424:530], 0)
        temp[:, 16] = np.sum(cgovr[212:318, 424:530], 0)
        temp[:, 17] = np.sum(lgovr[212:318, 424:530], 0)
        temp[:, 18] = np.sum(gfcap[212:318, 424:530], 0)
        temp[:, 19] = np.sum(valua[212:318, 424:530], 0)
        temp[:, 20] = np.sum(chinv[212:318, 424:530], 0)
        temp[:, 21] = np.sum(hhold[318:424, 424:530], 0)
        temp[:, 22] = np.sum(npish[318:424, 424:530], 0)
        temp[:, 23] = np.sum(cgovr[318:424, 424:530], 0)
        temp[:, 24] = np.sum(lgovr[318:424, 424:530], 0)
        temp[:, 25] = np.sum(gfcap[318:424, 424:530], 0)
        temp[:, 26] = np.sum(valua[318:424, 424:530], 0)
        temp[:, 27] = np.sum(chinv[318:424, 424:530], 0)
        temp[:, 28] = np.sum(hhold[106:212, 530:636], 0) + np.sum(
            hhold[106:212, 636:742], 0) + np.sum(hhold[106:212, 742:848], 0)
        temp[:, 29] = np.sum(npish[106:212, 530:636], 0) + np.sum(
            npish[106:212, 636:742], 0) + np.sum(npish[106:212, 742:848], 0)
        temp[:, 30] = np.sum(cgovr[106:212, 530:636], 0) + np.sum(
            cgovr[106:212, 636:742], 0) + np.sum(cgovr[106:212, 742:848], 0)
        temp[:, 31] = np.sum(lgovr[106:212, 530:636], 0) + np.sum(
            lgovr[106:212, 636:742], 0) + np.sum(lgovr[106:212, 742:848], 0)
        temp[:, 32] = np.sum(gfcap[106:212, 530:636], 0) + np.sum(
            gfcap[106:212, 636:742], 0) + np.sum(gfcap[106:212, 742:848], 0)
        temp[:, 33] = np.sum(valua[106:212, 530:636], 0) + np.sum(
            valua[106:212, 636:742], 0) + np.sum(valua[106:212, 742:848], 0)
        temp[:, 34] = np.sum(chinv[106:212, 530:636], 0) + np.sum(
            chinv[106:212, 636:742], 0) + np.sum(chinv[106:212, 742:848], 0)
        temp[:, 35] = np.sum(hhold[212:318, 530:636], 0) + np.sum(
            hhold[212:318, 636:742], 0) + np.sum(hhold[212:318, 742:848], 0)
        temp[:, 36] = np.sum(npish[212:318, 530:636], 0) + np.sum(
            npish[212:318, 636:742], 0) + np.sum(npish[212:318, 742:848], 0)
        temp[:, 37] = np.sum(cgovr[212:318, 530:636], 0) + np.sum(
            cgovr[212:318, 636:742], 0) + np.sum(cgovr[212:318, 742:848], 0)
        temp[:, 38] = np.sum(lgovr[212:318, 530:636], 0) + np.sum(
            lgovr[212:318, 636:742], 0) + np.sum(lgovr[212:318, 742:848], 0)
        temp[:, 39] = np.sum(gfcap[212:318, 530:636], 0) + np.sum(
            gfcap[212:318, 636:742], 0) + np.sum(gfcap[212:318, 742:848], 0)
        temp[:, 40] = np.sum(valua[212:318, 530:636], 0) + np.sum(
            valua[212:318, 636:742], 0) + np.sum(valua[212:318, 742:848], 0)
        temp[:, 41] = np.sum(chinv[212:318, 530:636], 0) + np.sum(
            chinv[212:318, 636:742], 0) + np.sum(chinv[212:318, 742:848], 0)
        temp[:, 42] = np.sum(hhold[318:424, 530:636], 0) + np.sum(
            hhold[318:424, 636:742], 0) + np.sum(hhold[318:424, 742:848], 0)
        temp[:, 43] = np.sum(npish[318:424, 530:636], 0) + np.sum(
            npish[318:424, 636:742], 0) + np.sum(npish[318:424, 742:848], 0)
        temp[:, 44] = np.sum(cgovr[318:424, 530:636], 0) + np.sum(
            cgovr[318:424, 636:742], 0) + np.sum(cgovr[318:424, 742:848], 0)
        temp[:, 45] = np.sum(lgovr[318:424, 530:636], 0) + np.sum(
            lgovr[318:424, 636:742], 0) + np.sum(lgovr[318:424, 742:848], 0)
        temp[:, 46] = np.sum(gfcap[318:424, 530:636], 0) + np.sum(
            gfcap[318:424, 636:742], 0) + np.sum(gfcap[318:424, 742:848], 0)
        temp[:, 47] = np.sum(valua[318:424, 530:636], 0) + np.sum(
            valua[318:424, 636:742], 0) + np.sum(valua[318:424, 742:848], 0)
        temp[:, 48] = np.sum(chinv[318:424, 530:636], 0) + np.sum(
            chinv[318:424, 636:742], 0) + np.sum(chinv[318:424, 742:848], 0)

        defra_foot[yr] = temp
    return defra_foot
Beispiel #7
0
def makeSDA(S, U, Y, nrg, allyears):

    yr0 = '2005'
    Z0 = io.make_Z_from_S_U(S[yr0], U[yr0])
    bigY0 = np.zeros(shape=[2120, 8])
    bigY0[1060:2120, 0:8] = Y[yr0]
    bigYhh0 = bigY0[:, 0]
    totalY0 = np.sum(np.sum(bigY0[:, 0]))
    propY0 = bigY0[:, 0] / totalY0
    x0 = io.make_x(Z0, bigY0)
    L0 = io.make_L(Z0, x0)
    bignrg0 = np.zeros(shape=[2120, 1])
    bignrg0[0:1060, :] = nrg[yr0]
    e0 = np.sum(bignrg0, 1) / x0
    count = 0
    temp = np.zeros(shape=[12, 3])
    temp2 = np.zeros(shape=[12, 3])
    for yr in allyears:
        yr1 = yr
        Z1 = io.make_Z_from_S_U(S[yr1], U[yr1])
        bigY1 = np.zeros(shape=[2120, 8])
        bigY1[1060:2120, 0:8] = Y[yr1]
        bigYhh1 = bigY1[:, 0]
        totalY1 = np.sum(np.sum(bigY1[:, 0]))
        propY1 = bigY1[:, 0] / totalY1
        x1 = io.make_x(Z1, bigY1)
        L1 = io.make_L(Z1, x1)
        bignrg1 = np.zeros(shape=[2120, 1])
        bignrg1[0:1060, :] = nrg[yr1]
        e1 = np.sum(bignrg1, 1) / x1

        foot_0 = np.dot(e0, L0)
        foot_0 = np.dot(foot_0, bigYhh0)

        foot_1 = np.dot(e1, L1)
        foot_1 = np.dot(foot_1, bigYhh1)

        foot_2 = np.dot(e0, L0)
        foot_2 = np.dot(foot_2, propY0)
        foot_2 = np.dot(foot_2, totalY0)

        foot_3 = np.dot(e1, L1)
        foot_3 = np.dot(foot_3, propY1)
        foot_3 = np.dot(foot_3, totalY1)

        sda_0 = {}
        sda_0[0] = e0
        sda_0[1] = L0
        sda_0[2] = bigYhh0

        sda_1 = {}
        sda_1[0] = e1
        sda_1[1] = L1
        sda_1[2] = bigYhh1

        sda_2 = {}
        sda_2[0] = np.dot(e0, L0)
        sda_2[1] = propY0
        sda_2[2] = totalY0

        sda_3 = {}
        sda_3[0] = np.dot(e1, L1)
        sda_3[1] = propY1
        sda_3[2] = totalY1

        result = io.sda(sda_1, sda_0)

        temp[count, :] = result[6, 1:4]

        result2 = io.sda(sda_3, sda_2)

        temp2[count, :] = result2[6, 1:4]
        count = count + 1

    return (temp, temp2)