Datasets:
Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/cycler/__init__.py +573 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/cycler/__pycache__/__init__.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/cycler/py.typed +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/jinja2-3.1.6.dist-info/INSTALLER +1 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/jinja2-3.1.6.dist-info/METADATA +84 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/jinja2-3.1.6.dist-info/RECORD +33 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/jinja2-3.1.6.dist-info/REQUESTED +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/jinja2-3.1.6.dist-info/WHEEL +4 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/jinja2-3.1.6.dist-info/entry_points.txt +3 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/jinja2-3.1.6.dist-info/licenses/LICENSE.txt +28 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/mako-1.3.10.dist-info/INSTALLER +1 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/mako-1.3.10.dist-info/METADATA +88 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/mako-1.3.10.dist-info/RECORD +42 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/mako-1.3.10.dist-info/REQUESTED +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/mako-1.3.10.dist-info/WHEEL +5 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/mako-1.3.10.dist-info/entry_points.txt +18 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/mako-1.3.10.dist-info/licenses/LICENSE +19 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/mako-1.3.10.dist-info/top_level.txt +1 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/__init__.py +53 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/algorithms/walks.py +79 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/conftest.py +284 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/convert.py +502 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/convert_matrix.py +1317 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/exception.py +131 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__init__.py +34 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/__init__.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/atlas.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/classic.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/cographs.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/community.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/degree_seq.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/directed.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/duplication.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/ego.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/expanders.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/geometric.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/harary_graph.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/internet_as_graphs.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/intersection.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/interval_graph.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/joint_degree_seq.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/lattice.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/line.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/mycielski.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/nonisomorphic_trees.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/random_clustered.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/random_graphs.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/small.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/social.cpython-310.pyc +0 -0
- Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/spectral_graph_forge.cpython-310.pyc +0 -0
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/cycler/__init__.py
ADDED
|
@@ -0,0 +1,573 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Cycler
|
| 3 |
+
======
|
| 4 |
+
|
| 5 |
+
Cycling through combinations of values, producing dictionaries.
|
| 6 |
+
|
| 7 |
+
You can add cyclers::
|
| 8 |
+
|
| 9 |
+
from cycler import cycler
|
| 10 |
+
cc = (cycler(color=list('rgb')) +
|
| 11 |
+
cycler(linestyle=['-', '--', '-.']))
|
| 12 |
+
for d in cc:
|
| 13 |
+
print(d)
|
| 14 |
+
|
| 15 |
+
Results in::
|
| 16 |
+
|
| 17 |
+
{'color': 'r', 'linestyle': '-'}
|
| 18 |
+
{'color': 'g', 'linestyle': '--'}
|
| 19 |
+
{'color': 'b', 'linestyle': '-.'}
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
You can multiply cyclers::
|
| 23 |
+
|
| 24 |
+
from cycler import cycler
|
| 25 |
+
cc = (cycler(color=list('rgb')) *
|
| 26 |
+
cycler(linestyle=['-', '--', '-.']))
|
| 27 |
+
for d in cc:
|
| 28 |
+
print(d)
|
| 29 |
+
|
| 30 |
+
Results in::
|
| 31 |
+
|
| 32 |
+
{'color': 'r', 'linestyle': '-'}
|
| 33 |
+
{'color': 'r', 'linestyle': '--'}
|
| 34 |
+
{'color': 'r', 'linestyle': '-.'}
|
| 35 |
+
{'color': 'g', 'linestyle': '-'}
|
| 36 |
+
{'color': 'g', 'linestyle': '--'}
|
| 37 |
+
{'color': 'g', 'linestyle': '-.'}
|
| 38 |
+
{'color': 'b', 'linestyle': '-'}
|
| 39 |
+
{'color': 'b', 'linestyle': '--'}
|
| 40 |
+
{'color': 'b', 'linestyle': '-.'}
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
from __future__ import annotations
|
| 45 |
+
|
| 46 |
+
from collections.abc import Hashable, Iterable, Generator
|
| 47 |
+
import copy
|
| 48 |
+
from functools import reduce
|
| 49 |
+
from itertools import product, cycle
|
| 50 |
+
from operator import mul, add
|
| 51 |
+
# Dict, List, Union required for runtime cast calls
|
| 52 |
+
from typing import TypeVar, Generic, Callable, Union, Dict, List, Any, overload, cast
|
| 53 |
+
|
| 54 |
+
__version__ = "0.12.1"
|
| 55 |
+
|
| 56 |
+
K = TypeVar("K", bound=Hashable)
|
| 57 |
+
L = TypeVar("L", bound=Hashable)
|
| 58 |
+
V = TypeVar("V")
|
| 59 |
+
U = TypeVar("U")
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def _process_keys(
|
| 63 |
+
left: Cycler[K, V] | Iterable[dict[K, V]],
|
| 64 |
+
right: Cycler[K, V] | Iterable[dict[K, V]] | None,
|
| 65 |
+
) -> set[K]:
|
| 66 |
+
"""
|
| 67 |
+
Helper function to compose cycler keys.
|
| 68 |
+
|
| 69 |
+
Parameters
|
| 70 |
+
----------
|
| 71 |
+
left, right : iterable of dictionaries or None
|
| 72 |
+
The cyclers to be composed.
|
| 73 |
+
|
| 74 |
+
Returns
|
| 75 |
+
-------
|
| 76 |
+
keys : set
|
| 77 |
+
The keys in the composition of the two cyclers.
|
| 78 |
+
"""
|
| 79 |
+
l_peek: dict[K, V] = next(iter(left)) if left != [] else {}
|
| 80 |
+
r_peek: dict[K, V] = next(iter(right)) if right is not None else {}
|
| 81 |
+
l_key: set[K] = set(l_peek.keys())
|
| 82 |
+
r_key: set[K] = set(r_peek.keys())
|
| 83 |
+
if l_key & r_key:
|
| 84 |
+
raise ValueError("Can not compose overlapping cycles")
|
| 85 |
+
return l_key | r_key
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def concat(left: Cycler[K, V], right: Cycler[K, U]) -> Cycler[K, V | U]:
|
| 89 |
+
r"""
|
| 90 |
+
Concatenate `Cycler`\s, as if chained using `itertools.chain`.
|
| 91 |
+
|
| 92 |
+
The keys must match exactly.
|
| 93 |
+
|
| 94 |
+
Examples
|
| 95 |
+
--------
|
| 96 |
+
>>> num = cycler('a', range(3))
|
| 97 |
+
>>> let = cycler('a', 'abc')
|
| 98 |
+
>>> num.concat(let)
|
| 99 |
+
cycler('a', [0, 1, 2, 'a', 'b', 'c'])
|
| 100 |
+
|
| 101 |
+
Returns
|
| 102 |
+
-------
|
| 103 |
+
`Cycler`
|
| 104 |
+
The concatenated cycler.
|
| 105 |
+
"""
|
| 106 |
+
if left.keys != right.keys:
|
| 107 |
+
raise ValueError(
|
| 108 |
+
"Keys do not match:\n"
|
| 109 |
+
"\tIntersection: {both!r}\n"
|
| 110 |
+
"\tDisjoint: {just_one!r}".format(
|
| 111 |
+
both=left.keys & right.keys, just_one=left.keys ^ right.keys
|
| 112 |
+
)
|
| 113 |
+
)
|
| 114 |
+
_l = cast(Dict[K, List[Union[V, U]]], left.by_key())
|
| 115 |
+
_r = cast(Dict[K, List[Union[V, U]]], right.by_key())
|
| 116 |
+
return reduce(add, (_cycler(k, _l[k] + _r[k]) for k in left.keys))
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
class Cycler(Generic[K, V]):
|
| 120 |
+
"""
|
| 121 |
+
Composable cycles.
|
| 122 |
+
|
| 123 |
+
This class has compositions methods:
|
| 124 |
+
|
| 125 |
+
``+``
|
| 126 |
+
for 'inner' products (zip)
|
| 127 |
+
|
| 128 |
+
``+=``
|
| 129 |
+
in-place ``+``
|
| 130 |
+
|
| 131 |
+
``*``
|
| 132 |
+
for outer products (`itertools.product`) and integer multiplication
|
| 133 |
+
|
| 134 |
+
``*=``
|
| 135 |
+
in-place ``*``
|
| 136 |
+
|
| 137 |
+
and supports basic slicing via ``[]``.
|
| 138 |
+
|
| 139 |
+
Parameters
|
| 140 |
+
----------
|
| 141 |
+
left, right : Cycler or None
|
| 142 |
+
The 'left' and 'right' cyclers.
|
| 143 |
+
op : func or None
|
| 144 |
+
Function which composes the 'left' and 'right' cyclers.
|
| 145 |
+
"""
|
| 146 |
+
|
| 147 |
+
def __call__(self):
|
| 148 |
+
return cycle(self)
|
| 149 |
+
|
| 150 |
+
def __init__(
|
| 151 |
+
self,
|
| 152 |
+
left: Cycler[K, V] | Iterable[dict[K, V]] | None,
|
| 153 |
+
right: Cycler[K, V] | None = None,
|
| 154 |
+
op: Any = None,
|
| 155 |
+
):
|
| 156 |
+
"""
|
| 157 |
+
Semi-private init.
|
| 158 |
+
|
| 159 |
+
Do not use this directly, use `cycler` function instead.
|
| 160 |
+
"""
|
| 161 |
+
if isinstance(left, Cycler):
|
| 162 |
+
self._left: Cycler[K, V] | list[dict[K, V]] = Cycler(
|
| 163 |
+
left._left, left._right, left._op
|
| 164 |
+
)
|
| 165 |
+
elif left is not None:
|
| 166 |
+
# Need to copy the dictionary or else that will be a residual
|
| 167 |
+
# mutable that could lead to strange errors
|
| 168 |
+
self._left = [copy.copy(v) for v in left]
|
| 169 |
+
else:
|
| 170 |
+
self._left = []
|
| 171 |
+
|
| 172 |
+
if isinstance(right, Cycler):
|
| 173 |
+
self._right: Cycler[K, V] | None = Cycler(
|
| 174 |
+
right._left, right._right, right._op
|
| 175 |
+
)
|
| 176 |
+
else:
|
| 177 |
+
self._right = None
|
| 178 |
+
|
| 179 |
+
self._keys: set[K] = _process_keys(self._left, self._right)
|
| 180 |
+
self._op: Any = op
|
| 181 |
+
|
| 182 |
+
def __contains__(self, k):
|
| 183 |
+
return k in self._keys
|
| 184 |
+
|
| 185 |
+
@property
|
| 186 |
+
def keys(self) -> set[K]:
|
| 187 |
+
"""The keys this Cycler knows about."""
|
| 188 |
+
return set(self._keys)
|
| 189 |
+
|
| 190 |
+
def change_key(self, old: K, new: K) -> None:
|
| 191 |
+
"""
|
| 192 |
+
Change a key in this cycler to a new name.
|
| 193 |
+
Modification is performed in-place.
|
| 194 |
+
|
| 195 |
+
Does nothing if the old key is the same as the new key.
|
| 196 |
+
Raises a ValueError if the new key is already a key.
|
| 197 |
+
Raises a KeyError if the old key isn't a key.
|
| 198 |
+
"""
|
| 199 |
+
if old == new:
|
| 200 |
+
return
|
| 201 |
+
if new in self._keys:
|
| 202 |
+
raise ValueError(
|
| 203 |
+
f"Can't replace {old} with {new}, {new} is already a key"
|
| 204 |
+
)
|
| 205 |
+
if old not in self._keys:
|
| 206 |
+
raise KeyError(
|
| 207 |
+
f"Can't replace {old} with {new}, {old} is not a key"
|
| 208 |
+
)
|
| 209 |
+
|
| 210 |
+
self._keys.remove(old)
|
| 211 |
+
self._keys.add(new)
|
| 212 |
+
|
| 213 |
+
if self._right is not None and old in self._right.keys:
|
| 214 |
+
self._right.change_key(old, new)
|
| 215 |
+
|
| 216 |
+
# self._left should always be non-None
|
| 217 |
+
# if self._keys is non-empty.
|
| 218 |
+
elif isinstance(self._left, Cycler):
|
| 219 |
+
self._left.change_key(old, new)
|
| 220 |
+
else:
|
| 221 |
+
# It should be completely safe at this point to
|
| 222 |
+
# assume that the old key can be found in each
|
| 223 |
+
# iteration.
|
| 224 |
+
self._left = [{new: entry[old]} for entry in self._left]
|
| 225 |
+
|
| 226 |
+
@classmethod
|
| 227 |
+
def _from_iter(cls, label: K, itr: Iterable[V]) -> Cycler[K, V]:
|
| 228 |
+
"""
|
| 229 |
+
Class method to create 'base' Cycler objects
|
| 230 |
+
that do not have a 'right' or 'op' and for which
|
| 231 |
+
the 'left' object is not another Cycler.
|
| 232 |
+
|
| 233 |
+
Parameters
|
| 234 |
+
----------
|
| 235 |
+
label : hashable
|
| 236 |
+
The property key.
|
| 237 |
+
|
| 238 |
+
itr : iterable
|
| 239 |
+
Finite length iterable of the property values.
|
| 240 |
+
|
| 241 |
+
Returns
|
| 242 |
+
-------
|
| 243 |
+
`Cycler`
|
| 244 |
+
New 'base' cycler.
|
| 245 |
+
"""
|
| 246 |
+
ret: Cycler[K, V] = cls(None)
|
| 247 |
+
ret._left = list({label: v} for v in itr)
|
| 248 |
+
ret._keys = {label}
|
| 249 |
+
return ret
|
| 250 |
+
|
| 251 |
+
def __getitem__(self, key: slice) -> Cycler[K, V]:
|
| 252 |
+
# TODO : maybe add numpy style fancy slicing
|
| 253 |
+
if isinstance(key, slice):
|
| 254 |
+
trans = self.by_key()
|
| 255 |
+
return reduce(add, (_cycler(k, v[key]) for k, v in trans.items()))
|
| 256 |
+
else:
|
| 257 |
+
raise ValueError("Can only use slices with Cycler.__getitem__")
|
| 258 |
+
|
| 259 |
+
def __iter__(self) -> Generator[dict[K, V], None, None]:
|
| 260 |
+
if self._right is None:
|
| 261 |
+
for left in self._left:
|
| 262 |
+
yield dict(left)
|
| 263 |
+
else:
|
| 264 |
+
if self._op is None:
|
| 265 |
+
raise TypeError(
|
| 266 |
+
"Operation cannot be None when both left and right are defined"
|
| 267 |
+
)
|
| 268 |
+
for a, b in self._op(self._left, self._right):
|
| 269 |
+
out = {}
|
| 270 |
+
out.update(a)
|
| 271 |
+
out.update(b)
|
| 272 |
+
yield out
|
| 273 |
+
|
| 274 |
+
def __add__(self, other: Cycler[L, U]) -> Cycler[K | L, V | U]:
|
| 275 |
+
"""
|
| 276 |
+
Pair-wise combine two equal length cyclers (zip).
|
| 277 |
+
|
| 278 |
+
Parameters
|
| 279 |
+
----------
|
| 280 |
+
other : Cycler
|
| 281 |
+
"""
|
| 282 |
+
if len(self) != len(other):
|
| 283 |
+
raise ValueError(
|
| 284 |
+
f"Can only add equal length cycles, not {len(self)} and {len(other)}"
|
| 285 |
+
)
|
| 286 |
+
return Cycler(
|
| 287 |
+
cast(Cycler[Union[K, L], Union[V, U]], self),
|
| 288 |
+
cast(Cycler[Union[K, L], Union[V, U]], other),
|
| 289 |
+
zip
|
| 290 |
+
)
|
| 291 |
+
|
| 292 |
+
@overload
|
| 293 |
+
def __mul__(self, other: Cycler[L, U]) -> Cycler[K | L, V | U]:
|
| 294 |
+
...
|
| 295 |
+
|
| 296 |
+
@overload
|
| 297 |
+
def __mul__(self, other: int) -> Cycler[K, V]:
|
| 298 |
+
...
|
| 299 |
+
|
| 300 |
+
def __mul__(self, other):
|
| 301 |
+
"""
|
| 302 |
+
Outer product of two cyclers (`itertools.product`) or integer
|
| 303 |
+
multiplication.
|
| 304 |
+
|
| 305 |
+
Parameters
|
| 306 |
+
----------
|
| 307 |
+
other : Cycler or int
|
| 308 |
+
"""
|
| 309 |
+
if isinstance(other, Cycler):
|
| 310 |
+
return Cycler(
|
| 311 |
+
cast(Cycler[Union[K, L], Union[V, U]], self),
|
| 312 |
+
cast(Cycler[Union[K, L], Union[V, U]], other),
|
| 313 |
+
product
|
| 314 |
+
)
|
| 315 |
+
elif isinstance(other, int):
|
| 316 |
+
trans = self.by_key()
|
| 317 |
+
return reduce(
|
| 318 |
+
add, (_cycler(k, v * other) for k, v in trans.items())
|
| 319 |
+
)
|
| 320 |
+
else:
|
| 321 |
+
return NotImplemented
|
| 322 |
+
|
| 323 |
+
@overload
|
| 324 |
+
def __rmul__(self, other: Cycler[L, U]) -> Cycler[K | L, V | U]:
|
| 325 |
+
...
|
| 326 |
+
|
| 327 |
+
@overload
|
| 328 |
+
def __rmul__(self, other: int) -> Cycler[K, V]:
|
| 329 |
+
...
|
| 330 |
+
|
| 331 |
+
def __rmul__(self, other):
|
| 332 |
+
return self * other
|
| 333 |
+
|
| 334 |
+
def __len__(self) -> int:
|
| 335 |
+
op_dict: dict[Callable, Callable[[int, int], int]] = {zip: min, product: mul}
|
| 336 |
+
if self._right is None:
|
| 337 |
+
return len(self._left)
|
| 338 |
+
l_len = len(self._left)
|
| 339 |
+
r_len = len(self._right)
|
| 340 |
+
return op_dict[self._op](l_len, r_len)
|
| 341 |
+
|
| 342 |
+
# iadd and imul do not exapand the the type as the returns must be consistent with
|
| 343 |
+
# self, thus they flag as inconsistent with add/mul
|
| 344 |
+
def __iadd__(self, other: Cycler[K, V]) -> Cycler[K, V]: # type: ignore[misc]
|
| 345 |
+
"""
|
| 346 |
+
In-place pair-wise combine two equal length cyclers (zip).
|
| 347 |
+
|
| 348 |
+
Parameters
|
| 349 |
+
----------
|
| 350 |
+
other : Cycler
|
| 351 |
+
"""
|
| 352 |
+
if not isinstance(other, Cycler):
|
| 353 |
+
raise TypeError("Cannot += with a non-Cycler object")
|
| 354 |
+
# True shallow copy of self is fine since this is in-place
|
| 355 |
+
old_self = copy.copy(self)
|
| 356 |
+
self._keys = _process_keys(old_self, other)
|
| 357 |
+
self._left = old_self
|
| 358 |
+
self._op = zip
|
| 359 |
+
self._right = Cycler(other._left, other._right, other._op)
|
| 360 |
+
return self
|
| 361 |
+
|
| 362 |
+
def __imul__(self, other: Cycler[K, V] | int) -> Cycler[K, V]: # type: ignore[misc]
|
| 363 |
+
"""
|
| 364 |
+
In-place outer product of two cyclers (`itertools.product`).
|
| 365 |
+
|
| 366 |
+
Parameters
|
| 367 |
+
----------
|
| 368 |
+
other : Cycler
|
| 369 |
+
"""
|
| 370 |
+
if not isinstance(other, Cycler):
|
| 371 |
+
raise TypeError("Cannot *= with a non-Cycler object")
|
| 372 |
+
# True shallow copy of self is fine since this is in-place
|
| 373 |
+
old_self = copy.copy(self)
|
| 374 |
+
self._keys = _process_keys(old_self, other)
|
| 375 |
+
self._left = old_self
|
| 376 |
+
self._op = product
|
| 377 |
+
self._right = Cycler(other._left, other._right, other._op)
|
| 378 |
+
return self
|
| 379 |
+
|
| 380 |
+
def __eq__(self, other: object) -> bool:
|
| 381 |
+
if not isinstance(other, Cycler):
|
| 382 |
+
return False
|
| 383 |
+
if len(self) != len(other):
|
| 384 |
+
return False
|
| 385 |
+
if self.keys ^ other.keys:
|
| 386 |
+
return False
|
| 387 |
+
return all(a == b for a, b in zip(self, other))
|
| 388 |
+
|
| 389 |
+
__hash__ = None # type: ignore
|
| 390 |
+
|
| 391 |
+
def __repr__(self) -> str:
|
| 392 |
+
op_map = {zip: "+", product: "*"}
|
| 393 |
+
if self._right is None:
|
| 394 |
+
lab = self.keys.pop()
|
| 395 |
+
itr = list(v[lab] for v in self)
|
| 396 |
+
return f"cycler({lab!r}, {itr!r})"
|
| 397 |
+
else:
|
| 398 |
+
op = op_map.get(self._op, "?")
|
| 399 |
+
msg = "({left!r} {op} {right!r})"
|
| 400 |
+
return msg.format(left=self._left, op=op, right=self._right)
|
| 401 |
+
|
| 402 |
+
def _repr_html_(self) -> str:
|
| 403 |
+
# an table showing the value of each key through a full cycle
|
| 404 |
+
output = "<table>"
|
| 405 |
+
sorted_keys = sorted(self.keys, key=repr)
|
| 406 |
+
for key in sorted_keys:
|
| 407 |
+
output += f"<th>{key!r}</th>"
|
| 408 |
+
for d in iter(self):
|
| 409 |
+
output += "<tr>"
|
| 410 |
+
for k in sorted_keys:
|
| 411 |
+
output += f"<td>{d[k]!r}</td>"
|
| 412 |
+
output += "</tr>"
|
| 413 |
+
output += "</table>"
|
| 414 |
+
return output
|
| 415 |
+
|
| 416 |
+
def by_key(self) -> dict[K, list[V]]:
|
| 417 |
+
"""
|
| 418 |
+
Values by key.
|
| 419 |
+
|
| 420 |
+
This returns the transposed values of the cycler. Iterating
|
| 421 |
+
over a `Cycler` yields dicts with a single value for each key,
|
| 422 |
+
this method returns a `dict` of `list` which are the values
|
| 423 |
+
for the given key.
|
| 424 |
+
|
| 425 |
+
The returned value can be used to create an equivalent `Cycler`
|
| 426 |
+
using only `+`.
|
| 427 |
+
|
| 428 |
+
Returns
|
| 429 |
+
-------
|
| 430 |
+
transpose : dict
|
| 431 |
+
dict of lists of the values for each key.
|
| 432 |
+
"""
|
| 433 |
+
|
| 434 |
+
# TODO : sort out if this is a bottle neck, if there is a better way
|
| 435 |
+
# and if we care.
|
| 436 |
+
|
| 437 |
+
keys = self.keys
|
| 438 |
+
out: dict[K, list[V]] = {k: list() for k in keys}
|
| 439 |
+
|
| 440 |
+
for d in self:
|
| 441 |
+
for k in keys:
|
| 442 |
+
out[k].append(d[k])
|
| 443 |
+
return out
|
| 444 |
+
|
| 445 |
+
# for back compatibility
|
| 446 |
+
_transpose = by_key
|
| 447 |
+
|
| 448 |
+
def simplify(self) -> Cycler[K, V]:
|
| 449 |
+
"""
|
| 450 |
+
Simplify the cycler into a sum (but no products) of cyclers.
|
| 451 |
+
|
| 452 |
+
Returns
|
| 453 |
+
-------
|
| 454 |
+
simple : Cycler
|
| 455 |
+
"""
|
| 456 |
+
# TODO: sort out if it is worth the effort to make sure this is
|
| 457 |
+
# balanced. Currently it is is
|
| 458 |
+
# (((a + b) + c) + d) vs
|
| 459 |
+
# ((a + b) + (c + d))
|
| 460 |
+
# I would believe that there is some performance implications
|
| 461 |
+
trans = self.by_key()
|
| 462 |
+
return reduce(add, (_cycler(k, v) for k, v in trans.items()))
|
| 463 |
+
|
| 464 |
+
concat = concat
|
| 465 |
+
|
| 466 |
+
|
| 467 |
+
@overload
|
| 468 |
+
def cycler(arg: Cycler[K, V]) -> Cycler[K, V]:
|
| 469 |
+
...
|
| 470 |
+
|
| 471 |
+
|
| 472 |
+
@overload
|
| 473 |
+
def cycler(**kwargs: Iterable[V]) -> Cycler[str, V]:
|
| 474 |
+
...
|
| 475 |
+
|
| 476 |
+
|
| 477 |
+
@overload
|
| 478 |
+
def cycler(label: K, itr: Iterable[V]) -> Cycler[K, V]:
|
| 479 |
+
...
|
| 480 |
+
|
| 481 |
+
|
| 482 |
+
def cycler(*args, **kwargs):
|
| 483 |
+
"""
|
| 484 |
+
Create a new `Cycler` object from a single positional argument,
|
| 485 |
+
a pair of positional arguments, or the combination of keyword arguments.
|
| 486 |
+
|
| 487 |
+
cycler(arg)
|
| 488 |
+
cycler(label1=itr1[, label2=iter2[, ...]])
|
| 489 |
+
cycler(label, itr)
|
| 490 |
+
|
| 491 |
+
Form 1 simply copies a given `Cycler` object.
|
| 492 |
+
|
| 493 |
+
Form 2 composes a `Cycler` as an inner product of the
|
| 494 |
+
pairs of keyword arguments. In other words, all of the
|
| 495 |
+
iterables are cycled simultaneously, as if through zip().
|
| 496 |
+
|
| 497 |
+
Form 3 creates a `Cycler` from a label and an iterable.
|
| 498 |
+
This is useful for when the label cannot be a keyword argument
|
| 499 |
+
(e.g., an integer or a name that has a space in it).
|
| 500 |
+
|
| 501 |
+
Parameters
|
| 502 |
+
----------
|
| 503 |
+
arg : Cycler
|
| 504 |
+
Copy constructor for Cycler (does a shallow copy of iterables).
|
| 505 |
+
label : name
|
| 506 |
+
The property key. In the 2-arg form of the function,
|
| 507 |
+
the label can be any hashable object. In the keyword argument
|
| 508 |
+
form of the function, it must be a valid python identifier.
|
| 509 |
+
itr : iterable
|
| 510 |
+
Finite length iterable of the property values.
|
| 511 |
+
Can be a single-property `Cycler` that would
|
| 512 |
+
be like a key change, but as a shallow copy.
|
| 513 |
+
|
| 514 |
+
Returns
|
| 515 |
+
-------
|
| 516 |
+
cycler : Cycler
|
| 517 |
+
New `Cycler` for the given property
|
| 518 |
+
|
| 519 |
+
"""
|
| 520 |
+
if args and kwargs:
|
| 521 |
+
raise TypeError(
|
| 522 |
+
"cycler() can only accept positional OR keyword arguments -- not both."
|
| 523 |
+
)
|
| 524 |
+
|
| 525 |
+
if len(args) == 1:
|
| 526 |
+
if not isinstance(args[0], Cycler):
|
| 527 |
+
raise TypeError(
|
| 528 |
+
"If only one positional argument given, it must "
|
| 529 |
+
"be a Cycler instance."
|
| 530 |
+
)
|
| 531 |
+
return Cycler(args[0])
|
| 532 |
+
elif len(args) == 2:
|
| 533 |
+
return _cycler(*args)
|
| 534 |
+
elif len(args) > 2:
|
| 535 |
+
raise TypeError(
|
| 536 |
+
"Only a single Cycler can be accepted as the lone "
|
| 537 |
+
"positional argument. Use keyword arguments instead."
|
| 538 |
+
)
|
| 539 |
+
|
| 540 |
+
if kwargs:
|
| 541 |
+
return reduce(add, (_cycler(k, v) for k, v in kwargs.items()))
|
| 542 |
+
|
| 543 |
+
raise TypeError("Must have at least a positional OR keyword arguments")
|
| 544 |
+
|
| 545 |
+
|
| 546 |
+
def _cycler(label: K, itr: Iterable[V]) -> Cycler[K, V]:
|
| 547 |
+
"""
|
| 548 |
+
Create a new `Cycler` object from a property name and iterable of values.
|
| 549 |
+
|
| 550 |
+
Parameters
|
| 551 |
+
----------
|
| 552 |
+
label : hashable
|
| 553 |
+
The property key.
|
| 554 |
+
itr : iterable
|
| 555 |
+
Finite length iterable of the property values.
|
| 556 |
+
|
| 557 |
+
Returns
|
| 558 |
+
-------
|
| 559 |
+
cycler : Cycler
|
| 560 |
+
New `Cycler` for the given property
|
| 561 |
+
"""
|
| 562 |
+
if isinstance(itr, Cycler):
|
| 563 |
+
keys = itr.keys
|
| 564 |
+
if len(keys) != 1:
|
| 565 |
+
msg = "Can not create Cycler from a multi-property Cycler"
|
| 566 |
+
raise ValueError(msg)
|
| 567 |
+
|
| 568 |
+
lab = keys.pop()
|
| 569 |
+
# Doesn't need to be a new list because
|
| 570 |
+
# _from_iter() will be creating that new list anyway.
|
| 571 |
+
itr = (v[lab] for v in itr)
|
| 572 |
+
|
| 573 |
+
return Cycler._from_iter(label, itr)
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/cycler/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (16.6 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/cycler/py.typed
ADDED
|
File without changes
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/jinja2-3.1.6.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
uv
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/jinja2-3.1.6.dist-info/METADATA
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: Jinja2
|
| 3 |
+
Version: 3.1.6
|
| 4 |
+
Summary: A very fast and expressive template engine.
|
| 5 |
+
Maintainer-email: Pallets <contact@palletsprojects.com>
|
| 6 |
+
Requires-Python: >=3.7
|
| 7 |
+
Description-Content-Type: text/markdown
|
| 8 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 9 |
+
Classifier: Environment :: Web Environment
|
| 10 |
+
Classifier: Intended Audience :: Developers
|
| 11 |
+
Classifier: License :: OSI Approved :: BSD License
|
| 12 |
+
Classifier: Operating System :: OS Independent
|
| 13 |
+
Classifier: Programming Language :: Python
|
| 14 |
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
| 15 |
+
Classifier: Topic :: Text Processing :: Markup :: HTML
|
| 16 |
+
Classifier: Typing :: Typed
|
| 17 |
+
License-File: LICENSE.txt
|
| 18 |
+
Requires-Dist: MarkupSafe>=2.0
|
| 19 |
+
Requires-Dist: Babel>=2.7 ; extra == "i18n"
|
| 20 |
+
Project-URL: Changes, https://jinja.palletsprojects.com/changes/
|
| 21 |
+
Project-URL: Chat, https://discord.gg/pallets
|
| 22 |
+
Project-URL: Documentation, https://jinja.palletsprojects.com/
|
| 23 |
+
Project-URL: Donate, https://palletsprojects.com/donate
|
| 24 |
+
Project-URL: Source, https://github.com/pallets/jinja/
|
| 25 |
+
Provides-Extra: i18n
|
| 26 |
+
|
| 27 |
+
# Jinja
|
| 28 |
+
|
| 29 |
+
Jinja is a fast, expressive, extensible templating engine. Special
|
| 30 |
+
placeholders in the template allow writing code similar to Python
|
| 31 |
+
syntax. Then the template is passed data to render the final document.
|
| 32 |
+
|
| 33 |
+
It includes:
|
| 34 |
+
|
| 35 |
+
- Template inheritance and inclusion.
|
| 36 |
+
- Define and import macros within templates.
|
| 37 |
+
- HTML templates can use autoescaping to prevent XSS from untrusted
|
| 38 |
+
user input.
|
| 39 |
+
- A sandboxed environment can safely render untrusted templates.
|
| 40 |
+
- AsyncIO support for generating templates and calling async
|
| 41 |
+
functions.
|
| 42 |
+
- I18N support with Babel.
|
| 43 |
+
- Templates are compiled to optimized Python code just-in-time and
|
| 44 |
+
cached, or can be compiled ahead-of-time.
|
| 45 |
+
- Exceptions point to the correct line in templates to make debugging
|
| 46 |
+
easier.
|
| 47 |
+
- Extensible filters, tests, functions, and even syntax.
|
| 48 |
+
|
| 49 |
+
Jinja's philosophy is that while application logic belongs in Python if
|
| 50 |
+
possible, it shouldn't make the template designer's job difficult by
|
| 51 |
+
restricting functionality too much.
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
## In A Nutshell
|
| 55 |
+
|
| 56 |
+
```jinja
|
| 57 |
+
{% extends "base.html" %}
|
| 58 |
+
{% block title %}Members{% endblock %}
|
| 59 |
+
{% block content %}
|
| 60 |
+
<ul>
|
| 61 |
+
{% for user in users %}
|
| 62 |
+
<li><a href="{{ user.url }}">{{ user.username }}</a></li>
|
| 63 |
+
{% endfor %}
|
| 64 |
+
</ul>
|
| 65 |
+
{% endblock %}
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
## Donate
|
| 69 |
+
|
| 70 |
+
The Pallets organization develops and supports Jinja and other popular
|
| 71 |
+
packages. In order to grow the community of contributors and users, and
|
| 72 |
+
allow the maintainers to devote more time to the projects, [please
|
| 73 |
+
donate today][].
|
| 74 |
+
|
| 75 |
+
[please donate today]: https://palletsprojects.com/donate
|
| 76 |
+
|
| 77 |
+
## Contributing
|
| 78 |
+
|
| 79 |
+
See our [detailed contributing documentation][contrib] for many ways to
|
| 80 |
+
contribute, including reporting issues, requesting features, asking or answering
|
| 81 |
+
questions, and making PRs.
|
| 82 |
+
|
| 83 |
+
[contrib]: https://palletsprojects.com/contributing/
|
| 84 |
+
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/jinja2-3.1.6.dist-info/RECORD
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
jinja2-3.1.6.dist-info/INSTALLER,sha256=5hhM4Q4mYTT9z6QB6PGpUAW81PGNFrYrdXMj4oM_6ak,2
|
| 2 |
+
jinja2-3.1.6.dist-info/METADATA,sha256=aMVUj7Z8QTKhOJjZsx7FDGvqKr3ZFdkh8hQ1XDpkmcg,2871
|
| 3 |
+
jinja2-3.1.6.dist-info/RECORD,,
|
| 4 |
+
jinja2-3.1.6.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 5 |
+
jinja2-3.1.6.dist-info/WHEEL,sha256=_2ozNFCLWc93bK4WKHCO-eDUENDlo-dgc9cU3qokYO4,82
|
| 6 |
+
jinja2-3.1.6.dist-info/entry_points.txt,sha256=OL85gYU1eD8cuPlikifFngXpeBjaxl6rIJ8KkC_3r-I,58
|
| 7 |
+
jinja2-3.1.6.dist-info/licenses/LICENSE.txt,sha256=O0nc7kEF6ze6wQ-vG-JgQI_oXSUrjp3y4JefweCUQ3s,1475
|
| 8 |
+
jinja2/__init__.py,sha256=xxepO9i7DHsqkQrgBEduLtfoz2QCuT6_gbL4XSN1hbU,1928
|
| 9 |
+
jinja2/_identifier.py,sha256=_zYctNKzRqlk_murTNlzrju1FFJL7Va_Ijqqd7ii2lU,1958
|
| 10 |
+
jinja2/async_utils.py,sha256=vK-PdsuorOMnWSnEkT3iUJRIkTnYgO2T6MnGxDgHI5o,2834
|
| 11 |
+
jinja2/bccache.py,sha256=gh0qs9rulnXo0PhX5jTJy2UHzI8wFnQ63o_vw7nhzRg,14061
|
| 12 |
+
jinja2/compiler.py,sha256=9RpCQl5X88BHllJiPsHPh295Hh0uApvwFJNQuutULeM,74131
|
| 13 |
+
jinja2/constants.py,sha256=GMoFydBF_kdpaRKPoM5cl5MviquVRLVyZtfp5-16jg0,1433
|
| 14 |
+
jinja2/debug.py,sha256=CnHqCDHd-BVGvti_8ZsTolnXNhA3ECsY-6n_2pwU8Hw,6297
|
| 15 |
+
jinja2/defaults.py,sha256=boBcSw78h-lp20YbaXSJsqkAI2uN_mD_TtCydpeq5wU,1267
|
| 16 |
+
jinja2/environment.py,sha256=9nhrP7Ch-NbGX00wvyr4yy-uhNHq2OCc60ggGrni_fk,61513
|
| 17 |
+
jinja2/exceptions.py,sha256=ioHeHrWwCWNaXX1inHmHVblvc4haO7AXsjCp3GfWvx0,5071
|
| 18 |
+
jinja2/ext.py,sha256=5PF5eHfh8mXAIxXHHRB2xXbXohi8pE3nHSOxa66uS7E,31875
|
| 19 |
+
jinja2/filters.py,sha256=PQ_Egd9n9jSgtnGQYyF4K5j2nYwhUIulhPnyimkdr-k,55212
|
| 20 |
+
jinja2/idtracking.py,sha256=-ll5lIp73pML3ErUYiIJj7tdmWxcH_IlDv3yA_hiZYo,10555
|
| 21 |
+
jinja2/lexer.py,sha256=LYiYio6br-Tep9nPcupWXsPEtjluw3p1mU-lNBVRUfk,29786
|
| 22 |
+
jinja2/loaders.py,sha256=wIrnxjvcbqh5VwW28NSkfotiDq8qNCxIOSFbGUiSLB4,24055
|
| 23 |
+
jinja2/meta.py,sha256=OTDPkaFvU2Hgvx-6akz7154F8BIWaRmvJcBFvwopHww,4397
|
| 24 |
+
jinja2/nativetypes.py,sha256=7GIGALVJgdyL80oZJdQUaUfwSt5q2lSSZbXt0dNf_M4,4210
|
| 25 |
+
jinja2/nodes.py,sha256=m1Duzcr6qhZI8JQ6VyJgUNinjAf5bQzijSmDnMsvUx8,34579
|
| 26 |
+
jinja2/optimizer.py,sha256=rJnCRlQ7pZsEEmMhsQDgC_pKyDHxP5TPS6zVPGsgcu8,1651
|
| 27 |
+
jinja2/parser.py,sha256=lLOFy3sEmHc5IaEHRiH1sQVnId2moUQzhyeJZTtdY30,40383
|
| 28 |
+
jinja2/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 29 |
+
jinja2/runtime.py,sha256=gDk-GvdriJXqgsGbHgrcKTP0Yp6zPXzhzrIpCFH3jAU,34249
|
| 30 |
+
jinja2/sandbox.py,sha256=Mw2aitlY2I8la7FYhcX2YG9BtUYcLnD0Gh3d29cDWrY,15009
|
| 31 |
+
jinja2/tests.py,sha256=VLsBhVFnWg-PxSBz1MhRnNWgP1ovXk3neO1FLQMeC9Q,5926
|
| 32 |
+
jinja2/utils.py,sha256=rRp3o9e7ZKS4fyrWRbELyLcpuGVTFcnooaOa1qx_FIk,24129
|
| 33 |
+
jinja2/visitor.py,sha256=EcnL1PIwf_4RVCOMxsRNuR8AXHbS1qfAdMOE2ngKJz4,3557
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/jinja2-3.1.6.dist-info/REQUESTED
ADDED
|
File without changes
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/jinja2-3.1.6.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: flit 3.11.0
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/jinja2-3.1.6.dist-info/entry_points.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[babel.extractors]
|
| 2 |
+
jinja2=jinja2.ext:babel_extract[i18n]
|
| 3 |
+
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/jinja2-3.1.6.dist-info/licenses/LICENSE.txt
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright 2007 Pallets
|
| 2 |
+
|
| 3 |
+
Redistribution and use in source and binary forms, with or without
|
| 4 |
+
modification, are permitted provided that the following conditions are
|
| 5 |
+
met:
|
| 6 |
+
|
| 7 |
+
1. Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
|
| 10 |
+
2. Redistributions in binary form must reproduce the above copyright
|
| 11 |
+
notice, this list of conditions and the following disclaimer in the
|
| 12 |
+
documentation and/or other materials provided with the distribution.
|
| 13 |
+
|
| 14 |
+
3. Neither the name of the copyright holder nor the names of its
|
| 15 |
+
contributors may be used to endorse or promote products derived from
|
| 16 |
+
this software without specific prior written permission.
|
| 17 |
+
|
| 18 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 19 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 20 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
| 21 |
+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 22 |
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 23 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
| 24 |
+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
| 25 |
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
| 26 |
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
| 27 |
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 28 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/mako-1.3.10.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
uv
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/mako-1.3.10.dist-info/METADATA
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: Mako
|
| 3 |
+
Version: 1.3.10
|
| 4 |
+
Summary: A super-fast templating language that borrows the best ideas from the existing templating languages.
|
| 5 |
+
Home-page: https://www.makotemplates.org/
|
| 6 |
+
Author: Mike Bayer
|
| 7 |
+
Author-email: mike@zzzcomputing.com
|
| 8 |
+
License: MIT
|
| 9 |
+
Project-URL: Documentation, https://docs.makotemplates.org
|
| 10 |
+
Project-URL: Issue Tracker, https://github.com/sqlalchemy/mako
|
| 11 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 12 |
+
Classifier: License :: OSI Approved :: MIT License
|
| 13 |
+
Classifier: Environment :: Web Environment
|
| 14 |
+
Classifier: Intended Audience :: Developers
|
| 15 |
+
Classifier: Programming Language :: Python
|
| 16 |
+
Classifier: Programming Language :: Python :: 3
|
| 17 |
+
Classifier: Programming Language :: Python :: 3.8
|
| 18 |
+
Classifier: Programming Language :: Python :: 3.9
|
| 19 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 20 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 21 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 22 |
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
| 23 |
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
| 24 |
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
| 25 |
+
Requires-Python: >=3.8
|
| 26 |
+
Description-Content-Type: text/x-rst
|
| 27 |
+
License-File: LICENSE
|
| 28 |
+
Requires-Dist: MarkupSafe>=0.9.2
|
| 29 |
+
Provides-Extra: testing
|
| 30 |
+
Requires-Dist: pytest; extra == "testing"
|
| 31 |
+
Provides-Extra: babel
|
| 32 |
+
Requires-Dist: Babel; extra == "babel"
|
| 33 |
+
Provides-Extra: lingua
|
| 34 |
+
Requires-Dist: lingua; extra == "lingua"
|
| 35 |
+
Dynamic: license-file
|
| 36 |
+
|
| 37 |
+
=========================
|
| 38 |
+
Mako Templates for Python
|
| 39 |
+
=========================
|
| 40 |
+
|
| 41 |
+
Mako is a template library written in Python. It provides a familiar, non-XML
|
| 42 |
+
syntax which compiles into Python modules for maximum performance. Mako's
|
| 43 |
+
syntax and API borrows from the best ideas of many others, including Django
|
| 44 |
+
templates, Cheetah, Myghty, and Genshi. Conceptually, Mako is an embedded
|
| 45 |
+
Python (i.e. Python Server Page) language, which refines the familiar ideas
|
| 46 |
+
of componentized layout and inheritance to produce one of the most
|
| 47 |
+
straightforward and flexible models available, while also maintaining close
|
| 48 |
+
ties to Python calling and scoping semantics.
|
| 49 |
+
|
| 50 |
+
Nutshell
|
| 51 |
+
========
|
| 52 |
+
|
| 53 |
+
::
|
| 54 |
+
|
| 55 |
+
<%inherit file="base.html"/>
|
| 56 |
+
<%
|
| 57 |
+
rows = [[v for v in range(0,10)] for row in range(0,10)]
|
| 58 |
+
%>
|
| 59 |
+
<table>
|
| 60 |
+
% for row in rows:
|
| 61 |
+
${makerow(row)}
|
| 62 |
+
% endfor
|
| 63 |
+
</table>
|
| 64 |
+
|
| 65 |
+
<%def name="makerow(row)">
|
| 66 |
+
<tr>
|
| 67 |
+
% for name in row:
|
| 68 |
+
<td>${name}</td>\
|
| 69 |
+
% endfor
|
| 70 |
+
</tr>
|
| 71 |
+
</%def>
|
| 72 |
+
|
| 73 |
+
Philosophy
|
| 74 |
+
===========
|
| 75 |
+
|
| 76 |
+
Python is a great scripting language. Don't reinvent the wheel...your templates can handle it !
|
| 77 |
+
|
| 78 |
+
Documentation
|
| 79 |
+
==============
|
| 80 |
+
|
| 81 |
+
See documentation for Mako at https://docs.makotemplates.org/en/latest/
|
| 82 |
+
|
| 83 |
+
License
|
| 84 |
+
========
|
| 85 |
+
|
| 86 |
+
Mako is licensed under an MIT-style license (see LICENSE).
|
| 87 |
+
Other incorporated projects may be licensed under different licenses.
|
| 88 |
+
All licenses allow for non-commercial and commercial use.
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/mako-1.3.10.dist-info/RECORD
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
../../../bin/mako-render,sha256=G-zvRm0Al2su8FiBLnN50blSdaviiE_SumORecZeJUA,367
|
| 2 |
+
mako-1.3.10.dist-info/INSTALLER,sha256=5hhM4Q4mYTT9z6QB6PGpUAW81PGNFrYrdXMj4oM_6ak,2
|
| 3 |
+
mako-1.3.10.dist-info/METADATA,sha256=VAbwPOfALVKbDJYv5l848ZceyGwynnE9s_TXP6_dr5o,2919
|
| 4 |
+
mako-1.3.10.dist-info/RECORD,,
|
| 5 |
+
mako-1.3.10.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 6 |
+
mako-1.3.10.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
| 7 |
+
mako-1.3.10.dist-info/entry_points.txt,sha256=LsKkUsOsJQYbJ2M72hZCm968wi5K8Ywb5uFxCuN8Obk,512
|
| 8 |
+
mako-1.3.10.dist-info/licenses/LICENSE,sha256=aNcGTlPj_6jp9CCp5gS9LiBZ2cMwSS-m69TrPUgRFok,1098
|
| 9 |
+
mako-1.3.10.dist-info/top_level.txt,sha256=LItdH8cDPetpUu8rUyBG3DObS6h9Gcpr9j_WLj2S-R0,5
|
| 10 |
+
mako/__init__.py,sha256=n-XoSW8ChrO6NkJ2xUHElzvSnU6XUu5ruMZe86QldTI,243
|
| 11 |
+
mako/_ast_util.py,sha256=hCbfnnizWEa3xRCA-uVyShC2HohSpmVvexz5as_lHc8,20247
|
| 12 |
+
mako/ast.py,sha256=xYrdSiJFbf1CxJ9tU9pcPEWK0BYfwF2aDNDNLQG9PqQ,6642
|
| 13 |
+
mako/cache.py,sha256=kA6FKGl5NeTBnSTcnhoPkSaeJ0JeYpF6GM8qzEZGSts,7680
|
| 14 |
+
mako/cmd.py,sha256=Y2Y6VxNCYwO2Y8EXOdLTf5tpYgfdoondV6Ehlbh8a84,2813
|
| 15 |
+
mako/codegen.py,sha256=N49EH57CcTUfKGzI8V7GFBrAEoFhRo9lkdXBzpFYzBY,47736
|
| 16 |
+
mako/compat.py,sha256=owGbObdoF0C-6rCCs6Vnk3YGHv0bf0PpTja55Woxqb4,1820
|
| 17 |
+
mako/exceptions.py,sha256=87Djuoi1IS5zyVFml1Z5zpCP1IoI7UMOH3h4ejt3x3g,12530
|
| 18 |
+
mako/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 19 |
+
mako/ext/autohandler.py,sha256=QuhNiPSF1LZ53awQ1Qfpwu1Zi9RGOmrtCDnwCLgQzeE,1885
|
| 20 |
+
mako/ext/babelplugin.py,sha256=mmt5fG3pcYII1QsrLEV3wH1ltj-C7uKl8vBIpAjxsKY,2091
|
| 21 |
+
mako/ext/beaker_cache.py,sha256=4quuJQuXRKKUyF6kM43LQhJT1J2z1KSglRZVDW-7c1I,2578
|
| 22 |
+
mako/ext/extract.py,sha256=ZUeaRL2jWcUlrpnhXFXJB0CUJfvQVGBF9tJr5nKJAWI,4659
|
| 23 |
+
mako/ext/linguaplugin.py,sha256=sUZalJSI_XeON9aRBb2hds-ilVQaxHKlfCg_nAl7EuU,1935
|
| 24 |
+
mako/ext/preprocessors.py,sha256=HYG45idRJUwJkDpswEELL8lPFLisQzgDhW5EHpTDGkI,576
|
| 25 |
+
mako/ext/pygmentplugin.py,sha256=TnpJDyQeWTTGHZraMDpw8FB3PNzbmXhaZcjyIBudyi0,4753
|
| 26 |
+
mako/ext/turbogears.py,sha256=egv8hradAnnSJwxtmW8uXAsqPUzX8cZZCXclmO_8hMA,2141
|
| 27 |
+
mako/filters.py,sha256=IBXyGOby4eFE3UGvNLhJlzbe1FfwJ2dcEr1-gKO_Ljc,4658
|
| 28 |
+
mako/lexer.py,sha256=GMq8yf0dEn04-xw2EVDEzaOLXMSVVQz9HyUbfwKnZKg,16321
|
| 29 |
+
mako/lookup.py,sha256=4ALORJiL0wIdDvK1okW8rbjq2jL5F_TNASekDFQSULY,12428
|
| 30 |
+
mako/parsetree.py,sha256=-wmyX_mklAoKhc-7Psx0U15EKpNSd8oGRXFmvk2JQWo,19021
|
| 31 |
+
mako/pygen.py,sha256=689_jR0GG_8Am62Dmlm5h59VY6eyZAU3GroodqEDnZ0,10416
|
| 32 |
+
mako/pyparser.py,sha256=8ZqUbCDIlgEup4si2zP7-xJns14JvVzX_QMO9sCCGJ0,7558
|
| 33 |
+
mako/runtime.py,sha256=ZsUEN22nX3d3dECQujF69mBKDQS6yVv2nvz_0eTvFGg,27804
|
| 34 |
+
mako/template.py,sha256=Vn5nLoBY-YzSQJKvRPFGb4fiPyZryA5Q-8mWutv0b9A,23563
|
| 35 |
+
mako/testing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 36 |
+
mako/testing/_config.py,sha256=k-qpnsnbXUoN-ykMN5BRpg84i1x0p6UsAddKQnrIytU,3566
|
| 37 |
+
mako/testing/assertions.py,sha256=pfbGl84QlW7QWGg3_lo3wP8XnBAVo9AjzNp2ajmn7FA,5161
|
| 38 |
+
mako/testing/config.py,sha256=wmYVZfzGvOK3mJUZpzmgO8-iIgvaCH41Woi4yDpxq6E,323
|
| 39 |
+
mako/testing/exclusions.py,sha256=_t6ADKdatk3f18tOfHV_ZY6u_ZwQsKphZ2MXJVSAOcI,1553
|
| 40 |
+
mako/testing/fixtures.py,sha256=nEp7wTusf7E0n3Q-BHJW2s_t1vx0KB9poadQ1BmIJzE,3044
|
| 41 |
+
mako/testing/helpers.py,sha256=z4HAactwlht4ut1cbvxKt1QLb3yLPk1U7cnh5BwVUlc,1623
|
| 42 |
+
mako/util.py,sha256=SNYeX2_PmajQJIR3-S1Yqxxylz8lwS65rC8YbCdTkUU,10638
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/mako-1.3.10.dist-info/REQUESTED
ADDED
|
File without changes
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/mako-1.3.10.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: setuptools (78.1.0)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
| 5 |
+
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/mako-1.3.10.dist-info/entry_points.txt
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[babel.extractors]
|
| 2 |
+
mako = mako.ext.babelplugin:extract [babel]
|
| 3 |
+
|
| 4 |
+
[console_scripts]
|
| 5 |
+
mako-render = mako.cmd:cmdline
|
| 6 |
+
|
| 7 |
+
[lingua.extractors]
|
| 8 |
+
mako = mako.ext.linguaplugin:LinguaMakoExtractor [lingua]
|
| 9 |
+
|
| 10 |
+
[pygments.lexers]
|
| 11 |
+
css+mako = mako.ext.pygmentplugin:MakoCssLexer
|
| 12 |
+
html+mako = mako.ext.pygmentplugin:MakoHtmlLexer
|
| 13 |
+
js+mako = mako.ext.pygmentplugin:MakoJavascriptLexer
|
| 14 |
+
mako = mako.ext.pygmentplugin:MakoLexer
|
| 15 |
+
xml+mako = mako.ext.pygmentplugin:MakoXmlLexer
|
| 16 |
+
|
| 17 |
+
[python.templating.engines]
|
| 18 |
+
mako = mako.ext.turbogears:TGPlugin
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/mako-1.3.10.dist-info/licenses/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright 2006-2025 the Mako authors and contributors <see AUTHORS file>.
|
| 2 |
+
|
| 3 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
| 4 |
+
this software and associated documentation files (the "Software"), to deal in
|
| 5 |
+
the Software without restriction, including without limitation the rights to
|
| 6 |
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
| 7 |
+
of the Software, and to permit persons to whom the Software is furnished to do
|
| 8 |
+
so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
The above copyright notice and this permission notice shall be included in all
|
| 11 |
+
copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 18 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 19 |
+
SOFTWARE.
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/mako-1.3.10.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
mako
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/__init__.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
NetworkX
|
| 3 |
+
========
|
| 4 |
+
|
| 5 |
+
NetworkX is a Python package for the creation, manipulation, and study of the
|
| 6 |
+
structure, dynamics, and functions of complex networks.
|
| 7 |
+
|
| 8 |
+
See https://networkx.org for complete documentation.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
__version__ = "3.4.2"
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
# These are imported in order as listed
|
| 15 |
+
from networkx.lazy_imports import _lazy_import
|
| 16 |
+
|
| 17 |
+
from networkx.exception import *
|
| 18 |
+
|
| 19 |
+
from networkx import utils
|
| 20 |
+
from networkx.utils import _clear_cache, _dispatchable
|
| 21 |
+
|
| 22 |
+
# load_and_call entry_points, set configs
|
| 23 |
+
config = utils.backends._set_configs_from_environment()
|
| 24 |
+
utils.config = utils.configs.config = config # type: ignore[attr-defined]
|
| 25 |
+
|
| 26 |
+
from networkx import classes
|
| 27 |
+
from networkx.classes import filters
|
| 28 |
+
from networkx.classes import *
|
| 29 |
+
|
| 30 |
+
from networkx import convert
|
| 31 |
+
from networkx.convert import *
|
| 32 |
+
|
| 33 |
+
from networkx import convert_matrix
|
| 34 |
+
from networkx.convert_matrix import *
|
| 35 |
+
|
| 36 |
+
from networkx import relabel
|
| 37 |
+
from networkx.relabel import *
|
| 38 |
+
|
| 39 |
+
from networkx import generators
|
| 40 |
+
from networkx.generators import *
|
| 41 |
+
|
| 42 |
+
from networkx import readwrite
|
| 43 |
+
from networkx.readwrite import *
|
| 44 |
+
|
| 45 |
+
# Need to test with SciPy, when available
|
| 46 |
+
from networkx import algorithms
|
| 47 |
+
from networkx.algorithms import *
|
| 48 |
+
|
| 49 |
+
from networkx import linalg
|
| 50 |
+
from networkx.linalg import *
|
| 51 |
+
|
| 52 |
+
from networkx import drawing
|
| 53 |
+
from networkx.drawing import *
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/algorithms/walks.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Function for computing walks in a graph."""
|
| 2 |
+
|
| 3 |
+
import networkx as nx
|
| 4 |
+
|
| 5 |
+
__all__ = ["number_of_walks"]
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
@nx._dispatchable
|
| 9 |
+
def number_of_walks(G, walk_length):
|
| 10 |
+
"""Returns the number of walks connecting each pair of nodes in `G`
|
| 11 |
+
|
| 12 |
+
A *walk* is a sequence of nodes in which each adjacent pair of nodes
|
| 13 |
+
in the sequence is adjacent in the graph. A walk can repeat the same
|
| 14 |
+
edge and go in the opposite direction just as people can walk on a
|
| 15 |
+
set of paths, but standing still is not counted as part of the walk.
|
| 16 |
+
|
| 17 |
+
This function only counts the walks with `walk_length` edges. Note that
|
| 18 |
+
the number of nodes in the walk sequence is one more than `walk_length`.
|
| 19 |
+
The number of walks can grow very quickly on a larger graph
|
| 20 |
+
and with a larger walk length.
|
| 21 |
+
|
| 22 |
+
Parameters
|
| 23 |
+
----------
|
| 24 |
+
G : NetworkX graph
|
| 25 |
+
|
| 26 |
+
walk_length : int
|
| 27 |
+
A nonnegative integer representing the length of a walk.
|
| 28 |
+
|
| 29 |
+
Returns
|
| 30 |
+
-------
|
| 31 |
+
dict
|
| 32 |
+
A dictionary of dictionaries in which outer keys are source
|
| 33 |
+
nodes, inner keys are target nodes, and inner values are the
|
| 34 |
+
number of walks of length `walk_length` connecting those nodes.
|
| 35 |
+
|
| 36 |
+
Raises
|
| 37 |
+
------
|
| 38 |
+
ValueError
|
| 39 |
+
If `walk_length` is negative
|
| 40 |
+
|
| 41 |
+
Examples
|
| 42 |
+
--------
|
| 43 |
+
|
| 44 |
+
>>> G = nx.Graph([(0, 1), (1, 2)])
|
| 45 |
+
>>> walks = nx.number_of_walks(G, 2)
|
| 46 |
+
>>> walks
|
| 47 |
+
{0: {0: 1, 1: 0, 2: 1}, 1: {0: 0, 1: 2, 2: 0}, 2: {0: 1, 1: 0, 2: 1}}
|
| 48 |
+
>>> total_walks = sum(sum(tgts.values()) for _, tgts in walks.items())
|
| 49 |
+
|
| 50 |
+
You can also get the number of walks from a specific source node using the
|
| 51 |
+
returned dictionary. For example, number of walks of length 1 from node 0
|
| 52 |
+
can be found as follows:
|
| 53 |
+
|
| 54 |
+
>>> walks = nx.number_of_walks(G, 1)
|
| 55 |
+
>>> walks[0]
|
| 56 |
+
{0: 0, 1: 1, 2: 0}
|
| 57 |
+
>>> sum(walks[0].values()) # walks from 0 of length 1
|
| 58 |
+
1
|
| 59 |
+
|
| 60 |
+
Similarly, a target node can also be specified:
|
| 61 |
+
|
| 62 |
+
>>> walks[0][1]
|
| 63 |
+
1
|
| 64 |
+
|
| 65 |
+
"""
|
| 66 |
+
import numpy as np
|
| 67 |
+
|
| 68 |
+
if walk_length < 0:
|
| 69 |
+
raise ValueError(f"`walk_length` cannot be negative: {walk_length}")
|
| 70 |
+
|
| 71 |
+
A = nx.adjacency_matrix(G, weight=None)
|
| 72 |
+
# TODO: Use matrix_power from scipy.sparse when available
|
| 73 |
+
# power = sp.sparse.linalg.matrix_power(A, walk_length)
|
| 74 |
+
power = np.linalg.matrix_power(A.toarray(), walk_length)
|
| 75 |
+
result = {
|
| 76 |
+
u: {v: power.item(u_idx, v_idx) for v_idx, v in enumerate(G)}
|
| 77 |
+
for u_idx, u in enumerate(G)
|
| 78 |
+
}
|
| 79 |
+
return result
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/conftest.py
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Testing
|
| 3 |
+
=======
|
| 4 |
+
|
| 5 |
+
General guidelines for writing good tests:
|
| 6 |
+
|
| 7 |
+
- doctests always assume ``import networkx as nx`` so don't add that
|
| 8 |
+
- prefer pytest fixtures over classes with setup methods.
|
| 9 |
+
- use the ``@pytest.mark.parametrize`` decorator
|
| 10 |
+
- use ``pytest.importorskip`` for numpy, scipy, pandas, and matplotlib b/c of PyPy.
|
| 11 |
+
and add the module to the relevant entries below.
|
| 12 |
+
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
import os
|
| 16 |
+
import sys
|
| 17 |
+
import warnings
|
| 18 |
+
from importlib.metadata import entry_points
|
| 19 |
+
|
| 20 |
+
import pytest
|
| 21 |
+
|
| 22 |
+
import networkx
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def pytest_addoption(parser):
|
| 26 |
+
parser.addoption(
|
| 27 |
+
"--runslow", action="store_true", default=False, help="run slow tests"
|
| 28 |
+
)
|
| 29 |
+
parser.addoption(
|
| 30 |
+
"--backend",
|
| 31 |
+
action="store",
|
| 32 |
+
default=None,
|
| 33 |
+
help="Run tests with a backend by auto-converting nx graphs to backend graphs",
|
| 34 |
+
)
|
| 35 |
+
parser.addoption(
|
| 36 |
+
"--fallback-to-nx",
|
| 37 |
+
action="store_true",
|
| 38 |
+
default=False,
|
| 39 |
+
help="Run nx function if a backend doesn't implement a dispatchable function"
|
| 40 |
+
" (use with --backend)",
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def pytest_configure(config):
|
| 45 |
+
config.addinivalue_line("markers", "slow: mark test as slow to run")
|
| 46 |
+
backend = config.getoption("--backend")
|
| 47 |
+
if backend is None:
|
| 48 |
+
backend = os.environ.get("NETWORKX_TEST_BACKEND")
|
| 49 |
+
# nx_loopback backend is only available when testing with a backend
|
| 50 |
+
loopback_ep = entry_points(name="nx_loopback", group="networkx.backends")
|
| 51 |
+
if not loopback_ep:
|
| 52 |
+
warnings.warn(
|
| 53 |
+
"\n\n WARNING: Mixed NetworkX configuration! \n\n"
|
| 54 |
+
" This environment has mixed configuration for networkx.\n"
|
| 55 |
+
" The test object nx_loopback is not configured correctly.\n"
|
| 56 |
+
" You should not be seeing this message.\n"
|
| 57 |
+
" Try `pip install -e .`, or change your PYTHONPATH\n"
|
| 58 |
+
" Make sure python finds the networkx repo you are testing\n\n"
|
| 59 |
+
)
|
| 60 |
+
config.backend = backend
|
| 61 |
+
if backend:
|
| 62 |
+
# We will update `networkx.config.backend_priority` below in `*_modify_items`
|
| 63 |
+
# to allow tests to get set up with normal networkx graphs.
|
| 64 |
+
networkx.utils.backends.backends["nx_loopback"] = loopback_ep["nx_loopback"]
|
| 65 |
+
networkx.utils.backends.backend_info["nx_loopback"] = {}
|
| 66 |
+
networkx.config.backends = networkx.utils.Config(
|
| 67 |
+
nx_loopback=networkx.utils.Config(),
|
| 68 |
+
**networkx.config.backends,
|
| 69 |
+
)
|
| 70 |
+
fallback_to_nx = config.getoption("--fallback-to-nx")
|
| 71 |
+
if not fallback_to_nx:
|
| 72 |
+
fallback_to_nx = os.environ.get("NETWORKX_FALLBACK_TO_NX")
|
| 73 |
+
networkx.config.fallback_to_nx = bool(fallback_to_nx)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def pytest_collection_modifyitems(config, items):
|
| 77 |
+
# Setting this to True here allows tests to be set up before dispatching
|
| 78 |
+
# any function call to a backend.
|
| 79 |
+
if config.backend:
|
| 80 |
+
# Allow pluggable backends to add markers to tests (such as skip or xfail)
|
| 81 |
+
# when running in auto-conversion test mode
|
| 82 |
+
backend_name = config.backend
|
| 83 |
+
if backend_name != "networkx":
|
| 84 |
+
networkx.utils.backends._dispatchable._is_testing = True
|
| 85 |
+
networkx.config.backend_priority.algos = [backend_name]
|
| 86 |
+
networkx.config.backend_priority.generators = [backend_name]
|
| 87 |
+
backend = networkx.utils.backends.backends[backend_name].load()
|
| 88 |
+
if hasattr(backend, "on_start_tests"):
|
| 89 |
+
getattr(backend, "on_start_tests")(items)
|
| 90 |
+
|
| 91 |
+
if config.getoption("--runslow"):
|
| 92 |
+
# --runslow given in cli: do not skip slow tests
|
| 93 |
+
return
|
| 94 |
+
skip_slow = pytest.mark.skip(reason="need --runslow option to run")
|
| 95 |
+
for item in items:
|
| 96 |
+
if "slow" in item.keywords:
|
| 97 |
+
item.add_marker(skip_slow)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
# TODO: The warnings below need to be dealt with, but for now we silence them.
|
| 101 |
+
@pytest.fixture(autouse=True)
|
| 102 |
+
def set_warnings():
|
| 103 |
+
warnings.filterwarnings(
|
| 104 |
+
"ignore",
|
| 105 |
+
category=FutureWarning,
|
| 106 |
+
message="\n\nsingle_target_shortest_path_length",
|
| 107 |
+
)
|
| 108 |
+
warnings.filterwarnings(
|
| 109 |
+
"ignore",
|
| 110 |
+
category=FutureWarning,
|
| 111 |
+
message="\n\nshortest_path",
|
| 112 |
+
)
|
| 113 |
+
warnings.filterwarnings(
|
| 114 |
+
"ignore", category=DeprecationWarning, message="\n\nThe `normalized`"
|
| 115 |
+
)
|
| 116 |
+
warnings.filterwarnings(
|
| 117 |
+
"ignore", category=DeprecationWarning, message="\n\nall_triplets"
|
| 118 |
+
)
|
| 119 |
+
warnings.filterwarnings(
|
| 120 |
+
"ignore", category=DeprecationWarning, message="\n\nrandom_triad"
|
| 121 |
+
)
|
| 122 |
+
warnings.filterwarnings(
|
| 123 |
+
"ignore", category=DeprecationWarning, message="minimal_d_separator"
|
| 124 |
+
)
|
| 125 |
+
warnings.filterwarnings(
|
| 126 |
+
"ignore", category=DeprecationWarning, message="d_separated"
|
| 127 |
+
)
|
| 128 |
+
warnings.filterwarnings("ignore", category=DeprecationWarning, message="\n\nk_core")
|
| 129 |
+
warnings.filterwarnings(
|
| 130 |
+
"ignore", category=DeprecationWarning, message="\n\nk_shell"
|
| 131 |
+
)
|
| 132 |
+
warnings.filterwarnings(
|
| 133 |
+
"ignore", category=DeprecationWarning, message="\n\nk_crust"
|
| 134 |
+
)
|
| 135 |
+
warnings.filterwarnings(
|
| 136 |
+
"ignore", category=DeprecationWarning, message="\n\nk_corona"
|
| 137 |
+
)
|
| 138 |
+
warnings.filterwarnings(
|
| 139 |
+
"ignore", category=DeprecationWarning, message="\n\ntotal_spanning_tree_weight"
|
| 140 |
+
)
|
| 141 |
+
warnings.filterwarnings(
|
| 142 |
+
"ignore", category=DeprecationWarning, message=r"\n\nThe 'create=matrix'"
|
| 143 |
+
)
|
| 144 |
+
warnings.filterwarnings(
|
| 145 |
+
"ignore", category=DeprecationWarning, message="\n\n`compute_v_structures"
|
| 146 |
+
)
|
| 147 |
+
warnings.filterwarnings(
|
| 148 |
+
"ignore", category=DeprecationWarning, message="Keyword argument 'link'"
|
| 149 |
+
)
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
@pytest.fixture(autouse=True)
|
| 153 |
+
def add_nx(doctest_namespace):
|
| 154 |
+
doctest_namespace["nx"] = networkx
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
# What dependencies are installed?
|
| 158 |
+
|
| 159 |
+
try:
|
| 160 |
+
import numpy
|
| 161 |
+
|
| 162 |
+
has_numpy = True
|
| 163 |
+
except ImportError:
|
| 164 |
+
has_numpy = False
|
| 165 |
+
|
| 166 |
+
try:
|
| 167 |
+
import scipy
|
| 168 |
+
|
| 169 |
+
has_scipy = True
|
| 170 |
+
except ImportError:
|
| 171 |
+
has_scipy = False
|
| 172 |
+
|
| 173 |
+
try:
|
| 174 |
+
import matplotlib
|
| 175 |
+
|
| 176 |
+
has_matplotlib = True
|
| 177 |
+
except ImportError:
|
| 178 |
+
has_matplotlib = False
|
| 179 |
+
|
| 180 |
+
try:
|
| 181 |
+
import pandas
|
| 182 |
+
|
| 183 |
+
has_pandas = True
|
| 184 |
+
except ImportError:
|
| 185 |
+
has_pandas = False
|
| 186 |
+
|
| 187 |
+
try:
|
| 188 |
+
import pygraphviz
|
| 189 |
+
|
| 190 |
+
has_pygraphviz = True
|
| 191 |
+
except ImportError:
|
| 192 |
+
has_pygraphviz = False
|
| 193 |
+
|
| 194 |
+
try:
|
| 195 |
+
import pydot
|
| 196 |
+
|
| 197 |
+
has_pydot = True
|
| 198 |
+
except ImportError:
|
| 199 |
+
has_pydot = False
|
| 200 |
+
|
| 201 |
+
try:
|
| 202 |
+
import sympy
|
| 203 |
+
|
| 204 |
+
has_sympy = True
|
| 205 |
+
except ImportError:
|
| 206 |
+
has_sympy = False
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
# List of files that pytest should ignore
|
| 210 |
+
|
| 211 |
+
collect_ignore = []
|
| 212 |
+
|
| 213 |
+
needs_numpy = [
|
| 214 |
+
"algorithms/approximation/traveling_salesman.py",
|
| 215 |
+
"algorithms/centrality/current_flow_closeness.py",
|
| 216 |
+
"algorithms/centrality/laplacian.py",
|
| 217 |
+
"algorithms/node_classification.py",
|
| 218 |
+
"algorithms/non_randomness.py",
|
| 219 |
+
"algorithms/polynomials.py",
|
| 220 |
+
"algorithms/shortest_paths/dense.py",
|
| 221 |
+
"algorithms/tree/mst.py",
|
| 222 |
+
"drawing/nx_latex.py",
|
| 223 |
+
"generators/expanders.py",
|
| 224 |
+
"linalg/bethehessianmatrix.py",
|
| 225 |
+
"linalg/laplacianmatrix.py",
|
| 226 |
+
"utils/misc.py",
|
| 227 |
+
]
|
| 228 |
+
needs_scipy = [
|
| 229 |
+
"algorithms/approximation/traveling_salesman.py",
|
| 230 |
+
"algorithms/assortativity/correlation.py",
|
| 231 |
+
"algorithms/assortativity/mixing.py",
|
| 232 |
+
"algorithms/assortativity/pairs.py",
|
| 233 |
+
"algorithms/bipartite/matrix.py",
|
| 234 |
+
"algorithms/bipartite/spectral.py",
|
| 235 |
+
"algorithms/centrality/current_flow_betweenness.py",
|
| 236 |
+
"algorithms/centrality/current_flow_betweenness_subset.py",
|
| 237 |
+
"algorithms/centrality/eigenvector.py",
|
| 238 |
+
"algorithms/centrality/katz.py",
|
| 239 |
+
"algorithms/centrality/laplacian.py",
|
| 240 |
+
"algorithms/centrality/second_order.py",
|
| 241 |
+
"algorithms/centrality/subgraph_alg.py",
|
| 242 |
+
"algorithms/communicability_alg.py",
|
| 243 |
+
"algorithms/community/divisive.py",
|
| 244 |
+
"algorithms/distance_measures.py",
|
| 245 |
+
"algorithms/link_analysis/hits_alg.py",
|
| 246 |
+
"algorithms/link_analysis/pagerank_alg.py",
|
| 247 |
+
"algorithms/node_classification.py",
|
| 248 |
+
"algorithms/similarity.py",
|
| 249 |
+
"algorithms/tree/mst.py",
|
| 250 |
+
"algorithms/walks.py",
|
| 251 |
+
"convert_matrix.py",
|
| 252 |
+
"drawing/layout.py",
|
| 253 |
+
"drawing/nx_pylab.py",
|
| 254 |
+
"generators/spectral_graph_forge.py",
|
| 255 |
+
"generators/expanders.py",
|
| 256 |
+
"linalg/algebraicconnectivity.py",
|
| 257 |
+
"linalg/attrmatrix.py",
|
| 258 |
+
"linalg/bethehessianmatrix.py",
|
| 259 |
+
"linalg/graphmatrix.py",
|
| 260 |
+
"linalg/laplacianmatrix.py",
|
| 261 |
+
"linalg/modularitymatrix.py",
|
| 262 |
+
"linalg/spectrum.py",
|
| 263 |
+
"utils/rcm.py",
|
| 264 |
+
]
|
| 265 |
+
needs_matplotlib = ["drawing/nx_pylab.py", "generators/classic.py"]
|
| 266 |
+
needs_pandas = ["convert_matrix.py"]
|
| 267 |
+
needs_pygraphviz = ["drawing/nx_agraph.py"]
|
| 268 |
+
needs_pydot = ["drawing/nx_pydot.py"]
|
| 269 |
+
needs_sympy = ["algorithms/polynomials.py"]
|
| 270 |
+
|
| 271 |
+
if not has_numpy:
|
| 272 |
+
collect_ignore += needs_numpy
|
| 273 |
+
if not has_scipy:
|
| 274 |
+
collect_ignore += needs_scipy
|
| 275 |
+
if not has_matplotlib:
|
| 276 |
+
collect_ignore += needs_matplotlib
|
| 277 |
+
if not has_pandas:
|
| 278 |
+
collect_ignore += needs_pandas
|
| 279 |
+
if not has_pygraphviz:
|
| 280 |
+
collect_ignore += needs_pygraphviz
|
| 281 |
+
if not has_pydot:
|
| 282 |
+
collect_ignore += needs_pydot
|
| 283 |
+
if not has_sympy:
|
| 284 |
+
collect_ignore += needs_sympy
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/convert.py
ADDED
|
@@ -0,0 +1,502 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Functions to convert NetworkX graphs to and from other formats.
|
| 2 |
+
|
| 3 |
+
The preferred way of converting data to a NetworkX graph is through the
|
| 4 |
+
graph constructor. The constructor calls the to_networkx_graph() function
|
| 5 |
+
which attempts to guess the input type and convert it automatically.
|
| 6 |
+
|
| 7 |
+
Examples
|
| 8 |
+
--------
|
| 9 |
+
Create a graph with a single edge from a dictionary of dictionaries
|
| 10 |
+
|
| 11 |
+
>>> d = {0: {1: 1}} # dict-of-dicts single edge (0,1)
|
| 12 |
+
>>> G = nx.Graph(d)
|
| 13 |
+
|
| 14 |
+
See Also
|
| 15 |
+
--------
|
| 16 |
+
nx_agraph, nx_pydot
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
import warnings
|
| 20 |
+
from collections.abc import Collection, Generator, Iterator
|
| 21 |
+
|
| 22 |
+
import networkx as nx
|
| 23 |
+
|
| 24 |
+
__all__ = [
|
| 25 |
+
"to_networkx_graph",
|
| 26 |
+
"from_dict_of_dicts",
|
| 27 |
+
"to_dict_of_dicts",
|
| 28 |
+
"from_dict_of_lists",
|
| 29 |
+
"to_dict_of_lists",
|
| 30 |
+
"from_edgelist",
|
| 31 |
+
"to_edgelist",
|
| 32 |
+
]
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def to_networkx_graph(data, create_using=None, multigraph_input=False):
|
| 36 |
+
"""Make a NetworkX graph from a known data structure.
|
| 37 |
+
|
| 38 |
+
The preferred way to call this is automatically
|
| 39 |
+
from the class constructor
|
| 40 |
+
|
| 41 |
+
>>> d = {0: {1: {"weight": 1}}} # dict-of-dicts single edge (0,1)
|
| 42 |
+
>>> G = nx.Graph(d)
|
| 43 |
+
|
| 44 |
+
instead of the equivalent
|
| 45 |
+
|
| 46 |
+
>>> G = nx.from_dict_of_dicts(d)
|
| 47 |
+
|
| 48 |
+
Parameters
|
| 49 |
+
----------
|
| 50 |
+
data : object to be converted
|
| 51 |
+
|
| 52 |
+
Current known types are:
|
| 53 |
+
any NetworkX graph
|
| 54 |
+
dict-of-dicts
|
| 55 |
+
dict-of-lists
|
| 56 |
+
container (e.g. set, list, tuple) of edges
|
| 57 |
+
iterator (e.g. itertools.chain) that produces edges
|
| 58 |
+
generator of edges
|
| 59 |
+
Pandas DataFrame (row per edge)
|
| 60 |
+
2D numpy array
|
| 61 |
+
scipy sparse array
|
| 62 |
+
pygraphviz agraph
|
| 63 |
+
|
| 64 |
+
create_using : NetworkX graph constructor, optional (default=nx.Graph)
|
| 65 |
+
Graph type to create. If graph instance, then cleared before populated.
|
| 66 |
+
|
| 67 |
+
multigraph_input : bool (default False)
|
| 68 |
+
If True and data is a dict_of_dicts,
|
| 69 |
+
try to create a multigraph assuming dict_of_dict_of_lists.
|
| 70 |
+
If data and create_using are both multigraphs then create
|
| 71 |
+
a multigraph from a multigraph.
|
| 72 |
+
|
| 73 |
+
"""
|
| 74 |
+
# NX graph
|
| 75 |
+
if hasattr(data, "adj"):
|
| 76 |
+
try:
|
| 77 |
+
result = from_dict_of_dicts(
|
| 78 |
+
data.adj,
|
| 79 |
+
create_using=create_using,
|
| 80 |
+
multigraph_input=data.is_multigraph(),
|
| 81 |
+
)
|
| 82 |
+
# data.graph should be dict-like
|
| 83 |
+
result.graph.update(data.graph)
|
| 84 |
+
# data.nodes should be dict-like
|
| 85 |
+
# result.add_node_from(data.nodes.items()) possible but
|
| 86 |
+
# for custom node_attr_dict_factory which may be hashable
|
| 87 |
+
# will be unexpected behavior
|
| 88 |
+
for n, dd in data.nodes.items():
|
| 89 |
+
result._node[n].update(dd)
|
| 90 |
+
return result
|
| 91 |
+
except Exception as err:
|
| 92 |
+
raise nx.NetworkXError("Input is not a correct NetworkX graph.") from err
|
| 93 |
+
|
| 94 |
+
# dict of dicts/lists
|
| 95 |
+
if isinstance(data, dict):
|
| 96 |
+
try:
|
| 97 |
+
return from_dict_of_dicts(
|
| 98 |
+
data, create_using=create_using, multigraph_input=multigraph_input
|
| 99 |
+
)
|
| 100 |
+
except Exception as err1:
|
| 101 |
+
if multigraph_input is True:
|
| 102 |
+
raise nx.NetworkXError(
|
| 103 |
+
f"converting multigraph_input raised:\n{type(err1)}: {err1}"
|
| 104 |
+
)
|
| 105 |
+
try:
|
| 106 |
+
return from_dict_of_lists(data, create_using=create_using)
|
| 107 |
+
except Exception as err2:
|
| 108 |
+
raise TypeError("Input is not known type.") from err2
|
| 109 |
+
|
| 110 |
+
# edgelists
|
| 111 |
+
if isinstance(data, list | tuple | nx.reportviews.EdgeViewABC | Iterator):
|
| 112 |
+
try:
|
| 113 |
+
return from_edgelist(data, create_using=create_using)
|
| 114 |
+
except:
|
| 115 |
+
pass
|
| 116 |
+
|
| 117 |
+
# pygraphviz agraph
|
| 118 |
+
if hasattr(data, "is_strict"):
|
| 119 |
+
try:
|
| 120 |
+
return nx.nx_agraph.from_agraph(data, create_using=create_using)
|
| 121 |
+
except Exception as err:
|
| 122 |
+
raise nx.NetworkXError("Input is not a correct pygraphviz graph.") from err
|
| 123 |
+
|
| 124 |
+
# Pandas DataFrame
|
| 125 |
+
try:
|
| 126 |
+
import pandas as pd
|
| 127 |
+
|
| 128 |
+
if isinstance(data, pd.DataFrame):
|
| 129 |
+
if data.shape[0] == data.shape[1]:
|
| 130 |
+
try:
|
| 131 |
+
return nx.from_pandas_adjacency(data, create_using=create_using)
|
| 132 |
+
except Exception as err:
|
| 133 |
+
msg = "Input is not a correct Pandas DataFrame adjacency matrix."
|
| 134 |
+
raise nx.NetworkXError(msg) from err
|
| 135 |
+
else:
|
| 136 |
+
try:
|
| 137 |
+
return nx.from_pandas_edgelist(
|
| 138 |
+
data, edge_attr=True, create_using=create_using
|
| 139 |
+
)
|
| 140 |
+
except Exception as err:
|
| 141 |
+
msg = "Input is not a correct Pandas DataFrame edge-list."
|
| 142 |
+
raise nx.NetworkXError(msg) from err
|
| 143 |
+
except ImportError:
|
| 144 |
+
pass
|
| 145 |
+
|
| 146 |
+
# numpy array
|
| 147 |
+
try:
|
| 148 |
+
import numpy as np
|
| 149 |
+
|
| 150 |
+
if isinstance(data, np.ndarray):
|
| 151 |
+
try:
|
| 152 |
+
return nx.from_numpy_array(data, create_using=create_using)
|
| 153 |
+
except Exception as err:
|
| 154 |
+
raise nx.NetworkXError(
|
| 155 |
+
f"Failed to interpret array as an adjacency matrix."
|
| 156 |
+
) from err
|
| 157 |
+
except ImportError:
|
| 158 |
+
pass
|
| 159 |
+
|
| 160 |
+
# scipy sparse array - any format
|
| 161 |
+
try:
|
| 162 |
+
import scipy
|
| 163 |
+
|
| 164 |
+
if hasattr(data, "format"):
|
| 165 |
+
try:
|
| 166 |
+
return nx.from_scipy_sparse_array(data, create_using=create_using)
|
| 167 |
+
except Exception as err:
|
| 168 |
+
raise nx.NetworkXError(
|
| 169 |
+
"Input is not a correct scipy sparse array type."
|
| 170 |
+
) from err
|
| 171 |
+
except ImportError:
|
| 172 |
+
pass
|
| 173 |
+
|
| 174 |
+
# Note: most general check - should remain last in order of execution
|
| 175 |
+
# Includes containers (e.g. list, set, dict, etc.), generators, and
|
| 176 |
+
# iterators (e.g. itertools.chain) of edges
|
| 177 |
+
|
| 178 |
+
if isinstance(data, Collection | Generator | Iterator):
|
| 179 |
+
try:
|
| 180 |
+
return from_edgelist(data, create_using=create_using)
|
| 181 |
+
except Exception as err:
|
| 182 |
+
raise nx.NetworkXError("Input is not a valid edge list") from err
|
| 183 |
+
|
| 184 |
+
raise nx.NetworkXError("Input is not a known data type for conversion.")
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
@nx._dispatchable
|
| 188 |
+
def to_dict_of_lists(G, nodelist=None):
|
| 189 |
+
"""Returns adjacency representation of graph as a dictionary of lists.
|
| 190 |
+
|
| 191 |
+
Parameters
|
| 192 |
+
----------
|
| 193 |
+
G : graph
|
| 194 |
+
A NetworkX graph
|
| 195 |
+
|
| 196 |
+
nodelist : list
|
| 197 |
+
Use only nodes specified in nodelist
|
| 198 |
+
|
| 199 |
+
Notes
|
| 200 |
+
-----
|
| 201 |
+
Completely ignores edge data for MultiGraph and MultiDiGraph.
|
| 202 |
+
|
| 203 |
+
"""
|
| 204 |
+
if nodelist is None:
|
| 205 |
+
nodelist = G
|
| 206 |
+
|
| 207 |
+
d = {}
|
| 208 |
+
for n in nodelist:
|
| 209 |
+
d[n] = [nbr for nbr in G.neighbors(n) if nbr in nodelist]
|
| 210 |
+
return d
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
@nx._dispatchable(graphs=None, returns_graph=True)
|
| 214 |
+
def from_dict_of_lists(d, create_using=None):
|
| 215 |
+
"""Returns a graph from a dictionary of lists.
|
| 216 |
+
|
| 217 |
+
Parameters
|
| 218 |
+
----------
|
| 219 |
+
d : dictionary of lists
|
| 220 |
+
A dictionary of lists adjacency representation.
|
| 221 |
+
|
| 222 |
+
create_using : NetworkX graph constructor, optional (default=nx.Graph)
|
| 223 |
+
Graph type to create. If graph instance, then cleared before populated.
|
| 224 |
+
|
| 225 |
+
Examples
|
| 226 |
+
--------
|
| 227 |
+
>>> dol = {0: [1]} # single edge (0,1)
|
| 228 |
+
>>> G = nx.from_dict_of_lists(dol)
|
| 229 |
+
|
| 230 |
+
or
|
| 231 |
+
|
| 232 |
+
>>> G = nx.Graph(dol) # use Graph constructor
|
| 233 |
+
|
| 234 |
+
"""
|
| 235 |
+
G = nx.empty_graph(0, create_using)
|
| 236 |
+
G.add_nodes_from(d)
|
| 237 |
+
if G.is_multigraph() and not G.is_directed():
|
| 238 |
+
# a dict_of_lists can't show multiedges. BUT for undirected graphs,
|
| 239 |
+
# each edge shows up twice in the dict_of_lists.
|
| 240 |
+
# So we need to treat this case separately.
|
| 241 |
+
seen = {}
|
| 242 |
+
for node, nbrlist in d.items():
|
| 243 |
+
for nbr in nbrlist:
|
| 244 |
+
if nbr not in seen:
|
| 245 |
+
G.add_edge(node, nbr)
|
| 246 |
+
seen[node] = 1 # don't allow reverse edge to show up
|
| 247 |
+
else:
|
| 248 |
+
G.add_edges_from(
|
| 249 |
+
((node, nbr) for node, nbrlist in d.items() for nbr in nbrlist)
|
| 250 |
+
)
|
| 251 |
+
return G
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
def to_dict_of_dicts(G, nodelist=None, edge_data=None):
|
| 255 |
+
"""Returns adjacency representation of graph as a dictionary of dictionaries.
|
| 256 |
+
|
| 257 |
+
Parameters
|
| 258 |
+
----------
|
| 259 |
+
G : graph
|
| 260 |
+
A NetworkX graph
|
| 261 |
+
|
| 262 |
+
nodelist : list
|
| 263 |
+
Use only nodes specified in nodelist
|
| 264 |
+
|
| 265 |
+
edge_data : scalar, optional
|
| 266 |
+
If provided, the value of the dictionary will be set to `edge_data` for
|
| 267 |
+
all edges. Usual values could be `1` or `True`. If `edge_data` is
|
| 268 |
+
`None` (the default), the edgedata in `G` is used, resulting in a
|
| 269 |
+
dict-of-dict-of-dicts. If `G` is a MultiGraph, the result will be a
|
| 270 |
+
dict-of-dict-of-dict-of-dicts. See Notes for an approach to customize
|
| 271 |
+
handling edge data. `edge_data` should *not* be a container.
|
| 272 |
+
|
| 273 |
+
Returns
|
| 274 |
+
-------
|
| 275 |
+
dod : dict
|
| 276 |
+
A nested dictionary representation of `G`. Note that the level of
|
| 277 |
+
nesting depends on the type of `G` and the value of `edge_data`
|
| 278 |
+
(see Examples).
|
| 279 |
+
|
| 280 |
+
See Also
|
| 281 |
+
--------
|
| 282 |
+
from_dict_of_dicts, to_dict_of_lists
|
| 283 |
+
|
| 284 |
+
Notes
|
| 285 |
+
-----
|
| 286 |
+
For a more custom approach to handling edge data, try::
|
| 287 |
+
|
| 288 |
+
dod = {
|
| 289 |
+
n: {nbr: custom(n, nbr, dd) for nbr, dd in nbrdict.items()}
|
| 290 |
+
for n, nbrdict in G.adj.items()
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
where `custom` returns the desired edge data for each edge between `n` and
|
| 294 |
+
`nbr`, given existing edge data `dd`.
|
| 295 |
+
|
| 296 |
+
Examples
|
| 297 |
+
--------
|
| 298 |
+
>>> G = nx.path_graph(3)
|
| 299 |
+
>>> nx.to_dict_of_dicts(G)
|
| 300 |
+
{0: {1: {}}, 1: {0: {}, 2: {}}, 2: {1: {}}}
|
| 301 |
+
|
| 302 |
+
Edge data is preserved by default (``edge_data=None``), resulting
|
| 303 |
+
in dict-of-dict-of-dicts where the innermost dictionary contains the
|
| 304 |
+
edge data:
|
| 305 |
+
|
| 306 |
+
>>> G = nx.Graph()
|
| 307 |
+
>>> G.add_edges_from(
|
| 308 |
+
... [
|
| 309 |
+
... (0, 1, {"weight": 1.0}),
|
| 310 |
+
... (1, 2, {"weight": 2.0}),
|
| 311 |
+
... (2, 0, {"weight": 1.0}),
|
| 312 |
+
... ]
|
| 313 |
+
... )
|
| 314 |
+
>>> d = nx.to_dict_of_dicts(G)
|
| 315 |
+
>>> d # doctest: +SKIP
|
| 316 |
+
{0: {1: {'weight': 1.0}, 2: {'weight': 1.0}},
|
| 317 |
+
1: {0: {'weight': 1.0}, 2: {'weight': 2.0}},
|
| 318 |
+
2: {1: {'weight': 2.0}, 0: {'weight': 1.0}}}
|
| 319 |
+
>>> d[1][2]["weight"]
|
| 320 |
+
2.0
|
| 321 |
+
|
| 322 |
+
If `edge_data` is not `None`, edge data in the original graph (if any) is
|
| 323 |
+
replaced:
|
| 324 |
+
|
| 325 |
+
>>> d = nx.to_dict_of_dicts(G, edge_data=1)
|
| 326 |
+
>>> d
|
| 327 |
+
{0: {1: 1, 2: 1}, 1: {0: 1, 2: 1}, 2: {1: 1, 0: 1}}
|
| 328 |
+
>>> d[1][2]
|
| 329 |
+
1
|
| 330 |
+
|
| 331 |
+
This also applies to MultiGraphs: edge data is preserved by default:
|
| 332 |
+
|
| 333 |
+
>>> G = nx.MultiGraph()
|
| 334 |
+
>>> G.add_edge(0, 1, key="a", weight=1.0)
|
| 335 |
+
'a'
|
| 336 |
+
>>> G.add_edge(0, 1, key="b", weight=5.0)
|
| 337 |
+
'b'
|
| 338 |
+
>>> d = nx.to_dict_of_dicts(G)
|
| 339 |
+
>>> d # doctest: +SKIP
|
| 340 |
+
{0: {1: {'a': {'weight': 1.0}, 'b': {'weight': 5.0}}},
|
| 341 |
+
1: {0: {'a': {'weight': 1.0}, 'b': {'weight': 5.0}}}}
|
| 342 |
+
>>> d[0][1]["b"]["weight"]
|
| 343 |
+
5.0
|
| 344 |
+
|
| 345 |
+
But multi edge data is lost if `edge_data` is not `None`:
|
| 346 |
+
|
| 347 |
+
>>> d = nx.to_dict_of_dicts(G, edge_data=10)
|
| 348 |
+
>>> d
|
| 349 |
+
{0: {1: 10}, 1: {0: 10}}
|
| 350 |
+
"""
|
| 351 |
+
dod = {}
|
| 352 |
+
if nodelist is None:
|
| 353 |
+
if edge_data is None:
|
| 354 |
+
for u, nbrdict in G.adjacency():
|
| 355 |
+
dod[u] = nbrdict.copy()
|
| 356 |
+
else: # edge_data is not None
|
| 357 |
+
for u, nbrdict in G.adjacency():
|
| 358 |
+
dod[u] = dod.fromkeys(nbrdict, edge_data)
|
| 359 |
+
else: # nodelist is not None
|
| 360 |
+
if edge_data is None:
|
| 361 |
+
for u in nodelist:
|
| 362 |
+
dod[u] = {}
|
| 363 |
+
for v, data in ((v, data) for v, data in G[u].items() if v in nodelist):
|
| 364 |
+
dod[u][v] = data
|
| 365 |
+
else: # nodelist and edge_data are not None
|
| 366 |
+
for u in nodelist:
|
| 367 |
+
dod[u] = {}
|
| 368 |
+
for v in (v for v in G[u] if v in nodelist):
|
| 369 |
+
dod[u][v] = edge_data
|
| 370 |
+
return dod
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
@nx._dispatchable(graphs=None, returns_graph=True)
|
| 374 |
+
def from_dict_of_dicts(d, create_using=None, multigraph_input=False):
|
| 375 |
+
"""Returns a graph from a dictionary of dictionaries.
|
| 376 |
+
|
| 377 |
+
Parameters
|
| 378 |
+
----------
|
| 379 |
+
d : dictionary of dictionaries
|
| 380 |
+
A dictionary of dictionaries adjacency representation.
|
| 381 |
+
|
| 382 |
+
create_using : NetworkX graph constructor, optional (default=nx.Graph)
|
| 383 |
+
Graph type to create. If graph instance, then cleared before populated.
|
| 384 |
+
|
| 385 |
+
multigraph_input : bool (default False)
|
| 386 |
+
When True, the dict `d` is assumed
|
| 387 |
+
to be a dict-of-dict-of-dict-of-dict structure keyed by
|
| 388 |
+
node to neighbor to edge keys to edge data for multi-edges.
|
| 389 |
+
Otherwise this routine assumes dict-of-dict-of-dict keyed by
|
| 390 |
+
node to neighbor to edge data.
|
| 391 |
+
|
| 392 |
+
Examples
|
| 393 |
+
--------
|
| 394 |
+
>>> dod = {0: {1: {"weight": 1}}} # single edge (0,1)
|
| 395 |
+
>>> G = nx.from_dict_of_dicts(dod)
|
| 396 |
+
|
| 397 |
+
or
|
| 398 |
+
|
| 399 |
+
>>> G = nx.Graph(dod) # use Graph constructor
|
| 400 |
+
|
| 401 |
+
"""
|
| 402 |
+
G = nx.empty_graph(0, create_using)
|
| 403 |
+
G.add_nodes_from(d)
|
| 404 |
+
# does dict d represent a MultiGraph or MultiDiGraph?
|
| 405 |
+
if multigraph_input:
|
| 406 |
+
if G.is_directed():
|
| 407 |
+
if G.is_multigraph():
|
| 408 |
+
G.add_edges_from(
|
| 409 |
+
(u, v, key, data)
|
| 410 |
+
for u, nbrs in d.items()
|
| 411 |
+
for v, datadict in nbrs.items()
|
| 412 |
+
for key, data in datadict.items()
|
| 413 |
+
)
|
| 414 |
+
else:
|
| 415 |
+
G.add_edges_from(
|
| 416 |
+
(u, v, data)
|
| 417 |
+
for u, nbrs in d.items()
|
| 418 |
+
for v, datadict in nbrs.items()
|
| 419 |
+
for key, data in datadict.items()
|
| 420 |
+
)
|
| 421 |
+
else: # Undirected
|
| 422 |
+
if G.is_multigraph():
|
| 423 |
+
seen = set() # don't add both directions of undirected graph
|
| 424 |
+
for u, nbrs in d.items():
|
| 425 |
+
for v, datadict in nbrs.items():
|
| 426 |
+
if (u, v) not in seen:
|
| 427 |
+
G.add_edges_from(
|
| 428 |
+
(u, v, key, data) for key, data in datadict.items()
|
| 429 |
+
)
|
| 430 |
+
seen.add((v, u))
|
| 431 |
+
else:
|
| 432 |
+
seen = set() # don't add both directions of undirected graph
|
| 433 |
+
for u, nbrs in d.items():
|
| 434 |
+
for v, datadict in nbrs.items():
|
| 435 |
+
if (u, v) not in seen:
|
| 436 |
+
G.add_edges_from(
|
| 437 |
+
(u, v, data) for key, data in datadict.items()
|
| 438 |
+
)
|
| 439 |
+
seen.add((v, u))
|
| 440 |
+
|
| 441 |
+
else: # not a multigraph to multigraph transfer
|
| 442 |
+
if G.is_multigraph() and not G.is_directed():
|
| 443 |
+
# d can have both representations u-v, v-u in dict. Only add one.
|
| 444 |
+
# We don't need this check for digraphs since we add both directions,
|
| 445 |
+
# or for Graph() since it is done implicitly (parallel edges not allowed)
|
| 446 |
+
seen = set()
|
| 447 |
+
for u, nbrs in d.items():
|
| 448 |
+
for v, data in nbrs.items():
|
| 449 |
+
if (u, v) not in seen:
|
| 450 |
+
G.add_edge(u, v, key=0)
|
| 451 |
+
G[u][v][0].update(data)
|
| 452 |
+
seen.add((v, u))
|
| 453 |
+
else:
|
| 454 |
+
G.add_edges_from(
|
| 455 |
+
((u, v, data) for u, nbrs in d.items() for v, data in nbrs.items())
|
| 456 |
+
)
|
| 457 |
+
return G
|
| 458 |
+
|
| 459 |
+
|
| 460 |
+
@nx._dispatchable(preserve_edge_attrs=True)
|
| 461 |
+
def to_edgelist(G, nodelist=None):
|
| 462 |
+
"""Returns a list of edges in the graph.
|
| 463 |
+
|
| 464 |
+
Parameters
|
| 465 |
+
----------
|
| 466 |
+
G : graph
|
| 467 |
+
A NetworkX graph
|
| 468 |
+
|
| 469 |
+
nodelist : list
|
| 470 |
+
Use only nodes specified in nodelist
|
| 471 |
+
|
| 472 |
+
"""
|
| 473 |
+
if nodelist is None:
|
| 474 |
+
return G.edges(data=True)
|
| 475 |
+
return G.edges(nodelist, data=True)
|
| 476 |
+
|
| 477 |
+
|
| 478 |
+
@nx._dispatchable(graphs=None, returns_graph=True)
|
| 479 |
+
def from_edgelist(edgelist, create_using=None):
|
| 480 |
+
"""Returns a graph from a list of edges.
|
| 481 |
+
|
| 482 |
+
Parameters
|
| 483 |
+
----------
|
| 484 |
+
edgelist : list or iterator
|
| 485 |
+
Edge tuples
|
| 486 |
+
|
| 487 |
+
create_using : NetworkX graph constructor, optional (default=nx.Graph)
|
| 488 |
+
Graph type to create. If graph instance, then cleared before populated.
|
| 489 |
+
|
| 490 |
+
Examples
|
| 491 |
+
--------
|
| 492 |
+
>>> edgelist = [(0, 1)] # single edge (0,1)
|
| 493 |
+
>>> G = nx.from_edgelist(edgelist)
|
| 494 |
+
|
| 495 |
+
or
|
| 496 |
+
|
| 497 |
+
>>> G = nx.Graph(edgelist) # use Graph constructor
|
| 498 |
+
|
| 499 |
+
"""
|
| 500 |
+
G = nx.empty_graph(0, create_using)
|
| 501 |
+
G.add_edges_from(edgelist)
|
| 502 |
+
return G
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/convert_matrix.py
ADDED
|
@@ -0,0 +1,1317 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
| 4 |
+
The preferred way of converting data to a NetworkX graph is through the
|
| 5 |
+
graph constructor. The constructor calls the `~networkx.convert.to_networkx_graph`
|
| 6 |
+
function which attempts to guess the input type and convert it automatically.
|
| 7 |
+
|
| 8 |
+
Examples
|
| 9 |
+
--------
|
| 10 |
+
Create a 10 node random graph from a numpy array
|
| 11 |
+
|
| 12 |
+
>>> import numpy as np
|
| 13 |
+
>>> rng = np.random.default_rng()
|
| 14 |
+
>>> a = rng.integers(low=0, high=2, size=(10, 10))
|
| 15 |
+
>>> DG = nx.from_numpy_array(a, create_using=nx.DiGraph)
|
| 16 |
+
|
| 17 |
+
or equivalently:
|
| 18 |
+
|
| 19 |
+
>>> DG = nx.DiGraph(a)
|
| 20 |
+
|
| 21 |
+
which calls `from_numpy_array` internally based on the type of ``a``.
|
| 22 |
+
|
| 23 |
+
See Also
|
| 24 |
+
--------
|
| 25 |
+
nx_agraph, nx_pydot
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
import itertools
|
| 29 |
+
from collections import defaultdict
|
| 30 |
+
|
| 31 |
+
import networkx as nx
|
| 32 |
+
from networkx.utils import not_implemented_for
|
| 33 |
+
|
| 34 |
+
__all__ = [
|
| 35 |
+
"from_pandas_adjacency",
|
| 36 |
+
"to_pandas_adjacency",
|
| 37 |
+
"from_pandas_edgelist",
|
| 38 |
+
"to_pandas_edgelist",
|
| 39 |
+
"from_scipy_sparse_array",
|
| 40 |
+
"to_scipy_sparse_array",
|
| 41 |
+
"from_numpy_array",
|
| 42 |
+
"to_numpy_array",
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
@nx._dispatchable(edge_attrs="weight")
|
| 47 |
+
def to_pandas_adjacency(
|
| 48 |
+
G,
|
| 49 |
+
nodelist=None,
|
| 50 |
+
dtype=None,
|
| 51 |
+
order=None,
|
| 52 |
+
multigraph_weight=sum,
|
| 53 |
+
weight="weight",
|
| 54 |
+
nonedge=0.0,
|
| 55 |
+
):
|
| 56 |
+
"""Returns the graph adjacency matrix as a Pandas DataFrame.
|
| 57 |
+
|
| 58 |
+
Parameters
|
| 59 |
+
----------
|
| 60 |
+
G : graph
|
| 61 |
+
The NetworkX graph used to construct the Pandas DataFrame.
|
| 62 |
+
|
| 63 |
+
nodelist : list, optional
|
| 64 |
+
The rows and columns are ordered according to the nodes in `nodelist`.
|
| 65 |
+
If `nodelist` is None, then the ordering is produced by G.nodes().
|
| 66 |
+
|
| 67 |
+
multigraph_weight : {sum, min, max}, optional
|
| 68 |
+
An operator that determines how weights in multigraphs are handled.
|
| 69 |
+
The default is to sum the weights of the multiple edges.
|
| 70 |
+
|
| 71 |
+
weight : string or None, optional
|
| 72 |
+
The edge attribute that holds the numerical value used for
|
| 73 |
+
the edge weight. If an edge does not have that attribute, then the
|
| 74 |
+
value 1 is used instead.
|
| 75 |
+
|
| 76 |
+
nonedge : float, optional
|
| 77 |
+
The matrix values corresponding to nonedges are typically set to zero.
|
| 78 |
+
However, this could be undesirable if there are matrix values
|
| 79 |
+
corresponding to actual edges that also have the value zero. If so,
|
| 80 |
+
one might prefer nonedges to have some other value, such as nan.
|
| 81 |
+
|
| 82 |
+
Returns
|
| 83 |
+
-------
|
| 84 |
+
df : Pandas DataFrame
|
| 85 |
+
Graph adjacency matrix
|
| 86 |
+
|
| 87 |
+
Notes
|
| 88 |
+
-----
|
| 89 |
+
For directed graphs, entry i,j corresponds to an edge from i to j.
|
| 90 |
+
|
| 91 |
+
The DataFrame entries are assigned to the weight edge attribute. When
|
| 92 |
+
an edge does not have a weight attribute, the value of the entry is set to
|
| 93 |
+
the number 1. For multiple (parallel) edges, the values of the entries
|
| 94 |
+
are determined by the 'multigraph_weight' parameter. The default is to
|
| 95 |
+
sum the weight attributes for each of the parallel edges.
|
| 96 |
+
|
| 97 |
+
When `nodelist` does not contain every node in `G`, the matrix is built
|
| 98 |
+
from the subgraph of `G` that is induced by the nodes in `nodelist`.
|
| 99 |
+
|
| 100 |
+
The convention used for self-loop edges in graphs is to assign the
|
| 101 |
+
diagonal matrix entry value to the weight attribute of the edge
|
| 102 |
+
(or the number 1 if the edge has no weight attribute). If the
|
| 103 |
+
alternate convention of doubling the edge weight is desired the
|
| 104 |
+
resulting Pandas DataFrame can be modified as follows::
|
| 105 |
+
|
| 106 |
+
>>> import pandas as pd
|
| 107 |
+
>>> G = nx.Graph([(1, 1), (2, 2)])
|
| 108 |
+
>>> df = nx.to_pandas_adjacency(G)
|
| 109 |
+
>>> df
|
| 110 |
+
1 2
|
| 111 |
+
1 1.0 0.0
|
| 112 |
+
2 0.0 1.0
|
| 113 |
+
>>> diag_idx = list(range(len(df)))
|
| 114 |
+
>>> df.iloc[diag_idx, diag_idx] *= 2
|
| 115 |
+
>>> df
|
| 116 |
+
1 2
|
| 117 |
+
1 2.0 0.0
|
| 118 |
+
2 0.0 2.0
|
| 119 |
+
|
| 120 |
+
Examples
|
| 121 |
+
--------
|
| 122 |
+
>>> G = nx.MultiDiGraph()
|
| 123 |
+
>>> G.add_edge(0, 1, weight=2)
|
| 124 |
+
0
|
| 125 |
+
>>> G.add_edge(1, 0)
|
| 126 |
+
0
|
| 127 |
+
>>> G.add_edge(2, 2, weight=3)
|
| 128 |
+
0
|
| 129 |
+
>>> G.add_edge(2, 2)
|
| 130 |
+
1
|
| 131 |
+
>>> nx.to_pandas_adjacency(G, nodelist=[0, 1, 2], dtype=int)
|
| 132 |
+
0 1 2
|
| 133 |
+
0 0 2 0
|
| 134 |
+
1 1 0 0
|
| 135 |
+
2 0 0 4
|
| 136 |
+
|
| 137 |
+
"""
|
| 138 |
+
import pandas as pd
|
| 139 |
+
|
| 140 |
+
M = to_numpy_array(
|
| 141 |
+
G,
|
| 142 |
+
nodelist=nodelist,
|
| 143 |
+
dtype=dtype,
|
| 144 |
+
order=order,
|
| 145 |
+
multigraph_weight=multigraph_weight,
|
| 146 |
+
weight=weight,
|
| 147 |
+
nonedge=nonedge,
|
| 148 |
+
)
|
| 149 |
+
if nodelist is None:
|
| 150 |
+
nodelist = list(G)
|
| 151 |
+
return pd.DataFrame(data=M, index=nodelist, columns=nodelist)
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
@nx._dispatchable(graphs=None, returns_graph=True)
|
| 155 |
+
def from_pandas_adjacency(df, create_using=None):
|
| 156 |
+
r"""Returns a graph from Pandas DataFrame.
|
| 157 |
+
|
| 158 |
+
The Pandas DataFrame is interpreted as an adjacency matrix for the graph.
|
| 159 |
+
|
| 160 |
+
Parameters
|
| 161 |
+
----------
|
| 162 |
+
df : Pandas DataFrame
|
| 163 |
+
An adjacency matrix representation of a graph
|
| 164 |
+
|
| 165 |
+
create_using : NetworkX graph constructor, optional (default=nx.Graph)
|
| 166 |
+
Graph type to create. If graph instance, then cleared before populated.
|
| 167 |
+
|
| 168 |
+
Notes
|
| 169 |
+
-----
|
| 170 |
+
For directed graphs, explicitly mention create_using=nx.DiGraph,
|
| 171 |
+
and entry i,j of df corresponds to an edge from i to j.
|
| 172 |
+
|
| 173 |
+
If `df` has a single data type for each entry it will be converted to an
|
| 174 |
+
appropriate Python data type.
|
| 175 |
+
|
| 176 |
+
If you have node attributes stored in a separate dataframe `df_nodes`,
|
| 177 |
+
you can load those attributes to the graph `G` using the following code:
|
| 178 |
+
|
| 179 |
+
```
|
| 180 |
+
df_nodes = pd.DataFrame({"node_id": [1, 2, 3], "attribute1": ["A", "B", "C"]})
|
| 181 |
+
G.add_nodes_from((n, dict(d)) for n, d in df_nodes.iterrows())
|
| 182 |
+
```
|
| 183 |
+
|
| 184 |
+
If `df` has a user-specified compound data type the names
|
| 185 |
+
of the data fields will be used as attribute keys in the resulting
|
| 186 |
+
NetworkX graph.
|
| 187 |
+
|
| 188 |
+
See Also
|
| 189 |
+
--------
|
| 190 |
+
to_pandas_adjacency
|
| 191 |
+
|
| 192 |
+
Examples
|
| 193 |
+
--------
|
| 194 |
+
Simple integer weights on edges:
|
| 195 |
+
|
| 196 |
+
>>> import pandas as pd
|
| 197 |
+
>>> pd.options.display.max_columns = 20
|
| 198 |
+
>>> df = pd.DataFrame([[1, 1], [2, 1]])
|
| 199 |
+
>>> df
|
| 200 |
+
0 1
|
| 201 |
+
0 1 1
|
| 202 |
+
1 2 1
|
| 203 |
+
>>> G = nx.from_pandas_adjacency(df)
|
| 204 |
+
>>> G.name = "Graph from pandas adjacency matrix"
|
| 205 |
+
>>> print(G)
|
| 206 |
+
Graph named 'Graph from pandas adjacency matrix' with 2 nodes and 3 edges
|
| 207 |
+
"""
|
| 208 |
+
|
| 209 |
+
try:
|
| 210 |
+
df = df[df.index]
|
| 211 |
+
except Exception as err:
|
| 212 |
+
missing = list(set(df.index).difference(set(df.columns)))
|
| 213 |
+
msg = f"{missing} not in columns"
|
| 214 |
+
raise nx.NetworkXError("Columns must match Indices.", msg) from err
|
| 215 |
+
|
| 216 |
+
A = df.values
|
| 217 |
+
G = from_numpy_array(A, create_using=create_using, nodelist=df.columns)
|
| 218 |
+
|
| 219 |
+
return G
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
@nx._dispatchable(preserve_edge_attrs=True)
|
| 223 |
+
def to_pandas_edgelist(
|
| 224 |
+
G,
|
| 225 |
+
source="source",
|
| 226 |
+
target="target",
|
| 227 |
+
nodelist=None,
|
| 228 |
+
dtype=None,
|
| 229 |
+
edge_key=None,
|
| 230 |
+
):
|
| 231 |
+
"""Returns the graph edge list as a Pandas DataFrame.
|
| 232 |
+
|
| 233 |
+
Parameters
|
| 234 |
+
----------
|
| 235 |
+
G : graph
|
| 236 |
+
The NetworkX graph used to construct the Pandas DataFrame.
|
| 237 |
+
|
| 238 |
+
source : str or int, optional
|
| 239 |
+
A valid column name (string or integer) for the source nodes (for the
|
| 240 |
+
directed case).
|
| 241 |
+
|
| 242 |
+
target : str or int, optional
|
| 243 |
+
A valid column name (string or integer) for the target nodes (for the
|
| 244 |
+
directed case).
|
| 245 |
+
|
| 246 |
+
nodelist : list, optional
|
| 247 |
+
Use only nodes specified in nodelist
|
| 248 |
+
|
| 249 |
+
dtype : dtype, default None
|
| 250 |
+
Use to create the DataFrame. Data type to force.
|
| 251 |
+
Only a single dtype is allowed. If None, infer.
|
| 252 |
+
|
| 253 |
+
edge_key : str or int or None, optional (default=None)
|
| 254 |
+
A valid column name (string or integer) for the edge keys (for the
|
| 255 |
+
multigraph case). If None, edge keys are not stored in the DataFrame.
|
| 256 |
+
|
| 257 |
+
Returns
|
| 258 |
+
-------
|
| 259 |
+
df : Pandas DataFrame
|
| 260 |
+
Graph edge list
|
| 261 |
+
|
| 262 |
+
Examples
|
| 263 |
+
--------
|
| 264 |
+
>>> G = nx.Graph(
|
| 265 |
+
... [
|
| 266 |
+
... ("A", "B", {"cost": 1, "weight": 7}),
|
| 267 |
+
... ("C", "E", {"cost": 9, "weight": 10}),
|
| 268 |
+
... ]
|
| 269 |
+
... )
|
| 270 |
+
>>> df = nx.to_pandas_edgelist(G, nodelist=["A", "C"])
|
| 271 |
+
>>> df[["source", "target", "cost", "weight"]]
|
| 272 |
+
source target cost weight
|
| 273 |
+
0 A B 1 7
|
| 274 |
+
1 C E 9 10
|
| 275 |
+
|
| 276 |
+
>>> G = nx.MultiGraph([("A", "B", {"cost": 1}), ("A", "B", {"cost": 9})])
|
| 277 |
+
>>> df = nx.to_pandas_edgelist(G, nodelist=["A", "C"], edge_key="ekey")
|
| 278 |
+
>>> df[["source", "target", "cost", "ekey"]]
|
| 279 |
+
source target cost ekey
|
| 280 |
+
0 A B 1 0
|
| 281 |
+
1 A B 9 1
|
| 282 |
+
|
| 283 |
+
"""
|
| 284 |
+
import pandas as pd
|
| 285 |
+
|
| 286 |
+
if nodelist is None:
|
| 287 |
+
edgelist = G.edges(data=True)
|
| 288 |
+
else:
|
| 289 |
+
edgelist = G.edges(nodelist, data=True)
|
| 290 |
+
source_nodes = [s for s, _, _ in edgelist]
|
| 291 |
+
target_nodes = [t for _, t, _ in edgelist]
|
| 292 |
+
|
| 293 |
+
all_attrs = set().union(*(d.keys() for _, _, d in edgelist))
|
| 294 |
+
if source in all_attrs:
|
| 295 |
+
raise nx.NetworkXError(f"Source name {source!r} is an edge attr name")
|
| 296 |
+
if target in all_attrs:
|
| 297 |
+
raise nx.NetworkXError(f"Target name {target!r} is an edge attr name")
|
| 298 |
+
|
| 299 |
+
nan = float("nan")
|
| 300 |
+
edge_attr = {k: [d.get(k, nan) for _, _, d in edgelist] for k in all_attrs}
|
| 301 |
+
|
| 302 |
+
if G.is_multigraph() and edge_key is not None:
|
| 303 |
+
if edge_key in all_attrs:
|
| 304 |
+
raise nx.NetworkXError(f"Edge key name {edge_key!r} is an edge attr name")
|
| 305 |
+
edge_keys = [k for _, _, k in G.edges(keys=True)]
|
| 306 |
+
edgelistdict = {source: source_nodes, target: target_nodes, edge_key: edge_keys}
|
| 307 |
+
else:
|
| 308 |
+
edgelistdict = {source: source_nodes, target: target_nodes}
|
| 309 |
+
|
| 310 |
+
edgelistdict.update(edge_attr)
|
| 311 |
+
return pd.DataFrame(edgelistdict, dtype=dtype)
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
@nx._dispatchable(graphs=None, returns_graph=True)
|
| 315 |
+
def from_pandas_edgelist(
|
| 316 |
+
df,
|
| 317 |
+
source="source",
|
| 318 |
+
target="target",
|
| 319 |
+
edge_attr=None,
|
| 320 |
+
create_using=None,
|
| 321 |
+
edge_key=None,
|
| 322 |
+
):
|
| 323 |
+
"""Returns a graph from Pandas DataFrame containing an edge list.
|
| 324 |
+
|
| 325 |
+
The Pandas DataFrame should contain at least two columns of node names and
|
| 326 |
+
zero or more columns of edge attributes. Each row will be processed as one
|
| 327 |
+
edge instance.
|
| 328 |
+
|
| 329 |
+
Note: This function iterates over DataFrame.values, which is not
|
| 330 |
+
guaranteed to retain the data type across columns in the row. This is only
|
| 331 |
+
a problem if your row is entirely numeric and a mix of ints and floats. In
|
| 332 |
+
that case, all values will be returned as floats. See the
|
| 333 |
+
DataFrame.iterrows documentation for an example.
|
| 334 |
+
|
| 335 |
+
Parameters
|
| 336 |
+
----------
|
| 337 |
+
df : Pandas DataFrame
|
| 338 |
+
An edge list representation of a graph
|
| 339 |
+
|
| 340 |
+
source : str or int
|
| 341 |
+
A valid column name (string or integer) for the source nodes (for the
|
| 342 |
+
directed case).
|
| 343 |
+
|
| 344 |
+
target : str or int
|
| 345 |
+
A valid column name (string or integer) for the target nodes (for the
|
| 346 |
+
directed case).
|
| 347 |
+
|
| 348 |
+
edge_attr : str or int, iterable, True, or None
|
| 349 |
+
A valid column name (str or int) or iterable of column names that are
|
| 350 |
+
used to retrieve items and add them to the graph as edge attributes.
|
| 351 |
+
If `True`, all columns will be added except `source`, `target` and `edge_key`.
|
| 352 |
+
If `None`, no edge attributes are added to the graph.
|
| 353 |
+
|
| 354 |
+
create_using : NetworkX graph constructor, optional (default=nx.Graph)
|
| 355 |
+
Graph type to create. If graph instance, then cleared before populated.
|
| 356 |
+
|
| 357 |
+
edge_key : str or None, optional (default=None)
|
| 358 |
+
A valid column name for the edge keys (for a MultiGraph). The values in
|
| 359 |
+
this column are used for the edge keys when adding edges if create_using
|
| 360 |
+
is a multigraph.
|
| 361 |
+
|
| 362 |
+
If you have node attributes stored in a separate dataframe `df_nodes`,
|
| 363 |
+
you can load those attributes to the graph `G` using the following code:
|
| 364 |
+
|
| 365 |
+
```
|
| 366 |
+
df_nodes = pd.DataFrame({"node_id": [1, 2, 3], "attribute1": ["A", "B", "C"]})
|
| 367 |
+
G.add_nodes_from((n, dict(d)) for n, d in df_nodes.iterrows())
|
| 368 |
+
```
|
| 369 |
+
|
| 370 |
+
See Also
|
| 371 |
+
--------
|
| 372 |
+
to_pandas_edgelist
|
| 373 |
+
|
| 374 |
+
Examples
|
| 375 |
+
--------
|
| 376 |
+
Simple integer weights on edges:
|
| 377 |
+
|
| 378 |
+
>>> import pandas as pd
|
| 379 |
+
>>> pd.options.display.max_columns = 20
|
| 380 |
+
>>> import numpy as np
|
| 381 |
+
>>> rng = np.random.RandomState(seed=5)
|
| 382 |
+
>>> ints = rng.randint(1, 11, size=(3, 2))
|
| 383 |
+
>>> a = ["A", "B", "C"]
|
| 384 |
+
>>> b = ["D", "A", "E"]
|
| 385 |
+
>>> df = pd.DataFrame(ints, columns=["weight", "cost"])
|
| 386 |
+
>>> df[0] = a
|
| 387 |
+
>>> df["b"] = b
|
| 388 |
+
>>> df[["weight", "cost", 0, "b"]]
|
| 389 |
+
weight cost 0 b
|
| 390 |
+
0 4 7 A D
|
| 391 |
+
1 7 1 B A
|
| 392 |
+
2 10 9 C E
|
| 393 |
+
>>> G = nx.from_pandas_edgelist(df, 0, "b", ["weight", "cost"])
|
| 394 |
+
>>> G["E"]["C"]["weight"]
|
| 395 |
+
10
|
| 396 |
+
>>> G["E"]["C"]["cost"]
|
| 397 |
+
9
|
| 398 |
+
>>> edges = pd.DataFrame(
|
| 399 |
+
... {
|
| 400 |
+
... "source": [0, 1, 2],
|
| 401 |
+
... "target": [2, 2, 3],
|
| 402 |
+
... "weight": [3, 4, 5],
|
| 403 |
+
... "color": ["red", "blue", "blue"],
|
| 404 |
+
... }
|
| 405 |
+
... )
|
| 406 |
+
>>> G = nx.from_pandas_edgelist(edges, edge_attr=True)
|
| 407 |
+
>>> G[0][2]["color"]
|
| 408 |
+
'red'
|
| 409 |
+
|
| 410 |
+
Build multigraph with custom keys:
|
| 411 |
+
|
| 412 |
+
>>> edges = pd.DataFrame(
|
| 413 |
+
... {
|
| 414 |
+
... "source": [0, 1, 2, 0],
|
| 415 |
+
... "target": [2, 2, 3, 2],
|
| 416 |
+
... "my_edge_key": ["A", "B", "C", "D"],
|
| 417 |
+
... "weight": [3, 4, 5, 6],
|
| 418 |
+
... "color": ["red", "blue", "blue", "blue"],
|
| 419 |
+
... }
|
| 420 |
+
... )
|
| 421 |
+
>>> G = nx.from_pandas_edgelist(
|
| 422 |
+
... edges,
|
| 423 |
+
... edge_key="my_edge_key",
|
| 424 |
+
... edge_attr=["weight", "color"],
|
| 425 |
+
... create_using=nx.MultiGraph(),
|
| 426 |
+
... )
|
| 427 |
+
>>> G[0][2]
|
| 428 |
+
AtlasView({'A': {'weight': 3, 'color': 'red'}, 'D': {'weight': 6, 'color': 'blue'}})
|
| 429 |
+
|
| 430 |
+
|
| 431 |
+
"""
|
| 432 |
+
g = nx.empty_graph(0, create_using)
|
| 433 |
+
|
| 434 |
+
if edge_attr is None:
|
| 435 |
+
if g.is_multigraph() and edge_key is not None:
|
| 436 |
+
for u, v, k in zip(df[source], df[target], df[edge_key]):
|
| 437 |
+
g.add_edge(u, v, k)
|
| 438 |
+
else:
|
| 439 |
+
g.add_edges_from(zip(df[source], df[target]))
|
| 440 |
+
return g
|
| 441 |
+
|
| 442 |
+
reserved_columns = [source, target]
|
| 443 |
+
if g.is_multigraph() and edge_key is not None:
|
| 444 |
+
reserved_columns.append(edge_key)
|
| 445 |
+
|
| 446 |
+
# Additional columns requested
|
| 447 |
+
attr_col_headings = []
|
| 448 |
+
attribute_data = []
|
| 449 |
+
if edge_attr is True:
|
| 450 |
+
attr_col_headings = [c for c in df.columns if c not in reserved_columns]
|
| 451 |
+
elif isinstance(edge_attr, list | tuple):
|
| 452 |
+
attr_col_headings = edge_attr
|
| 453 |
+
else:
|
| 454 |
+
attr_col_headings = [edge_attr]
|
| 455 |
+
if len(attr_col_headings) == 0:
|
| 456 |
+
raise nx.NetworkXError(
|
| 457 |
+
f"Invalid edge_attr argument: No columns found with name: {attr_col_headings}"
|
| 458 |
+
)
|
| 459 |
+
|
| 460 |
+
try:
|
| 461 |
+
attribute_data = zip(*[df[col] for col in attr_col_headings])
|
| 462 |
+
except (KeyError, TypeError) as err:
|
| 463 |
+
msg = f"Invalid edge_attr argument: {edge_attr}"
|
| 464 |
+
raise nx.NetworkXError(msg) from err
|
| 465 |
+
|
| 466 |
+
if g.is_multigraph():
|
| 467 |
+
# => append the edge keys from the df to the bundled data
|
| 468 |
+
if edge_key is not None:
|
| 469 |
+
try:
|
| 470 |
+
multigraph_edge_keys = df[edge_key]
|
| 471 |
+
attribute_data = zip(attribute_data, multigraph_edge_keys)
|
| 472 |
+
except (KeyError, TypeError) as err:
|
| 473 |
+
msg = f"Invalid edge_key argument: {edge_key}"
|
| 474 |
+
raise nx.NetworkXError(msg) from err
|
| 475 |
+
|
| 476 |
+
for s, t, attrs in zip(df[source], df[target], attribute_data):
|
| 477 |
+
if edge_key is not None:
|
| 478 |
+
attrs, multigraph_edge_key = attrs
|
| 479 |
+
key = g.add_edge(s, t, key=multigraph_edge_key)
|
| 480 |
+
else:
|
| 481 |
+
key = g.add_edge(s, t)
|
| 482 |
+
|
| 483 |
+
g[s][t][key].update(zip(attr_col_headings, attrs))
|
| 484 |
+
else:
|
| 485 |
+
for s, t, attrs in zip(df[source], df[target], attribute_data):
|
| 486 |
+
g.add_edge(s, t)
|
| 487 |
+
g[s][t].update(zip(attr_col_headings, attrs))
|
| 488 |
+
|
| 489 |
+
return g
|
| 490 |
+
|
| 491 |
+
|
| 492 |
+
@nx._dispatchable(edge_attrs="weight")
|
| 493 |
+
def to_scipy_sparse_array(G, nodelist=None, dtype=None, weight="weight", format="csr"):
|
| 494 |
+
"""Returns the graph adjacency matrix as a SciPy sparse array.
|
| 495 |
+
|
| 496 |
+
Parameters
|
| 497 |
+
----------
|
| 498 |
+
G : graph
|
| 499 |
+
The NetworkX graph used to construct the sparse array.
|
| 500 |
+
|
| 501 |
+
nodelist : list, optional
|
| 502 |
+
The rows and columns are ordered according to the nodes in `nodelist`.
|
| 503 |
+
If `nodelist` is None, then the ordering is produced by ``G.nodes()``.
|
| 504 |
+
|
| 505 |
+
dtype : NumPy data-type, optional
|
| 506 |
+
A valid NumPy dtype used to initialize the array. If None, then the
|
| 507 |
+
NumPy default is used.
|
| 508 |
+
|
| 509 |
+
weight : string or None, optional (default='weight')
|
| 510 |
+
The edge attribute that holds the numerical value used for
|
| 511 |
+
the edge weight. If None then all edge weights are 1.
|
| 512 |
+
|
| 513 |
+
format : str in {'bsr', 'csr', 'csc', 'coo', 'lil', 'dia', 'dok'}
|
| 514 |
+
The format of the sparse array to be returned (default 'csr'). For
|
| 515 |
+
some algorithms different implementations of sparse arrays
|
| 516 |
+
can perform better. See [1]_ for details.
|
| 517 |
+
|
| 518 |
+
Returns
|
| 519 |
+
-------
|
| 520 |
+
A : SciPy sparse array
|
| 521 |
+
Graph adjacency matrix.
|
| 522 |
+
|
| 523 |
+
Notes
|
| 524 |
+
-----
|
| 525 |
+
For directed graphs, matrix entry ``i, j`` corresponds to an edge from
|
| 526 |
+
``i`` to ``j``.
|
| 527 |
+
|
| 528 |
+
The values of the adjacency matrix are populated using the edge attribute held in
|
| 529 |
+
parameter `weight`. When an edge does not have that attribute, the
|
| 530 |
+
value of the entry is 1.
|
| 531 |
+
|
| 532 |
+
For multiple edges the matrix values are the sums of the edge weights.
|
| 533 |
+
|
| 534 |
+
When `nodelist` does not contain every node in `G`, the adjacency matrix
|
| 535 |
+
is built from the subgraph of `G` that is induced by the nodes in
|
| 536 |
+
`nodelist`.
|
| 537 |
+
|
| 538 |
+
The convention used for self-loop edges in graphs is to assign the
|
| 539 |
+
diagonal matrix entry value to the weight attribute of the edge
|
| 540 |
+
(or the number 1 if the edge has no weight attribute). If the
|
| 541 |
+
alternate convention of doubling the edge weight is desired the
|
| 542 |
+
resulting array can be modified as follows::
|
| 543 |
+
|
| 544 |
+
>>> G = nx.Graph([(1, 1)])
|
| 545 |
+
>>> A = nx.to_scipy_sparse_array(G)
|
| 546 |
+
>>> A.toarray()
|
| 547 |
+
array([[1]])
|
| 548 |
+
>>> A.setdiag(A.diagonal() * 2)
|
| 549 |
+
>>> A.toarray()
|
| 550 |
+
array([[2]])
|
| 551 |
+
|
| 552 |
+
Examples
|
| 553 |
+
--------
|
| 554 |
+
|
| 555 |
+
Basic usage:
|
| 556 |
+
|
| 557 |
+
>>> G = nx.path_graph(4)
|
| 558 |
+
>>> A = nx.to_scipy_sparse_array(G)
|
| 559 |
+
>>> A # doctest: +SKIP
|
| 560 |
+
<Compressed Sparse Row sparse array of dtype 'int64'
|
| 561 |
+
with 6 stored elements and shape (4, 4)>
|
| 562 |
+
|
| 563 |
+
>>> A.toarray()
|
| 564 |
+
array([[0, 1, 0, 0],
|
| 565 |
+
[1, 0, 1, 0],
|
| 566 |
+
[0, 1, 0, 1],
|
| 567 |
+
[0, 0, 1, 0]])
|
| 568 |
+
|
| 569 |
+
.. note:: The `toarray` method is used in these examples to better visualize
|
| 570 |
+
the adjacancy matrix. For a dense representation of the adjaceny matrix,
|
| 571 |
+
use `to_numpy_array` instead.
|
| 572 |
+
|
| 573 |
+
Directed graphs:
|
| 574 |
+
|
| 575 |
+
>>> G = nx.DiGraph([(0, 1), (1, 2), (2, 3)])
|
| 576 |
+
>>> nx.to_scipy_sparse_array(G).toarray()
|
| 577 |
+
array([[0, 1, 0, 0],
|
| 578 |
+
[0, 0, 1, 0],
|
| 579 |
+
[0, 0, 0, 1],
|
| 580 |
+
[0, 0, 0, 0]])
|
| 581 |
+
|
| 582 |
+
>>> H = G.reverse()
|
| 583 |
+
>>> H.edges
|
| 584 |
+
OutEdgeView([(1, 0), (2, 1), (3, 2)])
|
| 585 |
+
>>> nx.to_scipy_sparse_array(H).toarray()
|
| 586 |
+
array([[0, 0, 0, 0],
|
| 587 |
+
[1, 0, 0, 0],
|
| 588 |
+
[0, 1, 0, 0],
|
| 589 |
+
[0, 0, 1, 0]])
|
| 590 |
+
|
| 591 |
+
By default, the order of the rows/columns of the adjacency matrix is determined
|
| 592 |
+
by the ordering of the nodes in `G`:
|
| 593 |
+
|
| 594 |
+
>>> G = nx.Graph()
|
| 595 |
+
>>> G.add_nodes_from([3, 5, 0, 1])
|
| 596 |
+
>>> G.add_edges_from([(1, 3), (1, 5)])
|
| 597 |
+
>>> nx.to_scipy_sparse_array(G).toarray()
|
| 598 |
+
array([[0, 0, 0, 1],
|
| 599 |
+
[0, 0, 0, 1],
|
| 600 |
+
[0, 0, 0, 0],
|
| 601 |
+
[1, 1, 0, 0]])
|
| 602 |
+
|
| 603 |
+
The ordering of the rows can be changed with `nodelist`:
|
| 604 |
+
|
| 605 |
+
>>> ordered = [0, 1, 3, 5]
|
| 606 |
+
>>> nx.to_scipy_sparse_array(G, nodelist=ordered).toarray()
|
| 607 |
+
array([[0, 0, 0, 0],
|
| 608 |
+
[0, 0, 1, 1],
|
| 609 |
+
[0, 1, 0, 0],
|
| 610 |
+
[0, 1, 0, 0]])
|
| 611 |
+
|
| 612 |
+
If `nodelist` contains a subset of the nodes in `G`, the adjacency matrix
|
| 613 |
+
for the node-induced subgraph is produced:
|
| 614 |
+
|
| 615 |
+
>>> nx.to_scipy_sparse_array(G, nodelist=[1, 3, 5]).toarray()
|
| 616 |
+
array([[0, 1, 1],
|
| 617 |
+
[1, 0, 0],
|
| 618 |
+
[1, 0, 0]])
|
| 619 |
+
|
| 620 |
+
The values of the adjacency matrix are drawn from the edge attribute
|
| 621 |
+
specified by the `weight` parameter:
|
| 622 |
+
|
| 623 |
+
>>> G = nx.path_graph(4)
|
| 624 |
+
>>> nx.set_edge_attributes(
|
| 625 |
+
... G, values={(0, 1): 1, (1, 2): 10, (2, 3): 2}, name="weight"
|
| 626 |
+
... )
|
| 627 |
+
>>> nx.set_edge_attributes(
|
| 628 |
+
... G, values={(0, 1): 50, (1, 2): 35, (2, 3): 10}, name="capacity"
|
| 629 |
+
... )
|
| 630 |
+
>>> nx.to_scipy_sparse_array(G).toarray() # Default weight="weight"
|
| 631 |
+
array([[ 0, 1, 0, 0],
|
| 632 |
+
[ 1, 0, 10, 0],
|
| 633 |
+
[ 0, 10, 0, 2],
|
| 634 |
+
[ 0, 0, 2, 0]])
|
| 635 |
+
>>> nx.to_scipy_sparse_array(G, weight="capacity").toarray()
|
| 636 |
+
array([[ 0, 50, 0, 0],
|
| 637 |
+
[50, 0, 35, 0],
|
| 638 |
+
[ 0, 35, 0, 10],
|
| 639 |
+
[ 0, 0, 10, 0]])
|
| 640 |
+
|
| 641 |
+
Any edges that don't have a `weight` attribute default to 1:
|
| 642 |
+
|
| 643 |
+
>>> G[1][2].pop("capacity")
|
| 644 |
+
35
|
| 645 |
+
>>> nx.to_scipy_sparse_array(G, weight="capacity").toarray()
|
| 646 |
+
array([[ 0, 50, 0, 0],
|
| 647 |
+
[50, 0, 1, 0],
|
| 648 |
+
[ 0, 1, 0, 10],
|
| 649 |
+
[ 0, 0, 10, 0]])
|
| 650 |
+
|
| 651 |
+
When `G` is a multigraph, the values in the adjacency matrix are given by
|
| 652 |
+
the sum of the `weight` edge attribute over each edge key:
|
| 653 |
+
|
| 654 |
+
>>> G = nx.MultiDiGraph([(0, 1), (0, 1), (0, 1), (2, 0)])
|
| 655 |
+
>>> nx.to_scipy_sparse_array(G).toarray()
|
| 656 |
+
array([[0, 3, 0],
|
| 657 |
+
[0, 0, 0],
|
| 658 |
+
[1, 0, 0]])
|
| 659 |
+
|
| 660 |
+
References
|
| 661 |
+
----------
|
| 662 |
+
.. [1] Scipy Dev. References, "Sparse Arrays",
|
| 663 |
+
https://docs.scipy.org/doc/scipy/reference/sparse.html
|
| 664 |
+
"""
|
| 665 |
+
import scipy as sp
|
| 666 |
+
|
| 667 |
+
if len(G) == 0:
|
| 668 |
+
raise nx.NetworkXError("Graph has no nodes or edges")
|
| 669 |
+
|
| 670 |
+
if nodelist is None:
|
| 671 |
+
nodelist = list(G)
|
| 672 |
+
nlen = len(G)
|
| 673 |
+
else:
|
| 674 |
+
nlen = len(nodelist)
|
| 675 |
+
if nlen == 0:
|
| 676 |
+
raise nx.NetworkXError("nodelist has no nodes")
|
| 677 |
+
nodeset = set(G.nbunch_iter(nodelist))
|
| 678 |
+
if nlen != len(nodeset):
|
| 679 |
+
for n in nodelist:
|
| 680 |
+
if n not in G:
|
| 681 |
+
raise nx.NetworkXError(f"Node {n} in nodelist is not in G")
|
| 682 |
+
raise nx.NetworkXError("nodelist contains duplicates.")
|
| 683 |
+
if nlen < len(G):
|
| 684 |
+
G = G.subgraph(nodelist)
|
| 685 |
+
|
| 686 |
+
index = dict(zip(nodelist, range(nlen)))
|
| 687 |
+
coefficients = zip(
|
| 688 |
+
*((index[u], index[v], wt) for u, v, wt in G.edges(data=weight, default=1))
|
| 689 |
+
)
|
| 690 |
+
try:
|
| 691 |
+
row, col, data = coefficients
|
| 692 |
+
except ValueError:
|
| 693 |
+
# there is no edge in the subgraph
|
| 694 |
+
row, col, data = [], [], []
|
| 695 |
+
|
| 696 |
+
if G.is_directed():
|
| 697 |
+
A = sp.sparse.coo_array((data, (row, col)), shape=(nlen, nlen), dtype=dtype)
|
| 698 |
+
else:
|
| 699 |
+
# symmetrize matrix
|
| 700 |
+
d = data + data
|
| 701 |
+
r = row + col
|
| 702 |
+
c = col + row
|
| 703 |
+
# selfloop entries get double counted when symmetrizing
|
| 704 |
+
# so we subtract the data on the diagonal
|
| 705 |
+
selfloops = list(nx.selfloop_edges(G, data=weight, default=1))
|
| 706 |
+
if selfloops:
|
| 707 |
+
diag_index, diag_data = zip(*((index[u], -wt) for u, v, wt in selfloops))
|
| 708 |
+
d += diag_data
|
| 709 |
+
r += diag_index
|
| 710 |
+
c += diag_index
|
| 711 |
+
A = sp.sparse.coo_array((d, (r, c)), shape=(nlen, nlen), dtype=dtype)
|
| 712 |
+
try:
|
| 713 |
+
return A.asformat(format)
|
| 714 |
+
except ValueError as err:
|
| 715 |
+
raise nx.NetworkXError(f"Unknown sparse matrix format: {format}") from err
|
| 716 |
+
|
| 717 |
+
|
| 718 |
+
def _csr_gen_triples(A):
|
| 719 |
+
"""Converts a SciPy sparse array in **Compressed Sparse Row** format to
|
| 720 |
+
an iterable of weighted edge triples.
|
| 721 |
+
|
| 722 |
+
"""
|
| 723 |
+
nrows = A.shape[0]
|
| 724 |
+
indptr, dst_indices, data = A.indptr, A.indices, A.data
|
| 725 |
+
import numpy as np
|
| 726 |
+
|
| 727 |
+
src_indices = np.repeat(np.arange(nrows), np.diff(indptr))
|
| 728 |
+
return zip(src_indices.tolist(), dst_indices.tolist(), A.data.tolist())
|
| 729 |
+
|
| 730 |
+
|
| 731 |
+
def _csc_gen_triples(A):
|
| 732 |
+
"""Converts a SciPy sparse array in **Compressed Sparse Column** format to
|
| 733 |
+
an iterable of weighted edge triples.
|
| 734 |
+
|
| 735 |
+
"""
|
| 736 |
+
ncols = A.shape[1]
|
| 737 |
+
indptr, src_indices, data = A.indptr, A.indices, A.data
|
| 738 |
+
import numpy as np
|
| 739 |
+
|
| 740 |
+
dst_indices = np.repeat(np.arange(ncols), np.diff(indptr))
|
| 741 |
+
return zip(src_indices.tolist(), dst_indices.tolist(), A.data.tolist())
|
| 742 |
+
|
| 743 |
+
|
| 744 |
+
def _coo_gen_triples(A):
|
| 745 |
+
"""Converts a SciPy sparse array in **Coordinate** format to an iterable
|
| 746 |
+
of weighted edge triples.
|
| 747 |
+
|
| 748 |
+
"""
|
| 749 |
+
return zip(A.row.tolist(), A.col.tolist(), A.data.tolist())
|
| 750 |
+
|
| 751 |
+
|
| 752 |
+
def _dok_gen_triples(A):
|
| 753 |
+
"""Converts a SciPy sparse array in **Dictionary of Keys** format to an
|
| 754 |
+
iterable of weighted edge triples.
|
| 755 |
+
|
| 756 |
+
"""
|
| 757 |
+
for (r, c), v in A.items():
|
| 758 |
+
# Use `v.item()` to convert a NumPy scalar to the appropriate Python scalar
|
| 759 |
+
yield int(r), int(c), v.item()
|
| 760 |
+
|
| 761 |
+
|
| 762 |
+
def _generate_weighted_edges(A):
|
| 763 |
+
"""Returns an iterable over (u, v, w) triples, where u and v are adjacent
|
| 764 |
+
vertices and w is the weight of the edge joining u and v.
|
| 765 |
+
|
| 766 |
+
`A` is a SciPy sparse array (in any format).
|
| 767 |
+
|
| 768 |
+
"""
|
| 769 |
+
if A.format == "csr":
|
| 770 |
+
return _csr_gen_triples(A)
|
| 771 |
+
if A.format == "csc":
|
| 772 |
+
return _csc_gen_triples(A)
|
| 773 |
+
if A.format == "dok":
|
| 774 |
+
return _dok_gen_triples(A)
|
| 775 |
+
# If A is in any other format (including COO), convert it to COO format.
|
| 776 |
+
return _coo_gen_triples(A.tocoo())
|
| 777 |
+
|
| 778 |
+
|
| 779 |
+
@nx._dispatchable(graphs=None, returns_graph=True)
|
| 780 |
+
def from_scipy_sparse_array(
|
| 781 |
+
A, parallel_edges=False, create_using=None, edge_attribute="weight"
|
| 782 |
+
):
|
| 783 |
+
"""Creates a new graph from an adjacency matrix given as a SciPy sparse
|
| 784 |
+
array.
|
| 785 |
+
|
| 786 |
+
Parameters
|
| 787 |
+
----------
|
| 788 |
+
A: scipy.sparse array
|
| 789 |
+
An adjacency matrix representation of a graph
|
| 790 |
+
|
| 791 |
+
parallel_edges : Boolean
|
| 792 |
+
If this is True, `create_using` is a multigraph, and `A` is an
|
| 793 |
+
integer matrix, then entry *(i, j)* in the matrix is interpreted as the
|
| 794 |
+
number of parallel edges joining vertices *i* and *j* in the graph.
|
| 795 |
+
If it is False, then the entries in the matrix are interpreted as
|
| 796 |
+
the weight of a single edge joining the vertices.
|
| 797 |
+
|
| 798 |
+
create_using : NetworkX graph constructor, optional (default=nx.Graph)
|
| 799 |
+
Graph type to create. If graph instance, then cleared before populated.
|
| 800 |
+
|
| 801 |
+
edge_attribute: string
|
| 802 |
+
Name of edge attribute to store matrix numeric value. The data will
|
| 803 |
+
have the same type as the matrix entry (int, float, (real,imag)).
|
| 804 |
+
|
| 805 |
+
Notes
|
| 806 |
+
-----
|
| 807 |
+
For directed graphs, explicitly mention create_using=nx.DiGraph,
|
| 808 |
+
and entry i,j of A corresponds to an edge from i to j.
|
| 809 |
+
|
| 810 |
+
If `create_using` is :class:`networkx.MultiGraph` or
|
| 811 |
+
:class:`networkx.MultiDiGraph`, `parallel_edges` is True, and the
|
| 812 |
+
entries of `A` are of type :class:`int`, then this function returns a
|
| 813 |
+
multigraph (constructed from `create_using`) with parallel edges.
|
| 814 |
+
In this case, `edge_attribute` will be ignored.
|
| 815 |
+
|
| 816 |
+
If `create_using` indicates an undirected multigraph, then only the edges
|
| 817 |
+
indicated by the upper triangle of the matrix `A` will be added to the
|
| 818 |
+
graph.
|
| 819 |
+
|
| 820 |
+
Examples
|
| 821 |
+
--------
|
| 822 |
+
>>> import scipy as sp
|
| 823 |
+
>>> A = sp.sparse.eye(2, 2, 1)
|
| 824 |
+
>>> G = nx.from_scipy_sparse_array(A)
|
| 825 |
+
|
| 826 |
+
If `create_using` indicates a multigraph and the matrix has only integer
|
| 827 |
+
entries and `parallel_edges` is False, then the entries will be treated
|
| 828 |
+
as weights for edges joining the nodes (without creating parallel edges):
|
| 829 |
+
|
| 830 |
+
>>> A = sp.sparse.csr_array([[1, 1], [1, 2]])
|
| 831 |
+
>>> G = nx.from_scipy_sparse_array(A, create_using=nx.MultiGraph)
|
| 832 |
+
>>> G[1][1]
|
| 833 |
+
AtlasView({0: {'weight': 2}})
|
| 834 |
+
|
| 835 |
+
If `create_using` indicates a multigraph and the matrix has only integer
|
| 836 |
+
entries and `parallel_edges` is True, then the entries will be treated
|
| 837 |
+
as the number of parallel edges joining those two vertices:
|
| 838 |
+
|
| 839 |
+
>>> A = sp.sparse.csr_array([[1, 1], [1, 2]])
|
| 840 |
+
>>> G = nx.from_scipy_sparse_array(
|
| 841 |
+
... A, parallel_edges=True, create_using=nx.MultiGraph
|
| 842 |
+
... )
|
| 843 |
+
>>> G[1][1]
|
| 844 |
+
AtlasView({0: {'weight': 1}, 1: {'weight': 1}})
|
| 845 |
+
|
| 846 |
+
"""
|
| 847 |
+
G = nx.empty_graph(0, create_using)
|
| 848 |
+
n, m = A.shape
|
| 849 |
+
if n != m:
|
| 850 |
+
raise nx.NetworkXError(f"Adjacency matrix not square: nx,ny={A.shape}")
|
| 851 |
+
# Make sure we get even the isolated nodes of the graph.
|
| 852 |
+
G.add_nodes_from(range(n))
|
| 853 |
+
# Create an iterable over (u, v, w) triples and for each triple, add an
|
| 854 |
+
# edge from u to v with weight w.
|
| 855 |
+
triples = _generate_weighted_edges(A)
|
| 856 |
+
# If the entries in the adjacency matrix are integers, the graph is a
|
| 857 |
+
# multigraph, and parallel_edges is True, then create parallel edges, each
|
| 858 |
+
# with weight 1, for each entry in the adjacency matrix. Otherwise, create
|
| 859 |
+
# one edge for each positive entry in the adjacency matrix and set the
|
| 860 |
+
# weight of that edge to be the entry in the matrix.
|
| 861 |
+
if A.dtype.kind in ("i", "u") and G.is_multigraph() and parallel_edges:
|
| 862 |
+
chain = itertools.chain.from_iterable
|
| 863 |
+
# The following line is equivalent to:
|
| 864 |
+
#
|
| 865 |
+
# for (u, v) in edges:
|
| 866 |
+
# for d in range(A[u, v]):
|
| 867 |
+
# G.add_edge(u, v, weight=1)
|
| 868 |
+
#
|
| 869 |
+
triples = chain(((u, v, 1) for d in range(w)) for (u, v, w) in triples)
|
| 870 |
+
# If we are creating an undirected multigraph, only add the edges from the
|
| 871 |
+
# upper triangle of the matrix. Otherwise, add all the edges. This relies
|
| 872 |
+
# on the fact that the vertices created in the
|
| 873 |
+
# `_generated_weighted_edges()` function are actually the row/column
|
| 874 |
+
# indices for the matrix `A`.
|
| 875 |
+
#
|
| 876 |
+
# Without this check, we run into a problem where each edge is added twice
|
| 877 |
+
# when `G.add_weighted_edges_from()` is invoked below.
|
| 878 |
+
if G.is_multigraph() and not G.is_directed():
|
| 879 |
+
triples = ((u, v, d) for u, v, d in triples if u <= v)
|
| 880 |
+
G.add_weighted_edges_from(triples, weight=edge_attribute)
|
| 881 |
+
return G
|
| 882 |
+
|
| 883 |
+
|
| 884 |
+
@nx._dispatchable(edge_attrs="weight") # edge attrs may also be obtained from `dtype`
|
| 885 |
+
def to_numpy_array(
|
| 886 |
+
G,
|
| 887 |
+
nodelist=None,
|
| 888 |
+
dtype=None,
|
| 889 |
+
order=None,
|
| 890 |
+
multigraph_weight=sum,
|
| 891 |
+
weight="weight",
|
| 892 |
+
nonedge=0.0,
|
| 893 |
+
):
|
| 894 |
+
"""Returns the graph adjacency matrix as a NumPy array.
|
| 895 |
+
|
| 896 |
+
Parameters
|
| 897 |
+
----------
|
| 898 |
+
G : graph
|
| 899 |
+
The NetworkX graph used to construct the NumPy array.
|
| 900 |
+
|
| 901 |
+
nodelist : list, optional
|
| 902 |
+
The rows and columns are ordered according to the nodes in `nodelist`.
|
| 903 |
+
If `nodelist` is ``None``, then the ordering is produced by ``G.nodes()``.
|
| 904 |
+
|
| 905 |
+
dtype : NumPy data type, optional
|
| 906 |
+
A NumPy data type used to initialize the array. If None, then the NumPy
|
| 907 |
+
default is used. The dtype can be structured if `weight=None`, in which
|
| 908 |
+
case the dtype field names are used to look up edge attributes. The
|
| 909 |
+
result is a structured array where each named field in the dtype
|
| 910 |
+
corresponds to the adjacency for that edge attribute. See examples for
|
| 911 |
+
details.
|
| 912 |
+
|
| 913 |
+
order : {'C', 'F'}, optional
|
| 914 |
+
Whether to store multidimensional data in C- or Fortran-contiguous
|
| 915 |
+
(row- or column-wise) order in memory. If None, then the NumPy default
|
| 916 |
+
is used.
|
| 917 |
+
|
| 918 |
+
multigraph_weight : callable, optional
|
| 919 |
+
An function that determines how weights in multigraphs are handled.
|
| 920 |
+
The function should accept a sequence of weights and return a single
|
| 921 |
+
value. The default is to sum the weights of the multiple edges.
|
| 922 |
+
|
| 923 |
+
weight : string or None optional (default = 'weight')
|
| 924 |
+
The edge attribute that holds the numerical value used for
|
| 925 |
+
the edge weight. If an edge does not have that attribute, then the
|
| 926 |
+
value 1 is used instead. `weight` must be ``None`` if a structured
|
| 927 |
+
dtype is used.
|
| 928 |
+
|
| 929 |
+
nonedge : array_like (default = 0.0)
|
| 930 |
+
The value used to represent non-edges in the adjacency matrix.
|
| 931 |
+
The array values corresponding to nonedges are typically set to zero.
|
| 932 |
+
However, this could be undesirable if there are array values
|
| 933 |
+
corresponding to actual edges that also have the value zero. If so,
|
| 934 |
+
one might prefer nonedges to have some other value, such as ``nan``.
|
| 935 |
+
|
| 936 |
+
Returns
|
| 937 |
+
-------
|
| 938 |
+
A : NumPy ndarray
|
| 939 |
+
Graph adjacency matrix
|
| 940 |
+
|
| 941 |
+
Raises
|
| 942 |
+
------
|
| 943 |
+
NetworkXError
|
| 944 |
+
If `dtype` is a structured dtype and `G` is a multigraph
|
| 945 |
+
ValueError
|
| 946 |
+
If `dtype` is a structured dtype and `weight` is not `None`
|
| 947 |
+
|
| 948 |
+
See Also
|
| 949 |
+
--------
|
| 950 |
+
from_numpy_array
|
| 951 |
+
|
| 952 |
+
Notes
|
| 953 |
+
-----
|
| 954 |
+
For directed graphs, entry ``i, j`` corresponds to an edge from ``i`` to ``j``.
|
| 955 |
+
|
| 956 |
+
Entries in the adjacency matrix are given by the `weight` edge attribute.
|
| 957 |
+
When an edge does not have a weight attribute, the value of the entry is
|
| 958 |
+
set to the number 1. For multiple (parallel) edges, the values of the
|
| 959 |
+
entries are determined by the `multigraph_weight` parameter. The default is
|
| 960 |
+
to sum the weight attributes for each of the parallel edges.
|
| 961 |
+
|
| 962 |
+
When `nodelist` does not contain every node in `G`, the adjacency matrix is
|
| 963 |
+
built from the subgraph of `G` that is induced by the nodes in `nodelist`.
|
| 964 |
+
|
| 965 |
+
The convention used for self-loop edges in graphs is to assign the
|
| 966 |
+
diagonal array entry value to the weight attribute of the edge
|
| 967 |
+
(or the number 1 if the edge has no weight attribute). If the
|
| 968 |
+
alternate convention of doubling the edge weight is desired the
|
| 969 |
+
resulting NumPy array can be modified as follows:
|
| 970 |
+
|
| 971 |
+
>>> import numpy as np
|
| 972 |
+
>>> G = nx.Graph([(1, 1)])
|
| 973 |
+
>>> A = nx.to_numpy_array(G)
|
| 974 |
+
>>> A
|
| 975 |
+
array([[1.]])
|
| 976 |
+
>>> A[np.diag_indices_from(A)] *= 2
|
| 977 |
+
>>> A
|
| 978 |
+
array([[2.]])
|
| 979 |
+
|
| 980 |
+
Examples
|
| 981 |
+
--------
|
| 982 |
+
>>> G = nx.MultiDiGraph()
|
| 983 |
+
>>> G.add_edge(0, 1, weight=2)
|
| 984 |
+
0
|
| 985 |
+
>>> G.add_edge(1, 0)
|
| 986 |
+
0
|
| 987 |
+
>>> G.add_edge(2, 2, weight=3)
|
| 988 |
+
0
|
| 989 |
+
>>> G.add_edge(2, 2)
|
| 990 |
+
1
|
| 991 |
+
>>> nx.to_numpy_array(G, nodelist=[0, 1, 2])
|
| 992 |
+
array([[0., 2., 0.],
|
| 993 |
+
[1., 0., 0.],
|
| 994 |
+
[0., 0., 4.]])
|
| 995 |
+
|
| 996 |
+
When `nodelist` argument is used, nodes of `G` which do not appear in the `nodelist`
|
| 997 |
+
and their edges are not included in the adjacency matrix. Here is an example:
|
| 998 |
+
|
| 999 |
+
>>> G = nx.Graph()
|
| 1000 |
+
>>> G.add_edge(3, 1)
|
| 1001 |
+
>>> G.add_edge(2, 0)
|
| 1002 |
+
>>> G.add_edge(2, 1)
|
| 1003 |
+
>>> G.add_edge(3, 0)
|
| 1004 |
+
>>> nx.to_numpy_array(G, nodelist=[1, 2, 3])
|
| 1005 |
+
array([[0., 1., 1.],
|
| 1006 |
+
[1., 0., 0.],
|
| 1007 |
+
[1., 0., 0.]])
|
| 1008 |
+
|
| 1009 |
+
This function can also be used to create adjacency matrices for multiple
|
| 1010 |
+
edge attributes with structured dtypes:
|
| 1011 |
+
|
| 1012 |
+
>>> G = nx.Graph()
|
| 1013 |
+
>>> G.add_edge(0, 1, weight=10)
|
| 1014 |
+
>>> G.add_edge(1, 2, cost=5)
|
| 1015 |
+
>>> G.add_edge(2, 3, weight=3, cost=-4.0)
|
| 1016 |
+
>>> dtype = np.dtype([("weight", int), ("cost", float)])
|
| 1017 |
+
>>> A = nx.to_numpy_array(G, dtype=dtype, weight=None)
|
| 1018 |
+
>>> A["weight"]
|
| 1019 |
+
array([[ 0, 10, 0, 0],
|
| 1020 |
+
[10, 0, 1, 0],
|
| 1021 |
+
[ 0, 1, 0, 3],
|
| 1022 |
+
[ 0, 0, 3, 0]])
|
| 1023 |
+
>>> A["cost"]
|
| 1024 |
+
array([[ 0., 1., 0., 0.],
|
| 1025 |
+
[ 1., 0., 5., 0.],
|
| 1026 |
+
[ 0., 5., 0., -4.],
|
| 1027 |
+
[ 0., 0., -4., 0.]])
|
| 1028 |
+
|
| 1029 |
+
As stated above, the argument "nonedge" is useful especially when there are
|
| 1030 |
+
actually edges with weight 0 in the graph. Setting a nonedge value different than 0,
|
| 1031 |
+
makes it much clearer to differentiate such 0-weighted edges and actual nonedge values.
|
| 1032 |
+
|
| 1033 |
+
>>> G = nx.Graph()
|
| 1034 |
+
>>> G.add_edge(3, 1, weight=2)
|
| 1035 |
+
>>> G.add_edge(2, 0, weight=0)
|
| 1036 |
+
>>> G.add_edge(2, 1, weight=0)
|
| 1037 |
+
>>> G.add_edge(3, 0, weight=1)
|
| 1038 |
+
>>> nx.to_numpy_array(G, nonedge=-1.0)
|
| 1039 |
+
array([[-1., 2., -1., 1.],
|
| 1040 |
+
[ 2., -1., 0., -1.],
|
| 1041 |
+
[-1., 0., -1., 0.],
|
| 1042 |
+
[ 1., -1., 0., -1.]])
|
| 1043 |
+
"""
|
| 1044 |
+
import numpy as np
|
| 1045 |
+
|
| 1046 |
+
if nodelist is None:
|
| 1047 |
+
nodelist = list(G)
|
| 1048 |
+
nlen = len(nodelist)
|
| 1049 |
+
|
| 1050 |
+
# Input validation
|
| 1051 |
+
nodeset = set(nodelist)
|
| 1052 |
+
if nodeset - set(G):
|
| 1053 |
+
raise nx.NetworkXError(f"Nodes {nodeset - set(G)} in nodelist is not in G")
|
| 1054 |
+
if len(nodeset) < nlen:
|
| 1055 |
+
raise nx.NetworkXError("nodelist contains duplicates.")
|
| 1056 |
+
|
| 1057 |
+
A = np.full((nlen, nlen), fill_value=nonedge, dtype=dtype, order=order)
|
| 1058 |
+
|
| 1059 |
+
# Corner cases: empty nodelist or graph without any edges
|
| 1060 |
+
if nlen == 0 or G.number_of_edges() == 0:
|
| 1061 |
+
return A
|
| 1062 |
+
|
| 1063 |
+
# If dtype is structured and weight is None, use dtype field names as
|
| 1064 |
+
# edge attributes
|
| 1065 |
+
edge_attrs = None # Only single edge attribute by default
|
| 1066 |
+
if A.dtype.names:
|
| 1067 |
+
if weight is None:
|
| 1068 |
+
edge_attrs = dtype.names
|
| 1069 |
+
else:
|
| 1070 |
+
raise ValueError(
|
| 1071 |
+
"Specifying `weight` not supported for structured dtypes\n."
|
| 1072 |
+
"To create adjacency matrices from structured dtypes, use `weight=None`."
|
| 1073 |
+
)
|
| 1074 |
+
|
| 1075 |
+
# Map nodes to row/col in matrix
|
| 1076 |
+
idx = dict(zip(nodelist, range(nlen)))
|
| 1077 |
+
if len(nodelist) < len(G):
|
| 1078 |
+
G = G.subgraph(nodelist).copy()
|
| 1079 |
+
|
| 1080 |
+
# Collect all edge weights and reduce with `multigraph_weights`
|
| 1081 |
+
if G.is_multigraph():
|
| 1082 |
+
if edge_attrs:
|
| 1083 |
+
raise nx.NetworkXError(
|
| 1084 |
+
"Structured arrays are not supported for MultiGraphs"
|
| 1085 |
+
)
|
| 1086 |
+
d = defaultdict(list)
|
| 1087 |
+
for u, v, wt in G.edges(data=weight, default=1.0):
|
| 1088 |
+
d[(idx[u], idx[v])].append(wt)
|
| 1089 |
+
i, j = np.array(list(d.keys())).T # indices
|
| 1090 |
+
wts = [multigraph_weight(ws) for ws in d.values()] # reduced weights
|
| 1091 |
+
else:
|
| 1092 |
+
i, j, wts = [], [], []
|
| 1093 |
+
|
| 1094 |
+
# Special branch: multi-attr adjacency from structured dtypes
|
| 1095 |
+
if edge_attrs:
|
| 1096 |
+
# Extract edges with all data
|
| 1097 |
+
for u, v, data in G.edges(data=True):
|
| 1098 |
+
i.append(idx[u])
|
| 1099 |
+
j.append(idx[v])
|
| 1100 |
+
wts.append(data)
|
| 1101 |
+
# Map each attribute to the appropriate named field in the
|
| 1102 |
+
# structured dtype
|
| 1103 |
+
for attr in edge_attrs:
|
| 1104 |
+
attr_data = [wt.get(attr, 1.0) for wt in wts]
|
| 1105 |
+
A[attr][i, j] = attr_data
|
| 1106 |
+
if not G.is_directed():
|
| 1107 |
+
A[attr][j, i] = attr_data
|
| 1108 |
+
return A
|
| 1109 |
+
|
| 1110 |
+
for u, v, wt in G.edges(data=weight, default=1.0):
|
| 1111 |
+
i.append(idx[u])
|
| 1112 |
+
j.append(idx[v])
|
| 1113 |
+
wts.append(wt)
|
| 1114 |
+
|
| 1115 |
+
# Set array values with advanced indexing
|
| 1116 |
+
A[i, j] = wts
|
| 1117 |
+
if not G.is_directed():
|
| 1118 |
+
A[j, i] = wts
|
| 1119 |
+
|
| 1120 |
+
return A
|
| 1121 |
+
|
| 1122 |
+
|
| 1123 |
+
@nx._dispatchable(graphs=None, returns_graph=True)
|
| 1124 |
+
def from_numpy_array(
|
| 1125 |
+
A, parallel_edges=False, create_using=None, edge_attr="weight", *, nodelist=None
|
| 1126 |
+
):
|
| 1127 |
+
"""Returns a graph from a 2D NumPy array.
|
| 1128 |
+
|
| 1129 |
+
The 2D NumPy array is interpreted as an adjacency matrix for the graph.
|
| 1130 |
+
|
| 1131 |
+
Parameters
|
| 1132 |
+
----------
|
| 1133 |
+
A : a 2D numpy.ndarray
|
| 1134 |
+
An adjacency matrix representation of a graph
|
| 1135 |
+
|
| 1136 |
+
parallel_edges : Boolean
|
| 1137 |
+
If this is True, `create_using` is a multigraph, and `A` is an
|
| 1138 |
+
integer array, then entry *(i, j)* in the array is interpreted as the
|
| 1139 |
+
number of parallel edges joining vertices *i* and *j* in the graph.
|
| 1140 |
+
If it is False, then the entries in the array are interpreted as
|
| 1141 |
+
the weight of a single edge joining the vertices.
|
| 1142 |
+
|
| 1143 |
+
create_using : NetworkX graph constructor, optional (default=nx.Graph)
|
| 1144 |
+
Graph type to create. If graph instance, then cleared before populated.
|
| 1145 |
+
|
| 1146 |
+
edge_attr : String, optional (default="weight")
|
| 1147 |
+
The attribute to which the array values are assigned on each edge. If
|
| 1148 |
+
it is None, edge attributes will not be assigned.
|
| 1149 |
+
|
| 1150 |
+
nodelist : sequence of nodes, optional
|
| 1151 |
+
A sequence of objects to use as the nodes in the graph. If provided, the
|
| 1152 |
+
list of nodes must be the same length as the dimensions of `A`. The
|
| 1153 |
+
default is `None`, in which case the nodes are drawn from ``range(n)``.
|
| 1154 |
+
|
| 1155 |
+
Notes
|
| 1156 |
+
-----
|
| 1157 |
+
For directed graphs, explicitly mention create_using=nx.DiGraph,
|
| 1158 |
+
and entry i,j of A corresponds to an edge from i to j.
|
| 1159 |
+
|
| 1160 |
+
If `create_using` is :class:`networkx.MultiGraph` or
|
| 1161 |
+
:class:`networkx.MultiDiGraph`, `parallel_edges` is True, and the
|
| 1162 |
+
entries of `A` are of type :class:`int`, then this function returns a
|
| 1163 |
+
multigraph (of the same type as `create_using`) with parallel edges.
|
| 1164 |
+
|
| 1165 |
+
If `create_using` indicates an undirected multigraph, then only the edges
|
| 1166 |
+
indicated by the upper triangle of the array `A` will be added to the
|
| 1167 |
+
graph.
|
| 1168 |
+
|
| 1169 |
+
If `edge_attr` is Falsy (False or None), edge attributes will not be
|
| 1170 |
+
assigned, and the array data will be treated like a binary mask of
|
| 1171 |
+
edge presence or absence. Otherwise, the attributes will be assigned
|
| 1172 |
+
as follows:
|
| 1173 |
+
|
| 1174 |
+
If the NumPy array has a single data type for each array entry it
|
| 1175 |
+
will be converted to an appropriate Python data type.
|
| 1176 |
+
|
| 1177 |
+
If the NumPy array has a user-specified compound data type the names
|
| 1178 |
+
of the data fields will be used as attribute keys in the resulting
|
| 1179 |
+
NetworkX graph.
|
| 1180 |
+
|
| 1181 |
+
See Also
|
| 1182 |
+
--------
|
| 1183 |
+
to_numpy_array
|
| 1184 |
+
|
| 1185 |
+
Examples
|
| 1186 |
+
--------
|
| 1187 |
+
Simple integer weights on edges:
|
| 1188 |
+
|
| 1189 |
+
>>> import numpy as np
|
| 1190 |
+
>>> A = np.array([[1, 1], [2, 1]])
|
| 1191 |
+
>>> G = nx.from_numpy_array(A)
|
| 1192 |
+
>>> G.edges(data=True)
|
| 1193 |
+
EdgeDataView([(0, 0, {'weight': 1}), (0, 1, {'weight': 2}), (1, 1, {'weight': 1})])
|
| 1194 |
+
|
| 1195 |
+
If `create_using` indicates a multigraph and the array has only integer
|
| 1196 |
+
entries and `parallel_edges` is False, then the entries will be treated
|
| 1197 |
+
as weights for edges joining the nodes (without creating parallel edges):
|
| 1198 |
+
|
| 1199 |
+
>>> A = np.array([[1, 1], [1, 2]])
|
| 1200 |
+
>>> G = nx.from_numpy_array(A, create_using=nx.MultiGraph)
|
| 1201 |
+
>>> G[1][1]
|
| 1202 |
+
AtlasView({0: {'weight': 2}})
|
| 1203 |
+
|
| 1204 |
+
If `create_using` indicates a multigraph and the array has only integer
|
| 1205 |
+
entries and `parallel_edges` is True, then the entries will be treated
|
| 1206 |
+
as the number of parallel edges joining those two vertices:
|
| 1207 |
+
|
| 1208 |
+
>>> A = np.array([[1, 1], [1, 2]])
|
| 1209 |
+
>>> temp = nx.MultiGraph()
|
| 1210 |
+
>>> G = nx.from_numpy_array(A, parallel_edges=True, create_using=temp)
|
| 1211 |
+
>>> G[1][1]
|
| 1212 |
+
AtlasView({0: {'weight': 1}, 1: {'weight': 1}})
|
| 1213 |
+
|
| 1214 |
+
User defined compound data type on edges:
|
| 1215 |
+
|
| 1216 |
+
>>> dt = [("weight", float), ("cost", int)]
|
| 1217 |
+
>>> A = np.array([[(1.0, 2)]], dtype=dt)
|
| 1218 |
+
>>> G = nx.from_numpy_array(A)
|
| 1219 |
+
>>> G.edges()
|
| 1220 |
+
EdgeView([(0, 0)])
|
| 1221 |
+
>>> G[0][0]["cost"]
|
| 1222 |
+
2
|
| 1223 |
+
>>> G[0][0]["weight"]
|
| 1224 |
+
1.0
|
| 1225 |
+
|
| 1226 |
+
"""
|
| 1227 |
+
kind_to_python_type = {
|
| 1228 |
+
"f": float,
|
| 1229 |
+
"i": int,
|
| 1230 |
+
"u": int,
|
| 1231 |
+
"b": bool,
|
| 1232 |
+
"c": complex,
|
| 1233 |
+
"S": str,
|
| 1234 |
+
"U": str,
|
| 1235 |
+
"V": "void",
|
| 1236 |
+
}
|
| 1237 |
+
G = nx.empty_graph(0, create_using)
|
| 1238 |
+
if A.ndim != 2:
|
| 1239 |
+
raise nx.NetworkXError(f"Input array must be 2D, not {A.ndim}")
|
| 1240 |
+
n, m = A.shape
|
| 1241 |
+
if n != m:
|
| 1242 |
+
raise nx.NetworkXError(f"Adjacency matrix not square: nx,ny={A.shape}")
|
| 1243 |
+
dt = A.dtype
|
| 1244 |
+
try:
|
| 1245 |
+
python_type = kind_to_python_type[dt.kind]
|
| 1246 |
+
except Exception as err:
|
| 1247 |
+
raise TypeError(f"Unknown numpy data type: {dt}") from err
|
| 1248 |
+
if _default_nodes := (nodelist is None):
|
| 1249 |
+
nodelist = range(n)
|
| 1250 |
+
else:
|
| 1251 |
+
if len(nodelist) != n:
|
| 1252 |
+
raise ValueError("nodelist must have the same length as A.shape[0]")
|
| 1253 |
+
|
| 1254 |
+
# Make sure we get even the isolated nodes of the graph.
|
| 1255 |
+
G.add_nodes_from(nodelist)
|
| 1256 |
+
# Get a list of all the entries in the array with nonzero entries. These
|
| 1257 |
+
# coordinates become edges in the graph. (convert to int from np.int64)
|
| 1258 |
+
edges = ((int(e[0]), int(e[1])) for e in zip(*A.nonzero()))
|
| 1259 |
+
# handle numpy constructed data type
|
| 1260 |
+
if python_type == "void":
|
| 1261 |
+
# Sort the fields by their offset, then by dtype, then by name.
|
| 1262 |
+
fields = sorted(
|
| 1263 |
+
(offset, dtype, name) for name, (dtype, offset) in A.dtype.fields.items()
|
| 1264 |
+
)
|
| 1265 |
+
triples = (
|
| 1266 |
+
(
|
| 1267 |
+
u,
|
| 1268 |
+
v,
|
| 1269 |
+
{}
|
| 1270 |
+
if edge_attr in [False, None]
|
| 1271 |
+
else {
|
| 1272 |
+
name: kind_to_python_type[dtype.kind](val)
|
| 1273 |
+
for (_, dtype, name), val in zip(fields, A[u, v])
|
| 1274 |
+
},
|
| 1275 |
+
)
|
| 1276 |
+
for u, v in edges
|
| 1277 |
+
)
|
| 1278 |
+
# If the entries in the adjacency matrix are integers, the graph is a
|
| 1279 |
+
# multigraph, and parallel_edges is True, then create parallel edges, each
|
| 1280 |
+
# with weight 1, for each entry in the adjacency matrix. Otherwise, create
|
| 1281 |
+
# one edge for each positive entry in the adjacency matrix and set the
|
| 1282 |
+
# weight of that edge to be the entry in the matrix.
|
| 1283 |
+
elif python_type is int and G.is_multigraph() and parallel_edges:
|
| 1284 |
+
chain = itertools.chain.from_iterable
|
| 1285 |
+
# The following line is equivalent to:
|
| 1286 |
+
#
|
| 1287 |
+
# for (u, v) in edges:
|
| 1288 |
+
# for d in range(A[u, v]):
|
| 1289 |
+
# G.add_edge(u, v, weight=1)
|
| 1290 |
+
#
|
| 1291 |
+
if edge_attr in [False, None]:
|
| 1292 |
+
triples = chain(((u, v, {}) for d in range(A[u, v])) for (u, v) in edges)
|
| 1293 |
+
else:
|
| 1294 |
+
triples = chain(
|
| 1295 |
+
((u, v, {edge_attr: 1}) for d in range(A[u, v])) for (u, v) in edges
|
| 1296 |
+
)
|
| 1297 |
+
else: # basic data type
|
| 1298 |
+
if edge_attr in [False, None]:
|
| 1299 |
+
triples = ((u, v, {}) for u, v in edges)
|
| 1300 |
+
else:
|
| 1301 |
+
triples = ((u, v, {edge_attr: python_type(A[u, v])}) for u, v in edges)
|
| 1302 |
+
# If we are creating an undirected multigraph, only add the edges from the
|
| 1303 |
+
# upper triangle of the matrix. Otherwise, add all the edges. This relies
|
| 1304 |
+
# on the fact that the vertices created in the
|
| 1305 |
+
# `_generated_weighted_edges()` function are actually the row/column
|
| 1306 |
+
# indices for the matrix `A`.
|
| 1307 |
+
#
|
| 1308 |
+
# Without this check, we run into a problem where each edge is added twice
|
| 1309 |
+
# when `G.add_edges_from()` is invoked below.
|
| 1310 |
+
if G.is_multigraph() and not G.is_directed():
|
| 1311 |
+
triples = ((u, v, d) for u, v, d in triples if u <= v)
|
| 1312 |
+
# Remap nodes if user provided custom `nodelist`
|
| 1313 |
+
if not _default_nodes:
|
| 1314 |
+
idx_to_node = dict(enumerate(nodelist))
|
| 1315 |
+
triples = ((idx_to_node[u], idx_to_node[v], d) for u, v, d in triples)
|
| 1316 |
+
G.add_edges_from(triples)
|
| 1317 |
+
return G
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/exception.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
**********
|
| 3 |
+
Exceptions
|
| 4 |
+
**********
|
| 5 |
+
|
| 6 |
+
Base exceptions and errors for NetworkX.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
__all__ = [
|
| 10 |
+
"HasACycle",
|
| 11 |
+
"NodeNotFound",
|
| 12 |
+
"PowerIterationFailedConvergence",
|
| 13 |
+
"ExceededMaxIterations",
|
| 14 |
+
"AmbiguousSolution",
|
| 15 |
+
"NetworkXAlgorithmError",
|
| 16 |
+
"NetworkXException",
|
| 17 |
+
"NetworkXError",
|
| 18 |
+
"NetworkXNoCycle",
|
| 19 |
+
"NetworkXNoPath",
|
| 20 |
+
"NetworkXNotImplemented",
|
| 21 |
+
"NetworkXPointlessConcept",
|
| 22 |
+
"NetworkXUnbounded",
|
| 23 |
+
"NetworkXUnfeasible",
|
| 24 |
+
]
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class NetworkXException(Exception):
|
| 28 |
+
"""Base class for exceptions in NetworkX."""
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class NetworkXError(NetworkXException):
|
| 32 |
+
"""Exception for a serious error in NetworkX"""
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class NetworkXPointlessConcept(NetworkXException):
|
| 36 |
+
"""Raised when a null graph is provided as input to an algorithm
|
| 37 |
+
that cannot use it.
|
| 38 |
+
|
| 39 |
+
The null graph is sometimes considered a pointless concept [1]_,
|
| 40 |
+
thus the name of the exception.
|
| 41 |
+
|
| 42 |
+
Notes
|
| 43 |
+
-----
|
| 44 |
+
Null graphs and empty graphs are often used interchangeably but they
|
| 45 |
+
are well defined in NetworkX. An ``empty_graph`` is a graph with ``n`` nodes
|
| 46 |
+
and 0 edges, and a ``null_graph`` is a graph with 0 nodes and 0 edges.
|
| 47 |
+
|
| 48 |
+
References
|
| 49 |
+
----------
|
| 50 |
+
.. [1] Harary, F. and Read, R. "Is the Null Graph a Pointless
|
| 51 |
+
Concept?" In Graphs and Combinatorics Conference, George
|
| 52 |
+
Washington University. New York: Springer-Verlag, 1973.
|
| 53 |
+
|
| 54 |
+
"""
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class NetworkXAlgorithmError(NetworkXException):
|
| 58 |
+
"""Exception for unexpected termination of algorithms."""
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
class NetworkXUnfeasible(NetworkXAlgorithmError):
|
| 62 |
+
"""Exception raised by algorithms trying to solve a problem
|
| 63 |
+
instance that has no feasible solution."""
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
class NetworkXNoPath(NetworkXUnfeasible):
|
| 67 |
+
"""Exception for algorithms that should return a path when running
|
| 68 |
+
on graphs where such a path does not exist."""
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
class NetworkXNoCycle(NetworkXUnfeasible):
|
| 72 |
+
"""Exception for algorithms that should return a cycle when running
|
| 73 |
+
on graphs where such a cycle does not exist."""
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
class HasACycle(NetworkXException):
|
| 77 |
+
"""Raised if a graph has a cycle when an algorithm expects that it
|
| 78 |
+
will have no cycles.
|
| 79 |
+
|
| 80 |
+
"""
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
class NetworkXUnbounded(NetworkXAlgorithmError):
|
| 84 |
+
"""Exception raised by algorithms trying to solve a maximization
|
| 85 |
+
or a minimization problem instance that is unbounded."""
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
class NetworkXNotImplemented(NetworkXException):
|
| 89 |
+
"""Exception raised by algorithms not implemented for a type of graph."""
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
class NodeNotFound(NetworkXException):
|
| 93 |
+
"""Exception raised if requested node is not present in the graph"""
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
class AmbiguousSolution(NetworkXException):
|
| 97 |
+
"""Raised if more than one valid solution exists for an intermediary step
|
| 98 |
+
of an algorithm.
|
| 99 |
+
|
| 100 |
+
In the face of ambiguity, refuse the temptation to guess.
|
| 101 |
+
This may occur, for example, when trying to determine the
|
| 102 |
+
bipartite node sets in a disconnected bipartite graph when
|
| 103 |
+
computing bipartite matchings.
|
| 104 |
+
|
| 105 |
+
"""
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
class ExceededMaxIterations(NetworkXException):
|
| 109 |
+
"""Raised if a loop iterates too many times without breaking.
|
| 110 |
+
|
| 111 |
+
This may occur, for example, in an algorithm that computes
|
| 112 |
+
progressively better approximations to a value but exceeds an
|
| 113 |
+
iteration bound specified by the user.
|
| 114 |
+
|
| 115 |
+
"""
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
class PowerIterationFailedConvergence(ExceededMaxIterations):
|
| 119 |
+
"""Raised when the power iteration method fails to converge within a
|
| 120 |
+
specified iteration limit.
|
| 121 |
+
|
| 122 |
+
`num_iterations` is the number of iterations that have been
|
| 123 |
+
completed when this exception was raised.
|
| 124 |
+
|
| 125 |
+
"""
|
| 126 |
+
|
| 127 |
+
def __init__(self, num_iterations, *args, **kw):
|
| 128 |
+
msg = f"power iteration failed to converge within {num_iterations} iterations"
|
| 129 |
+
exception_message = msg
|
| 130 |
+
superinit = super().__init__
|
| 131 |
+
superinit(self, exception_message, *args, **kw)
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__init__.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
A package for generating various graphs in networkx.
|
| 3 |
+
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from networkx.generators.atlas import *
|
| 7 |
+
from networkx.generators.classic import *
|
| 8 |
+
from networkx.generators.cographs import *
|
| 9 |
+
from networkx.generators.community import *
|
| 10 |
+
from networkx.generators.degree_seq import *
|
| 11 |
+
from networkx.generators.directed import *
|
| 12 |
+
from networkx.generators.duplication import *
|
| 13 |
+
from networkx.generators.ego import *
|
| 14 |
+
from networkx.generators.expanders import *
|
| 15 |
+
from networkx.generators.geometric import *
|
| 16 |
+
from networkx.generators.harary_graph import *
|
| 17 |
+
from networkx.generators.internet_as_graphs import *
|
| 18 |
+
from networkx.generators.intersection import *
|
| 19 |
+
from networkx.generators.interval_graph import *
|
| 20 |
+
from networkx.generators.joint_degree_seq import *
|
| 21 |
+
from networkx.generators.lattice import *
|
| 22 |
+
from networkx.generators.line import *
|
| 23 |
+
from networkx.generators.mycielski import *
|
| 24 |
+
from networkx.generators.nonisomorphic_trees import *
|
| 25 |
+
from networkx.generators.random_clustered import *
|
| 26 |
+
from networkx.generators.random_graphs import *
|
| 27 |
+
from networkx.generators.small import *
|
| 28 |
+
from networkx.generators.social import *
|
| 29 |
+
from networkx.generators.spectral_graph_forge import *
|
| 30 |
+
from networkx.generators.stochastic import *
|
| 31 |
+
from networkx.generators.sudoku import *
|
| 32 |
+
from networkx.generators.time_series import *
|
| 33 |
+
from networkx.generators.trees import *
|
| 34 |
+
from networkx.generators.triads import *
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (1.52 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/atlas.cpython-310.pyc
ADDED
|
Binary file (4.38 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/classic.cpython-310.pyc
ADDED
|
Binary file (29.9 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/cographs.cpython-310.pyc
ADDED
|
Binary file (2.28 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/community.cpython-310.pyc
ADDED
|
Binary file (31.2 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/degree_seq.cpython-310.pyc
ADDED
|
Binary file (25.7 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/directed.cpython-310.pyc
ADDED
|
Binary file (15 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/duplication.cpython-310.pyc
ADDED
|
Binary file (5.12 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/ego.cpython-310.pyc
ADDED
|
Binary file (1.86 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/expanders.cpython-310.pyc
ADDED
|
Binary file (12.4 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/geometric.cpython-310.pyc
ADDED
|
Binary file (39 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/harary_graph.cpython-310.pyc
ADDED
|
Binary file (4.85 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/internet_as_graphs.cpython-310.pyc
ADDED
|
Binary file (12.6 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/intersection.cpython-310.pyc
ADDED
|
Binary file (4.31 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/interval_graph.cpython-310.pyc
ADDED
|
Binary file (2.38 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/joint_degree_seq.cpython-310.pyc
ADDED
|
Binary file (17.2 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/lattice.cpython-310.pyc
ADDED
|
Binary file (15.1 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/line.cpython-310.pyc
ADDED
|
Binary file (15.4 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/mycielski.cpython-310.pyc
ADDED
|
Binary file (3.9 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/nonisomorphic_trees.cpython-310.pyc
ADDED
|
Binary file (5.7 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/random_clustered.cpython-310.pyc
ADDED
|
Binary file (4.18 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/random_graphs.cpython-310.pyc
ADDED
|
Binary file (40.3 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/small.cpython-310.pyc
ADDED
|
Binary file (26.5 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/social.cpython-310.pyc
ADDED
|
Binary file (13.5 kB). View file
|
|
|
Scripts_RSCM_sim_growth_n_climate_to_Yield/.venv/lib/python3.10/site-packages/networkx/generators/__pycache__/spectral_graph_forge.cpython-310.pyc
ADDED
|
Binary file (4.28 kB). View file
|
|
|