Issues (227)

awips/dataaccess/PyGridData.py (1 issue)

1
#
2
# Implements IGridData for use by native Python clients to the Data Access
3
# Framework.
4
#
5
#
6
#     SOFTWARE HISTORY
7
#
8
#    Date            Ticket#       Engineer       Description
9
#    ------------    ----------    -----------    --------------------------
10
#    06/03/13         #2023        dgilling      Initial Creation.
11
#    10/13/16         #5916        bsteffen      Correct grid shape, allow lat/lon
12
#    11/10/16         #5900        bsteffen      Correct grid shape
13
#                                                to be requested by a delegate
14
#
15
#
16
17
import numpy
18
import warnings
19
import six
20
21
from awips.dataaccess import IGridData
22
from awips.dataaccess import PyData
23
24
NO_UNIT_CONVERT_WARNING = """
25
The ability to unit convert grid data is not currently available in this version of the Data Access Framework.
26
"""
27
28
29 View Code Duplication
class PyGridData(IGridData, PyData.PyData):
0 ignored issues
show
This code seems to be duplicated in your project.
Loading history...
30
31
    def __init__(self, gridDataRecord, nx, ny, latLonGrid=None, latLonDelegate=None):
32
        PyData.PyData.__init__(self, gridDataRecord)
33
        nx = nx
34
        ny = ny
35
        self.__parameter = gridDataRecord.getParameter()
36
        self.__unit = gridDataRecord.getUnit()
37
        self.__gridData = numpy.reshape(numpy.array(gridDataRecord.getGridData()), (ny, nx))
38
        self.__latLonGrid = latLonGrid
39
        self.__latLonDelegate = latLonDelegate
40
41
    def getParameter(self):
42
        return self.__parameter
43
44
    def getUnit(self):
45
        if six.PY2:
46
            return self.__unit
47
        if self.__unit is not None and not isinstance(self.__unit, str):
48
            return self.__unit.decode('utf-8')
49
        return self.__unit
50
51
    def getRawData(self, unit=None):
52
        # TODO: Find a proper python library that deals will with numpy and
53
        # javax.measure style unit strings and hook it in to this method to
54
        # allow end-users to perform unit conversion for grid data.
55
        if unit is not None:
56
            warnings.warn(NO_UNIT_CONVERT_WARNING, stacklevel=2)
57
        return self.__gridData
58
59
    def getLatLonCoords(self):
60
        if self.__latLonGrid is not None:
61
            return self.__latLonGrid
62
        elif self.__latLonDelegate is not None:
63
            return self.__latLonDelegate()
64
        return self.__latLonGrid
65