From 620560fbcd9e5ae47b16184e7041b2e3445c3abb Mon Sep 17 00:00:00 2001 From: Chris Blanton Date: Thu, 16 Dec 2021 16:32:34 -0500 Subject: [PATCH 1/3] Update for locating basin codes in MOM6_refineDiag.csh The script currently looks for the codes in basin_codes.nc which does not exist in FRE output normally. Many FRE XMLs add basin_codes.nc to the history output before output staging, so the basin codes appear alongside the other history files with the YYYYMMDD.basin_codes.nc name. This update to the refineDiag wrapper script uses the YYYYMMDD.basin_codes.nc file as the basin codes if it exists. --- tools/analysis/MOM6_refineDiag.csh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/analysis/MOM6_refineDiag.csh b/tools/analysis/MOM6_refineDiag.csh index c849e0a06b..fe881eb8d6 100755 --- a/tools/analysis/MOM6_refineDiag.csh +++ b/tools/analysis/MOM6_refineDiag.csh @@ -101,6 +101,9 @@ chmod +x $script_dir/*.py set ocean_static_file = $yr1.ocean_static.nc if ( -e $yr1.ocean_static_no_mask_table.nc ) set ocean_static_file = $yr1.ocean_static_no_mask_table.nc +set basin_codes_file = basin_codes.nc +if ( -e $yr1.basin_codes.nc ) set basin_codes_file = $yr1.basin_codes.nc + set basin_codes_d2_file = ocean_static_d2.nc #echo '====annual mean Eddy Kinetic Energy======' @@ -109,13 +112,13 @@ set basin_codes_d2_file = ocean_static_d2.nc echo '==== Offline Diagnostics ====' if ( -f $yr1.ocean_month.nc ) then - $script_dir/refineDiag_ocean_month.py -b basin_codes.nc -r $refineDiagDir $yr1.ocean_month.nc + $script_dir/refineDiag_ocean_month.py -b $basin_codes_file -r $refineDiagDir $yr1.ocean_month.nc endif if ( -f $yr1.ocean_month_z.nc ) then - $script_dir/refineDiag_ocean_month_z.py -b basin_codes.nc -r $refineDiagDir -s ./ $yr1.ocean_month_z.nc + $script_dir/refineDiag_ocean_month_z.py -b $basin_codes_file -r $refineDiagDir -s ./ $yr1.ocean_month_z.nc endif if ( -f $yr1.ocean_month_rho2.nc ) then - $script_dir/refineDiag_ocean_month_rho2.py -b basin_codes.nc -r $refineDiagDir $yr1.ocean_month_rho2.nc + $script_dir/refineDiag_ocean_month_rho2.py -b $basin_codes_file -r $refineDiagDir $yr1.ocean_month_rho2.nc endif echo '==== Offline Diagnostics downsampled ====' From de8f0aa0948148f518908d6154340a97f5f1e264 Mon Sep 17 00:00:00 2001 From: Chris Blanton Date: Thu, 16 Dec 2021 16:39:00 -0500 Subject: [PATCH 2/3] Fix for detecting symmetric mode output in refineDiag_ocean_month.py The data has shape of TIME,Y,X and the mask has shape of Y,X, so the symmetric mode check should compare the 2nd index for the data and the 1st index for the mask. If the mask Y value is one greater than the data Y value, then the output is symmetric. --- tools/analysis/refineDiag_ocean_month.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/analysis/refineDiag_ocean_month.py b/tools/analysis/refineDiag_ocean_month.py index f83e747d24..493e4c05ba 100755 --- a/tools/analysis/refineDiag_ocean_month.py +++ b/tools/analysis/refineDiag_ocean_month.py @@ -40,7 +40,7 @@ def run(): def heat_trans_by_basin(x,mask=None,lat=None,minlat=None): if mask is not None: - if not (x.shape[0] == 1+mask.shape[0]): #symmetric case + if x.shape[1] == 1+mask.shape[0]: #symmetric case mask=np.append(mask,np.zeros((1,mask.shape[1])),axis=0) varmask = np.sum(mask,axis=-1) varmask = np.expand_dims(varmask,0) From 8aa5cc3d55ec1f4d2a559de16e1cd5fe86772efd Mon Sep 17 00:00:00 2001 From: Chris Blanton Date: Fri, 7 Jan 2022 10:30:29 -0500 Subject: [PATCH 3/3] Improved fix for detecting symmetric mode output in refineDiag_ocean_month.py Update symmetric mode test to handle 2D or 3D input data. Also, check that the data and mask are 2 or 3D and 2D, respectively. --- tools/analysis/refineDiag_ocean_month.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/analysis/refineDiag_ocean_month.py b/tools/analysis/refineDiag_ocean_month.py index 493e4c05ba..90ac10e4e0 100755 --- a/tools/analysis/refineDiag_ocean_month.py +++ b/tools/analysis/refineDiag_ocean_month.py @@ -40,7 +40,10 @@ def run(): def heat_trans_by_basin(x,mask=None,lat=None,minlat=None): if mask is not None: - if x.shape[1] == 1+mask.shape[0]: #symmetric case + assert len(mask.shape) == 2, 'mask should be 2 dimensions' + assert len(x.shape) == 2 or len(x.shape) == 3, 'data should be 2 or 3 dimensions' + # symmetric case + if x.shape[-2:][1] == 1+mask.shape[1] and x.shape[-2:][0] == 1+mask.shape[0]: mask=np.append(mask,np.zeros((1,mask.shape[1])),axis=0) varmask = np.sum(mask,axis=-1) varmask = np.expand_dims(varmask,0)