Evaluation of the long term dynamics of the model.

Data from runs over 3000 years for different possible income from trade.

Single trajectories are also evaluated, since the aggregate data does not give insight into the actual model behavior.

NOTE: These runs are done without climate variability. The variation is only caused by interplay of social and ecological dynamics in the system.


In [1]:
%pylab inline
pylab.rcParams['figure.figsize'] = (14, 6)

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

d_start = 150
d_length = 20

testing = False

location = '/home/jakob/Project_MayaSim/Python/output_data/X8_longterm_dynamics/results/trajectory'
if testing:
    location = '/home/jakob/Project_MayaSim/Python/output_data/test_output/X8_longterm_dynamics/results/trajectory'
    
data = pd.read_pickle(location)

def plot(obs, data):
    r_trades = data.index.levels[0].values
    fig = plt.figure()
    k = 0
    plots = []
    for j, r in enumerate(r_trades):
        k += 1
        ax = fig.add_subplot(1, len(r_trades), j + 1)
        ax.set_title('{}) r_trade = {}'.format(k, r))
        dt = data['<mean_trajectories>'].xs(level=('r_trade', 'observables'), key=(r, obs))
        de = data['<sigma_trajectories>'].xs(level=('r_trade', 'observables'), key=(r, obs))
        dt.plot(ax=ax)
        dtt = de.index.values
        ddt = dt.values
        dde = de.values
        plt.fill_between(dtt, ddt - dde, ddt + dde, alpha=0.2)

        ax.set_ylabel(obs)
        #ax.axvspan(d_start, d_start + d - 1, alpha=0.5, color='grey')
        plots.append((r, k, obs))
        ax.set_xticklabels(ax.xaxis.get_majorticklabels(), rotation=45)
        fig.tight_layout()
    return (fig, plots)
print(data.index.levels)


Populating the interactive namespace from numpy and matplotlib
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/pickle.py in try_read(path, encoding)
     98         try:
---> 99             return read_wrapper(lambda f: pkl.load(f))
    100         except Exception:

~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/pickle.py in read_wrapper(func)
     81                             compression=inferred_compression,
---> 82                             is_text=False)
     83         try:

~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/common.py in _get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text)
    395             # Python 3 and binary mode
--> 396             f = open(path_or_buf, mode)
    397         handles.append(f)

FileNotFoundError: [Errno 2] No such file or directory: '/home/jakob/Project_MayaSim/Python/output_data/X8_longterm_dynamics/results/trajectory'

During handling of the above exception, another exception occurred:

FileNotFoundError                         Traceback (most recent call last)
~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/pickle.py in try_read(path, encoding)
    103                 return read_wrapper(
--> 104                     lambda f: pc.load(f, encoding=encoding, compat=False))
    105             # compat pickle

~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/pickle.py in read_wrapper(func)
     81                             compression=inferred_compression,
---> 82                             is_text=False)
     83         try:

~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/common.py in _get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text)
    395             # Python 3 and binary mode
--> 396             f = open(path_or_buf, mode)
    397         handles.append(f)

FileNotFoundError: [Errno 2] No such file or directory: '/home/jakob/Project_MayaSim/Python/output_data/X8_longterm_dynamics/results/trajectory'

During handling of the above exception, another exception occurred:

FileNotFoundError                         Traceback (most recent call last)
~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/pickle.py in read_pickle(path, compression)
    109     try:
--> 110         return try_read(path)
    111     except:

~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/pickle.py in try_read(path, encoding)
    107                 return read_wrapper(
--> 108                     lambda f: pc.load(f, encoding=encoding, compat=True))
    109     try:

~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/pickle.py in read_wrapper(func)
     81                             compression=inferred_compression,
---> 82                             is_text=False)
     83         try:

~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/common.py in _get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text)
    395             # Python 3 and binary mode
--> 396             f = open(path_or_buf, mode)
    397         handles.append(f)

FileNotFoundError: [Errno 2] No such file or directory: '/home/jakob/Project_MayaSim/Python/output_data/X8_longterm_dynamics/results/trajectory'

During handling of the above exception, another exception occurred:

FileNotFoundError                         Traceback (most recent call last)
~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/pickle.py in try_read(path, encoding)
     98         try:
---> 99             return read_wrapper(lambda f: pkl.load(f))
    100         except Exception:

~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/pickle.py in read_wrapper(func)
     81                             compression=inferred_compression,
---> 82                             is_text=False)
     83         try:

~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/common.py in _get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text)
    395             # Python 3 and binary mode
--> 396             f = open(path_or_buf, mode)
    397         handles.append(f)

FileNotFoundError: [Errno 2] No such file or directory: '/home/jakob/Project_MayaSim/Python/output_data/X8_longterm_dynamics/results/trajectory'

During handling of the above exception, another exception occurred:

FileNotFoundError                         Traceback (most recent call last)
~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/pickle.py in try_read(path, encoding)
    103                 return read_wrapper(
--> 104                     lambda f: pc.load(f, encoding=encoding, compat=False))
    105             # compat pickle

~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/pickle.py in read_wrapper(func)
     81                             compression=inferred_compression,
---> 82                             is_text=False)
     83         try:

~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/common.py in _get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text)
    395             # Python 3 and binary mode
--> 396             f = open(path_or_buf, mode)
    397         handles.append(f)

FileNotFoundError: [Errno 2] No such file or directory: '/home/jakob/Project_MayaSim/Python/output_data/X8_longterm_dynamics/results/trajectory'

During handling of the above exception, another exception occurred:

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-1-9a5a96129c7e> in <module>
     16     location = '/home/jakob/Project_MayaSim/Python/output_data/test_output/X8_longterm_dynamics/results/trajectory'
     17 
---> 18 data = pd.read_pickle(location)
     19 
     20 def plot(obs, data):

~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/pickle.py in read_pickle(path, compression)
    111     except:
    112         if PY3:
--> 113             return try_read(path, encoding='latin1')
    114         raise
    115 

~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/pickle.py in try_read(path, encoding)
    106             except:
    107                 return read_wrapper(
--> 108                     lambda f: pc.load(f, encoding=encoding, compat=True))
    109     try:
    110         return try_read(path)

~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/pickle.py in read_wrapper(func)
     80         f, fh = _get_handle(path, 'rb',
     81                             compression=inferred_compression,
---> 82                             is_text=False)
     83         try:
     84             return func(f)

~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/common.py in _get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text)
    394         else:
    395             # Python 3 and binary mode
--> 396             f = open(path_or_buf, mode)
    397         handles.append(f)
    398 

FileNotFoundError: [Errno 2] No such file or directory: '/home/jakob/Project_MayaSim/Python/output_data/X8_longterm_dynamics/results/trajectory'

In [ ]:
pylab.rcParams['figure.figsize'] = (16, 4)

r_trades = data.index.levels[0].values

fig, plots = plot('total_population', data)

fig, plots = plot('total_income_trade', data)

The plots above show the long run data (aggregated from 50 runs) for total population and total income from trade

We see:

  • an overshoot and collapse behavior with fluctuation in the long run for possible income from trade,
  • some sort of saturation for intermediate income from taded and
  • an even quicker saturation for high possible income from trade.

To get some more information, a closer look at individual trajectories is required.


In [ ]:
location = '/home/jakob/Project_MayaSim/Python/output_data/X8_longterm_dynamics/results/all_trajectories'
all_data = pd.read_pickle(location)

print(all_data.columns)

In [2]:
pylab.rcParams['figure.figsize'] = (6, 12)
all_data.columns = range(0,2)
all_data.loc[6000, 1]

runs  = range(0, 2)
r_trades = all_data.index.values
fig = plt.figure()

annotations=['A)', 'B)', 'C)', 'D)']
for i, r_trade in enumerate(r_trades[[0, 1, 3]]):
    
    ax = fig.add_subplot(4, 1, i + 1)
    observable = 'total_population'

    for run in [0,1]:
        all_data.loc[r_trade, run][observable].plot(legend=(True if i == len(r_trades) - 1 else False))
    ax.set_xlim([0,2100])
    ax.annotate(annotations[i], xy=(0,0), xycoords='data', xytext=(0.92, 0.1), textcoords='axes fraction', fontsize=18)
    ax.set_ylabel('total population')
    if i == len(r_trades)-1:
        ax.set_xlabel('time in years')
        leg = ax.get_legend()
        for j, text in enumerate(leg.get_texts()):
            text.set_text('run {}'.format(j+1))

plt.savefig('longterm_population_development.pdf')


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-2-23198f52871d> in <module>
      1 pylab.rcParams['figure.figsize'] = (6, 12)
----> 2 all_data.columns = range(0,2)
      3 all_data.loc[6000, 1]
      4 
      5 runs  = range(0, 2)

NameError: name 'all_data' is not defined

The plots above show the total population of single two single runs for different possible trade income.

We see:

  • cyclical rise and fall for low possible income from trade,
  • stable society with high trade income with higher possible income from trade

This is in accordance with findings in archeological reserach that state that there have been cycles of growth and collapse in the Maya civilisation from 2000 BC to ~ 0 BC and that only after that in the socalled Classical Period a signifficant overshoot and collapse without recovery was observed.

In our model, this can be reproduced via an increase in trade efficiency, that leads to qualitatively different model behavior.


In [86]:
pylab.rcParams['figure.figsize'] = (6, 12)
all_data.columns = range(0,2)
all_data.loc[6000, 1]

runs  = range(0, 2)
r_trades = all_data.index.values
fig = plt.figure()

annotations=['A)', 'B)', 'C)']
colors = ['#336600', '#66FF33', '#FF9900', 'black']
for i, r_trade in enumerate(r_trades[[0,1,3]]):
    
    ax = fig.add_subplot(3, 1, i + 1)
    observables = ['forest_state_3_cells', 'forest_state_2_cells', 'forest_state_1_cells', 'total_agriculture_cells']
    forest_data = all_data.loc[r_trade, run][observables]
    forest_data['forest_state_1_cells'] = forest_data['forest_state_1_cells'].sub(forest_data['total_agriculture_cells'])
    forest_data.columns = ['climax forest', 'secondary regrowth', 'cleared land', 'agriculture cells']
    run = 1
    ln1 = forest_data.plot.area(stacked=True, 
                                legend=(True if i == len(r_trades) - 2 else False), 
                                ax=ax,
                                color=colors)
    ax2 = ax.twinx()
    ln2 = all_data.loc[r_trade, run]['total_population'].plot(legend=(True if i == len(r_trades) - 2 else False), 
                                                              ax=ax2, 
                                                              color='k')
    #print(all_data.loc[r_trade, run][observables])
    ax.set_xlim([0,1000])
    ax.annotate(annotations[i], xy=(0,0), xycoords='data', xytext=(0.9, 0.9), textcoords='axes fraction', fontsize=18)
    ax2.set_ylabel('total population')
    ax.set_ylabel('forest state')
    ax.set_ylim([0, 101000])
    if i == len(r_trades)-2:
        ax.set_xlabel('time in years')
        lgd2 = ax.legend(loc=1, bbox_to_anchor=[1, .4])
        lgd1 = ax2.legend(loc=1, bbox_to_anchor=[1., .55])
#fig.tight_layout()
fig.savefig('longterm_population_development.pdf', transparent=True, dpi=200)


/home/jakob/anaconda3/envs/py36/lib/python3.6/site-packages/ipykernel/__main__.py:16: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy

In [ ]: