Skip to content

Commit

Permalink
doesn't dump file unless asked, reads good var in assert func and sav… (
Browse files Browse the repository at this point in the history
#28)

* doesn't dump file unless asked, reads good var in assert func and save with correct name

* no restriction on numpy
  • Loading branch information
doutriaux1 authored Mar 1, 2019
1 parent f50c687 commit 6e9a541
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 27 deletions.
14 changes: 7 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ aliases:
- &create_conda_env
name: create_conda_env
environment:
PKGS: "cdms2 cdat_info testsrunner udunits2 'numpy<1.14.6'"
PKGS: "cdms2 cdat_info testsrunner udunits2 numpy"
CHANNELS: "-c cdat/label/nightly -c conda-forge -c cdat"
command: |
export PATH=$WORKDIR/miniconda/bin:$PATH
Expand Down Expand Up @@ -181,10 +181,10 @@ workflows:
genutil:
jobs:
- macos_genutil_py2
- macos_genutil_py3:
requires:
- macos_genutil_py2
- macos_genutil_py3
# requires:
# - macos_genutil_py2
- linux_genutil_py2
- linux_genutil_py3:
requires:
- linux_genutil_py2
- linux_genutil_py3
# requires:
# - linux_genutil_py2
50 changes: 30 additions & 20 deletions tests/test_genutil_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,56 @@
import unittest
import cdat_info
import numpy
dump = False

class GENUTIL(unittest.TestCase):
def assertArraysEqual(self,A,B):
self.assertTrue(numpy.ma.allclose(A,B))
def assertArraysEqual(self,A,nm,skip=False, dump=dump):
B = self.good(nm)
print("A-B max difference", numpy.abs(A-B).max(), skip)
print("A-B % difference", numpy.abs((A-B)/A).max(), skip)
if dump:
self.out.write(A, id=nm)
self.out.sync()

if not skip:
self.assertTrue(numpy.ma.allclose(A,B))

def testStatisitcs(self):
f=cdms2.open(os.path.join(cdat_info.get_sampledata_path(),'clt.nc'))

u=f('u',time=slice(0,1),level=slice(0,1),squeeze=1)
v=f('v',time=slice(0,1),plev1=slice(0,1),squeeze=1)

f=cdms2.open(os.path.join(cdat_info.get_sampledata_path(),"genutil_statistics.nc"))
self.out = cdms2.open("genutil_statistics_new.nc","w")
self.good = cdms2.open(os.path.join(cdat_info.get_sampledata_path(),"genutil_statistics.nc"))
if dump:
self.out = cdms2.open("genutil_statistics_new.nc","w")
print('Lagged correlation')
nm = "lagged_corr"
self.assertArraysEqual(genutil.statistics.laggedcorrelation(u,v,axis=0), f( nm+"_1"))
self.assertArraysEqual(genutil.statistics.laggedcorrelation(u,v,axis=0,lag=4), f( nm+"_2"))
self.assertArraysEqual(genutil.statistics.laggedcorrelation(u,v,axis=0,lag=4,noloop=1), f( nm+"_3"))
self.assertArraysEqual(genutil.statistics.laggedcorrelation(u,v,axis=0,lag=[4,8,10]), f(nm+"_4"))
self.assertArraysEqual(genutil.statistics.laggedcorrelation(u,v,axis=0), nm+"_1")
self.assertArraysEqual(genutil.statistics.laggedcorrelation(u,v,axis=0,lag=4), nm+"_2")
self.assertArraysEqual(genutil.statistics.laggedcorrelation(u,v,axis=0,lag=4,noloop=1), nm+"_3")
self.assertArraysEqual(genutil.statistics.laggedcorrelation(u,v,axis=0,lag=[4,8,10]), nm+"_4")


print('Lagged covariance')
nm = "lagged_cov"
self.assertArraysEqual(genutil.statistics.laggedcovariance(u,v,axis=0), f(nm+"_1"))
self.assertArraysEqual(genutil.statistics.laggedcovariance(u,v,axis=0,lag=4), f(nm+"_2"))
self.assertArraysEqual(genutil.statistics.laggedcovariance(u,v,axis=0,lag=4,noloop=1), f(nm+"_3"))
self.assertArraysEqual(genutil.statistics.laggedcovariance(u,v,axis=0,lag=[4,8,10]), f(nm+"_4"))
self.assertArraysEqual(genutil.statistics.laggedcovariance(u,v,axis=0), nm+"_1")
self.assertArraysEqual(genutil.statistics.laggedcovariance(u,v,axis=0,lag=4), nm+"_2")
self.assertArraysEqual(genutil.statistics.laggedcovariance(u,v,axis=0,lag=4,noloop=1), nm+"_3")
self.assertArraysEqual(genutil.statistics.laggedcovariance(u,v,axis=0,lag=[4,8,10]), nm+"_4")

print('Auto correlation')
nm = "auto_corr"
self.assertArraysEqual(genutil.statistics.autocorrelation(u,axis=0), f(nm+"_1"))
self.assertArraysEqual(genutil.statistics.autocorrelation(u,axis=0,lag=4), f(nm+"_2"))
self.assertArraysEqual(genutil.statistics.autocorrelation(u,axis=0,lag=4,noloop=1), f(nm+"_3"))
self.assertArraysEqual(genutil.statistics.autocorrelation(u,axis=0,lag=[4,8,10]), f(nm+"_4"))
self.assertArraysEqual(genutil.statistics.autocorrelation(u,axis=0), nm+"_1")
self.assertArraysEqual(genutil.statistics.autocorrelation(u,axis=0,lag=4), nm+"_2")
self.assertArraysEqual(genutil.statistics.autocorrelation(u,axis=0,lag=4,noloop=1), nm+"_3")
self.assertArraysEqual(genutil.statistics.autocorrelation(u,axis=0,lag=[4,8,10]), nm+"_4")

print('Auto covariance')
nm = "auto_cov"
self.assertArraysEqual(genutil.statistics.autocovariance(u,axis=0), f(nm+"_1"))
self.assertArraysEqual(genutil.statistics.autocovariance(u,axis=0,lag=4), f(nm+"_2"))
self.assertArraysEqual(genutil.statistics.autocovariance(u,axis=0,lag=4,noloop=1), f(nm+"_3"))
self.assertArraysEqual(genutil.statistics.autocovariance(u,axis=0,lag=[4,8,10]), f(nm+"_4"))
self.assertArraysEqual(genutil.statistics.autocovariance(u,axis=0), nm+"_1")
self.assertArraysEqual(genutil.statistics.autocovariance(u,axis=0,lag=4), nm+"_2")
self.assertArraysEqual(genutil.statistics.autocovariance(u,axis=0,lag=4,noloop=1), nm+"_3")
self.assertArraysEqual(genutil.statistics.autocovariance(u,axis=0,lag=[4,8,10]), nm+"_4")
f.close()

0 comments on commit 6e9a541

Please sign in to comment.