本文整理汇总了Python中h5py.Datatype方法的典型用法代码示例。如果您正苦于以下问题:Python h5py.Datatype方法的具体用法?Python h5py.Datatype怎么用?Python h5py.Datatype使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类h5py
的用法示例。
在下文中一共展示了h5py.Datatype方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _write_odim
# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Datatype [as 别名]
def _write_odim(src, dest):
""" Writes Odim Attributes.
Parameters
----------
src : dict
Attributes to write
dest : handle
h5py-group handle
"""
for key, value in src.items():
if key in dest.attrs:
continue
if isinstance(value, str):
tid = h5py.h5t.C_S1.copy()
tid.set_size(len(value) + 1)
H5T_C_S1_NEW = h5py.Datatype(tid)
dest.attrs.create(key, value, dtype=H5T_C_S1_NEW)
else:
dest.attrs[key] = value
示例2: _fetchAllChildren
# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Datatype [as 别名]
def _fetchAllChildren(self):
""" Fetches all sub groups and variables that this group contains.
"""
assert self._h5Group is not None, "dataset undefined (file not opened?)"
assert self.canFetchChildren(), "canFetchChildren must be True"
childItems = []
for childName, h5Child in self._h5Group.items():
if isinstance(h5Child, h5py.Group):
childItems.append(H5pyGroupRti(h5Child, nodeName=childName,
fileName=self.fileName))
elif isinstance(h5Child, h5py.Dataset):
if len(h5Child.shape) == 0:
childItems.append(H5pyScalarRti(h5Child, nodeName=childName,
fileName=self.fileName))
else:
childItems.append(H5pyDatasetRti(h5Child, nodeName=childName,
fileName=self.fileName))
elif isinstance(h5Child, h5py.Datatype):
#logger.debug("Ignored DataType item: {}".format(childName))
pass
else:
logger.warn("Ignored {}. It has an unexpected HDF-5 type: {}"
.format(childName, type(h5Child)))
return childItems
示例3: write_dataframe_with_index_columns
# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Datatype [as 别名]
def write_dataframe_with_index_columns(path, df, values_dtype, datetime_func):
"""
保存dataframe列表,分成三部分保存,时间,列表头,数据
因为时间轴可能与默认的不一样,所以使用这种方法在一个文件中保存一张表
:param path:
:param df:
:param values_dtype:
:param columns_dtype:
:return:
"""
f = h5py.File(path, 'w')
f.create_dataset('values', data=df.as_matrix(), compression="gzip", compression_opts=6, dtype=values_dtype)
index = df.index.map(datetime_func)
f.create_dataset('index', data=index, compression="gzip", compression_opts=6, dtype=np.int64)
# # 只能存定长byte类型的,变长的会导致工具打开出错
columns = list(df.columns.map(lambda x: np.string_(x)))
# f.create_dataset('columns', data=columns, dtype=columns_dtype)
tid = h5py.h5t.C_S1.copy()
tid.set_size(32)
H5T_C_S1_32 = h5py.Datatype(tid)
f.create_dataset('columns', data=columns, compression="gzip", compression_opts=6, dtype=H5T_C_S1_32)
f.close()
return
示例4: _write_odim_dataspace
# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Datatype [as 别名]
def _write_odim_dataspace(src, dest):
""" Writes Odim Dataspaces.
Parameters
----------
src : dict
Moments to write
dest : handle
h5py-group handle
"""
keys = [key for key in src if key in ODIM_NAMES]
data_list = ["data{}".format(i + 1) for i in range(len(keys))]
data_idx = np.argsort(data_list)
for idx in data_idx:
value = src[keys[idx]]
h5_data = dest.create_group(data_list[idx])
enc = value.encoding
# p. 21 ff
h5_what = h5_data.create_group("what")
try:
undetect = float(value._Undetect)
except AttributeError:
undetect = np.finfo(np.float).max
what = {
"quantity": value.name,
"gain": float(enc["scale_factor"]),
"offset": float(enc["add_offset"]),
"nodata": float(enc["_FillValue"]),
"undetect": undetect,
}
_write_odim(what, h5_what)
# moments handling
val = value.sortby("azimuth").values
fillval = enc["_FillValue"] * enc["scale_factor"]
fillval += enc["add_offset"]
val[np.isnan(val)] = fillval
val = (val - enc["add_offset"]) / enc["scale_factor"]
val = np.rint(val).astype(enc["dtype"])
ds = h5_data.create_dataset(
"data",
data=val,
compression="gzip",
compression_opts=6,
fillvalue=enc["_FillValue"],
)
if enc["dtype"] == "uint8":
image = "IMAGE"
version = "1.2"
tid1 = h5py.h5t.C_S1.copy()
tid1.set_size(len(image) + 1)
H5T_C_S1_IMG = h5py.Datatype(tid1)
tid2 = h5py.h5t.C_S1.copy()
tid2.set_size(len(version) + 1)
H5T_C_S1_VER = h5py.Datatype(tid2)
ds.attrs.create("CLASS", image, dtype=H5T_C_S1_IMG)
ds.attrs.create("IMAGE_VERSION", version, dtype=H5T_C_S1_VER)