diff --git a/talks/packages/packages.ipynb b/talks/packages/packages.ipynb index 84bc3797483fa3f76082dface02016a90764dd77..f96cca7eba78337021c01e5b1a540448a0dc0c07 100644 --- a/talks/packages/packages.ipynb +++ b/talks/packages/packages.ipynb @@ -19,8 +19,10 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 1, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "import numpy as np" @@ -47,7 +49,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "import scipy as sp" @@ -63,7 +67,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "from scipy import optimize\n", @@ -84,7 +90,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "import matplotlib as mpl\n", @@ -102,7 +110,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "x = np.linspace(0, 2, 100)\n", @@ -156,7 +166,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "import statsmodels.api as sm\n", @@ -167,7 +179,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "df = sm.datasets.get_rdataset(\"Guerry\", \"HistData\").data\n", @@ -177,7 +191,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "df.describe()" @@ -186,7 +202,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "df.groupby('Region').mean()" @@ -195,7 +213,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "results = smf.ols('Lottery ~ Literacy + np.log(Pop1831)', data=df).fit()\n", @@ -205,7 +225,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "df['log_pop'] = np.log(df.Pop1831)\n", @@ -215,7 +237,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "results = smf.ols('Lottery ~ Literacy + log_pop', data=df).fit()\n", @@ -225,7 +249,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "results = smf.ols('Lottery ~ Literacy + np.log(Pop1831) + Region', data=df).fit()\n", @@ -235,7 +261,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "results = smf.ols('Lottery ~ Literacy + np.log(Pop1831) + Region + Region * Literacy', data=df).fit()\n", @@ -245,7 +273,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "%matplotlib nbagg\n", @@ -263,7 +293,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "import sympy as sym # no standard nickname" @@ -272,7 +304,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "x, a, b, c = sym.symbols('x, a, b, c')\n", @@ -282,7 +316,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "sym.integrate(x/(x**2+a*x+2), x)" @@ -291,7 +327,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "f = sym.utilities.lambdify((x, a), sym.integrate((x**2+a*x+2), x))\n", @@ -309,7 +347,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "%%writefile test_argparse.py\n", @@ -335,7 +375,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "%run test_argparse.py 3 8 -v" @@ -344,7 +386,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "%run test_argparse.py -h" @@ -353,7 +397,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "%run test_argparse.py 3 8.5 -q" @@ -363,13 +409,45 @@ "cell_type": "markdown", "metadata": {}, "source": [ + "Alternatives:\n", + "- [docopt](http://docopt.org/): You write a usage string, docopt will generate the parser\n", + "> ```\n", + "> # example from https://realpython.com/blog/python/comparing-python-command-line-parsing-libraries-argparse-docopt-click/\n", + "> \"\"\"Greeter.\n", + ">\n", + "> Usage:\n", + "> commands.py hello\n", + "> commands.py goodbye\n", + "> commands.py -h | --help\n", + ">\n", + "> Options:\n", + "> -h --help Show this screen.\n", + "> \"\"\"\n", + "> from docopt import docopt\n", + ">\n", + "> if __name__ == '__main__':\n", + "> arguments = docopt(__doc__)\n", + "> ```\n", + "- [clize](http://clize.readthedocs.io/en/stable/why.html): You write a function, clize will generate the parser\n", + "> ```\n", + "> from clize import run\n", + ">\n", + "> def echo(word):\n", + "> return word\n", + ">\n", + "> if __name__ == '__main__':\n", + "> run(echo)\n", + "> ```\n", + "\n", "### [Gooey](https://github.com/chriskiehl/Gooey): GUI from command line tool" ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "%%writefile test_gooey.py\n", @@ -397,7 +475,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "%run test_gooey.py" @@ -406,7 +486,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "!gcoord_gui" @@ -416,13 +498,19 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## [Jinja2](http://jinja.pocoo.org/docs/2.10/): HTML generation" + "## [Jinja2](http://jinja.pocoo.org/docs/2.10/): Templating language\n", + "Jinja2 allows to create templates of files with placeholders, where future content will go.\n", + "This allows for the creation of a large number of similar files.\n", + "\n", + "This can for example be used to produce static HTML output in a highly flexible manner." ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "%%writefile image_list.jinja2\n", @@ -458,7 +546,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "def plot_sine(amplitude, frequency):\n", @@ -481,7 +571,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "from jinja2 import Environment, FileSystemLoader\n", @@ -503,7 +595,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "!open image_list.html" @@ -526,7 +620,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "%%writefile wx_hello_world.py\n", @@ -634,7 +730,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "%run wx_hello_world.py" @@ -649,13 +747,17 @@ "- theano/tensorflow/pytorch\n", " - keras\n", "\n", - "## [Pycuda](https://documen.tician.de/pycuda/): Programming the GPU" + "## [Pycuda](https://documen.tician.de/pycuda/): Programming the GPU\n", + "Wrapper around [Cuda](https://developer.nvidia.com/cuda-zone).\n", + "The alternative [Pyopencl](https://documen.tician.de/pyopencl/) provides a very similar wrapper around [OpenCL](https://www.khronos.org/opencl/)." ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "import pycuda.autoinit\n", @@ -778,11 +880,77 @@ "- [pylint](https://pypi.python.org/pypi/pylint): most extensive linter\n", "- [pyflake](https://pypi.python.org/pypi/pyflakes): if you think pylint is too strict\n", "- [pep8](https://pypi.python.org/pypi/pep8): just checks for style errors\n", - "- [mypy](http://mypy-lang.org/): adding explicit typing to python" + "- [mypy](http://mypy-lang.org/): adding explicit typing to python\n", + "\n", + "## Web frameworks\n", + "- [Django2](https://www.djangoproject.com/): includes the most features, but also forces you to do things their way\n", + "- [Pyramid](https://trypyramid.com): Intermediate options\n", + "- [Flask](http://flask.pocoo.org/): Bare-bone web framework, but many extensions available\n", + "\n", + "There are also many, many libraries to interact with databases, but you will have to google those yourself.\n", + "\n", + "# Several honourable mentions\n", + "- [trimesh](https://github.com/mikedh/trimesh): Triangular mesh algorithms\n", + "- [Pillow](https://pillow.readthedocs.io/en/latest/): Read/write/manipulate a wide variety of images (png, jpg, tiff, etc.)\n", + "- [psychopy](http://www.psychopy.org/): equivalent of psychtoolbox (workshop coming up in April in Nottingham)\n", + "- [Buit-in libraries](https://docs.python.org/3/py-modindex.html)\n", + " - [collections](https://docs.python.org/3.6/library/collections.html): deque, OrderedDict, namedtuple, and more\n", + " - [datetime](https://docs.python.org/3/library/datetime.html): Basic date and time types\n", + " - [enum](https://docs.python.org/3/library/enum.html): Enumerators\n", + " - [fractions](https://docs.python.org/3/library/fractions.html): rational numbers\n", + " - [functools](https://docs.python.org/3/library/functools.html): caching, decorators, and support for functional programming\n", + " - [json](https://docs.python.org/3/library/json.html)/[ipaddress](https://docs.python.org/3/library/ipaddress.html)/[xml](https://docs.python.org/3/library/xml.html#module-xml): parsing/writing\n", + " - [itertools](https://docs.python.org/3/library/itertools.html): more tools to loop over sequences\n", + " - [logging](https://docs.python.org/3/library/logging.htm): log your output to stdout or a file (more flexible than print statements)\n", + " - [multiprocessing](https://docs.python.org/3/library/multiprocessing.html)\n", + " - [os](https://docs.python.org/3/library/os.html#module-os)/[sys](https://docs.python.org/3/library/sys.html): Miscellaneous operating system interfaces\n", + " - [os.path](https://docs.python.org/3/library/os.path.html)/[pathlib](https://docs.python.org/3/library/pathlib.html): utilities to deal with filesystem paths (latter provides an object-oriented interface)\n", + " - [pickle](https://docs.python.org/3/library/pickle.html): Store/load any python object\n", + " - [shutil](https://docs.python.org/3/library/shutil.html): copy/move files\n", + " - [subprocess](https://docs.python.org/3/library/subprocess.html): call shell commands\n", + " - [turtule](https://docs.python.org/3/library/turtle.html#module-turtle): teach python to your kids!\n", + " - [warnings](https://docs.python.org/3/library/warnings.html#module-warnings): tell people they are not using your code properly" ] } ], - "metadata": {}, + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.2" + }, + "toc": { + "colors": { + "hover_highlight": "#DAA520", + "running_highlight": "#FF0000", + "selected_highlight": "#FFD700" + }, + "moveMenuLeft": true, + "nav_menu": { + "height": "417px", + "width": "252px" + }, + "navigate_menu": true, + "number_sections": true, + "sideBar": true, + "threshold": 4, + "toc_cell": false, + "toc_section_display": "block", + "toc_window_display": false + } + }, "nbformat": 4, "nbformat_minor": 2 } diff --git a/talks/packages/packages.md b/talks/packages/packages.md index 851c5065890aa015ad67da36b467cd0b7e515f8b..49f3a6d046d46a5b59133b19fc897cca8200a7c3 100644 --- a/talks/packages/packages.md +++ b/talks/packages/packages.md @@ -194,6 +194,36 @@ if __name__ == '__main__': %run test_argparse.py 3 8.5 -q ``` +Alternatives: +- [docopt](http://docopt.org/): You write a usage string, docopt will generate the parser +> ``` +> # example from https://realpython.com/blog/python/comparing-python-command-line-parsing-libraries-argparse-docopt-click/ +> """Greeter. +> +> Usage: +> commands.py hello +> commands.py goodbye +> commands.py -h | --help +> +> Options: +> -h --help Show this screen. +> """ +> from docopt import docopt +> +> if __name__ == '__main__': +> arguments = docopt(__doc__) +> ``` +- [clize](http://clize.readthedocs.io/en/stable/why.html): You write a function, clize will generate the parser +> ``` +> from clize import run +> +> def echo(word): +> return word +> +> if __name__ == '__main__': +> run(echo) +> ``` + ### [Gooey](https://github.com/chriskiehl/Gooey): GUI from command line tool ``` %%writefile test_gooey.py @@ -226,7 +256,11 @@ if __name__ == '__main__': !gcoord_gui ``` -## [Jinja2](http://jinja.pocoo.org/docs/2.10/): HTML generation +## [Jinja2](http://jinja.pocoo.org/docs/2.10/): Templating language +Jinja2 allows to create templates of files with placeholders, where future content will go. +This allows for the creation of a large number of similar files. + +This can for example be used to produce static HTML output in a highly flexible manner. ``` %%writefile image_list.jinja2 <!DOCTYPE html> @@ -418,6 +452,8 @@ if __name__ == '__main__': - keras ## [Pycuda](https://documen.tician.de/pycuda/): Programming the GPU +Wrapper around [Cuda](https://developer.nvidia.com/cuda-zone). +The alternative [Pyopencl](https://documen.tician.de/pyopencl/) provides a very similar wrapper around [OpenCL](https://www.khronos.org/opencl/). ``` import pycuda.autoinit import pycuda.driver as drv @@ -444,6 +480,7 @@ multiply_them( print(dest-a*b) ``` +Also see [pyopenGL](http://pyopengl.sourceforge.net/): graphics programming in python (used in FSLeyes) ## Testing - [unittest](https://docs.python.org/3.6/library/unittest.html): python built-in testing > ``` @@ -535,4 +572,34 @@ Linters check the code for any syntax errors, [style errors](https://www.python. - [pylint](https://pypi.python.org/pypi/pylint): most extensive linter - [pyflake](https://pypi.python.org/pypi/pyflakes): if you think pylint is too strict - [pep8](https://pypi.python.org/pypi/pep8): just checks for style errors -- [mypy](http://mypy-lang.org/): adding explicit typing to python \ No newline at end of file +- [mypy](http://mypy-lang.org/): adding explicit typing to python + +## Web frameworks +- [Django2](https://www.djangoproject.com/): includes the most features, but also forces you to do things their way +- [Pyramid](https://trypyramid.com): Intermediate options +- [Flask](http://flask.pocoo.org/): Bare-bone web framework, but many extensions available + +There are also many, many libraries to interact with databases, but you will have to google those yourself. + +# Several honourable mentions +- [trimesh](https://github.com/mikedh/trimesh): Triangular mesh algorithms +- [Pillow](https://pillow.readthedocs.io/en/latest/): Read/write/manipulate a wide variety of images (png, jpg, tiff, etc.) +- [psychopy](http://www.psychopy.org/): equivalent of psychtoolbox (workshop coming up in April in Nottingham) +- [Buit-in libraries](https://docs.python.org/3/py-modindex.html) + - [collections](https://docs.python.org/3.6/library/collections.html): deque, OrderedDict, namedtuple, and more + - [datetime](https://docs.python.org/3/library/datetime.html): Basic date and time types + - [enum](https://docs.python.org/3/library/enum.html): Enumerators + - [fractions](https://docs.python.org/3/library/fractions.html): rational numbers + - [functools](https://docs.python.org/3/library/functools.html): caching, decorators, and support for functional programming + - [json](https://docs.python.org/3/library/json.html)/[ipaddress](https://docs.python.org/3/library/ipaddress.html)/[xml](https://docs.python.org/3/library/xml.html#module-xml): parsing/writing + - [itertools](https://docs.python.org/3/library/itertools.html): more tools to loop over sequences + - [logging](https://docs.python.org/3/library/logging.htm): log your output to stdout or a file (more flexible than print statements) + - [multiprocessing](https://docs.python.org/3/library/multiprocessing.html) + - [os](https://docs.python.org/3/library/os.html#module-os)/[sys](https://docs.python.org/3/library/sys.html): Miscellaneous operating system interfaces + - [os.path](https://docs.python.org/3/library/os.path.html)/[pathlib](https://docs.python.org/3/library/pathlib.html): utilities to deal with filesystem paths (latter provides an object-oriented interface) + - [pickle](https://docs.python.org/3/library/pickle.html): Store/load any python object + - [shutil](https://docs.python.org/3/library/shutil.html): copy/move files + - [subprocess](https://docs.python.org/3/library/subprocess.html): call shell commands + - [time](https://docs.python.org/3/library/time.html)/[timeit](https://docs.python.org/3/library/timeit.html): keeping track of it + - [turtule](https://docs.python.org/3/library/turtle.html#module-turtle): teach python to your kids! + - [warnings](https://docs.python.org/3/library/warnings.html#module-warnings): tell people they are not using your code properly