本文整理汇总了Python中h5py.Reference方法的典型用法代码示例。如果您正苦于以下问题:Python h5py.Reference方法的具体用法?Python h5py.Reference怎么用?Python h5py.Reference使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类h5py
的用法示例。
在下文中一共展示了h5py.Reference方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_invalid_ref
# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Reference [as 别名]
def test_invalid_ref(self):
""" Invalid region references should raise ValueError """
ref = h5py.h5r.Reference()
with self.assertRaises(ValueError):
self.f[ref]
self.f.create_group('x')
ref = self.f['x'].ref
del self.f['x']
with self.assertRaises(ValueError):
self.f[ref]
# TODO: check that regionrefs also work with __getitem__
示例2: read_series
# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Reference [as 别名]
def read_series(dataset) -> Union[np.ndarray, pd.Categorical]:
if "categories" in dataset.attrs:
categories = dataset.attrs["categories"]
if isinstance(categories, h5py.Reference):
categories_dset = dataset.parent[dataset.attrs["categories"]]
categories = categories_dset[...]
ordered = bool(categories_dset.attrs.get("ordered", False))
else:
# TODO: remove this code at some point post 0.7
# TODO: Add tests for this
warn(
f"Your file {str(dataset.file.name)!r} has invalid categorical "
"encodings due to being written from a development version of "
"AnnData. Rewrite the file ensure you can read it in the future.",
FutureWarning,
)
return pd.Categorical.from_codes(dataset[...], categories, ordered=ordered)
else:
return dataset[...]
# @report_read_key_on_error
# def read_sparse_dataset_backed(group: h5py.Group) -> sparse.spmatrix:
# return SparseDataset(group)
示例3: test_reference_numpyobj
# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Reference [as 别名]
def test_reference_numpyobj(self):
""" Object can be opened by numpy.object_ containing object ref
Test for issue 181, issue 202.
"""
g = self.f.create_group('test')
rtype = h5py.special_dtype(ref=h5py.Reference)
dt = np.dtype([('a', 'i'),('b',rtype)])
dset = self.f.create_dataset('test_dset', (1,), dt)
dset[0] =(42,g.ref)
data = dset[0]
self.assertEqual(self.f[data[1]], g)
示例4: test_ref
# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Reference [as 别名]
def test_ref(self):
""" Reference types are correctly stored in compound types (issue 144)
"""
ref = h5py.special_dtype(ref=h5py.Reference)
dt = np.dtype([('a', ref), ('b', '<f4')])
tid = h5t.py_create(dt, logical=True)
t1, t2 = tid.get_member_type(0), tid.get_member_type(1)
self.assertEqual(t1, h5t.STD_REF_OBJ)
self.assertEqual(t2, h5t.IEEE_F32LE)
self.assertEqual(tid.get_member_offset(0), 0)
self.assertEqual(tid.get_member_offset(1), h5t.STD_REF_OBJ.get_size())
示例5: test_reference
# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Reference [as 别名]
def test_reference(self):
""" Indexing a reference dataset returns a h5py.Reference instance """
dset = self.f.create_dataset('x', (1,), dtype=h5py.special_dtype(ref=h5py.Reference))
dset[0] = self.f.ref
self.assertEqual(type(dset[0]), h5py.Reference)
示例6: test_reference_field
# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Reference [as 别名]
def test_reference_field(self):
""" Compound types of which a reference is an element work right """
reftype = h5py.special_dtype(ref=h5py.Reference)
dt = np.dtype([('a', 'i'),('b',reftype)])
dset = self.f.create_dataset('x', (1,), dtype=dt)
dset[0] = (42, self.f['/'].ref)
out = dset[0]
self.assertEqual(type(out[1]), h5py.Reference) # isinstance does NOT work
示例7: WriteModelVariables
# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Reference [as 别名]
def WriteModelVariables(self):
scalarVariables = self.modelVariable
# Get maximum length of string vectors
#maxLenName = self._getMaxLength(scalarVariables.keys())
#maxLenDescription = self._getMaxLength([x.description for x in scalarVariables.values()])
# Create dtype object
numpyDataType = numpy.dtype({'names': ['name', 'simpleTypeRow',
'causality', 'variability',
'description', 'objectId', 'column', 'negated'],
'formats': [h5py.special_dtype(vlen=unicode),#'S' + str(max(maxLenName, 1)),
'uint32',
h5py.special_dtype(enum=(numpy.uint8, CausalityType)), # 'uint8',
h5py.special_dtype(enum=(numpy.uint8, VariabilityType)), # 'uint8',
h5py.special_dtype(vlen=unicode),#'S' + str(max(maxLenDescription, 1)),
h5py.special_dtype(ref=h5py.Reference),
'uint32',
h5py.special_dtype(enum=(numpy.uint8, {'false':0, 'true':1}))]}) # 'uint8']})
self.description = self.file.create_group("ModelDescription")
# Write information on Simulation group
description = self.modelDescription
self.description.attrs['modelName'] = description.modelName
self.description.attrs['description'] = description.description
self.description.attrs['author'] = description.author
self.description.attrs['version'] = description.version
self.description.attrs['generationTool'] = description.generationTool
self.description.attrs['generationDateAndTime'] = description.generationDateAndTime
self.description.attrs['variableNamingConvention'] = description.variableNamingConvention
dataset = self.description.create_dataset('Variables', (len(scalarVariables), 1), dtype=numpyDataType, maxshape=(len(scalarVariables), 1), compression='gzip')
# Sort Variables by names
nameList = [x for x in scalarVariables.keys()]
nameList.sort()
allData = []
i = -1
for variableName in nameList:
variable = scalarVariables[variableName]
i += 1
variable.rowIndex = i
x = variableName
allData.append((x, variable.simpleTypeRow,
variable.causality, variable.variability,
variable.description,
variable.category.dataset.ref, variable.columnIndex, variable.aliasNegated))
dataset[:, 0] = allData
return