Sorry for the basic question, but I want to read a 32-bit
floating-point, 1000X2048X2048 dataset in python. I want to specify
the dimensions just like the hdfview utility does when we use "open
as".

How I do that in python? I tried the following code, but it results in
a segmentation fault:

import sys

import numpy as np
import h5py

FILE = "tomo.h5"
DATASET = "images"

# Strings are handled very differently between python2 and python3.
if sys.hexversion >= 0x03000000:
    FILE = FILE.encode()
    DATASET = DATASET.encode()

DIM0 = 0
DIM1 = 2047

def run():

    # Reopen the file and dataset using default properties.
    fid = h5py.h5f.open(FILE)
    dset = h5py.h5d.open(fid, DATASET)

    # Read the data using default properties.
    rdata = np.zeros((DIM0, DIM1), dtype=np.int32)
    dset.read(h5py.h5s.ALL, h5py.h5s.ALL, rdata)

    print("%s:" % DATASET)
    print(rdata)

if __name__ == "__main__":
    run()

Thank you very much,

Marcio

_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org

Reply via email to