本文整理匯總了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)