From f80914b0993cd2e36692a050de0777a5a3b1c0a0 Mon Sep 17 00:00:00 2001 From: AndrewEichmann-NOAA Date: Thu, 13 Jul 2023 16:12:03 +0000 Subject: [PATCH 01/14] initial changes for refactoring --- scripts/exgdas_global_marine_analysis_vrfy.py | 97 +------------- ush/soca_vrfy.py | 119 ++++++++++++++++++ 2 files changed, 120 insertions(+), 96 deletions(-) create mode 100644 ush/soca_vrfy.py diff --git a/scripts/exgdas_global_marine_analysis_vrfy.py b/scripts/exgdas_global_marine_analysis_vrfy.py index 04f56afd5..ed68fb100 100755 --- a/scripts/exgdas_global_marine_analysis_vrfy.py +++ b/scripts/exgdas_global_marine_analysis_vrfy.py @@ -19,108 +19,13 @@ import os import numpy as np -import matplotlib.pyplot as plt -import xarray as xr -import cartopy -import cartopy.crs as ccrs import gen_eva_obs_yaml import marine_eva_post import diag_statistics +from soca_vrfy import plot_config, plot_horizontal_slice, plot_zonal_slice import subprocess from datetime import datetime, timedelta -projs = {'North': ccrs.NorthPolarStereo(), - 'South': ccrs.SouthPolarStereo(), - 'Global': ccrs.Mollweide(central_longitude=-150)} - - -def plot_config(grid_file=[], data_file=[], - variable=[], levels=[], bounds=[], colormap=[], comout=[], lats=[]): - """ - Prepares the configuration for the plotting functions below - """ - config = {} - config['grid file'] = grid_file - config['fields file'] = data_file - config['variable'] = variable - config['levels'] = levels - config['bounds'] = bounds - config['colormap'] = colormap - config['lats'] = lats - config['comout'] = comout - config['max depth'] = 5000.0 - config['proj'] = 'Global' - return config - - -def plot_horizontal_slice(config): - """ - pcolormesh of a horizontal slice of an ocean field - """ - grid = xr.open_dataset(config['grid file']) - data = xr.open_dataset(config['fields file']) - - dirname = os.path.join(config['comout'], config['variable']) - os.makedirs(dirname, exist_ok=True) - - if config['variable'] in ['Temp', 'Salt', 'u', 'v']: - level = config['levels'][0] - slice_data = np.squeeze(data[config['variable']])[level, :, :] - label_colorbar = config['variable']+' Level '+str(level) - figname = os.path.join(dirname, config['variable']+'_Level_'+str(level)) - else: - slice_data = np.squeeze(data[config['variable']]) - label_colorbar = config['variable'] - figname = os.path.join(dirname, config['variable']+'_'+config['proj']) - - bounds = config['bounds'] - - fig, ax = plt.subplots(figsize=(8, 5), subplot_kw={'projection': projs[config['proj']]}) - plt.pcolormesh(np.squeeze(grid.lon), - np.squeeze(grid.lat), - slice_data, - vmin=bounds[0], vmax=bounds[1], - transform=ccrs.PlateCarree(), - cmap=config['colormap']) - - plt.colorbar(label=label_colorbar, shrink=0.5, orientation='horizontal') - ax.coastlines() # TODO: make this work on hpc - ax.gridlines(draw_labels=True) - if config['proj'] == 'South': - ax.set_extent([-180, 180, -90, -50], ccrs.PlateCarree()) - if config['proj'] == 'North': - ax.set_extent([-180, 180, 50, 90], ccrs.PlateCarree()) - # ax.add_feature(cartopy.feature.LAND) # TODO: make this work on hpc - plt.savefig(figname, bbox_inches='tight', dpi=600) - - -def plot_zonal_slice(config): - """ - pcolormesh of a zonal slice of an ocean field - """ - lat = float(config['lats'][0]) - grid = xr.open_dataset(config['grid file']) - data = xr.open_dataset(config['fields file']) - lat_index = np.argmin(np.array(np.abs(np.squeeze(grid.lat)[:, 0]-lat))) - slice_data = np.squeeze(np.array(data[config['variable']]))[:, lat_index, :] - depth = np.squeeze(np.array(grid['h']))[:, lat_index, :] - depth[np.where(np.abs(depth) > 10000.0)] = 0.0 - depth = np.cumsum(depth, axis=0) - bounds = config['bounds'] - x = np.tile(np.squeeze(grid.lon[:, lat_index]), (np.shape(depth)[0], 1)) - fig, ax = plt.subplots(figsize=(8, 5)) - plt.pcolormesh(x, -depth, slice_data, - vmin=bounds[0], vmax=bounds[1], - cmap=config['colormap']) - plt.colorbar(label=config['variable']+' Lat '+str(lat), shrink=0.5, orientation='horizontal') - ax.set_ylim(-config['max depth'], 0) - dirname = os.path.join(config['comout'], config['variable']) - os.makedirs(dirname, exist_ok=True) - figname = os.path.join(dirname, config['variable'] + - 'zonal_lat_'+str(int(lat)) + '_' + str(int(config['max depth'])) + 'm') - plt.savefig(figname, bbox_inches='tight', dpi=600) - - comout = os.getenv('COM_OCEAN_ANALYSIS') com_ice_history = os.getenv('COM_ICE_HISTORY_PREV') com_ocean_history = os.getenv('COM_OCEAN_HISTORY_PREV') diff --git a/ush/soca_vrfy.py b/ush/soca_vrfy.py new file mode 100644 index 000000000..689088c63 --- /dev/null +++ b/ush/soca_vrfy.py @@ -0,0 +1,119 @@ +#!/usr/bin/env python3 +################################################################################ +# UNIX Script Documentation Block +# . . +# Script name: soca_vrfy.py +# Script description: Module with plotting functions for marine analysis vrfy task +# +# Author: Andrew Eichmann Org: NCEP/EMC Date: 2023-07-13 +# +# Abstract: This script produces figures relevant to the marine DA cycle +# +# $Id$ +# +# Attributes: +# Language: Python3 +# +################################################################################ + + +import matplotlib.pyplot as plt +import xarray as xr +import cartopy +import cartopy.crs as ccrs +import numpy as np +import os + + +projs = {'North': ccrs.NorthPolarStereo(), + 'South': ccrs.SouthPolarStereo(), + 'Global': ccrs.Mollweide(central_longitude=-150)} + +def plot_config(grid_file=[], data_file=[], + variable=[], levels=[], bounds=[], colormap=[], comout=[], lats=[]): + """ + Prepares the configuration for the plotting functions below + """ + config = {} + config['grid file'] = grid_file + config['fields file'] = data_file + config['variable'] = variable + config['levels'] = levels + config['bounds'] = bounds + config['colormap'] = colormap + config['lats'] = lats + config['comout'] = comout + config['max depth'] = 5000.0 + config['proj'] = 'Global' + return config + + +def plot_horizontal_slice(config): + """ + pcolormesh of a horizontal slice of an ocean field + """ + grid = xr.open_dataset(config['grid file']) + data = xr.open_dataset(config['fields file']) + + dirname = os.path.join(config['comout'], config['variable']) + os.makedirs(dirname, exist_ok=True) + + if config['variable'] in ['Temp', 'Salt', 'u', 'v']: + level = config['levels'][0] + slice_data = np.squeeze(data[config['variable']])[level, :, :] + label_colorbar = config['variable']+' Level '+str(level) + figname = os.path.join(dirname, config['variable']+'_Level_'+str(level)) + else: + slice_data = np.squeeze(data[config['variable']]) + label_colorbar = config['variable'] + figname = os.path.join(dirname, config['variable']+'_'+config['proj']) + + bounds = config['bounds'] + + fig, ax = plt.subplots(figsize=(8, 5), subplot_kw={'projection': projs[config['proj']]}) + plt.pcolormesh(np.squeeze(grid.lon), + np.squeeze(grid.lat), + slice_data, + vmin=bounds[0], vmax=bounds[1], + transform=ccrs.PlateCarree(), + cmap=config['colormap']) + + plt.colorbar(label=label_colorbar, shrink=0.5, orientation='horizontal') + ax.coastlines() # TODO: make this work on hpc + ax.gridlines(draw_labels=True) + if config['proj'] == 'South': + ax.set_extent([-180, 180, -90, -50], ccrs.PlateCarree()) + if config['proj'] == 'North': + ax.set_extent([-180, 180, 50, 90], ccrs.PlateCarree()) + # ax.add_feature(cartopy.feature.LAND) # TODO: make this work on hpc + plt.savefig(figname, bbox_inches='tight', dpi=600) + + +def plot_zonal_slice(config): + """ + pcolormesh of a zonal slice of an ocean field + """ + lat = float(config['lats'][0]) + grid = xr.open_dataset(config['grid file']) + data = xr.open_dataset(config['fields file']) + lat_index = np.argmin(np.array(np.abs(np.squeeze(grid.lat)[:, 0]-lat))) + slice_data = np.squeeze(np.array(data[config['variable']]))[:, lat_index, :] + depth = np.squeeze(np.array(grid['h']))[:, lat_index, :] + depth[np.where(np.abs(depth) > 10000.0)] = 0.0 + depth = np.cumsum(depth, axis=0) + bounds = config['bounds'] + x = np.tile(np.squeeze(grid.lon[:, lat_index]), (np.shape(depth)[0], 1)) + fig, ax = plt.subplots(figsize=(8, 5)) + plt.pcolormesh(x, -depth, slice_data, + vmin=bounds[0], vmax=bounds[1], + cmap=config['colormap']) + plt.colorbar(label=config['variable']+' Lat '+str(lat), shrink=0.5, orientation='horizontal') + ax.set_ylim(-config['max depth'], 0) + dirname = os.path.join(config['comout'], config['variable']) + os.makedirs(dirname, exist_ok=True) + figname = os.path.join(dirname, config['variable'] + + 'zonal_lat_'+str(int(lat)) + '_' + str(int(config['max depth'])) + 'm') + plt.savefig(figname, bbox_inches='tight', dpi=600) + + + From f2f0d0ba314b3bc90fe3e24e23c58db14f408b0c Mon Sep 17 00:00:00 2001 From: AndrewEichmann-NOAA Date: Thu, 13 Jul 2023 20:51:24 +0000 Subject: [PATCH 02/14] python coding norms --- ush/soca_vrfy.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) mode change 100644 => 100755 ush/soca_vrfy.py diff --git a/ush/soca_vrfy.py b/ush/soca_vrfy.py old mode 100644 new mode 100755 index 689088c63..2cb3cb689 --- a/ush/soca_vrfy.py +++ b/ush/soca_vrfy.py @@ -29,6 +29,7 @@ 'South': ccrs.SouthPolarStereo(), 'Global': ccrs.Mollweide(central_longitude=-150)} + def plot_config(grid_file=[], data_file=[], variable=[], levels=[], bounds=[], colormap=[], comout=[], lats=[]): """ @@ -114,6 +115,3 @@ def plot_zonal_slice(config): figname = os.path.join(dirname, config['variable'] + 'zonal_lat_'+str(int(lat)) + '_' + str(int(config['max depth'])) + 'm') plt.savefig(figname, bbox_inches='tight', dpi=600) - - - From fd775fc3cd9708ee1995087ce527245e30690f9b Mon Sep 17 00:00:00 2001 From: AndrewEichmann-NOAA Date: Thu, 13 Jul 2023 20:58:13 +0000 Subject: [PATCH 03/14] removed paleolithic header --- ush/soca_vrfy.py | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/ush/soca_vrfy.py b/ush/soca_vrfy.py index 2cb3cb689..33a274101 100755 --- a/ush/soca_vrfy.py +++ b/ush/soca_vrfy.py @@ -1,21 +1,6 @@ #!/usr/bin/env python3 -################################################################################ -# UNIX Script Documentation Block -# . . -# Script name: soca_vrfy.py -# Script description: Module with plotting functions for marine analysis vrfy task -# -# Author: Andrew Eichmann Org: NCEP/EMC Date: 2023-07-13 -# -# Abstract: This script produces figures relevant to the marine DA cycle -# -# $Id$ -# -# Attributes: -# Language: Python3 -# -################################################################################ +# make plots for marine analysis import matplotlib.pyplot as plt import xarray as xr From c4e0bbe8738a66a4dc01d41538a35286733606bc Mon Sep 17 00:00:00 2001 From: AndrewEichmann-NOAA Date: Mon, 17 Jul 2023 14:26:38 +0000 Subject: [PATCH 04/14] python coding norms --- ush/soca_vrfy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ush/soca_vrfy.py b/ush/soca_vrfy.py index 33a274101..f06e4cd4f 100755 --- a/ush/soca_vrfy.py +++ b/ush/soca_vrfy.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# make plots for marine analysis +# make plots for marine analysis import matplotlib.pyplot as plt import xarray as xr From c41fb4fbf78b48f3abaadc35e07a5f18220f9e18 Mon Sep 17 00:00:00 2001 From: AndrewEichmann-NOAA Date: Mon, 17 Jul 2023 20:53:07 +0000 Subject: [PATCH 05/14] further removal of plotting guts from script script --- scripts/exgdas_global_marine_analysis_vrfy.py | 167 ++---------------- ush/soca_vrfy.py | 164 +++++++++++++++++ 2 files changed, 177 insertions(+), 154 deletions(-) diff --git a/scripts/exgdas_global_marine_analysis_vrfy.py b/scripts/exgdas_global_marine_analysis_vrfy.py index ed68fb100..86cdea931 100755 --- a/scripts/exgdas_global_marine_analysis_vrfy.py +++ b/scripts/exgdas_global_marine_analysis_vrfy.py @@ -22,21 +22,18 @@ import gen_eva_obs_yaml import marine_eva_post import diag_statistics -from soca_vrfy import plot_config, plot_horizontal_slice, plot_zonal_slice +from soca_vrfy import plot_increment, plot_analysis import subprocess from datetime import datetime, timedelta comout = os.getenv('COM_OCEAN_ANALYSIS') com_ice_history = os.getenv('COM_ICE_HISTORY_PREV') com_ocean_history = os.getenv('COM_OCEAN_HISTORY_PREV') -data = os.getenv('DATA') -pdy = os.getenv('PDY') cyc = os.getenv('cyc') RUN = os.getenv('RUN') -bcyc = str((int(cyc) - 3) % 24).zfill(2) gcyc = str((int(cyc) - 6) % 24).zfill(2) -gcdate = datetime.strptime(os.getenv('PDY')+os.getenv('cyc'), '%Y%m%d%H') - timedelta(hours=int(os.getenv('assim_freq'))) +bcyc = str((int(cyc) - 3) % 24).zfill(2) grid_file = os.path.join(comout, f'{RUN}.t'+bcyc+'z.ocngrid.nc') # for eva @@ -47,161 +44,20 @@ ####################################### # INCREMENT ####################################### -incr_cmap = 'RdBu' -data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ocninc.nc') -config = plot_config(grid_file=grid_file, - data_file=data_file, - colormap=incr_cmap, - comout=os.path.join(comout, 'vrfy', 'incr')) - -####################################### -# zonal slices - -for lat in np.arange(-60, 60, 10): - for max_depth in [700.0, 5000.0]: - config['lats'] = [lat] - config['max depth'] = max_depth - - # Temperature - config.update({'variable': 'Temp', 'levels': [1], 'bounds': [-.5, .5]}) - plot_zonal_slice(config) - - # Salinity - config.update({'variable': 'Salt', 'levels': [1], 'bounds': [-.1, .1]}) - plot_zonal_slice(config) - -####################################### -# Horizontal slices - -# Temperature -config.update({'variable': 'Temp', 'levels': [1], 'bounds': [-1, 1]}) -plot_horizontal_slice(config) - -# Salinity -config.update({'variable': 'Salt', 'bounds': [-0.1, 0.1]}) -plot_horizontal_slice(config) - -# Sea surface height -config.update({'variable': 'ave_ssh', 'bounds': [-0.1, 0.1]}) -plot_horizontal_slice(config) - -####################################### -# Sea ice -data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ice.incr.nc') -config = plot_config(grid_file=grid_file, - data_file=data_file, - colormap=incr_cmap, - comout=os.path.join(comout, 'vrfy', 'incr')) - -for proj in ['North', 'South']: - # concentration - config.update({'variable': 'aicen', 'bounds': [-0.2, 0.2], 'proj': proj}) - plot_horizontal_slice(config) - - # thickness - config.update({'variable': 'hicen', 'bounds': [-0.5, 0.5], 'proj': proj}) - plot_horizontal_slice(config) - - # snow depth - config.update({'variable': 'hsnon', 'bounds': [-0.1, 0.1], 'proj': proj}) - plot_horizontal_slice(config) +plot_increment(comout, cyc, RUN, grid_file) ####################################### # Analysis/Background ####################################### -####################################### -# Sea ice -data_files = [os.path.join(comout, f'{RUN}.t{cyc}z.iceana.nc'), - os.path.join(com_ice_history, f'{RUN}.t{gcyc}z.icef006.nc')] -dirs_out = ['ana', 'bkg'] -ice_vars = {'bkg': ['aice_h', 'hs_h', 'hi_h'], 'ana': ['aicen', 'hicen', 'hsnon']} -for data_file, dir_out in zip(data_files, dirs_out): - config = plot_config(grid_file=grid_file, - data_file=data_file, - colormap='jet', - comout=os.path.join(comout, 'vrfy', dir_out)) - - for proj in ['North', 'South', 'Global']: - # concentration - var = ice_vars[dir_out] - config.update({'variable': var[0], 'bounds': [0.0, 1.0], 'proj': proj}) - plot_horizontal_slice(config) - - # thickness - config.update({'variable': var[1], 'bounds': [0.0, 4.0], 'proj': proj}) - plot_horizontal_slice(config) - - # snow depth - config.update({'variable': var[2], 'bounds': [0.0, 0.5], 'proj': proj}) - plot_horizontal_slice(config) - -####################################### -# Ocean surface -data_files = [os.path.join(comout, f'{RUN}.t'+cyc+'z.ocnana.nc'), - os.path.join(com_ocean_history, f'{RUN}.t{gcyc}z.ocnf006.nc')] -dirs_out = ['ana', 'bkg'] -ocn_vars = ['ave_ssh', 'Temp', 'Salt'] -for data_file, dir_out in zip(data_files, dirs_out): - config = plot_config(grid_file=grid_file, - data_file=data_file, - colormap='jet', - comout=os.path.join(comout, 'vrfy', dir_out)) - - # ssh - config.update({'variable': 'ave_ssh', 'bounds': [-1.8, 1.3], 'proj': proj, 'levels': [1]}) - plot_horizontal_slice(config) - - # sst - config.update({'variable': 'Temp', 'bounds': [-1.8, 34.0], 'proj': proj, 'levels': [1]}) - plot_horizontal_slice(config) - - # sss - config.update({'variable': 'Salt', 'bounds': [30, 38], 'proj': proj, 'levels': [1]}) - plot_horizontal_slice(config) - -####################################### -# Std Bkg. Error -####################################### -bmat_cmap = 'jet' -data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ocn.bkgerr_stddev.nc') -config = plot_config(grid_file=grid_file, - data_file=data_file, - colormap=bmat_cmap, - comout=os.path.join(comout, 'vrfy', 'bkgerr')) - -####################################### -# zonal slices - -for lat in np.arange(-60, 60, 10): - - for max_depth in [700.0, 5000.0]: - config['lats'] = [lat] - config['max depth'] = max_depth - - # Temperature - config.update({'variable': 'Temp', 'levels': [1], 'bounds': [0, 1.5]}) - plot_zonal_slice(config) - - # Salinity - config.update({'variable': 'Salt', 'levels': [1], 'bounds': [0, .2]}) - plot_zonal_slice(config) - -####################################### -# Horizontal slices - -# Temperature -config.update({'variable': 'Temp', 'levels': [1], 'bounds': [0, 2]}) -plot_horizontal_slice(config) - -# Salinity -config.update({'variable': 'Salt', 'bounds': [0, 0.2]}) -plot_horizontal_slice(config) - -# Sea surface height -config.update({'variable': 'ave_ssh', 'bounds': [0, 0.1]}) -plot_horizontal_slice(config) +plot_analysis(comout, + com_ice_history, + com_ocean_history, + cyc, + RUN, + grid_file, + gcyc) ####################################### # eva plots @@ -231,4 +87,7 @@ print('running eva on', infile) subprocess.run(['eva', infile], check=True) +####################################### +# calculate diag statistics + diag_statistics.get_diag_stats() diff --git a/ush/soca_vrfy.py b/ush/soca_vrfy.py index f06e4cd4f..acb75c391 100755 --- a/ush/soca_vrfy.py +++ b/ush/soca_vrfy.py @@ -100,3 +100,167 @@ def plot_zonal_slice(config): figname = os.path.join(dirname, config['variable'] + 'zonal_lat_'+str(int(lat)) + '_' + str(int(config['max depth'])) + 'm') plt.savefig(figname, bbox_inches='tight', dpi=600) + + +def plot_increment(comout, cyc, RUN, grid_file): + + incr_cmap = 'RdBu' + data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ocninc.nc') + config = plot_config(grid_file=grid_file, + data_file=data_file, + colormap=incr_cmap, + comout=os.path.join(comout, 'vrfy', 'incr')) + + ####################################### + # zonal slices + + for lat in np.arange(-60, 60, 10): + + for max_depth in [700.0, 5000.0]: + config['lats'] = [lat] + config['max depth'] = max_depth + + # Temperature + config.update({'variable': 'Temp', 'levels': [1], 'bounds': [-.5, .5]}) + plot_zonal_slice(config) + + # Salinity + config.update({'variable': 'Salt', 'levels': [1], 'bounds': [-.1, .1]}) + plot_zonal_slice(config) + + ####################################### + # Horizontal slices + + # Temperature + config.update({'variable': 'Temp', 'levels': [1], 'bounds': [-1, 1]}) + plot_horizontal_slice(config) + + # Salinity + config.update({'variable': 'Salt', 'bounds': [-0.1, 0.1]}) + plot_horizontal_slice(config) + + # Sea surface height + config.update({'variable': 'ave_ssh', 'bounds': [-0.1, 0.1]}) + plot_horizontal_slice(config) + + ####################################### + # Sea ice + data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ice.incr.nc') + config = plot_config(grid_file=grid_file, + data_file=data_file, + colormap=incr_cmap, + comout=os.path.join(comout, 'vrfy', 'incr')) + + for proj in ['North', 'South']: + # concentration + config.update({'variable': 'aicen', 'bounds': [-0.2, 0.2], 'proj': proj}) + plot_horizontal_slice(config) + + # thickness + config.update({'variable': 'hicen', 'bounds': [-0.5, 0.5], 'proj': proj}) + plot_horizontal_slice(config) + + # snow depth + config.update({'variable': 'hsnon', 'bounds': [-0.1, 0.1], 'proj': proj}) + plot_horizontal_slice(config) + +def plot_analysis(comout, + com_ice_history, + com_ocean_history, + cyc, + RUN, + grid_file, + gcyc): + + ####################################### + # Sea ice + data_files = [os.path.join(comout, f'{RUN}.t{cyc}z.iceana.nc'), + os.path.join(com_ice_history, f'{RUN}.t{gcyc}z.icef006.nc')] + dirs_out = ['ana', 'bkg'] + ice_vars = {'bkg': ['aice_h', 'hs_h', 'hi_h'], 'ana': ['aicen', 'hicen', 'hsnon']} + for data_file, dir_out in zip(data_files, dirs_out): + config = plot_config(grid_file=grid_file, + data_file=data_file, + colormap='jet', + comout=os.path.join(comout, 'vrfy', dir_out)) + + for proj in ['North', 'South', 'Global']: + # concentration + var = ice_vars[dir_out] + config.update({'variable': var[0], 'bounds': [0.0, 1.0], 'proj': proj}) + plot_horizontal_slice(config) + + # thickness + config.update({'variable': var[1], 'bounds': [0.0, 4.0], 'proj': proj}) + plot_horizontal_slice(config) + + # snow depth + config.update({'variable': var[2], 'bounds': [0.0, 0.5], 'proj': proj}) + plot_horizontal_slice(config) + + ####################################### + # Ocean surface + data_files = [os.path.join(comout, f'{RUN}.t'+cyc+'z.ocnana.nc'), + os.path.join(com_ocean_history, f'{RUN}.t{gcyc}z.ocnf006.nc')] + dirs_out = ['ana', 'bkg'] + ocn_vars = ['ave_ssh', 'Temp', 'Salt'] + for data_file, dir_out in zip(data_files, dirs_out): + config = plot_config(grid_file=grid_file, + data_file=data_file, + colormap='jet', + comout=os.path.join(comout, 'vrfy', dir_out)) + + # ssh + config.update({'variable': 'ave_ssh', 'bounds': [-1.8, 1.3], 'proj': proj, 'levels': [1]}) + plot_horizontal_slice(config) + + # sst + config.update({'variable': 'Temp', 'bounds': [-1.8, 34.0], 'proj': proj, 'levels': [1]}) + plot_horizontal_slice(config) + + # sss + config.update({'variable': 'Salt', 'bounds': [30, 38], 'proj': proj, 'levels': [1]}) + plot_horizontal_slice(config) + + ####################################### + # Std Bkg. Error + ####################################### + bmat_cmap = 'jet' + data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ocn.bkgerr_stddev.nc') + config = plot_config(grid_file=grid_file, + data_file=data_file, + colormap=bmat_cmap, + comout=os.path.join(comout, 'vrfy', 'bkgerr')) + + ####################################### + # zonal slices + + for lat in np.arange(-60, 60, 10): + + for max_depth in [700.0, 5000.0]: + config['lats'] = [lat] + config['max depth'] = max_depth + + # Temperature + config.update({'variable': 'Temp', 'levels': [1], 'bounds': [0, 1.5]}) + plot_zonal_slice(config) + + # Salinity + config.update({'variable': 'Salt', 'levels': [1], 'bounds': [0, .2]}) + plot_zonal_slice(config) + + ####################################### + # Horizontal slices + + # Temperature + config.update({'variable': 'Temp', 'levels': [1], 'bounds': [0, 2]}) + plot_horizontal_slice(config) + + # Salinity + config.update({'variable': 'Salt', 'bounds': [0, 0.2]}) + plot_horizontal_slice(config) + + # Sea surface height + config.update({'variable': 'ave_ssh', 'bounds': [0, 0.1]}) + plot_horizontal_slice(config) + From 83baf8c682d05330ae7e26f238f557dd7977fa80 Mon Sep 17 00:00:00 2001 From: AndrewEichmann-NOAA Date: Mon, 17 Jul 2023 21:08:02 +0000 Subject: [PATCH 06/14] python style --- scripts/exgdas_global_marine_analysis_vrfy.py | 12 +-- ush/soca_vrfy.py | 77 ++++++++++--------- 2 files changed, 45 insertions(+), 44 deletions(-) diff --git a/scripts/exgdas_global_marine_analysis_vrfy.py b/scripts/exgdas_global_marine_analysis_vrfy.py index 86cdea931..cd64ea7df 100755 --- a/scripts/exgdas_global_marine_analysis_vrfy.py +++ b/scripts/exgdas_global_marine_analysis_vrfy.py @@ -51,12 +51,12 @@ # Analysis/Background ####################################### -plot_analysis(comout, - com_ice_history, - com_ocean_history, - cyc, - RUN, - grid_file, +plot_analysis(comout, + com_ice_history, + com_ocean_history, + cyc, + RUN, + grid_file, gcyc) ####################################### diff --git a/ush/soca_vrfy.py b/ush/soca_vrfy.py index acb75c391..11188bfc8 100755 --- a/ush/soca_vrfy.py +++ b/ush/soca_vrfy.py @@ -110,39 +110,39 @@ def plot_increment(comout, cyc, RUN, grid_file): data_file=data_file, colormap=incr_cmap, comout=os.path.join(comout, 'vrfy', 'incr')) - + ####################################### # zonal slices - + for lat in np.arange(-60, 60, 10): - + for max_depth in [700.0, 5000.0]: config['lats'] = [lat] config['max depth'] = max_depth - + # Temperature config.update({'variable': 'Temp', 'levels': [1], 'bounds': [-.5, .5]}) plot_zonal_slice(config) - + # Salinity config.update({'variable': 'Salt', 'levels': [1], 'bounds': [-.1, .1]}) plot_zonal_slice(config) - + ####################################### # Horizontal slices - + # Temperature config.update({'variable': 'Temp', 'levels': [1], 'bounds': [-1, 1]}) plot_horizontal_slice(config) - + # Salinity config.update({'variable': 'Salt', 'bounds': [-0.1, 0.1]}) plot_horizontal_slice(config) - + # Sea surface height config.update({'variable': 'ave_ssh', 'bounds': [-0.1, 0.1]}) plot_horizontal_slice(config) - + ####################################### # Sea ice data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ice.incr.nc') @@ -150,26 +150,27 @@ def plot_increment(comout, cyc, RUN, grid_file): data_file=data_file, colormap=incr_cmap, comout=os.path.join(comout, 'vrfy', 'incr')) - + for proj in ['North', 'South']: # concentration config.update({'variable': 'aicen', 'bounds': [-0.2, 0.2], 'proj': proj}) plot_horizontal_slice(config) - + # thickness config.update({'variable': 'hicen', 'bounds': [-0.5, 0.5], 'proj': proj}) plot_horizontal_slice(config) - + # snow depth config.update({'variable': 'hsnon', 'bounds': [-0.1, 0.1], 'proj': proj}) plot_horizontal_slice(config) - -def plot_analysis(comout, - com_ice_history, - com_ocean_history, - cyc, - RUN, - grid_file, + + +def plot_analysis(comout, + com_ice_history, + com_ocean_history, + cyc, + RUN, + grid_file, gcyc): ####################################### @@ -183,21 +184,21 @@ def plot_analysis(comout, data_file=data_file, colormap='jet', comout=os.path.join(comout, 'vrfy', dir_out)) - + for proj in ['North', 'South', 'Global']: # concentration var = ice_vars[dir_out] config.update({'variable': var[0], 'bounds': [0.0, 1.0], 'proj': proj}) plot_horizontal_slice(config) - + # thickness config.update({'variable': var[1], 'bounds': [0.0, 4.0], 'proj': proj}) plot_horizontal_slice(config) - + # snow depth config.update({'variable': var[2], 'bounds': [0.0, 0.5], 'proj': proj}) plot_horizontal_slice(config) - + ####################################### # Ocean surface data_files = [os.path.join(comout, f'{RUN}.t'+cyc+'z.ocnana.nc'), @@ -209,19 +210,19 @@ def plot_analysis(comout, data_file=data_file, colormap='jet', comout=os.path.join(comout, 'vrfy', dir_out)) - + # ssh config.update({'variable': 'ave_ssh', 'bounds': [-1.8, 1.3], 'proj': proj, 'levels': [1]}) plot_horizontal_slice(config) - + # sst config.update({'variable': 'Temp', 'bounds': [-1.8, 34.0], 'proj': proj, 'levels': [1]}) plot_horizontal_slice(config) - + # sss config.update({'variable': 'Salt', 'bounds': [30, 38], 'proj': proj, 'levels': [1]}) plot_horizontal_slice(config) - + ####################################### # Std Bkg. Error ####################################### @@ -231,36 +232,36 @@ def plot_analysis(comout, data_file=data_file, colormap=bmat_cmap, comout=os.path.join(comout, 'vrfy', 'bkgerr')) - + ####################################### # zonal slices - + for lat in np.arange(-60, 60, 10): - + for max_depth in [700.0, 5000.0]: config['lats'] = [lat] config['max depth'] = max_depth - + # Temperature config.update({'variable': 'Temp', 'levels': [1], 'bounds': [0, 1.5]}) plot_zonal_slice(config) - + # Salinity config.update({'variable': 'Salt', 'levels': [1], 'bounds': [0, .2]}) plot_zonal_slice(config) - + ####################################### # Horizontal slices - + # Temperature config.update({'variable': 'Temp', 'levels': [1], 'bounds': [0, 2]}) plot_horizontal_slice(config) - + # Salinity config.update({'variable': 'Salt', 'bounds': [0, 0.2]}) plot_horizontal_slice(config) - + # Sea surface height config.update({'variable': 'ave_ssh', 'bounds': [0, 0.1]}) plot_horizontal_slice(config) - + From fa7ce3f82726c02489e9aedf88ccca978055b008 Mon Sep 17 00:00:00 2001 From: AndrewEichmann-NOAA Date: Mon, 17 Jul 2023 21:08:59 +0000 Subject: [PATCH 07/14] python style --- ush/soca_vrfy.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ush/soca_vrfy.py b/ush/soca_vrfy.py index 11188bfc8..1f09a1595 100755 --- a/ush/soca_vrfy.py +++ b/ush/soca_vrfy.py @@ -264,4 +264,3 @@ def plot_analysis(comout, # Sea surface height config.update({'variable': 'ave_ssh', 'bounds': [0, 0.1]}) plot_horizontal_slice(config) - From cf596beeee09cfe4fc759ebf314b6e7a4c1d6284 Mon Sep 17 00:00:00 2001 From: AndrewEichmann-NOAA Date: Thu, 27 Jul 2023 14:35:27 +0000 Subject: [PATCH 08/14] added plotting class --- scripts/exgdas_global_marine_analysis_vrfy.py | 21 +- ush/{ => soca}/diag_statistics.py | 0 ush/{ => soca}/soca_vrfy.py | 180 +++++++++++++----- 3 files changed, 154 insertions(+), 47 deletions(-) rename ush/{ => soca}/diag_statistics.py (100%) rename ush/{ => soca}/soca_vrfy.py (63%) diff --git a/scripts/exgdas_global_marine_analysis_vrfy.py b/scripts/exgdas_global_marine_analysis_vrfy.py index cd64ea7df..cd302e1c0 100755 --- a/scripts/exgdas_global_marine_analysis_vrfy.py +++ b/scripts/exgdas_global_marine_analysis_vrfy.py @@ -22,7 +22,7 @@ import gen_eva_obs_yaml import marine_eva_post import diag_statistics -from soca_vrfy import plot_increment, plot_analysis +from soca_vrfy import StatePlotter, plot_config, plot_increment, plot_analysis import subprocess from datetime import datetime, timedelta @@ -59,6 +59,25 @@ grid_file, gcyc) + + + +data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ocn.bkgerr_stddev.nc') +config = plot_config(grid_file = grid_file, + data_file = data_file, + lats = np.arange(-60, 60, 10), + variables_zonal = ['Temp', 'Salt'], + variables_horiz = ['Temp', 'Salt', 'ave_ssh'], + allbounds = {'Temp': [0, 2], + 'Salt': [0, 0.2], + 'ave_ssh': [0, 0.1]}, + colormap = 'jet', + comout = os.path.join(comout, 'vrfy', 'bkgerr')) +BkgErrPlotter = StatePlotter(config) +BkgErrPlotter.plot() + + + ####################################### # eva plots diff --git a/ush/diag_statistics.py b/ush/soca/diag_statistics.py similarity index 100% rename from ush/diag_statistics.py rename to ush/soca/diag_statistics.py diff --git a/ush/soca_vrfy.py b/ush/soca/soca_vrfy.py similarity index 63% rename from ush/soca_vrfy.py rename to ush/soca/soca_vrfy.py index 1f09a1595..cfb4e7336 100755 --- a/ush/soca_vrfy.py +++ b/ush/soca/soca_vrfy.py @@ -15,8 +15,21 @@ 'Global': ccrs.Mollweide(central_longitude=-150)} -def plot_config(grid_file=[], data_file=[], - variable=[], levels=[], bounds=[], colormap=[], comout=[], lats=[]): +def plot_config(grid_file=[], + data_file=[], + variable=[], + levels=[], + allbounds=[], + bounds=[], + colormap=[], + max_depth=np.nan, + max_depths = [700.0, 5000.0], + comout=[], + variables_horiz = [], + variables_zonal = [], + lat=np.nan, + lats=np.arange(-60, 60, 10)): + """ Prepares the configuration for the plotting functions below """ @@ -24,12 +37,17 @@ def plot_config(grid_file=[], data_file=[], config['grid file'] = grid_file config['fields file'] = data_file config['variable'] = variable - config['levels'] = levels + config['levels'] = [1] config['bounds'] = bounds + config['all bounds'] = allbounds config['colormap'] = colormap - config['lats'] = lats + config['lats'] = lats # all the lats to plot + config['lat'] = lat # the lat being currently plotted config['comout'] = comout - config['max depth'] = 5000.0 + config['max depth'] = max_depth + config['max depths'] = max_depths + config['horiz variables'] = variables_horiz + config['zonal variables'] = variables_zonal config['proj'] = 'Global' return config @@ -79,7 +97,7 @@ def plot_zonal_slice(config): """ pcolormesh of a zonal slice of an ocean field """ - lat = float(config['lats'][0]) + lat = float(config['lat']) grid = xr.open_dataset(config['grid file']) data = xr.open_dataset(config['fields file']) lat_index = np.argmin(np.array(np.abs(np.squeeze(grid.lat)[:, 0]-lat))) @@ -117,7 +135,7 @@ def plot_increment(comout, cyc, RUN, grid_file): for lat in np.arange(-60, 60, 10): for max_depth in [700.0, 5000.0]: - config['lats'] = [lat] + config['lat'] = lat config['max depth'] = max_depth # Temperature @@ -223,44 +241,114 @@ def plot_analysis(comout, config.update({'variable': 'Salt', 'bounds': [30, 38], 'proj': proj, 'levels': [1]}) plot_horizontal_slice(config) - ####################################### - # Std Bkg. Error - ####################################### - bmat_cmap = 'jet' - data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ocn.bkgerr_stddev.nc') - config = plot_config(grid_file=grid_file, - data_file=data_file, - colormap=bmat_cmap, - comout=os.path.join(comout, 'vrfy', 'bkgerr')) - - ####################################### - # zonal slices +#def plot_error(comout, +# com_ice_history, +# com_ocean_history, +# cyc, +# RUN, +# grid_file, +# gcyc): + +# ####################################### +# # Std Bkg. Error +# ####################################### +# bmat_cmap = 'jet' +# data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ocn.bkgerr_stddev.nc') +# config = plot_config(grid_file=grid_file, +# data_file=data_file, +# colormap=bmat_cmap, +# comout=os.path.join(comout, 'vrfy', 'bkgerr')) +# +# ####################################### +# # zonal slices +# +# for lat in np.arange(-60, 60, 10): +# +# for max_depth in [700.0, 5000.0]: +# config['lat'] = lat +# config['max depth'] = max_depth +# +# # Temperature +# config.update({'variable': 'Temp', 'levels': [1], 'bounds': [0, 1.5]}) +# plot_zonal_slice(config) +# +# # Salinity +# config.update({'variable': 'Salt', 'levels': [1], 'bounds': [0, .2]}) +# plot_zonal_slice(config) +# +# ####################################### +# # Horizontal slices +# +# # Temperature +# config.update({'variable': 'Temp', 'levels': [1], 'bounds': [0, 2]}) +# plot_horizontal_slice(config) +# +# # Salinity +# config.update({'variable': 'Salt', 'bounds': [0, 0.2]}) +# plot_horizontal_slice(config) +# +# # Sea surface height +# config.update({'variable': 'ave_ssh', 'bounds': [0, 0.1]}) +# plot_horizontal_slice(config) +# +class StatePlotter: + + def __init__(self, config_dict): + self.config = config_dict +# self.grid_file = config['grid file'] +# self.data_file = config['fields file'] +# self.variable = config['variable'] +# self.levels = config['levels'] +# self.bounds = config['bounds'] +# self.colormap = config['colormap'] +# self.lats = config['lats'] +# self.comout = config['comout'] +# self.maxdepth = 5000.0 +# self.proj = 'Global' +# + ... + # Where config contains the bounds, filename and whatever else is needed to plot stuff + + def plot(self): + # Loop over variables, slices (horiz and vertical) and projections ... and whatever else is needed + + ####################################### + # zonal slices + + for lat in self.config['lats']: + self.config['lat'] = lat + + for max_depth in self.config['max depths']: + self.config['max depth'] = max_depth + + for variable in self.config['zonal variables']: + # Temperature + bounds = self.config['all bounds'][variable] + self.config.update({'variable': variable, 'bounds': bounds}) + plot_zonal_slice(self.config) + + # Salinity +# self.config.update({'variable': 'Salt', 'levels': [1], 'bounds': [0, .2]}) +# plot_zonal_slice(config) + + ####################################### + # Horizontal slices + + for variable in self.config['horiz variables']: + bounds = self.config['all bounds'][variable] + self.config.update({'variable': variable, 'bounds': bounds}) + plot_horizontal_slice(self.config) + +# # Temperature +# self.config.update({'variable': 'Temp', 'levels': [1], 'bounds': [0, 2]}) +# plot_horizontal_slice(config) +# +# # Salinity +# self.config.update({'variable': 'Salt', 'bounds': [0, 0.2]}) +# plot_horizontal_slice(config) +# +# # Sea surface height +# self.config.update({'variable': 'ave_ssh', 'bounds': [0, 0.1]}) +# plot_horizontal_slice(config) - for lat in np.arange(-60, 60, 10): - - for max_depth in [700.0, 5000.0]: - config['lats'] = [lat] - config['max depth'] = max_depth - - # Temperature - config.update({'variable': 'Temp', 'levels': [1], 'bounds': [0, 1.5]}) - plot_zonal_slice(config) - # Salinity - config.update({'variable': 'Salt', 'levels': [1], 'bounds': [0, .2]}) - plot_zonal_slice(config) - - ####################################### - # Horizontal slices - - # Temperature - config.update({'variable': 'Temp', 'levels': [1], 'bounds': [0, 2]}) - plot_horizontal_slice(config) - - # Salinity - config.update({'variable': 'Salt', 'bounds': [0, 0.2]}) - plot_horizontal_slice(config) - - # Sea surface height - config.update({'variable': 'ave_ssh', 'bounds': [0, 0.1]}) - plot_horizontal_slice(config) From 02e3ed1682340e9404226c6332f2fea2ebc47219 Mon Sep 17 00:00:00 2001 From: AndrewEichmann-NOAA Date: Thu, 27 Jul 2023 18:22:13 +0000 Subject: [PATCH 09/14] rest of plot suites added, cleanup --- scripts/exgdas_global_marine_analysis_vrfy.py | 110 +++++++- ush/soca/soca_vrfy.py | 236 ++---------------- 2 files changed, 115 insertions(+), 231 deletions(-) diff --git a/scripts/exgdas_global_marine_analysis_vrfy.py b/scripts/exgdas_global_marine_analysis_vrfy.py index cd302e1c0..2a61994d5 100755 --- a/scripts/exgdas_global_marine_analysis_vrfy.py +++ b/scripts/exgdas_global_marine_analysis_vrfy.py @@ -22,7 +22,7 @@ import gen_eva_obs_yaml import marine_eva_post import diag_statistics -from soca_vrfy import StatePlotter, plot_config, plot_increment, plot_analysis +from soca_vrfy import StatePlotter, plot_config import subprocess from datetime import datetime, timedelta @@ -40,27 +40,111 @@ diagdir = os.path.join(comout, 'diags') HOMEgfs = os.getenv('HOMEgfs') +####################################### +# ocean increment +####################################### + +data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ocninc.nc') +config = plot_config(grid_file = grid_file, + data_file = data_file, + lats = np.arange(-60, 60, 10), + variables_zonal = ['Temp', 'Salt'], + variables_horiz = ['Temp', 'Salt', 'ave_ssh'], + allbounds = {'Temp': [-0.5, 0.5], + 'Salt': [-0.1, 0.1], + 'ave_ssh': [-0.1, 0.1]}, + colormap = 'RdBu', + comout = os.path.join(comout, 'vrfy', 'incr')) +OcnIncPlotter = StatePlotter(config) +OcnIncPlotter.plot() ####################################### -# INCREMENT +# sea ice increment ####################################### -plot_increment(comout, cyc, RUN, grid_file) +data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ice.incr.nc') +config = plot_config(grid_file = grid_file, + data_file = data_file, + lats = np.arange(-60, 60, 10), + variables_horiz = ['aicen', 'hicen', 'hsnon'], + allbounds = {'aicen': [-0.2, 0.2], + 'hicen': [-0.5, 0.5], + 'hsnon': [-0.1, 0.1]}, + colormap = 'RdBu', + projs = ['North', 'South'], + comout = os.path.join(comout, 'vrfy', 'incr')) +IceIncPlotter = StatePlotter(config) +IceIncPlotter.plot() ####################################### -# Analysis/Background +# sea ice analysis ####################################### -plot_analysis(comout, - com_ice_history, - com_ocean_history, - cyc, - RUN, - grid_file, - gcyc) +data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.iceana.nc') +config = plot_config(grid_file = grid_file, + data_file = data_file, + variables_horiz = ['aicen', 'hicen', 'hsnon'], + allbounds = {'aicen': [0.0, 1.0], + 'hicen': [0.0, 4.0], + 'hsnon': [0.0, 0.5]}, + colormap = 'jet', + projs = ['North', 'South','Global'], + comout = os.path.join(comout, 'vrfy', 'ana')) +IceAnaPlotter = StatePlotter(config) +IceAnaPlotter.plot() +####################################### +# sea ice background +####################################### +data_file = os.path.join(com_ice_history, f'{RUN}.t{gcyc}z.icef006.nc') +config = plot_config(grid_file = grid_file, + data_file = data_file, + variables_horiz = ['aice_h', 'hs_h', 'hi_h'], + allbounds = {'aice_h': [0.0, 1.0], + 'hs_h': [0.0, 4.0], + 'hi_h': [0.0, 0.5]}, + colormap = 'jet', + projs = ['North', 'South','Global'], + comout = os.path.join(comout, 'vrfy', 'bkg')) +IceBkgPlotter = StatePlotter(config) +IceBkgPlotter.plot() +####################################### +# ocean surface analysis +####################################### + +data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ocnana.nc') +config = plot_config(grid_file = grid_file, + data_file = data_file, + variables_horiz = ['ave_ssh', 'Temp', 'Salt'], + allbounds = {'ave_ssh': [-1.8, 1.3], + 'Temp': [-1.8, 34.0], + 'Salt': [30, 38]}, + colormap = 'jet', + comout = os.path.join(comout, 'vrfy', 'ana')) +OcnAnaPlotter = StatePlotter(config) +OcnAnaPlotter.plot() + +####################################### +# ocean surface background +####################################### + +data_file = os.path.join(com_ocean_history, f'{RUN}.t{gcyc}z.ocnf006.nc') +config = plot_config(grid_file = grid_file, + data_file = data_file, + variables_horiz = ['ave_ssh', 'Temp', 'Salt'], + allbounds = {'ave_ssh': [-1.8, 1.3], + 'Temp': [-1.8, 34.0], + 'Salt': [30, 38]}, + colormap = 'jet', + comout = os.path.join(comout, 'vrfy', 'bkg')) +OcnBkgPlotter = StatePlotter(config) +OcnBkgPlotter.plot() + +####################################### +# background error +####################################### data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ocn.bkgerr_stddev.nc') config = plot_config(grid_file = grid_file, @@ -76,10 +160,9 @@ BkgErrPlotter = StatePlotter(config) BkgErrPlotter.plot() - - ####################################### # eva plots +####################################### evadir = os.path.join(HOMEgfs, 'sorc', f'{RUN}.cd', 'ush', 'eva') marinetemplate = os.path.join(evadir, 'marine_gdas_plots.yaml') @@ -108,5 +191,6 @@ ####################################### # calculate diag statistics +####################################### diag_statistics.get_diag_stats() diff --git a/ush/soca/soca_vrfy.py b/ush/soca/soca_vrfy.py index cfb4e7336..5e8c9d492 100755 --- a/ush/soca/soca_vrfy.py +++ b/ush/soca/soca_vrfy.py @@ -28,27 +28,30 @@ def plot_config(grid_file=[], variables_horiz = [], variables_zonal = [], lat=np.nan, - lats=np.arange(-60, 60, 10)): + lats=np.arange(-60, 60, 10), + proj='set me', + projs=['Global']): """ Prepares the configuration for the plotting functions below """ config = {} + config['comout'] = comout # output directory config['grid file'] = grid_file config['fields file'] = data_file - config['variable'] = variable config['levels'] = [1] - config['bounds'] = bounds - config['all bounds'] = allbounds config['colormap'] = colormap + config['all bounds'] = allbounds + config['bounds'] = bounds config['lats'] = lats # all the lats to plot config['lat'] = lat # the lat being currently plotted - config['comout'] = comout - config['max depth'] = max_depth - config['max depths'] = max_depths - config['horiz variables'] = variables_horiz - config['zonal variables'] = variables_zonal - config['proj'] = 'Global' + config['max depths'] = max_depths # all the max depths to plot + config['max depth'] = max_depth # the max depth currently plotted + config['horiz variables'] = variables_horiz # all the vars for horiz plots + config['zonal variables'] = variables_zonal # all the vars for zonal plots + config['variable'] = variable # the variable currently plotted + config['projs'] = projs # all the projections etc. + config['proj'] = proj return config @@ -120,194 +123,10 @@ def plot_zonal_slice(config): plt.savefig(figname, bbox_inches='tight', dpi=600) -def plot_increment(comout, cyc, RUN, grid_file): - - incr_cmap = 'RdBu' - data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ocninc.nc') - config = plot_config(grid_file=grid_file, - data_file=data_file, - colormap=incr_cmap, - comout=os.path.join(comout, 'vrfy', 'incr')) - - ####################################### - # zonal slices - - for lat in np.arange(-60, 60, 10): - - for max_depth in [700.0, 5000.0]: - config['lat'] = lat - config['max depth'] = max_depth - - # Temperature - config.update({'variable': 'Temp', 'levels': [1], 'bounds': [-.5, .5]}) - plot_zonal_slice(config) - - # Salinity - config.update({'variable': 'Salt', 'levels': [1], 'bounds': [-.1, .1]}) - plot_zonal_slice(config) - - ####################################### - # Horizontal slices - - # Temperature - config.update({'variable': 'Temp', 'levels': [1], 'bounds': [-1, 1]}) - plot_horizontal_slice(config) - - # Salinity - config.update({'variable': 'Salt', 'bounds': [-0.1, 0.1]}) - plot_horizontal_slice(config) - - # Sea surface height - config.update({'variable': 'ave_ssh', 'bounds': [-0.1, 0.1]}) - plot_horizontal_slice(config) - - ####################################### - # Sea ice - data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ice.incr.nc') - config = plot_config(grid_file=grid_file, - data_file=data_file, - colormap=incr_cmap, - comout=os.path.join(comout, 'vrfy', 'incr')) - - for proj in ['North', 'South']: - # concentration - config.update({'variable': 'aicen', 'bounds': [-0.2, 0.2], 'proj': proj}) - plot_horizontal_slice(config) - - # thickness - config.update({'variable': 'hicen', 'bounds': [-0.5, 0.5], 'proj': proj}) - plot_horizontal_slice(config) - - # snow depth - config.update({'variable': 'hsnon', 'bounds': [-0.1, 0.1], 'proj': proj}) - plot_horizontal_slice(config) - - -def plot_analysis(comout, - com_ice_history, - com_ocean_history, - cyc, - RUN, - grid_file, - gcyc): - - ####################################### - # Sea ice - data_files = [os.path.join(comout, f'{RUN}.t{cyc}z.iceana.nc'), - os.path.join(com_ice_history, f'{RUN}.t{gcyc}z.icef006.nc')] - dirs_out = ['ana', 'bkg'] - ice_vars = {'bkg': ['aice_h', 'hs_h', 'hi_h'], 'ana': ['aicen', 'hicen', 'hsnon']} - for data_file, dir_out in zip(data_files, dirs_out): - config = plot_config(grid_file=grid_file, - data_file=data_file, - colormap='jet', - comout=os.path.join(comout, 'vrfy', dir_out)) - - for proj in ['North', 'South', 'Global']: - # concentration - var = ice_vars[dir_out] - config.update({'variable': var[0], 'bounds': [0.0, 1.0], 'proj': proj}) - plot_horizontal_slice(config) - - # thickness - config.update({'variable': var[1], 'bounds': [0.0, 4.0], 'proj': proj}) - plot_horizontal_slice(config) - - # snow depth - config.update({'variable': var[2], 'bounds': [0.0, 0.5], 'proj': proj}) - plot_horizontal_slice(config) - - ####################################### - # Ocean surface - data_files = [os.path.join(comout, f'{RUN}.t'+cyc+'z.ocnana.nc'), - os.path.join(com_ocean_history, f'{RUN}.t{gcyc}z.ocnf006.nc')] - dirs_out = ['ana', 'bkg'] - ocn_vars = ['ave_ssh', 'Temp', 'Salt'] - for data_file, dir_out in zip(data_files, dirs_out): - config = plot_config(grid_file=grid_file, - data_file=data_file, - colormap='jet', - comout=os.path.join(comout, 'vrfy', dir_out)) - - # ssh - config.update({'variable': 'ave_ssh', 'bounds': [-1.8, 1.3], 'proj': proj, 'levels': [1]}) - plot_horizontal_slice(config) - - # sst - config.update({'variable': 'Temp', 'bounds': [-1.8, 34.0], 'proj': proj, 'levels': [1]}) - plot_horizontal_slice(config) - - # sss - config.update({'variable': 'Salt', 'bounds': [30, 38], 'proj': proj, 'levels': [1]}) - plot_horizontal_slice(config) - -#def plot_error(comout, -# com_ice_history, -# com_ocean_history, -# cyc, -# RUN, -# grid_file, -# gcyc): - -# ####################################### -# # Std Bkg. Error -# ####################################### -# bmat_cmap = 'jet' -# data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ocn.bkgerr_stddev.nc') -# config = plot_config(grid_file=grid_file, -# data_file=data_file, -# colormap=bmat_cmap, -# comout=os.path.join(comout, 'vrfy', 'bkgerr')) -# -# ####################################### -# # zonal slices -# -# for lat in np.arange(-60, 60, 10): -# -# for max_depth in [700.0, 5000.0]: -# config['lat'] = lat -# config['max depth'] = max_depth -# -# # Temperature -# config.update({'variable': 'Temp', 'levels': [1], 'bounds': [0, 1.5]}) -# plot_zonal_slice(config) -# -# # Salinity -# config.update({'variable': 'Salt', 'levels': [1], 'bounds': [0, .2]}) -# plot_zonal_slice(config) -# -# ####################################### -# # Horizontal slices -# -# # Temperature -# config.update({'variable': 'Temp', 'levels': [1], 'bounds': [0, 2]}) -# plot_horizontal_slice(config) -# -# # Salinity -# config.update({'variable': 'Salt', 'bounds': [0, 0.2]}) -# plot_horizontal_slice(config) -# -# # Sea surface height -# config.update({'variable': 'ave_ssh', 'bounds': [0, 0.1]}) -# plot_horizontal_slice(config) -# class StatePlotter: def __init__(self, config_dict): self.config = config_dict -# self.grid_file = config['grid file'] -# self.data_file = config['fields file'] -# self.variable = config['variable'] -# self.levels = config['levels'] -# self.bounds = config['bounds'] -# self.colormap = config['colormap'] -# self.lats = config['lats'] -# self.comout = config['comout'] -# self.maxdepth = 5000.0 -# self.proj = 'Global' -# - ... - # Where config contains the bounds, filename and whatever else is needed to plot stuff def plot(self): # Loop over variables, slices (horiz and vertical) and projections ... and whatever else is needed @@ -322,33 +141,14 @@ def plot(self): self.config['max depth'] = max_depth for variable in self.config['zonal variables']: - # Temperature bounds = self.config['all bounds'][variable] self.config.update({'variable': variable, 'bounds': bounds}) plot_zonal_slice(self.config) - # Salinity -# self.config.update({'variable': 'Salt', 'levels': [1], 'bounds': [0, .2]}) -# plot_zonal_slice(config) - ####################################### # Horizontal slices - - for variable in self.config['horiz variables']: - bounds = self.config['all bounds'][variable] - self.config.update({'variable': variable, 'bounds': bounds}) - plot_horizontal_slice(self.config) - -# # Temperature -# self.config.update({'variable': 'Temp', 'levels': [1], 'bounds': [0, 2]}) -# plot_horizontal_slice(config) -# -# # Salinity -# self.config.update({'variable': 'Salt', 'bounds': [0, 0.2]}) -# plot_horizontal_slice(config) -# -# # Sea surface height -# self.config.update({'variable': 'ave_ssh', 'bounds': [0, 0.1]}) -# plot_horizontal_slice(config) - - + for proj in self.config['projs']: + for variable in self.config['horiz variables']: + bounds = self.config['all bounds'][variable] + self.config.update({'variable': variable, 'bounds': bounds, 'proj': proj}) + plot_horizontal_slice(self.config) From bf27a51f7606f4df7329e7307a5b9a8a98978148 Mon Sep 17 00:00:00 2001 From: AndrewEichmann-NOAA Date: Thu, 27 Jul 2023 18:41:46 +0000 Subject: [PATCH 10/14] python code style --- scripts/exgdas_global_marine_analysis_vrfy.py | 100 +++++++++--------- ush/soca/soca_vrfy.py | 26 ++--- 2 files changed, 63 insertions(+), 63 deletions(-) diff --git a/scripts/exgdas_global_marine_analysis_vrfy.py b/scripts/exgdas_global_marine_analysis_vrfy.py index 2a61994d5..122bccbc2 100755 --- a/scripts/exgdas_global_marine_analysis_vrfy.py +++ b/scripts/exgdas_global_marine_analysis_vrfy.py @@ -45,16 +45,16 @@ ####################################### data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ocninc.nc') -config = plot_config(grid_file = grid_file, - data_file = data_file, - lats = np.arange(-60, 60, 10), - variables_zonal = ['Temp', 'Salt'], - variables_horiz = ['Temp', 'Salt', 'ave_ssh'], - allbounds = {'Temp': [-0.5, 0.5], +config = plot_config(grid_file=grid_file, + data_file=data_file, + lats=np.arange(-60, 60, 10), + variables_zonal=['Temp', 'Salt'], + variables_horiz=['Temp', 'Salt', 'ave_ssh'], + allbounds={'Temp': [-0.5, 0.5], 'Salt': [-0.1, 0.1], 'ave_ssh': [-0.1, 0.1]}, - colormap = 'RdBu', - comout = os.path.join(comout, 'vrfy', 'incr')) + colormap='RdBu', + comout=os.path.join(comout, 'vrfy', 'incr')) OcnIncPlotter = StatePlotter(config) OcnIncPlotter.plot() @@ -63,16 +63,16 @@ ####################################### data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ice.incr.nc') -config = plot_config(grid_file = grid_file, - data_file = data_file, - lats = np.arange(-60, 60, 10), - variables_horiz = ['aicen', 'hicen', 'hsnon'], - allbounds = {'aicen': [-0.2, 0.2], +config = plot_config(grid_file=grid_file, + data_file=data_file, + lats=np.arange(-60, 60, 10), + variables_horiz=['aicen', 'hicen', 'hsnon'], + allbounds={'aicen': [-0.2, 0.2], 'hicen': [-0.5, 0.5], 'hsnon': [-0.1, 0.1]}, - colormap = 'RdBu', - projs = ['North', 'South'], - comout = os.path.join(comout, 'vrfy', 'incr')) + colormap='RdBu', + projs=['North', 'South'], + comout=os.path.join(comout, 'vrfy', 'incr')) IceIncPlotter = StatePlotter(config) IceIncPlotter.plot() @@ -81,15 +81,15 @@ ####################################### data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.iceana.nc') -config = plot_config(grid_file = grid_file, - data_file = data_file, - variables_horiz = ['aicen', 'hicen', 'hsnon'], - allbounds = {'aicen': [0.0, 1.0], +config = plot_config(grid_file=grid_file, + data_file=data_file, + variables_horiz=['aicen', 'hicen', 'hsnon'], + allbounds={'aicen': [0.0, 1.0], 'hicen': [0.0, 4.0], 'hsnon': [0.0, 0.5]}, - colormap = 'jet', - projs = ['North', 'South','Global'], - comout = os.path.join(comout, 'vrfy', 'ana')) + colormap='jet', + projs=['North', 'South','Global'], + comout=os.path.join(comout, 'vrfy', 'ana')) IceAnaPlotter = StatePlotter(config) IceAnaPlotter.plot() @@ -98,15 +98,15 @@ ####################################### data_file = os.path.join(com_ice_history, f'{RUN}.t{gcyc}z.icef006.nc') -config = plot_config(grid_file = grid_file, - data_file = data_file, - variables_horiz = ['aice_h', 'hs_h', 'hi_h'], - allbounds = {'aice_h': [0.0, 1.0], +config = plot_config(grid_file=grid_file, + data_file=data_file, + variables_horiz=['aice_h', 'hs_h', 'hi_h'], + allbounds={'aice_h': [0.0, 1.0], 'hs_h': [0.0, 4.0], 'hi_h': [0.0, 0.5]}, - colormap = 'jet', - projs = ['North', 'South','Global'], - comout = os.path.join(comout, 'vrfy', 'bkg')) + colormap='jet', + projs=['North', 'South', 'Global'], + comout=os.path.join(comout, 'vrfy', 'bkg')) IceBkgPlotter = StatePlotter(config) IceBkgPlotter.plot() @@ -115,14 +115,14 @@ ####################################### data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ocnana.nc') -config = plot_config(grid_file = grid_file, - data_file = data_file, - variables_horiz = ['ave_ssh', 'Temp', 'Salt'], - allbounds = {'ave_ssh': [-1.8, 1.3], +config = plot_config(grid_file=grid_file, + data_file=data_file, + variables_horiz=['ave_ssh', 'Temp', 'Salt'], + allbounds={'ave_ssh': [-1.8, 1.3], 'Temp': [-1.8, 34.0], 'Salt': [30, 38]}, - colormap = 'jet', - comout = os.path.join(comout, 'vrfy', 'ana')) + colormap='jet', + comout=os.path.join(comout, 'vrfy', 'ana')) OcnAnaPlotter = StatePlotter(config) OcnAnaPlotter.plot() @@ -131,14 +131,14 @@ ####################################### data_file = os.path.join(com_ocean_history, f'{RUN}.t{gcyc}z.ocnf006.nc') -config = plot_config(grid_file = grid_file, - data_file = data_file, - variables_horiz = ['ave_ssh', 'Temp', 'Salt'], - allbounds = {'ave_ssh': [-1.8, 1.3], +config = plot_config(grid_file=grid_file, + data_file=data_file, + variables_horiz=['ave_ssh', 'Temp', 'Salt'], + allbounds={'ave_ssh': [-1.8, 1.3], 'Temp': [-1.8, 34.0], 'Salt': [30, 38]}, - colormap = 'jet', - comout = os.path.join(comout, 'vrfy', 'bkg')) + colormap='jet', + comout=os.path.join(comout, 'vrfy', 'bkg')) OcnBkgPlotter = StatePlotter(config) OcnBkgPlotter.plot() @@ -147,16 +147,16 @@ ####################################### data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ocn.bkgerr_stddev.nc') -config = plot_config(grid_file = grid_file, - data_file = data_file, - lats = np.arange(-60, 60, 10), - variables_zonal = ['Temp', 'Salt'], - variables_horiz = ['Temp', 'Salt', 'ave_ssh'], - allbounds = {'Temp': [0, 2], +config = plot_config(grid_file=grid_file, + data_file=data_file, + lats=np.arange(-60, 60, 10), + variables_zonal=['Temp', 'Salt'], + variables_horiz=['Temp', 'Salt', 'ave_ssh'], + allbounds={'Temp': [0, 2], 'Salt': [0, 0.2], 'ave_ssh': [0, 0.1]}, - colormap = 'jet', - comout = os.path.join(comout, 'vrfy', 'bkgerr')) + colormap='jet', + comout=os.path.join(comout, 'vrfy', 'bkgerr')) BkgErrPlotter = StatePlotter(config) BkgErrPlotter.plot() diff --git a/ush/soca/soca_vrfy.py b/ush/soca/soca_vrfy.py index 5e8c9d492..90f17477a 100755 --- a/ush/soca/soca_vrfy.py +++ b/ush/soca/soca_vrfy.py @@ -23,10 +23,10 @@ def plot_config(grid_file=[], bounds=[], colormap=[], max_depth=np.nan, - max_depths = [700.0, 5000.0], + max_depths=[700.0, 5000.0], comout=[], - variables_horiz = [], - variables_zonal = [], + variables_horiz=[], + variables_zonal=[], lat=np.nan, lats=np.arange(-60, 60, 10), proj='set me', @@ -36,22 +36,22 @@ def plot_config(grid_file=[], Prepares the configuration for the plotting functions below """ config = {} - config['comout'] = comout # output directory + config['comout'] = comout # output directory config['grid file'] = grid_file config['fields file'] = data_file config['levels'] = [1] config['colormap'] = colormap config['all bounds'] = allbounds config['bounds'] = bounds - config['lats'] = lats # all the lats to plot + config['lats'] = lats # all the lats to plot config['lat'] = lat # the lat being currently plotted - config['max depths'] = max_depths # all the max depths to plot - config['max depth'] = max_depth # the max depth currently plotted - config['horiz variables'] = variables_horiz # all the vars for horiz plots - config['zonal variables'] = variables_zonal # all the vars for zonal plots - config['variable'] = variable # the variable currently plotted - config['projs'] = projs # all the projections etc. - config['proj'] = proj + config['max depths'] = max_depths # all the max depths to plot + config['max depth'] = max_depth # the max depth currently plotted + config['horiz variables'] = variables_horiz # all the vars for horiz plots + config['zonal variables'] = variables_zonal # all the vars for zonal plots + config['variable'] = variable # the variable currently plotted + config['projs'] = projs # all the projections etc. + config['proj'] = proj return config @@ -130,7 +130,7 @@ def __init__(self, config_dict): def plot(self): # Loop over variables, slices (horiz and vertical) and projections ... and whatever else is needed - + ####################################### # zonal slices From 02ace93a07312d54768e22d358a66f1f0343a587 Mon Sep 17 00:00:00 2001 From: AndrewEichmann-NOAA Date: Thu, 27 Jul 2023 18:45:20 +0000 Subject: [PATCH 11/14] python code style --- scripts/exgdas_global_marine_analysis_vrfy.py | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/scripts/exgdas_global_marine_analysis_vrfy.py b/scripts/exgdas_global_marine_analysis_vrfy.py index 122bccbc2..45e7f3adc 100755 --- a/scripts/exgdas_global_marine_analysis_vrfy.py +++ b/scripts/exgdas_global_marine_analysis_vrfy.py @@ -51,8 +51,8 @@ variables_zonal=['Temp', 'Salt'], variables_horiz=['Temp', 'Salt', 'ave_ssh'], allbounds={'Temp': [-0.5, 0.5], - 'Salt': [-0.1, 0.1], - 'ave_ssh': [-0.1, 0.1]}, + 'Salt': [-0.1, 0.1], + 'ave_ssh': [-0.1, 0.1]}, colormap='RdBu', comout=os.path.join(comout, 'vrfy', 'incr')) OcnIncPlotter = StatePlotter(config) @@ -68,8 +68,8 @@ lats=np.arange(-60, 60, 10), variables_horiz=['aicen', 'hicen', 'hsnon'], allbounds={'aicen': [-0.2, 0.2], - 'hicen': [-0.5, 0.5], - 'hsnon': [-0.1, 0.1]}, + 'hicen': [-0.5, 0.5], + 'hsnon': [-0.1, 0.1]}, colormap='RdBu', projs=['North', 'South'], comout=os.path.join(comout, 'vrfy', 'incr')) @@ -85,10 +85,10 @@ data_file=data_file, variables_horiz=['aicen', 'hicen', 'hsnon'], allbounds={'aicen': [0.0, 1.0], - 'hicen': [0.0, 4.0], - 'hsnon': [0.0, 0.5]}, + 'hicen': [0.0, 4.0], + 'hsnon': [0.0, 0.5]}, colormap='jet', - projs=['North', 'South','Global'], + projs=['North', 'South', 'Global'], comout=os.path.join(comout, 'vrfy', 'ana')) IceAnaPlotter = StatePlotter(config) IceAnaPlotter.plot() @@ -102,8 +102,8 @@ data_file=data_file, variables_horiz=['aice_h', 'hs_h', 'hi_h'], allbounds={'aice_h': [0.0, 1.0], - 'hs_h': [0.0, 4.0], - 'hi_h': [0.0, 0.5]}, + 'hs_h': [0.0, 4.0], + 'hi_h': [0.0, 0.5]}, colormap='jet', projs=['North', 'South', 'Global'], comout=os.path.join(comout, 'vrfy', 'bkg')) @@ -119,8 +119,8 @@ data_file=data_file, variables_horiz=['ave_ssh', 'Temp', 'Salt'], allbounds={'ave_ssh': [-1.8, 1.3], - 'Temp': [-1.8, 34.0], - 'Salt': [30, 38]}, + 'Temp': [-1.8, 34.0], + 'Salt': [30, 38]}, colormap='jet', comout=os.path.join(comout, 'vrfy', 'ana')) OcnAnaPlotter = StatePlotter(config) @@ -135,8 +135,8 @@ data_file=data_file, variables_horiz=['ave_ssh', 'Temp', 'Salt'], allbounds={'ave_ssh': [-1.8, 1.3], - 'Temp': [-1.8, 34.0], - 'Salt': [30, 38]}, + 'Temp': [-1.8, 34.0], + 'Salt': [30, 38]}, colormap='jet', comout=os.path.join(comout, 'vrfy', 'bkg')) OcnBkgPlotter = StatePlotter(config) @@ -153,8 +153,8 @@ variables_zonal=['Temp', 'Salt'], variables_horiz=['Temp', 'Salt', 'ave_ssh'], allbounds={'Temp': [0, 2], - 'Salt': [0, 0.2], - 'ave_ssh': [0, 0.1]}, + 'Salt': [0, 0.2], + 'ave_ssh': [0, 0.1]}, colormap='jet', comout=os.path.join(comout, 'vrfy', 'bkgerr')) BkgErrPlotter = StatePlotter(config) From 43c7e3f5f530046620bb224d826be507a270c093 Mon Sep 17 00:00:00 2001 From: AndrewEichmann-NOAA Date: Mon, 31 Jul 2023 15:14:23 +0000 Subject: [PATCH 12/14] correcting camel case --- scripts/exgdas_global_marine_analysis_vrfy.py | 44 +++++++++---------- ush/soca/soca_vrfy.py | 42 +++++++++--------- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/scripts/exgdas_global_marine_analysis_vrfy.py b/scripts/exgdas_global_marine_analysis_vrfy.py index 45e7f3adc..6daa3b01b 100755 --- a/scripts/exgdas_global_marine_analysis_vrfy.py +++ b/scripts/exgdas_global_marine_analysis_vrfy.py @@ -22,7 +22,7 @@ import gen_eva_obs_yaml import marine_eva_post import diag_statistics -from soca_vrfy import StatePlotter, plot_config +from soca_vrfy import statePlotter, plotConfig import subprocess from datetime import datetime, timedelta @@ -45,7 +45,7 @@ ####################################### data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ocninc.nc') -config = plot_config(grid_file=grid_file, +config = plotConfig(grid_file=grid_file, data_file=data_file, lats=np.arange(-60, 60, 10), variables_zonal=['Temp', 'Salt'], @@ -55,15 +55,15 @@ 'ave_ssh': [-0.1, 0.1]}, colormap='RdBu', comout=os.path.join(comout, 'vrfy', 'incr')) -OcnIncPlotter = StatePlotter(config) -OcnIncPlotter.plot() +ocnIncPlotter = statePlotter(config) +ocnIncPlotter.plot() ####################################### # sea ice increment ####################################### data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ice.incr.nc') -config = plot_config(grid_file=grid_file, +config = plotConfig(grid_file=grid_file, data_file=data_file, lats=np.arange(-60, 60, 10), variables_horiz=['aicen', 'hicen', 'hsnon'], @@ -73,15 +73,15 @@ colormap='RdBu', projs=['North', 'South'], comout=os.path.join(comout, 'vrfy', 'incr')) -IceIncPlotter = StatePlotter(config) -IceIncPlotter.plot() +iceIncPlotter = statePlotter(config) +iceIncPlotter.plot() ####################################### # sea ice analysis ####################################### data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.iceana.nc') -config = plot_config(grid_file=grid_file, +config = plotConfig(grid_file=grid_file, data_file=data_file, variables_horiz=['aicen', 'hicen', 'hsnon'], allbounds={'aicen': [0.0, 1.0], @@ -90,15 +90,15 @@ colormap='jet', projs=['North', 'South', 'Global'], comout=os.path.join(comout, 'vrfy', 'ana')) -IceAnaPlotter = StatePlotter(config) -IceAnaPlotter.plot() +iceAnaPlotter = statePlotter(config) +iceAnaPlotter.plot() ####################################### # sea ice background ####################################### data_file = os.path.join(com_ice_history, f'{RUN}.t{gcyc}z.icef006.nc') -config = plot_config(grid_file=grid_file, +config = plotConfig(grid_file=grid_file, data_file=data_file, variables_horiz=['aice_h', 'hs_h', 'hi_h'], allbounds={'aice_h': [0.0, 1.0], @@ -107,15 +107,15 @@ colormap='jet', projs=['North', 'South', 'Global'], comout=os.path.join(comout, 'vrfy', 'bkg')) -IceBkgPlotter = StatePlotter(config) -IceBkgPlotter.plot() +iceBkgPlotter = statePlotter(config) +iceBkgPlotter.plot() ####################################### # ocean surface analysis ####################################### data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ocnana.nc') -config = plot_config(grid_file=grid_file, +config = plotConfig(grid_file=grid_file, data_file=data_file, variables_horiz=['ave_ssh', 'Temp', 'Salt'], allbounds={'ave_ssh': [-1.8, 1.3], @@ -123,15 +123,15 @@ 'Salt': [30, 38]}, colormap='jet', comout=os.path.join(comout, 'vrfy', 'ana')) -OcnAnaPlotter = StatePlotter(config) -OcnAnaPlotter.plot() +ocnAnaPlotter = statePlotter(config) +ocnAnaPlotter.plot() ####################################### # ocean surface background ####################################### data_file = os.path.join(com_ocean_history, f'{RUN}.t{gcyc}z.ocnf006.nc') -config = plot_config(grid_file=grid_file, +config = plotConfig(grid_file=grid_file, data_file=data_file, variables_horiz=['ave_ssh', 'Temp', 'Salt'], allbounds={'ave_ssh': [-1.8, 1.3], @@ -139,15 +139,15 @@ 'Salt': [30, 38]}, colormap='jet', comout=os.path.join(comout, 'vrfy', 'bkg')) -OcnBkgPlotter = StatePlotter(config) -OcnBkgPlotter.plot() +ocnBkgPlotter = statePlotter(config) +ocnBkgPlotter.plot() ####################################### # background error ####################################### data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ocn.bkgerr_stddev.nc') -config = plot_config(grid_file=grid_file, +config = plotConfig(grid_file=grid_file, data_file=data_file, lats=np.arange(-60, 60, 10), variables_zonal=['Temp', 'Salt'], @@ -157,8 +157,8 @@ 'ave_ssh': [0, 0.1]}, colormap='jet', comout=os.path.join(comout, 'vrfy', 'bkgerr')) -BkgErrPlotter = StatePlotter(config) -BkgErrPlotter.plot() +bkgErrPlotter = statePlotter(config) +bkgErrPlotter.plot() ####################################### # eva plots diff --git a/ush/soca/soca_vrfy.py b/ush/soca/soca_vrfy.py index 90f17477a..248505711 100755 --- a/ush/soca/soca_vrfy.py +++ b/ush/soca/soca_vrfy.py @@ -15,22 +15,22 @@ 'Global': ccrs.Mollweide(central_longitude=-150)} -def plot_config(grid_file=[], - data_file=[], - variable=[], - levels=[], - allbounds=[], - bounds=[], - colormap=[], - max_depth=np.nan, - max_depths=[700.0, 5000.0], - comout=[], - variables_horiz=[], - variables_zonal=[], - lat=np.nan, - lats=np.arange(-60, 60, 10), - proj='set me', - projs=['Global']): +def plotConfig(grid_file=[], + data_file=[], + variable=[], + levels=[], + allbounds=[], + bounds=[], + colormap=[], + max_depth=np.nan, + max_depths=[700.0, 5000.0], + comout=[], + variables_horiz=[], + variables_zonal=[], + lat=np.nan, + lats=np.arange(-60, 60, 10), + proj='set me', + projs=['Global']): """ Prepares the configuration for the plotting functions below @@ -55,7 +55,7 @@ def plot_config(grid_file=[], return config -def plot_horizontal_slice(config): +def plotHorizontalSlice(config): """ pcolormesh of a horizontal slice of an ocean field """ @@ -96,7 +96,7 @@ def plot_horizontal_slice(config): plt.savefig(figname, bbox_inches='tight', dpi=600) -def plot_zonal_slice(config): +def plotZonalSlice(config): """ pcolormesh of a zonal slice of an ocean field """ @@ -123,7 +123,7 @@ def plot_zonal_slice(config): plt.savefig(figname, bbox_inches='tight', dpi=600) -class StatePlotter: +class statePlotter: def __init__(self, config_dict): self.config = config_dict @@ -143,7 +143,7 @@ def plot(self): for variable in self.config['zonal variables']: bounds = self.config['all bounds'][variable] self.config.update({'variable': variable, 'bounds': bounds}) - plot_zonal_slice(self.config) + plotZonalSlice(self.config) ####################################### # Horizontal slices @@ -151,4 +151,4 @@ def plot(self): for variable in self.config['horiz variables']: bounds = self.config['all bounds'][variable] self.config.update({'variable': variable, 'bounds': bounds, 'proj': proj}) - plot_horizontal_slice(self.config) + plotHorizontalSlice(self.config) From 2e330f51c9a8aedc1f02caf466e42eb4856ecd57 Mon Sep 17 00:00:00 2001 From: AndrewEichmann-NOAA Date: Mon, 31 Jul 2023 15:25:31 +0000 Subject: [PATCH 13/14] python coding norms --- scripts/exgdas_global_marine_analysis_vrfy.py | 114 +++++++++--------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/scripts/exgdas_global_marine_analysis_vrfy.py b/scripts/exgdas_global_marine_analysis_vrfy.py index 6daa3b01b..88a33f49b 100755 --- a/scripts/exgdas_global_marine_analysis_vrfy.py +++ b/scripts/exgdas_global_marine_analysis_vrfy.py @@ -46,15 +46,15 @@ data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ocninc.nc') config = plotConfig(grid_file=grid_file, - data_file=data_file, - lats=np.arange(-60, 60, 10), - variables_zonal=['Temp', 'Salt'], - variables_horiz=['Temp', 'Salt', 'ave_ssh'], - allbounds={'Temp': [-0.5, 0.5], - 'Salt': [-0.1, 0.1], - 'ave_ssh': [-0.1, 0.1]}, - colormap='RdBu', - comout=os.path.join(comout, 'vrfy', 'incr')) + data_file=data_file, + lats=np.arange(-60, 60, 10), + variables_zonal=['Temp', 'Salt'], + variables_horiz=['Temp', 'Salt', 'ave_ssh'], + allbounds={'Temp': [-0.5, 0.5], + 'Salt': [-0.1, 0.1], + 'ave_ssh': [-0.1, 0.1]}, + colormap='RdBu', + comout=os.path.join(comout, 'vrfy', 'incr')) ocnIncPlotter = statePlotter(config) ocnIncPlotter.plot() @@ -64,15 +64,15 @@ data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ice.incr.nc') config = plotConfig(grid_file=grid_file, - data_file=data_file, - lats=np.arange(-60, 60, 10), - variables_horiz=['aicen', 'hicen', 'hsnon'], - allbounds={'aicen': [-0.2, 0.2], - 'hicen': [-0.5, 0.5], - 'hsnon': [-0.1, 0.1]}, - colormap='RdBu', - projs=['North', 'South'], - comout=os.path.join(comout, 'vrfy', 'incr')) + data_file=data_file, + lats=np.arange(-60, 60, 10), + variables_horiz=['aicen', 'hicen', 'hsnon'], + allbounds={'aicen': [-0.2, 0.2], + 'hicen': [-0.5, 0.5], + 'hsnon': [-0.1, 0.1]}, + colormap='RdBu', + projs=['North', 'South'], + comout=os.path.join(comout, 'vrfy', 'incr')) iceIncPlotter = statePlotter(config) iceIncPlotter.plot() @@ -82,14 +82,14 @@ data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.iceana.nc') config = plotConfig(grid_file=grid_file, - data_file=data_file, - variables_horiz=['aicen', 'hicen', 'hsnon'], - allbounds={'aicen': [0.0, 1.0], - 'hicen': [0.0, 4.0], - 'hsnon': [0.0, 0.5]}, - colormap='jet', - projs=['North', 'South', 'Global'], - comout=os.path.join(comout, 'vrfy', 'ana')) + data_file=data_file, + variables_horiz=['aicen', 'hicen', 'hsnon'], + allbounds={'aicen': [0.0, 1.0], + 'hicen': [0.0, 4.0], + 'hsnon': [0.0, 0.5]}, + colormap='jet', + projs=['North', 'South', 'Global'], + comout=os.path.join(comout, 'vrfy', 'ana')) iceAnaPlotter = statePlotter(config) iceAnaPlotter.plot() @@ -99,14 +99,14 @@ data_file = os.path.join(com_ice_history, f'{RUN}.t{gcyc}z.icef006.nc') config = plotConfig(grid_file=grid_file, - data_file=data_file, - variables_horiz=['aice_h', 'hs_h', 'hi_h'], - allbounds={'aice_h': [0.0, 1.0], - 'hs_h': [0.0, 4.0], - 'hi_h': [0.0, 0.5]}, - colormap='jet', - projs=['North', 'South', 'Global'], - comout=os.path.join(comout, 'vrfy', 'bkg')) + data_file=data_file, + variables_horiz=['aice_h', 'hs_h', 'hi_h'], + allbounds={'aice_h': [0.0, 1.0], + 'hs_h': [0.0, 4.0], + 'hi_h': [0.0, 0.5]}, + colormap='jet', + projs=['North', 'South', 'Global'], + comout=os.path.join(comout, 'vrfy', 'bkg')) iceBkgPlotter = statePlotter(config) iceBkgPlotter.plot() @@ -116,13 +116,13 @@ data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ocnana.nc') config = plotConfig(grid_file=grid_file, - data_file=data_file, - variables_horiz=['ave_ssh', 'Temp', 'Salt'], - allbounds={'ave_ssh': [-1.8, 1.3], - 'Temp': [-1.8, 34.0], - 'Salt': [30, 38]}, - colormap='jet', - comout=os.path.join(comout, 'vrfy', 'ana')) + data_file=data_file, + variables_horiz=['ave_ssh', 'Temp', 'Salt'], + allbounds={'ave_ssh': [-1.8, 1.3], + 'Temp': [-1.8, 34.0], + 'Salt': [30, 38]}, + colormap='jet', + comout=os.path.join(comout, 'vrfy', 'ana')) ocnAnaPlotter = statePlotter(config) ocnAnaPlotter.plot() @@ -132,13 +132,13 @@ data_file = os.path.join(com_ocean_history, f'{RUN}.t{gcyc}z.ocnf006.nc') config = plotConfig(grid_file=grid_file, - data_file=data_file, - variables_horiz=['ave_ssh', 'Temp', 'Salt'], - allbounds={'ave_ssh': [-1.8, 1.3], - 'Temp': [-1.8, 34.0], - 'Salt': [30, 38]}, - colormap='jet', - comout=os.path.join(comout, 'vrfy', 'bkg')) + data_file=data_file, + variables_horiz=['ave_ssh', 'Temp', 'Salt'], + allbounds={'ave_ssh': [-1.8, 1.3], + 'Temp': [-1.8, 34.0], + 'Salt': [30, 38]}, + colormap='jet', + comout=os.path.join(comout, 'vrfy', 'bkg')) ocnBkgPlotter = statePlotter(config) ocnBkgPlotter.plot() @@ -148,15 +148,15 @@ data_file = os.path.join(comout, f'{RUN}.t'+cyc+'z.ocn.bkgerr_stddev.nc') config = plotConfig(grid_file=grid_file, - data_file=data_file, - lats=np.arange(-60, 60, 10), - variables_zonal=['Temp', 'Salt'], - variables_horiz=['Temp', 'Salt', 'ave_ssh'], - allbounds={'Temp': [0, 2], - 'Salt': [0, 0.2], - 'ave_ssh': [0, 0.1]}, - colormap='jet', - comout=os.path.join(comout, 'vrfy', 'bkgerr')) + data_file=data_file, + lats=np.arange(-60, 60, 10), + variables_zonal=['Temp', 'Salt'], + variables_horiz=['Temp', 'Salt', 'ave_ssh'], + allbounds={'Temp': [0, 2], + 'Salt': [0, 0.2], + 'ave_ssh': [0, 0.1]}, + colormap='jet', + comout=os.path.join(comout, 'vrfy', 'bkgerr')) bkgErrPlotter = statePlotter(config) bkgErrPlotter.plot() From 4bb692016570b08cc1e5e1b79e9a43e1f7ceb23d Mon Sep 17 00:00:00 2001 From: AndrewEichmann-NOAA Date: Mon, 31 Jul 2023 19:14:22 +0000 Subject: [PATCH 14/14] python style thing in something completely unrelated --- ush/ufsda/genYAML.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ush/ufsda/genYAML.py b/ush/ufsda/genYAML.py index accc8d5c5..b61b11de7 100644 --- a/ush/ufsda/genYAML.py +++ b/ush/ufsda/genYAML.py @@ -31,7 +31,7 @@ def genYAML(yamlconfig, output=None): # what if the config_dict has environment variables that need substituted? pattern = re.compile(r'.*?\${(\w+)}.*?') for key, value in config_dict.items(): - if type(value) == str: + if value is str: match = pattern.findall(value) if match: fullvalue = value