Commit 868bbef5154ed2d325a4789ec392b0a3d7d74fdb

Authored by Louis Baetens
1 parent 5c9bdcd6
Exists in master

RMV the deprecated function

Showing 1 changed file with 0 additions and 248 deletions   Show diff stats
PCC/statistics_synthesis.py
... ... @@ -335,220 +335,6 @@ def plot_all_metrics_simplified(data_maja, data_sen2cor, data_fmask, out_fig_nam
335 335  
336 336 return all_means
337 337  
338   -
339   -
340   -
341   -
342   -
343   -
344   -
345   -
346   -
347   -
348   -
349   -
350   -
351   -
352   -
353   -def plot_all_metrics_deprecated(paths_configuration, comparison_parameters, locations, alcd_algo = 'alcd_initial',
354   - grouping = 'by_chain', plot_type = 'errorbar', excluded = [], maja_erode = False, cas_alcd = None):
355   - '''
356   - Plot 4 metrics for all the processing chains
357   - '''
358   -
359   - alcd_algo_dir_name = comparison_parameters["processing"][alcd_algo]["sub_dir"]
360   -
361   - # get all the statistics files
362   - all_stats_files_temp = get_all_stats_files(paths_configuration, locations, alcd_algo_dir_name)
363   - all_stats_files = list(all_stats_files_temp)
364   - if len(excluded) != 0:
365   - for a in all_stats_files_temp:
366   - for e in excluded:
367   - if e in op.basename(a):
368   - all_stats_files.remove(a)
369   -
370   - all_stats_files = sorted(all_stats_files)
371   -
372   - maja_stats = [f for f in all_stats_files if 'maja_ini' in op.basename(f)]
373   - maja_eroded_stats = [f for f in all_stats_files if 'maja_erode_' in op.basename(f)]
374   -
375   - sen2cor_stats = [f for f in all_stats_files if 'sen2cor_ini' in op.basename(f)]
376   - sen2cor_dilated_stats = [f for f in all_stats_files if 'sen2cor_dilat_' in op.basename(f)]
377   -
378   - fmask_stats = [f for f in all_stats_files if 'fmask_ini' in op.basename(f)]
379   - fmask_dilated_stats = [f for f in all_stats_files if 'fmask_dilat_' in op.basename(f)]
380   -
381   -
382   - print('Nb of sites: {}'.format(len(maja_stats)))
383   -
384   - nb_metrics = 4
385   - nb_chains = 3
386   - positions = []
387   -
388   - if grouping == 'by_stats':
389   - width = 1./(nb_metrics)
390   - for chain in range(nb_chains):
391   - positions.append((np.arange(chain*width, 4+chain*width, 1) + width/2))
392   - else:
393   - n = 0
394   - width = 1./(nb_metrics-1)
395   - for k in range(nb_chains):
396   - positions.append(np.linspace(n,n+1,nb_metrics) + width/2)
397   - n += 2
398   -
399   - # Positions of the future bars
400   - positions_maja = positions[0]
401   - positions_sen2cor = positions[1]
402   - positions_fmask = positions[2]
403   -
404   - # Get the data of all the stats
405   - if alcd_algo == "alcd_dilat":
406   - data_maja, means_maja, stds_maja = get_data_and_means(maja_stats)
407   - data_sen2cor, means_sen2cor, stds_sen2cor = get_data_and_means(sen2cor_dilated_stats)
408   - data_fmask, means_fmask, stds_fmask = get_data_and_means(fmask_dilated_stats)
409   -
410   - if alcd_algo == "alcd_initial":
411   - if maja_erode:
412   - data_maja, means_maja, stds_maja = get_data_and_means(maja_eroded_stats)
413   - else:
414   - data_maja, means_maja, stds_maja = get_data_and_means(maja_stats)
415   - data_sen2cor, means_sen2cor, stds_sen2cor = get_data_and_means(sen2cor_stats)
416   - data_fmask, means_fmask, stds_fmask = get_data_and_means(fmask_stats)
417   -
418   -
419   -
420   -
421   - fig, ax = plt.subplots()
422   - ax.yaxis.grid(True) # put horizontal grid
423   -
424   -
425   - if grouping == 'by_stats':
426   - colors=[[0.0, 0.69, 0.20], [0.0, 0.77, 0.80], [0.80, 0.62, 0.0]]
427   - all_legend_names = ['MAJA', 'Sen2Cor', 'Fmask']
428   - ticks_names = ['Accuracy', 'F1-score', 'Recall\n(~sous-detection)', 'Precision\n(~sur-detection)']
429   - ticks_positions = [ 0.125, 1.125, 2.125, 3.125]
430   - ticks_positions = positions[0]
431   - x_limits = [0,4.5]
432   - plt.xlabel('Score type')
433   - else:
434   - colors=[[0.0,0.5,0.5], [0.7,0.1,0.2],[0.8,0.9,0.45],[0.0,0.6,0.9]]
435   - all_legend_names = ['Accuracy', 'F1-score', 'Recall (~sous-detection)', 'Precision (~sur-detection)']
436   - ticks_names = ['MAJA', 'Sen2Cor', 'Fmask']
437   - ticks_positions = [0.5, 2.5, 4.5]
438   - ticks_positions = [np.mean(positions[k])-width for k in range(len(positions))]
439   - print(positions)
440   - x_limits = [0,6]
441   - plt.xlabel('Processing chain')
442   -
443   -
444   - all_means = []
445   - for means_list in [means_maja, means_sen2cor, means_fmask]:
446   - all_means.extend(means_list)
447   -
448   - all_stds = []
449   - for stds_list in [stds_maja, stds_sen2cor, stds_fmask]:
450   - all_stds.extend(stds_list)
451   - up_stds = np.add(all_means, all_stds)
452   - down_stds = np.subtract(all_means, all_stds)
453   -
454   - all_positions = []
455   - for positions_list in [positions_maja, positions_sen2cor, positions_fmask]:
456   - all_positions.extend(positions_list)
457   -
458   -
459   - if plot_type == 'boxplot':
460   - outliers = '' # put 'ow' to have outliers as white points
461   - boxes_maja = plt.boxplot(data_maja, sym=outliers, positions=positions_maja, widths = width, patch_artist=True)
462   - boxes_sen2cor = plt.boxplot(data_sen2cor, sym=outliers, positions=positions_sen2cor, widths = width, patch_artist=True)
463   - boxes_fmask = plt.boxplot(data_fmask, sym=outliers, positions=positions_fmask, widths = width, patch_artist=True)
464   -
465   - if grouping == 'by_stats':
466   - colors_maps = []
467   - for k in range(len(colors)):
468   - for l in range(nb_metrics):
469   - colors_maps.append(colors[k])
470   - k = 0
471   - for bplot in (boxes_maja, boxes_sen2cor, boxes_fmask):
472   - for patch in bplot['boxes']:
473   - colo_spec = colors_maps[k]
474   - patch.set_facecolor(colo_spec)
475   - k += 1
476   - else:
477   - for bplot in (boxes_maja, boxes_sen2cor, boxes_fmask):
478   - for patch, color in zip(bplot['boxes'], colors):
479   - patch.set_facecolor(color)
480   -
481   -
482   - plt.plot(all_positions, all_means, 'ro')
483   -
484   -
485   -
486   - elif plot_type == 'errorbar':
487   -
488   - if grouping == 'by_stats':
489   - colors=[[0.0, 0.69, 0.20], [0.0, 0.77, 0.80], [0.80, 0.62, 0.0]]
490   - plt.errorbar(positions_maja, means_maja, stds_maja, linestyle='None',
491   - marker='o', lw=2.0, color = colors[0], capsize = 10.0)
492   -
493   - plt.errorbar(positions_sen2cor, means_sen2cor, stds_sen2cor, linestyle='None',
494   - marker='o', lw=2.0, color = colors[1], capsize = 10.0)
495   -
496   - plt.errorbar(positions_fmask, means_fmask, stds_fmask, linestyle='None',
497   - marker='o', lw=2.0, color = colors[2], capsize = 10.0)
498   -
499   - else:
500   - colors=[[0.0,0.5,0.5], [0.7,0.1,0.2],[0.8,0.9,0.45],[0.0,0.6,0.9]]
501   - for metric in range(nb_metrics):
502   - color = colors[metric]
503   - print(color)
504   - plt.errorbar(positions_maja[metric], means_maja[metric], stds_maja[metric], linestyle='None',
505   - marker='o', lw=2.0, color = color, capsize = 10.0)
506   -
507   - plt.errorbar(positions_sen2cor[metric], means_sen2cor[metric], stds_sen2cor[metric], linestyle='None',
508   - marker='o', lw=2.0, color = color, capsize = 10.0)
509   -
510   - plt.errorbar(positions_fmask[metric], means_fmask[metric], stds_fmask[metric], linestyle='None',
511   - marker='o', lw=2.0, color = color, capsize = 10.0)
512   -
513   -
514   -
515   - plt.ylim(0,1)
516   - plt.xlim(x_limits)
517   - plt.ylabel('Scores')
518   -
519   -
520   - plt.xticks(([t + width for t in ticks_positions]), ticks_names)
521   -
522   - # legend customization
523   - custom_lines = [Line2D([0], [0], color=colors[j], lw=4) for j in range(len(all_legend_names))]
524   - if plot_type == 'boxplot':
525   - custom_lines.append(Line2D([0], [0], color='w', markerfacecolor = 'r', marker='o'))
526   - all_legend_names.append('Means')
527   - #~ plt.legend(custom_lines, all_legend_names, bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
528   - plt.title('Statistics over {} images'.format(len(maja_stats)))
529   -
530   - plt.show(block = False)
531   -
532   - n = 3
533   - print('Worst accuracies :')
534   - #~ for data in [data_maja, data_sen2cor, data_fmask]:
535   - #~ worst_accuracies_indexes = np.array([d[0] for d in data]).argsort()[:n]
536   - #~ worst_accuracies = [data[idx][0] for idx in worst_accuracies_indexes]
537   - #~ if len(worst_accuracies_indexes) > 0:
538   - #~ print(worst_accuracies_indexes)
539   - #~ print(worst_accuracies)
540   - #~ print([op.basename(maja_stats[idx]) for idx in worst_accuracies_indexes])
541   -
542   - if cas_alcd == None:
543   - out_fig = op.join('tmp_report', 'cas1_stats_synthesis_{}_{}.png'.format(plot_type, grouping))
544   - else:
545   - out_fig = op.join('tmp_report', 'cas{}_stats_synthesis_{}_{}.png'.format(cas_alcd, plot_type, grouping))
546   - plt.savefig(out_fig, bbox_inches='tight')
547   - plt.close()
548   -
549   -
550   - return means_maja, means_sen2cor, means_fmask
551   -
552 338  
553 339  
554 340 def main():
... ... @@ -583,40 +369,6 @@ def main():
583 369 out_fig_name = 'stats_synthesis_{}_cas{}.png'.format(pcc_sub_dir, cas_alcd)
584 370  
585 371 plot_all_metrics_simplified(data_maja, data_sen2cor, data_fmask, out_fig_name)
586   -
587   -
588   -
589   - return
590   -
591   - locations = ['Arles', 'Gobabeb', 'Ispra', 'Marrakech', 'Mongu', 'Orleans', 'Pretoria', 'RailroadValley',
592   - 'Munich', 'Alta_Floresta_Brazil']
593   - excluded = []
594   -
595   -
596   - maja = []
597   - sen2cor = []
598   - fmask = []
599   -
600   - for cas_alcd in [2]:
601   - if cas_alcd == 1:
602   - alcd_algo = 'alcd_initial'
603   - maja_erode = False
604   - elif cas_alcd == 2:
605   - alcd_algo = 'alcd_dilat'
606   - maja_erode = False
607   - elif cas_alcd == 3:
608   - alcd_algo = 'alcd_initial'
609   - maja_erode = True
610   -
611   - #~ grouping = 'by_stats'
612   - #~ plot_all_metrics(paths_configuration, comparison_parameters, locations, alcd_algo,
613   - #~ grouping, plot_type = 'boxplot', excluded = excluded, maja_erode = maja_erode,
614   - #~ cas_alcd = cas_alcd)
615   -
616   - file_suffix = 'HOT17'
617   -
618   -
619   -
620 372  
621 373  
622 374 if __name__ == '__main__':
... ...