signature stringlengths 29 44.1k | implementation stringlengths 0 85.2k |
|---|---|
def convert_from_gps_time ( gps_time , gps_week = None ) :
"""Convert gps time in ticks to standard time .""" | converted_gps_time = None
gps_timestamp = float ( gps_time )
if gps_week != None : # image date
converted_gps_time = GPS_START + datetime . timedelta ( seconds = int ( gps_week ) * SECS_IN_WEEK + gps_timestamp )
else : # TAI scale with 1970-01-01 00:00:10 ( TAI ) epoch
os . environ [ 'TZ' ] = 'right/UTC'
# ... |
def create_reward_encoder ( ) :
"""Creates TF ops to track and increment recent average cumulative reward .""" | last_reward = tf . Variable ( 0 , name = "last_reward" , trainable = False , dtype = tf . float32 )
new_reward = tf . placeholder ( shape = [ ] , dtype = tf . float32 , name = 'new_reward' )
update_reward = tf . assign ( last_reward , new_reward )
return last_reward , new_reward , update_reward |
def fixup_namespace_packages ( path_item , parent = None ) :
"""Ensure that previously - declared namespace packages include path _ item""" | _imp . acquire_lock ( )
try :
for package in _namespace_packages . get ( parent , ( ) ) :
subpath = _handle_ns ( package , path_item )
if subpath :
fixup_namespace_packages ( subpath , package )
finally :
_imp . release_lock ( ) |
def filter ( self , media_type , ** params ) :
"""iterate all the accept media types that match media _ type
media _ type - - string - - the media type to filter by
* * params - - dict - - further filter by key : val
return - - generator - - yields all matching media type info things""" | mtype , msubtype = self . _split_media_type ( media_type )
for x in self . __iter__ ( ) : # all the params have to match to make the media type valid
matched = True
for k , v in params . items ( ) :
if x [ 2 ] . get ( k , None ) != v :
matched = False
break
if matched :
... |
def drop_column ( self , table , name ) :
"""Remove a column to an existing table .""" | try :
self . execute ( 'ALTER TABLE {0} DROP COLUMN {1}' . format ( wrap ( table ) , name ) )
self . _printer ( '\tDropped column {0} from {1}' . format ( name , table ) )
except ProgrammingError :
self . _printer ( "\tCan't DROP '{0}'; check that column/key exists in '{1}'" . format ( name , table ) )
retu... |
def translate_sites ( self , indices , vector , frac_coords = True , to_unit_cell = True ) :
"""Translate specific sites by some vector , keeping the sites within the
unit cell .
Args :
indices : Integer or List of site indices on which to perform the
translation .
vector : Translation vector for sites . ... | if not isinstance ( indices , collections . abc . Iterable ) :
indices = [ indices ]
for i in indices :
site = self . _sites [ i ]
if frac_coords :
fcoords = site . frac_coords + vector
else :
fcoords = self . _lattice . get_fractional_coords ( site . coords + vector )
if to_unit_cel... |
def check_image_is_4d ( img , min_num_volumes = 2 ) :
"""Ensures the image loaded is 3d and nothing else .""" | if len ( img . shape ) < 4 :
raise ValueError ( 'Input volume must be 4D!' )
elif len ( img . shape ) == 4 :
for dim_size in img . shape [ : 3 ] :
if dim_size < 1 :
raise ValueError ( 'Atleast one slice must exist in each dimension' )
if img . shape [ 3 ] < min_num_volumes :
rais... |
def _format_info ( data ) :
'''Return user information in a pretty way''' | return { 'gid' : data . pw_gid , 'groups' : list_groups ( data . pw_name ) , 'home' : data . pw_dir , 'name' : data . pw_name , 'shell' : data . pw_shell , 'uid' : data . pw_uid , 'fullname' : data . pw_gecos } |
def df ( self ) :
"""Get data usage information .
Returns :
( dict ) : A dictionary representing different resource categories
and their respective data usage .
Raises :
: py : class : ` docker . errors . APIError `
If the server returns an error .""" | url = self . _url ( '/system/df' )
return self . _result ( self . _get ( url ) , True ) |
def parse_func_kwarg_keys ( func , with_vals = False ) :
"""hacky inference of kwargs keys
SeeAlso :
argparse _ funckw
recursive _ parse _ kwargs
parse _ kwarg _ keys
parse _ func _ kwarg _ keys
get _ func _ kwargs""" | sourcecode = get_func_sourcecode ( func , strip_docstr = True , strip_comments = True )
kwkeys = parse_kwarg_keys ( sourcecode , with_vals = with_vals )
# ut . get _ func _ kwargs TODO
return kwkeys |
def add_triangle ( self , neighbors , color , center = None , opacity = 0.4 , draw_edges = False , edges_color = [ 0.0 , 0.0 , 0.0 ] , edges_linewidth = 2 ) :
"""Adds a triangular surface between three atoms .
Args :
atoms : Atoms between which a triangle will be drawn .
color : Color for triangle as RGB .
... | points = vtk . vtkPoints ( )
triangle = vtk . vtkTriangle ( )
for ii in range ( 3 ) :
points . InsertNextPoint ( neighbors [ ii ] . x , neighbors [ ii ] . y , neighbors [ ii ] . z )
triangle . GetPointIds ( ) . SetId ( ii , ii )
triangles = vtk . vtkCellArray ( )
triangles . InsertNextCell ( triangle )
# polyda... |
def fields ( self ) :
"""Access the fields
: returns : twilio . rest . autopilot . v1 . assistant . task . field . FieldList
: rtype : twilio . rest . autopilot . v1 . assistant . task . field . FieldList""" | if self . _fields is None :
self . _fields = FieldList ( self . _version , assistant_sid = self . _solution [ 'assistant_sid' ] , task_sid = self . _solution [ 'sid' ] , )
return self . _fields |
def present ( name , tablespace = None , encoding = None , lc_collate = None , lc_ctype = None , owner = None , owner_recurse = False , template = None , user = None , maintenance_db = None , db_password = None , db_host = None , db_port = None , db_user = None ) :
'''Ensure that the named database is present with ... | ret = { 'name' : name , 'changes' : { } , 'result' : True , 'comment' : 'Database {0} is already present' . format ( name ) }
db_args = { 'maintenance_db' : maintenance_db , 'runas' : user , 'host' : db_host , 'user' : db_user , 'port' : db_port , 'password' : db_password , }
dbs = __salt__ [ 'postgres.db_list' ] ( ** ... |
def geo_field ( queryset ) :
"""Returns the GeometryField for a django or spillway GeoQuerySet .""" | for field in queryset . model . _meta . fields :
if isinstance ( field , models . GeometryField ) :
return field
raise exceptions . FieldDoesNotExist ( 'No GeometryField found' ) |
def get_taskfileinfo ( self , refobj ) :
"""Return the : class : ` jukeboxcore . filesys . TaskFileInfo ` that is loaded
by the refobj
: param refobj : the refobject to query
: type refobj : refobj
: returns : the taskfileinfo that is loaded in the scene
: rtype : : class : ` jukeboxcore . filesys . TaskF... | tf = self . get_taskfile ( refobj )
return TaskFileInfo . create_from_taskfile ( tf ) |
def get_media_detail_input_rbridge_id ( self , ** kwargs ) :
"""Auto Generated Code""" | config = ET . Element ( "config" )
get_media_detail = ET . Element ( "get_media_detail" )
config = get_media_detail
input = ET . SubElement ( get_media_detail , "input" )
rbridge_id = ET . SubElement ( input , "rbridge-id" )
rbridge_id . text = kwargs . pop ( 'rbridge_id' )
callback = kwargs . pop ( 'callback' , self .... |
def _process_plugin ( self , plugin ) :
'''Logic to handle each plugin that is active
@ param plugin : a plugin dict object''' | instance = plugin [ 'instance' ]
regex = plugin [ 'regex' ]
for key in self . redis_conn . scan_iter ( match = regex ) : # acquire lock
lock = self . _create_lock_object ( key )
try :
if lock . acquire ( blocking = False ) :
val = self . redis_conn . get ( key )
self . _process_k... |
def get_arp_input_input_type_static_static ( self , ** kwargs ) :
"""Auto Generated Code""" | config = ET . Element ( "config" )
get_arp = ET . Element ( "get_arp" )
config = get_arp
input = ET . SubElement ( get_arp , "input" )
input_type = ET . SubElement ( input , "input-type" )
static = ET . SubElement ( input_type , "static" )
static = ET . SubElement ( static , "static" )
callback = kwargs . pop ( 'callba... |
def csi ( self ) :
"""Gilbert ' s Score or Threat Score or Critical Success Index a / ( a + b + c )""" | return self . table [ 0 , 0 ] / ( self . table [ 0 , 0 ] + self . table [ 0 , 1 ] + self . table [ 1 , 0 ] ) |
def exitClient ( self ) :
"""Teardown button handler .""" | self . sendRtspRequest ( self . TEARDOWN )
# self . handler ( )
os . remove ( CACHE_FILE_NAME + str ( self . sessionId ) + CACHE_FILE_EXT )
# Delete the cache image from video
rate = float ( self . counter / self . frameNbr )
print ( '-' * 60 + "\nRTP Packet Loss Rate :" + str ( rate ) + "\n" + '-' * 60 )
sys . exit ( ... |
def query_file ( self , path , fetchall = False , ** params ) :
"""Like Connection . query , but takes a filename to load a query from .""" | # If path doesn ' t exists
if not os . path . exists ( path ) :
raise IOError ( "File '{}' not found!" . format ( path ) )
# If it ' s a directory
if os . path . isdir ( path ) :
raise IOError ( "'{}' is a directory!" . format ( path ) )
# Read the given . sql file into memory .
with open ( path ) as f :
qu... |
def connection_made ( self ) :
"""Connection to peer handler .
We send bgp open message to peer and initialize related attributes .""" | assert self . state == BGP_FSM_CONNECT
# We have a connection with peer we send open message .
open_msg = self . _peer . create_open_msg ( )
self . _holdtime = open_msg . hold_time
self . state = BGP_FSM_OPEN_SENT
if not self . is_reactive :
self . _peer . state . bgp_state = self . state
self . sent_open_msg = ope... |
def dlls_in_dir ( directory ) :
"""Returns * . dll , * . so , * . dylib in given directory .""" | files = [ ]
files . extend ( glob . glob ( os . path . join ( directory , '*.so' ) ) )
files . extend ( glob . glob ( os . path . join ( directory , '*.dll' ) ) )
files . extend ( glob . glob ( os . path . join ( directory , '*.dylib' ) ) )
return files |
def _ar_matrix ( self ) :
"""Creates Autoregressive matrix
Returns
X : np . ndarray
Autoregressive Matrix""" | Y = np . array ( self . data [ self . max_lag : self . data . shape [ 0 ] ] )
X = self . data [ ( self . max_lag - 1 ) : - 1 ]
if self . ar != 0 :
for i in range ( 1 , self . ar ) :
X = np . vstack ( ( X , self . data [ ( self . max_lag - i - 1 ) : - i - 1 ] ) )
return X |
def com_adobe_fonts_check_fsselection_matches_macstyle ( ttFont ) :
"""Check if OS / 2 fsSelection matches head macStyle bold and italic bits .""" | from fontbakery . constants import FsSelection , MacStyle
failed = False
head_bold = ( ttFont [ 'head' ] . macStyle & MacStyle . BOLD ) != 0
os2_bold = ( ttFont [ 'OS/2' ] . fsSelection & FsSelection . BOLD ) != 0
if head_bold != os2_bold :
failed = True
yield FAIL , "The OS/2.fsSelection and head.macStyle " "b... |
def _get_match ( self , prefix ) :
"""Return the key that maps to this prefix .""" | # ( hard coded ) If we match a CPR response , return Keys . CPRResponse .
# ( This one doesn ' t fit in the ANSI _ SEQUENCES , because it contains
# integer variables . )
if _cpr_response_re . match ( prefix ) :
return Keys . CPRResponse
elif _mouse_event_re . match ( prefix ) :
return Keys . Vt100MouseEvent
# ... |
def _load_api ( self ) :
"""Add the routes for the scheduler API .""" | self . _add_url_route ( 'get_scheduler_info' , '' , api . get_scheduler_info , 'GET' )
self . _add_url_route ( 'add_job' , '/jobs' , api . add_job , 'POST' )
self . _add_url_route ( 'get_job' , '/jobs/<job_id>' , api . get_job , 'GET' )
self . _add_url_route ( 'get_jobs' , '/jobs' , api . get_jobs , 'GET' )
self . _add... |
def list_files ( dir_pathname , recursive = True , topdown = True , followlinks = False ) :
"""Enlists all the files using their absolute paths within the specified
directory , optionally recursively .
: param dir _ pathname :
The directory to traverse .
: param recursive :
` ` True ` ` for walking recurs... | for root , dirnames , filenames in walk ( dir_pathname , recursive , topdown , followlinks ) :
for filename in filenames :
yield absolute_path ( os . path . join ( root , filename ) ) |
def get_rewritten_query ( self ) :
"""Returns rewritten query or None ( if any )""" | rewrittenQuery = self . _extract ( _PartitionedQueryExecutionInfo . RewrittenQueryPath )
if rewrittenQuery is not None : # Hardcode formattable filter to true for now
rewrittenQuery = rewrittenQuery . replace ( '{documentdb-formattableorderbyquery-filter}' , 'true' )
return rewrittenQuery |
def closed_issues ( issues , after ) :
"""Yields closed issues ( closed after a given datetime ) given a list of issues .""" | logging . info ( 'finding closed issues after {}...' . format ( after ) )
seen = set ( )
for issue in issues :
if closed_issue ( issue , after ) and issue [ 'title' ] not in seen :
seen . add ( issue [ 'title' ] )
yield issue |
def draw ( self , cov , num_reals = 1 , names = None ) :
"""draw random realizations from a multivariate
Gaussian distribution
Parameters
cov : pyemu . Cov
covariance structure to draw from
num _ reals : int
number of realizations to generate
names : list
list of columns names to draw for . If None ... | real_names = np . arange ( num_reals , dtype = np . int64 )
# make sure everything is cool WRT ordering
if names is not None :
vals = self . mean_values . loc [ names ]
cov = cov . get ( names )
elif self . names != cov . row_names :
names = get_common_elements ( self . names , cov . row_names )
vals = ... |
def run ( self ) :
"""Called by Sphinx .
: returns : ImgurEmbedNode and ImgurJavaScriptNode instances with config values passed as arguments .
: rtype : list""" | # Get Imgur ID .
imgur_id = self . arguments [ 0 ]
if not RE_IMGUR_ID . match ( imgur_id ) :
raise ImgurError ( 'Invalid Imgur ID specified. Must be 5-10 letters and numbers. Albums prefixed with "a/".' )
# Validate directive options .
if imgur_id . startswith ( 'a/' ) and self . options . get ( 'target_largest' , ... |
def server_from_config ( config = None , server_class = None , additional_kwargs = None ) :
"""Gets a configured L { coilmq . server . StompServer } from specified config .
If ` config ` is None , global L { coilmq . config . config } var will be used instead .
The ` server _ class ` and ` additional _ kwargs `... | global global_config
if not config :
config = global_config
queue_store_factory = resolve_name ( config . get ( 'coilmq' , 'qstore.factory' ) )
subscriber_scheduler_factory = resolve_name ( config . get ( 'coilmq' , 'scheduler.subscriber_priority_factory' ) )
queue_scheduler_factory = resolve_name ( config . get ( ... |
def save_sql_to_files ( overwrite = False ) :
"""Executes every . sql files in / data / scripts / using salic db vpn and
then saves pickle files into / data / raw /""" | ext_size = len ( SQL_EXTENSION )
path = DATA_PATH / 'scripts'
save_dir = DATA_PATH / "raw"
for file in os . listdir ( path ) :
if file . endswith ( SQL_EXTENSION ) :
file_path = os . path . join ( save_dir , file [ : - ext_size ] + '.' + FILE_EXTENSION )
if not os . path . isfile ( file_path ) or ov... |
def WriteEventMACBGroup ( self , event_macb_group ) :
"""Writes an event MACB group to the output .
Args :
event _ macb _ group ( list [ EventObject ] ) : event MACB group .""" | output_values = self . _GetOutputValues ( event_macb_group [ 0 ] )
timestamp_descriptions = [ event . timestamp_desc for event in event_macb_group ]
output_values [ 3 ] = ( self . _output_mediator . GetMACBRepresentationFromDescriptions ( timestamp_descriptions ) )
# TODO : fix timestamp description in source .
output_... |
def cpuinfo ( ) :
"""Get the cpu info""" | f = open ( "/proc/cpuinfo" )
hwinfo = { }
for line in f . readlines ( ) :
cpul = line . split ( ":" )
name = cpul [ 0 ] . strip ( )
if ( len ( cpul ) > 1 ) :
val = cpul [ 1 ] . strip ( )
if ( name == "model name" ) :
hwinfo [ "CPU" ] = val
elif ( name == "cpu MHz" ) :
hwinfo ... |
def patch ( * args , ** kwargs ) :
'''Add patches to plot . The color of the patches is indexed according to a specified color - index .
: example :
Plot a finite element mesh : the outline of the undeformed configuration , and the deformed
configuration for which the elements get a color e . g . based on str... | from matplotlib . collections import PatchCollection
from matplotlib . patches import Polygon
# check dependent options
if ( 'coor' not in kwargs or 'conn' not in kwargs ) :
raise IOError ( 'Specify both "coor" and "conn"' )
# extract local options
axis = kwargs . pop ( 'axis' , plt . gca ( ) )
cindex = kwargs . po... |
def make ( parser ) :
"""Ceph MON Daemon management""" | parser . formatter_class = ToggleRawTextHelpFormatter
mon_parser = parser . add_subparsers ( dest = 'subcommand' )
mon_parser . required = True
mon_add = mon_parser . add_parser ( 'add' , help = ( 'R|Add a monitor to an existing cluster:\n' '\tceph-deploy mon add node1\n' 'Or:\n' '\tceph-deploy mon add --address 192.16... |
def combine_kwargs ( ** kwargs ) :
"""Flatten a series of keyword arguments from complex combinations of
dictionaries and lists into a list of tuples representing
properly - formatted parameters to pass to the Requester object .
: param kwargs : A dictionary containing keyword arguments to be
flattened into... | combined_kwargs = [ ]
# Loop through all kwargs provided
for kw , arg in kwargs . items ( ) :
if isinstance ( arg , dict ) :
for k , v in arg . items ( ) :
for tup in flatten_kwarg ( k , v ) :
combined_kwargs . append ( ( '{}{}' . format ( kw , tup [ 0 ] ) , tup [ 1 ] ) )
eli... |
def dphi_fc ( fdata ) :
"""Apply phi derivative in the Fourier domain .""" | nrows = fdata . shape [ 0 ]
ncols = fdata . shape [ 1 ]
B = int ( ncols / 2 )
# As always , we assume nrows and ncols are even
a = list ( range ( 0 , int ( B ) ) )
ap = list ( range ( - int ( B ) , 0 ) )
a . extend ( ap )
dphi = np . zeros ( [ nrows , ncols ] , np . complex128 )
for k in xrange ( 0 , nrows ) :
dphi... |
def custom_observable_properties_prefix_strict ( instance ) :
"""Ensure observable object custom properties follow strict naming style
conventions .""" | for key , obj in instance [ 'objects' ] . items ( ) :
if 'type' not in obj :
continue
type_ = obj [ 'type' ]
for prop in obj : # Check objects ' properties
if ( type_ in enums . OBSERVABLE_PROPERTIES and prop not in enums . OBSERVABLE_PROPERTIES [ type_ ] and not CUSTOM_PROPERTY_PREFIX_RE . ... |
def _sign_string ( message , private_key_file = None , private_key_string = None ) :
"""Signs a string for use with Amazon CloudFront . Requires the M2Crypto
library be installed .""" | try :
from M2Crypto import EVP
except ImportError :
raise NotImplementedError ( "Boto depends on the python M2Crypto " "library to generate signed URLs for " "CloudFront" )
# Make sure only one of private _ key _ file and private _ key _ string is set
if private_key_file and private_key_string :
raise Value... |
def to_masked_array ( self , copy = True ) :
"""Convert this array into a numpy . ma . MaskedArray
Parameters
copy : bool
If True ( default ) make a copy of the array in the result . If False ,
a MaskedArray view of DataArray . values is returned .
Returns
result : MaskedArray
Masked where invalid val... | isnull = pd . isnull ( self . values )
return np . ma . MaskedArray ( data = self . values , mask = isnull , copy = copy ) |
def parseSearchTerm ( term ) :
"""Turn a string search query into a two - tuple of a search term and a
dictionary of search keywords .""" | terms = [ ]
keywords = { }
for word in term . split ( ) :
if word . count ( ':' ) == 1 :
k , v = word . split ( u':' )
if k and v :
keywords [ k ] = v
elif k or v :
terms . append ( k or v )
else :
terms . append ( word )
term = u' ' . join ( terms )
if ke... |
def shuffle ( seq , random = None ) :
r"""Return shuffled * copy * of ` seq ` .""" | if isinstance ( seq , list ) :
return ipshuffle ( seq [ : ] , random )
elif isString ( seq ) : # seq [ 0:0 ] = = " " or u " "
return seq [ 0 : 0 ] . join ( ipshuffle ( list ( seq ) ) , random )
else :
return type ( seq ) ( ipshuffle ( list ( seq ) , random ) ) |
def reset_stats_history ( self ) :
"""Reset the stats history ( dict of GlancesAttribute ) .""" | if self . history_enable ( ) :
reset_list = [ a [ 'name' ] for a in self . get_items_history_list ( ) ]
logger . debug ( "Reset history for plugin {} (items: {})" . format ( self . plugin_name , reset_list ) )
self . stats_history . reset ( ) |
def popitem ( self ) :
"""Remove and return an item .""" | key , value = super ( LFUCache , self ) . popitem ( )
return ( key , value [ 1 ] ) |
def render_python_template_to ( src , dest , subsd , only_update = False , prev_subsd = None , create_dest_dirs = True , logger = None ) :
"""Overload this function if you want to use a template engine such as
e . g . mako .""" | if only_update :
if subsd == prev_subsd :
if not missing_or_other_newer ( dest , src ) :
if logger :
msg = ( "Did not re-render {}. " "(destination newer + same dict)" )
logger . info ( msg . format ( src ) )
return
with open ( src , 'rt' ) as ifh :
... |
def clip ( layer_to_clip , mask_layer ) :
"""Clip a vector layer with another .
Issue https : / / github . com / inasafe / inasafe / issues / 3186
: param layer _ to _ clip : The vector layer to clip .
: type layer _ to _ clip : QgsVectorLayer
: param mask _ layer : The vector layer to use for clipping .
... | output_layer_name = clip_steps [ 'output_layer_name' ]
output_layer_name = output_layer_name % ( layer_to_clip . keywords [ 'layer_purpose' ] )
parameters = { 'INPUT' : layer_to_clip , 'OVERLAY' : mask_layer , 'OUTPUT' : 'memory:' }
# TODO implement callback through QgsProcessingFeedback object
initialize_processing ( ... |
def translate ( self , vector , inc_alt_states = True ) :
"""Translates every atom in the AMPAL object .
Parameters
vector : 3D Vector ( tuple , list , numpy . array )
Vector used for translation .
inc _ alt _ states : bool , optional
If true , will rotate atoms in all states i . e . includes
alternate ... | vector = numpy . array ( vector )
for atom in self . get_atoms ( inc_alt_states = inc_alt_states ) :
atom . _vector += vector
return |
def get_ordered_tokens_from_vocab ( vocab : Vocab ) -> List [ str ] :
"""Returns the list of tokens in a vocabulary , ordered by increasing vocabulary id .
: param vocab : Input vocabulary .
: return : List of tokens .""" | return [ token for token , token_id in sorted ( vocab . items ( ) , key = lambda i : i [ 1 ] ) ] |
def save_account ( message , collection = DATABASE . account ) :
"""save account
Arguments :
message { [ type ] } - - [ description ]
Keyword Arguments :
collection { [ type ] } - - [ description ] ( default : { DATABASE } )""" | try :
collection . create_index ( [ ( "account_cookie" , ASCENDING ) , ( "user_cookie" , ASCENDING ) , ( "portfolio_cookie" , ASCENDING ) ] , unique = True )
except :
pass
collection . update ( { 'account_cookie' : message [ 'account_cookie' ] , 'portfolio_cookie' : message [ 'portfolio_cookie' ] , 'user_cookie... |
def canonicalize ( parsed_op ) :
"""Get the " canonical form " of this operation , putting it into a form where it can be serialized
to form a consensus hash . This method is meant to preserve compatibility across blockstackd releases .
For NAME _ TRANSFER , this means :
* add ' keep _ data ' flag""" | assert 'op' in parsed_op
assert len ( parsed_op [ 'op' ] ) == 2
if parsed_op [ 'op' ] [ 1 ] == TRANSFER_KEEP_DATA :
parsed_op [ 'keep_data' ] = True
elif parsed_op [ 'op' ] [ 1 ] == TRANSFER_REMOVE_DATA :
parsed_op [ 'keep_data' ] = False
else :
raise ValueError ( "Invalid op '{}'" . format ( parsed_op [ 'o... |
def start ( st_reg_number ) :
"""Checks the number valiaty for the Sergipe state""" | divisor = 11
if len ( st_reg_number ) > 9 :
return False
if len ( st_reg_number ) < 9 :
return False
sum_total = 0
peso = 9
for i in range ( len ( st_reg_number ) - 1 ) :
sum_total = sum_total + int ( st_reg_number [ i ] ) * peso
peso = peso - 1
rest_division = sum_total % divisor
digit = divisor - rest... |
def replacing_symlink ( source , link_name ) :
"""Create symlink that overwrites any existing target .""" | with make_tmp_name ( link_name ) as tmp_link_name :
os . symlink ( source , tmp_link_name )
replace_file_or_dir ( link_name , tmp_link_name ) |
def useragent ( self , value ) :
"""gets / sets the user agent value""" | if value is None :
self . _useragent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"
elif self . _useragent != value :
self . _useragent = value |
def create_role ( self , role_name , role_type , host_id ) :
"""Create a role .
@ param role _ name : Role name
@ param role _ type : Role type
@ param host _ id : ID of the host to assign the role to
@ return : An ApiRole object""" | return roles . create_role ( self . _get_resource_root ( ) , self . name , role_type , role_name , host_id , self . _get_cluster_name ( ) ) |
def _xml_to_dict ( xml ) :
'''Helper function to covert xml into a data dictionary .
xml
The xml data to convert .''' | dicts = { }
for item in xml :
key = item . tag . lower ( )
idx = 1
while key in dicts :
key += six . text_type ( idx )
idx += 1
if item . text is None :
dicts [ key ] = _xml_to_dict ( item )
else :
dicts [ key ] = item . text
return dicts |
def rts_smooth ( kalman_filter , state_count = None ) :
"""Compute the Rauch - Tung - Striebel smoothed state estimates and estimate
covariances for a Kalman filter .
Args :
kalman _ filter ( KalmanFilter ) : Filter whose smoothed states should be
returned
state _ count ( int or None ) : Number of smoothe... | if state_count is None :
state_count = kalman_filter . state_count
state_count = int ( state_count )
if state_count < 0 or state_count > kalman_filter . state_count :
raise ValueError ( "Invalid state count: {}" . format ( state_count ) )
# No states to return ?
if state_count == 0 :
return [ ]
# Initialise... |
def _apply_hard_disk ( unit_number , key , operation , disk_label = None , size = None , unit = 'GB' , controller_key = None , thin_provision = None , eagerly_scrub = None , datastore = None , filename = None ) :
'''Returns a vim . vm . device . VirtualDeviceSpec object specifying to add / edit
a virtual disk dev... | log . trace ( 'Configuring hard disk %s size=%s, unit=%s, controller_key=%s, ' 'thin_provision=%s, eagerly_scrub=%s, datastore=%s, filename=%s' , disk_label , size , unit , controller_key , thin_provision , eagerly_scrub , datastore , filename )
disk_spec = vim . vm . device . VirtualDeviceSpec ( )
disk_spec . device =... |
def update_cors_configuration ( self , enable_cors = True , allow_credentials = True , origins = None , overwrite_origins = False ) :
"""Merges existing CORS configuration with updated values .
: param bool enable _ cors : Enables / disables CORS . Defaults to True .
: param bool allow _ credentials : Allows au... | if origins is None :
origins = [ ]
cors_config = { 'enable_cors' : enable_cors , 'allow_credentials' : allow_credentials , 'origins' : origins }
if overwrite_origins :
return self . _write_cors_configuration ( cors_config )
old_config = self . cors_configuration ( )
# update config values
updated_config = old_c... |
def list_filepaths ( self , wildcard = None ) :
"""Return the list of absolute filepaths in the directory .
Args :
wildcard : String of tokens separated by " | " . Each token represents a pattern .
If wildcard is not None , we return only those files that match the given shell pattern ( uses fnmatch ) .
Exa... | # Select the files in the directory .
fnames = [ f for f in os . listdir ( self . path ) ]
filepaths = filter ( os . path . isfile , [ os . path . join ( self . path , f ) for f in fnames ] )
# Filter using the shell patterns .
if wildcard is not None :
filepaths = WildCard ( wildcard ) . filter ( filepaths )
retur... |
def get_params_from_page ( path , file_name , method_count ) :
"""This function accesses the rendered content .
We must do this because how the params are not defined in the docs ,
but rather the rendered HTML""" | # open the rendered file .
file_name = file_name . replace ( ".rst" , "" )
file_path = "{0}/../_build/html/endpoints/{1}/index.html" . format ( path , file_name )
soup = bs4 . BeautifulSoup ( open ( file_path ) )
# Pull out the relevant section
section = soup . find_all ( 'div' , class_ = 'section' ) [ method_count ]
#... |
def delete_tags ( filesystemid , tags , keyid = None , key = None , profile = None , region = None , ** kwargs ) :
'''Deletes the specified tags from a file system .
filesystemid
( string ) - ID of the file system for whose tags will be removed .
tags
( list [ string ] ) - The tag keys to delete to the file... | client = _get_conn ( key = key , keyid = keyid , profile = profile , region = region )
client . delete_tags ( FileSystemId = filesystemid , Tags = tags ) |
def undo_sign_in ( entry , session = None ) :
"""Delete a signed in entry .
: param entry : ` models . Entry ` object . The entry to delete .
: param session : ( optional ) SQLAlchemy session through which to access the database .""" | # noqa
if session is None :
session = Session ( )
else :
session = session
entry_to_delete = ( session . query ( Entry ) . filter ( Entry . uuid == entry . uuid ) . one_or_none ( ) )
if entry_to_delete :
logger . info ( 'Undo sign in: {}' . format ( entry_to_delete . user_id ) )
logger . debug ( 'Undo s... |
def stratified_resample ( weights ) :
"""Performs the stratified resampling algorithm used by particle filters .
This algorithms aims to make selections relatively uniformly across the
particles . It divides the cumulative sum of the weights into N equal
divisions , and then selects one particle randomly from... | N = len ( weights )
# make N subdivisions , and chose a random position within each one
positions = ( random ( N ) + range ( N ) ) / N
indexes = np . zeros ( N , 'i' )
cumulative_sum = np . cumsum ( weights )
i , j = 0 , 0
while i < N :
if positions [ i ] < cumulative_sum [ j ] :
indexes [ i ] = j
i... |
def post ( self , ** kwargs ) :
"""Send a POST request to the currently loaded website ' s URL .
The browser will automatically fill out the form . If ` data ` dict has
been passed into ` ` kwargs ` ` , the contained input values will override
the automatically filled out values .
Returns :
` Response ` o... | if self . _url is None :
raise NoWebsiteLoadedError ( 'request submission requires a loaded website' )
data = kwargs . get ( 'data' , { } )
for i in self . soup ( 'form' ) . select ( 'input[name]' ) :
if i . get ( 'name' ) not in data :
data [ i . get ( 'name' ) ] = i . get ( 'value' , '' )
kwargs [ 'da... |
def execute_managed_notebook ( cls , nb_man , kernel_name , log_output = False , start_timeout = 60 , execution_timeout = None , ** kwargs ) :
"""Performs the actual execution of the parameterized notebook locally .
Args :
nb ( NotebookNode ) : Executable notebook object .
kernel _ name ( str ) : Name of kern... | preprocessor = PapermillExecutePreprocessor ( timeout = execution_timeout , startup_timeout = start_timeout , kernel_name = kernel_name , log = logger , )
preprocessor . log_output = log_output
preprocessor . preprocess ( nb_man , kwargs ) |
def _step ( self , actions ) :
"""Takes a step in all environments , shouldn ' t pre - process or record .
Subclasses should override this to do the actual step if something other
than the default implementation is desired .
Args :
actions : ( np . ndarray ) with first dimension equal to the batch size .
... | # Pre - conditions : common _ preconditions , see ` assert _ common _ preconditions ` .
# : len ( actions ) = = len ( self . _ envs )
self . assert_common_preconditions ( )
assert len ( actions ) == len ( self . _envs )
observations = [ ]
rewards = [ ]
dones = [ ]
infos = [ ]
# Take steps in all environments .
for env ... |
def module_entry ( yfile ) :
"""Add entry for one file containing YANG module text .
Args :
yfile ( file ) : File containing a YANG module or submodule .""" | ytxt = yfile . read ( )
mp = ModuleParser ( ytxt )
mst = mp . statement ( )
submod = mst . keyword == "submodule"
import_only = True
rev = ""
features = [ ]
includes = [ ]
rec = { }
for sst in mst . substatements :
if not rev and sst . keyword == "revision" :
rev = sst . argument
elif import_only and ss... |
def _createStructure ( self , linkResult , replaceParamFile ) :
"""Create GSSHAPY Structure Objects Method""" | # Constants
WEIRS = ( 'WEIR' , 'SAG_WEIR' )
CULVERTS = ( 'ROUND_CULVERT' , 'RECT_CULVERT' )
CURVES = ( 'RATING_CURVE' , 'SCHEDULED_RELEASE' , 'RULE_CURVE' )
header = linkResult [ 'header' ]
# Initialize GSSHAPY StreamLink object
link = StreamLink ( linkNumber = header [ 'link' ] , type = linkResult [ 'type' ] , numElem... |
def absolute_url ( relative_url ) :
"""Returns an absolute URL from a URL relative to the server root .
The base URL is taken from the Flask app config if present , otherwise it
falls back to ` ` http : / / inspirehep . net ` ` .""" | default_server = 'http://inspirehep.net'
server = current_app . config . get ( 'SERVER_NAME' , default_server )
if not re . match ( '^https?://' , server ) :
server = u'http://{}' . format ( server )
return urllib . parse . urljoin ( server , relative_url ) |
def create ( buildout_directory , buildout_extends ) :
"""Create buildout directory""" | # Resolve arguments
directory = get_buildout_directory ( buildout_directory )
extends = get_buildout_extends ( buildout_extends )
# Create buildout directory
local ( 'mkdir -p {0:s}' . format ( directory ) )
# Create buildout . cfg
filename = os . path . join ( directory , 'buildout.cfg' )
contents = """\
[buildout]
ex... |
def noise_op ( latents , hparams ) :
"""Adds isotropic gaussian - noise to each latent .
Args :
latents : 4 - D or 5 - D tensor , shape = ( NTHWC ) or ( NHWC ) .
hparams : HParams .
Returns :
latents : latents with isotropic gaussian noise appended .""" | if hparams . latent_noise == 0 or hparams . mode != tf . estimator . ModeKeys . TRAIN :
return latents
latent_shape = common_layers . shape_list ( latents )
return latents + tf . random_normal ( latent_shape , stddev = hparams . latent_noise ) |
def _handle_request ( self , request ) :
"""Finds the resource to which a request maps and then calls it .
Instantiates , fills and returns a : class : ` webob . Response ` object . If
no resource matches the request , a 404 status is set on the response
object .
: param request : Object representing the cu... | response = webob . Response ( request = request )
path = request . path_info
parsed = self . _urlmap ( path )
if parsed :
path_params , resource = parsed
else :
path_params , resource = { } , self . NOT_FOUND_RESOURCE
instance = resource ( request = request , response = response , path_params = path_params , ap... |
def _render_dataframe ( dataframe ) :
"""Helper to render a dataframe as an HTML table .""" | data = dataframe . to_dict ( orient = 'records' )
fields = dataframe . columns . tolist ( )
return IPython . core . display . HTML ( datalab . utils . commands . HtmlBuilder . render_table ( data , fields ) ) |
def get_facets ( self ) :
'''Returns a dictionary of facets : :
> > > res = solr . query ( ' SolrClient _ unittest ' , {
' q ' : ' product _ name : Lorem ' ,
' facet ' : True ,
' facet . field ' : ' facet _ test ' ,
> > > res . get _ results _ count ( )
> > > res . get _ facets ( )
{ ' facet _ test ' ... | if not hasattr ( self , 'facets' ) :
self . facets = { }
data = self . data
if 'facet_counts' in data . keys ( ) and type ( data [ 'facet_counts' ] ) == dict :
if 'facet_fields' in data [ 'facet_counts' ] . keys ( ) and type ( data [ 'facet_counts' ] [ 'facet_fields' ] ) == dict :
for fa... |
def ti ( self ) :
"""Include the Threat Intel Module .
. . Note : : Threat Intell methods can be accessed using ` ` tcex . ti . < method > ` ` .""" | if self . _ti is None :
from . tcex_ti import TcExTi
self . _ti = TcExTi ( self )
return self . _ti |
def stSpectralFlux ( X , X_prev ) :
"""Computes the spectral flux feature of the current frame
ARGUMENTS :
X : the abs ( fft ) of the current frame
X _ prev : the abs ( fft ) of the previous frame""" | # compute the spectral flux as the sum of square distances :
sumX = numpy . sum ( X + eps )
sumPrevX = numpy . sum ( X_prev + eps )
F = numpy . sum ( ( X / sumX - X_prev / sumPrevX ) ** 2 )
return F |
def go_to_background ( ) :
"""Daemonize the running process .""" | try :
if os . fork ( ) :
sys . exit ( )
except OSError as errmsg :
LOGGER . error ( 'Fork failed: {0}' . format ( errmsg ) )
sys . exit ( 'Fork failed' ) |
def read_data ( self , variable_instance ) :
"""read values from the device""" | if self . inst is None :
return
vp_func = variable_instance . variableproperty_set . filter ( name = ':FUNC' ) . first ( )
measure_function = ''
if vp_func :
if vp_func . value ( ) :
measure_function = ':FUNC "%s";' % vp_func . value ( )
trig_delay = 0.1
if variable_instance . visavariable . device_prop... |
def get_tree_collection_strings ( self , scale = 1 , guide_tree = None ) :
"""Function to get input strings for tree _ collection
tree _ collection needs distvar , genome _ map and labels -
these are returned in the order above""" | records = [ self . collection [ i ] for i in self . indices ]
return TreeCollectionTaskInterface ( ) . scrape_args ( records ) |
def organize_commands ( corrected_commands ) :
"""Yields sorted commands without duplicates .
: type corrected _ commands : Iterable [ thefuck . types . CorrectedCommand ]
: rtype : Iterable [ thefuck . types . CorrectedCommand ]""" | try :
first_command = next ( corrected_commands )
yield first_command
except StopIteration :
return
without_duplicates = { command for command in sorted ( corrected_commands , key = lambda command : command . priority ) if command != first_command }
sorted_commands = sorted ( without_duplicates , key = lamb... |
def named_config ( name : str , config_dict : typing . Mapping ) -> None :
"""Adds a named config to the config registry . The first argument
may either be a string or a collection of strings .
This function should be called in a . konchrc file .""" | names = ( name if isinstance ( name , Iterable ) and not isinstance ( name , ( str , bytes ) ) else [ name ] )
for each in names :
_config_registry [ each ] = Config ( ** config_dict ) |
def _next_cTn_id ( self ) :
"""Return the next available unique ID ( int ) for p : cTn element .""" | cTn_id_strs = self . xpath ( '/p:sld/p:timing//p:cTn/@id' )
ids = [ int ( id_str ) for id_str in cTn_id_strs ]
return max ( ids ) + 1 |
def get_dataset ( self ) : # type : ( ) - > hdx . data . dataset . Dataset
"""Return dataset containing this resource
Returns :
hdx . data . dataset . Dataset : Dataset containing this resource""" | package_id = self . data . get ( 'package_id' )
if package_id is None :
raise HDXError ( 'Resource has no package id!' )
return hdx . data . dataset . Dataset . read_from_hdx ( package_id ) |
def write_dividend_data ( self , dividends , stock_dividends = None ) :
"""Write both dividend payouts and the derived price adjustment ratios .""" | # First write the dividend payouts .
self . _write_dividends ( dividends )
self . _write_stock_dividends ( stock_dividends )
# Second from the dividend payouts , calculate ratios .
dividend_ratios = self . calc_dividend_ratios ( dividends )
self . write_frame ( 'dividends' , dividend_ratios ) |
def get_global_vars ( func ) :
"""Store any methods or variables bound from the function ' s closure
Args :
func ( function ) : function to inspect
Returns :
dict : mapping of variable names to globally bound VARIABLES""" | closure = getclosurevars ( func )
if closure [ 'nonlocal' ] :
raise TypeError ( "Can't launch a job with closure variables: %s" % closure [ 'nonlocals' ] . keys ( ) )
globalvars = dict ( modules = { } , functions = { } , vars = { } )
for name , value in closure [ 'global' ] . items ( ) :
if inspect . ismodule (... |
def get_msms_df ( model , pdb_id , outfile = None , outdir = None , outext = '_msms.df' , force_rerun = False ) :
"""Run MSMS ( using Biopython ) on a Biopython Structure Model .
Depths are in units Angstroms . 1A = 10 ^ - 10 m = 1nm . Returns a dictionary of : :
chain _ id : {
resnum1 _ id : ( res _ depth , ... | # XTODO : need to deal with temporary surface / vertex files in tmp directory when running on a large scale - -
# XTODO : will run into inode limits ! Also , some valuable information is in these MSMS output files that we should save .
# Create the output file name
outfile = ssbio . utils . outfile_maker ( inname = pdb... |
def constant_coefficients ( d , timelines , constant = True , independent = 0 ) :
"""Proportional hazards model .
d : the dimension of the dataset
timelines : the observational times
constant : True for constant coefficients
independent : the number of coffients to set to 0 ( covariate is ind of survival ) ... | return time_varying_coefficients ( d , timelines , constant , independent = independent , randgen = random . normal ) |
def index ( self , prefix ) :
"""Return the model index for a prefix .""" | # Any web domain will be handled by the standard URLField .
if self . is_external_url_prefix ( prefix ) :
prefix = 'http'
for i , urltype in enumerate ( self . _url_types ) :
if urltype . prefix == prefix :
return i
return None |
def get ( self , symbol ) :
"""Gets a Symbol based on name , which is expected to exist .
Parameters
symbol : str or Symbol
Returns
Symbol
Raises
Exception
If it does not exist . Use . try _ to _ get ( ) ,
if the symbol may or may not exist .""" | syms = self . try_to_get ( symbol )
if syms is None :
raise Exception ( "Symbol {} does not exist" . format ( symbol ) )
else :
return syms |
def increment ( self , key , cache = None , amount = 1 ) :
"""Query the server to increment the value of the key by the specified
amount . Negative amounts can be used to decrement .
Keyword arguments :
key - - the key the item is stored under . Required .
cache - - the cache the item belongs to . Defaults ... | if cache is None :
cache = self . name
if cache is None :
raise ValueError ( "Cache name must be set" )
cache = quote_plus ( cache )
key = quote_plus ( key )
body = json . dumps ( { "amount" : amount } )
result = self . client . post ( "caches/%s/items/%s/increment" % ( cache , key ) , body , { "Content-Type" :... |
def subprocess ( self ) :
"""Retrieve the subprocess in which this activity is defined .
If this is a task on top level , it raises NotFounderror .
: return : a subprocess : class : ` Activity `
: raises NotFoundError : when it is a task in the top level of a project
: raises APIError : when other error occ... | subprocess_id = self . _json_data . get ( 'container' )
if subprocess_id == self . _json_data . get ( 'root_container' ) :
raise NotFoundError ( "Cannot find subprocess for this task '{}', " "as this task exist on top level." . format ( self . name ) )
return self . _client . activity ( pk = subprocess_id , scope =... |
def set ( self , key , * args ) :
"""Hash the key and set it in the cache""" | return self . cache . set ( self . _hashed ( key ) , * args ) |
def connectivity_array ( self ) :
"""Provides connectivity array .
Returns :
connectivity : An array of shape [ atomi , atomj , imagej ] . atomi is
the index of the atom in the input structure . Since the second
atom can be outside of the unit cell , it must be described
by both an atom index and an image... | # shape = [ site , axis ]
cart_coords = np . array ( self . s . cart_coords )
# shape = [ site , image , axis ]
all_sites = cart_coords [ : , None , : ] + self . cart_offsets [ None , : , : ]
vt = Voronoi ( all_sites . reshape ( ( - 1 , 3 ) ) )
n_images = all_sites . shape [ 1 ]
cs = ( len ( self . s ) , len ( self . s... |
def benchmark_mitdb_record ( rec , detector , verbose ) :
"""Benchmark a single mitdb record""" | sig , fields = rdsamp ( rec , pb_dir = 'mitdb' , channels = [ 0 ] )
ann_ref = rdann ( rec , pb_dir = 'mitdb' , extension = 'atr' )
qrs_inds = detector ( sig = sig [ : , 0 ] , fs = fields [ 'fs' ] , verbose = verbose )
comparitor = compare_annotations ( ref_sample = ann_ref . sample [ 1 : ] , test_sample = qrs_inds , wi... |
def update ( self , password = values . unset ) :
"""Update the CredentialInstance
: param unicode password : The password will not be returned in the response
: returns : Updated CredentialInstance
: rtype : twilio . rest . api . v2010 . account . sip . credential _ list . credential . CredentialInstance""" | data = values . of ( { 'Password' : password , } )
payload = self . _version . update ( 'POST' , self . _uri , data = data , )
return CredentialInstance ( self . _version , payload , account_sid = self . _solution [ 'account_sid' ] , credential_list_sid = self . _solution [ 'credential_list_sid' ] , sid = self . _solut... |
def generate ( env ) :
"""Add Builders and construction variables for C compilers to an Environment .""" | static_obj , shared_obj = SCons . Tool . createObjBuilders ( env )
for suffix in CSuffixes :
static_obj . add_action ( suffix , SCons . Defaults . CAction )
shared_obj . add_action ( suffix , SCons . Defaults . ShCAction )
static_obj . add_emitter ( suffix , SCons . Defaults . StaticObjectEmitter )
shar... |
def attempt_social_login ( self , provider , id ) :
"""Attempt social login and return boolean result""" | if not provider or not id :
return False
params = dict ( )
params [ provider . lower ( ) + '_id' ] = id
user = self . first ( ** params )
if not user :
return False
self . force_login ( user )
return True |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.