def run( self, run_args ): data = get_json_arg( 'data', run_args ) region = get_json_arg( 'region', run_args ) result_obj = {} try: start_time = time.time() cdms2keyargs = self.region2cdms( region ) variable = run_args.get( "dataSlice", None ) if variable is None: id = data["id"] url = data.get("url",None) if url is not None: var_cache_id = ":".join( [url,id] ) dataset = self.loadFileFromURL( url ) else: collection = data.get("collection",None) if collection is not None: var_cache_id = ":".join( [collection,id] ) dataset = self.loadFileFromCollection( collection, id ) else: wpsLog.debug( " $$$ Empty Data Request: '%s' ", str( run_args ) ) return None wpsLog.debug( " $$$ Data Request: '%s', '%s' ", var_cache_id, str( cdms2keyargs ) ) variable = dataset[ id ] result_obj['variable'] = record_attributes( variable, [ 'long_name', 'name', 'units' ], { 'id': id } ) result_obj['dataset'] = record_attributes( dataset, [ 'id', 'uri' ]) else: result_obj['variable'] = record_attributes( variable, [ 'long_name', 'name', 'id', 'units' ] ) read_start_time = time.time() subsetted_variable = numpy.ma.fix_invalid( variable(**cdms2keyargs) ) read_end_time = time.time() wpsLog.debug( " $$$ DATA READ Complete: " + str( (read_end_time-read_start_time) ) ) process_start_time = time.time() ( result_data, time_axis ) = self.applyOperation( subsetted_variable, self.operation ) process_end_time = time.time() wpsLog.debug( " $$$ DATA PROCESSING Complete: " + str( (process_end_time-process_start_time) ) ) # pydevd.settrace('localhost', port=8030, stdoutToServer=False, stderrToServer=True) if time_axis is not None: time_obj = record_attributes( time_axis, [ 'units', 'calendar' ] ) time_data = time_axis.getValue().tolist() try: time_obj['t0'] = time_data[0] time_obj['dt'] = time_data[1] - time_data[0] except Exception, err: time_obj['data'] = time_data result_obj['time'] = time_obj result_obj['data'] = result_data end_time = time.time() wpsLog.debug( " $$$ Execution complete, total time: %.2f sec", (end_time-start_time) )
def run( self, run_args ): operation = get_json_arg( 'operation', run_args ) kernel = self.getKernel( operation ) if kernel: result = kernel.run( run_args ) return result else: raise Exception( "No compute kernel found for operation %s" % str(operation) )