genet.utils.graph_operations
Filter(conditions=None, how=any, mixed_dtypes=True)
#
Helps filtering on specified attributes.
| PARAMETER | DESCRIPTION |
|---|---|
conditions
|
{'attribute_key': 'target_value'} or nested {'attribute_key': {'another_key': {'yet_another_key': 'target_value'}}}, where 'target_value' could be:
|
how
|
The level of rigour used to match conditions. Defaults to any. - all: means all conditions need to be met - any: means at least one condition needs to be met |
mixed_dtypes
|
If True, will consider the intersection of single values or lists of values in queried dictionary keys, e.g. as in simplified networks. Defaults to True.
TYPE:
|
Source code in src/genet/utils/graph_operations.py
conditions = conditions
instance-attribute
#
how = how
instance-attribute
#
mixed_dtypes = mixed_dtypes
instance-attribute
#
evaluate_condition(condition, data_dict)
#
Source code in src/genet/utils/graph_operations.py
satisfies_conditions(data_dict)
#
Source code in src/genet/utils/graph_operations.py
apply_function_to_attributes(iterator, function, location)
#
Source code in src/genet/utils/graph_operations.py
apply_mapping_to_attributes(iterator, mapping, location)
#
Source code in src/genet/utils/graph_operations.py
apply_to_attributes(iterator, to_apply, location)
#
build_attribute_dataframe(iterator, keys, index_name=None)
#
Builds a pandas.DataFrame from data in iterator.
| PARAMETER | DESCRIPTION |
|---|---|
iterator
|
iterator or list of tuples (id, dictionary data with keys of interest).
TYPE:
|
keys
|
keys to extract data from.
Can be a string, list or dictionary/list of dictionaries if accessing nested dictionaries, for example on using dictionaries see |
index_name
|
Name of returned dataframe index. Defaults to None. |
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
pd.DataFrame: Attribute dataframe. |
Source code in src/genet/utils/graph_operations.py
consolidate_link_indices(left, right)
#
Changes the link indexing in right to match left on modes stored on the links and resolves clashing link ids if they don't match.
This method assumes that the node ids of left vs right have already been consolidated (see consolidate_node_indices, which consolidates node ids).
| PARAMETER | DESCRIPTION |
|---|---|
left
|
GeNet network.
TYPE:
|
right
|
GeNet network that needs to be updated to match left network.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Network
|
Updated
TYPE:
|
Source code in src/genet/utils/graph_operations.py
411 412 413 414 415 416 417 418 419 420 421 422 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 | |
consolidate_node_indices(left, right)
#
Changes the node indexing in right to match left spatially and resolves clashing node ids if they don't match spatially.
The two networks need to be in matching coordinate systems.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
GeNet network.
TYPE:
|
right
|
GeNet network that needs to be updated to match left network.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
Nodes must be spatially unique. |
| RETURNS | DESCRIPTION |
|---|---|
Network
|
Updated
TYPE:
|
Source code in src/genet/utils/graph_operations.py
convert_list_of_link_ids_to_network_nodes(network, link_ids)
#
Extracts nodes corresponding to link ids in the order of given link_ids list.
Useful for extracting network routes.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
GeNet network.
TYPE:
|
link_ids
|
Link IDs whose nodes are to be extracted.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list
|
Node IDs.
TYPE:
|
Source code in src/genet/utils/graph_operations.py
extract_on_attributes(iterator, conditions, how=any, mixed_dtypes=True)
#
Extracts ids in iterator based on values of attributes attached to the items.
Fails silently, assumes not all items have those attributes. In the case were the attributes stored are a list or set, like in the case of a simplified network (there will be a mix of objects that are sets and not), an intersection of values satisfying condition(s) is considered in case of iterable value, if not empty, it is deemed successful by default. To disable this behaviour set mixed_dtypes to False.
| PARAMETER | DESCRIPTION |
|---|---|
iterator
|
list or set of two-tuples: (id of the item, attributes of the item) |
conditions
|
{'attribute_key': 'target_value'} or nested {'attribute_key': {'another_key': {'yet_another_key': 'target_value'}}}, where 'target_value' could be:
|
how
|
The level of rigour used to match conditions. Defaults to any. - all: means all conditions need to be met - any: means at least one condition needs to be met |
mixed_dtypes
|
If True, will consider the intersection of single values or lists of values in queried dictionary keys, e.g. as in simplified networks. Defaults to True.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list
|
list of ids in input iterator satisfying conditions
TYPE:
|
Source code in src/genet/utils/graph_operations.py
find_shortest_path_link(link_attribute_dictionary, modes=None)
#
Finds link that is deemed quickest if freespeed present.
Relies on (link) id being stored on edge data (default if using genet Network's add_link or add_edge methods or reading data using genet's Network methods.)
Throws a RuntimeError if a link id is not found.
| PARAMETER | DESCRIPTION |
|---|---|
link_attribute_dictionary
|
Link attribute dictionary, e.g.
TYPE:
|
modes
|
If passed and there is more than one possible edge that has the same length and speed, will also check if there is a link with modes that match exactly with |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
Link ID must exist. |
| RETURNS | DESCRIPTION |
|---|---|
str
|
Shortest path link ID
TYPE:
|
Source code in src/genet/utils/graph_operations.py
get_attribute_data_under_key(iterator, key)
#
Returns all data stored under key in attribute dictionaries for iterators yielding (index, attribute_dictionary).
Inherits index from the iterator.
| PARAMETER | DESCRIPTION |
|---|---|
iterator
|
list or iterator yielding (index, attribute_dictionary)
TYPE:
|
key
|
A string, e.g. 'modes'.
A dictionary, if accessing nested information, e.g. |
| RETURNS | DESCRIPTION |
|---|---|
dict
|
dictionary where keys are indices and values are data stored under the key
TYPE:
|
Source code in src/genet/utils/graph_operations.py
get_attribute_schema(iterator, data=False)
#
Source code in src/genet/utils/graph_operations.py
parse_leaf(leaf)
#
| PARAMETER | DESCRIPTION |
|---|---|
leaf
|
Leaf node.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Union[str, dict]
|
Union[str, dict]: str or dictionary with string key value pairs, for use as keys to extraction methods. |