signature stringlengths 29 44.1k | implementation stringlengths 0 85.2k |
|---|---|
def queue_raw_jobs ( queue , params_list , ** kwargs ) :
"""Queue some jobs on a raw queue""" | from . queue import Queue
queue_obj = Queue ( queue )
queue_obj . enqueue_raw_jobs ( params_list , ** kwargs ) |
def get_slab ( self , shift = 0 , tol = 0.1 , energy = None ) :
"""This method takes in shift value for the c lattice direction and
generates a slab based on the given shift . You should rarely use this
method . Instead , it is used by other generation algorithms to obtain
all slabs .
Arg :
shift ( float ... | h = self . _proj_height
p = h / self . parent . lattice . d_hkl ( self . miller_index )
if self . in_unit_planes :
nlayers_slab = int ( math . ceil ( self . min_slab_size / p ) )
nlayers_vac = int ( math . ceil ( self . min_vac_size / p ) )
else :
nlayers_slab = int ( math . ceil ( self . min_slab_size / h ... |
def on_select_fit ( self , event ) :
"""Picks out the fit selected in the fit combobox and sets it to the
current fit of the GUI then calls the select function of the fit to
set the GUI ' s bounds boxes and alter other such parameters
Parameters
event : the wx . ComboBoxEvent that triggers this function
A... | fit_val = self . fit_box . GetValue ( )
if self . s not in self . pmag_results_data [ 'specimens' ] or not self . pmag_results_data [ 'specimens' ] [ self . s ] or fit_val == 'None' :
self . clear_boxes ( )
self . current_fit = None
self . fit_box . SetStringSelection ( 'None' )
self . tmin_box . SetStr... |
def list_comments ( self , page = 0 ) :
"""Get the comments of current object
: param page : the page starting at 0
: return : the emails
: rtype : list""" | from highton . models . comment import Comment
params = { 'page' : int ( page ) * self . COMMENT_OFFSET }
return fields . ListField ( name = self . ENDPOINT , init_class = Comment ) . decode ( self . element_from_string ( self . _get_request ( endpoint = self . ENDPOINT + '/' + str ( self . id ) + '/' + Comment . ENDPO... |
def _choose_package_version ( self ) : # type : ( ) - > Union [ str , None ]
"""Tries to select a version of a required package .
Returns the name of the package whose incompatibilities should be
propagated by _ propagate ( ) , or None indicating that version solving is
complete and a solution has been found ... | unsatisfied = self . _solution . unsatisfied
if not unsatisfied :
return
# Prefer packages with as few remaining versions as possible ,
# so that if a conflict is necessary it ' s forced quickly .
def _get_min ( dependency ) :
if dependency . name in self . _use_latest : # If we ' re forced to use the latest ve... |
def serialize ( self ) :
"""Convert Document to python dictionary .""" | # Serialize fields to a dict
elements = [ ]
for element in self . elements :
elements . append ( element . serialize ( ) )
data = { 'type' : 'document' , 'elements' : elements }
return data |
def floating_ip_disassociate ( self , server_name , floating_ip ) :
'''Disassociate a floating IP from server
. . versionadded : : 2016.3.0''' | nt_ks = self . compute_conn
server_ = self . server_by_name ( server_name )
server = nt_ks . servers . get ( server_ . __dict__ [ 'id' ] )
server . remove_floating_ip ( floating_ip )
return self . floating_ip_list ( ) [ floating_ip ] |
def calculate_dc_coefficients ( contour ) :
"""Calculate the : math : ` A _ 0 ` and : math : ` C _ 0 ` coefficients of the elliptic Fourier series .
: param numpy . ndarray contour : A contour array of size ` ` [ M x 2 ] ` ` .
: return : The : math : ` A _ 0 ` and : math : ` C _ 0 ` coefficients .
: rtype : t... | dxy = np . diff ( contour , axis = 0 )
dt = np . sqrt ( ( dxy ** 2 ) . sum ( axis = 1 ) )
t = np . concatenate ( [ ( [ 0. , ] ) , np . cumsum ( dt ) ] )
T = t [ - 1 ]
xi = np . cumsum ( dxy [ : , 0 ] ) - ( dxy [ : , 0 ] / dt ) * t [ 1 : ]
A0 = ( 1 / T ) * np . sum ( ( ( dxy [ : , 0 ] / ( 2 * dt ) ) * np . diff ( t ** 2... |
def get_logger ( name ) :
"""Get a logger with the specified name .""" | logger = logging . getLogger ( name )
logger . setLevel ( getenv ( 'LOGLEVEL' , 'INFO' ) )
return logger |
def __initialize_ui ( self ) :
"""Initializes the Widget ui .""" | LOGGER . debug ( "> Initializing Application toolBar!" )
self . setIconSize ( QSize ( UiConstants . default_toolbar_icon_size , UiConstants . default_toolbar_icon_size ) )
self . setAllowedAreas ( Qt . TopToolBarArea )
self . setFloatable ( False )
self . setMovable ( False )
self . set_layout_default_geometry ( )
self... |
def format_full_name ( first_name : str , last_name : str , max_length : int = 20 ) :
"""Limits name length to specified length . Tries to keep name as human - readable an natural as possible .
: param first _ name : First name
: param last _ name : Last name
: param max _ length : Maximum length
: return :... | # dont allow commas in limited names
first_name = first_name . replace ( ',' , ' ' )
last_name = last_name . replace ( ',' , ' ' )
# accept short full names as is
original_full_name = first_name + ' ' + last_name
if len ( original_full_name ) <= max_length :
return original_full_name
# drop middle names
first_name ... |
def all ( self , res ) :
"Get resources using a filter condition" | B = get_backend ( )
return B . get_objects ( B . get_concrete ( res ) ) |
def _get_params ( mapper_spec , allowed_keys = None , allow_old = True ) :
"""Obtain input reader parameters .
Utility function for input readers implementation . Fetches parameters
from mapreduce specification giving appropriate usage warnings .
Args :
mapper _ spec : The MapperSpec for the job
allowed _... | if "input_reader" not in mapper_spec . params :
message = ( "Input reader's parameters should be specified in " "input_reader subdictionary." )
if not allow_old or allowed_keys :
raise errors . BadReaderParamsError ( message )
params = mapper_spec . params
params = dict ( ( str ( n ) , v ) for n... |
def from_ff_and_topologies ( cls , box , ff , topologies , atom_style = "full" ) :
"""Constructor building LammpsData from a ForceField object and a
list of Topology objects . Do not support intermolecular
topologies since a Topology object includes data for ONE
molecule or structure only .
Args :
box ( L... | atom_types = set . union ( * [ t . species for t in topologies ] )
assert atom_types . issubset ( ff . maps [ "Atoms" ] . keys ( ) ) , "Unknown atom type found in topologies"
items = dict ( box = box , atom_style = atom_style , masses = ff . masses , force_field = ff . force_field )
mol_ids , charges , coords , labels ... |
def read ( filename ) :
"""Read a file relative to setup . py location .""" | import os
here = os . path . dirname ( os . path . abspath ( __file__ ) )
with open ( os . path . join ( here , filename ) ) as fd :
return fd . read ( ) |
def plot_wigner2d ( iradon_output , bin_centres , cmap = _cm . cubehelix_r , figsize = ( 6 , 6 ) ) :
"""Plots the wigner space representation as a 2D heatmap .
Parameters
iradon _ output : ndarray
2d array of size ( histbins x histbins )
bin _ centres : ndarray
positions of the bin centres
cmap : matplo... | xx , yy = _np . meshgrid ( bin_centres , bin_centres )
resid1 = iradon_output . sum ( axis = 0 )
resid2 = iradon_output . sum ( axis = 1 )
wigner_marginal_seperation = 0.001
left , width = 0.2 , 0.65 - 0.1
# left = left side of hexbin and hist _ x
bottom , height = 0.1 , 0.65 - 0.1
# bottom = bottom of hexbin and hist ... |
def getMusicAlbumList ( self , tagtype = 0 , startnum = 0 , pagingrow = 100 ) :
"""GetMusicAlbumList
Args :
tagtype = ? ? ?
startnum
pagingrow
Returns :
False : Failed to get property""" | url = nurls [ 'setProperty' ]
data = { 'userid' : self . user_id , 'useridx' : self . useridx , 'tagtype' : tagtype , 'startnum' : startnum , 'pagingrow' : pagingrow , }
r = self . session . post ( url = url , data = data )
return resultManager ( r . text ) |
def get_version ( module ) :
"""Return package version as listed in ` _ _ version _ _ ` .""" | init_py = open ( '{0}.py' . format ( module ) ) . read ( )
return re . search ( "__version__ = ['\"]([^'\"]+)['\"]" , init_py ) . group ( 1 ) |
def AddPort ( self , protocol , port , port_to = None ) :
"""Add and commit a single port .
# Add single port
> > > clc . v2 . Server ( " WA1BTDIX01 " ) . PublicIPs ( ) . public _ ips [ 0 ] . AddPort ( protocol = ' TCP ' , port = ' 22 ' ) . WaitUntilComplete ( )
# Add port range
> > > clc . v2 . Server ( " ... | self . ports . append ( Port ( self , protocol , port , port_to ) )
return ( self . Update ( ) ) |
def links ( cls , page ) :
"""return all links on a page , including potentially rel = links .""" | for match in cls . HREF_RE . finditer ( page ) :
yield cls . href_match_to_url ( match ) |
async def get_decryption_aes_key ( self , key : bytes , material_description : Dict [ str , Any ] ) -> bytes :
"""Get decryption key for a given S3 object
: param key : Base64 decoded version of x - amz - key - v2
: param material _ description : JSON decoded x - amz - matdesc
: return : Raw AES key bytes""" | raise NotImplementedError ( ) |
def parse_log ( file_path ) :
"""Parse a CISM output log and extract some information .
Args :
file _ path : absolute path to the log file
Return :
A dictionary created by the elements object corresponding to
the results of the bit for bit testing""" | if not os . path . isfile ( file_path ) :
return elements . error ( "Output Log" , "Could not open file: " + file_path . split ( os . sep ) [ - 1 ] )
headers = [ "Converged Iterations" , "Avg. Iterations to Converge" , "Processor Count" , "Dycore Type" ]
with open ( file_path , 'r' ) as f :
dycore_types = { "0"... |
def union ( union_a , union_b ) :
"""Union of two vector layers .
Issue https : / / github . com / inasafe / inasafe / issues / 3186
: param union _ a : The vector layer for the union .
: type union _ a : QgsVectorLayer
: param union _ b : The vector layer for the union .
: type union _ b : QgsVectorLayer... | output_layer_name = union_steps [ 'output_layer_name' ]
output_layer_name = output_layer_name % ( union_a . keywords [ 'layer_purpose' ] , union_b . keywords [ 'layer_purpose' ] )
keywords_union_1 = union_a . keywords
keywords_union_2 = union_b . keywords
inasafe_fields_union_1 = keywords_union_1 [ 'inasafe_fields' ]
i... |
def conceptual_info ( subsystem ) :
"""Return the conceptual information for a | Subsystem | .
This is the distance from the subsystem ' s | CauseEffectStructure | to the
null concept .""" | ci = ces_distance ( ces ( subsystem ) , CauseEffectStructure ( ( ) , subsystem = subsystem ) )
return round ( ci , config . PRECISION ) |
def check_selection_for_save ( self , task , releasetype , descriptor ) :
"""Emit warnings if the descriptor is None or the current file
is of a different task .
: param task : the selected task
: type task : : class : ` djadapter . models . Task `
: param releasetype : the releasetype to save ( probably wo... | if not descriptor :
self . statusbar . showMessage ( "Please provide a descriptor!" )
return False
try :
jukedj . validators . alphanum_vld ( descriptor )
except ValidationError :
self . statusbar . showMessage ( "Descriptor contains characters other than alphanumerical ones." )
return False
cur = s... |
def snmp_server_user_ipv4_acl ( self , ** kwargs ) :
"""Auto Generated Code""" | config = ET . Element ( "config" )
snmp_server = ET . SubElement ( config , "snmp-server" , xmlns = "urn:brocade.com:mgmt:brocade-snmp" )
user = ET . SubElement ( snmp_server , "user" )
username_key = ET . SubElement ( user , "username" )
username_key . text = kwargs . pop ( 'username' )
ipv4_acl = ET . SubElement ( us... |
def set_current_filename ( self , filename , focus = True ) :
"""Set current filename and return the associated editor instance .""" | index = self . has_filename ( filename )
if index is not None :
if focus :
self . set_stack_index ( index )
editor = self . data [ index ] . editor
if focus :
editor . setFocus ( )
else :
self . stack_history . remove_and_append ( index )
return editor |
def load ( self , key = None ) : # type : ( Hashable ) - > Promise
"""Loads a key , returning a ` Promise ` for the value represented by that key .""" | if key is None :
raise TypeError ( ( "The loader.load() function must be called with a value," + "but got: {}." ) . format ( key ) )
cache_key = self . get_cache_key ( key )
# If caching and there is a cache - hit , return cached Promise .
if self . cache :
cached_promise = self . _promise_cache . get ( cache_k... |
def points_with_surrounding_gaps ( points ) :
"""This function makes sure that any gaps in the sequence provided have stopper points at their beginning
and end so a graph will be drawn with correct 0 ranges . This is more efficient than filling in all points
up to the maximum value . For example :
input : [ 1... | points_with_gaps = [ ]
last_point = - 1
for point in points :
if last_point + 1 == point :
pass
elif last_point + 2 == point :
points_with_gaps . append ( last_point + 1 )
else :
points_with_gaps . append ( last_point + 1 )
points_with_gaps . append ( point - 1 )
points_w... |
def content ( self ) :
"""以处理过的Html代码形式返回答案内容 .
: return : 答案内容
: rtype : str""" | answer_wrap = self . soup . find ( 'div' , id = 'zh-question-answer-wrap' )
content = answer_wrap . find ( 'div' , class_ = 'zm-editable-content' )
content = answer_content_process ( content )
return content |
def only ( self , * fields ) :
'''Restricts the fields to be fetched when mapping . Set to ` _ _ model ` to fetch all fields define in the ModelIndex .''' | s = self . _clone ( )
if len ( fields ) == 1 and fields [ 0 ] == '__model' :
s . _only = '__model'
else :
s . _only = fields
return s |
def report ( self , simulation , state ) :
"""Generate a report .
Parameters
simulation : Simulation
The Simulation to generate a report for
state : State
The current state of the simulation""" | if not self . _initialized :
self . _initial_clock_time = datetime . now ( )
self . _initial_simulation_time = state . getTime ( )
self . _initial_steps = simulation . currentStep
self . _initialized = True
steps = simulation . currentStep
time = datetime . now ( ) - self . _initial_clock_time
days = ti... |
def select ( self , selection_specs = None , ** selection ) :
"""Applies selection by dimension name
Applies a selection along the dimensions of the object using
keyword arguments . The selection may be narrowed to certain
objects using selection _ specs . For container objects the
selection will be applied... | if selection_specs is not None and not isinstance ( selection_specs , ( list , tuple ) ) :
selection_specs = [ selection_specs ]
selection = { dim : sel for dim , sel in selection . items ( ) if dim in self . dimensions ( ) + [ 'selection_mask' ] }
if ( selection_specs and not any ( self . matches ( sp ) for sp in ... |
def get_intern_pattern ( self , url = None ) :
"""Get pattern for intern URL matching .
@ return non - empty regex pattern or None
@ rtype String or None""" | if url is None :
url = absolute_url ( self . base_url , self . base_ref , self . parent_url )
if not url :
return None
return get_intern_pattern ( url ) |
def extend_hierarchy ( levels , strength , CF , keep ) :
"""Extend the multigrid hierarchy .""" | def unpack_arg ( v ) :
if isinstance ( v , tuple ) :
return v [ 0 ] , v [ 1 ]
else :
return v , { }
A = levels [ - 1 ] . A
# Compute the strength - of - connection matrix C , where larger
# C [ i , j ] denote stronger couplings between i and j .
fn , kwargs = unpack_arg ( strength )
if fn == 'sy... |
def _validate ( self , val ) :
"""val must be None , an instance of self . class _ if self . is _ instance = True or a subclass of self _ class if self . is _ instance = False""" | if isinstance ( self . class_ , tuple ) :
class_name = ( '(%s)' % ', ' . join ( cl . __name__ for cl in self . class_ ) )
else :
class_name = self . class_ . __name__
if self . is_instance :
if not ( isinstance ( val , self . class_ ) ) and not ( val is None and self . allow_None ) :
raise ValueErro... |
def get_assets ( self ) :
"""Gets the asset list resulting from a search .
return : ( osid . repository . AssetList ) - the asset list
raise : IllegalState - the list has already been retrieved
* compliance : mandatory - - This method must be implemented . *""" | if self . retrieved :
raise errors . IllegalState ( 'List has already been retrieved.' )
self . retrieved = True
return objects . AssetList ( self . _results , runtime = self . _runtime ) |
def get ( self , key ) :
"""Gets a value by a key .
Args :
key ( str ) : Key to retrieve the value .
Returns : Retrieved value .""" | self . _create_file_if_none_exists ( )
with open ( self . filename , 'rb' ) as file_object :
cache_pickle = pickle . load ( file_object )
val = cache_pickle . get ( key , None )
return val |
def _try_prop_method ( self , instance , value , method_name ) :
"""Helper method to perform a method on each of the union props
This method gathers all errors and returns them at the end
if the method on each of the props fails .""" | error_messages = [ ]
for prop in self . props :
try :
return getattr ( prop , method_name ) ( instance , value )
except GENERIC_ERRORS as err :
if hasattr ( err , 'error_tuples' ) :
error_messages += [ err_tup . message for err_tup in err . error_tuples ]
if error_messages :
extr... |
def _w_sigma_delta ( self , sigma , delta ) :
"""invert variance
: param sigma :
: param delta :
: return : w parameter""" | sigma2 = sigma ** 2
w2 = sigma2 / ( 1 - 2 * delta ** 2 / np . pi )
w = np . sqrt ( w2 )
return w |
def get_instance ( self , payload ) :
"""Build an instance of AssignedAddOnExtensionInstance
: param dict payload : Payload response from the API
: returns : twilio . rest . api . v2010 . account . incoming _ phone _ number . assigned _ add _ on . assigned _ add _ on _ extension . AssignedAddOnExtensionInstance... | return AssignedAddOnExtensionInstance ( self . _version , payload , account_sid = self . _solution [ 'account_sid' ] , resource_sid = self . _solution [ 'resource_sid' ] , assigned_add_on_sid = self . _solution [ 'assigned_add_on_sid' ] , ) |
def _import_model ( models , crumbs ) :
"""Change the nested items of the paleoModel data . Overwrite the data in - place .
: param list models : Metadata
: param str crumbs : Crumbs
: return dict _ models : Metadata""" | logger_jsons . info ( "enter import_model" . format ( crumbs ) )
_models = OrderedDict ( )
try :
for _idx , model in enumerate ( models ) : # Keep the original dictionary , but replace the three main entries below
# Do a direct replacement of chronModelTable columns . No table name , no table work needed .
... |
def get_subdomain_ops_at_txid ( txid , db_path = None , zonefiles_dir = None ) :
"""Static method for getting the list of subdomain operations accepted at a given txid .
Includes unaccepted subdomain operations""" | opts = get_blockstack_opts ( )
if not is_subdomains_enabled ( opts ) :
return [ ]
if db_path is None :
db_path = opts [ 'subdomaindb_path' ]
if zonefiles_dir is None :
zonefiles_dir = opts [ 'zonefiles' ]
db = SubdomainDB ( db_path , zonefiles_dir )
return db . get_subdomain_ops_at_txid ( txid ) |
def __parseResponse ( self , result ) :
"""Parses the server response .""" | response = [ ]
for data in result [ 'data' ] :
result_dict = { }
for k , v in data . items ( ) :
column = self . getOutputColumn ( k )
if column != None :
type = column . getSqlColumnType ( )
if type != None and type . startswith ( 'int' ) :
result_dict . ... |
def swap_atom_keys ( self , swap_dict , dict_key = 'atom_ids' ) :
"""Swap a force field atom id for another user - defined value .
This modified all values in : attr : ` MolecularSystem . system [ ' atom _ ids ' ] `
that match criteria .
This function can be used to decipher a whole forcefield if an
appropr... | # Similar situation to the one from decipher _ atom _ keys function .
if 'atom_ids' not in self . system . keys ( ) :
dict_key = 'elements'
for atom_key in range ( len ( self . system [ dict_key ] ) ) :
for key in swap_dict . keys ( ) :
if self . system [ dict_key ] [ atom_key ] == key :
sel... |
def cover ( self ) :
"""album cover as : class : ` Picture ` object""" | if not self . _cover :
self . _cover = Picture ( self . _cover_url , self . _connection )
return self . _cover |
def humanize_filesize ( value ) :
"""Return an humanized file size .""" | value = float ( value )
if value == 1 :
return '1 Byte'
elif value < 1024 :
return '%d Bytes' % value
elif value < 1024 :
return '%dB' % value
for i , s in enumerate ( SUFFIXES ) :
unit = 1024 ** ( i + 2 )
if value < unit :
return '%.1f %s' % ( ( 1024 * value / unit ) , s )
return '%.1f %s' ... |
def stationary_distribution_sensitivity ( T , j ) :
r"""Calculate the sensitivity matrix for entry j the stationary
distribution vector given transition matrix T .
Parameters
T : numpy . ndarray shape = ( n , n )
Transition matrix
j : int
entry of stationary distribution for which the sensitivity is to ... | n = len ( T )
lEV = numpy . ones ( n )
rEV = stationary_distribution ( T )
eVal = 1.0
T = numpy . transpose ( T )
vecA = numpy . zeros ( n )
vecA [ j ] = 1.0
matA = T - eVal * numpy . identity ( n )
# normalize s . t . sum is one using rEV which is constant
matA = numpy . concatenate ( ( matA , [ lEV ] ) )
phi = numpy ... |
def text_dict_write ( fpath , dict_ ) :
"""Very naive , but readable way of storing a dictionary on disk
FIXME : This broke on RoseMary ' s big dataset . Not sure why . It gave bad
syntax . And the SyntaxError did not seem to be excepted .""" | # dict _ = text _ dict _ read ( fpath )
# dict _ [ key ] = val
dict_text2 = util_str . repr4 ( dict_ , strvals = False )
if VERBOSE :
print ( '[cache] ' + str ( dict_text2 ) )
util_io . write_to ( fpath , dict_text2 ) |
def get_feedback ( self , feedback = None , ** kwargs ) :
"""[ NOT IMPLEMENTED ]
: raises NotImplementedError : because it isn ' t""" | raise NotImplementedError
if feedback is not None :
kwargs [ 'feedback' ] = feedback
kwargs [ 'context' ] = 'feedback'
return self . filter ( ** kwargs ) |
def findPrimerBidi ( primer , seq ) :
"""Look for a primer in a sequence and its reverse complement .
@ param primer : A C { str } primer sequence .
@ param seq : A BioPython C { Bio . Seq } sequence .
@ return : A C { tuple } of two lists . The first contains ( zero - based )
ascending offsets into the seq... | # Note that we reverse complement the primer to find the reverse
# matches . This is much simpler than reverse complementing the sequence
# because it allows us to use findPrimer and to deal with overlapping
# matches correctly .
forward = findPrimer ( primer , seq )
reverse = findPrimer ( reverse_complement ( primer )... |
def iso8601_datetime ( d ) :
"""Return a string representation of a date that the Twilio API understands
Format is YYYY - MM - DD . Returns None if d is not a string , datetime , or date""" | if d == values . unset :
return d
elif isinstance ( d , datetime . datetime ) or isinstance ( d , datetime . date ) :
return d . strftime ( '%Y-%m-%dT%H:%M:%SZ' )
elif isinstance ( d , str ) :
return d |
def _getUniqueName ( self , fileName , jobStoreID = None , sourceFunctionName = "x" ) :
"""Create unique file name within a jobStore directory or tmp directory .
: param fileName : A file name , which can be a full path as only the
basename will be used .
: param jobStoreID : If given , the path returned will... | fd , absPath = self . _getTempFile ( jobStoreID )
os . close ( fd )
os . unlink ( absPath )
# remove the . tmp extension and add the file name
( noExt , ext ) = os . path . splitext ( absPath )
uniquePath = noExt + '-' + sourceFunctionName + '-' + os . path . basename ( fileName )
if os . path . exists ( absPath ) :
... |
def get_tab ( self , tab_name , allow_disabled = False ) :
"""Returns a specific tab from this tab group .
If the tab is not allowed or not enabled this method returns ` ` None ` ` .
If the tab is disabled but you wish to return it anyway , you can pass
` ` True ` ` to the allow _ disabled argument .""" | tab = self . _tabs . get ( tab_name , None )
if tab and tab . _allowed and ( tab . _enabled or allow_disabled ) :
return tab
return None |
def option ( func , * args , ** attrs ) :
"""Args :
func ( function ) : Function defining this option
* args : Optional extra short flag name
* * attrs : Optional attr overrides provided by caller
Returns :
function : Click decorator""" | if click is None :
return func
def decorator ( f ) :
name = attrs . pop ( "name" , func . __name__ . replace ( "_" , "-" ) )
attrs . setdefault ( "help" , func . __doc__ )
attrs . setdefault ( "required" , False )
if not attrs . get ( "is_flag" ) :
attrs . setdefault ( "show_default" , True ... |
def _clean_flags ( args , caller ) :
'''Sanitize flags passed into df''' | flags = ''
if args is None :
return flags
allowed = ( 'a' , 'B' , 'h' , 'H' , 'i' , 'k' , 'l' , 'P' , 't' , 'T' , 'x' , 'v' )
for flag in args :
if flag in allowed :
flags += flag
else :
raise CommandExecutionError ( 'Invalid flag passed to {0}' . format ( caller ) )
return flags |
def profile ( ids = None , track_ids = None , buckets = None , limit = False ) :
"""get the profiles for multiple songs at once
Args :
ids ( str or list ) : a song ID or list of song IDs
Kwargs :
buckets ( list ) : A list of strings specifying which buckets to retrieve
limit ( bool ) : A boolean indicatin... | kwargs = { }
if ids :
if not isinstance ( ids , list ) :
ids = [ ids ]
kwargs [ 'id' ] = ids
if track_ids :
if not isinstance ( track_ids , list ) :
track_ids = [ track_ids ]
kwargs [ 'track_id' ] = track_ids
buckets = buckets or [ ]
if buckets :
kwargs [ 'bucket' ] = buckets
if limi... |
def _evolve_kwargs ( self ) :
"""Filter None keyword arguments . Intended to be passed on to algorithm . evolve ( . . . )""" | valid_evolve_kwargs = ( 'max_generations' , 'max_evaluations' , 'pop_size' , 'neighborhood_size' , 'tournament_size' , 'mutation_rate' )
filtered_evolve_kwargs = dict ( )
for key in valid_evolve_kwargs :
attr_value = getattr ( self , key )
if attr_value is not None :
filtered_evolve_kwargs [ key ] = att... |
def set_state ( self , state , enable ) :
"""Set the state .""" | is_enabled = self . get_state ( state )
if is_enabled == enable :
return True
key = None
desired_states = [ { 'state' : state , 'enabled' : not is_enabled } ]
if state == States . FILTER_LOW_SPEED :
if not self . _multi_speed_pump :
return False
# Send the FILTER key once .
# If the pump is in h... |
def update ( self , ell , k ) :
"""Update the posterior and estimates after a label is sampled
Parameters
ell : int
sampled label : 0 or 1
k : int
index of stratum where label was sampled""" | self . alpha_ [ k ] += ell
self . beta_ [ k ] += 1 - ell
self . _calc_theta ( )
if self . store_variance :
self . _calc_var_theta ( ) |
def publish ( self ) :
"""Start asynchonous publishing
Publishing takes into account all available and currently
toggled plug - ins and instances .""" | def get_data ( ) :
model = self . data [ "models" ] [ "item" ]
# Communicate with host to retrieve current plugins and instances
# This can potentially take a very long time ; it is run
# asynchronously and initiates processing once complete .
host_plugins = dict ( ( p . id , p ) for p in self . hos... |
def monitor_deletion ( ) :
"""Function for checking for correct deletion of weakref - able objects .
Example usage : :
monitor , is _ alive = monitor _ deletion ( )
obj = set ( )
monitor ( obj , " obj " )
assert is _ alive ( " obj " ) # True because there is a ref to ` obj ` is _ alive
del obj
assert ... | monitors = { }
def set_deleted ( x ) :
def _ ( weakref ) :
del monitors [ x ]
return _
def monitor ( item , name ) :
monitors [ name ] = ref ( item , set_deleted ( name ) )
def is_alive ( name ) :
return monitors . get ( name , None ) is not None
return monitor , is_alive |
def tag ( self : object , tokens : List [ str ] ) :
"""Docs ( mostly ) inherited from TaggerI ; cf .
https : / / www . nltk . org / _ modules / nltk / tag / api . html # TaggerI . tag
Two tweaks :
1 . Properly handle ' verbose ' listing of current tagger in
the case of None ( i . e . ` ` if tag : etc . ` ` ... | tags = [ ]
taggers = [ ]
for i in range ( len ( tokens ) ) :
tag , tagger = self . tag_one ( tokens , i , tags )
tags . append ( tag )
taggers . append ( str ( tagger ) ) if tag else taggers . append ( None )
if self . VERBOSE :
return list ( zip ( tokens , tags , taggers ) )
else :
return list ( zi... |
def getUpperDetectionLimit ( self ) :
"""Returns the Upper Detection Limit ( UDL ) that applies to this
analysis in particular . If no value set or the analysis service
doesn ' t allow manual input of detection limits , returns the value set
by default in the Analysis Service""" | if self . isUpperDetectionLimit ( ) :
result = self . getResult ( )
try : # in this case , the result itself is the LDL .
return float ( result )
except ( TypeError , ValueError ) :
logger . warn ( "The result for the analysis %s is a lower " "detection limit, but not floatable: '%s'. " "Ret... |
def updateUserTone ( conversationPayload , toneAnalyzerPayload , maintainHistory ) :
"""updateUserTone processes the Tone Analyzer payload to pull out the emotion ,
writing and social tones , and identify the meaningful tones ( i . e . ,
those tones that meet the specified thresholds ) .
The conversationPaylo... | emotionTone = None
writingTone = None
socialTone = None
# if there is no context in a
if 'context' not in conversationPayload :
conversationPayload [ 'context' ] = { }
if 'user' not in conversationPayload [ 'context' ] :
conversationPayload [ 'context' ] = initUser ( )
# For convenience sake , define a variable... |
def log_predictive_density ( self , y_test , mu_star , var_star , Y_metadata = None ) :
"""assumes independence""" | v = var_star + self . variance
return - 0.5 * np . log ( 2 * np . pi ) - 0.5 * np . log ( v ) - 0.5 * np . square ( y_test - mu_star ) / v |
def get_merge_rules ( schema = None ) :
"""Returns merge rules as key - value pairs , in which the key is a JSON path as a tuple , and the value is a list of
merge properties whose values are ` true ` .""" | schema = schema or get_release_schema_url ( get_tags ( ) [ - 1 ] )
if isinstance ( schema , dict ) :
deref_schema = jsonref . JsonRef . replace_refs ( schema )
else :
deref_schema = _get_merge_rules_from_url_or_path ( schema )
return dict ( _get_merge_rules ( deref_schema [ 'properties' ] ) ) |
def is_uniformly_weighted ( self ) :
"""` ` True ` ` if the weighting is the same for all space points .""" | try :
is_uniformly_weighted = self . __is_uniformly_weighted
except AttributeError :
bdry_fracs = self . partition . boundary_cell_fractions
is_uniformly_weighted = ( np . allclose ( bdry_fracs , 1.0 ) or self . exponent == float ( 'inf' ) or not getattr ( self . tspace , 'is_weighted' , False ) )
self ... |
def subst_dict ( target , source ) :
"""Create a dictionary for substitution of special
construction variables .
This translates the following special arguments :
target - the target ( object or array of objects ) ,
used to generate the TARGET and TARGETS
construction variables
source - the source ( obj... | dict = { }
if target :
def get_tgt_subst_proxy ( thing ) :
try :
subst_proxy = thing . get_subst_proxy ( )
except AttributeError :
subst_proxy = thing
# probably a string , just return it
return subst_proxy
tnl = NLWrapper ( target , get_tgt_subst_prox... |
def elementTypeName ( self ) :
"""String representation of the element type .""" | fieldName = self . nodeName
return str ( self . _h5Dataset . dtype . fields [ fieldName ] [ 0 ] ) |
def parse ( content ) :
"""Parse the content of a . env file ( a line - delimited KEY = value format ) into a
dictionary mapping keys to values .""" | values = { }
for line in content . splitlines ( ) :
lexer = shlex . shlex ( line , posix = True )
tokens = list ( lexer )
# parses the assignment statement
if len ( tokens ) < 3 :
continue
name , op = tokens [ : 2 ]
value = '' . join ( tokens [ 2 : ] )
if op != '=' :
continue... |
def item ( self , infohash , prefetch = None , cache = False ) :
"""Fetch a single item by its info hash .""" | return next ( self . items ( infohash , prefetch , cache ) ) |
def explained_variance ( returns , values ) :
"""Calculate how much variance in returns do the values explain""" | exp_var = 1 - torch . var ( returns - values ) / torch . var ( returns )
return exp_var . item ( ) |
def _random_stochastic_matrix ( m , n , k = None , sparse = False , format = 'csr' , random_state = None ) :
"""Generate a " non - square stochastic matrix " of shape ( m , n ) , which
contains as rows m probability vectors of length n with k nonzero
entries .
For other parameters , see ` random _ stochastic ... | if k is None :
k = n
# m prob vectors of dimension k , shape ( m , k )
probvecs = probvec ( m , k , random_state = random_state )
if k == n :
P = probvecs
if sparse :
return scipy . sparse . coo_matrix ( P ) . asformat ( format )
else :
return P
# if k < n :
rows = np . repeat ( np . ara... |
def open_outside_spyder ( self , fnames ) :
"""Open file outside Spyder with the appropriate application
If this does not work , opening unknown file in Spyder , as text file""" | for path in sorted ( fnames ) :
path = file_uri ( path )
ok = programs . start_file ( path )
if not ok :
self . sig_edit . emit ( path ) |
def read_handle ( self , handle : int ) -> bytes :
"""Read a handle from the device .""" | if not self . is_connected ( ) :
raise BluetoothBackendException ( 'Not connected to device!' )
return self . _device . char_read_handle ( handle ) |
def render_linked_css ( self , css_files : Iterable [ str ] ) -> str :
"""Default method used to render the final css links for the
rendered webpage .
Override this method in a sub - classed controller to change the output .""" | paths = [ ]
unique_paths = set ( )
# type : Set [ str ]
for path in css_files :
if not is_absolute ( path ) :
path = self . static_url ( path )
if path not in unique_paths :
paths . append ( path )
unique_paths . add ( path )
return "" . join ( '<link href="' + escape . xhtml_escape ( p ... |
def container_state ( name = None , remote_addr = None , cert = None , key = None , verify_cert = True ) :
'''Get container state
remote _ addr :
An URL to a remote Server , you also have to give cert and key if
you provide remote _ addr and its a TCP Address !
Examples :
https : / / myserver . lan : 8443... | client = pylxd_client_get ( remote_addr , cert , key , verify_cert )
if name is None :
containers = client . containers . all ( )
else :
try :
containers = [ client . containers . get ( name ) ]
except pylxd . exceptions . LXDAPIException :
raise SaltInvocationError ( 'Container \'{0}\' not ... |
def deprecated ( message ) :
"""Deprecated function decorator .""" | def wrapper ( fn ) :
def deprecated_method ( * args , ** kargs ) :
warnings . warn ( message , DeprecationWarning , 2 )
return fn ( * args , ** kargs )
# TODO : use decorator ? functools . wrapper ?
deprecated_method . __name__ = fn . __name__
deprecated_method . __doc__ = "%s\n\n%s" % (... |
def close_stream ( self ) :
"""Close the underlying socket .""" | if not self . is_connected :
return
self . stream . close ( )
self . state = DISCONNECTED
self . on_close . send ( self ) |
def make_attribute_list ( self , node ) :
"""Produces the " Attributes " section in class docstrings for public
member variables ( attributes ) .""" | atr_nodes = [ ]
for n in self . get_specific_subnodes ( node , 'memberdef' , recursive = 2 ) :
if n . attributes [ 'kind' ] . value == 'variable' and n . attributes [ 'prot' ] . value == 'public' :
atr_nodes . append ( n )
if not atr_nodes :
return
self . add_text ( [ '\n' , 'Attributes' , '\n' , '-----... |
def plotly_app_identifier ( name = None , slug = None , da = None , postfix = None ) :
'Return a slug - friendly identifier' | da , app = _locate_daapp ( name , slug , da )
slugified_id = app . slugified_id ( )
if postfix :
return "%s-%s" % ( slugified_id , postfix )
return slugified_id |
def _readfile ( self , filename ) :
"""Read content of specified NEWS file""" | f = open ( filename )
self . content = f . readlines ( )
f . close ( ) |
def mlon2mlt ( self , mlon , datetime , ssheight = 50 * 6371 ) :
"""Computes the magnetic local time at the specified magnetic longitude
and UT .
Parameters
mlon : array _ like
Magnetic longitude ( apex and quasi - dipole longitude are always
equal )
datetime : : class : ` datetime . datetime `
Date a... | ssglat , ssglon = helpers . subsol ( datetime )
ssalat , ssalon = self . geo2apex ( ssglat , ssglon , ssheight )
# np . float64 will ensure lists are converted to arrays
return ( 180 + np . float64 ( mlon ) - ssalon ) / 15 % 24 |
def code_from_ipynb ( nb , markdown = False ) :
"""Get the code for a given notebook
nb is passed in as a dictionary that ' s a parsed ipynb file""" | code = PREAMBLE
for cell in nb [ 'cells' ] :
if cell [ 'cell_type' ] == 'code' : # transform the input to executable Python
code += '' . join ( cell [ 'source' ] )
if cell [ 'cell_type' ] == 'markdown' :
code += '\n# ' + '# ' . join ( cell [ 'source' ] )
# We want a blank newline after each ... |
def create_response ( version , status , headers ) :
"""Create a HTTP response header .""" | message = [ ]
message . append ( 'HTTP/{} {}\r\n' . format ( version , status ) )
for name , value in headers :
message . append ( name )
message . append ( ': ' )
message . append ( value )
message . append ( '\r\n' )
message . append ( '\r\n' )
return s2b ( '' . join ( message ) ) |
def find_in_subgraph_by_name ( subgraph , target_name , target_package , nodetype ) :
"""Find an entry in a subgraph by name . Any mapping that implements
. items ( ) and maps unique id - > something can be used as the subgraph .
Names are like :
' { nodetype } . { target _ package } . { target _ name } '
Y... | for name , model in subgraph . items ( ) :
if id_matches ( name , target_name , target_package , nodetype , model ) :
return model
return None |
def getDateReceived ( self ) :
"""Used to populate catalog values .
Returns the date the Analysis Request this analysis belongs to was
received . If the analysis was created after , then returns the date
the analysis was created .""" | request = self . getRequest ( )
if request :
ar_date = request . getDateReceived ( )
if ar_date and self . created ( ) > ar_date :
return self . created ( )
return ar_date
return None |
def max_size ( self ) :
"""Gets the largest size of the object over all timesteps .
Returns :
Maximum size of the object in pixels""" | sizes = np . array ( [ m . sum ( ) for m in self . masks ] )
return sizes . max ( ) |
def add_url ( self , issuer , url , ** kwargs ) :
"""Add a set of keys by url . This method will create a
: py : class : ` oidcmsg . key _ bundle . KeyBundle ` instance with the
url as source specification . If no file format is given it ' s assumed
that what ' s on the other side is a JWKS .
: param issuer... | if not url :
raise KeyError ( "No url given" )
if "/localhost:" in url or "/localhost/" in url :
kb = self . keybundle_cls ( source = url , verify_ssl = False , httpc = self . httpc , ** kwargs )
else :
kb = self . keybundle_cls ( source = url , verify_ssl = self . verify_ssl , httpc = self . httpc , ** kwa... |
def delete_comment ( repo : GithubRepository , comment_id : int ) -> None :
"""References :
https : / / developer . github . com / v3 / issues / comments / # delete - a - comment""" | url = ( "https://api.github.com/repos/{}/{}/issues/comments/{}" "?access_token={}" . format ( repo . organization , repo . name , comment_id , repo . access_token ) )
response = requests . delete ( url )
if response . status_code != 204 :
raise RuntimeError ( 'Comment delete failed. Code: {}. Content: {}.' . format... |
def graph_attention ( q , k , v , bias , dropout_rate = 0.0 , image_shapes = None , name = None , make_image_summary = True , save_weights_to = None , dropout_broadcast_dims = None , adjacency_matrix = None , num_edge_types = 5 ) :
"""graph attention .
Args :
q : a Tensor with shape [ batch , heads , length _ q... | with tf . variable_scope ( name , default_name = "dot_product_attention" , values = [ q , k , v ] ) as scope : # [ batch , num _ heads , query _ length , memory _ length ]
logits = tf . matmul ( q , k , transpose_b = True )
if adjacency_matrix is not None :
key_head_depth = common_layers . shape_list ( ... |
def headers_as_dict ( cls , resp ) :
"""Turns an array of response headers into a dictionary""" | if six . PY2 :
pairs = [ header . split ( ':' , 1 ) for header in resp . msg . headers ]
return dict ( [ ( k , v . strip ( ) ) for k , v in pairs ] )
else :
return dict ( [ ( k , v . strip ( ) ) for k , v in resp . msg . _headers ] ) |
def url ( self ) :
"""Path to local catalog file""" | return os . path . join ( self . path , self . main . value [ 0 ] ) |
def set_access_control ( self , mode , onerror = None ) :
"""Enable use of access control lists at connection setup if mode
is X . EnableAccess , disable if it is X . DisableAccess .""" | request . SetAccessControl ( display = self . display , onerror = onerror , mode = mode ) |
def start_fitting ( self ) :
"""Launches the fitting routine on another thread""" | self . queue = queue . Queue ( )
self . peak_vals = [ ]
self . fit_thread = QThread ( )
# must be assigned as an instance variable , not local , as otherwise thread is garbage
# collected immediately at the end of the function before it runs
self . fitobj = self . do_fit ( str ( self . data_filepath . text ( ) ) , self... |
def check_session ( self ) :
"""Make sure a session is open .
If it ' s not and autosession is turned on , create a new session automatically .
If it ' s not and autosession is off , raise an exception .""" | if self . session is None :
if self . autosession :
self . open_session ( )
else :
msg = "must open a session before modifying %s" % self
raise RuntimeError ( msg ) |
def total_write_throughput ( self ) :
"""Combined write throughput of table and global indexes""" | total = self . write_throughput
for index in itervalues ( self . global_indexes ) :
total += index . write_throughput
return total |
def find_hbd ( self , all_atoms , hydroph_atoms ) :
"""Find all possible strong and weak hydrogen bonds donors ( all hydrophobic C - H pairings )""" | donor_pairs = [ ]
data = namedtuple ( 'hbonddonor' , 'd d_orig_atom d_orig_idx h type' )
for donor in [ a for a in all_atoms if a . OBAtom . IsHbondDonor ( ) and a . idx not in self . altconf ] :
in_ring = False
if not in_ring :
for adj_atom in [ a for a in pybel . ob . OBAtomAtomIter ( donor . OBAtom )... |
def detectIphone ( self ) :
"""Return detection of an iPhone
Detects if the current device is an iPhone .""" | # The iPad and iPod touch say they ' re an iPhone ! So let ' s disambiguate .
return UAgentInfo . deviceIphone in self . __userAgent and not self . detectIpad ( ) and not self . detectIpod ( ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.