piegy 1.1.3__py3-none-any.whl → 1.1.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
piegy/test_var.py CHANGED
@@ -31,7 +31,7 @@ Additional tools (can be called directly):
31
31
  - var_convergence2: Find the simulatoin results of test_var2 that diverge.
32
32
  '''
33
33
 
34
- from . import model as model
34
+ from . import simulation
35
35
  from .tools import figure_tools as figure_t
36
36
  from . import analysis as analysis
37
37
  from . import data_tools as data_t
@@ -45,7 +45,7 @@ import numpy as np
45
45
  # can be 'o-', 'x-', ...
46
46
  DOTTED_CURVE_TYPE = 'o-'
47
47
 
48
- # map patch_var name to index in the patch class (in stochastic_model.py)
48
+ # map patch_var name to index in the patch class (in simulation.py)
49
49
  PATCH_VAR_DICT = {'mu1': 0, 'mu2': 1, 'w1': 2, 'w2': 3, 'kappa1': 4, 'kappa2': 5}
50
50
 
51
51
  # display name (in latex)
@@ -54,16 +54,16 @@ PATCH_VAR_DISP = {'mu1': r'$\mu_U$', 'mu2': r'$\mu_V$', 'w1': r'$w_U$', 'w2': r'
54
54
 
55
55
 
56
56
 
57
- def test_var1(sim, var, values, dirs, compress_itv = None, predict_runtime = False):
57
+ def test_var1(mod, var, values, dirs, compress_itv = None, predict_runtime = False):
58
58
  '''
59
59
  Test the influence of one patch variable on simulation results.
60
60
 
61
61
  Inputs::
62
- - sim: a simulation object. All tests will use parameters of sim, except for the variable to test.
62
+ - sim: a simulation.model object. All tests will use parameters of mod, except for the variable to test.
63
63
  - var: str, which patch variable to test. e.g. var can be 'mu1', 'w2', 'kappa2', ...
64
64
  - values: 1D np.array or list, what values of var to test.
65
65
  - dirs: str, where to save data.
66
- - compress_itv: int, whether to reduce data size (if not 1), passed to model.simulation.compress_data function.
66
+ - compress_itv: int, whether to reduce data size (if not 1), passed to simulation.model.compress_data function.
67
67
  - predict_runtime: bool, whether to predict how much time left for each test.
68
68
 
69
69
  Returns::
@@ -79,16 +79,16 @@ def test_var1(sim, var, values, dirs, compress_itv = None, predict_runtime = Fal
79
79
  var_dirs = []
80
80
 
81
81
  for k in range(len(values)):
82
- sim2 = sim.copy(copy_data = False)
82
+ sim2 = mod.copy(copy_data = False)
83
83
  current_var_str = var + '=' + str(values[k]) # e.g., 'mu1=0.1'
84
84
  var_dirs.append(dirs + '/' + current_var_str)
85
85
 
86
- for i in range(sim.N):
87
- for j in range(sim.M):
86
+ for i in range(mod.N):
87
+ for j in range(mod.M):
88
88
  sim2.P[i][j][PATCH_VAR_DICT[var]] = values[k]
89
89
 
90
90
  try:
91
- model.run(sim2, predict_runtime, message = current_var_str + ', ')
91
+ simulation.run(sim2, predict_runtime, message = current_var_str + ', ')
92
92
  if compress_itv != None:
93
93
  sim2.compress_data(compress_itv)
94
94
  data_t.save_data(sim2, var_dirs[k], print_msg = False)
@@ -100,12 +100,12 @@ def test_var1(sim, var, values, dirs, compress_itv = None, predict_runtime = Fal
100
100
 
101
101
 
102
102
 
103
- def test_var2(sim, var1, var2, values1, values2, dirs, compress_itv = None, predict_runtime = False):
103
+ def test_var2(mod, var1, var2, values1, values2, dirs, compress_itv = None, predict_runtime = False):
104
104
  '''
105
105
  Two-variable version of test_var1. Test the influence of two varibles on simulation results.
106
106
 
107
107
  Inputs:
108
- - sim: a simulation object. All tests will use the parameters of sim, except for the two vars to be tested.
108
+ - sim: a simulation.model object. All tests will use the parameters of mod, except for the two vars to be tested.
109
109
  - var1: str, the first variable to test.
110
110
  - var2: str, the second variable to test.
111
111
  - values1: 1D list or np.array, values for var1.
@@ -125,17 +125,17 @@ def test_var2(sim, var1, var2, values1, values2, dirs, compress_itv = None, pred
125
125
 
126
126
  for k1 in range(len(values1)):
127
127
  for k2 in range(len(values2)):
128
- sim2 = sim.copy(copy_data = False)
128
+ sim2 = mod.copy(copy_data = False)
129
129
  current_var_str = var1 + '=' + str(values1[k1]) + ', ' + var2 + '=' + str(values2[k2]) # e.g., mu1=0.1, mu2=0.2
130
130
  var_dirs[k1].append(dirs + '/' + current_var_str)
131
131
 
132
- for i in range(sim.N):
133
- for j in range(sim.M):
132
+ for i in range(mod.N):
133
+ for j in range(mod.M):
134
134
  sim2.P[i][j][PATCH_VAR_DICT[var1]] = values1[k1]
135
135
  sim2.P[i][j][PATCH_VAR_DICT[var2]] = values2[k2]
136
136
 
137
137
  try:
138
- model.run(sim2, predict_runtime, message = current_var_str + ', ')
138
+ simulation.run(sim2, predict_runtime, message = current_var_str + ', ')
139
139
  if compress_itv != None:
140
140
  sim2.compress_data(compress_itv)
141
141
  data_t.save_data(sim2, var_dirs[k1][k2], print_msg = False)
@@ -488,11 +488,11 @@ def var_convergence1(var_dirs, interval = 20, start = 0.8, fluc = 0.07):
488
488
 
489
489
  Inputs:
490
490
  - var_dirs: Return value of test_var1
491
- - interval: int. One of the inputs of model_analysis.check_convergence.
491
+ - interval: int. One of the inputs of analysis.check_convergence.
492
492
  The size of interval to take average over.
493
- - start: (0,1) float. One of the inputs of model_analysis.check_convergence.
493
+ - start: (0,1) float. One of the inputs of analysis.check_convergence.
494
494
  Convergence is expected to start from at least this point.
495
- - fluc: (0,1) float. One of the inputs of model_analysis.check_convergence.
495
+ - fluc: (0,1) float. One of the inputs of analysis.check_convergence.
496
496
  Expect the difference between any two small intervals (a quotient-form difference) should be less than fluc.
497
497
 
498
498
  Returns:
@@ -503,11 +503,11 @@ def var_convergence1(var_dirs, interval = 20, start = 0.8, fluc = 0.07):
503
503
 
504
504
  for dirs in var_dirs:
505
505
  try:
506
- sim = data_t.read_data(dirs)
506
+ mod = data_t.read_data(dirs)
507
507
  except FileNotFoundError:
508
508
  print(dirs + ' data not found, skipped')
509
509
  continue
510
- if not analysis.check_convergence(sim, interval, start, fluc):
510
+ if not analysis.check_convergence(mod, interval, start, fluc):
511
511
  diverge_list.append(dirs)
512
512
 
513
513
  return diverge_list
@@ -554,11 +554,11 @@ def var_convergence2(var_dirs, interval = 20, start = 0.8, fluc = 0.07):
554
554
 
555
555
  Inputs:
556
556
  - var_dirs: Return value of test_var2
557
- - interval: int. One of the inputs of model_analysis.check_convergence.
557
+ - interval: int. One of the inputs of analysis.check_convergence.
558
558
  The size of interval to take average over.
559
- - start: (0,1) float. One of the inputs of model_analysis.check_convergence.
559
+ - start: (0,1) float. One of the inputs of analysis.check_convergence.
560
560
  Convergence is expected to start from at least this point.
561
- - fluc: (0,1) float. One of the inputs of model_analysis.check_convergence.
561
+ - fluc: (0,1) float. One of the inputs of analysis.check_convergence.
562
562
  Expect the difference between any two small intervals (a quotient-form difference) should be less than fluc.
563
563
 
564
564
  Returns:
@@ -570,11 +570,11 @@ def var_convergence2(var_dirs, interval = 20, start = 0.8, fluc = 0.07):
570
570
  for sublist in var_dirs:
571
571
  for dirs in sublist:
572
572
  try:
573
- sim = data_t.read_data(dirs)
573
+ mod = data_t.read_data(dirs)
574
574
  except FileNotFoundError:
575
575
  print(dirs + ' data not found, skipped')
576
576
  continue
577
- if not analysis.check_convergence(sim, interval, start, fluc):
577
+ if not analysis.check_convergence(mod, interval, start, fluc):
578
578
  diverge_list.append(dirs)
579
579
 
580
580
  return diverge_list
@@ -7,7 +7,7 @@ Functions:
7
7
  - scatter: Make a scatter plot. Sets title, text ... as well.
8
8
  - gen_title: Generates a title when the plot is about an interval of time.
9
9
  - gen_text: Generates a text about standard deviation info.
10
- - scale_interval: scale interval if sim's data was already reduced.
10
+ - scale_interval: scale interval if mod's data was already reduced.
11
11
  - ave_interval: Calculates average value of data over a time interval.
12
12
  - ave_interval_1D: Return in a 1D format.
13
13
  - config_mpl: Configure Matplotlib parameters in a nice format
@@ -201,13 +201,13 @@ def ave_interval_1D(data, start_index, end_index):
201
201
 
202
202
 
203
203
  def scale_interval(interval, compress_itv):
204
- # scale interval if sim's data was already reduced.
204
+ # scale interval if mod's data was already reduced.
205
205
  if compress_itv < 1:
206
206
  raise ValueError('figures.scale_interval has compress_itv < 1:', compress_itv)
207
207
 
208
208
  interval = int(interval / compress_itv)
209
209
  if interval == 0:
210
- print('Warning: data already smoothed by an interval: sim.compress_itv =', compress_itv, 'which is coarser than your', interval)
210
+ print('Warning: data already smoothed by an interval: mod.compress_itv =', compress_itv, 'which is coarser than your', interval)
211
211
  interval = 1
212
212
 
213
213
  return interval
piegy/videos.py CHANGED
@@ -106,12 +106,12 @@ def get_max_lim(lims):
106
106
 
107
107
 
108
108
 
109
- def frame_lim(sim, func, frames):
109
+ def frame_lim(mod, func, frames):
110
110
  '''
111
111
  Find a large enough xlim and ylim for frames, if not heatmaps.
112
112
 
113
113
  Inputs:
114
- sim: A stochastic_model.simulation object, the simulation results.
114
+ mod: A simulation.model object, the simulation results.
115
115
  frames: How many frame to make for the video.
116
116
 
117
117
  Returns:
@@ -125,15 +125,17 @@ def frame_lim(sim, func, frames):
125
125
  V_ylist = []
126
126
 
127
127
  for i in range(10):
128
- U_fig, V_fig = func(sim, start = i / 10, end = (i / 10 + 1 / frames))
128
+ fig_U, ax_U = plt.subplots()
129
+ fig_V, ax_V = plt.subplots()
130
+ ax_U, ax_V = func(mod, ax_U = ax_U, ax_V = ax_V, start = i / 10, end = (i / 10 + 1 / frames))
129
131
 
130
- U_xlist.append(U_fig.get_axes()[0].get_xlim())
131
- U_ylist.append(U_fig.get_axes()[0].get_ylim())
132
- V_xlist.append(V_fig.get_axes()[0].get_xlim())
133
- V_ylist.append(V_fig.get_axes()[0].get_ylim())
132
+ U_xlist.append(ax_U.get_xlim())
133
+ U_ylist.append(ax_U.get_ylim())
134
+ V_xlist.append(ax_V.get_xlim())
135
+ V_ylist.append(ax_V.get_ylim())
134
136
 
135
- plt.close(U_fig)
136
- plt.close(V_fig)
137
+ plt.close(fig_U)
138
+ plt.close(fig_V)
137
139
 
138
140
  # get the largest 'range' based on the lists
139
141
  U_xlim = get_max_lim(U_xlist)
@@ -146,12 +148,12 @@ def frame_lim(sim, func, frames):
146
148
 
147
149
 
148
150
 
149
- def frame_heatmap_lim(sim, func, frames):
151
+ def frame_heatmap_lim(mod, func, frames):
150
152
  '''
151
153
  Find a large enough color bar lim for frames, if heatmaps.
152
154
 
153
155
  Inputs:
154
- sim: A stochastic_model.simulation object, the simulation results.
156
+ mod: A simulation.model object, the simulation results.
155
157
  frames: How many frame to make for the video.
156
158
 
157
159
  Returns:
@@ -164,7 +166,7 @@ def frame_heatmap_lim(sim, func, frames):
164
166
  for i in range(10):
165
167
  fig_U, ax_U = plt.subplots()
166
168
  fig_V, ax_V = plt.subplots()
167
- ax_U, ax_V = func(sim, ax_U = ax_U, ax_V = ax_V, start = i / 10, end = (i / 10 + 1 / frames))
169
+ ax_U, ax_V = func(mod, ax_U = ax_U, ax_V = ax_V, start = i / 10, end = (i / 10 + 1 / frames))
168
170
 
169
171
  U_list.append(ax_U.collections[0].get_clim())
170
172
  V_list.append(ax_V.collections[0].get_clim())
@@ -201,12 +203,12 @@ def make_mp4(video_dir, frame_dir, fps):
201
203
 
202
204
 
203
205
 
204
- def make_video(sim, func_name = 'UV_heatmap', frames = 100, dpi = 200, fps = 30, U_color = 'Greens', V_color = 'Purples', annot = False, fmt = '.3g', del_frames = False, dirs = 'videos'):
206
+ def make_video(mod, func_name = 'UV_heatmap', frames = 100, dpi = 200, fps = 30, U_color = 'Greens', V_color = 'Purples', annot = False, fmt = '.3g', del_frames = False, dirs = 'videos'):
205
207
  '''
206
208
  Make a mp4 video based on simulation results.
207
209
 
208
210
  Inputs:
209
- - sim: a stochastic_model.simulation object, the simulation results.
211
+ - mod: a simulation.model object, the simulation results.
210
212
  - func_name: what function to use to make the frames. Should be one of the functions in figures.py
211
213
  - frames: how many frames to make. Use more frames for more smooth evolutions.
212
214
  - dpi: dots per inch.
@@ -232,10 +234,10 @@ def make_video(sim, func_name = 'UV_heatmap', frames = 100, dpi = 200, fps = 30,
232
234
 
233
235
  if 'heatmap' in func_name:
234
236
  # make sure a fixed color bar for all frames
235
- U_clim, V_clim = frame_heatmap_lim(sim, func, frames)
237
+ U_clim, V_clim = frame_heatmap_lim(mod, func, frames)
236
238
  else:
237
239
  # make sure y axis not changing if not making heatmaps
238
- U_xlim, U_ylim, V_xlim, V_ylim = frame_lim(sim, func, frames)
240
+ U_xlim, U_ylim, V_xlim, V_ylim = frame_lim(mod, func, frames)
239
241
 
240
242
 
241
243
  U_frame_dirs = dirs + '/U-' + func_name
@@ -259,9 +261,9 @@ def make_video(sim, func_name = 'UV_heatmap', frames = 100, dpi = 200, fps = 30,
259
261
  fig_V, ax_V = plt.subplots(figsize = (6.4, 4.8))#, constrained_layout = True)
260
262
 
261
263
  if 'heatmap' in func_name:
262
- ax_U, ax_V = func(sim, ax_U = ax_U, ax_V = ax_V, U_color = U_color, V_color = V_color, start = i / frames, end = (i + 1) / frames, annot = annot, fmt = fmt)
264
+ ax_U, ax_V = func(mod, ax_U = ax_U, ax_V = ax_V, U_color = U_color, V_color = V_color, start = i / frames, end = (i + 1) / frames, annot = annot, fmt = fmt)
263
265
  else:
264
- ax_U, ax_V = func(sim, ax_U = ax_U, ax_V = ax_V, U_color = U_color, V_color = V_color, start = i / frames, end = (i + 1) / frames)
266
+ ax_U, ax_V = func(mod, ax_U = ax_U, ax_V = ax_V, U_color = U_color, V_color = V_color, start = i / frames, end = (i + 1) / frames)
265
267
 
266
268
  if 'heatmap' in func_name:
267
269
  ax_U.collections[0].set_clim(U_clim)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: piegy
3
- Version: 1.1.3
3
+ Version: 1.1.4
4
4
  Summary: Payoff-Driven Stochastic Spatial Model for Evolutionary Game Theory
5
5
  Author-email: Chenning Xu <cxu7@caltech.edu>
6
6
  License: BSD 3-Clause License
@@ -0,0 +1,16 @@
1
+ piegy/__init__.py,sha256=plq8y9IE9ilaKtEFIblJ_QexipAvPBXoalXhXLbs71Q,3244
2
+ piegy/__version__.py,sha256=p8vZzyuX_tcu2qlBukCqdCu3SozzbpVqCUOaVaEe8rE,856
3
+ piegy/analysis.py,sha256=5X6cpEAgFlHiRoaVmqYALlUvkep_LmrqpJHLCtQrd9Q,8727
4
+ piegy/data_tools.py,sha256=Rw1fzeCGbxAB8MqTxZNZnOkVn7FmoUGoRz21scTAvF0,3550
5
+ piegy/figures.py,sha256=bMHS7gTYtWdixUMW_wokBD6NSj_WOjQtnWp0R8VXChw,19059
6
+ piegy/simulation.py,sha256=ngyLGzXAePYlyrcRznxWA7FEvGl9Gad976Sh1gHT0hU,45178
7
+ piegy/test_var.py,sha256=g6BS_G_sewLn-8urUdTnlaVd8LYt_5GDvQQr_4bmNDU,23604
8
+ piegy/videos.py,sha256=QfSpOdwfaDsrQYRoiHmZ6gowzRQHom3m8kx1P65_8sM,10218
9
+ piegy/tools/__init__.py,sha256=eYOl_HJHDonYexfrmKh3koOlxvtSo46vH6jHvCEEB4k,300
10
+ piegy/tools/figure_tools.py,sha256=54vJSJMReXidFnSPE_xFvedtgnJU3d55zQDPNBLGs98,6975
11
+ piegy/tools/file_tools.py,sha256=ncxFWeHfIE-GYLQlOrahFlhBgqPyuY3R5_93fpQeCEs,630
12
+ piegy-1.1.4.dist-info/licenses/LICENSE.txt,sha256=wfzEht_CxOcfGGmg3f3at4mWJb9rTBjA51mXLl_3O3g,1498
13
+ piegy-1.1.4.dist-info/METADATA,sha256=R3zSrrCR85dtpvtQBmfMTikrnuqSPSJveHjOtIcUr-E,5291
14
+ piegy-1.1.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
15
+ piegy-1.1.4.dist-info/top_level.txt,sha256=k4QLYL8PqdqDuy95-4NZD_FVLqJDsmq67tpKkBn4vMw,6
16
+ piegy-1.1.4.dist-info/RECORD,,
@@ -1,16 +0,0 @@
1
- piegy/__init__.py,sha256=Lrh6NegSvo6LOCXg_tBTu804eicnHpQY2zmE0FchjKE,3241
2
- piegy/__version__.py,sha256=bfx1My4_mpMZlHLCS9hPCp888d56dz178h1mb2itmNo,724
3
- piegy/analysis.py,sha256=1cF06igQMGJGVjLiyhtgepGk8fYhzvL0orI48tOK1qY,8713
4
- piegy/data_tools.py,sha256=lNFOX4H0o_WfRSNQoC9QGCK66-IdrZ0zCnz12N-Ael4,3599
5
- piegy/figures.py,sha256=xXvr9LcGGhpeVibWTnIiDQlc_kBPibT8qYU5ALKS-zw,19063
6
- piegy/model.py,sha256=iTC0Ybp4qtrCcX_NcmEEk4bbqIXqUh470eF0CPbeEK0,45311
7
- piegy/test_var.py,sha256=HpdJf8i90iWteoJaVnYt37NJo1it2cf9srCsuYtwc7k,23628
8
- piegy/videos.py,sha256=ReLrMwwgZfOgtsXPW5q29AAyFv0_E4A3DKo6BUFzups,10213
9
- piegy/tools/__init__.py,sha256=eYOl_HJHDonYexfrmKh3koOlxvtSo46vH6jHvCEEB4k,300
10
- piegy/tools/figure_tools.py,sha256=IWxMF_Yali37l2knzKLAcvrE8ndAQhCixfUu1_sWEf0,6975
11
- piegy/tools/file_tools.py,sha256=ncxFWeHfIE-GYLQlOrahFlhBgqPyuY3R5_93fpQeCEs,630
12
- piegy-1.1.3.dist-info/licenses/LICENSE.txt,sha256=wfzEht_CxOcfGGmg3f3at4mWJb9rTBjA51mXLl_3O3g,1498
13
- piegy-1.1.3.dist-info/METADATA,sha256=HhWIqo8y685rQPZv-fZnDhz-n1O4gW4aZZ4FfcF3UHE,5291
14
- piegy-1.1.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
15
- piegy-1.1.3.dist-info/top_level.txt,sha256=k4QLYL8PqdqDuy95-4NZD_FVLqJDsmq67tpKkBn4vMw,6
16
- piegy-1.1.3.dist-info/RECORD,,
File without changes