This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def public(f): | |
"""Use a decorator to avoid retyping function/class names. [#]_ | |
* Based on an idea by Duncan Booth: | |
http://groups.google.com/group/comp.lang.python/msg/11cbb03e09611b8a | |
* Improved via a suggestion by Dave Angel: | |
http://groups.google.com/group/comp.lang.python/msg/3d400fb22d8a42e1 | |
References: | |
.. [#] https://stackoverflow.com/questions/6206089/is-it-a-good-practice-to-add-names-to-all-using-a-decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import sys | |
def format_time(timespan, precision=3): | |
"""Formats the timespan in a human readable form | |
Args: | |
timespan (float): | |
Time in seconds. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sphinx-quickstart "docs" -p "project" -a "Jaan Tollander de Balsch" -v "0.1" -l "en" --makefile --batchfile --quiet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adapted from a comment from: | |
# https://mathieularose.com/function-composition-in-python/ | |
import functools | |
def compose(*funcs): | |
"""Compose functions f, g, h, ... into ...(f(g(h(x)))) | |
Args: | |
*funcs: Functions to be composed. Fuctions must take only one argument. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name | symbol | value | unit | explanation | source | |
---|---|---|---|---|---|---|
size | :math:`N` | Number of agents (N) | ||||
shape | :math:`(N, 2)` | Shape for arrays | ||||
three_circles_flag | Boolean indicating if agent is modeled with three circle model | |||||
orientable_flag | Boolean indicating if agent is orientable | |||||
active | Boolean indicating if agent is active | |||||
goal_reached | Boolean indicating if goal is reahed | |||||
mass | :math:`m` | kg | Mass | fds+evac | ||
radius | :math:`r` | m | Radius | fds+evac | ||
r_t | :math:`r_t` | m | Radius of torso | fds+evac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def format_numpy(precision=5, threshold=6, edgeitems=3, linewidth=None, | |
suppress=False, nanstr=None, infstr=None, formatter=None): | |
try: | |
import numpy as np | |
np.set_printoptions(precision, threshold, edgeitems, linewidth, | |
suppress, nanstr, infstr, formatter) | |
except ImportError: | |
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generator(): return range(10) | |
# Here f and g does the exactly same thing | |
# Generator delegation | |
def f(): | |
yield from generator() | |
# Legacy python syntax |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Convert shapely geometries to other objects | |
Other interfaces | |
- matplotlib: PathPatch | |
- pyqtgraph: PlotItem | |
- bokeh: Glyph | |
- scikit-image: Indices on a grid | |
References |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pytest | |
def test_$NAME$(): | |
assert True$END$ | |
# Traitlets | |
@default('$NAME$') | |
def _default_$NAME$(self): | |
return $END$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""How to use line profiler [1]_ programatically. Code adapted from [2]_. | |
.. [1] https://github.com/rkern/line_profiler | |
.. [2] https://nvbn.github.io/2017/05/29/complexity/ | |
""" | |
from line_profiler import LineProfiler | |
def main(*args, **kwargs): | |
"""Function to be profiled""" |
OlderNewer