def test_niml(self): d = dict( data=np.random.normal(size=(10, 2)), node_indices=np.arange(10), stats=["none", "Tstat(2)"], labels=["foo", "bar"], ) a = niml.from_niml(d) b = niml.to_niml(a) _, fn = tempfile.mkstemp(".niml.dset", "dset") afni_niml_dset.write(fn, b) bb = afni_niml_dset.read(fn) cc = niml.from_niml(bb) os.remove(fn) for dset in (a, cc): assert_equal(list(dset.sa["labels"]), d["labels"]) assert_equal(list(dset.sa["stats"]), d["stats"]) assert_array_equal(np.asarray(dset.fa["node_indices"]).ravel(), d["node_indices"]) eps_dec = 4 assert_array_almost_equal(dset.samples, d["data"].transpose(), eps_dec) # some more tests to ensure that the order of elements is ok # (row first or column first) d = np.arange(10).reshape((5, -1)) + 0.5 ds = Dataset(d) fn = _, fn = tempfile.mkstemp(".niml.dset", "dset") writers = [niml.write, afni_niml_dset.write] for i, writer in enumerate(writers): for form in ("text", "binary", "base64"): if i == 0: writer(fn, ds, form=form) else: writer(fn, dict(data=d.transpose()), form=form) x = afni_niml_dset.read(fn) assert_array_equal(x["data"], d.transpose())
def test_niml(self, fn): d = dict(data=np.random.normal(size=(10, 2)), node_indices=np.arange(10), stats=['none', 'Tstat(2)'], labels=['foo', 'bar']) a = niml.from_niml(d) b = niml.to_niml(a) afni_niml_dset.write(fn, b) readers = (niml.from_any, lambda x: niml.from_niml(afni_niml_dset.read(x))) for reader in readers: cc = reader(fn) for dset in (a, cc): assert_equal(list(dset.sa['labels']), d['labels']) assert_equal(list(dset.sa['stats']), d['stats']) assert_array_equal( np.asarray(dset.fa['node_indices']).ravel(), d['node_indices']) eps_dec = 4 assert_array_almost_equal(dset.samples, d['data'].transpose(), eps_dec) # some more tests to ensure that the order of elements is ok # (row first or column first) d = np.arange(10).reshape((5, -1)) + .5 ds = Dataset(d) writers = [niml.write, afni_niml_dset.write] for i, writer in enumerate(writers): for form in ('text', 'binary', 'base64'): if i == 0: writer(fn, ds, form=form) else: writer(fn, dict(data=d.transpose()), form=form) x = afni_niml_dset.read(fn) assert_array_equal(x['data'], d.transpose())
def test_niml(self, fn): d = dict(data=np.random.normal(size=(10, 2)), node_indices=np.arange(10), stats=['none', 'Tstat(2)'], labels=['foo', 'bar']) a = niml.from_niml(d) b = niml.to_niml(a) afni_niml_dset.write(fn, b) readers = (niml.from_any, lambda x: niml.from_niml(afni_niml_dset.read(x))) for reader in readers: cc = reader(fn) for dset in (a, cc): assert_equal(list(dset.sa['labels']), d['labels']) assert_equal(list(dset.sa['stats']), d['stats']) assert_array_equal(np.asarray(dset.fa['node_indices']).ravel(), d['node_indices']) eps_dec = 4 assert_array_almost_equal(dset.samples, d['data'].transpose(), eps_dec) # some more tests to ensure that the order of elements is ok # (row first or column first) d = np.arange(10).reshape((5, -1)) + .5 ds = Dataset(d) writers = [niml.write, afni_niml_dset.write] for i, writer in enumerate(writers): for form in ('text', 'binary', 'base64'): if i == 0: writer(fn, ds, form=form) else: writer(fn, dict(data=d.transpose()), form=form) x = afni_niml_dset.read(fn) assert_array_equal(x['data'], d.transpose())