Skip to content

hdfio

hdf_close(fileid)

fileid - file id

Source code in monetio/sat/hdfio.py
53
54
55
56
57
def hdf_close(fileid):
    """
    fileid - file id
    """
    fileid.end()

hdf_create(filename)

filename - file name return - file id

Source code in monetio/sat/hdfio.py
38
39
40
41
42
43
44
45
46
47
48
49
50
def hdf_create(filename):
    """
    filename - file name
    return - file id
    """
    hdf = _get_hdf()
    try:
        fileid = hdf.SD(filename, hdf.SDC.WRITE | hdf.SDC.CREATE | hdf.SDC.TRUNC)
        logging.debug("hdfio.hdf_create:" + filename)
    except OSError:
        logging.error("hdfio.hdf_create:" + filename)
        sys.exit(1)
    return fileid

hdf_list(fileid)

fileid - file id return datasets

Source code in monetio/sat/hdfio.py
60
61
62
63
64
65
66
67
68
69
70
71
72
def hdf_list(fileid):
    """
    fileid - file id
    return datasets
    """
    hdf = _get_hdf()
    datasets = sorted(fileid.datasets())
    indices = list()
    for dataset in datasets:
        index = hdf.SD.nametoindex(fileid, dataset)
        indices.append(index)
        logging.debug("hdfio.hdf_list:" + str(index) + ":" + dataset)
    return datasets, indices

hdf_open(filename)

filename - file name return - file id

Source code in monetio/sat/hdfio.py
23
24
25
26
27
28
29
30
31
32
33
34
35
def hdf_open(filename):
    """
    filename - file name
    return - file id
    """
    hdf = _get_hdf()
    try:
        fileid = hdf.SD(filename, hdf.SDC.READ)
        logging.debug("hdfio.hdf_open:" + filename)
    except OSError:
        logging.error("hdfio.hdf_open:" + filename)
        sys.exit(1)
    return fileid

hdf_read(fileid, varname)

fileid - file id varname - variable name return data

Source code in monetio/sat/hdfio.py
75
76
77
78
79
80
81
82
83
84
def hdf_read(fileid, varname):
    """
    fileid - file id
    varname - variable name
    return data
    """
    logging.debug("hdfio.hdf_read:" + varname)
    varid = fileid.select(varname)
    data = varid[:]
    return data

hdf_write_coord(fileid, coordname, data)

fileid - file id coordname - coordinate variable name data - coordinate array

Source code in monetio/sat/hdfio.py
87
88
89
90
91
92
93
94
95
96
97
98
99
def hdf_write_coord(fileid, coordname, data):
    """
    fileid - file id
    coordname - coordinate variable name
    data - coordinate array
    """
    hdftypes = _get_hdftypes()
    logging.debug("hdfio.hdf_write_coord:" + coordname)
    coordid = fileid.create(coordname, hdftypes[str(data.dtype)], data.shape)
    dimid = coordid.dim(0)
    dimid.setname(coordname)
    coordid[:] = data
    coordid.endaccess()

hdf_write_field(fileid, fieldname, coordnames, data, fill=None)

fileid - file id fieldname - field variable name coordnames - tuple of coordinate variable names data - field array fill - fill value

Source code in monetio/sat/hdfio.py
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
def hdf_write_field(fileid, fieldname, coordnames, data, fill=None):
    """
    fileid - file id
    fieldname - field variable name
    coordnames - tuple of coordinate variable names
    data - field array
    fill - fill value
    """
    hdftypes = _get_hdftypes()
    logging.debug("hdfio.hdf_write_field:" + fieldname)
    fieldid = fileid.create(fieldname, hdftypes[str(data.dtype)], data.shape)
    for i in range(len(coordnames)):
        dimid = fieldid.dim(i)
        dimid.setname(coordnames[i])
    fieldid[:] = data
    if fill is not None:
        fieldid.setfillvalue(fill)
    fieldid.endaccess()