Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix 394 roc #398

Merged
merged 4 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion metplotpy/plots/base_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import os
import logging
import warnings
import numpy as np
import yaml
from typing import Union
Expand Down Expand Up @@ -343,6 +344,9 @@ def save_to_file(self):

image_name = self.get_config_value('plot_filename')

# Suppress deprecation warnings from third-party packages that are not in our control.
warnings.filterwarnings("ignore", category=DeprecationWarning)

# Create the directory for the output plot if it doesn't already exist
dirname = os.path.dirname(os.path.abspath(image_name))
if not os.path.exists(dirname):
Expand All @@ -354,9 +358,12 @@ def save_to_file(self):
self.logger.error(f"FileNotFoundError: Cannot save to file"
f" {image_name}")
# print("Can't save to file " + image_name)
except ResourceWarning:
self.logger.warning(f"ResourceWarning: in _kaleido"
f" {image_name}")

except ValueError as ex:
self.logger.error(f"ValueError: Could not save output file.")
# print(ex)
else:
self.logger.error(f"The figure {dirname} cannot be saved.")
print("Oops! The figure was not created. Can't save.")
Expand Down
27 changes: 7 additions & 20 deletions metplotpy/plots/roc_diagram/roc_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
import yaml
import re
import sys
import warnings
# with warnings.catch_warnings():
# warnings.simplefilter("ignore", category="DeprecationWarning")
# warnings.simplefilter("ignore", category="ResourceWarning")

import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots
Expand All @@ -29,6 +34,7 @@
import metcalcpy.util.utils as calc_util



class ROCDiagram(BasePlot):
"""
Creates a ROC diagram based on settings in a config file and
Expand Down Expand Up @@ -154,6 +160,7 @@ def remove_file(self):
"""

image_name = self.get_config_value('plot_filename')
warnings.filterwarnings("ignore", category=DeprecationWarning)

# remove the old file if it exist
if os.path.exists(image_name):
Expand Down Expand Up @@ -363,27 +370,7 @@ def add_trace_copy(trace):

return fig

def save_to_file(self):
"""Saves the image to a file specified in the config file.
Prints a message if fails

Args:

Returns:

"""
image_name = self.get_config_value('plot_filename')
if self.figure:
try:
self.figure.write_image(image_name)

except FileNotFoundError:
self.logger.error(f"FileNotFoundError: Cannot save "
f"{image_name} to file.")
except ValueError as ex:
self.logger.error(f"ValueError: {ex}")
else:
self.logger.warning("Oops! The figure wasn't created. Cannot save file.")

def write_output_file(self):
"""
Expand Down
3 changes: 2 additions & 1 deletion test/roc_diagram/PCT_ROC.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ show_signif:
- 'False'
stat_input: PCT_ROC.data
sync_yaxes: 'False'
title: test title
title: test title PCT ROC data

title_align: 0.5
title_offset: -2
title_size: 1.4
Expand Down
2 changes: 1 addition & 1 deletion test/roc_diagram/custom_roc_diagram.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dump_points_1: 'False'
# points_path: '/dir_to_save_points1_file'

# Title settings
title: "Custom: ROC PCT 20200507_074426 "
title: "Custom: ROC CTC 20200507_074426 "
# value of 0.5 centers the title, smaller values moves text to the left
title_align: 0.3
# -2 locates title at top, -1.5 puts title inside plotting region
Expand Down