Exemplo n.º 1
0
import numpy.ma as ma

import iris
import iris.exceptions
from iris.coord_systems import GeogCS, RotatedGeogCS, TransverseMercator
from iris.fileformats.grib import grib_phenom_translation as gptx
from iris.fileformats.grib._load_convert import (_STATISTIC_TYPE_NAMES,
                                                 _TIME_RANGE_UNITS)
from iris.util import is_regular, regular_step

# Invert code tables from :mod:`iris.fileformats.grib._load_convert`.
_STATISTIC_TYPE_NAMES = {
    val: key
    for key, val in _STATISTIC_TYPE_NAMES.items()
}
_TIME_RANGE_UNITS = {val: key for key, val in _TIME_RANGE_UNITS.items()}


def fixup_float32_as_int32(value):
    """
    Workaround for use when the ECMWF GRIB API treats an IEEE 32-bit
    floating-point value as a signed, 4-byte integer.

    Returns the integer value which will result in the on-disk
    representation corresponding to the IEEE 32-bit floating-point
    value.

    """
    value_as_float32 = np.array(value, dtype='f4')
    value_as_uint32 = value_as_float32.view(dtype='u4')
    if value_as_uint32 >= 0x80000000:
Exemplo n.º 2
0
import numpy.ma as ma

import iris
import iris.exceptions
import iris.unit
from iris.coord_systems import GeogCS, RotatedGeogCS, TransverseMercator
from iris.fileformats.grib import grib_phenom_translation as gptx
from iris.fileformats.grib._load_convert import (_STATISTIC_TYPE_NAMES,
                                                 _TIME_RANGE_UNITS)
from iris.util import is_regular, regular_step


# Invert code tables from :mod:`iris.fileformats.grib._load_convert`.
_STATISTIC_TYPE_NAMES = {val: key for key, val in
                         _STATISTIC_TYPE_NAMES.items()}
_TIME_RANGE_UNITS = {val: key for key, val in _TIME_RANGE_UNITS.items()}


def fixup_float32_as_int32(value):
    """
    Workaround for use when the ECMWF GRIB API treats an IEEE 32-bit
    floating-point value as a signed, 4-byte integer.

    Returns the integer value which will result in the on-disk
    representation corresponding to the IEEE 32-bit floating-point
    value.

    """
    value_as_float32 = np.array(value, dtype='f4')
    value_as_uint32 = value_as_float32.view(dtype='u4')
    if value_as_uint32 >= 0x80000000: