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

Diurnal test off #575

Merged
merged 4 commits into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# 'GISS-E2-H', 'inmcm4', 'IPSL-CM5A-LR', 'IPSL-CM5A-MR',
# 'MIROC4h', 'MIROC5', 'MIROC-ESM', 'MIROC-ESM-CHEM'

from __future__ import print_function
from __future__ import print_function, division
import cdms2
import genutil
import MV2
Expand Down Expand Up @@ -44,7 +44,7 @@ def compute(params):
print('Opening %s ...' % fileName)
f = cdms2.open(fileName)

# Composite-mean and composite-s.d diurnal cycle for month and year(s):
# Composite-mean and composite-s.d diurnal cycle for month and year(s):
iYear = 0
for year in range(args.firstyear, args.lastyear + 1):
print('Year %s:' % year)
Expand Down Expand Up @@ -77,7 +77,7 @@ def compute(params):
nlats = dimensions[1]
nlons = dimensions[2]
deltaH = 24. / N
dayspermo = tvarb.shape[0] / N
dayspermo = tvarb.shape[0] // N
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to be safe, you might want to have from __future__ import division. This will use the Python 3 way of dividing, if that's what you wanted. I'm not too sure if that's what you were aiming for however.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you're right @zshaheen updating now, I'm surpised py2 passed.

print(' %d timepoints per day, %d hr intervals between timepoints' % (N, deltaH))
comptime = firstday.getTime()
modellons = tvarb.getLongitude()
Expand Down Expand Up @@ -221,5 +221,4 @@ def compute(params):
print("FILES:", fileList)
params = [INPUT(args, name, template) for name in fileList]
print("PARAMS:", params)

cdp.cdp_run.multiprocess(compute, params, num_workers=args.num_workers)
39 changes: 21 additions & 18 deletions tests/test_pmp_diurnal.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,38 @@ def compare_nc(self,test_name):
test_out = cdms2.open(os.path.join("test_data",test_name))
good_out = cdms2.open(os.path.join("tests/diurnal",test_name))

print("Checking same variables are present as in {}".format(good_name))
self.assertEqual(list(test_out.variables.keys()),list(good_out.variables.keys()))

for v in list(good_out.variables.keys()):
print("Checking variable {} is correct".format(v))
test = test_out(v)
good = good_out(v)

self.assertSame(test,good)

def teistDiurnaliComputeStdDailyMean(self):
cmd = 'computeStdDailyMeansWrapped.py --mp test_data --rd test_data/results/nc -t "sample_data_pr_%(model).nc" -m7'
def testDiurnaliComputeStdDailyMean(self):
data_pth = cdat_info.get_sampledata_path()
cmd = 'computeStdDailyMeansWrapped.py --mp {} --rd test_data/results/nc -t "sample_data_pr_%(model).nc" -m7'.format(data_pth)
p = subprocess.Popen(shlex.split(cmd))
p.communicate()

self.compare_nc("results/nc/pr_CMCC_Jul_1999-2005_std_of_dailymeans.nc")

def teistFourierDiurnalAllGridWrapped(self):
cmd = 'fourierDiurnalAllGridWrapped.py --mp test_data/results/nc --rd test_data/results/nc -m7'
def testFourierDiurnalAllGridWrapped(self):
cmd = 'fourierDiurnalAllGridWrapped.py --mp tests/diurnal/results/nc --rd test_data/results/nc -m7'
p = subprocess.Popen(shlex.split(cmd))
p.communicate()
self.compare_nc("results/nc/pr_CMCC_Jul_1999-2005_tmean.nc")
self.compare_nc("results/nc/pr_CMCC_Jul_1999-2005_tS.nc")
self.compare_nc("results/nc/pr_CMCC_Jul_1999-2005_S.nc")

def teistDiurnalStdDailyVariance(self):
self.runJsoner("std_of_dailymeansWrappedInOut.py","pr_Jul_1999_2005_std_of_dailymeans.json")
def runJsoner(self,script,json_file):
cmd = '{} --region_name=TROPICS --lat1=-30. --lat2=30. --lon1=0. --lon2=360 --mp tests/diurnal/results/nc --rd test_data/results/jsons -m7 -t "pr_%(model)_%(month)_%(firstyear)-%(lastyear)_S.nc"'.format(script)
def testDiurnalStdDailyVariance(self):
self.runJsoner("std_of_dailymeansWrappedInOut.py","pr_Jul_1999_2005_std_of_dailymeans.json","std_of_dailymeans")
def runJsoner(self,script,json_file,ext):
cmd = '{} --region_name=TROPICS --lat1=-30. --lat2=30. --lon1=0. --lon2=360 --mp tests/diurnal/results/nc --rd test_data/results/jsons -m7 -t "pr_%(model)_%(month)_%(firstyear)-%(lastyear)_{}.nc"'.format(script, ext)
p = subprocess.Popen(shlex.split(cmd))
p.communicate()
cmd = '{} --append --mp tests/diurnal/results/nc --rd test_data/results/jsons -m7 -t "pr_%(model)_%(month)_%(firstyear)-%(lastyear)_S.nc"'.format(script)
cmd = '{} --append --mp tests/diurnal/results/nc --rd test_data/results/jsons -m7 -t "pr_%(model)_%(month)_%(firstyear)-%(lastyear)_{}.nc"'.format(script, ext)
p = subprocess.Popen(shlex.split(cmd))
p.communicate()
good = open("tests/diurnal/results/json/{}".format(json_file))
Expand All @@ -65,24 +67,25 @@ def runJsoner(self,script,json_file):
good = json.load(good)
self.assertEqual(test["RESULTS"],good["RESULTS"])
"""
def teistCompositeDiurnalStatisticsWrapped(self):
cmd = 'compositeDiurnalStatisticsWrapped.py --mp test_data --rd test_data/results/nc -t "sample_data_pr_%(model).nc" -m7'
def testCompositeDiurnalStatisticsWrapped(self):
data_pth = cdat_info.get_sampledata_path()
cmd = 'compositeDiurnalStatisticsWrapped.py --mp {} --rd test_data/results/nc -t "sample_data_pr_%(model).nc" -m7'.format(data_pth)
p = subprocess.Popen(shlex.split(cmd))
p.communicate()
self.compare_nc("results/nc/pr_CMCC_Jul_1999-2005_diurnal_avg.nc")
self.compare_nc("results/nc/pr_CMCC_Jul_1999-2005_diurnal_std.nc")
self.compare_nc("results/nc/pr_CMCC_LocalSolarTimes.nc")

def teistStd_of_hourlyvaluesWrappedInOut(self):
self.runJsoner("std_of_hourlyvaluesWrappedInOut.py","pr_Jul_1999-2005_std_of_hourlymeans.json")
def testStd_of_hourlyvaluesWrappedInOut(self):
self.runJsoner("std_of_hourlyvaluesWrappedInOut.py","pr_Jul_1999-2005_std_of_hourlymeans.json","diurnal_std")

def teistStd_of_meandiurnalcycWrappedInOut(self):
self.runJsoner("std_of_meandiurnalcycWrappedInOut.py","pr_Jul_1999-2005_std_of_meandiurnalcyc.json")
def testStd_of_meandiurnalcycWrappedInOut(self):
self.runJsoner("std_of_meandiurnalcycWrappedInOut.py","pr_Jul_1999-2005_std_of_meandiurnalcyc.json","diurnal_avg")

def testSavg_fourierWrappedInOut(self):
self.runJsoner("savg_fourierWrappedInOut.py","pr_Jul_1999-2005_savg_DiurnalFourier.json")
self.runJsoner("savg_fourierWrappedInOut.py","pr_Jul_1999-2005_savg_DiurnalFourier.json","S")

def teistfourierDiurnalGridpoints(self):
def testfourierDiurnalGridpoints(self):
cmd = 'fourierDiurnalGridpoints.py --mp tests/diurnal/results/nc --rd test_data/results/ascii'
p = subprocess.Popen(shlex.split(cmd))
p.communicate()
Expand Down