signature stringlengths 29 44.1k | implementation stringlengths 0 85.2k |
|---|---|
def get_slice ( self , key , column_parent , predicate , consistency_level ) :
"""Get the group of columns contained by column _ parent ( either a ColumnFamily name or a ColumnFamily / SuperColumn name
pair ) specified by the given SlicePredicate . If no matching values are found , an empty list is returned .
P... | self . _seqid += 1
d = self . _reqs [ self . _seqid ] = defer . Deferred ( )
self . send_get_slice ( key , column_parent , predicate , consistency_level )
return d |
def _GetMemberForOffset ( self , offset ) :
"""Finds the member whose data includes the provided offset .
Args :
offset ( int ) : offset in the uncompressed data to find the
containing member for .
Returns :
gzipfile . GzipMember : gzip file member or None if not available .
Raises :
ValueError : if t... | if offset < 0 or offset >= self . uncompressed_data_size :
raise ValueError ( 'Offset {0:d} is larger than file size {1:d}.' . format ( offset , self . uncompressed_data_size ) )
for end_offset , member in iter ( self . _members_by_end_offset . items ( ) ) :
if offset < end_offset :
return member
return... |
def atlas_zonefile_push_enqueue ( zonefile_hash , name , txid , zonefile_data , zonefile_queue = None , con = None , path = None ) :
"""Enqueue the given zonefile into our " push " queue ,
from which it will be replicated to storage and sent
out to other peers who don ' t have it .
Return True if we enqueued ... | res = False
bits = atlasdb_get_zonefile_bits ( zonefile_hash , path = path , con = con )
if len ( bits ) == 0 : # invalid hash
return
with AtlasZonefileQueueLocked ( zonefile_queue ) as zfq :
if len ( zfq ) < MAX_QUEUED_ZONEFILES :
zfdata = { 'zonefile_hash' : zonefile_hash , 'zonefile' : zonefile_data ... |
def receive_message ( self , msg ) :
"""Responds to messages from other participants .""" | if isinstance ( msg , Resolution ) :
return
paxos = self . paxos_instance
while msg :
if isinstance ( msg , Resolution ) :
self . print_if_verbose ( "{} resolved value {}" . format ( self . network_uid , msg . value ) )
break
else :
self . print_if_verbose ( "{} <- {} <- {}" . format... |
def _build_index ( maf_strm , ref_spec ) :
"""Build an index for a MAF genome alig file and return StringIO of it .""" | idx_strm = StringIO . StringIO ( )
bound_iter = functools . partial ( genome_alignment_iterator , reference_species = ref_spec )
hash_func = JustInTimeGenomeAlignmentBlock . build_hash
idx = IndexedFile ( maf_strm , bound_iter , hash_func )
idx . write_index ( idx_strm )
idx_strm . seek ( 0 )
# seek to the start
return... |
def h_kinetic ( T , P , MW , Hvap , f = 1 ) :
r'''Calculates heat transfer coefficient for condensation
of a pure chemical inside a vertical tube or tube bundle , as presented in
[2 ] _ according to [ 1 ] _ .
. . math : :
h = \ left ( \ frac { 2f } { 2 - f } \ right ) \ left ( \ frac { MW } { 1000 \ cdot 2 ... | return ( 2 * f ) / ( 2 - f ) * ( MW / ( 1000 * 2 * pi * R * T ) ) ** 0.5 * ( Hvap ** 2 * P * MW ) / ( 1000 * R * T ** 2 ) |
def temperature ( self ) :
"""Read the value for the internal temperature sensor .
: returns : Temperature in degree celcius as float
: Example :
> > > sensor = MPU6050I2C ( gw )
> > > sensor . wakeup ( )
> > > sensor . temperature ( )
49.38""" | if not self . awake :
raise Exception ( "MPU6050 is in sleep mode, use wakeup()" )
raw = self . i2c_read_register ( 0x41 , 2 )
raw = struct . unpack ( '>h' , raw ) [ 0 ]
return round ( ( raw / 340 ) + 36.53 , 2 ) |
def _get_web_auth_token ( self ) :
"""Retrieves a token from the network for web authentication .
The token then has to be authorized from getAuthURL before creating
session .""" | request = _Request ( self . network , "auth.getToken" )
# default action is that a request is signed only when
# a session key is provided .
request . sign_it ( )
doc = request . execute ( )
e = doc . getElementsByTagName ( "token" ) [ 0 ]
return e . firstChild . data |
def _parse_multi_byte ( self , s ) : # type : ( str ) - > int
"""_ parse _ multi _ byte parses x as a multibyte representation to get the
int value of this AbstractUVarIntField .
@ param str s : the multibyte string to parse .
@ return int : The parsed int value represented by this AbstractUVarIntField . # no... | assert ( len ( s ) >= 2 )
tmp_len = len ( s )
value = 0
i = 1
byte = orb ( s [ i ] )
# For CPU sake , stops at an arbitrary large number !
max_value = 1 << 64
# As long as the MSG is set , an another byte must be read
while byte & 0x80 :
value += ( byte ^ 0x80 ) << ( 7 * ( i - 1 ) )
if value > max_value :
... |
def grid_search ( grid_scores , change , subset = None , kind = 'line' , cmap = None , ax = None ) :
"""Plot results from a sklearn grid search by changing two parameters at most .
Parameters
grid _ scores : list of named tuples
Results from a sklearn grid search ( get them using the
` grid _ scores _ ` par... | if change is None :
raise ValueError ( ( 'change can\'t be None, you need to select at least' ' one value to make the plot.' ) )
if ax is None :
ax = plt . gca ( )
if cmap is None :
cmap = default_heatmap ( )
if isinstance ( change , string_types ) or len ( change ) == 1 :
return _grid_search_single ( g... |
def median ( self , default = None ) :
"""Calculate the median value over the time series .
: param default : Value to return as a default should the calculation not be possible .
: return : Float representing the median value or ` None ` .""" | return numpy . asscalar ( numpy . median ( self . values ) ) if self . values else default |
def get_or_create_vocab ( self , data_dir , tmp_dir , force_get = False ) :
"""Get vocab for distill problems .""" | # We assume that vocab file is present in data _ dir directory where the
# data generated will be stored .
vocab_filepath = os . path . join ( data_dir , self . vocab_filename )
encoder = text_encoder . SubwordTextEncoder ( vocab_filepath )
return encoder |
def get_user ( self , username ) :
"""Gest a specific user""" | ret = { }
tmp = self . _get_user ( self . _byte_p2 ( username ) , ALL_ATTRS )
if tmp is None :
raise UserDoesntExist ( username , self . backend_name )
attrs_tmp = tmp [ 1 ]
for attr in attrs_tmp :
value_tmp = attrs_tmp [ attr ]
if len ( value_tmp ) == 1 :
ret [ attr ] = value_tmp [ 0 ]
else :
... |
def WriteFileHash ( self , path , hash_value ) :
"""Writes the file path and hash to stdout .
Args :
path ( str ) : path of the file .
hash _ value ( str ) : message digest hash calculated over the file data .""" | string = '{0:s}\t{1:s}' . format ( hash_value , path )
encoded_string = self . _EncodeString ( string )
print ( encoded_string ) |
def _get_dynamic_field_for ( cls , field_name ) :
"""Return the dynamic field within this class that match the given name .
Keep an internal cache to speed up future calls wieh same field name .
( The cache store the field for each individual class and subclasses , to
keep the link between a field and its dir... | from . fields import DynamicFieldMixin
# here to avoid circular import
if cls not in ModelWithDynamicFieldMixin . _dynamic_fields_cache :
ModelWithDynamicFieldMixin . _dynamic_fields_cache [ cls ] = { }
if field_name not in ModelWithDynamicFieldMixin . _dynamic_fields_cache [ cls ] :
ModelWithDynamicFieldMixin ... |
def _parse_nationality ( self , player_info ) :
"""Parse the player ' s nationality .
The player ' s nationality is denoted by a flag in the information
section with a country code for each nation . The country code needs to
pulled and then matched to find the player ' s home country . Once found ,
the ' _ ... | for span in player_info ( 'span' ) . items ( ) :
if 'class="f-i' in str ( span ) :
nationality = span . text ( )
nationality = NATIONALITY [ nationality ]
setattr ( self , '_nationality' , nationality )
break |
def parse_args ( ) :
"""Argument parser and validator""" | parser = argparse . ArgumentParser ( description = "Uploads specified VMDK file to AWS s3 bucket, and converts to AMI" )
parser . add_argument ( '-r' , '--aws_regions' , type = str , nargs = '+' , required = True , help = 'list of AWS regions where uploaded ami should be copied. Available' ' regions: {}.' . format ( AW... |
def delete ( identifier , files = None , formats = None , glob_pattern = None , cascade_delete = None , access_key = None , secret_key = None , verbose = None , debug = None , ** kwargs ) :
"""Delete files from an item . Note : Some system files , such as < itemname > _ meta . xml ,
cannot be deleted .
: type i... | files = get_files ( identifier , files , formats , glob_pattern , ** kwargs )
responses = [ ]
for f in files :
r = f . delete ( cascade_delete = cascade_delete , access_key = access_key , secret_key = secret_key , verbose = verbose , debug = debug )
responses . append ( r )
return responses |
def set_property ( obj , name , value ) :
"""Recursively sets value of object and its subobjects property specified by its name .
The object can be a user defined object , map or array .
The property name correspondently must be object property , map key or array index .
If the property does not exist or intr... | if obj == None or name == None :
return
names = name . split ( "." )
if names == None or len ( names ) == 0 :
return
RecursiveObjectWriter . _perform_set_property ( obj , names , 0 , value ) |
def add_journal ( self , units = None , boot = None , since = None , until = None , lines = None , allfields = False , output = None , timeout = None , identifier = None , catalog = None , sizelimit = None , pred = None ) :
"""Collect journald logs from one of more units .
: param units : A string , or list of st... | journal_cmd = "journalctl --no-pager "
unit_opt = " --unit %s"
boot_opt = " --boot %s"
since_opt = " --since %s"
until_opt = " --until %s"
lines_opt = " --lines %s"
output_opt = " --output %s"
identifier_opt = " --identifier %s"
catalog_opt = " --catalog"
journal_size = 100
all_logs = self . get_option ( "all_logs" )
l... |
def can_document_member ( cls , member , membername , isattr , parent ) :
"""Called to see if a member can be documented by this documenter .""" | if not super ( ) . can_document_member ( member , membername , isattr , parent ) :
return False
return iscoroutinefunction ( member ) |
def draw_rects ( self , * rects ) :
"""Draw some number of rectangles on the current rendering target .
Args :
* rects ( Rect ) : The destination rectangles .
Raises :
SDLError : If an error is encountered .""" | rect_array = ffi . new ( 'SDL_Rect[]' , len ( rects ) )
for i , r in enumerate ( rects ) :
rect_array [ i ] = r . _ptr [ 0 ]
check_int_err ( lib . SDL_RenderDrawRects ( self . _ptr , rect_array , len ( rects ) ) ) |
def get_params ( ) :
"""get the cmdline params""" | parser = argparse . ArgumentParser ( )
parser . add_argument ( "--connect-timeout" , type = float , default = 10.0 , help = "ZK connect timeout" )
parser . add_argument ( "--run-once" , type = str , default = "" , help = "Run a command non-interactively and exit" )
parser . add_argument ( "--run-from-stdin" , action = ... |
def _get_image_for_different_arch ( self , image , platform ) :
"""Get image from random arch
This is a workaround for aarch64 platform , because orchestrator cannot
get this arch from manifests lists so we have to provide digest of a
random platform to get image metadata for orchestrator .
For standard pla... | parents_digests = self . workflow . builder . parent_images_digests
try :
digests = parents_digests . get_image_digests ( image )
except KeyError :
return None
if not digests :
return None
platform_digest = digests . get ( platform )
if platform_digest is None : # exact match is not found , get random platf... |
def _multihop_xml ( self , ** kwargs ) :
"""Build BGP multihop XML .
Do not use this method directly . You probably want ` ` multihop ` ` .
Args :
rbridge _ id ( str ) : The rbridge ID of the device on which BGP will be
configured in a VCS fabric .
neighbor ( ipaddress . ip _ interface ) : ` ip _ interfac... | ip_addr = kwargs . pop ( 'neighbor' )
ip = str ( ip_addr . ip )
rbr_ns = 'urn:brocade.com:mgmt:brocade-rbridge'
bgp_ns = 'urn:brocade.com:mgmt:brocade-bgp'
config = ET . Element ( 'config' )
ele = ET . SubElement ( config , 'rbridge-id' , xmlns = rbr_ns )
ET . SubElement ( ele , 'rbridge-id' ) . text = kwargs . pop ( '... |
def _count_localizations ( df ) :
"""count the most likely localization for each depentent peptide .
: param df : allPeptides . txt table .""" | grp = df . groupby ( _index_columns )
counts = grp [ 'DP AA' ] . apply ( lambda x : count ( x . str . split ( ';' ) . values ) )
counts . index = counts . index . set_names ( 'DP AA' , level = 4 )
counts . name = 'DP AA count'
best_localization = counts . reset_index ( ) . groupby ( _index_columns ) . apply ( _frequent... |
def _match_and_pop ( self , regex_pattern ) :
"""Pop one event from each of the event queues whose names
match ( in a sense of regular expression ) regex _ pattern .""" | results = [ ]
self . lock . acquire ( )
for name in self . event_dict . keys ( ) :
if re . match ( regex_pattern , name ) :
q = self . event_dict [ name ]
if q :
try :
results . append ( q . get ( False ) )
except :
pass
self . lock . release (... |
def rename_unzipped_folder ( version ) :
"""Renames unzipped spark version folder to the release tag .
: param version : version from release tag .
: return :""" | for filename in os . listdir ( Spark . svm_path ( ) ) :
if fnmatch . fnmatch ( filename , 'apache-spark-*' ) :
return os . rename ( os . path . join ( Spark . svm_path ( ) , filename ) , Spark . svm_version_path ( version ) )
raise SparkInstallationError ( "Unable to find unzipped Spark folder in {}" . form... |
def colour ( colour , message , bold = False ) :
"""Color a message""" | return style ( fg = colour , text = message , bold = bold ) |
def _project_on_ellipsoid ( c , r , locations ) :
"""displace locations to the nearest point on ellipsoid surface""" | p0 = locations - c
# original locations
l2 = 1 / np . sum ( p0 ** 2 / r ** 2 , axis = 1 , keepdims = True )
p = p0 * np . sqrt ( l2 )
# initial approximation ( projection of points towards center of ellipsoid )
fun = lambda x : np . sum ( ( x . reshape ( p0 . shape ) - p0 ) ** 2 )
# minimize distance between new and ol... |
def update_resources ( self , cpu , gpu , ** kwargs ) :
"""EXPERIMENTAL : Updates the resource requirements .
Should only be called when the trial is not running .
Raises :
ValueError if trial status is running .""" | if self . status is Trial . RUNNING :
raise ValueError ( "Cannot update resources while Trial is running." )
self . resources = Resources ( cpu , gpu , ** kwargs ) |
def affiliation_history ( self ) :
"""List of ScopusAffiliation objects representing former
affiliations of the author . Only affiliations with more than one
publication are considered .""" | aff_ids = [ e . attrib . get ( 'affiliation-id' ) for e in self . xml . findall ( 'author-profile/affiliation-history/affiliation' ) if e is not None and len ( list ( e . find ( "ip-doc" ) . iter ( ) ) ) > 1 ]
return [ ScopusAffiliation ( aff_id ) for aff_id in aff_ids ] |
def _set_cmap_seq ( self , v , load = False ) :
"""Setter method for cmap _ seq , mapped from YANG variable / overlay _ class _ map / cmap _ seq ( list )
If this variable is read - only ( config : false ) in the
source YANG file , then _ set _ cmap _ seq is considered as a private
method . Backends looking to... | if hasattr ( v , "_utype" ) :
v = v . _utype ( v )
try :
t = YANGDynClass ( v , base = YANGListType ( "cmap_seq_num" , cmap_seq . cmap_seq , yang_name = "cmap-seq" , rest_name = "seq" , parent = self , is_container = 'list' , user_ordered = False , path_helper = self . _path_helper , yang_keys = 'cmap-seq-num' ... |
def search ( self , start_ts , end_ts ) :
"""Called to query Solr for documents in a time range .""" | query = '_ts: [%s TO %s]' % ( start_ts , end_ts )
return self . _stream_search ( query ) |
def train_batch ( batch_list , context , network , gluon_trainer ) :
"""Training with multiple GPUs
Parameters
batch _ list : List
list of dataset
context : List
a list of all GPUs to be used for training
network :
ResNet
gluon _ trainer :
rain module of gluon""" | # Split and load data into multiple GPUs
data = batch_list [ 0 ]
data = gluon . utils . split_and_load ( data , context )
# Split and load label into multiple GPUs
label = batch_list [ 1 ]
label = gluon . utils . split_and_load ( label , context )
# Run the forward and backward pass
forward_backward ( network , data , ... |
def _check_download_dir ( link , download_dir , hashes ) : # type : ( Link , str , Hashes ) - > Optional [ str ]
"""Check download _ dir for previously downloaded file with correct hash
If a correct file is found return its path else None""" | download_path = os . path . join ( download_dir , link . filename )
if os . path . exists ( download_path ) : # If already downloaded , does its hash match ?
logger . info ( 'File was already downloaded %s' , download_path )
if hashes :
try :
hashes . check_against_path ( download_path )
... |
def to_odict ( self , exclude = None ) :
"""Returns an OrderedDict representation of the SQLalchemy table row .""" | if exclude is None :
exclude = tuple ( )
colnames = [ c . name for c in self . __table__ . columns if c . name not in exclude ]
return OrderedDict ( ( ( col , getattr ( self , col ) ) for col in colnames ) ) |
def ListVoices ( voice_spec = None ) :
'''Reads the voice files from espeak - data / voices and returns a list of VOICE objects .
If voice _ spec is None then all voices are listed .
If voice spec is given , then only the voices which are compatible with the voice _ spec
are listed , and they are listed in pr... | ppv = cListVoices ( voice_spec )
res = [ ]
i = 0
while ppv [ i ] :
res . append ( ppv [ i ] [ 0 ] )
i += 1
return res |
def is_end_node ( node ) :
"""Checks if a node is the " end " keyword .
Args :
node : AST node .
Returns :
True if the node is the " end " keyword , otherwise False .""" | return ( isinstance ( node , ast . Expr ) and isinstance ( node . value , ast . Name ) and node . value . id == 'end' ) |
def _new_redis_client ( self ) :
"""Create a new redis client and assign it the class _ redis _ client
attribute for reuse across requests .
: rtype : tornadoredis . Client ( )""" | if 'tornadoredis' not in globals ( ) :
import tornadoredis
kwargs = self . _redis_connection_settings ( )
LOGGER . info ( 'Connecting to %(host)s:%(port)s DB %(selected_db)s' , kwargs )
return tornadoredis . Client ( ** kwargs ) |
def execute ( self , statement , parameters = None ) :
"""Execute statement on database
: param statement : a valid SQL statement
: param parameters : a list / tuple of parameters
: returns : this cursor
In order to be compatible with Python ' s DBAPI five parameter styles
must be supported .
paramstyle... | self . _check_closed ( )
if not parameters : # Directly execute the statement , nothing else to prepare :
self . _execute_direct ( statement )
else :
self . executemany ( statement , parameters = [ parameters ] )
return self |
def flush ( self ) :
"""Remove all cached objects from the database .""" | keys = list ( self . keys ( ) )
if keys :
return self . database . delete ( * keys ) |
def calcFontScaling ( self ) :
'''Calculates the current font size and left position for the current window .''' | self . ypx = self . figure . get_size_inches ( ) [ 1 ] * self . figure . dpi
self . xpx = self . figure . get_size_inches ( ) [ 0 ] * self . figure . dpi
self . fontSize = self . vertSize * ( self . ypx / 2.0 )
self . leftPos = self . axes . get_xlim ( ) [ 0 ]
self . rightPos = self . axes . get_xlim ( ) [ 1 ] |
def assign_assessment_taken_to_bank ( self , assessment_taken_id , bank_id ) :
"""Adds an existing ` ` AssessmentTaken ` ` to a ` ` Bank ` ` .
arg : assessment _ taken _ id ( osid . id . Id ) : the ` ` Id ` ` of the
` ` AssessmentTaken ` `
arg : bank _ id ( osid . id . Id ) : the ` ` Id ` ` of the ` ` Bank ` ... | # Implemented from template for
# osid . resource . ResourceBinAssignmentSession . assign _ resource _ to _ bin
mgr = self . _get_provider_manager ( 'ASSESSMENT' , local = True )
lookup_session = mgr . get_bank_lookup_session ( proxy = self . _proxy )
lookup_session . get_bank ( bank_id )
# to raise NotFound
self . _as... |
def _parse_the_ned_position_results ( self , ra , dec , nedResults ) :
"""* parse the ned results *
* * Key Arguments : * *
- ` ` ra ` ` - - the search ra
- ` ` dec ` ` - - the search dec
* * Return : * *
- ` ` results ` ` - - list of result dictionaries""" | self . log . info ( 'starting the ``_parse_the_ned_results`` method' )
results = [ ]
resultLen = 0
if nedResults : # OPEN THE RESULT FILE FROM NED
pathToReadFile = nedResults
try :
self . log . debug ( "attempting to open the file %s" % ( pathToReadFile , ) )
readFile = codecs . open ( pathToRea... |
def gisland ( self , dae ) :
"""Reset g ( x ) for islanded buses and areas""" | if not ( self . islanded_buses and self . island_sets ) :
return
a , v = list ( ) , list ( )
# for islanded areas without a slack bus
for island in self . island_sets :
nosw = 1
for item in self . system . SW . bus :
if self . uid [ item ] in island :
nosw = 0
break
if no... |
def requireCleanup ( self ) :
"""If you intend to use any signal / slot connections on this QTreeWidgetItem , you will need
to call the requireCleanup method and implement manual disconnections in the destroy method .
QTreeWidgetItem ' s do not inherit from QObject , and as such do not utilize the memory cleanu... | try :
tree . destroyed . connect ( self . destroy , QtCore . Qt . UniqueConnection )
except StandardError :
pass |
def Parse ( self , stat , file_object , knowledge_base ) :
"""Parse the wtmp file .""" | _ , _ = stat , knowledge_base
users = { }
wtmp = file_object . read ( )
while wtmp :
try :
record = UtmpStruct ( wtmp )
except utils . ParsingError :
break
wtmp = wtmp [ record . size : ]
# Users only appear for USER _ PROCESS events , others are system .
if record . ut_type != 7 :
... |
def parse_domain ( url ) :
"""parse the domain from the url""" | domain_match = lib . DOMAIN_REGEX . match ( url )
if domain_match :
return domain_match . group ( ) |
def init_opdata ( l , from_mod , version = None , is_pypy = False ) :
"""Sets up a number of the structures found in Python ' s
opcode . py . Python opcode . py routines assign attributes to modules .
In order to do this in a modular way here , the local dictionary
for the module is passed .""" | if version :
l [ 'python_version' ] = version
l [ 'is_pypy' ] = is_pypy
l [ 'cmp_op' ] = cmp_op
l [ 'HAVE_ARGUMENT' ] = HAVE_ARGUMENT
if version <= 3.5 :
l [ 'findlinestarts' ] = findlinestarts
l [ 'findlabels' ] = findlabels
l [ 'get_jump_targets' ] = get_jump_targets
l [ 'get_jump_target_maps' ] =... |
def laminar_entry_Baehr_Stephan ( Re = None , Pr = None , L = None , Di = None ) :
r'''Calculates average internal convection Nusselt number for laminar flows
in pipe during the thermal and velocity entry region according to [ 1 ] _ as
shown in [ 2 ] _ .
. . math : :
Nu _ D = \ frac { \ frac { 3.657 } { \ t... | Gz = Di / L * Re * Pr
return ( 3.657 / tanh ( 2.264 * Gz ** ( - 1 / 3. ) + 1.7 * Gz ** ( - 2 / 3.0 ) ) + 0.0499 * Gz * tanh ( 1. / Gz ) ) / tanh ( 2.432 * Pr ** ( 1 / 6.0 ) * Gz ** ( - 1 / 6.0 ) ) |
def read ( self , size ) :
"""Read from the current offset a total number of ` size ` bytes
and increment the offset by ` size `
: param int size : length of bytes to read
: rtype : bytearray""" | if isinstance ( size , SV ) :
size = size . value
buff = self . __buff [ self . __idx : self . __idx + size ]
self . __idx += size
return buff |
def find_clusters ( struct , connected_list ) :
"""Finds bonded clusters of atoms in the structure with periodic boundary conditions .
If there are atoms that are not bonded to anything , returns [ 0,1,0 ] . ( For faster computation time in FindDimension ( ) )
Args :
struct ( Structure ) : Input structure
c... | n_atoms = len ( struct . species )
if len ( np . unique ( connected_list ) ) != n_atoms :
return [ 0 , 1 , 0 ]
if n_atoms == 0 :
return [ 0 , 0 , 0 ]
cluster_sizes = [ ]
clusters = [ ]
for atom in range ( n_atoms ) :
connected_inds = np . where ( connected_list == atom ) [ 0 ]
atom_cluster = np . unique... |
def with_organisation ( self , organisation ) :
"""Add an organisation segment .
Args :
organisation ( str ) : Official name of an administrative body
holding an election .
Returns :
IdBuilder
Raises :
ValueError""" | if organisation is None :
organisation = ''
organisation = slugify ( organisation )
self . _validate_organisation ( organisation )
self . organisation = organisation
return self |
def get_instrument_history ( self , instrument , candle_format = "bidask" , granularity = 'S5' , count = 500 , daily_alignment = None , alignment_timezone = None , weekly_alignment = "Monday" , start = None , end = None ) :
"""See more :
http : / / developer . oanda . com / rest - live / rates / # retrieveInstrum... | url = "{0}/{1}/candles" . format ( self . domain , self . API_VERSION )
params = { "accountId" : self . account_id , "instrument" : instrument , "candleFormat" : candle_format , "granularity" : granularity , "count" : count , "dailyAlignment" : daily_alignment , "alignmentTimezone" : alignment_timezone , "weeklyAlignme... |
def _new_conn ( self ) :
"""Return a fresh : class : ` HTTPConnection ` .""" | self . num_connections += 1
log . debug ( "Starting new HTTP connection (%d): %s" , self . num_connections , self . host )
conn = self . ConnectionCls ( host = self . host , port = self . port , timeout = self . timeout . connect_timeout , strict = self . strict , ** self . conn_kw )
return conn |
def datatype ( dbtype , description , cursor ) :
"""Google AppEngine Helper to convert a data type into a string .""" | dt = cursor . db . introspection . get_field_type ( dbtype , description )
if type ( dt ) is tuple :
return dt [ 0 ]
else :
return dt |
def get_user_permissions ( user ) :
'''Returns the queryset of permissions for the given user .''' | permissions = SeedPermission . objects . all ( )
# User must be on a team that grants the permission
permissions = permissions . filter ( seedteam__users = user )
# The team must be active
permissions = permissions . filter ( seedteam__archived = False )
# The organization of that team must be active
permissions = perm... |
def get_model_schema_and_features ( model_dir ) :
"""Get a local model ' s schema and features config .
Args :
model _ dir : local or GCS path of a model .
Returns :
A tuple of schema ( list ) and features config ( dict ) .""" | schema_file = os . path . join ( model_dir , 'assets.extra' , 'schema.json' )
schema = json . loads ( file_io . read_file_to_string ( schema_file ) )
features_file = os . path . join ( model_dir , 'assets.extra' , 'features.json' )
features_config = json . loads ( file_io . read_file_to_string ( features_file ) )
retur... |
def _collect_box_count ( self , boxes ) :
"""Count the occurences of each box type .""" | count = Counter ( [ box . box_id for box in boxes ] )
# Add the counts in the superboxes .
for box in boxes :
if hasattr ( box , 'box' ) :
count . update ( self . _collect_box_count ( box . box ) )
return count |
def check_for_errors ( self ) :
"""Check connection and channel for errors .
: raises AMQPChannelError : Raises if the channel encountered an error .
: raises AMQPConnectionError : Raises if the connection
encountered an error .
: return :""" | try :
self . _connection . check_for_errors ( )
except AMQPConnectionError :
self . set_state ( self . CLOSED )
raise
if self . exceptions :
exception = self . exceptions [ 0 ]
if self . is_open :
self . exceptions . pop ( 0 )
raise exception
if self . is_closed :
raise AMQPChannelEr... |
def addsuffix ( subject , suffix , replace = False ) :
"""Adds the specified * suffix * to the * subject * . If * replace * is True , the
old suffix will be removed first . If * suffix * is callable , it must accept
exactly one argument and return a modified value .""" | if not suffix and not replace :
return subject
if replace :
subject = rmvsuffix ( subject )
if suffix and callable ( suffix ) :
subject = suffix ( subject )
elif suffix :
subject += suffix
return subject |
def split ( self , dt ) :
"""Split the segments in the list is subsegments at least as long as dt""" | outlist = [ ]
for seg in self :
start = seg . start ( )
stop = seg . end ( )
id = seg . id ( )
while start < stop :
tmpstop = start + dt
if tmpstop > stop :
tmpstop = stop
elif tmpstop + dt > stop :
tmpstop = int ( ( start + stop ) / 2 )
x = Scienc... |
def get ( method , hmc , uri , uri_parms , logon_required ) :
"""Operation : List Partitions of a CPC ( empty result if not in DPM
mode ) .""" | cpc_oid = uri_parms [ 0 ]
query_str = uri_parms [ 1 ]
try :
cpc = hmc . cpcs . lookup_by_oid ( cpc_oid )
except KeyError :
raise InvalidResourceError ( method , uri )
# Reflect the result of listing the partition
result_partitions = [ ]
if cpc . dpm_enabled :
filter_args = parse_query_parms ( method , uri ,... |
def terminate_all ( self ) :
"""Terminate all currently running tasks .""" | logger . info ( 'Job {0} terminating all currently running tasks' . format ( self . name ) )
for task in self . tasks . itervalues ( ) :
if task . started_at and not task . completed_at :
task . terminate ( ) |
def char_size ( self , size ) :
'''Changes font size
Args :
size : change font size . Options are 24 ' ' 32 ' ' 48 ' for bitmap fonts
33 , 38 , 42 , 46 , 50 , 58 , 67 , 75 , 83 , 92 , 100 , 117 , 133 , 150 , 167 , 200 233,
11 , 44 , 77 , 111 , 144 for outline fonts .
Returns :
None
Raises :
RuntimeE... | sizes = { '24' : 0 , '32' : 0 , '48' : 0 , '33' : 0 , '38' : 0 , '42' : 0 , '46' : 0 , '50' : 0 , '58' : 0 , '67' : 0 , '75' : 0 , '83' : 0 , '92' : 0 , '100' : 0 , '117' : 0 , '133' : 0 , '150' : 0 , '167' : 0 , '200' : 0 , '233' : 0 , '11' : 1 , '44' : 1 , '77' : 1 , '111' : 1 , '144' : 1 }
if size in sizes :
if ... |
def pulse_width ( self ) :
"""Returns the current pulse width controlling the servo .""" | if self . pwm_device . pin . frequency is None :
return None
else :
return self . pwm_device . pin . state * self . frame_width |
def start ( cls , settings = None ) :
"""RUN ME FIRST TO SETUP THE THREADED LOGGING
http : / / victorlin . me / 2012/08 / good - logging - practice - in - python /
log - LIST OF PARAMETERS FOR LOGGER ( S )
trace - SHOW MORE DETAILS IN EVERY LOG LINE ( default False )
cprofile - True = = ENABLE THE C - PROFI... | global _Thread
if not settings :
return
settings = wrap ( settings )
Log . stop ( )
cls . settings = settings
cls . trace = coalesce ( settings . trace , False )
if cls . trace :
from mo_threads import Thread as _Thread
_ = _Thread
# ENABLE CPROFILE
if settings . cprofile is False :
settings . cprofile ... |
def wait_instances_running ( ec2 , instances ) :
"""Wait until no instance in the given iterable is ' pending ' . Yield every instance that
entered the running state as soon as it does .
: param boto . ec2 . connection . EC2Connection ec2 : the EC2 connection to use for making requests
: param Iterator [ Inst... | running_ids = set ( )
other_ids = set ( )
while True :
pending_ids = set ( )
for i in instances :
if i . state == 'pending' :
pending_ids . add ( i . id )
elif i . state == 'running' :
assert i . id not in running_ids
running_ids . add ( i . id )
y... |
def get_product_trades ( self , product_id , before = '' , after = '' , limit = None , result = None ) :
"""List the latest trades for a product .
This method returns a generator which may make multiple HTTP requests
while iterating through it .
Args :
product _ id ( str ) : Product
before ( Optional [ st... | return self . _send_paginated_message ( '/products/{}/trades' . format ( product_id ) ) |
def _write_avg_gradient ( self ) -> None :
"Writes the average of the gradients to Tensorboard ." | avg_gradient = sum ( x . data . mean ( ) for x in self . gradients ) / len ( self . gradients )
self . _add_gradient_scalar ( 'avg_gradient' , scalar_value = avg_gradient ) |
def cut_microsoft_quote ( html_message ) :
'''Cuts splitter block and all following blocks .''' | # use EXSLT extensions to have a regex match ( ) function with lxml
ns = { "re" : "http://exslt.org/regular-expressions" }
# general pattern : @ style = ' border : none ; border - top : solid < color > 1.0pt ; padding : 3.0pt 0 < unit > 0 < unit > 0 < unit > '
# outlook 2007 , 2010 ( international ) < color = # B5C4DF ... |
def check_output ( * args , ** kwargs ) :
'''Compatibility wrapper for Python 2.6 missin g subprocess . check _ output''' | if hasattr ( subprocess , 'check_output' ) :
return subprocess . check_output ( stderr = subprocess . STDOUT , universal_newlines = True , * args , ** kwargs )
else :
process = subprocess . Popen ( * args , stdout = subprocess . PIPE , stderr = subprocess . STDOUT , universal_newlines = True , ** kwargs )
o... |
def get_auth ( self ) :
"""Returns auth response which has client token unless MFA is required""" | auth_resp = get_with_retry ( self . cerberus_url + '/v2/auth/user' , auth = ( self . username , self . password ) , headers = self . HEADERS )
if auth_resp . status_code != 200 :
throw_if_bad_response ( auth_resp )
return auth_resp . json ( ) |
def _get_download_table_ids ( self ) :
"""Get a list of PyPI downloads table ( sharded per day ) IDs .
: return : list of table names ( strings )
: rtype : ` ` list ` `""" | all_table_names = [ ]
# matching per - date table names
logger . info ( 'Querying for all tables in dataset' )
tables = self . service . tables ( )
request = tables . list ( projectId = self . _PROJECT_ID , datasetId = self . _DATASET_ID )
while request is not None :
response = request . execute ( )
# if the nu... |
def resolved ( value ) :
"""Creates a promise object resolved with a certain value .""" | p = Promise ( )
p . _state = 'resolved'
p . value = value
return p |
def _delete ( self , c , context , hm ) :
"""Delete a healthmonitor and ALL its pool associations""" | pools = hm . get ( "pools" , [ ] )
for pool in pools :
pool_id = pool . get ( "pool_id" )
self . _dissociate ( c , context , hm , pool_id )
self . _delete_unused ( c , context , hm ) |
def standard_deviation ( numbers ) :
"""Return standard deviation .""" | numbers = list ( numbers )
if not numbers :
return 0
mean = sum ( numbers ) / len ( numbers )
return ( sum ( ( n - mean ) ** 2 for n in numbers ) / len ( numbers ) ) ** .5 |
def add_JSsource ( self , new_src ) :
"""add additional js script source ( s )""" | if isinstance ( new_src , list ) :
for h in new_src :
self . JSsource . append ( h )
elif isinstance ( new_src , basestring ) :
self . JSsource . append ( new_src )
else :
raise OptionTypeError ( "Option: %s Not Allowed For Series Type: %s" % type ( new_src ) ) |
def addChild ( self , cur ) :
"""Add a new node to @ parent , at the end of the child ( or
property ) list merging adjacent TEXT nodes ( in which case
@ cur is freed ) If the new node is ATTRIBUTE , it is added
into properties instead of children . If there is an
attribute with equal name , it is first dest... | if cur is None :
cur__o = None
else :
cur__o = cur . _o
ret = libxml2mod . xmlAddChild ( self . _o , cur__o )
if ret is None :
raise treeError ( 'xmlAddChild() failed' )
__tmp = xmlNode ( _obj = ret )
return __tmp |
def timemap_stretch ( y , sr , time_map , rbargs = None ) :
'''Apply a timemap stretch to an audio time series .
A timemap stretch allows non - linear time - stretching by mapping source to
target sample frame numbers for fixed time points within the audio data .
This uses the ` time ` and ` timemap ` form fo... | if rbargs is None :
rbargs = dict ( )
is_positive = all ( time_map [ i ] [ 0 ] >= 0 and time_map [ i ] [ 1 ] >= 0 for i in range ( len ( time_map ) ) )
is_monotonic = all ( time_map [ i ] [ 0 ] <= time_map [ i + 1 ] [ 0 ] and time_map [ i ] [ 1 ] <= time_map [ i + 1 ] [ 1 ] for i in range ( len ( time_map ) - 1 ) )... |
def set_network ( self , machines , local_listen_port = 12400 , listen_time_out = 120 , num_machines = 1 ) :
"""Set the network configuration .
Parameters
machines : list , set or string
Names of machines .
local _ listen _ port : int , optional ( default = 12400)
TCP listen port for local machines .
li... | _safe_call ( _LIB . LGBM_NetworkInit ( c_str ( machines ) , ctypes . c_int ( local_listen_port ) , ctypes . c_int ( listen_time_out ) , ctypes . c_int ( num_machines ) ) )
self . network = True
return self |
def read_transform ( filename , dimension = 2 , precision = 'float' ) :
"""Read a transform from file
ANTsR function : ` readAntsrTransform `
Arguments
filename : string
filename of transform
dimension : integer
spatial dimension of transform
precision : string
numerical precision of transform
Ret... | filename = os . path . expanduser ( filename )
if not os . path . exists ( filename ) :
raise ValueError ( 'filename does not exist!' )
libfn1 = utils . get_lib_fn ( 'getTransformDimensionFromFile' )
dimension = libfn1 ( filename )
libfn2 = utils . get_lib_fn ( 'getTransformNameFromFile' )
transform_type = libfn2 (... |
def setup_prjs_signals ( self , ) :
"""Setup the signals for the projects page
: returns : None
: rtype : None
: raises : None""" | log . debug ( "Setting up projects page signals." )
self . prjs_prj_view_pb . clicked . connect ( self . prjs_view_prj )
self . prjs_prj_create_pb . clicked . connect ( self . prjs_create_prj ) |
def get_tamil_words ( letters ) :
"""reverse a Tamil word according to letters , not unicode - points""" | if not isinstance ( letters , list ) :
raise Exception ( "metehod needs to be used with list generated from 'tamil.utf8.get_letters(...)'" )
return [ word for word in get_words_iterable ( letters , tamil_only = True ) ] |
def convolve_comb_lines ( lines_wave , lines_flux , sigma , crpix1 , crval1 , cdelt1 , naxis1 ) :
"""Convolve a set of lines of known wavelengths and flux .
Parameters
lines _ wave : array like
Input array with wavelengths
lines _ flux : array like
Input array with fluxes
sigma : float
Sigma of the br... | # generate wavelengths for output spectrum
xwave = crval1 + ( np . arange ( naxis1 ) + 1 - crpix1 ) * cdelt1
# initialize output spectrum
spectrum = np . zeros ( naxis1 )
# convolve each line
for wave , flux in zip ( lines_wave , lines_flux ) :
sp_tmp = gauss_box_model ( x = xwave , amplitude = flux , mean = wave ,... |
def _convert_event_api ( lambda_logical_id , event_properties ) :
"""Converts a AWS : : Serverless : : Function ' s Event Property to an Api configuration usable by the provider .
: param str lambda _ logical _ id : Logical Id of the AWS : : Serverless : : Function
: param dict event _ properties : Dictionary o... | path = event_properties . get ( SamApiProvider . _EVENT_PATH )
method = event_properties . get ( SamApiProvider . _EVENT_METHOD )
# An API Event , can have RestApiId property which designates the resource that owns this API . If omitted ,
# the API is owned by Implicit API resource . This could either be a direct resou... |
def execute_prepared_cql_query ( self , itemId , values ) :
"""Executes a prepared CQL ( Cassandra Query Language ) statement by passing an id token and a list of variables
to bind and returns a CqlResult containing the results .
Parameters :
- itemId
- values""" | self . _seqid += 1
d = self . _reqs [ self . _seqid ] = defer . Deferred ( )
self . send_execute_prepared_cql_query ( itemId , values )
return d |
def use_comparative_resource_view ( self ) :
"""Pass through to provider ResourceLookupSession . use _ comparative _ resource _ view""" | self . _object_views [ 'resource' ] = COMPARATIVE
# self . _ get _ provider _ session ( ' resource _ lookup _ session ' ) # To make sure the session is tracked
for session in self . _get_provider_sessions ( ) :
try :
session . use_comparative_resource_view ( )
except AttributeError :
pass |
def _bse_cli_lookup_by_role ( args ) :
'''Handles the lookup - by - role subcommand''' | return api . lookup_basis_by_role ( args . basis , args . role , args . data_dir ) |
def least_loaded_node ( self ) :
"""Choose the node with fewest outstanding requests , with fallbacks .
This method will prefer a node with an existing connection and no
in - flight - requests . If no such node is found , a node will be chosen
randomly from disconnected nodes that are not " blacked out " ( i ... | nodes = [ broker . nodeId for broker in self . cluster . brokers ( ) ]
random . shuffle ( nodes )
inflight = float ( 'inf' )
found = None
for node_id in nodes :
conn = self . _conns . get ( node_id )
connected = conn is not None and conn . connected ( )
blacked_out = conn is not None and conn . blacked_out ... |
async def async_set_operation_mode ( self , operation_mode : OperationMode , password : str = '' ) -> None :
"""Set the operation mode on the base unit .
: param operation _ mode : the operation mode to change to
: param password : if specified , will be used instead of the password
property when issuing the ... | await self . _protocol . async_execute ( SetOpModeCommand ( operation_mode ) , password = password ) |
def query_order ( self , transaction_id = None , out_trade_no = None ) :
"""查询订单 api
: param transaction _ id : 二选一 微信订单号 微信的订单号 , 优先使用
: param out _ trade _ no : 二选一 商户订单号 商户系统内部的订单号 , 当没提供transaction _ id时需要传这个 。
: return : 返回的结果信息""" | if not transaction_id and not out_trade_no :
raise ValueError ( "transaction_id and out_trade_no must be a choice." )
data = { "appid" : self . appid , "mch_id" : self . mch_id , "transaction_id" : transaction_id , "out_trade_no" : out_trade_no , }
return self . _post ( "pay/paporderquery" , data = data ) |
def _read_style ( style ) :
'''Deal with different style format ( str , list , tuple )''' | if isinstance ( style , string_types ) :
style = [ style ]
else :
style = list ( style )
return style |
def parse_msdos ( self , lines ) :
'''Parse lines from a MS - DOS format .''' | for line in lines :
fields = line . split ( None , 4 )
date_str = fields [ 0 ]
time_str = fields [ 1 ]
datetime_str = '{} {}' . format ( date_str , time_str )
file_datetime = self . parse_datetime ( datetime_str ) [ 0 ]
if fields [ 2 ] == '<DIR>' :
file_size = None
file_type = 'd... |
def bulk_attachments ( self , article , attachments ) :
"""This function implements associating attachments to an article after article creation ( for
unassociated attachments ) .
: param article : Article id or : class : ` Article ` object
: param attachments : : class : ` ArticleAttachment ` object , or lis... | return HelpdeskAttachmentRequest ( self ) . post ( self . endpoint . bulk_attachments , article = article , attachments = attachments ) |
def box ( b , line_width = 2 , color = 'g' , style = '-' ) :
"""Draws a box on the current plot .
Parameters
b : : obj : ` autolab _ core . Box `
box to draw
line _ width : int
width of lines on side of box
color : : obj : ` str `
color of box
style : : obj : ` str `
style of lines to draw""" | if not isinstance ( b , Box ) :
raise ValueError ( 'Input must be of type Box' )
# get min pixels
min_i = b . min_pt [ 1 ]
min_j = b . min_pt [ 0 ]
max_i = b . max_pt [ 1 ]
max_j = b . max_pt [ 0 ]
top_left = np . array ( [ min_i , min_j ] )
top_right = np . array ( [ max_i , min_j ] )
bottom_left = np . array ( [ ... |
def ParseShadowEntry ( self , line ) :
"""Extract the user accounts in / etc / shadow .
Identifies the users in / etc / shadow and several attributes of their account ,
including how their password is crypted and password aging characteristics .
Args :
line : An entry of the shadow file .""" | fields = ( "login" , "passwd" , "last_change" , "min_age" , "max_age" , "warn_time" , "inactivity" , "expire" , "reserved" )
if line :
rslt = dict ( zip ( fields , line . split ( ":" ) ) )
pw_entry = self . shadow . setdefault ( rslt [ "login" ] , rdf_client . PwEntry ( ) )
pw_entry . store = self . shadow_... |
def lift ( fn = None , state_fn = None ) :
"""The lift decorator function will be used to abstract away the management
of the state object used as the intermediate representation of actions .
: param function answer : a function to provide
the result of some action given a value
: param function state : a f... | if fn is None :
return partial ( lift , state_fn = state_fn )
@ wraps ( fn )
def _lift ( * args , ** kwargs ) :
def _run ( state ) :
ans = fn ( * cons ( state , args ) , ** kwargs )
s = state_fn ( state ) if state_fn is not None else ans
return { 'answer' : ans , 'state' : s }
return... |
def pointSampler ( actor , distance = None ) :
"""Algorithm to generate points the specified distance apart .""" | poly = actor . polydata ( True )
pointSampler = vtk . vtkPolyDataPointSampler ( )
if not distance :
distance = actor . diagonalSize ( ) / 100.0
pointSampler . SetDistance ( distance )
# pointSampler . GenerateVertexPointsOff ( )
# pointSampler . GenerateEdgePointsOff ( )
# pointSampler . GenerateVerticesOn ( )
# po... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.