Ejemplo n.º 1
0
 def testGetGeometryDataWithLocationSpecified(self):
     req = DAL.newDataRequest(self.datatype)
     req.addIdentifier('table', 'fcstheight')
     locs = DAL.getAvailableLocationNames(req)
     if locs:
         req.setLocationNames(locs[0])
         req.setParameters('probability', 'value')
         data = self.runGeometryDataTest(req)
         self.assertNotEqual(len(data), 0)
Ejemplo n.º 2
0
 def testGetGeometryDataWithLocationSpecified(self):
     req = DAL.newDataRequest(self.datatype)
     req.addIdentifier('table', 'fcstheight')
     locs = DAL.getAvailableLocationNames(req)
     if locs:
         req.setLocationNames(locs[0])
         req.setParameters('probability', 'value')
         data = self.runGeometryDataTest(req)
         self.assertNotEqual(len(data), 0)
Ejemplo n.º 3
0
 def runLocationsTest(self, req):
     locs = DAL.getAvailableLocationNames(req)
     self.assertIsNotNone(locs)
     print("Number of location names: " + str(len(locs)))
     print("Sample location names:\n" + str(locs[:self.sampleDataLimit]))
Ejemplo n.º 4
0
 def _getLocationNames(self):
     req = DAL.newDataRequest()
     req.setDatatype(self.datatype)
     return DAL.getAvailableLocationNames(req)
Ejemplo n.º 5
0
 def testGetAvailableLocationsWithInvalidTable(self):
     req = DAL.newDataRequest(self.datatype)
     req.addIdentifier('table', 'city')
     with self.assertRaises(ThriftRequestException) as cm:
         DAL.getAvailableLocationNames(req)
     self.assertIn('IncompatibleRequestException', str(cm.exception))
Ejemplo n.º 6
0
def main():
    user_args = get_args()

    if user_args.host:
        DataAccessLayer.changeEDEXHost(user_args.host)

    if (user_args.date and not user_args.time) or (user_args.time and not user_args.date):
        print >> sys.stderr, "date and time must be provided together"
        return

    # If a time range is provided, results will be filtered based on available times
    timeRange = None
    if user_args.date:
        midRange = datetime.strptime( user_args.date + " " + user_args.time, "%Y-%m-%d %H:%M")
        beginRange = midRange - timedelta(0, 60)
        endRange = midRange + timedelta(0, 60)
        timeRange = TimeRange(beginRange, endRange)

    req = create_request(user_args)
    if user_args.icao:
        if user_args.productCode: # retrieve available times and/or true or primary elevation angles
            if timeRange:
                tr = timeRange
            else:
                tr = None
            lines = set()

            if user_args.outputAngle:
                levels = DataAccessLayer.getAvailableLevels(req)
                for level in levels:
                    line = ""
                    req.setLevels(level)
                    if user_args.outputDate:
                        times = DataAccessLayer.getAvailableTimes(req)
                        for time in times:
                            if not tr or tr.contains(time.getValidPeriod()):
                                line = str(time) + ".0"
                                line += " "
                                if user_args.outputAngle == "true":
                                    line += "%.1f"%level.getLeveltwovalue()
                                else:
                                    line += "%.1f"%level.getLevelonevalue()
                                lines.add(line)
                    else:
                        if not tr or data_in_time_range(req, tr):
                            if user_args.outputAngle == "true":
                                line = "%.1f"%level.getLeveltwovalue()
                            else:
                                line = "%.1f"%level.getLevelonevalue()
                        lines.add(line)
            else : # just output time
                times = DataAccessLayer.getAvailableTimes(req)
                for time in times:
                    if not tr or tr.contains(time.getValidPeriod()):
                        lines.add(str(time) + ".0")
            msg = "\n".join(lines)
        else: #retrieve available product codes
            unfiltered = DataAccessLayer.getAvailableParameters(req)
            productCodes = []
            for parameter in unfiltered: #filter to just productCodes
                if parameter.isdigit(): 
                    productCodes.append(parameter)
            if timeRange:
                unfiltered = productCodes
                productCodes = []
                for productCode in unfiltered:
                    req = create_request(user_args)
                    req.setParameters(productCode)
                    if data_in_time_range(req, timeRange):
                        productCodes.append(productCode)
            msg = "\n".join(productCodes)
            
    else: # retrieve available icaos
        icaos = DataAccessLayer.getAvailableLocationNames(req)
        if timeRange:
            unfiltered = icaos
            icaos = []
            for icao in unfiltered:
                req = create_request(user_args)
                req.addIdentifier("icao", icao)
                if data_in_time_range(req, timeRange):
                    icaos.append(icao)
                
        msg = "\n".join(icaos)

    print msg.strip()
Ejemplo n.º 7
0
 def testGetAvailableLocationsWithInvalidTable(self):
     req = DAL.newDataRequest(self.datatype)
     req.addIdentifier('table', 'public.boolean_values')
     with self.assertRaises(ThriftRequestException) as cm:
         DAL.getAvailableLocationNames(req)
     self.assertIn('IncompatibleRequestException', str(cm.exception))
Ejemplo n.º 8
0
 def _getLocationNames(self):
     req = DAL.newDataRequest()
     req.setDatatype(self.datatype)
     return DAL.getAvailableLocationNames(req)
Ejemplo n.º 9
0
 def runLocationsTest(self, req):
     locs = DAL.getAvailableLocationNames(req)
     self.assertIsNotNone(locs)
     print("Number of location names: " + str(len(locs)))
     print("Sample location names:\n" + str(locs[:self.sampleDataLimit]))
Ejemplo n.º 10
0
    def index(self):

        request = DataAccessLayer.newDataRequest()
        request.setDatatype("grid")
        # Grid names
        available_grids = DataAccessLayer.getAvailableLocationNames(request)
        available_grids.sort()
        # Grid parameters
        availableParms = DataAccessLayer.getAvailableParameters(request)
        availableParms.sort()

        # Build dropdowns
        lvlString = ''
        gridSelect = """
        <h1>AWIPS Forecast & Analysis Grids</h1>
        <div class="ui search">
          <div class="ui icon input">
            <input class="prompt" type="text" placeholder="Search parameters...">
            <i class="search icon"></i>
          </div>
          <div class="results"></div>
        </div>
        """
        gridCards = '<div class="ui link cards">'
        gridMenu = ''
        for grid in available_grids:

            for gname, info in grid_dictionary.iteritems():
                if gname == grid:
                    centerid = info[0]
                    subcenterid = info[1]
                    gridid = info[2]
                    centername = wmo_centers[centerid]
                    gridnav = navigation[gridid]
                    # '216': ['grid over Alaska (polar stereographic)', '139', '107', '45.0', '45.0', 'km'],
                    grid_size = gridnav[1] + "x" + gridnav[2]
                    grid_res = str(round(float(gridnav[3]),2)) + " " + gridnav[5]

            if not pattern.match(grid):
                gridMenu += """<a class="item" href="/grid?name="""+ grid +"""">"""+ grid +"""</a>"""
                gridCards += """<div class="card">
                                    <div class="image"></div>
                                    <div class="content">
                                        <div class="header"><a href="/grid?name="""+ grid +"""">"""+ grid +"""</a></div>
                                        <div class="meta">""" + gridnav[0] + """</div>
                                        <div class="description">""" + centername[1] + """ (""" + centername[0] + """)</div>
                                    </div>
                                    <div class="extra content">
                                      <span class="right floated">""" + grid_size + """</span>
                                      <span>
                                        """ + grid_res + """ resolution
                                      </span>
                                    </div>
                                </div>


                                """





        parameter_content = 'var parameter_content = ['
        previous = ''
        for gridparm in availableParms:
            for item in parm_dict:
                replaced = re.sub('[0-9]{1,2}hr', '', gridparm)
                if item == replaced and replaced <> previous:
                    previous = replaced
                    parmDescription = parm_dict[item][0]
                    parameter_content += "{ name: '"+replaced+"', title: '"+replaced+" - "+parmDescription+"'},"
        gridCards += '</div>'
        parameter_content += '];'
        renderHtml = gridSelect + gridCards
        sideContent = ''

        stringReturn = createpage("", "", "", "",renderHtml,sideContent,parameter_content,gridMenu)
        return stringReturn
Ejemplo n.º 11
0
    def parm(self, name="", parm="", level=""):
        request = DataAccessLayer.newDataRequest()
        request.setDatatype("grid")
        availableParms = DataAccessLayer.getAvailableParameters(request)
        availableParms.sort()
        request.setParameters(parm)
        parmDescription = ''
        parmUnit = ''
        for item in parm_dict:
            replaced = re.sub('[0-9]{1,2}hr$', '', parm)
            if item == replaced:
                parmDescription = parm
                parmDescription = parm_dict[item][0]
                parmUnit = parm_dict[item][1]

        # Grid names
        available_grids = DataAccessLayer.getAvailableLocationNames(request)
        available_grids.sort()
        parmSearch = """
                <h1>AWIPS Forecast & Analysis Grids</h1>
                <div class="ui search">
                  <div class="ui icon input">
                    <input class="prompt" type="text" placeholder="Search parameters...">
                    <i class="search icon"></i>
                  </div>
                  <div class="results"></div>
                </div>
                """
        gridString = ''
        for grid in available_grids:
            if not pattern.match(grid):
                gridString += '<h3><a href="/grid?name='+grid+'">'+grid+'</a></h3>'\
                        '<table class="ui single line table"><thead>' \
                        '<tr><th>Parameter</th><th>Description</th><th>Unit</th><th>Level</th><th>DAF</th></tr>' \
                        '</thead>'
                request.setLocationNames(grid)
                availableLevels = DataAccessLayer.getAvailableLevels(request)
                availableLevels.sort()
                for llevel in availableLevels:
                    for litem in level_dict:
                        lreplaced = re.sub('^[0-9|\.|\_]+', '', str(llevel))
                        if str(litem) == lreplaced:
                            levelDesc = level_dict[litem][0]
                    idhash = hash(grid+parm+str(llevel))
                    gridString += '<tr><td><a href="/grid?name=' + grid + '&parm=' + parm + '">' + parm + '</a></td>' \
                            '<td> ' + parmDescription + '</td>' \
                            '<td>'+ parmUnit +'</td>' \
                            '<td><div class="small ui label" data-tooltip="' + levelDesc + '">' + str(llevel) +'</div></td>' \
                            '<td><a class="showcode circular ui icon basic button" name="'+str(idhash)+'" ' \
                            'href="/json?name=' + grid + '&parm=' + parm + '&level=' + str(llevel) + '">' \
                             '<i class="code icon small"></i></a></td></tr>'


                    gridString += '''<tr id="'''+str(idhash)+'''" class="transition hidden"><td colspan=5><div class="ui instructive bottom attached segment"><pre><code class="code xml">request = DataAccessLayer.newDataRequest()
request.setDatatype("grid")
request.setLocationNames("'''+grid+'''")
request.setParameters("'''+parm+'''")
request.setLevels("'''+str(llevel)+'''")
</code></pre></div></td></tr>'''

                gridString += '</table>'

        # Build dropdowns
        # lvlString = ''
        # renderHtml = '<div class=""><select class="ui select dropdown" id="gridSelect">'
        # for grid in available_grids:
        #     if not pattern.match(grid): renderHtml += '<option value="%s">%s</option>' % (grid, grid)
        # renderHtml += '</select></div>'
        #
        # renderHtml += '<div class=""><select class="ui select dropdown" id="levelSelect">'
        # for llevel in availableLevels:
        #     renderHtml += '<option value="%s">%s</option>' % (llevel, llevel)
        # renderHtml += '</select></div>'
        #
        # # Forecast Cycles
        # cycles = DataAccessLayer.getAvailableTimes(request, True)
        # t = DataAccessLayer.getAvailableTimes(request)
        # fcstRun = []
        # for time in t:
        #     if str(time)[:19] == str(cycles[-1]):
        #         fcstRun.append(time)
        #
        # renderHtml += '<div class="ui one column grid"><div class="ten wide column"><div><select class="ui select dropdown" id="cycleSelect">'
        # for time in fcstRun:
        #     renderHtml += '<option value="%s">%s</option>' % (time, time)
        # renderHtml += '</select></div><br><Br>'


        parameter_content = 'var parameter_content = ['
        previous = ''
        for gridparm in availableParms:
            for item in parm_dict:
                replaced = re.sub('[0-9]{1,2}hr', '', gridparm)
                if item == replaced and replaced <> previous:
                    previous = replaced
                    parmDescription = parm_dict[item][0]
                    parameter_content += "{ name: '" + replaced + "', title: '" + replaced + " - " + parmDescription + "'},"
        parameter_content += '];'

        renderHtml = parmSearch + '<h1 class="ui dividing header">' + parm + ' - ' + parmDescription + ' (' + parmUnit + ')</h1>' \
                     + '<p>' + gridString + '</p></div></div>'

        sideContent = ''
        parmlist = ''
        stringReturn = createpage(name,parm,str(level),"",renderHtml,sideContent,parameter_content, parmlist)
        return stringReturn
Ejemplo n.º 12
0
@author: CoeFamily
"""

from awips.dataaccess import DataAccessLayer
import unittest
import numpy as np

DataAccessLayer.changeEDEXHost("edex-cloud.unidata.ucar.edu")
dataTypes = DataAccessLayer.getSupportedDatatypes()
dataTypes.sort()
list(dataTypes)

request = DataAccessLayer.newDataRequest()
request.setDatatype("grid")
available_grids = DataAccessLayer.getAvailableLocationNames(request)
available_grids.sort()
list(available_grids)

request.setLocationNames("NAM12")
availableParms = DataAccessLayer.getAvailableParameters(request)
availableParms.sort()
list(availableParms)

request.setParameters("T")
availableLevels = DataAccessLayer.getAvailableLevels(request)

request.setLevels("0.0SFC")

cycles = DataAccessLayer.getAvailableTimes(request, True)
times = DataAccessLayer.getAvailableTimes(request)