예제 #1
0
파일: _message.py 프로젝트: pp-mo/iris
    def _get_key_value(self, key):
        """
        Get the value associated with the given key in the GRIB message.

        Args:

        * key:
            The GRIB key to retrieve the value of.

        Returns the value associated with the requested key in the GRIB
        message.

        """
        vector_keys = ('codedValues', 'pv', 'satelliteSeries',
                       'satelliteNumber', 'instrumentType',
                       'scaleFactorOfCentralWaveNumber',
                       'scaledValueOfCentralWaveNumber',
                       'longitudes', 'latitudes')
        if key in vector_keys:
            res = gribapi.grib_get_array(self._message_id, key)
        elif key == 'bitmap':
            # The bitmap is stored as contiguous boolean bits, one bit for each
            # data point. GRIBAPI returns these as strings, so it must be
            # type-cast to return an array of ints (0, 1).
            res = gribapi.grib_get_array(self._message_id, key, int)
        elif key in ('typeOfFirstFixedSurface', 'typeOfSecondFixedSurface'):
            # By default these values are returned as unhelpful strings but
            # we can use int representation to compare against instead.
            res = gribapi.grib_get(self._message_id, key, int)
        else:
            res = gribapi.grib_get(self._message_id, key)
        return res
예제 #2
0
    def _get_key_value(self, key):
        """
        Get the value associated with the given key in the GRIB message.

        Args:

        * key:
            The GRIB key to retrieve the value of.

        Returns the value associated with the requested key in the GRIB
        message.

        """
        vector_keys = ('codedValues', 'pv', 'satelliteSeries',
                       'satelliteNumber', 'instrumentType',
                       'scaleFactorOfCentralWaveNumber',
                       'scaledValueOfCentralWaveNumber', 'longitudes',
                       'latitudes', 'distinctLatitudes')
        if key in vector_keys:
            res = gribapi.grib_get_array(self._message_id, key)
        elif key == 'bitmap':
            # The bitmap is stored as contiguous boolean bits, one bit for each
            # data point. GRIBAPI returns these as strings, so it must be
            # type-cast to return an array of ints (0, 1).
            res = gribapi.grib_get_array(self._message_id, key, int)
        elif key in ('typeOfFirstFixedSurface', 'typeOfSecondFixedSurface'):
            # By default these values are returned as unhelpful strings but
            # we can use int representation to compare against instead.
            res = gribapi.grib_get(self._message_id, key, int)
        else:
            res = gribapi.grib_get(self._message_id, key)
        return res
예제 #3
0
    def _get_key_value(self, key):
        """
        Get the value associated with the given key in the GRIB message.

        Args:

        * key:
            The GRIB key to retrieve the value of.

        Returns the value associated with the requested key in the GRIB
        message.

        """
        vector_keys = (
            "codedValues",
            "pv",
            "satelliteSeries",
            "satelliteNumber",
            "instrumentType",
            "scaleFactorOfCentralWaveNumber",
            "scaledValueOfCentralWaveNumber",
        )
        if key in vector_keys:
            res = gribapi.grib_get_array(self._message_id, key)
        elif key in ("typeOfFirstFixedSurface", "typeOfSecondFixedSurface"):
            # By default these values are returned as unhelpful strings but
            # we can use int representation to compare against instead.
            res = gribapi.grib_get(self._message_id, key, int)
        else:
            res = gribapi.grib_get(self._message_id, key)
        return res
예제 #4
0
 def get(self, key, ktype=None):
     """Get value of a given key as its native or specified type."""
     if self.missing(key):
         raise KeyError("Key is missing from message.")
     if gribapi.grib_get_size(self.gid, key) > 1:
         ret = gribapi.grib_get_array(self.gid, key, ktype)
     else:
         ret = gribapi.grib_get(self.gid, key, ktype)
     return ret
예제 #5
0
 def get(self, key, type=None):
     """Get value of a given key as its native or specified type."""
     if self.missing(key):
         raise KeyError("Key is missing from message.")
     if key == "values":
         ret = gribapi.grib_get_values(self.gid)
     else:
         try:
             ret = gribapi.grib_get(self.gid, key, type)
         # This is an ugly hack because the library does not differentiate
         # exception types
         except gribapi.GribInternalError, e:
             if e.msg == "Passed array is too small":
                 ret = gribapi.grib_get_array(self.gid, key, type)
             else:
                 raise e
예제 #6
0
 def get(self, key, type=None):
     """Get value of a given key as its native or specified type."""
     if self.missing(key):
         raise KeyError("Key is missing from message.")
     if key == "values":
         ret = gribapi.grib_get_values(self.gid)
     else:
         try:
             ret = gribapi.grib_get(self.gid, key, type)
         # This is an ugly hack because the library does not differentiate
         # exception types
         except gribapi.GribInternalError, e:
             if e.msg == "Passed array is too small":
                 ret = gribapi.grib_get_array(self.gid, key, type)
             else:
                 raise e
예제 #7
0
    def get_computed_key(self, key):
        """
        Get the computed value associated with the given key in the GRIB
        message.

        Args:

        * key:
            The GRIB key to retrieve the value of.

        Returns the value associated with the requested key in the GRIB
        message.

        """
        vector_keys = ('longitudes', 'latitudes', 'distinctLatitudes')
        if key in vector_keys:
            res = gribapi.grib_get_array(self._message_id, key)
        else:
            res = gribapi.grib_get(self._message_id, key)
        return res
예제 #8
0
    def get_computed_key(self, key):
        """
        Get the computed value associated with the given key in the GRIB
        message.

        Args:

        * key:
            The GRIB key to retrieve the value of.

        Returns the value associated with the requested key in the GRIB
        message.

        """
        vector_keys = ('longitudes', 'latitudes', 'distinctLatitudes')
        if key in vector_keys:
            res = gribapi.grib_get_array(self._message_id, key)
        else:
            res = gribapi.grib_get(self._message_id, key)
        return res
예제 #9
0
gidV = np.flipud([
    i + 1 for i in range(len(varNames))
    if (varNames[i] == 'v' and levels[i] in levsIncl)
])
# W-component of wind
gidW = np.flipud([
    i + 1 for i in range(len(varNames))
    if (varNames[i] == 'wz' and levels[i] in levsIncl)
])
# Relative humidity
gidRH = np.flipud([
    i + 1 for i in range(len(varNames))
    if (varNames[i] == 'r' and levels[i] in levsIncl)
])
# GET LATS, LONS, NI AND NJ
lats = gribapi.grib_get_array(gidPRMSL, 'distinctLatitudes')
lons = gribapi.grib_get_array(gidPRMSL, 'distinctLongitudes')
Ni = gribapi.grib_get(gidPRMSL, 'Ni')
Nj = gribapi.grib_get(gidPRMSL, 'Nj')
#####

# DETERMINE SUBDOMAIN INDICES BASED ON CALPUFF GRID EXTENT
for i in range(len(lats) - 1):
    if lats[i + 1] >= latMinCP:
        iLatMinGRIB = i
        break
for i in range(len(lats) - 1):
    if lats[i + 1] > latMaxCP:
        iLatMaxGRIB = i + 1
        break
for i in range(len(lons) - 1):