Skip to content

Commit

Permalink
Merge pull request #5 from CommerceGov/usr/nnz/fix_analysis_template
Browse files Browse the repository at this point in the history
- Corrects environment and imports needed for MIDAS.
- Fixes EKE script.
- Fixes #2.
  • Loading branch information
adcroft committed Nov 6, 2014
2 parents ef2c397 + 5c2878c commit e794854
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
22 changes: 13 additions & 9 deletions ice_ocean_SIS/OM4_025/ocn_annual.frepp
Original file line number Diff line number Diff line change
Expand Up @@ -70,34 +70,38 @@ set target
if ($#argv) set argu = ($argv:q)


set freanalysismodule = fre-analysis/test
#set freanalysismodule = fre-analysis/test

# make sure valid platform and required modules are loaded
if (`gfdl_platform` == "hpcs-csc") then
source $MODULESHOME/init/csh
module use -a /home/fms/local/modulefiles #/usr/local/paida/Modules
module purge
module load $fremodule
module load $freanalysismodule
module load gcc
# module load $fremodule
# module load $freanalysismodule
# module load gcc
module load netcdf/4.2
module load python/2.7.3
module load intel_compilers
else
echo "ERROR: invalid platform"
exit 1
endif

# check again?
if (! $?FRE_ANALYSIS_HOME) then
echo "ERROR: environment variable FRE_ANALYSIS_HOME not set."
exit 1
endif
#if (! $?FRE_ANALYSIS_HOME) then
# echo "ERROR: environment variable FRE_ANALYSIS_HOME not set."
# exit 1
#endif

# Build MIDAS libs and set PYTHONPATH
(cd ${out_dir}/mom6/tools/python/025gridGeneration ; make frepp_local )
setenv PYTHONPATH ${out_dir}/mom6/tools/python/025gridGeneration/local/lib/python

# Run script
set src_dir = ${out_dir}/mom6/tools/analysis
set script_bash = ${src_dir}/MOM6_ts_annual.bash
set script_dir = ${out_dir}/mom6/tools/analysis
setenv PYTHONPATH ${out_dir}/mom6/tools/python/025gridGeneration/local/lib/python
set woa05=/archive/gold/datasets/OM4_025/obs/WOA05_ptemp_salt_annual.v20141006.nc
set mosaicDir=/archive/gold/datasets/OM4_025/mosaic.v20140610.unpacked

Expand Down
24 changes: 19 additions & 5 deletions tools/analysis/EddyKineticEnergy.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
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))
#msk = numpy.ma.array(msk, mask=(msk==0))

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

ssu = rootGroup.variables['ssu']

ssu_mean = ssu[:].mean(axis=0)
eke_u = (0.5*(ssu-ssu_mean)**2).mean(axis=0)
eke = (eke_u + numpy.roll(eke_u,1,axis=-1))/2 # U-point to T-point transform
Expand All @@ -39,10 +40,23 @@
eke_v = (0.5*(ssv-ssv_mean)**2).mean(axis=0)
eke = eke + (eke_v + numpy.roll(eke_v,1,axis=-2))/2

ci=m6plot.pmCI(0.0,0.5,0.1)
#factor of 10000 to convert to (cm/s)^2
eke = 10000*eke

#clip the extreme small values that cause log to blow up
eke = eke.clip(min=1.0e-8)

#Plot with logscale=True
#ci=m6plot.pmCI(0.0,10.0,0.1)
#plot_title = 'Eddy Kinetic Energy annual mean [(cm/s)^2]'

#The logscale=True of matplotlib.pyplot does not work!
#So, pass the log to be plotted instead
eke = numpy.log(eke)
plot_title = 'Log of Eddy Kinetic Energy annual mean [(cm/s)^2]'

m6plot.xyplot( 10000*eke, x, y, area=area,
suptitle=rootGroup.title+' '+cmdLineArgs.label, title='Eddy Kinetic Energy annual mean [(cm/s)^2]',
clim=ci, logscale=True,
m6plot.xyplot( eke, x, y, area=area,
suptitle=rootGroup.title+' '+cmdLineArgs.label, title=plot_title,
# clim=ci, logscale=True,
save=cmdLineArgs.outdir+'/EKE_mean.png')

3 changes: 3 additions & 0 deletions tools/analysis/TS_depth_integrals.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

from midas.rectgrid import *
from midas.rectgrid_gen import *
import matplotlib
# Force matplotlib to not use any Xwindows backend.
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import netCDF4 as nc
Expand Down

0 comments on commit e794854

Please sign in to comment.