idx
int64
0
252k
question
stringlengths
48
5.28k
target
stringlengths
5
1.23k
235,400
def validate_metadata ( self , metadata ) : response = self . requests_session . post ( f'{self.url}/validate' , data = json . dumps ( metadata ) , headers = self . _headers ) if response . content == b'true\n' : return True else : logger . info ( self . _parse_search_response ( response . content ) ) return False
Validate that the metadata of your ddo is valid .
235,401
def get_sla_template_path ( service_type = ServiceTypes . ASSET_ACCESS ) : if service_type == ServiceTypes . ASSET_ACCESS : name = 'access_sla_template.json' elif service_type == ServiceTypes . CLOUD_COMPUTE : name = 'compute_sla_template.json' elif service_type == ServiceTypes . FITCHAIN_COMPUTE : name = 'fitchain_sla...
Get the template for a ServiceType .
235,402
def balance ( self , account ) : return Balance ( self . _keeper . get_ether_balance ( account . address ) , self . _keeper . token . get_token_balance ( account . address ) )
Return the balance a tuple with the eth and ocn balance .
235,403
def process_agreement_events_consumer ( publisher_address , agreement_id , did , service_agreement , price , consumer_account , condition_ids , consume_callback ) : conditions_dict = service_agreement . condition_by_name events_manager = EventsManager . get_instance ( Keeper . get_instance ( ) ) events_manager . watch_...
Process the agreement events during the register of the service agreement for the consumer side .
235,404
def process_agreement_events_publisher ( publisher_account , agreement_id , did , service_agreement , price , consumer_address , condition_ids ) : conditions_dict = service_agreement . condition_by_name events_manager = EventsManager . get_instance ( Keeper . get_instance ( ) ) events_manager . watch_lock_reward_event ...
Process the agreement events during the register of the service agreement for the publisher side
235,405
def execute_pending_service_agreements ( storage_path , account , actor_type , did_resolver_fn ) : keeper = Keeper . get_instance ( ) for ( agreement_id , did , _ , price , files , start_time , _ ) in get_service_agreements ( storage_path ) : ddo = did_resolver_fn ( did ) for service in ddo . services : if service . ty...
Iterates over pending service agreements recorded in the local storage fetches their service definitions and subscribes to service agreement events .
235,406
def generate_multi_value_hash ( types , values ) : assert len ( types ) == len ( values ) return Web3Provider . get_web3 ( ) . soliditySha3 ( types , values )
Return the hash of the given list of values . This is equivalent to packing and hashing values in a solidity smart contract hence the use of soliditySha3 .
235,407
def process_tx_receipt ( tx_hash , event , event_name ) : web3 = Web3Provider . get_web3 ( ) try : web3 . eth . waitForTransactionReceipt ( tx_hash , timeout = 20 ) except Timeout : logger . info ( 'Waiting for transaction receipt timed out. Cannot verify receipt and event.' ) return receipt = web3 . eth . getTransacti...
Wait until the tx receipt is processed .
235,408
def get_condition ( self , condition_id ) : condition = self . contract_concise . getCondition ( condition_id ) if condition and len ( condition ) == 7 : return ConditionValues ( * condition ) return None
Retrieve the condition for a condition_id .
235,409
def fulfill ( self , agreement_id , message , account_address , signature , from_account ) : return self . _fulfill ( agreement_id , message , account_address , signature , transact = { 'from' : from_account . address , 'passphrase' : from_account . password } )
Fulfill the sign conditon .
235,410
def create ( self , did , service_definition_id , agreement_id , service_agreement_signature , consumer_address , account ) : assert consumer_address and Web3Provider . get_web3 ( ) . isChecksumAddress ( consumer_address ) , f'Invalid consumer address {consumer_address}' assert account . address in self . _keeper . acc...
Execute the service agreement on - chain using keeper s ServiceAgreement contract .
235,411
def is_access_granted ( self , agreement_id , did , consumer_address ) : agreement_consumer = self . _keeper . escrow_access_secretstore_template . get_agreement_consumer ( agreement_id ) if agreement_consumer != consumer_address : logger . warning ( f'Invalid consumer address {consumer_address} and/or ' f'service agre...
Check permission for the agreement .
235,412
def _verify_service_agreement_signature ( self , did , agreement_id , service_definition_id , consumer_address , signature , ddo = None ) : if not ddo : ddo = self . _asset_resolver . resolve ( did ) service_agreement = ServiceAgreement . from_ddo ( service_definition_id , ddo ) agreement_hash = service_agreement . get...
Verify service agreement signature .
235,413
def status ( self , agreement_id ) : condition_ids = self . _keeper . agreement_manager . get_agreement ( agreement_id ) . condition_ids result = { "agreementId" : agreement_id } conditions = dict ( ) for i in condition_ids : conditions [ self . _keeper . get_condition_name_by_address ( self . _keeper . condition_manag...
Get the status of a service agreement .
235,414
def create_agreement ( self , agreement_id , did , condition_ids , time_locks , time_outs , consumer_address , account ) : logger . info ( f'Creating agreement {agreement_id} with did={did}, consumer={consumer_address}.' ) tx_hash = self . send_transaction ( 'createAgreement' , ( agreement_id , did , condition_ids , ti...
Create the service agreement . Return true if it is created successfully .
235,415
def subscribe_agreement_created ( self , agreement_id , timeout , callback , args , wait = False ) : logger . info ( f'Subscribing {self.AGREEMENT_CREATED_EVENT} event with agreement id {agreement_id}.' ) return self . subscribe_to_event ( self . AGREEMENT_CREATED_EVENT , timeout , { '_agreementId' : Web3Provider . get...
Subscribe to an agreement created .
235,416
def generate_id ( self , agreement_id , types , values ) : values_hash = utils . generate_multi_value_hash ( types , values ) return utils . generate_multi_value_hash ( [ 'bytes32' , 'address' , 'bytes32' ] , [ agreement_id , self . address , values_hash ] )
Generate id for the condition .
235,417
def _fulfill ( self , * args , ** kwargs ) : tx_hash = self . send_transaction ( 'fulfill' , args , ** kwargs ) receipt = self . get_tx_receipt ( tx_hash ) return receipt . status == 1
Fulfill the condition .
235,418
def subscribe_condition_fulfilled ( self , agreement_id , timeout , callback , args , timeout_callback = None , wait = False ) : logger . info ( f'Subscribing {self.FULFILLED_EVENT} event with agreement id {agreement_id}.' ) return self . subscribe_to_event ( self . FULFILLED_EVENT , timeout , { '_agreementId' : Web3Pr...
Subscribe to the condition fullfilled event .
235,419
def transact_with_contract_function ( address , web3 , function_name = None , transaction = None , contract_abi = None , fn_abi = None , * args , ** kwargs ) : transact_transaction = prepare_transaction ( address , web3 , fn_identifier = function_name , contract_abi = contract_abi , transaction = transaction , fn_abi =...
Helper function for interacting with a contract function by sending a transaction . This is copied from web3 transact_with_contract_function so we can use personal_sendTransaction when possible .
235,420
def transact ( self , transaction = None ) : if transaction is None : transact_transaction = { } else : transact_transaction = dict ( ** transaction ) if 'data' in transact_transaction : raise ValueError ( "Cannot set data in transact transaction" ) cf = self . _contract_function if cf . address is not None : transact_...
Customize calling smart contract transaction functions to use personal_sendTransaction instead of eth_sendTransaction and to estimate gas limit . This function is largely copied from web3 ContractFunction with important addition .
235,421
def fulfill ( self , agreement_id , amount , receiver_address , sender_address , lock_condition_id , release_condition_id , account ) : return self . _fulfill ( agreement_id , amount , receiver_address , sender_address , lock_condition_id , release_condition_id , transact = { 'from' : account . address , 'passphrase' :...
Fulfill the escrow reward condition .
235,422
def hash_values ( self , amount , receiver_address , sender_address , lock_condition_id , release_condition_id ) : return self . _hash_values ( amount , receiver_address , sender_address , lock_condition_id , release_condition_id )
Hash the values of the escrow reward condition .
235,423
def as_dictionary ( self ) : return { "name" : self . name , "type" : self . type , "value" : remove_0x_prefix ( self . value ) if self . type == 'bytes32' else self . value }
Return the parameter as a dictionary .
235,424
def init_from_condition_json ( self , condition_json ) : self . name = condition_json [ 'name' ] self . timelock = condition_json [ 'timelock' ] self . timeout = condition_json [ 'timeout' ] self . contract_name = condition_json [ 'contractName' ] self . function_name = condition_json [ 'functionName' ] self . paramete...
Init the condition values from a condition json .
235,425
def as_dictionary ( self ) : condition_dict = { "name" : self . name , "timelock" : self . timelock , "timeout" : self . timeout , "contractName" : self . contract_name , "functionName" : self . function_name , "events" : [ e . as_dictionary ( ) for e in self . events ] , "parameters" : [ p . as_dictionary ( ) for p in...
Return the condition as a dictionary .
235,426
def update_value ( self , name , value ) : if name not in { 'id' , self . SERVICE_ENDPOINT , self . CONSUME_ENDPOINT , 'type' } : self . _values [ name ] = value
Update value in the array of values .
235,427
def as_text ( self , is_pretty = False ) : values = { 'type' : self . _type , self . SERVICE_ENDPOINT : self . _service_endpoint , } if self . _consume_endpoint is not None : values [ self . CONSUME_ENDPOINT ] = self . _consume_endpoint if self . _values : for name , value in self . _values . items ( ) : values [ name ...
Return the service as a JSON string .
235,428
def as_dictionary ( self ) : values = { 'type' : self . _type , self . SERVICE_ENDPOINT : self . _service_endpoint , } if self . _consume_endpoint is not None : values [ self . CONSUME_ENDPOINT ] = self . _consume_endpoint if self . _values : for name , value in self . _values . items ( ) : if isinstance ( value , obje...
Return the service as a python dictionary .
235,429
def from_json ( cls , service_dict ) : sd = service_dict . copy ( ) service_endpoint = sd . get ( cls . SERVICE_ENDPOINT ) if not service_endpoint : logger . error ( 'Service definition in DDO document is missing the "serviceEndpoint" key/value.' ) raise IndexError _type = sd . get ( 'type' ) if not _type : logger . er...
Create a service object from a JSON string .
235,430
def fulfill ( self , agreement_id , document_id , grantee_address , account ) : return self . _fulfill ( agreement_id , document_id , grantee_address , transact = { 'from' : account . address , 'passphrase' : account . password } )
Fulfill the access secret store condition .
235,431
def get_purchased_assets_by_address ( self , address , from_block = 0 , to_block = 'latest' ) : block_filter = EventFilter ( ConditionBase . FULFILLED_EVENT , getattr ( self . events , ConditionBase . FULFILLED_EVENT ) , from_block = from_block , to_block = to_block , argument_filters = { '_grantee' : address } ) log_i...
Get the list of the assets dids consumed for an address .
235,432
def get_web3 ( ) : if Web3Provider . _web3 is None : config = ConfigProvider . get_config ( ) provider = ( config . web3_provider if config . web3_provider else CustomHTTPProvider ( config . keeper_url ) ) Web3Provider . _web3 = Web3 ( provider ) Web3Provider . _web3 . eth = getattr ( Web3Provider . _web3 , 'eth' ) Web...
Return the web3 instance to interact with the ethereum client .
235,433
def _get_type ( points , soma_class ) : assert soma_class in ( SOMA_CONTOUR , SOMA_CYLINDER ) npoints = len ( points ) if soma_class == SOMA_CONTOUR : return { 0 : None , 1 : SomaSinglePoint , 2 : None } . get ( npoints , SomaSimpleContour ) if ( npoints == 3 and points [ 0 ] [ COLS . P ] == - 1 and points [ 1 ] [ COLS...
get the type of the soma
235,434
def make_soma ( points , soma_check = None , soma_class = SOMA_CONTOUR ) : if soma_check : soma_check ( points ) stype = _get_type ( points , soma_class ) if stype is None : raise SomaError ( 'Invalid soma points' ) return stype ( points )
Make a soma object from a set of points
235,435
def center ( self ) : points = np . array ( self . _points ) return np . mean ( points [ : , COLS . XYZ ] , axis = 0 )
Obtain the center from the average of all points
235,436
def section_tortuosity ( section ) : pts = section . points return 1 if len ( pts ) < 2 else mm . section_length ( pts ) / mm . point_dist ( pts [ - 1 ] , pts [ 0 ] )
Tortuosity of a section
235,437
def section_end_distance ( section ) : pts = section . points return 0 if len ( pts ) < 2 else mm . point_dist ( pts [ - 1 ] , pts [ 0 ] )
End to end distance of a section
235,438
def strahler_order ( section ) : if section . children : child_orders = [ strahler_order ( child ) for child in section . children ] max_so_children = max ( child_orders ) it = iter ( co == max_so_children for co in child_orders ) any ( it ) if any ( it ) : return max_so_children + 1 return max_so_children return 1
Branching order of a tree section
235,439
def figure_naming ( pretitle = '' , posttitle = '' , prefile = '' , postfile = '' ) : if pretitle : pretitle = "%s -- " % pretitle if posttitle : posttitle = " -- %s" % posttitle if prefile : prefile = "%s_" % prefile if postfile : postfile = "_%s" % postfile return pretitle , posttitle , prefile , postfile
Helper function to define the strings that handle pre - post conventions for viewing - plotting title and saving options .
235,440
def get_figure ( new_fig = True , subplot = '111' , params = None ) : _get_plt ( ) if new_fig : fig = plt . figure ( ) else : fig = plt . gcf ( ) params = dict_if_none ( params ) if isinstance ( subplot , ( tuple , list ) ) : ax = fig . add_subplot ( * subplot , ** params ) else : ax = fig . add_subplot ( subplot , ** ...
Function to be used for viewing - plotting to initialize the matplotlib figure - axes .
235,441
def save_plot ( fig , prefile = '' , postfile = '' , output_path = './' , output_name = 'Figure' , output_format = 'png' , dpi = 300 , transparent = False , ** _ ) : if not os . path . exists ( output_path ) : os . makedirs ( output_path ) output = os . path . join ( output_path , prefile + output_name + postfile + "."...
Generates a figure file in the selected directory .
235,442
def plot_style ( fig , ax , pretitle = '' , title = 'Figure' , posttitle = '' , title_fontsize = 14 , title_arg = None , label_fontsize = 14 , xlabel = None , xlabel_arg = None , ylabel = None , ylabel_arg = None , zlabel = None , zlabel_arg = None , tick_fontsize = 12 , xticks = None , xticks_args = None , yticks = No...
Set the basic options of a matplotlib figure to be used by viewing - plotting functions
235,443
def plot_title ( ax , pretitle = '' , title = 'Figure' , posttitle = '' , title_fontsize = 14 , title_arg = None ) : current_title = ax . get_title ( ) if not current_title : current_title = pretitle + title + posttitle title_arg = dict_if_none ( title_arg ) ax . set_title ( current_title , fontsize = title_fontsize , ...
Set title options of a matplotlib plot
235,444
def plot_labels ( ax , label_fontsize = 14 , xlabel = None , xlabel_arg = None , ylabel = None , ylabel_arg = None , zlabel = None , zlabel_arg = None ) : xlabel = xlabel if xlabel is not None else ax . get_xlabel ( ) or 'X' ylabel = ylabel if ylabel is not None else ax . get_ylabel ( ) or 'Y' xlabel_arg = dict_if_none...
Sets the labels options of a matplotlib plot
235,445
def plot_ticks ( ax , tick_fontsize = 12 , xticks = None , xticks_args = None , yticks = None , yticks_args = None , zticks = None , zticks_args = None ) : if xticks is not None : ax . set_xticks ( xticks ) xticks_args = dict_if_none ( xticks_args ) ax . xaxis . set_tick_params ( labelsize = tick_fontsize , ** xticks_a...
Function that defines the labels options of a matplotlib plot .
235,446
def update_plot_limits ( ax , white_space ) : if hasattr ( ax , 'zz_dataLim' ) : bounds = ax . xy_dataLim . bounds ax . set_xlim ( bounds [ 0 ] - white_space , bounds [ 0 ] + bounds [ 2 ] + white_space ) ax . set_ylim ( bounds [ 1 ] - white_space , bounds [ 1 ] + bounds [ 3 ] + white_space ) bounds = ax . zz_dataLim . ...
Sets the limit options of a matplotlib plot .
235,447
def plot_legend ( ax , no_legend = True , legend_arg = None ) : legend_arg = dict_if_none ( legend_arg ) if not no_legend : ax . legend ( ** legend_arg )
Function that defines the legend options of a matplotlib plot .
235,448
def generate_cylindrical_points ( start , end , start_radius , end_radius , linspace_count = _LINSPACE_COUNT ) : v = end - start length = norm ( v ) v = v / length n1 , n2 = _get_normals ( v ) l , theta = np . meshgrid ( np . linspace ( 0 , length , linspace_count ) , np . linspace ( 0 , 2 * np . pi , linspace_count ) ...
Generate a 3d mesh of a cylinder with start and end points and varying radius
235,449
def plot_cylinder ( ax , start , end , start_radius , end_radius , color = 'black' , alpha = 1. , linspace_count = _LINSPACE_COUNT ) : assert not np . all ( start == end ) , 'Cylinder must have length' x , y , z = generate_cylindrical_points ( start , end , start_radius , end_radius , linspace_count = linspace_count ) ...
plot a 3d cylinder
235,450
def plot_sphere ( ax , center , radius , color = 'black' , alpha = 1. , linspace_count = _LINSPACE_COUNT ) : u = np . linspace ( 0 , 2 * np . pi , linspace_count ) v = np . linspace ( 0 , np . pi , linspace_count ) sin_v = np . sin ( v ) x = center [ 0 ] + radius * np . outer ( np . cos ( u ) , sin_v ) y = center [ 1 ]...
Plots a 3d sphere given the center and the radius .
235,451
def has_sequential_ids ( data_wrapper ) : db = data_wrapper . data_block ids = db [ : , COLS . ID ] steps = ids [ np . where ( np . diff ( ids ) != 1 ) [ 0 ] + 1 ] . astype ( int ) return CheckResult ( len ( steps ) == 0 , steps )
Check that IDs are increasing and consecutive
235,452
def no_missing_parents ( data_wrapper ) : db = data_wrapper . data_block ids = np . setdiff1d ( db [ : , COLS . P ] , db [ : , COLS . ID ] ) [ 1 : ] return CheckResult ( len ( ids ) == 0 , ids . astype ( np . int ) + 1 )
Check that all points have existing parents Point s parent ID must exist and parent must be declared before child .
235,453
def is_single_tree ( data_wrapper ) : db = data_wrapper . data_block bad_ids = db [ db [ : , COLS . P ] == - 1 ] [ 1 : , COLS . ID ] return CheckResult ( len ( bad_ids ) == 0 , bad_ids . tolist ( ) )
Check that data forms a single tree
235,454
def has_soma_points ( data_wrapper ) : db = data_wrapper . data_block return CheckResult ( POINT_TYPE . SOMA in db [ : , COLS . TYPE ] , None )
Checks if the TYPE column of raw data block has an element of type soma
235,455
def has_all_finite_radius_neurites ( data_wrapper , threshold = 0.0 ) : db = data_wrapper . data_block neurite_ids = np . in1d ( db [ : , COLS . TYPE ] , POINT_TYPE . NEURITES ) zero_radius_ids = db [ : , COLS . R ] <= threshold bad_pts = np . array ( db [ neurite_ids & zero_radius_ids ] [ : , COLS . ID ] , dtype = int...
Check that all points with neurite type have a finite radius
235,456
def has_valid_soma ( data_wrapper ) : try : make_soma ( data_wrapper . soma_points ( ) ) return CheckResult ( True ) except SomaError : return CheckResult ( False )
Check if a data block has a valid soma
235,457
def _pelita_member_filter ( parent_name , item_names ) : filtered_names = [ ] if parent_name not in sys . modules : return item_names module = sys . modules [ parent_name ] for item_name in item_names : item = getattr ( module , item_name , None ) location = getattr ( item , '__module__' , None ) if location is None or...
Filter a list of autodoc items for which to generate documentation .
235,458
def has_axon ( neuron , treefun = _read_neurite_type ) : return CheckResult ( NeuriteType . axon in ( treefun ( n ) for n in neuron . neurites ) )
Check if a neuron has an axon
235,459
def has_apical_dendrite ( neuron , min_number = 1 , treefun = _read_neurite_type ) : types = [ treefun ( n ) for n in neuron . neurites ] return CheckResult ( types . count ( NeuriteType . apical_dendrite ) >= min_number )
Check if a neuron has apical dendrites
235,460
def has_basal_dendrite ( neuron , min_number = 1 , treefun = _read_neurite_type ) : types = [ treefun ( n ) for n in neuron . neurites ] return CheckResult ( types . count ( NeuriteType . basal_dendrite ) >= min_number )
Check if a neuron has basal dendrites
235,461
def has_no_flat_neurites ( neuron , tol = 0.1 , method = 'ratio' ) : return CheckResult ( len ( get_flat_neurites ( neuron , tol , method ) ) == 0 )
Check that a neuron has no flat neurites
235,462
def has_all_nonzero_segment_lengths ( neuron , threshold = 0.0 ) : bad_ids = [ ] for sec in _nf . iter_sections ( neuron ) : p = sec . points for i , s in enumerate ( zip ( p [ : - 1 ] , p [ 1 : ] ) ) : if segment_length ( s ) <= threshold : bad_ids . append ( ( sec . id , i ) ) return CheckResult ( len ( bad_ids ) == ...
Check presence of neuron segments with length not above threshold
235,463
def has_all_nonzero_section_lengths ( neuron , threshold = 0.0 ) : bad_ids = [ s . id for s in _nf . iter_sections ( neuron . neurites ) if section_length ( s . points ) <= threshold ] return CheckResult ( len ( bad_ids ) == 0 , bad_ids )
Check presence of neuron sections with length not above threshold
235,464
def has_all_nonzero_neurite_radii ( neuron , threshold = 0.0 ) : bad_ids = [ ] seen_ids = set ( ) for s in _nf . iter_sections ( neuron ) : for i , p in enumerate ( s . points ) : info = ( s . id , i ) if p [ COLS . R ] <= threshold and info not in seen_ids : seen_ids . add ( info ) bad_ids . append ( info ) return Che...
Check presence of neurite points with radius not above threshold
235,465
def has_no_fat_ends ( neuron , multiple_of_mean = 2.0 , final_point_count = 5 ) : bad_ids = [ ] for leaf in _nf . iter_sections ( neuron . neurites , iterator_type = Tree . ileaf ) : mean_radius = np . mean ( leaf . points [ 1 : ] [ - final_point_count : , COLS . R ] ) if mean_radius * multiple_of_mean <= leaf . points...
Check if leaf points are too large
235,466
def has_no_narrow_start ( neuron , frac = 0.9 ) : bad_ids = [ ( neurite . root_node . id , [ neurite . root_node . points [ 1 ] ] ) for neurite in neuron . neurites if neurite . root_node . points [ 1 ] [ COLS . R ] < frac * neurite . root_node . points [ 2 ] [ COLS . R ] ] return CheckResult ( len ( bad_ids ) == 0 , b...
Check if neurites have a narrow start
235,467
def has_no_dangling_branch ( neuron ) : soma_center = neuron . soma . points [ : , COLS . XYZ ] . mean ( axis = 0 ) recentered_soma = neuron . soma . points [ : , COLS . XYZ ] - soma_center radius = np . linalg . norm ( recentered_soma , axis = 1 ) soma_max_radius = radius . max ( ) def is_dangling ( neurite ) : starti...
Check if the neuron has dangling neurites
235,468
def has_no_narrow_neurite_section ( neuron , neurite_filter , radius_threshold = 0.05 , considered_section_min_length = 50 ) : considered_sections = ( sec for sec in iter_sections ( neuron , neurite_filter = neurite_filter ) if sec . length > considered_section_min_length ) def narrow_section ( section ) : return secti...
Check if the neuron has dendrites with narrow sections
235,469
def transform_header ( mtype_name ) : head_dict = OrderedDict ( ) head_dict [ "m-type" ] = mtype_name head_dict [ "components" ] = defaultdict ( OrderedDict ) return head_dict
Add header to json output to wrap around distribution data .
235,470
def draw ( obj , plane = '3d' , inline = False , ** kwargs ) : if plane . lower ( ) == '3d' : return _plot_neuron3d ( obj , inline , ** kwargs ) return _plot_neuron ( obj , plane , inline , ** kwargs )
Draw the morphology using in the given plane
235,471
def _make_trace ( neuron , plane ) : for neurite in iter_neurites ( neuron ) : segments = list ( iter_segments ( neurite ) ) segs = [ ( s [ 0 ] [ COLS . XYZ ] , s [ 1 ] [ COLS . XYZ ] ) for s in segments ] coords = dict ( x = list ( chain . from_iterable ( ( p1 [ 0 ] , p2 [ 0 ] , None ) for p1 , p2 in segs ) ) , y = li...
Create the trace to be plotted
235,472
def get_figure ( neuron , plane , title ) : data = list ( _make_trace ( neuron , plane ) ) axis = dict ( gridcolor = 'rgb(255, 255, 255)' , zerolinecolor = 'rgb(255, 255, 255)' , showbackground = True , backgroundcolor = 'rgb(230, 230,230)' ) if plane != '3d' : soma_2d = [ { 'type' : 'circle' , 'xref' : 'x' , 'yref' : ...
Returns the plotly figure containing the neuron
235,473
def rotate ( obj , axis , angle , origin = None ) : R = _rodrigues_to_dcm ( axis , angle ) try : return obj . transform ( PivotRotation ( R , origin ) ) except AttributeError : raise NotImplementedError
Rotation around unit vector following the right hand rule
235,474
def _sin ( x ) : return 0. if np . isclose ( np . mod ( x , np . pi ) , 0. ) else np . sin ( x )
sine with case for pi multiples
235,475
def _rodrigues_to_dcm ( axis , angle ) : ux , uy , uz = axis / np . linalg . norm ( axis ) uxx = ux * ux uyy = uy * uy uzz = uz * uz uxy = ux * uy uxz = ux * uz uyz = uy * uz sn = _sin ( angle ) cs = _sin ( np . pi / 2. - angle ) cs1 = 1. - cs R = np . zeros ( [ 3 , 3 ] ) R [ 0 , 0 ] = cs + uxx * cs1 R [ 0 , 1 ] = uxy ...
Generates transformation matrix from unit vector and rotation angle . The rotation is applied in the direction of the axis which is a unit vector following the right hand rule .
235,476
def total_length ( nrn_pop , neurite_type = NeuriteType . all ) : nrns = _neuronfunc . neuron_population ( nrn_pop ) return list ( sum ( section_lengths ( n , neurite_type = neurite_type ) ) for n in nrns )
Get the total length of all sections in the group of neurons or neurites
235,477
def n_segments ( neurites , neurite_type = NeuriteType . all ) : return sum ( len ( s . points ) - 1 for s in iter_sections ( neurites , neurite_filter = is_type ( neurite_type ) ) )
Number of segments in a collection of neurites
235,478
def n_neurites ( neurites , neurite_type = NeuriteType . all ) : return sum ( 1 for _ in iter_neurites ( neurites , filt = is_type ( neurite_type ) ) )
Number of neurites in a collection of neurites
235,479
def n_sections ( neurites , neurite_type = NeuriteType . all , iterator_type = Tree . ipreorder ) : return sum ( 1 for _ in iter_sections ( neurites , iterator_type = iterator_type , neurite_filter = is_type ( neurite_type ) ) )
Number of sections in a collection of neurites
235,480
def n_bifurcation_points ( neurites , neurite_type = NeuriteType . all ) : return n_sections ( neurites , neurite_type = neurite_type , iterator_type = Tree . ibifurcation_point )
number of bifurcation points in a collection of neurites
235,481
def n_forking_points ( neurites , neurite_type = NeuriteType . all ) : return n_sections ( neurites , neurite_type = neurite_type , iterator_type = Tree . iforking_point )
number of forking points in a collection of neurites
235,482
def n_leaves ( neurites , neurite_type = NeuriteType . all ) : return n_sections ( neurites , neurite_type = neurite_type , iterator_type = Tree . ileaf )
number of leaves points in a collection of neurites
235,483
def total_area_per_neurite ( neurites , neurite_type = NeuriteType . all ) : return [ neurite . area for neurite in iter_neurites ( neurites , filt = is_type ( neurite_type ) ) ]
Surface area in a collection of neurites .
235,484
def map_sections ( fun , neurites , neurite_type = NeuriteType . all , iterator_type = Tree . ipreorder ) : return map ( fun , iter_sections ( neurites , iterator_type = iterator_type , neurite_filter = is_type ( neurite_type ) ) )
Map fun to all the sections in a collection of neurites
235,485
def section_lengths ( neurites , neurite_type = NeuriteType . all ) : return map_sections ( _section_length , neurites , neurite_type = neurite_type )
section lengths in a collection of neurites
235,486
def section_term_lengths ( neurites , neurite_type = NeuriteType . all ) : return map_sections ( _section_length , neurites , neurite_type = neurite_type , iterator_type = Tree . ileaf )
Termination section lengths in a collection of neurites
235,487
def section_bif_lengths ( neurites , neurite_type = NeuriteType . all ) : return map_sections ( _section_length , neurites , neurite_type = neurite_type , iterator_type = Tree . ibifurcation_point )
Bifurcation section lengths in a collection of neurites
235,488
def section_branch_orders ( neurites , neurite_type = NeuriteType . all ) : return map_sections ( sectionfunc . branch_order , neurites , neurite_type = neurite_type )
section branch orders in a collection of neurites
235,489
def section_bif_branch_orders ( neurites , neurite_type = NeuriteType . all ) : return map_sections ( sectionfunc . branch_order , neurites , neurite_type = neurite_type , iterator_type = Tree . ibifurcation_point )
Bifurcation section branch orders in a collection of neurites
235,490
def section_term_branch_orders ( neurites , neurite_type = NeuriteType . all ) : return map_sections ( sectionfunc . branch_order , neurites , neurite_type = neurite_type , iterator_type = Tree . ileaf )
Termination section branch orders in a collection of neurites
235,491
def section_path_lengths ( neurites , neurite_type = NeuriteType . all ) : dist = { } neurite_filter = is_type ( neurite_type ) for s in iter_sections ( neurites , neurite_filter = neurite_filter ) : dist [ s ] = s . length def pl2 ( node ) : return sum ( dist [ n ] for n in node . iupstream ( ) ) return map_sections (...
Path lengths of a collection of neurites
235,492
def map_neurons ( fun , neurites , neurite_type ) : nrns = _neuronfunc . neuron_population ( neurites ) return [ fun ( n , neurite_type = neurite_type ) for n in nrns ]
Map fun to all the neurites in a single or collection of neurons
235,493
def map_segments ( func , neurites , neurite_type ) : neurite_filter = is_type ( neurite_type ) return [ s for ss in iter_sections ( neurites , neurite_filter = neurite_filter ) for s in func ( ss ) ]
Map func to all the segments in a collection of neurites
235,494
def segment_volumes ( neurites , neurite_type = NeuriteType . all ) : def _func ( sec ) : return [ morphmath . segment_volume ( seg ) for seg in zip ( sec . points [ : - 1 ] , sec . points [ 1 : ] ) ] return map_segments ( _func , neurites , neurite_type )
Volumes of the segments in a collection of neurites
235,495
def segment_radii ( neurites , neurite_type = NeuriteType . all ) : def _seg_radii ( sec ) : pts = sec . points [ : , COLS . R ] return np . divide ( np . add ( pts [ : - 1 ] , pts [ 1 : ] ) , 2.0 ) return map_segments ( _seg_radii , neurites , neurite_type )
arithmetic mean of the radii of the points in segments in a collection of neurites
235,496
def segment_taper_rates ( neurites , neurite_type = NeuriteType . all ) : def _seg_taper_rates ( sec ) : pts = sec . points [ : , COLS . XYZR ] diff = np . diff ( pts , axis = 0 ) distance = np . linalg . norm ( diff [ : , COLS . XYZ ] , axis = 1 ) return np . divide ( 2 * np . abs ( diff [ : , COLS . R ] ) , distance ...
taper rates of the segments in a collection of neurites
235,497
def segment_midpoints ( neurites , neurite_type = NeuriteType . all ) : def _seg_midpoint ( sec ) : pts = sec . points [ : , COLS . XYZ ] return np . divide ( np . add ( pts [ : - 1 ] , pts [ 1 : ] ) , 2.0 ) return map_segments ( _seg_midpoint , neurites , neurite_type )
Return a list of segment mid - points in a collection of neurites
235,498
def local_bifurcation_angles ( neurites , neurite_type = NeuriteType . all ) : return map_sections ( _bifurcationfunc . local_bifurcation_angle , neurites , neurite_type = neurite_type , iterator_type = Tree . ibifurcation_point )
Get a list of local bifurcation angles in a collection of neurites
235,499
def remote_bifurcation_angles ( neurites , neurite_type = NeuriteType . all ) : return map_sections ( _bifurcationfunc . remote_bifurcation_angle , neurites , neurite_type = neurite_type , iterator_type = Tree . ibifurcation_point )
Get a list of remote bifurcation angles in a collection of neurites