Example #1
0
    def getTaskRequestData( self, request_params ):
        task_parameters = {}
        request = dict( request_params )
        inputs = request.get('datainputs',None)
        wpsLog.debug( ">>>> REQUEST datainputs: %s" % str(inputs) )
        if inputs:
            if isinstance( inputs, dict ):
                task_parameters.update( inputs )
            elif isinstance( inputs, list ):
                for item in inputs:
                    if isinstance( item, list ):
                        task_parameters[ str(item[0]) ] = convert_json_str( item[1] )
                    elif isinstance( item, basestring ):
                        self.parseDatainputsStr( item, task_parameters )
            else:
                self.parseDatainputsStr(self, inputs, task_parameters )
            del request[ 'datainputs' ]
        for key in self.dataInputKeys:
            parameter = request.get(key,None)
            if parameter:
                if isinstance(parameter, basestring):
                    try:
                        parameter = json.loads( parameter )
                    except:
                        wpsLog.error( " Error json decoding parameter: '%s' " % parameter )
                        parameter = ""
                task_parameters[ key ] = parameter
                del request[key]
        for key in self.controlKeys:
            parameter = request.get(key,None)
            if parameter:
                if isinstance(parameter, basestring): parameter = parameter.lower()
                task_parameters[ key ] = parameter
                del request[key]
        for item in request.items():
            task_parameters[ item[0] ] = item[1]

        for key_alias, alt_key in self.aliases.items():
            if key_alias in task_parameters:
                task_parameters[ alt_key ] = task_parameters[ key_alias ]
                del task_parameters[ key_alias ]

        return task_parameters
if __name__ == "__main__":
    wpsLog.addHandler( logging.StreamHandler(sys.stdout) ) #logging.FileHandler( os.path.abspath( os.path.join(os.path.dirname(__file__), '..', 'logs', 'wps.log') ) ) )
    wpsLog.setLevel(logging.DEBUG)
    pp = pprint.PrettyPrinter(indent=4)

    variables = [ { 'collection': 'MERRA/mon/atmos', 'id': 'clt' },
                  { 'url': 'file://usr/local/web/data/MERRA/u750/merra_u750.xml', 'id': 'u' },
                  { 'url': 'file://usr/local/web/data/MERRA/MERRA100.xml', 'id': 't' },
                  { 'url': 'file://usr/local/web/data/MERRA/u750/merra_u750.nc', 'id': 'u' },
                  { 'url': 'file://usr/local/web/data/MERRA/u750/merra_u750_1979_1982.nc', 'id': 'u' },
                  { 'url': 'file://usr/local/web/WPCDAS/data/TestData.nc', 'id': 't' },
                  { 'url': 'file://usr/local/web/WPCDAS/data/atmos_ua.nc', 'id': 'ua' } ]
    var_index = 0
    region    = { "longitude":-24.20, "latitude":58.45 }

    operations = [ '{"kernel":"time", "type":"climatology", "bounds":"annualcycle"}',
                   '{"kernel":"time", "type":"departures",  "bounds":"np"}',
                   { 'type': 'climatology', 'bounds': 'annualcycle' },
                   { 'type': 'departures', 'bounds': '' },
                   { 'type': 'climatology', 'bounds': '' },
                   { 'type': 'departures', 'bounds': 'np' },
                   { 'type': 'climatology', 'bounds': 'np' },
                   { 'type': '', 'bounds': '' } ]
    operation_index = 1

    processor = TimeseriesAnalytics( convert_json_str( operations[operation_index] )  )
    result = processor.run( { 'data':variables[var_index], 'region': region } )
    print "\n ---------- Result: ---------- "
    pp.pprint(result)