Skip to content

Commit

Permalink
Fix analysis script to work with any resolution, issue #13
Browse files Browse the repository at this point in the history
- The script tools/analysis/EddyKineticEnergy.py was always loading the 1/4 degree gridSpec
  and fail for 1 deg models.
- Fixed it to use the ocean_static.nc in the working directory instead. Works for any resolution
- Fixed the calling refineDiag script to pass ocean_static.nc as grid.
- This fixes issue #13
  • Loading branch information
nikizadehgfdl committed Dec 10, 2014
1 parent 2fb8640 commit a18b728
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
16 changes: 7 additions & 9 deletions tools/analysis/EddyKineticEnergy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,22 @@
try: import argparse
except: raise Exception('This version of python is not new enough. python 2.7 or newer is required.')

parser = argparse.ArgumentParser(description='''Script for plotting annual-average SST bias.''')
parser.add_argument('annual_file', type=str, help='''Annually-averaged file contained 3D temp.''')
parser = argparse.ArgumentParser(description='''Script for plotting annual-average eddy kinetic energy.''')
parser.add_argument('annual_file', type=str, help='''Daily file containing ssu,ssv.''')
parser.add_argument('-l','--label', type=str, default='', help='''Label to add to the plot.''')
parser.add_argument('-o','--outdir', type=str, default='.', help='''Directory in which to place plots.''')
parser.add_argument('-g','--gridspec', type=str,
default='/archive/gold/datasets/MOM6z_SIS_025/siena/mosaic.unpacked',
help='''Directory containing mosaic/grid-spec files (ocean_hgrid.nc and ocean_mask.nc).''')
help='''File containing variables geolon,geolat,wet,area_t. Usually the ocean_static.nc from diag_table.''')
cmdLineArgs = parser.parse_args()

rootGroup = netCDF4.Dataset( cmdLineArgs.annual_file )
if 'ssu' not in rootGroup.variables: raise Exception('Could not find "ssu" in file "%s"'%(cmdLineArgs.annual_file))
if 'ssv' not in rootGroup.variables: raise Exception('Could not find "ssv" in file "%s"'%(cmdLineArgs.annual_file))

x = netCDF4.Dataset(cmdLineArgs.gridspec+'/ocean_hgrid.nc').variables['x'][::2,::2]
y = netCDF4.Dataset(cmdLineArgs.gridspec+'/ocean_hgrid.nc').variables['y'][::2,::2]
msk = netCDF4.Dataset(cmdLineArgs.gridspec+'/ocean_mask.nc').variables['mask'][:]
area = msk*netCDF4.Dataset(cmdLineArgs.gridspec+'/ocean_hgrid.nc').variables['area'][:,:].reshape([msk.shape[0], 2, msk.shape[1], 2]).sum(axis=-3).sum(axis=-1)
#msk = numpy.ma.array(msk, mask=(msk==0))
x = netCDF4.Dataset(cmdLineArgs.gridspec).variables['geolon'][:,:]
y = netCDF4.Dataset(cmdLineArgs.gridspec).variables['geolat'][:,:]
msk = netCDF4.Dataset(cmdLineArgs.gridspec).variables['wet'][:,:]
area = msk*netCDF4.Dataset(cmdLineArgs.gridspec).variables['area_t'][:,:]

#[t,z,y,x] corresponds to axis [0,1,2,3] which can be indexed by [-4,-3,-2,-1]

Expand Down
5 changes: 4 additions & 1 deletion tools/analysis/MOM6_refineDiag.csh
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@ set script_dir=${out_dir}/mom6/tools/analysis

echo '==Run some example annual scripts. These are not reviewed by scientists.'

#log the experiment to the MDBI database
fredb -x $rtsxml -p $platform -t $target -q cobweb -d curator $name

echo '====annual mean Eddy Kinetic Energy======'
mkdir -p $out_dir/ocean_${yr1}/EddyKineticEnergy

$script_dir/EddyKineticEnergy.py -g /archive/gold/datasets/OM4_025/mosaic.v20140610.unpacked -o $out_dir/ocean_${yr1}/EddyKineticEnergy -l ${yr1} $yr1.ocean_daily.nc
$script_dir/EddyKineticEnergy.py -g $yr1.ocean_static.nc -o $out_dir/ocean_${yr1}/EddyKineticEnergy -l ${yr1} $yr1.ocean_daily.nc

echo " ---------- end yearly analysis ---------- "

Expand Down

5 comments on commit a18b728

@adcroft
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will reading geolon,geolat from ocean_static work for masked output?

@Zhi-Liang
Copy link

@Zhi-Liang Zhi-Liang commented on a18b728 Dec 11, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adcroft
Copy link
Member

@adcroft adcroft commented on a18b728 Dec 11, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikizadehgfdl
Copy link
Contributor Author

@nikizadehgfdl nikizadehgfdl commented on a18b728 Dec 11, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikizadehgfdl
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this fix in a OM4_SIS_baseline experiment with mask_table and it worked.

/nbhome/Niki.Zadeh/testing_mom6_20141215/OM4_SIS_baseline_TEST/mom6/tools/analysis/EddyKineticEnergy.py -g 19040101.ocean_static.nc -o /nbhome/Niki.Zadeh/testing_mom6_20141215/OM4_SIS_baseline_TEST/ocean_19040101/EddyKineticEnergy -l 19040101 19040101.ocean_daily.nc
/usr/local/python/2.7.3/lib/python2.7/site-packages/numpy/ma/core.py:932: RuntimeWarning: overflow encountered in multiply
  result = self.f(da, db, *args, **kwargs)

Please sign in to comment.