Repository navigation
Expand file tree
/
Copy pathplot_cell_data.py
More file actions
100 lines (91 loc) · 2.62 KB
/
Copy pathplot_cell_data.py
File metadata and controls
100 lines (91 loc) · 2.62 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#
# plot_cell_data.py: plot a cell's custom data value over time
#
# Usage:
# python plot_cell_data.py <...>
# i.e., the arguments <...> are optional and have defaults.
#
# Dependencies include matplotlib and numpy. We recommend installing the Anaconda Python3 distribution.
#
# Examples (run from directory containing the .xml and .mat files):
# python
#
# Author: Randy Heiland
#
__author__ = "Randy Heiland"
import sys
import glob
import os
import xml.etree.ElementTree as ET
import math
from pyMCDS import pyMCDS
#join_our_list = "(Join/ask questions at https://groups.google.com/forum/#!forum/physicell-users)\n"
join_our_list = "( Submit a ticket at https://sourceforge.net/p/physicell/tickets/)\n"
try:
import matplotlib
import matplotlib.colors as mplc
from matplotlib.patches import Circle, Ellipse, Rectangle
from matplotlib.collections import PatchCollection
except:
print("\n---Error: cannot import matplotlib")
print("---Try: python -m pip install matplotlib")
print(join_our_list)
# print("---Consider installing Anaconda's Python 3 distribution.\n")
raise
try:
import numpy as np # if mpl was installed, numpy should have been too.
except:
print("\n---Error: cannot import numpy")
print("---Try: python -m pip install numpy\n")
print(join_our_list)
raise
from collections import deque
try:
# apparently we need mpl's Qt backend to do keypresses
# matplotlib.use("Qt5Agg")
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
except:
print("\n---Error: cannot use matplotlib's TkAgg backend")
print(join_our_list)
# print("Consider installing Anaconda's Python 3 distribution.")
raise
current_idx = 0
print("# args=",len(sys.argv)-1)
xml_files = glob.glob('output*.xml')
xml_files.sort()
print(xml_files)
#for current_idx in range(len(svg_files)):
#mcds = pyMCDS(xml_files[0], '.') # first file
mcds = pyMCDS(xml_files[-1], '.') # last file
print(mcds.data.keys())
# Now our data lives in:
#mcds.data
tval = mcds.get_time()
cell_ids = mcds.data['discrete_cells']['ID'].astype(int)
print('cell_ids = ',cell_ids)
print()
cell_vars = mcds.get_cell_variables()
print('cell_vars = ',cell_vars)
val = mcds.data['discrete_cells']['assembled_virion']
print(val)
sum = val.sum()
print("sum = ",sum)
x=[]
y=[]
for fname in xml_files:
mcds = pyMCDS(fname, '.') # last file
tval = mcds.get_time()
x.append(tval)
val = mcds.data['discrete_cells']['assembled_virion']
y.append(val.sum())
# fig, ax = plt.subplot(1, figsize=(6,4))
# ax.plot(x,y)
plt.plot(x,y)
plt.xlabel("time")
plt.ylabel("total assembled_virion")
#ax.set_xlabel('time')
#ax.set_ylabel('')
# keep last plot displayed
#plt.ioff()
plt.show()