In [5]:
%pylab inline
pylab.rcParams['figure.figsize'] = (14,14)
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
location = '/home/jakob/Project_MayaSim/Python/output_data/X9_stability_analysis/results/all_trajectories.pkl'
all_data = pd.read_pickle(location)
Populating the interactive namespace from numpy and matplotlib
---------------------------------------------------------------------------
EOFError 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)
83 try:
---> 84 return func(f)
85 finally:
~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/pickle.py in <lambda>(f)
98 try:
---> 99 return read_wrapper(lambda f: pkl.load(f))
100 except Exception:
EOFError: Ran out of input
During handling of the above exception, another exception occurred:
EOFError 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)
83 try:
---> 84 return func(f)
85 finally:
~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/pickle.py in <lambda>(f)
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/compat/pickle_compat.py in load(fh, encoding, compat, is_verbose)
193
--> 194 return up.load()
195 except:
~/anaconda3/envs/py36/lib/python3.6/pickle.py in load(self)
1047 if not key:
-> 1048 raise EOFError
1049 assert isinstance(key, bytes_types)
EOFError:
During handling of the above exception, another exception occurred:
EOFError 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)
83 try:
---> 84 return func(f)
85 finally:
~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/pickle.py in <lambda>(f)
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/compat/pickle_compat.py in load(fh, encoding, compat, is_verbose)
193
--> 194 return up.load()
195 except:
~/anaconda3/envs/py36/lib/python3.6/pickle.py in load(self)
1047 if not key:
-> 1048 raise EOFError
1049 assert isinstance(key, bytes_types)
EOFError:
During handling of the above exception, another exception occurred:
EOFError 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)
83 try:
---> 84 return func(f)
85 finally:
~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/pickle.py in <lambda>(f)
98 try:
---> 99 return read_wrapper(lambda f: pkl.load(f))
100 except Exception:
EOFError: Ran out of input
During handling of the above exception, another exception occurred:
EOFError 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)
83 try:
---> 84 return func(f)
85 finally:
~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/pickle.py in <lambda>(f)
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/compat/pickle_compat.py in load(fh, encoding, compat, is_verbose)
193
--> 194 return up.load()
195 except:
~/anaconda3/envs/py36/lib/python3.6/pickle.py in load(self)
1047 if not key:
-> 1048 raise EOFError
1049 assert isinstance(key, bytes_types)
EOFError:
During handling of the above exception, another exception occurred:
EOFError Traceback (most recent call last)
<ipython-input-5-9c07bf781641> in <module>()
8
9 location = '/home/jakob/Project_MayaSim/Python/output_data/X9_stability_analysis/results/all_trajectories.pkl'
---> 10 all_data = pd.read_pickle(location)
~/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)
82 is_text=False)
83 try:
---> 84 return func(f)
85 finally:
86 for _f in fh:
~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/io/pickle.py in <lambda>(f)
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/compat/pickle_compat.py in load(fh, encoding, compat, is_verbose)
192 up.is_verbose = is_verbose
193
--> 194 return up.load()
195 except:
196 raise
~/anaconda3/envs/py36/lib/python3.6/pickle.py in load(self)
1046 key = read(1)
1047 if not key:
-> 1048 raise EOFError
1049 assert isinstance(key, bytes_types)
1050 dispatch[key[0]](self)
EOFError:
In [97]:
pylab.rcParams['figure.figsize'] = (14,14)
index_names = all_data.index.names
all_data.columns = range(len(all_data.columns))
d_lengths = all_data.index.levels[0]
d_severities = all_data.index.levels[1]
r_trades = all_data.index.levels[2]
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.set_xlabel('total population')
ax.set_ylabel('ecosystem state')
ax.set_xlim([0, 1.2 * 1e7])
#ax.set_xscale('log')
r_trade = 9000
d_length = 0
d_severity = 0
index_value = (d_length, d_severity, r_trade)
print(index_value)
for run in range(20):
tmp = all_data.loc[index_value, run]
d_length = index_value[0]
d_start = 200
d_end = d_start + d_length
d_severity = index_value[1]
alpha = 0 if not d_severity != 0 else float(d_severity*d_length)/10000.
population = tmp['total_population']
ecosystem = tmp['forest_state_3_cells']
ax.plot(population[0:d_start+1],
ecosystem[0:d_start+1],
color='grey', alpha=0.1)
ax.plot(population[d_start:d_end+1],
ecosystem[d_start:d_end+1],
color='red', alpha=0.1)
ax.plot(population[d_end:],
ecosystem[d_end:],
color='green', alpha=0.1)
if population.values[-1] != 0:
ax.scatter(population.values[-1],
ecosystem.values[-1])
(0, 0, 9000)
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-97-54f48d045d03> in <module>()
21 print(index_value)
22 for run in range(20):
---> 23 tmp = all_data.loc[index_value, run]
24 d_length = index_value[0]
25 d_start = 200
/home/jakob/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/core/indexing.py in __getitem__(self, key)
1323 except (KeyError, IndexError):
1324 pass
-> 1325 return self._getitem_tuple(key)
1326 else:
1327 key = com._apply_if_callable(key, self.obj)
/home/jakob/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/core/indexing.py in _getitem_tuple(self, tup)
834 def _getitem_tuple(self, tup):
835 try:
--> 836 return self._getitem_lowerdim(tup)
837 except IndexingError:
838 pass
/home/jakob/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/core/indexing.py in _getitem_lowerdim(self, tup)
946 # we may have a nested tuples indexer here
947 if self._is_nested_tuple_indexer(tup):
--> 948 return self._getitem_nested_tuple(tup)
949
950 # we maybe be using a tuple to represent multiple dimensions here
/home/jakob/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/core/indexing.py in _getitem_nested_tuple(self, tup)
1021
1022 current_ndim = obj.ndim
-> 1023 obj = getattr(obj, self.name)._getitem_axis(key, axis=axis)
1024 axis += 1
1025
/home/jakob/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/core/indexing.py in _getitem_axis(self, key, axis)
1550 # fall thru to straight lookup
1551 self._has_valid_type(key, axis)
-> 1552 return self._get_label(key, axis=axis)
1553
1554
/home/jakob/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/core/indexing.py in _get_label(self, label, axis)
134 raise IndexingError('no slices here, handle elsewhere')
135
--> 136 return self.obj._xs(label, axis=axis)
137
138 def _get_loc(self, key, axis=0):
/home/jakob/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/core/generic.py in xs(self, key, axis, level, drop_level)
2028 if isinstance(index, MultiIndex):
2029 loc, new_index = self.index.get_loc_level(key,
-> 2030 drop_level=drop_level)
2031 else:
2032 loc = self.index.get_loc(key)
/home/jakob/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/core/indexes/multi.py in get_loc_level(self, key, level, drop_level)
2127
2128 return (self._engine.get_loc(
-> 2129 _values_from_object(key)), None)
2130
2131 else:
pandas/_libs/index.pyx in pandas._libs.index.MultiIndexObjectEngine.get_loc (pandas/_libs/index.c:12722)()
pandas/_libs/index.pyx in pandas._libs.index.MultiIndexObjectEngine.get_loc (pandas/_libs/index.c:12643)()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas/_libs/index.c:5280)()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas/_libs/index.c:5126)()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas/_libs/hashtable.c:20523)()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas/_libs/hashtable.c:20477)()
KeyError: (0, 0, 9000)
In [ ]:
Content source: jakobkolb/MayaSim
Similar notebooks: