Skip to content

Commit 3e8e319

Browse files
committed
Fixing minor issues for figures display/closing [skip ci]
1 parent 90c8d90 commit 3e8e319

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

raidionicsval/Plotting/metric_versus_binned_boxplot.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def compute_binned_metric_over_metric_boxplot(folder, data, metric1, metric2, cr
7474
sns_plot = sns.boxplot(x=data[metric1], y=binned)
7575
sns_plot.figure.savefig(os.path.join(folder, 'boxplot_' + metric1 + '_over_' + metric2 + '_normal_bins' + postfix + '.png'),
7676
dpi=300, bbox_inches="tight")
77+
plt.close(sns_plot.figure)
7778

7879
binned, edges = pd.qcut(data[metric2], q=nb_bins, retbins=True, precision=2, duplicates='drop')
7980
nb_bins = len(edges) - 1
@@ -125,6 +126,7 @@ def compute_binned_metric_over_metric_boxplot(folder, data, metric1, metric2, cr
125126
sns_plot.figure.savefig(os.path.join(folder, 'boxplot_' + metric1 + '_over_' + metric2 + '_equal_bins' + postfix + '.png'),
126127
dpi=300, bbox_inches="tight")
127128
# plt.show()
129+
plt.close(sns_plot.figure)
128130

129131
print('\n\nTotal selected: {}, total to find: {}. Recall: {:.4f}'.format(total_selected, total_to_find,
130132
total_selected / total_to_find))

raidionicsval/Studies/AbstractStudy.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ def compute_and_plot_metric_over_metric_categories(self, class_name: str, data=N
271271
for cat in optimal_results_per_cutoff.keys():
272272
# @TODO. Must include a new fold average specific for the studies, with mean and std values as input,
273273
# which is different from the inputs to the computation in the validation part....
274+
if len(optimal_results_per_cutoff[cat]) == 0:
275+
print("Skipping analysis for {} {}. Collected pd.DataFrame is empty.\n".format(metric2, cat))
276+
return
274277
self.compute_fold_average(self.output_folder, data=optimal_results_per_cutoff[cat],
275278
class_optimal=self.classes_optimal, metrics=self.metric_names,
276279
suffix=suffix + '_' + metric2 + '_' + cat,

raidionicsval/Validation/extra_metrics_computation.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,26 @@ def compute_overall_metrics_correlation(input_folder, output_folder, data=None,
310310
results_for_matrix_df = results_for_matrix_df.dropna()
311311
results_for_matrix_df = results_for_matrix_df.apply(pd.to_numeric)
312312
corr_matrix = results_for_matrix_df.corr()
313-
# print(corr_matrix.style.background_gradient(cmap='coolwarm').set_precision(2).render())
314313
export_correlation_matrix_to_latex(output_folder, corr_matrix, suffix='_' + class_name + suffix)
314+
export_correlation_matrix_to_html(output_folder, corr_matrix, suffix='_' + class_name + suffix)
315+
316+
317+
def export_correlation_matrix_to_html(output_folder, matrix, suffix=""):
318+
"""
319+
Converts and saves the correlation matrix as an html table
320+
321+
...
322+
Attributes
323+
----------
324+
output_folder: str
325+
Destination folder where the latex table will be saved under correlation_matrix.html
326+
matrix: pd.DataFrame
327+
Correlation matrix object as a pandas DataFrame
328+
suffix: (optional) str
329+
Name to append to the end of the destination file
330+
"""
331+
matrix_filename = os.path.join(output_folder, 'correlation_matrix' + suffix + '.html')
332+
matrix.style.background_gradient(cmap='coolwarm').to_html(matrix_filename)
315333

316334

317335
def export_correlation_matrix_to_latex(output_folder, matrix, suffix=""):

raidionicsval/Validation/validation_utilities.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ def best_segmentation_probability_threshold_analysis_inner(folder, detection_ove
144144
fig4.savefig(os.path.join(folder, 'Validation', 'OptimalSearch', 'metrics_scatter_over_threshold.png'), dpi=300,
145145
bbox_inches="tight")
146146

147+
plt.close(fig)
148+
plt.close(fig2)
149+
plt.close(fig3)
150+
plt.close(fig4)
147151
return max_overlap, max_threshold
148152

149153

0 commit comments

Comments
 (0)