11import os
2- import pickle
32import numpy as np
43
54from hapiclient import hapi
@@ -38,8 +37,8 @@ def equalNonFloats(a, b):
3837 allequal = True
3938 for name in a .dtype .names :
4039 if np .issubdtype (a [name ].dtype , np .integer ) or np .issubdtype (a [name ].dtype , np .flexible ):
41- # https://docs.scipy.org/doc/numpy-1.10.1/reference/arrays.scalars.html
4240 # Parameter type is string or integer
41+ # https://docs.scipy.org/doc/numpy-1.10.1/reference/arrays.scalars.html
4342 if not np .array_equal (a [name ], b [name ]):
4443 allequal = False
4544 if debug : print (name + ' values differ.' )
@@ -52,16 +51,19 @@ def closeFloats(a, b):
5251 allclose = True
5352 for name in a .dtype .names :
5453 if np .issubdtype (a [name ].dtype , np .inexact ):
55- # https://docs.scipy.org/doc/numpy-1.10.1/reference/arrays.scalars.html
5654 # Parameter is floating point number
57- if np .allclose (a [name ], b [name ], rtol = 1e-15 , atol = 0.0 , equal_nan = True ):
58- if not np .array_equal (a [name ], b [name ]):
59- if debug : print (name + ' values equal within rtol=1e-15.' )
55+ # See https://docs.scipy.org/doc/numpy-1.10.1/reference/arrays.scalars.html
56+ atol = np .finfo (a [name ].dtype .str ).eps
57+ if np .allclose (a [name ], b [name ], rtol = 0.0 , atol = atol , equal_nan = True ):
58+ if debug and not np .array_equal (a [name ], b [name ]):
59+ mdiff = np .max (np .abs (a [name ] - b [name ]))
60+ print ('All values in parameter ' + name \
61+ + ' equal within absolute tolerance ' \
62+ + 'of %.2e; max |diff| = %.2e' % (atol , mdiff ))
6063 else :
6164 allclose = False
62- if debug : print (name + ' values not equal within rtol=1e-15.' )
63- if debug : import pdb ; pdb .set_trace ()
64-
65+ print ('All values in parameter ' + name \
66+ + ' not equal within absolute tolerance of %.2e.' % atol )
6567
6668 return allclose
6769
@@ -70,6 +72,7 @@ def closeFloats(a, b):
7072logfile = os .path .realpath (__file__ )[0 :- 2 ] + "log"
7173with open (logfile , "w" ) as f : pass
7274
75+
7376def xprint (msg ):
7477 print (msg )
7578 f = open (logfile , "a" )
@@ -82,12 +85,12 @@ def readcompare(server, dataset, parameters, run, opts):
8285 # Note that for this dataset, there are differences in
8386 # the numeric values that seem not to be due to issues
8487 # with the reader. This needs investigation.
85-
88+
8689 dataset = 'dataset1'
8790 start = '1970-01-01'
8891
8992 allpass = True
90-
93+
9194 if run == 'short' :
9295 stop = '1970-01-01T00:00:03' # Returns 3 time values
9396
@@ -98,7 +101,7 @@ def readcompare(server, dataset, parameters, run, opts):
98101 stop = '1970-01-02T00:00:00' # Returns 86400 time values
99102
100103 # Checks that all four read methods give same result.
101- # Does not check that an individual read is correct.
104+ # Does not check that an individual read is correct.
102105 # Do this manually.
103106
104107 opts ['format' ] = 'csv'
@@ -114,66 +117,50 @@ def readcompare(server, dataset, parameters, run, opts):
114117 xprint ('Method total d/l->buff parse buff' )
115118 xprint ('___________________________________________________________' )
116119
117-
120+
118121 opts ['method' ] = 'numpynolength'
119122 data , meta = hapi (server , dataset , parameters , start , stop , ** opts )
120123 xprint ('csv; numpy; no len. %8.4f %8.4f %8.4f' % \
121124 (meta ['x_totalTime' ], meta ['x_downloadTime' ], meta ['x_readTime' ]))
122125 datalast = data
123126
124-
127+
125128 opts ['method' ] = 'pandasnolength'
126129 data , meta = hapi (server , dataset , parameters , start , stop , ** opts )
127130
128- diffs = ''
129- if np .array_equal (data , datalast ):
130- diffs = '(diffs in float values <= 1e-15)'
131-
132- xprint ('csv; pandas; no len. %8.4f %8.4f %8.4f %s' % \
133- (meta ['x_totalTime' ], meta ['x_downloadTime' ], meta ['x_readTime' ], diffs ))
131+ xprint ('csv; pandas; no len. %8.4f %8.4f %8.4f' % \
132+ (meta ['x_totalTime' ], meta ['x_downloadTime' ], meta ['x_readTime' ]))
134133
135134 allpass = comparisonOK (data , datalast )
136135 datalast = data
137136
138-
137+
139138 opts ['method' ] = 'numpy'
140139 data , meta = hapi (server , dataset , parameters , start , stop , ** opts )
141140
142- diffs = ''
143- if np .array_equal (data , datalast ):
144- diffs = '(diffs in float values <= 1e-15)'
145-
146- xprint ('csv; numpy %8.4f %8.4f %8.4f %s' % \
147- (meta ['x_totalTime' ], meta ['x_downloadTime' ], meta ['x_readTime' ], diffs ))
141+ xprint ('csv; numpy %8.4f %8.4f %8.4f' % \
142+ (meta ['x_totalTime' ], meta ['x_downloadTime' ], meta ['x_readTime' ]))
148143
149144 allpass = comparisonOK (data , datalast )
150145 datalast = data
151146
152-
147+
153148 opts ['method' ] = 'pandas'
154149 data , meta = hapi (server , dataset , parameters , start , stop , ** opts )
155150
156- diffs = ''
157- if np .array_equal (data , datalast ):
158- diffs = '(diffs in float values <= 1e-15)'
159-
160- xprint ('csv; pandas %8.4f %8.4f %8.4f %s' % \
161- (meta ['x_totalTime' ], meta ['x_downloadTime' ], meta ['x_readTime' ], diffs ))
151+ xprint ('csv; pandas %8.4f %8.4f %8.4f' % \
152+ (meta ['x_totalTime' ], meta ['x_downloadTime' ], meta ['x_readTime' ]))
162153
163154 allpass = comparisonOK (data , datalast )
164155 datalast = data
165-
156+
166157
167158 opts ['format' ] = 'binary'
168159 opts ['method' ] = '' # Ignored
169160 data , meta = hapi (server , dataset , parameters , start , stop , ** opts )
170161
171- diffs = ''
172- if np .array_equal (data , datalast ):
173- diffs = '(diffs in float values <= 1e-15)'
174-
175- xprint ('binary %8.4f %8.4f %8.4f %s' % \
176- (meta ['x_totalTime' ], meta ['x_downloadTime' ], meta ['x_readTime' ], diffs ))
162+ xprint ('binary %8.4f %8.4f %8.4f' % \
163+ (meta ['x_totalTime' ], meta ['x_downloadTime' ], meta ['x_readTime' ]))
177164
178165 allpass = comparisonOK (data , datalast )
179166
0 commit comments