當前位置: 首頁>>代碼示例>>Python>>正文


Python h5py.Reference方法代碼示例

本文整理匯總了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__ 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:18,代碼來源:test_group.py

示例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) 
開發者ID:theislab,項目名稱:anndata,代碼行數:26,代碼來源:h5ad.py

示例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) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:16,代碼來源:test_group.py

示例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()) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:13,代碼來源:test_h5t.py

示例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) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:7,代碼來源:test_slicing.py

示例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 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:12,代碼來源:test_slicing.py

示例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 
開發者ID:PySimulator,項目名稱:PySimulator,代碼行數:46,代碼來源:pyMtsf.py


注:本文中的h5py.Reference方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。