Skip to main content

imutum's packages for HDF

Project description

mtmhdf

mtmhdf 是一个用于读取 HDF4 和 HDF5 (包括 NetCDF) 文件的 Python 库。它提供了清晰的接口来处理不同格式的 HDF 文件,并支持自动的数值缩放(Scale)和偏移(Offset)处理,以及掩膜(Mask)处理。

主要功能

  • 格式支持:提供 HDF4ReaderHDF5Reader 类,分别处理 HDF4 和 HDF5/NetCDF 格式。
  • 自动处理:支持读取数据时自动应用 scale_factoradd_offset,以及处理 _FillValue
  • 灵活模式:提供 native(原生)和 manual(手动)模式,允许用户自定义数据转换方式。
  • 位操作:支持 readbit 方法,方便提取特定位的数据。

安装

本项目依赖于 Python 3.11+。

依赖项

  • pyhdf >= 0.10.5
  • netCDF4 >= 1.6.5
  • numpy >= 1.23.0

安装方法

你可以通过 pip 安装本项目(假设已发布或本地安装):

pip install .

或者使用 requirements.txt 安装依赖:

pip install -r requirements.txt

使用示例

基础读取

根据文件格式选择对应的 Reader 类:

from mtmhdf import HDF4Reader, HDF5Reader

# 读取 HDF4 文件 (.hdf, .hdf4)
hdf4 = HDF4Reader("MOD021KM.A2025001.0000.061.2025001132345.hdf")

# 读取 HDF5 或 NetCDF 文件 (.h5, .he5, .hdf5, .nc)
hdf5 = HDF5Reader("data.h5")

# 获取文件中的所有数据集名称
print(hdf4.keys())

# 获取文件全局属性信息
print(hdf4.infos())

# 读取数据集(默认自动应用 scale, offset 和 mask)
data = hdf4["Latitude"]
print(data)

高级用法

自定义读取选项

你可以通过 read 方法控制读取行为:

# 读取数据,但不进行自动缩放和偏移,也不进行掩膜处理
raw_data = hdf4.read("Latitude", isScaleAndOffset=False, isMasked=False)

# 获取原始数据对象(未经过任何处理)
raw_obj = hdf4.readraw("Latitude")

位操作读取

对于包含位标志的数据集,可以使用 readbit 提取特定位的值:

# 读取 "Cloud_Mask" 数据集的第 0 到第 2 位(左开右闭,即位 0, 1)
# bit_start_pos: 起始位
# bit_end_pos: 结束位 (不包含)
cloud_flags = hdf4.readbit("Cloud_Mask", 0, 2)

支持的文件格式

  • HDF4: .hdf, .hdf4 (使用 HDF4Reader)
  • HDF5 / NetCDF: .h5, .he5, .hdf5, .nc (使用 HDF5Reader)

开源协议

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mtmhdf-1.0.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file mtmhdf-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: mtmhdf-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mtmhdf-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3d6aac0558781bccedc3aeabc89ffbc9538de6057f440d467ad75db300a0bcfc
MD5 7b8504a11541d889f3db0ffc343efb8a
BLAKE2b-256 ebe479973920192aa05a0850b5023ce8357062fbc7a09444746ccd192644158d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page