In [ ]:
%pwd

In [ ]:
%cd /Users/brianbeckage/Documents/PROJECTS/Sesync/CLIMATE_CHANGE_MODEL

In [ ]:
%cd

Another way of changing working directory


In [ ]:
import os
os.chdir('/Users/brianbeckage/Documents/PROJECTS/Sesync/CLIMATE_CHANGE_MODEL')

Loading required libraries


In [1]:
%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

In [3]:
import SoCCo as sc
from SoCCo import api

In [4]:
sc.__file__
sc.__version__


Out[4]:
'0.0.1'

Setting initial conditions


In [6]:
nGroups=12
co2_ts=np.linspace(298, 299, 3)
popTotal=7130010000 # Wolfram: QuantityMagnitude[CountryData["World", "Population"]]
popN=sc.api.popIntoNgroups(popTotal,nGroups=nGroups)
pcE_ts=sc.api.randomNormalF(5.049, 0.5, nGroups)
pcE_ts=np.atleast_2d(pcE_ts).transpose()
tData_ts=np.array([0,0.1,0.2,0.1]) # temperature
eff=sc.api.efficacyF(nGroups)
pbc=sc.api.perceivedBehavioralControlF(nGroups)
percepWindowSize=3
riskSens=1000.0

In [7]:
sc.algorithms.social.popIntoNgroups(popTotal, nGroups=nGroups)


Out[7]:
array([  3.52904819e+08,   2.30893011e+07,   2.44773624e+08,
         2.10535129e+08,   4.42104815e+08,   1.39880405e+09,
         3.11869360e+08,   7.90620150e+08,   8.85261454e+08,
         7.84150154e+08,   1.37682319e+09,   3.09073950e+08])

In [8]:
sc.api.popIntoNgroups(popTotal,nGroups=nGroups)


Out[8]:
array([  4.97313393e+08,   5.90536901e+08,   3.58675968e+08,
         7.41327495e+08,   8.81107609e+08,   8.40444265e+08,
         1.42698236e+08,   8.79320936e+08,   7.07268014e+08,
         2.37827728e+07,   9.84779021e+08,   4.82755388e+08])

In [9]:
pcE_ts,tData_ts, co2_ts=sc.api.iterateNsteps(pcE_ts,tData_ts, co2_ts, 5, eff, pbc,popN,percepWindowSize,riskSens)

In [10]:
pcE_ts,tData_ts, co2_ts=api.iterateNsteps(pcE_ts,tData_ts, co2_ts, 100, eff, pbc,popN,percepWindowSize,riskSens)

In [11]:
pcE_ts,tData_ts, co2_ts=sc.algorithms.iter.iterateNsteps(pcE_ts,tData_ts, co2_ts, 100, eff, pbc,popN,percepWindowSize,riskSens)

In [12]:
pcE_tsT=pcE_ts.transpose()

In [13]:
pcE_tsT;

In [14]:
len(pcE_ts)


Out[14]:
12

In [15]:
tData_ts


Out[15]:
array([  0.00000000e+00,   1.00000000e-01,   2.00000000e-01,
         1.00000000e-01,   2.04942226e-01,   3.88904208e-01,
         6.74545447e-01,   1.08004930e+00,   1.61987204e+00,
         2.30536926e+00,   3.14531048e+00,   4.14630001e+00,
         5.31312459e+00,   6.64908255e+00,   8.15621168e+00,
         9.83552283e+00,   1.16871620e+01,   1.37105953e+01,
         1.59047160e+01,   1.82679949e+01,   2.07985452e+01,
         2.34941854e+01,   2.63525047e+01,   2.93709909e+01,
         3.25470824e+01,   3.58781547e+01,   3.93615269e+01,
         4.29944806e+01,   4.67743189e+01,   5.06983630e+01,
         5.47640100e+01,   5.89687265e+01,   6.33100247e+01,
         6.77854744e+01,   7.23926920e+01,   7.71293608e+01,
         8.19932182e+01,   8.69820488e+01,   9.20937202e+01,
         9.73261945e+01,   1.02677500e+02,   1.08145717e+02,
         1.13728992e+02,   1.19425525e+02,   1.25233560e+02,
         1.31151416e+02,   1.37177490e+02,   1.43310235e+02,
         1.49548143e+02,   1.55889764e+02,   1.62333686e+02,
         1.68878533e+02,   1.75522962e+02,   1.82265687e+02,
         1.89105486e+02,   1.96041176e+02,   2.03071604e+02,
         2.10195642e+02,   2.17412200e+02,   2.24720222e+02,
         2.32118698e+02,   2.39606662e+02,   2.47183172e+02,
         2.54847315e+02,   2.62598197e+02,   2.70434952e+02,
         2.78356730e+02,   2.86362696e+02,   2.94452044e+02,
         3.02624003e+02,   3.10877822e+02,   3.19212765e+02,
         3.27628112e+02,   3.36123161e+02,   3.44697217e+02,
         3.53349610e+02,   3.62079698e+02,   3.70886853e+02,
         3.79770458e+02,   3.88729911e+02,   3.97764620e+02,
         4.06874002e+02,   4.16057477e+02,   4.25314487e+02,
         4.34644498e+02,   4.44046987e+02,   4.53521438e+02,
         4.63067341e+02,   4.72684196e+02,   4.82371515e+02,
         4.92128827e+02,   5.01955678e+02,   5.11851622e+02,
         5.21816222e+02,   5.31849043e+02,   5.41949661e+02,
         5.52117658e+02,   5.62352614e+02,   5.72654123e+02,
         5.83021795e+02,   5.93455245e+02,   6.03954091e+02,
         6.14517960e+02,   6.25146481e+02,   6.35839286e+02,
         6.46596015e+02,   6.57416324e+02,   6.68299872e+02,
         6.79246322e+02,   6.90255343e+02,   7.01326606e+02,
         7.12459783e+02,   7.23654549e+02,   7.34910586e+02,
         7.46227590e+02,   7.57605262e+02,   7.69043302e+02,
         7.80541414e+02,   7.92099306e+02,   8.03716688e+02,
         8.15393284e+02,   8.27128822e+02,   8.38923037e+02,
         8.50775665e+02,   8.62686443e+02,   8.74655114e+02,
         8.86681420e+02,   8.98765105e+02,   9.10905917e+02,
         9.23103612e+02,   9.35357953e+02,   9.47668698e+02,
         9.60035613e+02,   9.72458463e+02,   9.84937013e+02,
         9.97471034e+02,   1.01006030e+03,   1.02270460e+03,
         1.03540371e+03,   1.04815742e+03,   1.06096551e+03,
         1.07382776e+03,   1.08674397e+03,   1.09971392e+03,
         1.11273741e+03,   1.12581424e+03,   1.13894421e+03,
         1.15212712e+03,   1.16536278e+03,   1.17865099e+03,
         1.19199155e+03,   1.20538430e+03,   1.21882904e+03,
         1.23232560e+03,   1.24587379e+03,   1.25947343e+03,
         1.27312436e+03,   1.28682638e+03,   1.30057933e+03,
         1.31438304e+03,   1.32823733e+03,   1.34214204e+03,
         1.35609700e+03,   1.37010205e+03,   1.38415703e+03,
         1.39826175e+03,   1.41241608e+03,   1.42661985e+03,
         1.44087291e+03,   1.45517509e+03,   1.46952626e+03,
         1.48392624e+03,   1.49837489e+03,   1.51287206e+03,
         1.52741759e+03,   1.54201133e+03,   1.55665316e+03,
         1.57134290e+03,   1.58608044e+03,   1.60086560e+03,
         1.61569827e+03,   1.63057830e+03,   1.64550556e+03,
         1.66047991e+03,   1.67550121e+03,   1.69056935e+03,
         1.70568417e+03,   1.72084555e+03,   1.73605335e+03,
         1.75130745e+03,   1.76660772e+03,   1.78195403e+03,
         1.79734626e+03,   1.81278428e+03,   1.82826795e+03,
         1.84379717e+03,   1.85937180e+03,   1.87499173e+03,
         1.89065683e+03,   1.90636699e+03,   1.92212209e+03,
         1.93792200e+03,   1.95376661e+03,   1.96965580e+03,
         1.98558944e+03,   2.00156744e+03,   2.01758967e+03,
         2.03365602e+03,   2.04976638e+03])

In [16]:
co2_ts


Out[16]:
array([   298.        ,    298.5       ,    299.        ,    327.06434315,
          355.80165411,    385.20113615,    415.28687803,    446.0638454 ,
          477.5396916 ,    509.71192491,    542.56331749,    576.06492705,
          610.2379407 ,    645.03124352,    680.45478746,    716.46132963,
          753.08655627,    790.27991161,    828.10628486,    866.51279627,
          905.45672991,    944.92291432,    985.0716593 ,   1025.94565014,
         1067.4476562 ,   1109.51493507,   1152.12069086,   1195.3623125 ,
         1239.18923956,   1283.74069391,   1328.99072999,   1374.852494  ,
         1421.34416372,   1468.41137684,   1516.10682921,   1564.3773851 ,
         1613.18061663,   1662.64386885,   1712.82837203,   1763.64023762,
         1815.01681424,   1867.02261542,   1919.60443126,   1972.7199409 ,
         2026.50625364,   2081.01434915,   2136.14965306,   2191.84961059,
         2248.18595492,   2305.10471708,   2362.56290804,   2420.54449538,
         2479.20991726,   2538.60116447,   2598.62077673,   2659.20590796,
         2720.32856141,   2782.08668188,   2844.42997453,   2907.4982596 ,
         2971.26541046,   3035.64452849,   3100.65351387,   3166.23804364,
         3232.4505431 ,   3299.23791369,   3366.55780807,   3434.53689377,
         3503.23730279,   3572.56515637,   3642.45780338,   3712.97912014,
         3784.07595797,   3855.70610895,   3928.00506353,   4001.02574743,
         4074.67365319,   4148.88615643,   4223.73357337,   4299.16206313,
         4375.12866788,   4451.61900426,   4528.79378878,   4606.69457668,
         4685.22382035,   4764.31864576,   4843.95061543,   4924.21791885,
         5005.07036926,   5086.64791588,   5168.92438863,   5251.81287934,
         5335.33122959,   5419.42512448,   5504.14693331,   5589.44356493,
         5675.27268929,   5761.76083565,   5848.97032239,   5936.80727201,
         6025.20903399,   6114.23935289,   6203.8450925 ,   6293.98406929,
         6384.79144492,   6476.32054348,   6568.47687037,   6661.19778819,
         6754.5533248 ,   6848.48966606,   6942.96386707,   7037.96221797,
         7133.64554008,   7230.0549323 ,   7327.09282724,   7424.69635846,
         7522.83637476,   7621.61146468,   7720.97163058,   7821.05698876,
         7921.841328  ,   8023.23773479,   8125.26398375,   8227.86577294,
         8331.09540409,   8434.89979688,   8539.23664316,   8644.23229928,
         8749.94931442,   8856.29381405,   8963.20314932,   9070.74090251,
         9178.85395301,   9287.50014802,   9396.81424523,   9506.85005887,
         9617.51311021,   9728.74074661,   9840.60264207,   9953.04501561,
        10066.02494106,  10179.53007495,  10293.721559  ,  10408.63926723,
        10524.1855944 ,  10640.29770759,  10756.94517006,  10874.22763303,
        10992.09547333,  11110.68814731,  11229.97953978,  11349.88275944,
        11470.41587936,  11591.52454147,  11713.26136134,  11835.57320729,
        11958.41767957,  12081.92194724,  12206.14751187,  12331.00047459,
        12456.41817869,  12582.46493991,  12709.08756454,  12836.24376515,
        12964.07015554,  13092.61831398,  13221.79368448,  13351.53368854,
        13481.90962025,  13612.86754907,  13744.36448955,  13876.38476301,
        14009.08891048,  14142.51893203,  14276.57733731,  14411.20126584,
        14546.36294555,  14682.16025008,  14818.5428256 ,  14955.65029772,
        15093.45657202,  15231.87475432,  15370.92282576,  15510.54644644,
        15650.79812696,  15791.62475414,  15932.98395446,  16075.0026186 ,
        16217.74258791,  16361.10997751,  16505.04213439,  16649.60313857,
        16794.73982114,  16940.40993696,  17086.74949208,  17233.81079108,
        17381.4993051 ,  17529.75243059,  17678.64093406,  17828.11093314,
        17978.11945411,  18128.65139355,  18279.8673813 ,  18431.80930378,
        18584.37963947,  18737.51551604,  18891.18909644,  19045.49829789])

Temperature Trajectory


In [17]:
plt.plot(tData_ts)
    plt.xlabel('Year')
    plt.ylabel('T')


Out[17]:
<matplotlib.text.Text at 0x1161109e8>
//anaconda/lib/python3.5/site-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
  warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')
//anaconda/lib/python3.5/site-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
  warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')

CO2 Trajectory


In [18]:
plt.plot(co2_ts)
    plt.xlabel('Year')
    plt.ylabel('ppm')


Out[18]:
<matplotlib.text.Text at 0x1148e6438>

Per Capita Emissions


In [19]:
plt.plot(pcE_ts.transpose())
    plt.xlabel('Year')
    plt.ylabel('ppm')


Out[19]:
<matplotlib.text.Text at 0x118a94cf8>

In [20]:
plt.plot(pcE_ts)
    plt.xlabel('Group')
    plt.ylabel('ppm')
    plt.legend(np.arange(5).astype('str'))


Out[20]:
<matplotlib.legend.Legend at 0x118bfc160>

In [21]:
pcE_ts.shape


Out[21]:
(12, 206)

In [23]:
np.arange(5).astype('str')


Out[23]:
array(['0', '1', '2', '3', '4'], 
      dtype='<U21')