Skip to content

Commit f457574

Browse files
authored
Merge pull request #280 from PhysiCell-Tools/development
fix cell scalars memory leak
2 parents ff2670f + 0299e42 commit f457574

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

bin/vis_base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ def __init__(self, studio_flag, rules_flag, nanohub_flag, config_tab, microenv_t
352352
self.bgcolor = [1,1,1,1] # all 1.0 for white
353353

354354
self.discrete_variable_observed = set()
355+
self.cell_scalar_updated = True
355356

356357
self.cell_scalar_human2mcds_dict = {} # initialize here for vis_tab.py
357358

@@ -559,6 +560,8 @@ def __init__(self, studio_flag, rules_flag, nanohub_flag, config_tab, microenv_t
559560
self.cax1 = None
560561
self.cax2 = None
561562

563+
self.cbar2 = None
564+
562565
self.figsize_width_2Dplot = basic_length
563566
self.figsize_height_2Dplot = basic_length
564567

@@ -1187,7 +1190,7 @@ def get_cell_types_from_config(self):
11871190
for var in uep.findall('cell_definition'):
11881191
name = var.attrib['name']
11891192
self.celltype_name.append(name)
1190-
print("get_cell_types_from_config(): ",self.celltype_name)
1193+
# print("get_cell_types_from_config(): ",self.celltype_name)
11911194
except:
11921195
msgBox = QMessageBox()
11931196
msgBox.setIcon(QMessageBox.Information)
@@ -1728,6 +1731,7 @@ def show_sample_model(self, config_file):
17281731

17291732
def cell_scalar_combobox_changed_cb(self, idx):
17301733
self.discrete_variable_observed = set()
1734+
self.cell_scalar_updated = True
17311735
self.update_plots()
17321736

17331737
#-------------------------------------

bin/vis_tab.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,11 @@ def plot_cell_scalar(self, frame):
838838
mcds = pyMCDS(xml_file_root, self.output_dir, microenv=False, graph=False, verbose=False)
839839
total_min = mcds.get_time() # warning: can return float that's epsilon from integer value
840840
# Get the cell data
841-
df_all_cells = mcds.get_cell_df()
841+
try:
842+
df_all_cells = mcds.get_cell_df()
843+
except:
844+
print("vis_tab.py: plot_cell_scalar(): error performing mcds.get_cell_df()")
845+
return
842846

843847
if self.celltype_filter:
844848
df_cells = df_all_cells.loc[ df_all_cells['cell_type'].isin(self.celltype_filter) ]
@@ -952,6 +956,7 @@ def plot_cell_scalar(self, frame):
952956
days = int(hrs/24)
953957
# print(f"mins={mins}, hrs={hrs}, days={days}")
954958
self.title_str = '%d days, %d hrs, %d mins' % (days, hrs-days*24, mins-hrs*60)
959+
# self.title_str = '%f mins' % (total_min) # rwh: custom
955960
self.title_str += " (" + str(num_cells) + " agents)"
956961

957962
axes_min = mcds.get_mesh()[0][0][0][0]
@@ -1001,14 +1006,21 @@ def plot_cell_scalar(self, frame):
10011006
handles = [lp(self.discrete_variable.index(i)) for i in sorted(list(self.discrete_variable_observed)) if i in self.discrete_variable]
10021007
self.ax0.legend(handles=handles,labels=names_observed, loc='upper center', bbox_to_anchor=(0.5, -0.15),ncols=4)
10031008

1004-
else:
1009+
else: # Note: vis_tab_ecm.py seems to avoid any memory leak and with simpler code
10051010
# If it's not there, we create it
10061011
if self.cax2 is None:
10071012
self.cax2 = self.figure.add_subplot(self.gs[1,0])
10081013
# ax2_divider = make_axes_locatable(self.ax0)
10091014
# self.cax2 = ax2_divider.append_axes("bottom", size="4%", pad="8%")
1010-
self.cbar2 = self.figure.colorbar(cell_plot, ticks=None, cax=self.cax2, orientation="horizontal")
1011-
self.cbar2.ax.tick_params(labelsize=self.fontsize)
1015+
if self.cbar2 is None:
1016+
self.cbar2 = self.figure.colorbar(cell_plot, ticks=None, cax=self.cax2, orientation="horizontal")
1017+
self.cbar2.ax.tick_params(labelsize=self.fontsize)
1018+
elif self.cell_scalar_updated:
1019+
self.cbar2 = self.figure.colorbar(cell_plot, ticks=None, cax=self.cax2, orientation="horizontal")
1020+
self.cell_scalar_updated = False
1021+
else:
1022+
self.cbar2.update_normal(cell_plot) # partial fix for memory leak
1023+
10121024
self.cbar2.ax.set_xlabel(cell_scalar_humanreadable_name, fontsize=self.cbar_label_fontsize)
10131025

10141026
self.ax0.set_title(self.title_str, fontsize=self.title_fontsize)

0 commit comments

Comments
 (0)