idx
int64
0
252k
question
stringlengths
48
5.28k
target
stringlengths
5
1.23k
4,600
def _set_subset_indices ( self , y_min , y_max , x_min , x_max ) : y_coords , x_coords = self . xd . lsm . coords dx = self . xd . lsm . dx dy = self . xd . lsm . dy lsm_y_indices_from_y , lsm_x_indices_from_y = np . where ( ( y_coords >= ( y_min - 2 * dy ) ) & ( y_coords <= ( y_max + 2 * dy ) ) ) lsm_y_indices_from_x ...
load subset based on extent
4,601
def _time_to_string ( self , dt , conversion_string = "%Y %m %d %H %M" ) : if self . output_timezone is not None : dt = dt . replace ( tzinfo = utc ) . astimezone ( self . output_timezone ) return dt . strftime ( conversion_string )
This converts a UTC time integer to a string
4,602
def _load_lsm_data ( self , data_var , conversion_factor = 1 , calc_4d_method = None , calc_4d_dim = None , time_step = None ) : data = self . xd . lsm . getvar ( data_var , yslice = self . yslice , xslice = self . xslice , calc_4d_method = calc_4d_method , calc_4d_dim = calc_4d_dim ) if isinstance ( time_step , dateti...
This extracts the LSM data from a folder of netcdf files
4,603
def _check_lsm_input ( self , data_var_map_array ) : REQUIRED_HMET_VAR_LIST = [ 'Prcp' , 'Pres' , 'Temp' , 'Clod' , 'RlHm' , 'Drad' , 'Grad' , 'WndS' ] given_hmet_var_list = [ ] for gssha_data_var , lsm_data_var in data_var_map_array : gssha_data_hmet_name = self . netcdf_attributes [ gssha_data_var ] [ 'hmet_name' ] i...
This function checks the input var map array to ensure the required input variables exist
4,604
def _resample_data ( self , gssha_var ) : self . data = self . data . lsm . resample ( gssha_var , self . gssha_grid )
This function resamples the data to match the GSSHA grid IN TESTING MODE
4,605
def _convert_data_to_hourly ( self , gssha_data_var ) : time_step_hours = np . diff ( self . data . time ) [ 0 ] / np . timedelta64 ( 1 , 'h' ) calc_function = self . _get_calc_function ( gssha_data_var ) resampled_data = None if time_step_hours < 1 : resampled_data = self . data . resample ( '1H' , dim = 'time' , how ...
This function converts the data to hourly data and then puts it into the data_np_array USED WHEN GENERATING HMET DATA ONLY
4,606
def lsm_var_to_grid ( self , out_grid_file , lsm_data_var , gssha_convert_var , time_step = 0 , ascii_format = 'grass' ) : self . _load_converted_gssha_data_from_lsm ( gssha_convert_var , lsm_data_var , 'grid' , time_step ) gssha_data_var_name = self . netcdf_attributes [ gssha_convert_var ] [ 'gssha_name' ] self . dat...
This function takes array data and writes out a GSSHA ascii grid .
4,607
def _write_hmet_card_file ( self , hmet_card_file_path , main_output_folder ) : with io_open ( hmet_card_file_path , 'w' ) as out_hmet_list_file : for hour_time in self . data . lsm . datetime : date_str = self . _time_to_string ( hour_time , "%Y%m%d%H" ) out_hmet_list_file . write ( u"{0}\n" . format ( path . join ( m...
This function writes the HMET_ASCII card file with ASCII file list for input to GSSHA
4,608
def lsm_data_to_arc_ascii ( self , data_var_map_array , main_output_folder = "" ) : self . _check_lsm_input ( data_var_map_array ) if not main_output_folder : main_output_folder = path . join ( self . gssha_project_folder , "hmet_ascii_data" ) try : mkdir ( main_output_folder ) except OSError : pass log . info ( "Outpu...
Writes extracted data to Arc ASCII file format into folder to be read in by GSSHA . Also generates the HMET_ASCII card file for GSSHA in the folder named hmet_file_list . txt .
4,609
def lsm_data_to_subset_netcdf ( self , netcdf_file_path , data_var_map_array , resample_method = None ) : self . _check_lsm_input ( data_var_map_array ) output_datasets = [ ] for gssha_var , lsm_var in data_var_map_array : if gssha_var in self . netcdf_attributes : self . _load_converted_gssha_data_from_lsm ( gssha_var...
Writes extracted data to the NetCDF file format
4,610
def export ( self , ** kwargs ) : query_params = { "_actions" : "false" , "_links" : "true" , "_embedded" : "true" } path_params = { } headers = { } body = None if "applicationId" in kwargs : path_params [ "applicationId" ] = kwargs [ "applicationId" ] if "query" in kwargs : body = kwargs [ "query" ] if "losantdomain" ...
Creates a csv file from a query of devices and attributes over a time range .
4,611
def _generate ( self , message ) : raw_params = { "INPUT_TEXT" : message . encode ( 'UTF8' ) , "INPUT_TYPE" : self . input_type , "OUTPUT_TYPE" : self . output_type , "LOCALE" : self . _locale , "AUDIO" : self . audio , "VOICE" : self . _voice , } params = urlencode ( raw_params ) headers = { } logging . debug ( 'maryc...
Given a message in message return a response in the appropriate format .
4,612
def receive ( self , msg ) : if msg [ TYPE ] == TELL and msg [ METHOD ] == 'stop' : self . running = False self . future_manager . stop ( ) else : result = None try : invoke = getattr ( self . _obj , msg [ METHOD ] ) params = msg [ PARAMS ] result = invoke ( * params [ 0 ] , ** params [ 1 ] ) except Exception , e : if ...
The message received from the queue specify a method of the class the actor represents . This invokes it . If the communication is an ASK sends the result back to the channel included in the message as an ASKRESPONSE .
4,613
def download_file ( url ) : response = requests . get ( url ) if response . status_code is not 200 : return None return response . text
Downloads a file from the specified URL .
4,614
def get_sub_dsp ( self , nodes_bunch , edges_bunch = None ) : nodes_bunch = [ self . get_node ( u ) [ 1 ] [ 0 ] for u in nodes_bunch ] sub_dsp = self . copy_structure ( dmap = self . dmap . subgraph ( nodes_bunch ) . copy ( ) ) nodes , dmap_out_degree = sub_dsp . nodes , sub_dsp . dmap . out_degree dmap_dv , dmap_rm_ed...
Returns the sub - dispatcher induced by given node and edge bunches .
4,615
def data_nodes ( self ) : return { k : v for k , v in self . nodes . items ( ) if v [ 'type' ] == 'data' }
Returns all data nodes of the dispatcher .
4,616
def function_nodes ( self ) : return { k : v for k , v in self . nodes . items ( ) if v [ 'type' ] == 'function' }
Returns all function nodes of the dispatcher .
4,617
def sub_dsp_nodes ( self ) : return { k : v for k , v in self . nodes . items ( ) if v [ 'type' ] == 'dispatcher' }
Returns all sub - dispatcher nodes of the dispatcher .
4,618
def blue ( self , memo = None ) : memo = { } if memo is None else memo if self in memo : return memo [ self ] from . utils . dsp import map_list from . utils . blue import BlueDispatcher , _parent_blue memo [ self ] = blue = BlueDispatcher ( executor = self . executor , name = self . name , raises = self . raises , des...
Constructs a BlueDispatcher out of the current object .
4,619
def extend ( self , * blues , memo = None ) : from . utils . blue import BlueDispatcher as Blue return Blue ( ) . extend ( * blues , memo = memo ) . register ( self , memo = memo )
Extends Dispatcher calling each deferred operation of given Blueprints .
4,620
def dispatch ( self , inputs = None , outputs = None , cutoff = None , inputs_dist = None , wildcard = False , no_call = False , shrink = False , rm_unused_nds = False , select_output_kw = None , _wait_in = None , stopper = None , executor = False , sol_name = ( ) ) : dsp = self if not no_call : if shrink : dsp = self ...
Evaluates the minimum workflow and data outputs of the dispatcher model from given inputs .
4,621
def shrink_dsp ( self , inputs = None , outputs = None , cutoff = None , inputs_dist = None , wildcard = True ) : bfs = None if inputs : wait_in = self . _get_wait_in ( flag = False ) o = self . dispatch ( inputs , outputs , cutoff , inputs_dist , wildcard , True , False , True , _wait_in = wait_in ) data_nodes = self ...
Returns a reduced dispatcher .
4,622
def _get_dsp_from_bfs ( self , outputs , bfs_graphs = None ) : bfs = bfs_graphs [ NONE ] if bfs_graphs is not None else self . dmap dsp = self . get_sub_dsp_from_workflow ( sources = outputs , graph = bfs , reverse = True , _update_links = False ) succ , nodes , pred = dsp . dmap . succ , dsp . nodes , dsp . dmap . pre...
Returns the sub - dispatcher induced by the workflow from outputs .
4,623
def add_callback ( self , method ) : from_actor = get_current ( ) if from_actor is not None : callback = ( method , from_actor . channel , from_actor . url ) with self . __condition : if self . __state is not FINISHED : self . __callbacks . append ( callback ) return msg = { TYPE : TELL , METHOD : method , PARAMS : ( [...
Attaches a mehtod that will be called when the future finishes .
4,624
def send_work ( self ) : if self . __set_running ( ) : msg = { TYPE : FUTURE , METHOD : self . __method , PARAMS : self . __params , CHANNEL : self . __channel , TO : self . __target , RPC_ID : self . __id } self . __actor_channel . send ( msg ) else : raise FutureError ( "Future already running." )
Sends the query to the actor for it to start executing the work .
4,625
def set_result ( self , result ) : with self . __condition : self . __result = result self . __state = FINISHED self . __condition . notify_all ( ) self . _invoke_callbacks ( )
Sets the return value of work associated with the future . Only called internally .
4,626
def set_exception ( self , exception ) : with self . __condition : self . __exception = exception self . __state = FINISHED self . __condition . notify_all ( ) self . _invoke_callbacks ( )
Sets the result of the future as being the given exception . Only called internally .
4,627
def angle_between_vectors ( x , y ) : dp = dot_product ( x , y ) if dp == 0 : return 0 xm = magnitude ( x ) ym = magnitude ( y ) return math . acos ( dp / ( xm * ym ) ) * ( 180. / math . pi )
Compute the angle between vector x and y
4,628
def _ssh_forward_accept ( ssh_session , timeout_ms ) : ssh_channel = c_ssh_forward_accept ( c_void_p ( ssh_session ) , c_int ( timeout_ms ) ) if ssh_channel is None : raise SshTimeoutException ( ) return ssh_channel
Waiting for an incoming connection from a reverse forwarded port . Note that this results in a kernel block until a connection is received .
4,629
def execute ( self , cmd , block_size = DEFAULT_EXECUTE_READ_BLOCK_SIZE ) : with SshChannel ( self ) as sc : self . __log . debug ( "Executing command: %s" % ( cmd ) ) sc . open_session ( ) sc . request_exec ( cmd ) buffer_ = bytearray ( ) while 1 : bytes = sc . read ( block_size ) yield bytes if len ( bytes ) < block_...
Execute a remote command . This functionality does not support more than one command to be executed on the same channel so we create a dedicated channel at the session level than allowing direct access at the channel level .
4,630
def _read ( self , directory , filename , session , path , name , extension , spatial , spatialReferenceID , replaceParamFile , force_relative = True ) : self . project_directory = directory with tmp_chdir ( directory ) : HEADERS = ( 'GSSHAPROJECT' , ) WMS_CARDS = ( '#INDEXGRID_GUID' , '#PROJECTION_FILE' , '#LandSoil' ...
Project File Read from File Method
4,631
def _write ( self , session , openFile , replaceParamFile ) : PRIORITY_CARDS = ( 'WMS' , 'MASK_WATERSHED' , 'REPLACE_LINE' , 'REPLACE_PARAMS' , 'REPLACE_VALS' , 'REPLACE_FOLDER' ) filename = os . path . split ( openFile . name ) [ 1 ] name = filename . split ( '.' ) [ 0 ] openFile . write ( 'GSSHAPROJECT\n' ) for card_...
Project File Write to File Method
4,632
def appendDirectory ( self , directory , projectFilePath ) : lines = [ ] with open ( projectFilePath , 'r' ) as original : for l in original : lines . append ( l ) with open ( projectFilePath , 'w' ) as new : for line in lines : card = { } try : card = self . _extractCard ( line ) except : card = self . _extractDirecto...
Append directory to relative paths in project file . By default the project file paths are read and written as relative paths . Use this method to prepend a directory to all the paths in the project file .
4,633
def readProject ( self , directory , projectFileName , session , spatial = False , spatialReferenceID = None ) : self . project_directory = directory with tmp_chdir ( directory ) : session . add ( self ) self . read ( directory , projectFileName , session , spatial = spatial , spatialReferenceID = spatialReferenceID ) ...
Read all files for a GSSHA project into the database .
4,634
def readInput ( self , directory , projectFileName , session , spatial = False , spatialReferenceID = None ) : self . project_directory = directory with tmp_chdir ( directory ) : session . add ( self ) self . read ( directory , projectFileName , session , spatial , spatialReferenceID ) if spatialReferenceID is None : s...
Read only input files for a GSSHA project into the database .
4,635
def readOutput ( self , directory , projectFileName , session , spatial = False , spatialReferenceID = None ) : self . project_directory = directory with tmp_chdir ( directory ) : session . add ( self ) self . read ( directory , projectFileName , session , spatial , spatialReferenceID ) batchDirectory = self . _getBatc...
Read only output files for a GSSHA project to the database .
4,636
def _readXputFile ( self , file_cards , card_name , directory , session , spatial = False , spatialReferenceID = None , replaceParamFile = None , ** kwargs ) : if spatialReferenceID is None : spatialReferenceID = self . _automaticallyDeriveSpatialReferenceId ( directory ) card = self . getCard ( card_name ) if card : f...
Read specific IO file for a GSSHA project to the database .
4,637
def writeProject ( self , session , directory , name ) : self . project_directory = directory with tmp_chdir ( directory ) : batchDirectory = self . _getBatchDirectory ( directory ) replaceParamFile = self . replaceParamFile self . _writeReplacementFiles ( session = session , directory = directory , name = name ) self ...
Write all files for a project from the database to file .
4,638
def writeInput ( self , session , directory , name ) : self . project_directory = directory with tmp_chdir ( directory ) : replaceParamFile = self . replaceParamFile self . write ( session = session , directory = directory , name = name ) self . _writeXput ( session = session , directory = directory , fileCards = self ...
Write only input files for a GSSHA project from the database to file .
4,639
def writeOutput ( self , session , directory , name ) : self . project_directory = directory with tmp_chdir ( directory ) : batchDirectory = self . _getBatchDirectory ( directory ) self . _writeReplacementFiles ( session = session , directory = directory , name = name ) self . write ( session = session , directory = di...
Write only output files for a GSSHA project from the database to file .
4,640
def getFileKeys ( self ) : files = self . getFileObjects ( ) files_list = [ ] for key , value in files . iteritems ( ) : if value : files_list . append ( key ) return files_list
Retrieve a list of file keys that have been read into the database .
4,641
def getFileObjects ( self ) : files = { 'project-file' : self , 'mapping-table-file' : self . mapTableFile , 'channel-input-file' : self . channelInputFile , 'precipitation-file' : self . precipFile , 'storm-pipe-network-file' : self . stormPipeNetworkFile , 'hmet-file' : self . hmetFile , 'nwsrfs-file' : self . nwsrfs...
Retrieve a dictionary of file objects .
4,642
def getCard ( self , name ) : cards = self . projectCards for card in cards : if card . name . upper ( ) == name . upper ( ) : return card return None
Retrieve card object for given card name .
4,643
def deleteCard ( self , card_name , db_session ) : card_name = card_name . upper ( ) gssha_card = self . getCard ( card_name ) if gssha_card is not None : db_session . delete ( gssha_card ) db_session . commit ( )
Removes card from gssha project file
4,644
def getGridByCard ( self , gssha_card_name ) : with tmp_chdir ( self . project_directory ) : if gssha_card_name not in ( self . INPUT_MAPS + self . WMS_DATASETS ) : raise ValueError ( "Card {0} not found in valid grid cards ..." . format ( gssha_card_name ) ) gssha_grid_card = self . getCard ( gssha_card_name ) if gssh...
Returns GDALGrid object of GSSHA grid
4,645
def getGrid ( self , use_mask = True ) : grid_card_name = "WATERSHED_MASK" if not use_mask : grid_card_name = "ELEVATION" return self . getGridByCard ( grid_card_name )
Returns GDALGrid object of GSSHA model bounds
4,646
def getIndexGrid ( self , name ) : index_map = self . mapTableFile . indexMaps . filter_by ( name = name ) . one ( ) gssha_pro_card = self . getCard ( "#PROJECTION_FILE" ) if gssha_pro_card is None : raise ValueError ( "#PROJECTION_FILE card not found ..." ) with tmp_chdir ( self . project_directory ) : return GDALGrid...
Returns GDALGrid object of index map
4,647
def getWkt ( self ) : gssha_pro_card = self . getCard ( "#PROJECTION_FILE" ) if gssha_pro_card is None : raise ValueError ( "#PROJECTION_FILE card not found ..." ) with tmp_chdir ( self . project_directory ) : gssha_prj_file = gssha_pro_card . value . strip ( '"' ) . strip ( "'" ) with open ( gssha_prj_file ) as pro_fi...
Returns GSSHA projection WKT string
4,648
def getOutlet ( self ) : outrow = int ( self . getCard ( name = 'OUTROW' ) . value ) - 1 outcol = int ( self . getCard ( name = 'OUTCOL' ) . value ) - 1 gssha_grid = self . getGrid ( ) return gssha_grid . pixel2lonlat ( outcol , outrow )
Gets the outlet latitude and longitude .
4,649
def setOutlet ( self , col , row , outslope = None ) : gssha_grid = self . getGrid ( ) self . setCard ( name = 'OUTROW' , value = str ( row ) ) self . setCard ( name = 'OUTCOL' , value = str ( col ) ) if outslope is None : self . calculateOutletSlope ( ) else : self . setCard ( name = 'OUTSLOPE' , value = str ( outslop...
Sets the outlet grid cell information in the project file .
4,650
def findOutlet ( self , shapefile_path ) : check_watershed_boundary_geometry ( shapefile_path ) shapefile = ogr . Open ( shapefile_path ) source_layer = shapefile . GetLayer ( 0 ) source_lyr_proj = source_layer . GetSpatialRef ( ) osr_geographic_proj = osr . SpatialReference ( ) osr_geographic_proj . ImportFromEPSG ( 4...
Calculate outlet location
4,651
def calculateOutletSlope ( self ) : try : mask_grid = self . getGrid ( ) elevation_grid = self . getGrid ( use_mask = False ) outrow = int ( self . getCard ( "OUTROW" ) . value ) - 1 outcol = int ( self . getCard ( "OUTCOL" ) . value ) - 1 cell_size = float ( self . getCard ( "GRIDSIZE" ) . value ) min_row = max ( 0 , ...
Attempt to determine the slope at the OUTLET
4,652
def timezone ( self ) : if self . _tz is None : cen_lat , cen_lon = self . centerLatLon ( ) tf = TimezoneFinder ( ) tz_name = tf . timezone_at ( lng = cen_lon , lat = cen_lat ) self . _tz = timezone ( tz_name ) return self . _tz
timezone of GSSHA model
4,653
def _getBatchDirectory ( self , projectRootDirectory ) : batchDirectory = projectRootDirectory replaceFolderCard = self . getCard ( 'REPLACE_FOLDER' ) if replaceFolderCard : replaceDir = replaceFolderCard . value . strip ( '"' ) batchDirectory = os . path . join ( batchDirectory , replaceDir ) if not os . path . isdir ...
Check the project file for the REPLACE_FOLDER card . If it exists append it s value to create the batch directory path . This is the directory output is written to when run in batch mode .
4,654
def _readXput ( self , fileCards , directory , session , spatial = False , spatialReferenceID = 4236 , replaceParamFile = None ) : for card in self . projectCards : if ( card . name in fileCards ) and self . _noneOrNumValue ( card . value ) and fileCards [ card . name ] : fileIO = fileCards [ card . name ] filename = c...
GSSHAPY Project Read Files from File Method
4,655
def _readXputMaps ( self , mapCards , directory , session , spatial = False , spatialReferenceID = 4236 , replaceParamFile = None ) : if self . mapType in self . MAP_TYPES_SUPPORTED : for card in self . projectCards : if ( card . name in mapCards ) and self . _noneOrNumValue ( card . value ) : filename = card . value ....
GSSHA Project Read Map Files from File Method
4,656
def _readWMSDatasets ( self , datasetCards , directory , session , spatial = False , spatialReferenceID = 4236 ) : if self . mapType in self . MAP_TYPES_SUPPORTED : maskMap = session . query ( RasterMapFile ) . filter ( RasterMapFile . projectFile == self ) . filter ( RasterMapFile . fileExtension == 'msk' ) . one ( ) ...
Method to handle the special case of WMS Dataset Files . WMS Dataset Files cannot be read in independently as other types of file can . They rely on the Mask Map file for some parameters .
4,657
def _readBatchOutputForFile ( self , directory , fileIO , filename , session , spatial , spatialReferenceID , replaceParamFile = None , maskMap = None ) : directoryList = os . listdir ( directory ) batchFiles = [ ] for thing in directoryList : if filename in thing : batchFiles . append ( thing ) numFilesRead = 0 for ba...
When batch mode is run in GSSHA the files of the same type are prepended with an integer to avoid filename conflicts . This will attempt to read files in this format and throw warnings if the files aren t found .
4,658
def _invokeRead ( self , fileIO , directory , filename , session , spatial = False , spatialReferenceID = 4236 , replaceParamFile = None , ** kwargs ) : path = os . path . join ( directory , filename ) if os . path . isfile ( path ) : instance = fileIO ( ) instance . projectFile = self instance . read ( directory , fil...
Invoke File Read Method on Other Files
4,659
def _writeXput ( self , session , directory , fileCards , name = None , replaceParamFile = None ) : for card in self . projectCards : if ( card . name in fileCards ) and self . _noneOrNumValue ( card . value ) and fileCards [ card . name ] : fileIO = fileCards [ card . name ] filename = card . value . strip ( '"' ) if ...
GSSHA Project Write Files to File Method
4,660
def _writeXputMaps ( self , session , directory , mapCards , name = None , replaceParamFile = None ) : if self . mapType in self . MAP_TYPES_SUPPORTED : for card in self . projectCards : if ( card . name in mapCards ) and self . _noneOrNumValue ( card . value ) : filename = card . value . strip ( '"' ) filename = self ...
GSSHAPY Project Write Map Files to File Method
4,661
def _writeWMSDatasets ( self , session , directory , wmsDatasetCards , name = None ) : if self . mapType in self . MAP_TYPES_SUPPORTED : for card in self . projectCards : if ( card . name in wmsDatasetCards ) and self . _noneOrNumValue ( card . value ) : filename = card . value . strip ( '"' ) filename = self . _replac...
GSSHAPY Project Write WMS Datasets to File Method
4,662
def _writeReplacementFiles ( self , session , directory , name ) : if self . replaceParamFile : self . replaceParamFile . write ( session = session , directory = directory , name = name ) if self . replaceValFile : self . replaceValFile . write ( session = session , directory = directory , name = name )
Write the replacement files
4,663
def _invokeWrite ( self , fileIO , session , directory , filename , replaceParamFile ) : instance = None try : instance = session . query ( fileIO ) . filter ( fileIO . projectFile == self ) . one ( ) except : extension = filename . split ( '.' ) [ 1 ] try : instance = session . query ( fileIO ) . filter ( fileIO . pro...
Invoke File Write Method on Other Files
4,664
def write ( self , originalPrefix , newPrefix = None ) : numSpaces = max ( 2 , 25 - len ( self . name ) ) if self . value is None : line = '%s\n' % self . name else : if self . name == 'WMS' : line = '%s %s\n' % ( self . name , self . value ) elif newPrefix is None : line = '%s%s%s\n' % ( self . name , ' ' * numSpaces ...
Write project card to string .
4,665
def elapsed ( self ) : if not self . started or self . _start_time is None : return 0.0 return self . _timing_data [ - 1 ] [ 0 ] - self . _start_time
Returns the number of seconds it has been since the start until the latest entry .
4,666
def rate_unstable ( self ) : if not self . started or self . stalled : return 0.0 x1 , y1 = self . _timing_data [ - 2 ] x2 , y2 = self . _timing_data [ - 1 ] return ( y2 - y1 ) / ( x2 - x1 )
Returns an unstable rate based on the last two entries in the timing data . Less intensive to compute .
4,667
def rate_overall ( self ) : elapsed = self . elapsed return self . rate if not elapsed else self . numerator / self . elapsed
Returns the overall average rate based on the start time .
4,668
def _calculate ( self ) : mean_x = sum ( i [ 0 ] for i in self . _timing_data ) / len ( self . _timing_data ) mean_y = sum ( i [ 1 ] for i in self . _timing_data ) / len ( self . _timing_data ) std_x = sqrt ( sum ( pow ( i [ 0 ] - mean_x , 2 ) for i in self . _timing_data ) / ( len ( self . _timing_data ) - 1 ) ) std_y...
Perform the ETA and rate calculation .
4,669
def _read ( self , directory , filename , session , path , name , extension , spatial , spatialReferenceID , replaceParamFile ) : self . fileExtension = extension with open ( path , 'r' ) as hmetFile : for line in hmetFile : sline = line . strip ( ) . split ( ) try : dateTime = datetime ( int ( sline [ 0 ] ) , int ( sl...
Read HMET WES from File Method
4,670
def _write ( self , session , openFile , replaceParamFile ) : hmetRecords = self . hmetRecords for record in hmetRecords : openFile . write ( '%s\t%s\t%s\t%s\t%.3f\t%s\t%s\t%s\t%s\t%.2f\t%.2f\n' % ( record . hmetDateTime . year , record . hmetDateTime . month , record . hmetDateTime . day , record . hmetDateTime . hour...
Write HMET WES to File Method
4,671
def _read ( self , directory , filename , session , path , name , extension , spatial = None , spatialReferenceID = None , replaceParamFile = None ) : yml_events = [ ] with open ( path ) as fo : yml_events = yaml . load ( fo ) for yml_event in yml_events : if os . path . exists ( os . path . join ( directory , yml_even...
ProjectFileEvent Read from File Method
4,672
def as_yml ( self ) : return YmlFileEvent ( name = str ( self . name ) , subfolder = str ( self . subfolder ) )
Return yml compatible version of self
4,673
def prepare_request ( node ) : if node . resource . method not in AVAILABLE_METHODS : raise UnsupportedHTTPMethodError ( node . resource . method ) def request ( data = None , json = None , ** kwargs ) : for key , value in kwargs . items ( ) : param = next ( ( p for p in node . resource . query_params if p . name == ke...
Prepare request to node s API route
4,674
def define_plot_data ( data , x_name , * y_names ) : it = [ ] for k in y_names : it . append ( { 'x' : data [ x_name ] , 'y' : data [ k ] , 'name' : k } ) return it
Defines the data to be plotted .
4,675
def plot_lines ( it ) : data = [ go . Scatter ( mode = 'lines' , ** d ) for d in it ] return py . iplot ( data , filename = 'scatter-mode' )
Plotting lines .
4,676
def _ssh_channel_read ( ssh_channel_int , count , is_stderr ) : buffer_ = create_string_buffer ( count ) while 1 : received_bytes = c_ssh_channel_read ( ssh_channel_int , cast ( buffer_ , c_void_p ) , c_uint32 ( count ) , c_int ( int ( is_stderr ) ) ) if received_bytes == SSH_ERROR : ssh_session_int = _ssh_channel_get_...
Do a read on a channel .
4,677
def eventChunk ( key , lines ) : KEYWORDS = ( 'EVENT' , 'NRPDS' , 'NRGAG' , 'COORD' , 'GAGES' , 'ACCUM' , 'RATES' , 'RADAR' ) NUM_CARDS = ( 'NRPDS' , 'NRGAG' ) VALUE_CARDS = ( 'GAGES' , 'ACCUM' , 'RATES' , 'RADAR' ) result = { 'description' : None , 'nrgag' : None , 'nrpds' : None , 'coords' : [ ] , 'valLines' : [ ] } ...
Parse EVENT chunks
4,678
def request ( self , method , path , params = None , headers = None , body = None ) : if not headers : headers = { } if not params : params = { } headers [ "Accept" ] = "application/json" headers [ "Accept-Version" ] = "^1.15.0" if self . auth_token : headers [ "Authorization" ] = "Bearer {0}" . format ( self . auth_to...
Base method for making a Losant API request
4,679
def flatten_params ( self , data , base_key = None ) : result = { } if data is None : return result map_data = None if not isinstance ( data , collections . Mapping ) : map_data = [ ] for idx , val in enumerate ( data ) : map_data . append ( [ str ( idx ) , val ] ) else : map_data = list ( data . items ( ) ) for key , ...
Flatten out nested arrays and dicts in query params into correct format
4,680
def read_excel ( input_fpath ) : return { k : v . values for k , v in pd . read_excel ( input_fpath ) . items ( ) }
Reads the excel file .
4,681
def save_outputs ( outputs , output_fpath ) : df = pd . DataFrame ( outputs ) with pd . ExcelWriter ( output_fpath ) as writer : df . to_excel ( writer )
Save model outputs in an Excel file .
4,682
def _read ( self , directory , filename , session , path , name , extension , spatial , spatialReferenceID , replaceParamFile ) : self . fileExtension = extension KEYWORDS = ( 'EVENT' , ) with open ( path , 'r' ) as f : chunks = pt . chunk ( KEYWORDS , f ) for key , chunkList in iteritems ( chunks ) : for chunk in chun...
Precipitation Read from File Method
4,683
def _write ( self , session , openFile , replaceParamFile ) : events = self . precipEvents for event in events : openFile . write ( 'EVENT "%s"\nNRGAG %s\nNRPDS %s\n' % ( event . description , event . nrGag , event . nrPds ) ) if event . nrGag > 0 : values = event . values valList = [ ] for value in values : valList . ...
Precipitation File Write to File Method
4,684
def _createGsshaPyObjects ( self , eventChunk ) : event = PrecipEvent ( description = eventChunk [ 'description' ] , nrGag = eventChunk [ 'nrgag' ] , nrPds = eventChunk [ 'nrpds' ] ) event . precipFile = self gages = [ ] for coord in eventChunk [ 'coords' ] : gage = PrecipGage ( description = coord [ 'description' ] , ...
Create GSSHAPY PrecipEvent PrecipValue and PrecipGage Objects Method
4,685
def lookupSpatialReferenceID ( cls , directory , filename ) : path = os . path . join ( directory , filename ) with open ( path , 'r' ) as f : srid = lookupSpatialReferenceID ( f . read ( ) ) return srid
Look up spatial reference system using the projection file .
4,686
def _read ( self , directory , filename , session , path , name , extension , spatial , spatialReferenceID , replaceParamFile ) : self . fileExtension = extension with io_open ( path , 'r' ) as f : self . projection = f . read ( )
Projection File Read from File Method
4,687
def _write ( self , session , openFile , replaceParamFile ) : openFile . write ( text ( self . projection ) )
Projection File Write to File Method
4,688
def numerator ( self , value ) : if self . eta_every <= 1 : self . _eta . numerator = value self . _eta_string = self . _generate_eta ( self . _eta . eta_seconds ) return if self . _eta . undefined : self . _eta . set_numerator ( value , calculate = False ) return if self . _eta_count >= self . eta_every : self . _eta_...
Sets a new numerator and generates the ETA . Must be greater than or equal to previous numerator .
4,689
def rate ( self ) : return float ( self . _eta . rate_unstable if self . eta_every > 1 else self . _eta . rate )
Returns the rate of the progress as a float . Selects the unstable rate if eta_every > 1 for performance .
4,690
def generateFromRaster ( self , elevation_raster , shapefile_path = None , out_elevation_grid = None , resample_method = gdalconst . GRA_Average , load_raster_to_db = True ) : if not self . projectFile : raise ValueError ( "Must be connected to project file ..." ) elevation_raster = os . path . abspath ( elevation_rast...
Generates an elevation grid for the GSSHA simulation from an elevation raster
4,691
def _read ( self , directory , filename , session , path , name , extension , spatial , spatialReferenceID , replaceParamFile ) : self . fileExtension = extension KEYWORDS = { 'CONNECT' : spc . connectChunk , 'SJUNC' : spc . sjuncChunk , 'SLINK' : spc . slinkChunk } sjuncs = [ ] slinks = [ ] connections = [ ] with open...
Storm Pipe Network File Read from File Method
4,692
def _write ( self , session , openFile , replaceParamFile ) : connections = self . connections self . _writeConnections ( connections = connections , fileObject = openFile ) sjuncs = self . superJunctions self . _writeSuperJunctions ( superJunctions = sjuncs , fileObject = openFile ) slinks = self . superLinks self . _...
Storm Pipe Network File Write to File Method
4,693
def _createConnection ( self , connections ) : for c in connections : connection = Connection ( slinkNumber = c [ 'slinkNumber' ] , upSjuncNumber = c [ 'upSjunc' ] , downSjuncNumber = c [ 'downSjunc' ] ) connection . stormPipeNetworkFile = self
Create GSSHAPY Connection Objects Method
4,694
def _createSlink ( self , slinks ) : for slink in slinks : superLink = SuperLink ( slinkNumber = slink [ 'slinkNumber' ] , numPipes = slink [ 'numPipes' ] ) superLink . stormPipeNetworkFile = self for node in slink [ 'nodes' ] : superNode = SuperNode ( nodeNumber = node [ 'nodeNumber' ] , groundSurfaceElev = node [ 'gr...
Create GSSHAPY SuperLink Pipe and SuperNode Objects Method
4,695
def _createSjunc ( self , sjuncs ) : for sjunc in sjuncs : superJunction = SuperJunction ( sjuncNumber = sjunc [ 'sjuncNumber' ] , groundSurfaceElev = sjunc [ 'groundSurfaceElev' ] , invertElev = sjunc [ 'invertElev' ] , manholeSA = sjunc [ 'manholeSA' ] , inletCode = sjunc [ 'inletCode' ] , linkOrCellI = sjunc [ 'link...
Create GSSHAPY SuperJunction Objects Method
4,696
def _writeConnections ( self , connections , fileObject ) : for connection in connections : fileObject . write ( 'CONNECT %s %s %s\n' % ( connection . slinkNumber , connection . upSjuncNumber , connection . downSjuncNumber ) )
Write Connections to File Method
4,697
def _writeSuperJunctions ( self , superJunctions , fileObject ) : for sjunc in superJunctions : fileObject . write ( 'SJUNC %s %.2f %.2f %.6f %s %s %s %.6f %.6f\n' % ( sjunc . sjuncNumber , sjunc . groundSurfaceElev , sjunc . invertElev , sjunc . manholeSA , sjunc . inletCode , sjunc . linkOrCellI , sjunc . no...
Write SuperJunctions to File Method
4,698
def _writeSuperLinks ( self , superLinks , fileObject ) : for slink in superLinks : fileObject . write ( 'SLINK %s %s\n' % ( slink . slinkNumber , slink . numPipes ) ) for node in slink . superNodes : fileObject . write ( 'NODE %s %.2f %.2f %.6f %s %s %s %.6f %.6f\n' % ( node . nodeNumber , node . groun...
Write SuperLinks to File Method
4,699
def ziegler_nichols ( self , ku , tu , control_type = 'pid' ) : converter = dict ( p = lambda ku , tu : ( .5 * ku , 0 , 0 ) , pi = lambda ku , tu : ( .45 * ku , 1.2 * ( .45 * ku ) / tu , 0 ) , pd = lambda ku , tu : ( .8 * ku , 0 , ( .8 * ku ) * tu / 8 ) , pid = lambda ku , tu : ( .6 * ku , 2 * ( .6 * ku ) / tu , ( .6 *...
ku = ultimate gain tu = period of oscillation at ultimate gain