-
Notifications
You must be signed in to change notification settings - Fork 0
/
age_structure_3d.py
executable file
·36 lines (29 loc) · 1.04 KB
/
age_structure_3d.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python3
import sys
from joblib import delayed, Parallel
import numpy
from matplotlib import pyplot
sys.path.append('..')
from herd import Parameters
import herd.age_structure
sys.path.pop()
start_times = numpy.linspace(0, 1, 12 + 1, endpoint=True)
ages = numpy.linspace(0, 20, 301, endpoint=True)
def get_age_structure(ages, start_time):
parameters = Parameters()
parameters.start_time = start_time
return herd.age_structure.gen(parameters).pdf(ages)
# This seems to be faster sequentially...
with Parallel(n_jobs=1) as parallel:
age_structures = parallel(delayed(get_age_structure)(ages, start_time)
for start_time in start_times)
fig, ax = pyplot.subplots()
im = ax.imshow(age_structures,
extent=(ages[0], ages[-1], start_times[0], start_times[-1]),
cmap='viridis', interpolation='bilinear',
origin='lower', aspect='auto')
ax.set_xlabel('age (y)')
ax.set_ylabel('start time (y)')
fig.colorbar(im, label='density (y$^{-1}$)')
fig.tight_layout()
pyplot.show()