# Pygeode interface for HDF4 files #TODO: bring out EOSGRID stuff into a separate module? from pygeode.libhelper import load_lib try: lib1 = load_lib('df', Global=True) # so we have symbol 'error_top' lib = load_lib('mfhdf') except OSError as e: print('Failed to load HDF libraries; no HDF support available.') del load_lib import numpy as np numpy_type = { 20: np.int8, 21: np.uint8, 22: np.int16, 23: np.uint16, 24: np.int32, 25: np.uint32, 5: np.float32, 6: np.float64 } del np hdf_type = { 'int8': 20, 'uint8': 21, 'int16': 22, 'uint16': 23, 'int32': 24,
#TODO: when saving, convert NaN to another fill value? # Pygeode interface for netCDF files from ctypes import c_char_p from pygeode.libhelper import load_lib lib = load_lib('netcdf') lib.nc_strerror.restype = c_char_p del c_char_p # Map netcdf types to numpy types import numpy as np numpy_type = {1:np.int8, 2:np.dtype('|S1'), 3:np.int16, 4:np.int32, 5:np.float32, 6:np.float64, 7:np.uint8, 8:np.uint16, 9:np.uint32, 10:np.int64, 11:np.uint64} del np NC_MAX_NAME = 256 NC_MAX_DIMS = 1024 NC_MAX_VAR_DIMS = NC_MAX_DIMS nc_type_v3 = {'int8':1, 'string8':2, 'bytes8':2, 'int16':3, 'int32':4, 'float32':5, 'float64':6, 'uint8':3, 'uint16':4, 'uint32':4, 'int64':6, 'uint64':6} nc_type_v4 = {'int8':1, 'string8':2, 'int16':3, 'int32':4, 'float32':5, 'float64':6, 'uint8':7, 'uint16':8, 'uint32':9, 'int64':10, 'uint64':11} nc_type = {3:nc_type_v3, 4:nc_type_v4} get_att_f = {1:lib.nc_get_att_schar, 2:lib.nc_get_att_text,
#TODO: when saving, convert NaN to another fill value? # Pygeode interface for netCDF files from ctypes import c_char_p from pygeode.libhelper import load_lib lib = load_lib('netcdf') lib.nc_strerror.restype = c_char_p del c_char_p # Map netcdf types to numpy types import numpy as np numpy_type = { 1: np.int8, 2: np.dtype('|S1'), 3: np.int16, 4: np.int32, 5: np.float32, 6: np.float64, 7: np.uint8, 8: np.uint16, 9: np.uint32, 10: np.int64, 11: np.uint64 } del np NC_MAX_NAME = 256 NC_MAX_DIMS = 1024 NC_MAX_VAR_DIMS = NC_MAX_DIMS nc_type_v3 = {
# Pygeode interface for HDF4 files #TODO: bring out EOSGRID stuff into a separate module? from pygeode.libhelper import load_lib try: lib1 = load_lib('df', Global=True) # so we have symbol 'error_top' lib = load_lib('mfhdf') except OSError as e: print('Failed to load HDF libraries; no HDF support available.') del load_lib import numpy as np numpy_type = {20:np.int8, 21:np.uint8, 22:np.int16, 23:np.uint16, 24:np.int32, 25:np.uint32, 5:np.float32, 6:np.float64} del np hdf_type = {'int8':20, 'uint8':21, 'int16':22, 'uint16':23, 'int32':24, 'uint32':25, 'float32':5, 'float64':6} # Return an attribute dictionary given an HDF id (and expected # of attributes) def get_attributes (obj_id, natts): from ctypes import create_string_buffer, c_long, byref import numpy as np from pygeode.tools import point atts = {} for i in range(natts): name = create_string_buffer(256) type = c_long() count = c_long() ret = lib.SDattrinfo(obj_id, i, name, byref(type), byref(count))