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

Feature internal 57 logging remaining #468

Merged
merged 19 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
265b782
Internal Issue #57 added logging support and changed names of setting…
bikegeek Apr 27, 2024
1acfd43
Internal Issue #57 logging support
bikegeek Apr 27, 2024
ef8c3d7
Internal Issue #57 updates for logging and to work with current inher…
bikegeek Apr 27, 2024
19485a5
Replace printing to stdout with logging for both exceptions and warni…
bikegeek May 6, 2024
d4e890d
remove unused catch_warnings()
bikegeek May 6, 2024
937ad8d
Added logging and better error handling
bikegeek May 7, 2024
bee1401
Added logging settings with description
bikegeek May 7, 2024
23f2e91
Remove unused logging assignment
bikegeek May 8, 2024
4792bc0
Merge branch 'develop' of https://github.com/dtcenter/METplotpy into …
bikegeek May 8, 2024
50c2adb
Merge branch 'develop' of https://github.com/dtcenter/METplotpy into …
bikegeek Aug 1, 2024
9967f76
Merge branch 'develop' of https://github.com/dtcenter/METplotpy into …
bikegeek Sep 30, 2024
bca72a7
Make config file generic
bikegeek Sep 30, 2024
3904ca5
METplus-Internal #57 Added logging for the polar ice plot script
bikegeek Sep 30, 2024
44cc6c2
METplus-Internal issue #57 modified logging for skew T to use common …
bikegeek Sep 30, 2024
b815300
Added default config file to test
bikegeek Oct 1, 2024
995c999
Added the default config filename to constructor
bikegeek Oct 1, 2024
7949b2e
Fix import statement
bikegeek Oct 1, 2024
31380c8
Address a SonarQube issue in make_maps() wrt logger
bikegeek Oct 1, 2024
6a648e8
Update metplotpy/plots/polar_plot/polar_ice.yaml
bikegeek Oct 1, 2024
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
42 changes: 36 additions & 6 deletions metplotpy/contributed/tc_rmw/plot_cross_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@
__author__ = 'David Fillmore'

import os
import sys
import argparse
import datetime
import yaml
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import xarray as xr

matplotlib.use('Agg')

from metplotpy.plots import util

def plot_cross_section(config, data_set, args):
"""
Expand All @@ -44,7 +46,24 @@ def plot_cross_section(config, data_set, args):
# Keep the use of 'ax' as this is commonly used
# pylint: disable=invalid-name

# Use default log level of INFO if unspecified
if args.loglevel is not None:
log_level = args.loglevel
else:
log_level = "INFO"

plot_outdir = args.plotdir
start = datetime.datetime.now()
# Create the log file using the same name as the plot name with '_log' and in the
# same location.
try:
os.makedirs(plot_outdir, exist_ok=True)
except FileExistsError:
pass
log_filename = os.path.join(plot_outdir, config['plot_filename'] + '_log' + '.txt')
logger = util.get_common_logger(log_level, log_filename)

logger.info("Begin plotting the cross-section")
plot_width = config['plot_size_width']
plot_height = config['plot_size_height']
fig, ax = plt.subplots(figsize=(plot_width, plot_height))
Expand All @@ -56,7 +75,6 @@ def plot_cross_section(config, data_set, args):
# (Github issue:https://github.com/dtcenter/METcalcpy/issues/308)
field_azi_mean = np.mean(field, axis=0)[:, :, itime]


# originally, the transpose of the field_azi_mean was used, but this is no
# longer necessary. If the transpose is used, the dimensions are incorrect
# and a TypeError will be raised by the contour plot.
Expand All @@ -80,10 +98,13 @@ def plot_cross_section(config, data_set, args):
config['y_tick_stepsize']))
ax.set_yscale(config['y_scale'])
ax.set_ylim(config['y_lim_start'], config['y_lim_end'])
plot_outdir = args.plotdir

logger.info("Saving cross-section plot")
fig.savefig(os.path.join(plot_outdir, config['plot_filename'] + '.png'), dpi=config['plot_res'])
fig.savefig(os.path.join(plot_outdir, config['plot_filename'] + '.pdf'))

logger.info(f"Finished generating cross-section plot in {datetime.datetime.now() - start} seconds")


if __name__ == '__main__':
parser = argparse.ArgumentParser(
Expand All @@ -101,17 +122,26 @@ def plot_cross_section(config, data_set, args):
parser.add_argument('--config', type=str,
required=True,
help='configuration file')
parser.add_argument('--loglevel', type=str,
required=False)

input_args = parser.parse_args()

"""
Read YAML configuration file
"""
plotting_config = yaml.load(
open(input_args.config), Loader=yaml.FullLoader)
try:
plotting_config = yaml.load(
open(input_args.config), Loader=yaml.FullLoader)
except yaml.YAMLError as exc:
sys.exit(1)

"""
Read dataset and call for plotting
"""
input_data = xr.open_dataset(os.path.join(input_args.datadir, input_args.filename))
try:
input_data = xr.open_dataset(os.path.join(input_args.datadir, input_args.filename))
except (ValueError, FileNotFoundError, PermissionError):
sys.exit(1)
plot_cross_section(plotting_config, input_data, input_args)

15 changes: 10 additions & 5 deletions metplotpy/contributed/tc_rmw/test_plot_cross_section.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
# ** P.O.Box 3000, Boulder, Colorado, 80307-3000, USA
# ============================*

export datadir=/path/to/vertically-interpolated-input-data
export plotdir=/path/to/output/plots
export filename=tc_rmw_example_vertical_interp.nc
export configfile=/path/to/configuration-file
export datadir=/Users/minnawin/AF_STIG/feature_57_METplotpy_logging/METplotpy/metplotpy/contributed/tc_rmw/Data
export plotdir=/Users/minnawin/AF_STIG/feature_57_METplotpy_logging/METplotpy/metplotpy/contributed/tc_rmw/plots
export filename=vertically_interpolated.nc
export configfile=/Users/minnawin/AF_STIG/feature_57_METplotpy_logging/METplotpy/metplotpy/contributed/tc_rmw/plot_cross_section.yaml
# Default is set to INFO in code, set to any other value here and add to the arguments
# in the call to the plot_cross_section.py below
export loglevel="ERROR"


python plot_cross_section.py \
--datadir=$datadir \
--plotdir=$plotdir \
--filename=$filename \
--config=$configfile
--config=$configfile \
# --loglevel=$loglevel
15 changes: 12 additions & 3 deletions metplotpy/plots/config/scatter_defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,25 @@ scatters:
- name: Scatter 1
data_file: ./scatter1_plot_data.txt
color: black
width: 1
dash:
line_width: 1
type: horiz_line
position: 0
line_style: dash

- name: Scatter 2
data_file: ./scatter2_plot_data.txt
color: black
line_width: 1
type: horiz_line
position: 0
line_style: dash

log_level: ERROR
log_filename: ./scatter_log.txt
width: 1
dash:

log_filename: stdout
log_level: ERROR

line_type: N/A
line_type: N/A
4 changes: 3 additions & 1 deletion metplotpy/plots/polar_plot/polar_ice.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
input_file: "~/grid_stat_north_000000L_20210305_120000V_pairs.nc"
input_file: "path-to-data/grid_stat_north_000000L_20210305_120000V_pairs.nc"
forecast_netcdf_var_name: "FCST_ice_coverage_SURFACE_FULL"
obs_netcdf_var_name: "OBS_ice_coverage_SURFACE_FULL"
diff_netcdf_var_name: "DIFF_ice_coverage_SURFACE_ice_coverage_SURFACE_FULL"
log_level: info
log_filename: ./polar_ice_log.txt
Loading