Here are the examples of the python api numpy.testing.assert_array_equal taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
173 Examples
5
Example 1
Project: chainer Source File: test_link.py
def test_copyparams(self):
self.link.x.grad.fill(0)
self.link.y.grad.fill(1)
gx = self.link.x.grad.copy()
gy = self.link.y.grad.copy()
l = chainer.Link(x=(2, 3), y=2)
l.x.data.fill(2)
l.x.grad.fill(3)
l.y.data.fill(4)
l.y.grad.fill(5)
self.link.copyparams(l)
numpy.testing.assert_array_equal(self.link.x.data, l.x.data)
numpy.testing.assert_array_equal(self.link.x.grad, gx)
numpy.testing.assert_array_equal(self.link.y.data, l.y.data)
numpy.testing.assert_array_equal(self.link.y.grad, gy)
5
Example 2
Project: chainer Source File: test_link.py
def test_copyparams(self):
l1 = chainer.Link(x=(2, 3))
l2 = chainer.Link(x=2)
l3 = chainer.Link(x=3)
c1 = chainer.Chain(l1=l1, l2=l2)
c2 = chainer.Chain(c1=c1, l3=l3)
l1.x.data.fill(0)
l2.x.data.fill(1)
l3.x.data.fill(2)
self.c2.copyparams(c2)
numpy.testing.assert_array_equal(self.l1.x.data, l1.x.data)
numpy.testing.assert_array_equal(self.l2.x.data, l2.x.data)
numpy.testing.assert_array_equal(self.l3.x.data, l3.x.data)
5
Example 3
def test_zero_integration_distance(self):
filtered = self.source1.filter_sites_by_distance_to_source(
integration_distance=0, sites=self.sitecol
)
self.assertIsInstance(filtered, FilteredSiteCollection)
self.assertIsNot(filtered, self.sitecol)
numpy.testing.assert_array_equal(filtered.indices, [0])
numpy.testing.assert_array_equal(filtered.vs30, [0.1])
filtered = self.source2.filter_sites_by_distance_to_source(
integration_distance=0, sites=self.sitecol
)
numpy.testing.assert_array_equal(filtered.indices, [0, 1])
5
Example 4
Project: cupy Source File: test_convert.py
def check_concat_arrays_padding(self, xp):
arrays = [xp.random.rand(3, 4),
xp.random.rand(2, 5),
xp.random.rand(4, 3)]
array = dataset.concat_examples(arrays, padding=0)
self.assertEqual(array.shape, (3, 4, 5))
self.assertEqual(type(array), type(arrays[0]))
arrays = [cuda.to_cpu(a) for a in arrays]
array = cuda.to_cpu(array)
numpy.testing.assert_array_equal(array[0, :3, :4], arrays[0])
numpy.testing.assert_array_equal(array[0, 3:, :], 0)
numpy.testing.assert_array_equal(array[0, :, 4:], 0)
numpy.testing.assert_array_equal(array[1, :2, :5], arrays[1])
numpy.testing.assert_array_equal(array[1, 2:, :], 0)
numpy.testing.assert_array_equal(array[2, :4, :3], arrays[2])
numpy.testing.assert_array_equal(array[2, :, 3:], 0)
5
Example 5
Project: chainer Source File: test_link.py
def test_copyparams(self):
l1 = chainer.Link(x=(2, 3))
l2 = chainer.Link(x=2)
l3 = chainer.Link(x=3)
c1 = chainer.ChainList(l1, l2)
c2 = chainer.ChainList(c1, l3)
l1.x.data.fill(0)
l2.x.data.fill(1)
l3.x.data.fill(2)
self.c2.copyparams(c2)
numpy.testing.assert_array_equal(self.l1.x.data, l1.x.data)
numpy.testing.assert_array_equal(self.l2.x.data, l2.x.data)
numpy.testing.assert_array_equal(self.l3.x.data, l3.x.data)
3
Example 6
Project: deepchem Source File: test_datasets.py
def test_itersamples_disk(self):
"""Test that iterating over samples in a DiskDataset works."""
solubility_dataset = dc.data.tests.load_solubility_data()
X = solubility_dataset.X
y = solubility_dataset.y
w = solubility_dataset.w
ids = solubility_dataset.ids
for i, (sx, sy, sw, sid) in enumerate(solubility_dataset.itersamples()):
np.testing.assert_array_equal(sx, X[i])
np.testing.assert_array_equal(sy, y[i])
np.testing.assert_array_equal(sw, w[i])
np.testing.assert_array_equal(sid, ids[i])
3
Example 7
Project: bdot Source File: test_carray.py
def test_dot_matrix_int32():
matrix = np.random.random_integers(0, 120, size=(1000, 100)).astype('int32')
bcarray1 = bdot.carray(matrix, chunklen=2**9, cparams=bdot.cparams(clevel=2))
bcarray2 = bdot.carray(matrix, chunklen=2**9, cparams=bdot.cparams(clevel=2))
result = bcarray1.dot(bcarray2)
expected = matrix.dot(matrix.T)
assert_array_equal(expected, result)
3
Example 8
Project: chaco Source File: test_lttb.py
def test_negative_buckets(self):
a = np.zeros(shape=(10,2))
n_buckets = -10
result = largest_triangle_three_buckets(a, n_buckets)
assert_array_equal(result, a)
3
Example 9
Project: deepTools Source File: test_countReadsPerBin.py
def test_get_coverage_of_region_large_bin(self):
self.c.bamFilesList = [self.bamFile2]
self.c.binLength = 200
self.c.stepSize = 200
resp, _ = self.c.count_reads_in_region('3R', 0, 200)
nt.assert_array_equal(resp, np.array([[4]]))
3
Example 10
Project: gensim Source File: test_similarities.py
def testMaintainSparsity(self):
"""Sparsity is correctly maintained when maintain_sparsity=True"""
num_features = len(dictionary)
index = self.cls(corpus, num_features=num_features)
dense_sims = index[corpus]
index = self.cls(corpus, num_features=num_features, maintain_sparsity=True)
sparse_sims = index[corpus]
self.assertFalse(scipy.sparse.issparse(dense_sims))
self.assertTrue(scipy.sparse.issparse(sparse_sims))
numpy.testing.assert_array_equal(dense_sims, sparse_sims.todense())
3
Example 11
Project: urbansim Source File: test_dcm.py
def test_unit_choice_not_enough(choosers, alternatives):
probabilities = [0, 0, 0, 0, 0, 1, 0, 1, 0, 0]
choices = dcm.unit_choice(
choosers.index, alternatives.index, probabilities)
npt.assert_array_equal(choices.index, choosers.index)
assert choices.isnull().sum() == 3
npt.assert_array_equal(sorted(choices[~choices.isnull()]), ['f', 'h'])
3
Example 12
def testUpdate(self):
particles = self.model.create_initial_estimate(1)
nextp = self.model.update(numpy.copy(particles), None, None, None)
(zl, Pl) = self.model.get_states(particles)
(nzl, nPl) = self.model.get_states(nextp)
npt.assert_array_equal(numpy.asarray(nzl), self.A * numpy.asarray(zl) + self.f)
npt.assert_array_equal(numpy.asarray(nPl), (self.A ** 2) * numpy.asarray(Pl) + self.Q)
3
Example 13
Project: brut Source File: test_cascade.py
def check_staged_decision(self, clf, x, y):
for i, yp in enumerate(clf.staged_decision_function(x)):
good = yp > 0
#df for positive examples == df for last stage
expect = clf.estimators_[i].decision_function(x[
good]) - clf.bias_[i]
np.testing.assert_array_equal(yp[good].ravel(), expect.ravel())
if len(clf.estimators_) > 0:
np.testing.assert_array_equal(clf.decision_function(x), yp)
3
Example 14
Project: word2gauss Source File: test_embeddings.py
def test_phrases_to_vector3(self):
self.embed = sample_embed(energy_type='IP', covariance_type='spherical')
vocab = sample_vocab()
target = [["new"], [""]]
res = np.array([0. , 0])
vec = self.embed.phrases_to_vector(target, vocab=vocab)
test.assert_array_equal(vec, res)
3
Example 15
Project: yellowbrick Source File: test_rcmod.py
def assert_rc_params(self, params):
for k, v in params.items():
if k in self.excluded_params:
continue
elif isinstance(v, np.ndarray):
npt.assert_array_equal(mpl.rcParams[k], v)
else:
self.assertEqual((k, mpl.rcParams[k]), (k, v))
3
Example 16
Project: QuantEcon.py Source File: test_core.py
def test_simulate_dense_vs_sparse():
n = 5
a = 1/3
b = (1 - a)/2
P = np.zeros((n, n))
for i in range(n):
P[i, (i-1) % n], P[i, i], P[i, (i+1) % n] = b, a, b
mcs = [MarkovChain(P), MarkovChain(sparse.csr_matrix(P))]
ts_length = 10
inits = (None, 0, [0, 1])
num_repss = (None, 2)
random_state = 0
for init, num_reps in itertools.product(inits, num_repss):
assert_array_equal(*(mc.simulate(ts_length, init, num_reps,
random_state=random_state)
for mc in mcs))
3
Example 17
Project: scimath Source File: unit_array_test_case.py
def test_subtract_dimensionless(self):
a = UnitArray([1,2,3], units=dimensionless)
b = 1
result = a - b
self.assertEqual(result.units, dimensionless)
assert_array_equal(result, UnitArray([0,1,2], units=dimensionless))
result = b - a
self.assertEqual(result.units, dimensionless)
assert_array_equal(result, UnitArray([0,-1,-2], units=dimensionless))
c = array([3,2,1])
result = a - c
self.assertEqual(result.units, dimensionless)
assert_array_equal(result, UnitArray([-2,0,2], units=dimensionless))
result = c - a
self.assertEqual(result.units, dimensionless)
assert_array_equal(result, UnitArray([2,0,-2], units=dimensionless))
3
Example 18
def test_store_data(self):
"""
Test data storage into file
"""
self.data_type.store_data(self.data_name, self.test_2D_array)
read_data = self.data_type.get_data(self.data_name)
numpy.testing.assert_array_equal(self.test_2D_array, read_data, "Did not get the expected data")
3
Example 19
Project: prettytensor Source File: functions_test.py
def test_every_other(self):
tensor = tf.constant([[1, 2], [3, 4]])
out = self.eval_tensor(functions.every_other(tensor))
testing.assert_array_equal(out[0], numpy.array([1, 3], dtype=numpy.int32))
tensor = tf.constant([[1, 2, 3, 4]])
out = self.eval_tensor(functions.every_other(tensor))
testing.assert_array_equal(out[0], numpy.array([1, 3], dtype=numpy.int32))
3
Example 20
Project: molecular-design-toolkit Source File: test_atom_containers.py
@pytest.mark.parametrize('fixturename', registered_types['container'])
def test_container_properties(fixturename, request):
obj = request.getfuncargvalue(fixturename)
assert obj.mass == sum([atom.mass for atom in obj.atoms])
np.testing.assert_array_equal(obj.positions.defunits(),
u.array([atom.position for atom in obj.atoms]).defunits())
assert obj.num_atoms == len(obj.atoms)
3
Example 21
Project: edm2016 Source File: test_node.py
def test_get_data_by_id(self):
dim, data, cpd, ids = self.gen_data()
node = undertest.Node(name='test node', data=data, cpd=cpd, ids=ids)
# test setting of ids
np.testing.assert_array_equal(node.ids, ids)
# test for one id
idx = np.random.randint(0, dim)
np.testing.assert_array_equal(node.get_data_by_id(ids[idx]).ravel(), node.data[idx])
# test for a random set of ids
ids_subset = np.random.choice(ids, dim, replace=True)
np.testing.assert_array_equal(node.get_data_by_id(ids_subset),
[node.data[np.flatnonzero(ids == x)[0]] for x in ids_subset])
# test for all ids
self.assertEqual(node.get_all_data_and_ids(), {x: node.get_data_by_id(x) for x in ids})
# test when data are singleton
dim, _, cpd, ids = self.gen_data(dim=1)
node = undertest.Node(name='test node', data=1, cpd=cpd, ids=ids)
self.assertEqual(node.get_all_data_and_ids(), {x: node.get_data_by_id(x) for x in ids})
3
Example 22
def test_addition(self):
m = 3
x = GF(arange(2**m), m)
y = GF(array([6, 4, 3, 1, 2, 0, 5, 7]), m)
z = GF(array([6, 5, 1, 2, 6, 5, 3, 0]), m)
assert_array_equal((x+y).elements, z.elements)
3
Example 23
Project: seqlearn Source File: test_datasets.py
def test_load_conll():
n_nonempty = sum(1 for ln in TEST_FILE.splitlines() if ln.strip())
X, y, lengths = load_conll(six.moves.StringIO(TEST_FILE), features)
assert_true(sp.isspmatrix(X))
assert_equal(X.shape[0], n_nonempty)
assert_equal(list(y),
["Det", "N", "V", "Pre", "Det", "N", "Punc",
"Adv", "Punc"])
assert_array_equal(lengths, [7, 2])
3
Example 24
Project: tracer Source File: test_tower.py
def test_secure_position(self):
"""Heliostats at default position absorb the sunlight"""
e = TracerEngine(self.field)
e.ray_tracer(self.rays, 1, 0.05)
N.testing.assert_array_equal(e.tree[-1].get_energy(), 0)
3
Example 25
Project: numexpr Source File: test_numexpr.py
def test_uint32_constant_promotion(self):
int32array = arange(100, dtype='int32')
stwo = np.int32(2)
utwo = np.uint32(2)
res = int32array * utwo
res32 = evaluate('int32array * stwo')
res64 = evaluate('int32array * utwo')
assert_array_equal(res, res32)
assert_array_equal(res, res64)
self.assertEqual(res32.dtype.name, 'int32')
self.assertEqual(res64.dtype.name, 'int64')
3
Example 26
def test():
arr = np.array([1,2,2,2], dtype=np.int32)
adder = gpuadder.GPUAdder(arr)
adder.increment()
adder.retreive_inplace()
results2 = adder.retreive()
npt.assert_array_equal(arr, [2,3,3,3])
npt.assert_array_equal(results2, [2,3,3,3])
3
Example 27
Project: xlwings Source File: udf_tests.py
def nparray_equal(a, b):
try:
assert_array_equal(a, b)
except AssertionError:
return False
return True
3
Example 28
Project: APGL Source File: UtilTest.py
def testCumMin(self):
v = numpy.array([5, 6, 4, 5, 1])
u = Util.cuemMin(v)
nptst.assert_array_equal(u, numpy.array([5, 5, 4, 4, 1]))
v = numpy.array([5, 4, 3, 2, 1])
u = Util.cuemMin(v)
nptst.assert_array_equal(u, v)
v = numpy.array([1, 2, 3])
u = Util.cuemMin(v)
nptst.assert_array_equal(u, numpy.ones(3))
3
Example 29
Project: iris Source File: test_coord_api.py
def _check_shared_data(self, coord):
# Updating the original coord's points should update the sliced
# coord's points too.
points = coord.points
new_points = coord[:].points
np.testing.assert_array_equal(points, new_points)
points[0, 0] = 999
self.assertEqual(points[0, 0], new_points[0, 0])
3
Example 30
Project: datajoint-python Source File: test_fetch.py
def test_getitem(self):
"""Testing Fetch.__getitem__"""
list1 = sorted(self.subject.proj().fetch.as_dict(), key=itemgetter('subject_id'))
list2 = sorted(self.subject.fetch[dj.key], key=itemgetter('subject_id'))
for l1, l2 in zip(list1, list2):
assert_dict_equal(l1, l2, 'Primary key is not returned correctly')
tmp = self.subject.fetch(order_by=['subject_id'])
subject_notes, key, real_id = self.subject.fetch['subject_notes', dj.key, 'real_id']
np.testing.assert_array_equal(sorted(subject_notes), sorted(tmp['subject_notes']))
np.testing.assert_array_equal(sorted(real_id), sorted(tmp['real_id']))
list1 = sorted(key, key=itemgetter('subject_id'))
for l1, l2 in zip(list1, list2):
assert_dict_equal(l1, l2, 'Primary key is not returned correctly')
3
Example 31
Project: python-control Source File: xferfcn_test.py
def testMulSISO(self):
"""Multiply two SISO systems."""
sys1 = TransferFunction([1., 3., 5], [1., 6., 2., -1])
sys2 = TransferFunction([[[-1., 3.]]], [[[1., 0., -1.]]])
sys3 = sys1 * sys2
sys4 = sys2 * sys1
np.testing.assert_array_equal(sys3.num, [[[-1., 0., 4., 15.]]])
np.testing.assert_array_equal(sys3.den, [[[1., 6., 1., -7., -2., 1.]]])
np.testing.assert_array_equal(sys3.num, sys4.num)
np.testing.assert_array_equal(sys3.den, sys4.den)
3
Example 32
Project: astrodendro Source File: test_io.py
@pytest.mark.parametrize('ext', ('fits', 'hdf5'))
def test_reload_retains_dendro_reference(self, ext):
# regression test for issue 106
d1 = Dendrogram.compute(self.data, verbose=False)
self.test_filename = 'astrodendro-test.%s' % ext
d1.save_to(self.test_filename)
d2 = Dendrogram.load_from(self.test_filename)
for s in d1:
np.testing.assert_array_equal(d2[s.idx].get_mask(subtree=True),
d1[s.idx].get_mask(subtree=True))
3
Example 33
Project: GPy Source File: kernel_tests.py
def test_active_dims(self):
np.testing.assert_array_equal(self.sumkern.active_dims, [0,1,2,3,7,9])
np.testing.assert_array_equal(self.sumkern._all_dims_active, range(10))
tmp = self.linear+self.rbf
np.testing.assert_array_equal(tmp.active_dims, [0,2,3,9])
np.testing.assert_array_equal(tmp._all_dims_active, range(10))
tmp = self.matern+self.rbf
np.testing.assert_array_equal(tmp.active_dims, [0,1,2,7,9])
np.testing.assert_array_equal(tmp._all_dims_active, range(10))
tmp = self.matern+self.rbf*self.linear
np.testing.assert_array_equal(tmp.active_dims, [0,1,2,3,7,9])
np.testing.assert_array_equal(tmp._all_dims_active, range(10))
tmp = self.matern+self.rbf+self.linear
np.testing.assert_array_equal(tmp.active_dims, [0,1,2,3,7,9])
np.testing.assert_array_equal(tmp._all_dims_active, range(10))
tmp = self.matern*self.rbf*self.linear
np.testing.assert_array_equal(tmp.active_dims, [0,1,2,3,7,9])
np.testing.assert_array_equal(tmp._all_dims_active, range(10))
3
Example 34
Project: blockcanvas Source File: numeric_context_test_case.py
def test_run_block_twice(self):
""" Make sure we don't die if we get run twice """
input = arange(-31.416, 31.416, 0.01)
desired_output = sin(input)
code = "from numpy import sin, ones \n"
code += "from geo.somewhere import interpolate_mask \n"
code += "trash = interpolate_mask(input, input > 2.1) \n"
code += "output=sin(input) \n"
block = Block(code)
context = NumericContext()
context['input'] = input
block.execute(context)
assert_array_equal(context['output'], desired_output)
block.execute(context)
assert_array_equal(context['output'], desired_output)
3
Example 35
Project: distarray Source File: test_distarray.py
def test_set_numpy_array_full_slice_with_distarray(self):
distribution = Distribution(self.context, (7, 9))
darr = self.context.ones(distribution)
nparr = numpy.zeros_like(darr)
nparr[...] = darr
assert_array_equal(nparr, darr.toarray())
3
Example 36
Project: TensorVision Source File: test_utils.py
def test_load_segmentation_mask():
"""Test load_segmentation_mask."""
from tensorvision.utils import load_segmentation_mask
import json
import scipy.misc
import numpy
import os
hypes_path = os.path.abspath('tensorvision/tests/croco.json')
seg_image = os.path.abspath('tensorvision/tests/croco-mask.png')
with open(hypes_path) as f:
hypes = json.load(f)
gt = load_segmentation_mask(hypes, seg_image)
# scipy.misc.imsave("tensorvision/tests/test-generated-mask.png", gt)
seg_image = 'tensorvision/tests/Crocodylus-johnsoni-3-mask.png'
true_gt = (scipy.misc.imread(seg_image) / 255.).astype(int)
numpy.testing.assert_array_equal(true_gt, gt)
assert gt.shape == (480, 640)
3
Example 37
Project: glymur Source File: test_opj_suite.py
@unittest.skipIf(re.match(r'''0|1|2.0.0''',
glymur.version.openjpeg_version) is not None,
"Only supported in 2.0.1 or higher")
def test_NR_DEC_p1_04_j2k_58_decode_0p7_backwards_compatibility(self):
"""
Test ability to read specified tiles. Requires 2.0.1 or higher.
0.7.x read usage deprecated, should use slicing
"""
jfile = opj_data_file('input/conformance/p1_04.j2k')
jp2k = Jp2k(jfile)
with warnings.catch_warnings():
warnings.simplefilter('ignore')
tdata = jp2k.read(tile=63, rlevel=2) # last tile
odata = jp2k[::4, ::4]
np.testing.assert_array_equal(tdata, odata[224:256, 224:256])
3
Example 38
def test_field_access(db, ctx):
for field in db.t.fields:
expr = getattr(db.t, field)
result = into(pd.Series, compute(expr, ctx, return_type='native'))
expected = compute(expr, {db: {'t': df}}, return_type='native')
assert result.name == expected.name
np.testing.assert_array_equal(result.values,
expected.values)
3
Example 39
def test_distance(self):
expected = Series(np.array([
np.sqrt((5 - 1)**2 + (5 - 1)**2),
np.nan]),
self.na_none.index)
assert_array_equal(expected, self.na_none.distance(self.p0))
expected = Series(np.array([np.sqrt(4**2 + 4**2), np.nan]),
self.g6.index)
assert_array_equal(expected, self.g6.distance(self.na_none))
3
Example 40
def test_offset(data):
sk = skim.Skim(data, offset=-1)
orig = [6, 10, 2]
dest = [3, 10, 7]
npt.assert_array_equal(
sk.get(orig, dest),
[52, 99, 16])
3
Example 41
Project: patsylearn Source File: test_patsy_model.py
def test_intercept_transformer():
data = patsy.demo_data("x1", "x2", "x3", "y")
# check wether X contains only the two features, no intercept
est = PatsyTransformer("x1 + x2")
est.fit(data)
assert_equal(est.transform(data).shape[1], 2)
# check wether X does contain intercept
est = PatsyTransformer("x1 + x2", add_intercept=True)
est.fit(data)
data_transformed = est.transform(data)
assert_array_equal(data_transformed[:, 0], 1)
assert_equal(est.transform(data).shape[1], 3)
3
Example 42
Project: spykeutils Source File: test_scipy_quantities.py
def test_works_with_quantity_arrays(self):
a = sp.array([[1]]) * pq.s
b = sp.array([[2000]]) * pq.ms
c = sp.array([[3]]) * pq.s
axis = 1
expected = sp.array([[1, 2, 3]]) * pq.s
actual = spq.concatenate((a, b, c), axis=axis)
assert_array_equal(expected, actual)
3
Example 43
Project: lifelines Source File: test_estimation.py
def test_custom_timeline_can_be_list_or_array(self, positive_sample_lifetimes, univariate_fitters):
T, C = positive_sample_lifetimes
timeline = [2, 3, 4., 1., 6, 5.]
for f in univariate_fitters:
fitter = f()
fitter.fit(T, C, timeline=timeline)
if hasattr(fitter, 'survival_function_'):
with_list = fitter.survival_function_.values
with_array = fitter.fit(T, C, timeline=np.array(timeline)).survival_function_.values
npt.assert_array_equal(with_list, with_array)
elif hasattr(fitter, 'cuemulative_hazard_'):
with_list = fitter.cuemulative_hazard_.values
with_array = fitter.fit(T, C, timeline=np.array(timeline)).cuemulative_hazard_.values
npt.assert_array_equal(with_list, with_array)
3
Example 44
Project: regreg Source File: test_affine.py
def test_composition():
X1 = np.random.standard_normal((20,30))
X2 = np.random.standard_normal((30,10))
b1 = np.random.standard_normal(20)
b2 = np.random.standard_normal(30)
L1 = affine_transform(X1, b1)
L2 = affine_transform(X2, b2)
z = np.random.standard_normal(10)
w = np.random.standard_normal(20)
comp = composition(L1,L2)
assert_array_equal(comp.linear_map(z), np.dot(X1, np.dot(X2, z)))
assert_array_equal(comp.adjoint_map(w), np.dot(X2.T, np.dot(X1.T, w)))
assert_array_equal(comp.affine_map(z), np.dot(X1, np.dot(X2, z)+b2)+b1)
3
Example 45
Project: siphon Source File: test_dataset.py
@recorder.use_cassette('nc4_compound_ref')
def test_struct():
"Test reading a structured variable"
ds = Dataset('http://localhost:8080/thredds/cdmremote/nc4/compound/ref_tst_compounds.nc4')
var = ds.variables['obs'][:]
assert var.shape == (3,)
assert var.dtype == np.dtype([('day', 'b'), ('elev', '<i2'), ('count', '<i4'),
('relhum', '<f4'), ('time', '<f8')])
assert_array_equal(var['day'], np.array([15, -99, 20]))
assert_array_equal(var['elev'], np.array([2, -99, 6]))
assert_array_equal(var['count'], np.array([1, -99, 3]))
assert_array_almost_equal(var['relhum'], np.array([0.5, -99.0, 0.75]))
assert_array_almost_equal(var['time'],
np.array([3600.01, -99.0, 5000.01], dtype=np.double))
3
Example 46
def test_binary():
y_targ = [1, 1, 1, 0, 0, 2, 0, 3]
y_pred = [1, 0, 1, 0, 0, 2, 1, 3]
x = np.array([[4, 1],
[1, 2]])
y = confusion_matrix(y_targ, y_pred, binary=True, positive_label=1)
assert_array_equal(x, y)
3
Example 47
Project: yatsm Source File: test_postprocess.py
def test_commission_nochange(sim_nochange):
""" In no change situation, we should get back exactly what we gave in
"""
record = commission_test(sim_nochange, 0.10)
assert len(record) == 1
np.testing.assert_array_equal(record, sim_nochange.record)
3
Example 48
Project: python-acoustics Source File: test_criterion.py
@pytest.mark.parametrize("nc, expected", [
(15, np.array([47, 36, 29, 22, 17, 14, 12, 11])),
(20, np.array([51, 40, 33, 26, 22, 19, 17, 16])),
(25, np.array([54, 44, 37, 31, 27, 24, 22, 21])),
(30, np.array([57, 48, 41, 35, 31, 29, 28, 27])),
(35, np.array([60, 52, 45, 40, 36, 34, 33, 32])),
(40, np.array([64, 56, 50, 45, 41, 39, 38, 37])),
(45, np.array([67, 60, 54, 49, 46, 44, 43, 42])),
(50, np.array([71, 64, 58, 54, 51, 49, 48, 47])),
(55, np.array([74, 67, 62, 58, 56, 54, 53, 52])),
(60, np.array([77, 71, 67, 63, 61, 59, 58, 57])),
(65, np.array([80, 75, 71, 68, 66, 64, 63, 62])),
(70, np.array([83, 79, 75, 72, 71, 70, 69, 68])),
(11, None),
(79, None),
])
def test_nc_curve(nc, expected):
curve = nc_curve(nc)
assert_array_equal(curve, expected)
3
Example 49
Project: cartopy Source File: test_img_nest.py
@requires_wmts_data
def test_find_images():
z2_dir = os.path.join(_TEST_DATA_DIR, 'z_2')
img_fname = os.path.join(z2_dir, 'x_2_y_0.png')
world_file_fname = os.path.join(z2_dir, 'x_2_y_0.pgw')
img = RoundedImg.from_world_file(img_fname, world_file_fname)
assert_equal(img.filename, img_fname)
assert_array_almost_equal(img.extent,
(0., 10018754.17139462,
10018754.17139462, 20037508.342789244),
decimal=4)
assert_equal(img.origin, 'lower')
assert_array_equal(img, np.array(Image.open(img.filename)))
assert_equal(img.pixel_size, (39135.7585, 39135.7585))
3
Example 50
Project: cesium Source File: test_data_management.py
def test_parse_headerfile():
"""Test header file parsing."""
targets, metadata = data_management.parse_headerfile(
pjoin(DATA_PATH, "asas_training_subset_classes_with_metadata.dat"))
npt.assert_array_equal(metadata.keys(), ["meta1", "meta2", "meta3"])
npt.assert_equal(targets.loc["217801"], "Mira")
npt.assert_almost_equal(metadata.loc["224635"].meta1, 0.330610932539)