signature stringlengths 29 44.1k | implementation stringlengths 0 85.2k |
|---|---|
def get_client_rect ( self ) :
"""Get the window ' s client area coordinates in the desktop .
@ rtype : L { win32 . Rect }
@ return : Rectangle occupied by the window ' s client area in the desktop .
@ raise WindowsError : An error occured while processing this request .""" | cr = win32 . GetClientRect ( self . get_handle ( ) )
cr . left , cr . top = self . client_to_screen ( cr . left , cr . top )
cr . right , cr . bottom = self . client_to_screen ( cr . right , cr . bottom )
return cr |
def new ( self , bootstrap_with = None , use_timer = False , incr = False , with_proof = False ) :
"""Actual constructor of the solver .""" | assert not incr or not with_proof , 'Incremental mode and proof tracing cannot be set together.'
if not self . glucose :
self . glucose = pysolvers . glucose41_new ( )
if bootstrap_with :
for clause in bootstrap_with :
self . add_clause ( clause )
self . use_timer = use_timer
self . ... |
def get_asset_content_lookup_session ( self , proxy = None ) :
"""Gets the ` ` OsidSession ` ` associated with the asset content lookup service .
return : ( osid . repository . AssetLookupSession ) - the new
` ` AssetLookupSession ` `
raise : OperationFailed - unable to complete request
raise : Unimplemente... | return AssetContentLookupSession ( self . _provider_manager . get_asset_content_lookup_session ( proxy ) , self . _config_map ) |
def create_unique_autosave_filename ( self , filename , autosave_dir ) :
"""Create unique autosave file name for specified file name .
Args :
filename ( str ) : original file name
autosave _ dir ( str ) : directory in which autosave files are stored""" | basename = osp . basename ( filename )
autosave_filename = osp . join ( autosave_dir , basename )
if autosave_filename in self . name_mapping . values ( ) :
counter = 0
root , ext = osp . splitext ( basename )
while autosave_filename in self . name_mapping . values ( ) :
counter += 1
autosav... |
def read_plink ( file_prefix , verbose = True ) :
r"""Read PLINK files into Pandas data frames .
Parameters
file _ prefix : str
Path prefix to the set of PLINK files . It supports loading many BED
files at once using globstrings wildcard .
verbose : bool
` ` True ` ` for progress information ; ` ` False... | from dask . array import concatenate
file_prefixes = sorted ( glob ( file_prefix ) )
if len ( file_prefixes ) == 0 :
file_prefixes = [ file_prefix . replace ( "*" , "" ) ]
file_prefixes = sorted ( _clean_prefixes ( file_prefixes ) )
fn = [ ]
for fp in file_prefixes :
fn . append ( { s : "%s.%s" % ( fp , s ) for... |
def get_domain_info ( self , domain ) :
"""Get the GoDaddy supplied information about a specific domain .
: param domain : The domain to obtain info about .
: type domain : str
: return A JSON string representing the domain information""" | url = self . API_TEMPLATE + self . DOMAIN_INFO . format ( domain = domain )
return self . _get_json_from_response ( url ) |
def store_oui ( self , port_uuid , oui_type , oui_data ) :
"""Function for storing the OUI .
param uuid : UUID of the vNIC
param oui _ type : OUI ID
param oui _ data : OUI Opaque Data""" | self . oui_vif_map [ port_uuid ] = { 'oui_id' : oui_type , 'oui_data' : oui_data } |
def create_command_history_subscription ( self , issued_command = None , on_data = None , timeout = 60 ) :
"""Create a new command history subscription .
: param . IssuedCommand [ ] issued _ command : ( Optional ) Previously issued
commands . If not provided updates
from any command are received .
: param o... | options = web_pb2 . CommandHistorySubscriptionRequest ( )
options . ignorePastCommands = True
if issued_command :
options . commandId . extend ( _build_command_ids ( issued_command ) )
manager = WebSocketSubscriptionManager ( self . _client , resource = 'cmdhistory' , options = options )
# Represent subscription as... |
def int_to_bytes ( int_ , width = None ) :
""". . _ int _ to _ bytes :
Converts the ` ` int ` ` ` ` int _ ` ` to a ` ` bytes ` ` object .
` ` len ( result ) = = width ` ` .
If ` ` width ` ` is None , a number of bytes that is able to hold the
number is choosen , depending on ` ` int _ . bit _ length ( ) ` `... | if ( width == None ) :
width = int_ . bit_length ( )
byts = math . ceil ( width / 8 )
return bytes ( [ ( int_ >> ( shift * 8 ) ) & 0xff for shift in range ( byts ) ] ) |
def line_distance_similarity ( p1a , p1b , p2a , p2b , T = CLOSE_DISTANCE_THRESHOLD ) :
"""Line distance similarity between two line segments
Args :
p1a ( [ float , float ] ) : x and y coordinates . Line A start
p1b ( [ float , float ] ) : x and y coordinates . Line A end
p2a ( [ float , float ] ) : x and y... | d1 = distance_similarity ( p1a , p1b , p2a , T = T )
d2 = distance_similarity ( p1a , p1b , p2b , T = T )
return abs ( d1 + d2 ) * 0.5 |
def _exclude_pattern ( self , pattern , anchor = True , prefix = None , is_regex = False ) :
"""Remove strings ( presumably filenames ) from ' files ' that match
' pattern ' .
Other parameters are the same as for ' include _ pattern ( ) ' , above .
The list ' self . files ' is modified in place . Return True ... | found = False
pattern_re = self . _translate_pattern ( pattern , anchor , prefix , is_regex )
for f in list ( self . files ) :
if pattern_re . search ( f ) :
self . files . remove ( f )
found = True
return found |
def explain_weights ( self , ** kwargs ) :
"""Call : func : ` eli5 . show _ weights ` for the locally - fit
classification pipeline . Keyword arguments are passed
to : func : ` eli5 . show _ weights ` .
: func : ` fit ` must be called before using this method .""" | self . _fix_target_names ( kwargs )
return eli5 . explain_weights ( self . clf_ , vec = self . vec_ , ** kwargs ) |
def _get_basin_response_term ( self , C , z2pt5 ) :
"""Returns the basin response term defined in equation 20""" | f_sed = np . zeros ( len ( z2pt5 ) )
idx = z2pt5 < 1.0
f_sed [ idx ] = ( C [ "c14" ] + C [ "c15" ] * float ( self . CONSTS [ "SJ" ] ) ) * ( z2pt5 [ idx ] - 1.0 )
idx = z2pt5 > 3.0
f_sed [ idx ] = C [ "c16" ] * C [ "k3" ] * exp ( - 0.75 ) * ( 1.0 - np . exp ( - 0.25 * ( z2pt5 [ idx ] - 3.0 ) ) )
return f_sed |
def autoIndentBlock ( self , block , char = '\n' ) :
"""Indent block after Enter pressed or trigger character typed""" | currentText = block . text ( )
spaceAtStartLen = len ( currentText ) - len ( currentText . lstrip ( ) )
currentIndent = currentText [ : spaceAtStartLen ]
indent = self . _smartIndenter . computeIndent ( block , char )
if indent is not None and indent != currentIndent :
self . _qpart . replaceText ( block . position... |
def get_sites ( self , filter_func = lambda x : True ) :
"""Returns a list of TSquareSite objects that represent the sites available
to a user .
@ param filter _ func - A function taking in a Site object as a parameter
that returns a True or False , depending on whether
or not that site should be returned b... | response = self . _session . get ( BASE_URL_TSQUARE + 'site.json' )
response . raise_for_status ( )
# raise an exception if not 200 : OK
site_list = response . json ( ) [ 'site_collection' ]
if not site_list : # this means that this t - square session expired . It ' s up
# to the user to re - authenticate .
self . ... |
def fillna ( self , value = None , method = None , limit = None ) :
"""Fill missing values with ` value ` .
Parameters
value : scalar , optional
method : str , optional
. . warning : :
Using ' method ' will result in high memory use ,
as all ` fill _ value ` methods will be converted to
an in - memory... | if ( ( method is None and value is None ) or ( method is not None and value is not None ) ) :
raise ValueError ( "Must specify one of 'method' or 'value'." )
elif method is not None :
msg = "fillna with 'method' requires high memory usage."
warnings . warn ( msg , PerformanceWarning )
filled = interpola... |
def bulk_overwrite ( self , entities_and_kinds ) :
"""Update the group to the given entities and sub - entity groups .
After this operation , the only members of this EntityGroup
will be the given entities , and sub - entity groups .
: type entities _ and _ kinds : List of ( Entity , EntityKind ) pairs .
: ... | EntityGroupMembership . objects . filter ( entity_group = self ) . delete ( )
return self . bulk_add_entities ( entities_and_kinds ) |
def check_variable_names ( self , ds ) :
"""Ensures all variables have a standard _ name set .""" | msgs = [ ]
count = 0
for k , v in ds . variables . items ( ) :
if 'standard_name' in v . ncattrs ( ) :
count += 1
else :
msgs . append ( "Variable '{}' missing standard_name attr" . format ( k ) )
return Result ( BaseCheck . MEDIUM , ( count , len ( ds . variables ) ) , 'Variable Names' , msgs ) |
def stats ( self , name , value ) :
"""Calculates min / average / max statistics based on the current and previous values .
: param name : a counter name of Statistics type
: param value : a value to update statistics""" | counter = self . get ( name , CounterType . Statistics )
self . _calculate_stats ( counter , value )
self . _update ( ) |
def loads ( s , key = None , salt = 'django.core.signing' , serializer = JSONSerializer , max_age = None ) :
"""Reverse of dumps ( ) , raise BadSignature if signature fails .
The serializer is expected to accept a bytestring .""" | # TimestampSigner . unsign ( ) returns str but base64 and zlib compression
# operate on bytes .
base64d = force_bytes ( TimestampSigner ( key , salt = salt ) . unsign ( s , max_age = max_age ) )
decompress = False
if base64d [ : 1 ] == b'.' : # It ' s compressed ; uncompress it first
base64d = base64d [ 1 : ]
d... |
def write_entrez2gene ( file_path , entrez2gene , logger ) :
"""Writes Entrez ID - > gene symbol mapping to a tab - delimited text file .
Parameters
file _ path : str
The path of the output file .
entrez2gene : dict
The mapping of Entrez IDs to gene symbols .
Returns
None""" | with misc . smart_open_write ( file_path , mode = 'wb' ) as ofh :
writer = csv . writer ( ofh , dialect = 'excel-tab' , lineterminator = os . linesep )
for k in sorted ( entrez2gene . keys ( ) , key = lambda x : int ( x ) ) :
writer . writerow ( [ k , entrez2gene [ k ] ] )
logger . info ( 'Output writte... |
def init ( self , single = None , swallow_exceptions = True ) :
"""Handles all important disk - mounting tasks , i . e . calls the : func : ` Disk . init ` function on all underlying
disks . It yields every volume that is encountered , including volumes that have not been mounted .
: param single : indicates wh... | for d in self . disks :
for v in d . init ( single , swallow_exceptions = swallow_exceptions ) :
yield v |
def build_losses ( self , logits_real , logits_fake ) :
"""Build standard GAN loss and set ` self . g _ loss ` and ` self . d _ loss ` .
D and G play two - player minimax game with value function V ( G , D )
min _ G max _ D V ( D , G ) = IE _ { x ~ p _ data } [ log D ( x ) ] + IE _ { z ~ p _ fake } [ log ( 1 - ... | with tf . name_scope ( "GAN_loss" ) :
score_real = tf . sigmoid ( logits_real )
score_fake = tf . sigmoid ( logits_fake )
tf . summary . histogram ( 'score-real' , score_real )
tf . summary . histogram ( 'score-fake' , score_fake )
with tf . name_scope ( "discrim" ) :
d_loss_pos = tf . reduc... |
def cns_vwl_pstr_long ( self ) :
"""Return a new IPAString , containing only :
1 . the consonants ,
2 . the vowels , and
3 . the primary stress diacritics , and
4 . the long suprasegmental
in the current string .
: rtype : IPAString""" | return IPAString ( ipa_chars = [ c for c in self . ipa_chars if ( c . is_letter ) or ( c . is_suprasegmental and ( c . is_primary_stress or c . is_long ) ) ] ) |
def create_function_f_y ( self ) :
"""output function""" | return ca . Function ( 'y' , [ self . t , self . x , self . m , self . p , self . c , self . ng , self . nu ] , [ self . y_rhs ] , [ 't' , 'x' , 'm' , 'p' , 'c' , 'ng' , 'nu' ] , [ 'y' ] , self . func_opt ) |
def get_valid_paths ( self , path ) :
"""There are some restrictions on the valid directory structures :
1 . There can be only one vasp run in each directory . Nested directories
are fine .
2 . Directories designated " relax1 " , " relax2 " are considered to be 2
parts of an aflow style run .
3 . Director... | ( parent , subdirs , files ) = path
if set ( self . runs ) . intersection ( subdirs ) :
return [ parent ]
if not any ( [ parent . endswith ( os . sep + r ) for r in self . runs ] ) and len ( glob . glob ( os . path . join ( parent , "vasprun.xml*" ) ) ) > 0 :
return [ parent ]
return [ ] |
def _output_text ( complete_output , categories ) :
"""Output the results obtained in text format .
: return : str , html formatted output""" | output = ""
for result in complete_output :
list_result = complete_output [ result ]
if list_result :
list_result_sorted = sorted ( list_result , key = lambda x : list_result [ x ] , reverse = True )
output += "\n\n{0}:\n" . format ( result )
for element in list_result_sorted :
... |
def crop_indices ( image , lowerind , upperind ) :
"""Create a proper ANTsImage sub - image by indexing the image with indices .
This is similar to but different from array sub - setting in that
the resulting sub - image can be decropped back into its place without
having to store its original index locations... | inpixeltype = 'float'
if image . pixeltype != 'float' :
inpixeltype = image . pixeltype
image = image . clone ( 'float' )
if ( image . dimension != len ( lowerind ) ) or ( image . dimension != len ( upperind ) ) :
raise ValueError ( 'image dimensionality and index length must match' )
libfn = utils . get_li... |
def datetime ( self ) :
"""[ datetime . datetime ] 当前快照数据的时间戳""" | try :
dt = self . _tick_dict [ 'datetime' ]
except ( KeyError , ValueError ) :
return datetime . datetime . min
else :
if not isinstance ( dt , datetime . datetime ) :
if dt > 10000000000000000 : # ms
return convert_ms_int_to_datetime ( dt )
else :
return convert_int_... |
def delete ( self ) :
"""DELETE / : login / machines / : id
Initiate deletion of a stopped remote machine .""" | j , r = self . datacenter . request ( 'DELETE' , self . path )
r . raise_for_status ( ) |
def _compute_labels ( self , element , data , mapping ) :
"""Computes labels for the nodes and adds it to the data .""" | if element . vdims :
edges = Dataset ( element ) [ element [ element . vdims [ 0 ] . name ] > 0 ]
nodes = list ( np . unique ( [ edges . dimension_values ( i ) for i in range ( 2 ) ] ) )
nodes = element . nodes . select ( ** { element . nodes . kdims [ 2 ] . name : nodes } )
else :
nodes = element
label... |
def makedirs_ ( path , owner = None , grant_perms = None , deny_perms = None , inheritance = True , reset = False ) :
'''Ensure that the parent directory containing this path is available .
Args :
path ( str ) :
The full path to the directory .
. . note : :
The path must end with a trailing slash otherwis... | path = os . path . expanduser ( path )
# walk up the directory structure until we find the first existing
# directory
dirname = os . path . normpath ( os . path . dirname ( path ) )
if os . path . isdir ( dirname ) : # There ' s nothing for us to do
msg = 'Directory \'{0}\' already exists' . format ( dirname )
... |
def profile ( model , inputs = None , n_texts = 10000 ) :
"""Profile a spaCy pipeline , to find out which functions take the most time .
Input should be formatted as one JSON object per line with a key " text " .
It can either be provided as a JSONL file , or be read from sys . sytdin .
If no input file is sp... | msg = Printer ( )
if inputs is not None :
inputs = _read_inputs ( inputs , msg )
if inputs is None :
n_inputs = 25000
with msg . loading ( "Loading IMDB dataset via Thinc..." ) :
imdb_train , _ = thinc . extra . datasets . imdb ( )
inputs , _ = zip ( * imdb_train )
msg . info ( "Loaded I... |
def mask_average ( dset , mask ) :
'''Returns average of voxels in ` ` dset ` ` within non - zero voxels of ` ` mask ` `''' | o = nl . run ( [ '3dmaskave' , '-q' , '-mask' , mask , dset ] )
if o :
return float ( o . output . split ( ) [ - 1 ] ) |
def __load ( self , path ) :
"""Method to load the serialized dataset from disk .""" | try :
path = os . path . abspath ( path )
with open ( path , 'rb' ) as df : # loaded _ dataset = pickle . load ( df )
self . __data , self . __classes , self . __labels , self . __dtype , self . __description , self . __num_features , self . __feature_names = pickle . load ( df )
# ensure the loaded... |
def _zom_arg ( lexer ) :
"""Return zero or more arguments .""" | tok = next ( lexer )
# ' , ' EXPR ZOM _ X
if isinstance ( tok , COMMA ) :
return ( _expr ( lexer ) , ) + _zom_arg ( lexer )
# null
else :
lexer . unpop_token ( tok )
return tuple ( ) |
def Filter ( self , function = None ) :
"""Construct Textable from the rows of which the function returns true .
Args :
function : A function applied to each row which returns a bool . If
function is None , all rows with empty column values are
removed .
Returns :
A new TextTable ( )
Raises :
TableE... | flat = lambda x : x if isinstance ( x , str ) else '' . join ( [ flat ( y ) for y in x ] )
if function is None :
function = lambda row : bool ( flat ( row . values ) )
new_table = self . __class__ ( )
# pylint : disable = protected - access
new_table . _table = [ self . header ]
for row in self :
if function ( ... |
async def remove ( self , * args , ** kwargs ) :
"""Delete Secret
Delete the secret associated with some key .
This method is ` ` stable ` `""" | return await self . _makeApiCall ( self . funcinfo [ "remove" ] , * args , ** kwargs ) |
def import_obj ( clsname , default_module = None ) :
"""Import the object given by clsname .
If default _ module is specified , import from this module .""" | if default_module is not None :
if not clsname . startswith ( default_module + '.' ) :
clsname = '{0}.{1}' . format ( default_module , clsname )
mod , clsname = clsname . rsplit ( '.' , 1 )
mod = importlib . import_module ( mod )
try :
obj = getattr ( mod , clsname )
except AttributeError :
raise Im... |
def assure_relation ( cls , cms_page ) :
"""Assure that we have a foreign key relation , pointing from CascadePage onto CMSPage .""" | try :
cms_page . cascadepage
except cls . DoesNotExist :
cls . objects . create ( extended_object = cms_page ) |
def bin_exact_kb_dense ( M , positions , length = 10 ) :
"""Perform the kb - binning procedure with total bin lengths being exactly
set to that of the specified input . Fragments overlapping two potential
bins will be split and related contact counts will be divided according
to overlap proportions in each bi... | unit = 10 ** 3
ul = unit * length
units = positions / ul
n = len ( positions )
idx = [ i for i in range ( n - 1 ) if np . ceil ( units [ i ] ) < np . ceil ( units [ i + 1 ] ) ]
m = len ( idx ) - 1
N = np . zeros ( ( m , m ) )
remainders = [ 0 ] + [ np . abs ( units [ i ] - units [ i + 1 ] ) for i in range ( m ) ]
for i... |
def RunMetadata ( self , run , tag ) :
"""Get the session . run ( ) metadata associated with a TensorFlow run and tag .
Args :
run : A string name of a TensorFlow run .
tag : A string name of the tag associated with a particular session . run ( ) .
Raises :
KeyError : If the run is not found , or the tag ... | accumulator = self . GetAccumulator ( run )
return accumulator . RunMetadata ( tag ) |
def _contentful_user_agent ( self ) :
"""Sets the X - Contentful - User - Agent header .""" | header = { }
from . import __version__
header [ 'sdk' ] = { 'name' : 'contentful-management.py' , 'version' : __version__ }
header [ 'app' ] = { 'name' : self . application_name , 'version' : self . application_version }
header [ 'integration' ] = { 'name' : self . integration_name , 'version' : self . integration_vers... |
def apply_partial_inheritance ( self , prop ) :
"""Define property with inheritance value of the property
: param prop : property
: type prop : str
: return : None""" | for i in itertools . chain ( iter ( list ( self . items . values ( ) ) ) , iter ( list ( self . templates . values ( ) ) ) ) :
self . get_property_by_inheritance ( i , prop )
# If a " null " attribute was inherited , delete it
try :
if getattr ( i , prop ) == 'null' :
delattr ( i , prop ... |
def add_actions ( self , entries , user_data = None ) :
"""The add _ actions ( ) method is a convenience method that creates a number
of gtk . Action objects based on the information in the list of action
entry tuples contained in entries and adds them to the action group .
The entry tuples can vary in size f... | try :
iter ( entries )
except ( TypeError ) :
raise TypeError ( 'entries must be iterable' )
def _process_action ( name , stock_id = None , label = None , accelerator = None , tooltip = None , callback = None ) :
action = Action ( name = name , label = label , tooltip = tooltip , stock_id = stock_id )
i... |
def surface_nodes ( self ) :
""": param points : a list of Point objects
: returns : a Node of kind ' griddedSurface '""" | line = [ ]
for point in self . mesh :
line . append ( point . longitude )
line . append ( point . latitude )
line . append ( point . depth )
return [ Node ( 'griddedSurface' , nodes = [ Node ( 'gml:posList' , { } , line ) ] ) ] |
def expire ( key , seconds , host = None , port = None , db = None , password = None ) :
'''Set a keys time to live in seconds
CLI Example :
. . code - block : : bash
salt ' * ' redis . expire foo 300''' | server = _connect ( host , port , db , password )
return server . expire ( key , seconds ) |
def head ( self , stream = 'stdout' , num_lines = 10 ) :
"""Head a specified stream ( stdout or stderr ) by num _ lines .""" | target = self . _map_string_to_file ( stream )
if not target : # no current temp file
last_run = self . backend . get_latest_run_log ( self . parent_job . job_id , self . name )
if not last_run :
return None
return self . _head_string ( last_run [ 'tasks' ] [ self . name ] [ stream ] , num_lines )
e... |
def index ( self ) :
"""Retrieve the attribute index number .
Args : :
no argument
Returns : :
attribute index number ( starting at 0)
C library equivalent : SDfindattr""" | self . _index = _C . SDfindattr ( self . _obj . _id , self . _name )
_checkErr ( 'find' , self . _index , 'illegal attribute name' )
return self . _index |
def old_properties_names_to_new ( self ) : # pragma : no cover , never called
"""Convert old Nagios2 names to Nagios3 new names
TODO : still useful ?
: return : None""" | for i in itertools . chain ( iter ( list ( self . items . values ( ) ) ) , iter ( list ( self . templates . values ( ) ) ) ) :
i . old_properties_names_to_new ( ) |
def getmask ( self , blc = ( ) , trc = ( ) , inc = ( ) ) :
"""Get image mask .
Using the arguments blc ( bottom left corner ) , trc ( top right corner ) ,
and inc ( stride ) it is possible to get a mask slice . Not all axes
need to be specified . Missing values default to begin , end , and 1.
The mask is re... | return numpy . logical_not ( self . _getmask ( self . _adjustBlc ( blc ) , self . _adjustTrc ( trc ) , self . _adjustInc ( inc ) ) ) |
def _notifyDone ( self ) :
'''Allow any other editatoms waiting on me to complete to resume''' | if self . notified :
return
self . doneevent . set ( )
for buid in self . mybldgbuids :
del self . allbldgbuids [ buid ]
self . notified = True |
def plot_prof_2 ( self , mod , species , xlim1 , xlim2 ) :
"""Plot one species for cycle between xlim1 and xlim2
Parameters
mod : string or integer
Model to plot , same as cycle number .
species : list
Which species to plot .
xlim1 , xlim2 : float
Mass coordinate range .""" | mass = self . se . get ( mod , 'mass' )
Xspecies = self . se . get ( mod , 'yps' , species )
pyl . plot ( mass , Xspecies , '-' , label = str ( mod ) + ', ' + species )
pyl . xlim ( xlim1 , xlim2 )
pyl . legend ( ) |
def coverageCounts ( self ) :
"""For each location in the subject , return a count of how many times that
location is covered by a read .
@ return : a C { Counter } where the keys are the C { int } locations on the
subject and the value is the number of times the location is
covered by a read .""" | coverageCounts = Counter ( )
for start , end in self . _intervals :
coverageCounts . update ( range ( max ( 0 , start ) , min ( self . _targetLength , end ) ) )
return coverageCounts |
def read_log ( self , logfile ) :
"""The read _ log method returns a memory efficient generator for rows in a Bro log .
Usage :
rows = my _ bro _ reader . read _ log ( logfile )
for row in rows :
do something with row
Args :
logfile : The Bro Log file .""" | # Make sure we ' re at the beginning
logfile . seek ( 0 )
# First parse the header of the bro log
field_names , _ = self . _parse_bro_header ( logfile )
# Note : SO stupid to write a csv reader , but csv . DictReader on Bro
# files was doing something weird with generator output that
# affected zeroRPC and gave ' could... |
def scope_groups ( self ) :
"""Return a new raw REST interface to scope _ group resources
: rtype : : py : class : ` ns1 . rest . ipam . Scopegroups `""" | import ns1 . rest . ipam
return ns1 . rest . ipam . Scopegroups ( self . config ) |
def get_output ( self , output_files , clear = True ) :
"Get the output files as an id indexed dict ." | patt = re . compile ( r'(.*?)-semantics.*?' )
for outpath in output_files :
if outpath is None :
logger . warning ( "Found outpath with value None. Skipping." )
continue
re_out = patt . match ( path . basename ( outpath ) )
if re_out is None :
raise SparserError ( "Could not get pref... |
def str2key ( self , keyString ) :
"""Parse a human readable key sequence .
If no error is raised , then ` ` keyString ` ` could be
successfully converted into a valid key sequence and is
henceforth represented by this object .
| Args |
* ` ` keyString ` ` ( * * QtmacsKeysequence * * ) : eg . " < ctrl > +... | # Ensure the string is non - empty .
if keyString == '' :
raise QtmacsKeysequenceError ( 'Cannot parse empty string' )
tmp = str ( keyString )
tmp = tmp . replace ( '<' , '<' )
tmp = tmp . replace ( '>' , '>' )
keyStringHtml = '<b>{}</b>.' . format ( tmp )
del tmp
# Remove leading and trailing white spaces , ... |
def discovery_multicast ( self ) :
"""Installs the multicast discovery bundles and instantiates components""" | # Install the bundle
self . context . install_bundle ( "pelix.remote.discovery.multicast" ) . start ( )
with use_waiting_list ( self . context ) as ipopo : # Instantiate the discovery
ipopo . add ( rs . FACTORY_DISCOVERY_MULTICAST , "pelix-discovery-multicast" ) |
def channel ( layer , n_channel , batch = None ) :
"""Visualize a single channel""" | if batch is None :
return lambda T : tf . reduce_mean ( T ( layer ) [ ... , n_channel ] )
else :
return lambda T : tf . reduce_mean ( T ( layer ) [ batch , ... , n_channel ] ) |
def cube ( cls , center = [ 0 , 0 , 0 ] , radius = [ 1 , 1 , 1 ] ) :
"""Construct an axis - aligned solid cuboid . Optional parameters are ` center ` and
` radius ` , which default to ` [ 0 , 0 , 0 ] ` and ` [ 1 , 1 , 1 ] ` . The radius can be
specified using a single number or a list of three numbers , one for... | c = Vector ( 0 , 0 , 0 )
r = [ 1 , 1 , 1 ]
if isinstance ( center , list ) :
c = Vector ( center )
if isinstance ( radius , list ) :
r = radius
else :
r = [ radius , radius , radius ]
polygons = list ( map ( lambda v : Polygon ( list ( map ( lambda i : Vertex ( Vector ( c . x + r [ 0 ] * ( 2 * bool ( i & 1 ... |
def kv ( d ) :
"""Equivalent to dict . items ( ) .
Usage : :
> > > for key , node in DictTree . kv ( d ) :
> > > print ( key , DictTree . getattr ( node , " population " ) )
MD 200000
VA 100000""" | return ( ( key , value ) for key , value in iteritems ( d ) if key != _meta ) |
def shrink ( self , amount ) :
"""Kill off worker threads ( not below self . min ) .""" | # Grow / shrink the pool if necessary .
# Remove any dead threads from our list
for t in self . _threads :
if not t . isAlive ( ) :
self . _threads . remove ( t )
amount -= 1
# calculate the number of threads above the minimum
n_extra = max ( len ( self . _threads ) - self . min , 0 )
# don ' t remo... |
def deleteColumn ( self , networkId , tableType , columnName , verbose = None ) :
"""Deletes the column specified by the ` columnName ` parameter from the table speficied by the ` tableType ` and ` networkId ` parameters .
: param networkId : SUID of the network containing the table from which to delete the colum... | response = api ( url = self . ___url + 'networks/' + str ( networkId ) + '/tables/' + str ( tableType ) + '/columns/' + str ( columnName ) + '' , method = "DELETE" , verbose = verbose )
return response |
def extractSurface ( image , radius = 0.5 ) :
"""` ` vtkExtractSurface ` ` filter . Input is a ` ` vtkImageData ` ` .
Generate zero - crossing isosurface from truncated signed distance volume .""" | fe = vtk . vtkExtractSurface ( )
fe . SetInputData ( image )
fe . SetRadius ( radius )
fe . Update ( )
return Actor ( fe . GetOutput ( ) ) |
def copy_to_clipboard ( dat ) :
"""复制 ` ` dat ` ` 内容到 剪切板中
: return : None""" | p = subprocess . Popen ( [ 'pbcopy' ] , stdin = subprocess . PIPE )
p . stdin . write ( to_bytes ( dat ) )
p . stdin . close ( )
p . communicate ( ) |
def lstlec ( string , n , lenvals , array ) :
"""Given a character string and an ordered array of character
strings , find the index of the largest array element less than
or equal to the given string .
http : / / naif . jpl . nasa . gov / pub / naif / toolkit _ docs / C / cspice / lstlec _ c . html
: param... | string = stypes . stringToCharP ( string )
array = stypes . listToCharArrayPtr ( array , xLen = lenvals , yLen = n )
n = ctypes . c_int ( n )
lenvals = ctypes . c_int ( lenvals )
return libspice . lstlec_c ( string , n , lenvals , array ) |
async def request ( self , api_commands ) :
"""Make a request .""" | if not isinstance ( api_commands , list ) :
result = await self . _execute ( api_commands )
return result
commands = ( self . _execute ( api_command ) for api_command in api_commands )
command_results = await asyncio . gather ( * commands , loop = self . _loop )
return command_results |
def crop ( gens , seconds = 5 , cropper = None ) :
'''Crop the generator to a finite number of frames
Return a generator which outputs the provided generator limited
to enough samples to produce seconds seconds of audio ( default 5s )
at the provided frame rate .''' | if hasattr ( gens , "next" ) : # single generator
gens = ( gens , )
if cropper == None :
cropper = lambda gen : itertools . islice ( gen , 0 , seconds * sampler . FRAME_RATE )
cropped = [ cropper ( gen ) for gen in gens ]
return cropped [ 0 ] if len ( cropped ) == 1 else cropped |
def verify ( self ) :
"""Verify the completeness of the data .
Raises :
ValueError : When this chat is invalid .""" | if any ( not i for i in ( self . chat_uid , self . module_id ) ) :
raise ValueError ( "Chat data is incomplete." )
if not isinstance ( self . chat_type , ChatType ) :
raise ValueError ( "Invalid chat type." )
if self . chat_type == ChatType . Group :
if any ( not isinstance ( i , EFBChat ) or not i . chat_t... |
def get_scene ( self ) :
"""- get _ scene ( ) : It return the x and y position , the smoothing length
of the particles and the index of the particles that are active in
the scene . In principle this is an internal function and you don ' t
need this data .""" | return self . _x , self . _y , self . _hsml , self . _m , self . _kview |
def proj_l1 ( v , gamma , axis = None , method = None ) :
r"""Projection operator of the : math : ` \ ell _ 1 ` norm .
Parameters
v : array _ like
Input array : math : ` \ mathbf { v } `
gamma : float
Parameter : math : ` \ gamma `
axis : None or int or tuple of ints , optional ( default None )
Axes o... | if method is None :
if axis is None :
method = 'scalarroot'
else :
method = 'sortcumsum'
if method == 'scalarroot' :
if axis is not None :
raise ValueError ( 'Method scalarroot only supports axis=None' )
return _proj_l1_scalar_root ( v , gamma )
elif method == 'sortcumsum' :
... |
def rowCount ( self , parent ) :
"""Return the number of rows under the given parent .
When the parent is valid return rowCount the number
of children of parent .
: param parent : the parent index
: type parent : : class : ` QtCore . QModelIndex ` :
: returns : the row count
: rtype : int
: raises : N... | if parent . column ( ) > 0 :
return 0
if not parent . isValid ( ) :
parentItem = self . _root
else :
parentItem = parent . internalPointer ( )
return parentItem . child_count ( ) |
def _BuildHttpRoutingMap ( self , router_cls ) :
"""Builds a werkzeug routing map out of a given router class .""" | if not issubclass ( router_cls , api_call_router . ApiCallRouter ) :
raise ValueError ( "Router has to be an instance of ApiCallRouter." )
routing_map = routing . Map ( )
# Note : we traverse methods of the base class ( ApiCallRouter ) to avoid
# potential problems caused by child router classes using the @ Http
# ... |
def preprocess ( self , raw_inputs ) :
"""Args :
raw _ inputs ( list of Images ) : a list of PIL Image objects
Returns :
array ( float32 ) : num images * height * width * num channels""" | image_arrays = [ ]
for raw_im in raw_inputs :
im = raw_im . resize ( VGG16_DIM [ : 2 ] , Image . ANTIALIAS )
im = im . convert ( 'RGB' )
arr = np . array ( im ) . astype ( 'float32' )
image_arrays . append ( arr )
all_raw_inputs = np . array ( image_arrays )
return imagenet_utils . preprocess_input ( al... |
def kind ( units ) :
"""Find the kind of given units .
Parameters
units : string
The units of interest
Returns
string
The kind of the given units . If no match is found , returns None .""" | for k , v in dicts . items ( ) :
if units in v . keys ( ) :
return k |
def base_variables ( self ) :
"""A mapping from the base _ variable names to the variables""" | if isinstance ( self . data , InteractiveList ) :
return dict ( chain ( * map ( lambda arr : six . iteritems ( arr . psy . base_variables ) , self . data ) ) )
else :
return self . data . psy . base_variables |
def html_visit ( self , node ) :
"""Visitor method for Need - node of builder ' html ' .
Does only wrap the Need - content into an extra < div > with class = need""" | self . body . append ( self . starttag ( node , 'div' , '' , CLASS = 'need' ) ) |
def _bootstrapped_fit_iter ( fitter_args_kargs , n = None , datalist = None , pdatalist = None , ** kargs ) :
"""Iterator that returns bootstrap copies of a fit .
Bootstrap iterator for | MultiFitter | fits analogous to
: meth : ` lsqfit . bootstrapped _ fit _ iter ` . The bootstrap uses the
same parameters a... | fitter , args , okargs = fitter_args_kargs
for k in okargs :
if k not in kargs :
kargs [ k ] = okargs [ k ]
if 'p0' not in kargs :
kargs [ 'p0' ] = args [ 'p0' ]
if datalist is not None :
pdatalist = ( MultiFitter . process_data ( d , args [ 'models' ] ) for d in datalist )
elif pdatalist is None :
... |
def delete_certificate_issuer ( self , certificate_issuer_id , ** kwargs ) : # noqa : E501
"""Delete certificate issuer . # noqa : E501
Delete a certificate issuer by ID . < br > * * Example usage : * * ` ` ` curl - X DELETE \\ - H ' authorization : < valid access token > ' \\ https : / / api . us - east - 1 . mb... | kwargs [ '_return_http_data_only' ] = True
if kwargs . get ( 'asynchronous' ) :
return self . delete_certificate_issuer_with_http_info ( certificate_issuer_id , ** kwargs )
# noqa : E501
else :
( data ) = self . delete_certificate_issuer_with_http_info ( certificate_issuer_id , ** kwargs )
# noqa : E501... |
def zerosFactory ( shape , dtype = float ) :
"""Creates a new NumPy array using ` arrayFactory ( ) ` and fills it with zeros .""" | arr = arrayFactory ( shape = shape , dtype = dtype )
arr . fill ( 0 )
return arr |
def assign_interval ( data ) :
"""Identify coverage based on percent of genome covered and relation to targets .
Classifies coverage into 3 categories :
- genome : Full genome coverage
- regional : Regional coverage , like exome capture , with off - target reads
- amplicon : Amplication based regional cover... | if not dd . get_coverage_interval ( data ) :
vrs = dd . get_variant_regions_merged ( data )
callable_file = dd . get_sample_callable ( data )
if vrs :
callable_size = pybedtools . BedTool ( vrs ) . total_coverage ( )
else :
callable_size = pybedtools . BedTool ( callable_file ) . total_c... |
def parse ( self , sentence , params = None , headers = None ) :
"""Request a parse of * sentence * and return the response .
Args :
sentence ( str ) : sentence to be parsed
params ( dict ) : a dictionary of request parameters
headers ( dict ) : a dictionary of additional request headers
Returns :
A Par... | if params is None :
params = { }
params [ 'input' ] = sentence
hdrs = { 'Accept' : 'application/json' }
if headers is not None :
hdrs . update ( headers )
url = urljoin ( self . server , 'parse' )
r = requests . get ( url , params = params , headers = hdrs )
if r . status_code == 200 :
return _RestResponse ... |
def get ( self , name , default = None ) :
'''Return the first part with that name or a default value ( None ) .''' | for part in self :
if name == part . name :
return part
return default |
def relative_humidity_wet_psychrometric ( dry_bulb_temperature , web_bulb_temperature , pressure , ** kwargs ) :
r"""Calculate the relative humidity with wet bulb and dry bulb temperatures .
This uses a psychrometric relationship as outlined in [ WMO8-2014 ] _ , with
coefficients from [ Fan1987 ] _ .
Paramete... | return ( psychrometric_vapor_pressure_wet ( dry_bulb_temperature , web_bulb_temperature , pressure , ** kwargs ) / saturation_vapor_pressure ( dry_bulb_temperature ) ) |
def close_error_dlg ( self ) :
"""Close error dialog .""" | if self . error_dlg . dismiss_box . isChecked ( ) :
self . dismiss_error = True
self . error_dlg . reject ( ) |
def staged_predict ( self , X ) :
"""Predict hazard at each stage for X .
This method allows monitoring ( i . e . determine error on testing set )
after each stage .
Parameters
X : array - like , shape = ( n _ samples , n _ features )
The input samples .
Returns
y : generator of array of shape = ( n _... | check_is_fitted ( self , 'estimators_' )
# if dropout wasn ' t used during training , proceed as usual ,
# otherwise consider scaling factor of individual trees
if not hasattr ( self , "scale_" ) :
for y in self . _staged_decision_function ( X ) :
yield self . _scale_prediction ( y . ravel ( ) )
else :
... |
def mouseDragEvent ( self , ev , axis = None ) :
"""Customized mouse dragging , where the right drag is bounding box zoom
: param ev : event object containing drag state info
: type ev : : py : class : ` MouseDragEvent < pyqtgraph : pyqtgraph . GraphicsScene . mouseEvents . MouseDragEvent > `""" | if self . _customMouse and ev . button ( ) == QtCore . Qt . RightButton :
ev . accept ( )
# # we accept all buttons
# directly copy - pasted from ViewBox for ViewBox . RectMode
if ev . isFinish ( ) : # # This is the final move in the drag ; change the view scale now
# print " finish "
pos = ... |
def resolve ( self , from_email , resolution = None ) :
"""Resolve an incident using a valid email address .""" | if from_email is None or not isinstance ( from_email , six . string_types ) :
raise MissingFromEmail ( from_email )
endpoint = '/' . join ( ( self . endpoint , self . id , ) )
add_headers = { 'from' : from_email , }
data = { 'incident' : { 'type' : 'incident' , 'status' : 'resolved' , } }
if resolution is not None ... |
def release_parts ( version ) :
"""Split RPM Release string into ( numeric X . Y . Z part , milestone , rest ) .
: returns : a three - element tuple ( number , milestone , rest ) . If we cannot
determine the " milestone " or " rest " , those will be an empty
string .""" | numver , tail = version_parts ( version )
if numver and not re . match ( r'\d' , numver ) : # entire release is macro a la % { release }
tail = numver
numver = ''
m = re . match ( r'(\.?(?:%\{\?milestone\}|[^%.]+))(.*)$' , tail )
if m :
milestone = m . group ( 1 )
rest = m . group ( 2 )
else :
miles... |
def groupby ( xs , key_fn ) :
"""Group elements of the list ` xs ` by keys generated from calling ` key _ fn ` .
Returns a dictionary which maps keys to sub - lists of ` xs ` .""" | result = defaultdict ( list )
for x in xs :
key = key_fn ( x )
result [ key ] . append ( x )
return result |
def _chirp_mass ( self ) :
"""Chirp mass calculation""" | return ( self . m1 * self . m2 ) ** ( 3. / 5. ) / ( self . m1 + self . m2 ) ** ( 1. / 5. ) |
def _read_ipv6_opts_options ( self , length ) :
"""Read IPv6 _ Opts options .
Positional arguments :
* length - - int , length of options
Returns :
* dict - - extracted IPv6 _ Opts options""" | counter = 0
# length of read options
optkind = list ( )
# option type list
options = dict ( )
# dict of option data
while counter < length : # break when eol triggered
code = self . _read_unpack ( 1 )
if not code :
break
# extract parameter
abbr , desc = _IPv6_Opts_OPT . get ( code , ( 'None' , ... |
def solid ( self , x , y ) :
"""Determine whether the pixel x , y is nonzero
Parameters
x , y : int
The pixel of interest .
Returns
solid : bool
True if the pixel is not zero .""" | if not ( 0 <= x < self . xsize ) or not ( 0 <= y < self . ysize ) :
return False
if self . data [ x , y ] == 0 :
return False
return True |
def remove_condition ( self , rank ) :
"""Remove a condition element using it ' s rank . You can find the
rank and element for a match condition by iterating the match
condition : :
> > > rule1 = rm . route _ map _ rules . get ( 0)
> > > for condition in rule1 . match _ condition :
. . . condition
Condi... | self . conditions [ : ] = [ r for r in self . conditions if r . get ( 'rank' ) != rank ] |
def teardown_websocket ( self , func : Callable ) -> Callable :
"""Add a teardown websocket function to the Blueprint .
This is designed to be used as a decorator , and has the same
arguments as : meth : ` ~ quart . Quart . teardown _ websocket ` . It
applies only to requests that are routed to an endpoint in... | self . record_once ( lambda state : state . app . teardown_websocket ( func , self . name ) )
return func |
def sort_references_dict ( refs ) :
"""Sorts a reference dictionary into a standard order
The keys of the references are also sorted , and the keys for the data for each
reference are put in a more canonical order .""" | if _use_odict :
refs_sorted = OrderedDict ( )
else :
refs_sorted = dict ( )
# We insert this first , That is ok - it will be overwritten
# with the sorted version later
refs_sorted [ 'molssi_bse_schema' ] = refs [ 'molssi_bse_schema' ]
# This sorts the entries by reference key ( author1985a , etc )
for k , v in... |
def p_Dictionary ( p ) :
"""Dictionary : dictionary IDENTIFIER Inheritance " { " DictionaryMembers " } " " ; " """ | p [ 0 ] = model . Dictionary ( name = p [ 2 ] , parent = p [ 3 ] , members = p [ 5 ] ) |
def run ( self , context = None , options = None ) :
"""Run axe against the current page .
: param context : which page part ( s ) to analyze and / or what to exclude .
: param options : dictionary of aXe options .""" | template = ( "var callback = arguments[arguments.length - 1];" + "axe.run(%s).then(results => callback(results))" )
args = ""
# If context parameter is passed , add to args
if context is not None :
args += "%r" % context
# Add comma delimiter only if both parameters are passed
if context is not None and options is ... |
def repr_arg ( d ) :
"""formats a function argument prettily but as working code
unicode encodable as ascii is formatted as str""" | if isinstance ( d , dict ) : # if d can be expressed in key = value syntax :
return "{%s}" % ", " . join ( "%s: %s" % ( repr_arg ( k ) , repr_arg ( v ) ) for k , v in d . items ( ) )
if isinstance ( d , list ) :
return "[%s]" % ", " . join ( repr_arg ( elem ) for elem in d )
if isinstance ( d , unicode ) :
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.