utils
navis.utils.CMTKError
#
Raise on CMTK transform error.
Source code in navis/utils/exceptions.py
23 24 25 |
|
navis.utils.ConstructionError
#
Raised when class can't be constructed from input.
Source code in navis/utils/exceptions.py
15 16 17 |
|
navis.utils.VolumeError
#
Raise when volume is invalid (e.g. not watertight).
Source code in navis/utils/exceptions.py
19 20 21 |
|
navis.utils.check_vispy
#
Check that vispy works.
RETURNS | DESCRIPTION |
---|---|
vispy.Viewer | A viewer which can be closed after use. |
Examples:
>>> import navis
>>> viewer = navis.utils.check_vispy()
>>> # When the viewer and neurons show up...
>>> navis.close3d()
Source code in navis/utils/misc.py
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
|
navis.utils.eval_conditions
#
Split list of strings into positive (no "~") and negative ("~").
Examples:
>>> eval_conditions('~negative condition')
([], ['negative condition'])
>>> eval_conditions(['positive cond1', '~negative cond1', 'positive cond2'])
(['positive cond1', 'positive cond2'], ['negative cond1'])
Source code in navis/utils/eval.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
navis.utils.eval_id
#
Evaluate neuron ID(s).
PARAMETER | DESCRIPTION |
---|---|
x |
TYPE: |
warn_duplicates |
TYPE: |
RETURNS | DESCRIPTION |
---|---|
list | List containing IDs. |
Source code in navis/utils/eval.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
|
navis.utils.eval_neurons
#
Extract neurons.
PARAMETER | DESCRIPTION |
---|---|
x |
TYPE: |
warn_duplicates |
TYPE: |
raise_other |
TYPE: |
RETURNS | DESCRIPTION |
---|---|
list | List containing neurons. |
None | If no neurons found. |
Source code in navis/utils/eval.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
|
navis.utils.eval_node_ids
#
Extract node IDs from data.
PARAMETER | DESCRIPTION |
---|---|
x |
TYPE: |
RETURNS | DESCRIPTION |
---|---|
list | List containing node IDs (integer) |
Source code in navis/utils/eval.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
|
navis.utils.eval_param
#
Check if parameter has expected type and/or value.
PARAMETER | DESCRIPTION |
---|---|
value |
TYPE: |
name |
TYPE: |
allowed_values |
TYPE: |
allowed_types |
|
on_error |
TYPE: |
RETURNS | DESCRIPTION |
---|---|
None | |
Source code in navis/utils/eval.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
navis.utils.is_blender
#
Test if navis is run inside Blender.
Examples:
>>> from navis.utils import is_blender
>>> # If run outside Blender
>>> is_blender()
False
Source code in navis/utils/misc.py
141 142 143 144 145 146 147 148 149 150 151 152 |
|
navis.utils.is_iterable
#
Test if input is iterable (but not str).
Examples:
>>> from navis.utils import is_iterable
>>> is_iterable(['a'])
True
>>> is_iterable('a')
False
>>> is_iterable({'a': 1})
True
Source code in navis/utils/iterables.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
navis.utils.is_jupyter
#
Test if navis is run in a Jupyter notebook.
Also returns True if inside Google colaboratory!
Examples:
>>> from navis.utils import is_jupyter
>>> # If run outside a Jupyter environment
>>> is_jupyter()
False
Source code in navis/utils/misc.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
navis.utils.is_mesh
#
Check if object is mesh (i.e. contains vertices and faces).
Examples:
>>> import navis
>>> is_mesh(navis.example_neurons(1))
False
>>> is_mesh(navis.example_volume('LH'))
True
Source code in navis/utils/eval.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
navis.utils.is_numeric
#
Determine whether the argument has a numeric datatype.
Booleans, unsigned integers, signed integers, floats and complex numbers are the kinds of numeric datatype.
Arrays with "dtype=object" will return True if data can be cast to floats.
PARAMETER | DESCRIPTION |
---|---|
array |
TYPE: |
bool_numeric |
TYPE: |
try_convert |
TYPE: |
RETURNS | DESCRIPTION |
---|---|
is_numeric | True if the array has a numeric datatype, False if not. TYPE: |
Source code in navis/utils/eval.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
navis.utils.is_url
#
Return True if str is URL.
Examples:
>>> from navis.utils import is_url
>>> is_url('www.google.com')
False
>>> is_url('http://www.google.com')
True
>>> is_url("ftp://download.ft-server.org:8000")
True
Source code in navis/utils/misc.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
navis.utils.lock_neuron
#
Lock neuron while function is executed.
This makes sure that temporary attributes aren't re-calculated as changes are being made.
Source code in navis/utils/decorators.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 |
|
navis.utils.make_iterable
#
Force input into a numpy array.
For dicts, keys will be turned into array.
Examples:
>>> from navis.utils import make_iterable
>>> make_iterable(1)
array([1])
>>> make_iterable([1])
array([1])
>>> make_iterable({'a': 1})
array(['a'], dtype='<U1')
Source code in navis/utils/iterables.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
navis.utils.make_non_iterable
#
Turn input into non-iterable, if it isn't already.
Will raise error if len(x) > 1
.
Examples:
>>> from navis.utils import make_non_iterable
>>> make_non_iterable([1])
1
>>> make_non_iterable(1)
1
>>> make_non_iterable([1, 2])
Traceback (most recent call last):
ValueError: Iterable must not contain more than one entry.
Source code in navis/utils/iterables.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
navis.utils.make_url
#
Generate URL.
PARAMETER | DESCRIPTION |
---|---|
*args |
TYPE: |
**GET |
DEFAULT: |
RETURNS | DESCRIPTION |
---|---|
url | TYPE: |
Examples:
>>> from navis.utils import is_url, make_url
>>> url = make_url('http://www.google.com', 'test', query='test')
>>> url
'http://www.google.com/test?query=test'
>>> is_url(url)
True
Source code in navis/utils/misc.py
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
|
navis.utils.make_volume
#
Try making a navis.Volume from input object.
Source code in navis/utils/misc.py
75 76 77 78 79 80 81 82 83 84 85 86 |
|
navis.utils.map_neuronlist
#
Decorate function to run on all neurons in the NeuronList.
This also updates the docstring.
PARAMETER | DESCRIPTION |
---|---|
desc |
TYPE: |
can_zip | |
must_zip |
TYPE: |
allow_parallel |
TYPE: |
Source code in navis/utils/decorators.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
navis.utils.map_neuronlist_df
#
Decorate function to run on all neurons in the NeuronList.
This version of the decorator is meant for functions that return a DataFrame. This decorator will add a neuron
column with the respective neuron's ID and will then concatenate the dataframes.
PARAMETER | DESCRIPTION |
---|---|
desc |
TYPE: |
id_col |
TYPE: |
reset_index |
TYPE: |
allow_parallel |
TYPE: |
Source code in navis/utils/decorators.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
|
navis.utils.meshneuron_skeleton
#
Decorate function such that MeshNeurons are automatically skeletonized, the function is run on the skeleton and changes are propagated back to the meshe.
PARAMETER | DESCRIPTION |
---|---|
method |
TYPE: |
include_connectors |
TYPE: |
copy_properties |
TYPE: |
disallowed_kwargs |
TYPE: |
node_props |
TYPE: |
reroot_soma |
TYPE: |
heal |
TYPE: |
Source code in navis/utils/decorators.py
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 |
|
navis.utils.multi_split
#
Split string at any of the given separators.
RETURNS | DESCRIPTION |
---|---|
list | |
Examples:
>>> from navis.utils import multi_split
>>> s = '123;456,789:'
>>> multi_split(s, ';')
['123', '456,789']
>>> multi_split(s, [';', ','])
['123', '456', '789']
Source code in navis/utils/iterables.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
navis.utils.parse_objects
#
Categorize objects e.g. for plotting.
RETURNS | DESCRIPTION |
---|---|
Neurons | TYPE: |
Volume | TYPE: |
Points | TYPE: |
Visuals | TYPE: |
Examples:
This is mostly for doc tests:
>>> from navis.utils import parse_objects
>>> from navis.data import example_neurons, example_volume
>>> import numpy as np
>>> nl = example_neurons(3)
>>> v = example_volume('LH')
>>> p = nl[0].nodes[['x', 'y', 'z']].values
>>> n, vols, points, vis = parse_objects([nl, v, p])
>>> type(n), len(n)
(<class 'navis.core.neuronlist.NeuronList'>, 3)
>>> type(vols), len(vols)
(<class 'list'>, 1)
>>> type(vols[0])
<class 'navis.core.volumes.Volume'>
>>> type(points), len(points)
(<class 'list'>, 1)
>>> type(points[0])
<class 'numpy.ndarray'>
>>> type(vis), len(vis)
(<class 'list'>, 0)
Source code in navis/utils/misc.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
|
navis.utils.round_smart
#
Round number intelligently to produce Human-readable numbers.
This functions rounds to the Nth decimal, where N is precision
minus the number of digits before the decimal. The general idea is that the bigger the number, the less we care about decimals - and vice versa.
PARAMETER | DESCRIPTION |
---|---|
num |
TYPE: |
prec |
TYPE: |
Examples:
>>> import navis
>>> navis.utils.round_smart(0.00999)
0.00999
>>> navis.utils.round_smart(10000000.00999)
10000000.0
Source code in navis/utils/misc.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
navis.utils.sizeof_fmt
#
Bytes to Human readable.
Source code in navis/utils/misc.py
66 67 68 69 70 71 72 |
|
navis.utils.unpack_neurons
#
Unpack neurons and returns a list of individual neurons.
Examples:
This is mostly for doc tests:
>>> from navis.utils import unpack_neurons
>>> from navis.data import example_neurons
>>> nl = example_neurons(3)
>>> type(nl)
<class 'navis.core.neuronlist.NeuronList'>
>>> # Unpack list of neuronlists
>>> unpacked = unpack_neurons([nl, nl])
>>> type(unpacked)
<class 'list'>
>>> type(unpacked[0])
<class 'navis.core.skeleton.TreeNeuron'>
>>> len(unpacked)
6
Source code in navis/utils/misc.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
navis.utils.validate_options
#
Check if neuron contains all required data.
E.g. for plot3d(plot_connectors=True)
.
PARAMETER | DESCRIPTION |
---|---|
x |
TYPE: |
options |
TYPE: |
kwargs |
TYPE: |
raise_on_error |
TYPE: |
RETURNS | DESCRIPTION |
---|---|
None | |
Source code in navis/utils/validate.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
navis.utils.validate_table
#
Validate DataFrame.
PARAMETER | DESCRIPTION |
---|---|
x |
TYPE: |
required |
TYPE: |
rename |
TYPE: |
restrict |
TYPE: |
optional |
TYPE: |
RETURNS | DESCRIPTION |
---|---|
pandas.DataFrame | If |
Examples:
>>> from navis.utils import validate_table
>>> from navis.data import example_neurons
>>> n = example_neurons(1)
>>> tbl = validate_table(n.nodes, ['x', 'y', 'z', 'node_id'])
>>> tbl = validate_table(n.nodes, ['does_not_exist'])
ValueError: Table missing required column: "does_not_exist"
RAISES | DESCRIPTION |
---|---|
ValueError | If any of the required columns are not in the table. |
Source code in navis/utils/validate.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|