Esempio n. 1
0
def test_that_can_get_variable_metadata():
    vd = hdf_vd.read(valid_hdf_vd_file, 'DEM_elevation')['DEM_elevation']
    metadata = hdf_vd.get_metadata(vd)
    eq_(metadata._name, "DEM_elevation")
    eq_(metadata.long_name, "Digital Elevation Map")
    eq_(metadata.shape, [37081])
    eq_(metadata.units, "meters")
    eq_(metadata.range, [-9999, 8850])
    eq_(metadata.factor, 1.0)
    eq_(metadata.offset, 0.0)
    eq_(metadata.missing_value, 9999)
Esempio n. 2
0
def test_that_can_get_coord_metadata():
    vd = hdf_vd.read(valid_hdf_vd_file, 'Longitude')['Longitude']
    metadata = hdf_vd.get_metadata(vd)
    eq_(metadata._name, "Longitude")
    eq_(metadata.standard_name, "longitude")
    eq_(metadata.long_name, "Spacecraft Longitude")
    eq_(metadata.shape, [37081])
    eq_(metadata.units, "degrees")
    eq_(metadata.range, [-180.0, 180.0])
    eq_(metadata.factor, 1.0)
    eq_(metadata.offset, 0.0)
    eq_(metadata.missing_value, None)
Esempio n. 3
0
def test_that_can_get_variable_metadata():
    vd = hdf_vd.read(escape_colons(valid_hdf_vd_file),
                     'DEM_elevation')['DEM_elevation']
    metadata = hdf_vd.get_metadata(vd)
    eq_(metadata._name, "DEM_elevation")
    eq_(metadata.long_name, "Digital Elevation Map")
    eq_(metadata.shape, [37081])
    eq_(metadata.units, "meters")
    eq_(metadata.factor, 1.0)
    eq_(metadata.offset, 0.0)
    eq_(metadata.missing_value, 9999)
    eq_(metadata.misc['valid_range'], [-9999, 8850])
Esempio n. 4
0
def test_that_can_get_coord_metadata():
    vd = hdf_vd.read(escape_colons(valid_hdf_vd_file),
                     'Longitude')['Longitude']
    metadata = hdf_vd.get_metadata(vd)
    eq_(metadata._name, "Longitude")
    eq_(metadata.standard_name, "longitude")
    eq_(metadata.long_name, "Spacecraft Longitude")
    eq_(metadata.shape, [37081])
    eq_(metadata.units, "degrees")
    eq_(metadata.factor, 1.0)
    eq_(metadata.offset, 0.0)
    eq_(metadata.missing_value, None)
    eq_(metadata.misc['valid_range'], [-180.0, 180.0])
Esempio n. 5
0
def __read_hdf4(filename, variables):
    """
        A wrapper method for reading raw data from hdf4 files. This returns a dictionary of io handles
         for each VD and SD data types.

        :param filename:     A name of a file to read
        :param variables:    List of variables to read from the files

        :return: (sds_dict, vds_dict) A tuple of dictionaries, one for sds objects and another for vds
    """
    from cis.exceptions import InvalidVariableError
    from pyhdf.error import HDF4Error

    variables = utils.listify(variables)

    # I'd rather not have to make this check but for pyhdf 0.9.0 and hdf 4.2.9 on OS X the c-level read routine will at
    # some point call exit(138) when reading valid netcdf files (rather than returning a negative status).
    if not filename.endswith('.hdf'):
        raise IOError("Tried to read non HDF file: {}".format(filename))

    try:
        sds_dict = hdf_sd.read(filename, variables)

        # remove the variables identified as SD (i.e. the keys in sds_dict)
        # no need to try looking for them as VD variable
        # AND this can cause a crash in some version/implementations of the core HDF4 libraries!

        # First create a copy of the list in order for the original list to be left intact when elements are removed
        # from it, this enables the original list to be used when many files are read
        vdvariables = list(variables)
        for sds_dict_key in sds_dict:
            vdvariables.remove(sds_dict_key)

        vds_dict = hdf_vd.read(filename, vdvariables)
    except HDF4Error as e:
        joined_up_message = "".join(e)
        raise IOError(joined_up_message)

    for variable in variables:
        if variable not in sds_dict and variable not in vds_dict:
            raise InvalidVariableError("Could not find " + variable + " in file: " + filename)

    return sds_dict, vds_dict
Esempio n. 6
0
def _read_hdf4(filename, variables):
    """
        A wrapper method for reading raw data from hdf4 files. This returns a dictionary of io handles
         for each VD and SD data types.

        :param filename:     A name of a file to read
        :param variables:    List of variables to read from the files

        :return: (sds_dict, vds_dict) A tuple of dictionaries, one for sds objects and another for vds
    """
    from cis.exceptions import InvalidVariableError
    from pyhdf.error import HDF4Error

    variables = utils.listify(variables)

    # I'd rather not have to make this check but for pyhdf 0.9.0 and hdf 4.2.9 on OS X the c-level read routine will at
    # some point call exit(138) when reading valid netcdf files (rather than returning a negative status).
    if not filename.endswith('.hdf'):
        raise IOError("Tried to read non HDF file: {}".format(filename))

    try:
        sds_dict = hdf_sd.read(filename, variables)

        # remove the variables identified as SD (i.e. the keys in sds_dict)
        # no need to try looking for them as VD variable
        # AND this can cause a crash in some version/implementations of the core HDF4 libraries!

        # First create a copy of the list in order for the original list to be left intact when elements are removed
        # from it, this enables the original list to be used when many files are read
        vdvariables = list(variables)
        for sds_dict_key in sds_dict:
            vdvariables.remove(sds_dict_key)

        vds_dict = hdf_vd.read(filename, vdvariables)
    except HDF4Error as e:
        raise IOError(str(e))

    for variable in variables:
        if variable not in sds_dict and variable not in vds_dict:
            raise InvalidVariableError("Could not find " + variable +
                                       " in file: " + filename)

    return sds_dict, vds_dict
Esempio n. 7
0
def test_that_can_get_data():
    vds_dict = hdf_vd.read(valid_hdf_vd_file, 'DEM_elevation')
    vds = vds_dict['DEM_elevation']
    data = hdf_vd.get_data(vds)
    eq_(37081, len(data))
Esempio n. 8
0
def test_that_can_get_data():
    vds_dict = hdf_vd.read(escape_colons(valid_hdf_vd_file), 'DEM_elevation')
    vds = vds_dict['DEM_elevation']
    data = hdf_vd.get_data(vds)
    eq_(37081, len(data))