├── .gitignore ├── 1-introduction.ipynb ├── 2-interoperabilite.ipynb ├── 3-packaging.ipynb ├── 4-pylint.ipynb ├── 5-sphinx.ipynb ├── 6-pytest.ipynb ├── README.md ├── TPs ├── 1.TP packaging.ipynb ├── 1.packaging │ ├── final_step │ │ ├── LICENSE │ │ ├── demos │ │ │ ├── circle.py │ │ │ ├── circles.py │ │ │ ├── line.py │ │ │ └── lines.py │ │ ├── recipes │ │ │ └── meta.yaml │ │ ├── scripts │ │ │ ├── __init__.py │ │ │ └── cli_splinart.py │ │ ├── setup.cfg │ │ ├── setup.py │ │ └── splinart │ │ │ ├── __init__.py │ │ │ ├── compute.py │ │ │ ├── draw.py │ │ │ ├── shapes │ │ │ ├── __init__.py │ │ │ └── base.py │ │ │ └── spline │ │ │ ├── __init__.py │ │ │ ├── spline.py │ │ │ └── splint.py │ ├── step0 │ │ ├── base.py │ │ ├── circle.py │ │ ├── circles.py │ │ ├── cli_splinart.py │ │ ├── compute.py │ │ ├── draw.py │ │ ├── line.py │ │ ├── lines.py │ │ ├── spline.py │ │ └── splint.py │ ├── step1 │ │ ├── demos │ │ │ ├── circle.py │ │ │ ├── circles.py │ │ │ ├── line.py │ │ │ └── lines.py │ │ ├── scripts │ │ │ ├── __init__.py │ │ │ └── cli_splinart.py │ │ ├── setup.py │ │ └── splinart │ │ │ ├── __init__.py │ │ │ ├── compute.py │ │ │ ├── draw.py │ │ │ ├── shapes │ │ │ ├── __init__.py │ │ │ └── base.py │ │ │ └── spline │ │ │ ├── __init__.py │ │ │ ├── spline.py │ │ │ └── splint.py │ ├── step2 │ │ ├── demos │ │ │ ├── circle.py │ │ │ ├── circles.py │ │ │ ├── line.py │ │ │ └── lines.py │ │ ├── scripts │ │ │ ├── __init__.py │ │ │ └── cli_splinart.py │ │ ├── setup.py │ │ └── splinart │ │ │ ├── __init__.py │ │ │ ├── compute.py │ │ │ ├── draw.py │ │ │ ├── shapes │ │ │ ├── __init__.py │ │ │ └── base.py │ │ │ └── spline │ │ │ ├── __init__.py │ │ │ ├── spline.py │ │ │ └── splint.py │ ├── step3 │ │ ├── demos │ │ │ ├── circle.py │ │ │ ├── circles.py │ │ │ ├── line.py │ │ │ └── lines.py │ │ ├── scripts │ │ │ ├── __init__.py │ │ │ └── cli_splinart.py │ │ ├── setup.py │ │ └── splinart │ │ │ ├── __init__.py │ │ │ ├── compute.py │ │ │ ├── draw.py │ │ │ ├── shapes │ │ │ ├── __init__.py │ │ │ └── base.py │ │ │ └── spline │ │ │ ├── __init__.py │ │ │ ├── spline.py │ │ │ └── splint.py │ └── step4 │ │ ├── demos │ │ ├── circle.py │ │ ├── circles.py │ │ ├── line.py │ │ └── lines.py │ │ ├── scripts │ │ ├── __init__.py │ │ └── cli_splinart.py │ │ ├── setup.py │ │ └── splinart │ │ ├── __init__.py │ │ ├── compute.py │ │ ├── draw.py │ │ ├── shapes │ │ ├── __init__.py │ │ └── base.py │ │ └── spline │ │ ├── __init__.py │ │ ├── spline.py │ │ └── splint.py ├── 2.TP pylint.ipynb ├── 2.pylint │ ├── final_step │ │ ├── LICENSE │ │ ├── demos │ │ │ ├── circle.py │ │ │ ├── circles.py │ │ │ ├── line.py │ │ │ └── lines.py │ │ ├── recipes │ │ │ └── meta.yaml │ │ ├── scripts │ │ │ ├── __init__.py │ │ │ └── cli_splinart.py │ │ ├── setup.cfg │ │ ├── setup.py │ │ └── splinart │ │ │ ├── __init__.py │ │ │ ├── color.py │ │ │ ├── compute.py │ │ │ ├── draw.py │ │ │ ├── shapes │ │ │ ├── __init__.py │ │ │ └── base.py │ │ │ └── spline │ │ │ ├── __init__.py │ │ │ ├── spline.py │ │ │ └── splint.py │ └── step0 │ │ ├── LICENSE │ │ ├── demos │ │ ├── circle.py │ │ ├── circles.py │ │ ├── line.py │ │ └── lines.py │ │ ├── recipes │ │ └── meta.yaml │ │ ├── scripts │ │ ├── __init__.py │ │ └── cli_splinart.py │ │ ├── setup.cfg │ │ ├── setup.py │ │ └── splinart │ │ ├── __init__.py │ │ ├── compute.py │ │ ├── draw.py │ │ ├── shapes │ │ ├── __init__.py │ │ └── base.py │ │ └── spline │ │ ├── __init__.py │ │ ├── spline.py │ │ └── splint.py ├── 3.TP Sphinx.ipynb ├── 3.sphinx │ ├── final_step │ │ ├── .pyrcfile │ │ ├── LICENSE │ │ ├── demos │ │ │ ├── circle.py │ │ │ ├── circles.py │ │ │ ├── line.py │ │ │ └── lines.py │ │ ├── doc │ │ │ ├── Makefile │ │ │ ├── api │ │ │ │ ├── modules.rst │ │ │ │ ├── splinart.rst │ │ │ │ ├── splinart.shapes.rst │ │ │ │ └── splinart.spline.rst │ │ │ ├── conf.py │ │ │ ├── index.rst │ │ │ ├── make.bat │ │ │ ├── notebooks │ │ │ │ └── circle.ipynb │ │ │ └── spline.rst │ │ ├── notebooks │ │ │ └── circle.ipynb │ │ ├── recipes │ │ │ └── meta.yaml │ │ ├── scripts │ │ │ ├── __init__.py │ │ │ └── cli_splinart.py │ │ ├── setup.cfg │ │ ├── setup.py │ │ └── splinart │ │ │ ├── __init__.py │ │ │ ├── color.py │ │ │ ├── compute.py │ │ │ ├── draw.py │ │ │ ├── shapes │ │ │ ├── __init__.py │ │ │ └── base.py │ │ │ ├── spline │ │ │ ├── __init__.py │ │ │ ├── spline.py │ │ │ └── splint.py │ │ │ └── version.py │ └── step0 │ │ ├── .pyrcfile │ │ ├── LICENSE │ │ ├── circle.ipynb │ │ ├── demos │ │ ├── circle.py │ │ ├── circles.py │ │ ├── line.py │ │ └── lines.py │ │ ├── recipes │ │ └── meta.yaml │ │ ├── scripts │ │ ├── __init__.py │ │ └── cli_splinart.py │ │ ├── setup.cfg │ │ ├── setup.py │ │ ├── splinart │ │ ├── __init__.py │ │ ├── color.py │ │ ├── compute.py │ │ ├── draw.py │ │ ├── shapes │ │ │ ├── __init__.py │ │ │ └── base.py │ │ ├── spline │ │ │ ├── __init__.py │ │ │ ├── spline.py │ │ │ └── splint.py │ │ └── version.py │ │ └── spline.rst ├── 4.TP Pytest.ipynb ├── 4.pytest │ └── final_step │ │ ├── .coverage │ │ ├── .pyrcfile │ │ ├── LICENSE │ │ ├── demos │ │ ├── circle.py │ │ ├── circles.py │ │ ├── line.py │ │ └── lines.py │ │ ├── doc │ │ ├── Makefile │ │ ├── api │ │ │ ├── modules.rst │ │ │ ├── splinart.rst │ │ │ ├── splinart.shapes.rst │ │ │ └── splinart.spline.rst │ │ ├── conf.py │ │ ├── index.rst │ │ ├── make.bat │ │ ├── notebooks │ │ │ └── circle.ipynb │ │ └── spline.rst │ │ ├── notebooks │ │ └── circle.ipynb │ │ ├── recipes │ │ └── meta.yaml │ │ ├── scripts │ │ ├── __init__.py │ │ └── cli_splinart.py │ │ ├── setup.cfg │ │ ├── setup.py │ │ ├── splinart │ │ ├── __init__.py │ │ ├── color.py │ │ ├── compute.py │ │ ├── draw.py │ │ ├── shapes │ │ │ ├── __init__.py │ │ │ └── base.py │ │ ├── spline │ │ │ ├── __init__.py │ │ │ ├── spline.py │ │ │ └── splint.py │ │ └── version.py │ │ └── tests │ │ ├── baseline │ │ └── test_circle_case.png │ │ ├── test_all.py │ │ ├── test_shape.py │ │ └── test_spline.py ├── 5.Le-final.ipynb └── rise.css ├── environment.yml ├── examples ├── calculator │ ├── MANIFEST.in │ ├── README │ ├── calculator │ │ ├── __init__.py │ │ ├── command_line.py │ │ ├── cython_mod.c │ │ ├── cython_mod.pyx │ │ ├── data.txt │ │ ├── data │ │ │ ├── data1.txt │ │ │ └── data2.txt │ │ ├── operator_ │ │ │ ├── README │ │ │ ├── __init__.py │ │ │ ├── add.py │ │ │ ├── data │ │ │ │ ├── data_op1.txt │ │ │ │ └── data_op2.txt │ │ │ ├── data_op.txt │ │ │ ├── div.py │ │ │ ├── mult.py │ │ │ └── sub.py │ │ ├── parser.py │ │ └── version.py │ ├── doc │ │ ├── Makefile │ │ ├── conf.py │ │ ├── doc1.rst │ │ ├── index.rst │ │ ├── make.bat │ │ └── notebooks │ ├── notebooks │ │ └── test.ipynb │ ├── readme.md │ ├── recipes │ │ ├── bld.bat │ │ ├── build1.sh │ │ └── meta.yaml │ ├── scripts │ │ ├── __init__.py │ │ ├── calculator │ │ └── command_line.py │ └── setup.py ├── calculator_1 │ ├── __init__.py │ ├── operator1 │ │ ├── __init__.py │ │ ├── add.py │ │ └── sub.py │ └── operator2 │ │ ├── __init__.py │ │ └── mult.py ├── data_example │ ├── MANIFEST.in │ ├── README │ ├── calculator │ │ ├── ... │ │ ├── data │ │ │ ├── data1.txt │ │ │ └── data2.txt │ │ ├── data_calc.txt │ │ ├── op │ │ │ ├── ... │ │ │ ├── __init_.py │ │ │ └── data_op.txt │ │ └── parser │ │ │ ├── ... │ │ │ ├── README │ │ │ └── __init_.py │ └── setup.py ├── linter │ ├── .pyrcfile │ ├── correction │ │ └── example2.py │ ├── disable.py │ ├── example1.py │ ├── example2.py │ ├── example3.py │ ├── example4.py │ ├── example5.py │ ├── missing.py │ ├── module1.py │ ├── numpy_check.py │ ├── numpy_doc.py │ ├── pep8.py │ ├── py2to3.py │ ├── pyrcfile │ ├── similarities │ │ ├── __init__.py │ │ ├── module1.py │ │ └── module2.py │ └── spellcheck.py └── tests │ ├── conftest.py │ ├── fibonacci.py │ ├── numpy │ ├── baseline │ │ ├── test_npz_1.npz │ │ └── test_npz_2.npz │ ├── conftest.py │ ├── reference │ │ ├── test_npz_1.npz │ │ ├── test_npz_2.npz │ │ ├── test_npz_arange.npz │ │ ├── test_npz_random.npz │ │ └── test_npz_two_arange.npz │ └── test_numpy.py │ ├── test_approx_1.py │ ├── test_approx_2.py │ ├── test_approx__id_2.py │ ├── test_approx_id_2.py │ ├── test_capture.py │ ├── test_conftest_fixture.py │ ├── test_fibo.py │ ├── test_fixture_1.py │ ├── test_key.py │ ├── test_mark.py │ ├── test_parametrize.py │ ├── test_parametrize_1.py │ ├── test_parametrize_2.py │ └── test_skip.py ├── images ├── Octocat.png ├── Text-x-python.svg ├── black.png ├── but.png ├── but1.png ├── but2.png ├── but3.png ├── but4.png ├── but5.png ├── computer-user-icon-16386.jpg ├── computer-user.svg ├── conda_logo.svg ├── data │ ├── manifest_1.png │ ├── manifest_2.png │ ├── manifest_3.png │ ├── manifest_4.png │ ├── package_data_1.png │ ├── package_data_2.png │ ├── package_data_3.png │ └── package_data_4.png ├── data_setup.png ├── dessin.svg ├── group-png-3216.png ├── group-png-3216.svg ├── idea.png ├── idea.svg ├── pip.png ├── pytest1.png ├── readthedocs.png ├── readthedocs.svg ├── sphinx.png └── travis.png ├── rise.css ├── sphinx ├── cheatsheet-back-full.png └── cheatsheet-front-full.png └── style ├── custom.css ├── reveal.css └── reveal.less /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | _build 3 | .cache 4 | dist 5 | .ipynb_checkpoints 6 | __pycache__ 7 | *~ 8 | Untitled.ipynb 9 | *.egg-info 10 | output/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # python_packaging_2017 2 | 3 | [![Binder](https://mybinder.org/badge.svg)](https://mybinder.org/v2/gh/gouarin/python_packaging_course/master) 4 | 5 | This repository contains all the stuff for a tutorial that I gave for the CNRS in November 2017. The slides are in French. 6 | 7 | The idea of this tutorial was to show to the attendees how to use all the toolchain to package a Python application. 8 | 9 | The agenda was the following 10 | 11 | - Introduction to setuptools 12 | - Introduction to Pylint 13 | - Introduction to Sphinx, napoleon and nbsphinx 14 | - Introduction to pytest 15 | 16 | The final part was dedicated to push the code on github and to use travis, appveyor to automate the tests and deployment of the Python package on PyPi and Conda with binaries for Linux, Mac OS and Windows. The documentation was also update on ReadTheDocs. 17 | 18 | The application used during all this tutorial can be found here https://github.com/gouarin/splinart. 19 | 20 | -------------------------------------------------------------------------------- /TPs/1.packaging/final_step/LICENSE: -------------------------------------------------------------------------------- 1 | New BSD License 2 | 3 | Copyright (c) 2017, the splinart Developers. 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, 7 | are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its contributors 17 | may be used to endorse or promote products derived from this software without 18 | specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /TPs/1.packaging/final_step/demos/circle.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | import splinart as spl 8 | 9 | img_size, channels = 1000, 4 10 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 11 | 12 | theta, path = spl.circle([.5, .5], .3, npoints=40) 13 | 14 | def xs_func(): 15 | nsamples = 500 16 | return (np.random.random() + 2 * np.pi * np.linspace(0, 1, nsamples))%(2*np.pi) 17 | 18 | spl.update_img(img, path, xs_func, nrep=4000, x=theta, scale_value=.00005) 19 | 20 | spl.save_img(img, './output', 'circle.png') 21 | -------------------------------------------------------------------------------- /TPs/1.packaging/final_step/demos/circles.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | from six.moves import range 8 | import splinart as spl 9 | 10 | img_size, channels = 1000, 4 11 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 12 | 13 | nb_circles = 10 14 | theta_circles = [] 15 | path_circles = [] 16 | color_circles = [] 17 | for i in range(nb_circles): 18 | radius = .1 + np.random.random()*.1 19 | center = .2 + np.random.random(2)*.6 20 | theta, path = spl.circle(center, radius, npoints=75) 21 | theta_circles.append(theta) 22 | path_circles.append(path) 23 | color = np.random.random(4)*.3 24 | color[-1] = 1. 25 | color_circles.append(color) 26 | 27 | def xs_func(): 28 | nsamples = 500 29 | return (np.random.random() + 2 * np.pi * np.linspace(0, 1, nsamples))%(2*np.pi) 30 | 31 | for i in range(nb_circles): 32 | img1 = np.ones_like(img) 33 | spl.update_img(img1, path_circles[i], xs_func, nrep=1000, scale_value=.00005, x=theta_circles[i], color=color_circles[i]) 34 | mask = img1 < 1. 35 | img[mask] += img1[mask] 36 | 37 | spl.save_img(img, './output', 'circles.png') 38 | -------------------------------------------------------------------------------- /TPs/1.packaging/final_step/demos/line.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | import splinart as spl 8 | 9 | img_size, channels = 1000, 4 10 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 11 | 12 | def xs_func(): 13 | nsamples = 500 14 | return .001*np.random.random() + np.linspace(lo+.1,up-.1, nsamples) 15 | 16 | lo, up = .2, .8 17 | path = spl.line(lo, up, .5) 18 | 19 | spl.update_img(img, path, xs_func, nrep=1000, periodic=False) 20 | 21 | spl.save_img(img, "./output", "line.png") 22 | -------------------------------------------------------------------------------- /TPs/1.packaging/final_step/demos/lines.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | from six.moves import range 8 | import splinart as spl 9 | 10 | img_size, channels = 1000, 4 11 | img = np.ones((img_size, img_size, channels)), dtype=np.float32) 12 | 13 | lo, up = .2, .8 14 | path = [] 15 | color_lines = [] 16 | npoints = 20 17 | for iy, y in enumerate(np.linspace(lo, up, 10)): 18 | npoints += 5 19 | path.append(spl.line(lo, up, y, npoints)) 20 | color = np.random.random(4)*.3 21 | color[-1] = 1. 22 | color_lines.append(color) 23 | 24 | def xs_func(): 25 | nsamples = 500 26 | return .001*np.random.random() + np.linspace(lo+.02,up-.02, nsamples) 27 | 28 | for i in range(len(path)): 29 | img1 = np.ones_like(img) 30 | spl.update_img(img1, path[i], xs_func, nrep=1000, periodic=False, color=color_lines[i]) 31 | mask = img1 < 1. 32 | img[mask] += img1[mask] 33 | 34 | spl.save_img(img, "./output", "lines.png") 35 | -------------------------------------------------------------------------------- /TPs/1.packaging/final_step/recipes/meta.yaml: -------------------------------------------------------------------------------- 1 | {% set data = load_setup_py_data() %} 2 | 3 | package: 4 | name: splinart 5 | version: {{ data.get('version') }} 6 | 7 | source: 8 | path: ../ 9 | 10 | build: 11 | number: 0 12 | script: python setup.py install --single-version-externally-managed --record=record.txt 13 | 14 | requirements: 15 | build: 16 | - python 17 | - setuptools 18 | run: 19 | - python 20 | - numpy 21 | - matplotlib 22 | - six 23 | 24 | test: 25 | imports: 26 | - splinart 27 | 28 | about: 29 | home: http://github.com/gouarin/splinart 30 | license: BSD 31 | license_family: BSD 32 | license_file: '' 33 | summary: 'spline art generator' 34 | description: 'spline art generator' 35 | doc_url: '' 36 | dev_url: '' 37 | 38 | extra: 39 | recipe-maintainers: 'loic.gouarin@gmail.com' 40 | -------------------------------------------------------------------------------- /TPs/1.packaging/final_step/scripts/__init__.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause -------------------------------------------------------------------------------- /TPs/1.packaging/final_step/scripts/cli_splinart.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function, division, absolute_import 2 | # Author: 3 | # Loic Gouarin 4 | # 5 | # License: BSD 3 clause 6 | import splinart as spl 7 | import numpy as np 8 | import argparse 9 | 10 | def circle(img): 11 | def xs_func(): 12 | nsamples = 500 13 | return (np.random.random() + 2 * np.pi * np.linspace(0, 1, nsamples))%(2*np.pi) 14 | 15 | theta, path = spl.circle([.5, .5], .3, npoints=40) 16 | spl.update_img(img, path, xs_func, nrep=4000, x=theta, scale_value=.00005) 17 | 18 | def line(img): 19 | def xs_func(): 20 | nsamples = 500 21 | return .001*np.random.random() + np.linspace(lo+.1,up-.1, nsamples) 22 | 23 | lo, up = .2, .8 24 | path = spl.line(lo, up, .5) 25 | spl.update_img(img, path, xs_func, nrep=1000, periodic=False) 26 | 27 | def main(): 28 | parser = argparse.ArgumentParser(description="Splinart generator") 29 | parser.add_argument('-f', '--filename', type=str, 30 | help="filename where the output is stored", 31 | default='output.png') 32 | parser.add_argument('--path', type=str, 33 | help="path where to store the results", 34 | default='.') 35 | parser.add_argument('-s', '--shape', type=str, 36 | help='apply spline on this shape', 37 | default='circle', 38 | choices=['circle', 'line']) 39 | parser.add_argument('--show', 40 | help='show the result using matplotlib', 41 | action='store_true') 42 | args = parser.parse_args() 43 | 44 | img_size, channels = 1000, 4 45 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 46 | 47 | if args.shape == 'circle': 48 | circle(img) 49 | else: 50 | line(img) 51 | 52 | if args.show: 53 | spl.show_img(img) 54 | else: 55 | spl.save_img(img, args.path, args.filename) 56 | 57 | -------------------------------------------------------------------------------- /TPs/1.packaging/final_step/setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal=1 -------------------------------------------------------------------------------- /TPs/1.packaging/final_step/setup.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from setuptools import setup, find_packages 6 | 7 | CLASSIFIERS = [ 8 | "Development Status :: 3 - Alpha", 9 | "Intended Audience :: Science/Research", 10 | "Intended Audience :: Developers", 11 | "License :: OSI Approved :: BSD License", 12 | "Programming Language :: Python", 13 | "Programming Language :: Python :: 2", 14 | "Programming Language :: Python :: 2.7", 15 | "Programming Language :: Python :: 3", 16 | "Programming Language :: Python :: 3.4", 17 | "Programming Language :: Python :: 3.5", 18 | "Topic :: Software Development", 19 | "Topic :: Scientific/Engineering", 20 | "Operating System :: Microsoft :: Windows", 21 | "Operating System :: POSIX", 22 | "Operating System :: Unix", 23 | "Operating System :: MacOS" 24 | ] 25 | 26 | MAJOR = 0 27 | MINOR = 1 28 | PATCH = 0 29 | VERSION = "{}.{}.{}".format(MAJOR, MINOR, PATCH) 30 | 31 | with open("splinart/version.py", "w") as f: 32 | f.write("__version__ = '{}'\n".format(VERSION)) 33 | 34 | setup( 35 | name = "splinart", 36 | author = "loic.gouarin@gmail.com", 37 | description = "spline art generator", 38 | version = VERSION, 39 | license = "BSD", 40 | classifiers = CLASSIFIERS, 41 | packages = find_packages(exclude=["demos"]), 42 | install_requires = ["numpy", 43 | "matplotlib>=2", 44 | "six"], 45 | entry_points={ 'console_scripts': [ 46 | 'splinart=scripts.cli_splinart:main', 47 | ], 48 | }, 49 | ) -------------------------------------------------------------------------------- /TPs/1.packaging/final_step/splinart/__init__.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from .shapes import * 6 | from .compute import update_img 7 | from .draw import save_img, show_img -------------------------------------------------------------------------------- /TPs/1.packaging/final_step/splinart/compute.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | from six.moves import range 8 | 9 | from .spline import spline, splint 10 | from .draw import draw_pixel 11 | 12 | def update_path(path, periodic=False, scale_value=0.00001): 13 | n = path.shape[0] 14 | scale = np.arange(n)*scale_value 15 | r = 1.0-2.0*np.random.random(n) 16 | noise = r*scale 17 | phi = np.random.random(n)*2*np.pi 18 | rnd = np.c_[np.cos(phi), np.sin(phi)] 19 | path += rnd*noise[:, np.newaxis] 20 | if periodic: 21 | path[-1] = path[0] 22 | 23 | def update_img(img, path, xs_func, 24 | x=None, 25 | nrep=300, 26 | periodic=True, 27 | scale_color = .005, 28 | color=[0.0, 0.41568627450980394, 0.61960784313725492, 1.], 29 | scale_value = .00001): 30 | 31 | xs = xs_func() 32 | 33 | if x is not None: 34 | ys = np.zeros((xs.size, 2)) 35 | else: 36 | ys = np.zeros(xs.size) 37 | 38 | for i in range(nrep): 39 | if x is not None: 40 | y2 = spline(x, path) 41 | xs = xs_func() 42 | splint(x, path, y2, xs, ys) 43 | draw_pixel(img, ys[:, 0], ys[:, 1], scale_color, color) 44 | else: 45 | y2 = spline(path[:, 0], path[:, 1]) 46 | xs = xs_func() 47 | splint(path[:, 0], path[:, 1], y2, xs, ys) 48 | draw_pixel(img, ys, xs, scale_color, color) 49 | update_path(path, scale_value=scale_value, periodic=periodic) 50 | -------------------------------------------------------------------------------- /TPs/1.packaging/final_step/splinart/draw.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | import matplotlib.pyplot as plt 8 | import os 9 | 10 | def draw_pixel(img, xs, ys, scale_color=.0005, color=[0.0, 0.41568627450980394, 0.61960784313725492, 1.]): 11 | size = img.shape[0] 12 | newxs = np.floor(xs*size) 13 | xs_mask = np.logical_and(newxs>=0, newxs=0, newys 3 | # 4 | # License: BSD 3 clause 5 | from .base import line, circle -------------------------------------------------------------------------------- /TPs/1.packaging/final_step/splinart/shapes/base.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | 8 | def circle(center, radius, npoints = 50): 9 | theta = 2 * np.pi * np.linspace(0, 1, npoints) 10 | path = np.c_[center[0]+radius*np.cos(theta), center[1]+radius*np.sin(theta)] 11 | return theta, path 12 | 13 | def line(begin, end, ypos=0.5, npoints = 50): 14 | x = np.linspace(begin, end, npoints) 15 | yy = ypos*np.ones(npoints) 16 | return np.c_[x, yy] 17 | -------------------------------------------------------------------------------- /TPs/1.packaging/final_step/splinart/spline/__init__.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from .spline import spline 6 | from .splint import splint 7 | -------------------------------------------------------------------------------- /TPs/1.packaging/final_step/splinart/spline/spline.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | from six.moves import range 8 | 9 | def spline(x, y): 10 | n = x.shape[0] 11 | u = np.zeros_like(y) 12 | y2 = np.zeros_like(y) 13 | 14 | dif = np.diff(x) 15 | sig = dif[:-1]/(x[2:]-x[:-2]) 16 | 17 | if y.ndim == 2: 18 | dif = dif[:, np.newaxis] 19 | 20 | u[1:-1] = (y[2:]- y[1:-1])/dif[1:] - (y[1:-1]-y[:-2])/dif[:-1] 21 | 22 | for i in range(1, n-1): 23 | p = sig[i-1]*y2[i-1] + 2. 24 | y2[i] = (sig[i-1]-1)/p 25 | u[i] = (6*u[i]/(x[i+1]-x[i-1])-sig[i-1]*u[i-1])/p 26 | 27 | for i in range(n-2, -1, -1): 28 | y2[i] = y2[i]*y2[i+1]+u[i] 29 | 30 | return y2 31 | -------------------------------------------------------------------------------- /TPs/1.packaging/final_step/splinart/spline/splint.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | 8 | def splint(xa, ya, y2a, x, y): 9 | khi = np.searchsorted(xa, x) 10 | klo = khi-1 11 | h = xa[khi] - xa[klo] 12 | a = ((xa[khi]-x)/h) 13 | b = ((x-xa[klo])/h) 14 | 15 | if y.ndim == 2: 16 | h = h[:, np.newaxis] 17 | a = a[:, np.newaxis] 18 | b = b[:, np.newaxis] 19 | 20 | y[:] = a*ya[klo]+b*ya[khi]+((a**3-a)*y2a[klo]+(b**3-b)*y2a[khi])*h**2/6 21 | -------------------------------------------------------------------------------- /TPs/1.packaging/step0/base.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | def circle(center, radius, npoints = 50): 4 | theta = 2 * np.pi * np.linspace(0, 1, npoints) 5 | path = np.c_[center[0]+radius*np.cos(theta), center[1]+radius*np.sin(theta)] 6 | return theta, path 7 | 8 | def line(begin, end, ypos=0.5, npoints = 50): 9 | x = np.linspace(begin, end, npoints) 10 | yy = ypos*np.ones(npoints) 11 | return np.c_[x, yy] 12 | -------------------------------------------------------------------------------- /TPs/1.packaging/step0/circle.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import splinart as spl 3 | 4 | img_size, channels = 1000, 4 5 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 6 | 7 | theta, path = spl.circle([.5, .5], .3, npoints=40) 8 | 9 | def xs_func(): 10 | nsamples = 500 11 | return (np.random.random() + 2 * np.pi * np.linspace(0, 1, nsamples))%(2*np.pi) 12 | 13 | spl.update_img(img, path, xs_func, nrep=4000, x=theta, scale_value=.00005) 14 | 15 | spl.save_img(img, './output', 'circle.png') 16 | -------------------------------------------------------------------------------- /TPs/1.packaging/step0/circles.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import splinart as spl 3 | 4 | img_size, channels = 1000, 4 5 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 6 | 7 | nb_circles = 10 8 | theta_circles = [] 9 | path_circles = [] 10 | color_circles = [] 11 | for i in range(nb_circles): 12 | radius = .1 + np.random.random()*.1 13 | center = .2 + np.random.random(2)*.6 14 | theta, path = spl.circle(center, radius, npoints=75) 15 | theta_circles.append(theta) 16 | path_circles.append(path) 17 | color = np.random.random(4)*.3 18 | color[-1] = 1. 19 | color_circles.append(color) 20 | 21 | def xs_func(): 22 | nsamples = 500 23 | return (np.random.random() + 2 * np.pi * np.linspace(0, 1, nsamples))%(2*np.pi) 24 | 25 | for i in range(nb_circles): 26 | img1 = np.ones_like(img) 27 | spl.update_img(img1, path_circles[i], xs_func, nrep=1000, scale_value=.00005, x=theta_circles[i], color=color_circles[i]) 28 | mask = img1 < 1. 29 | img[mask] += img1[mask] 30 | 31 | spl.save_img(img, './output', 'circles.png') 32 | -------------------------------------------------------------------------------- /TPs/1.packaging/step0/cli_splinart.py: -------------------------------------------------------------------------------- 1 | import splinart as spl 2 | import numpy as np 3 | import argparse 4 | 5 | def circle(img): 6 | def xs_func(): 7 | nsamples = 500 8 | return (np.random.random() + 2 * np.pi * np.linspace(0, 1, nsamples))%(2*np.pi) 9 | 10 | theta, path = spl.circle([.5, .5], .3, npoints=40) 11 | spl.update_img(img, path, xs_func, nrep=4000, x=theta, scale_value=.00005) 12 | 13 | def line(img): 14 | def xs_func(): 15 | nsamples = 500 16 | return .001*np.random.random() + np.linspace(lo+.1,up-.1, nsamples) 17 | 18 | lo, up = .2, .8 19 | path = spl.line(lo, up, .5) 20 | spl.update_img(img, path, xs_func, nrep=1000, periodic=False) 21 | 22 | def main(): 23 | parser = argparse.ArgumentParser(description="Splinart generator") 24 | parser.add_argument('-f', '--filename', type=str, 25 | help="filename where the output is stored", 26 | default='output.png') 27 | parser.add_argument('--path', type=str, 28 | help="path where to store the results", 29 | default='.') 30 | parser.add_argument('-s', '--shape', type=str, 31 | help='apply spline on this shape', 32 | default='circle', 33 | choices=['circle', 'line']) 34 | parser.add_argument('--show', 35 | help='show the result using matplotlib', 36 | action='store_true') 37 | args = parser.parse_args() 38 | 39 | img_size, channels = 1000, 4 40 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 41 | 42 | if args.shape == 'circle': 43 | circle(img) 44 | else: 45 | line(img) 46 | 47 | if args.show: 48 | spl.show_img(img) 49 | else: 50 | spl.save_img(img, args.path, args.filename) 51 | 52 | -------------------------------------------------------------------------------- /TPs/1.packaging/step0/compute.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | from .spline import spline, splint 4 | from .draw import draw_pixel 5 | 6 | def update_path(path, periodic=False, scale_value=0.00001): 7 | n = path.shape[0] 8 | scale = np.arange(n)*scale_value 9 | r = 1.0-2.0*np.random.random(n) 10 | noise = r*scale 11 | phi = np.random.random(n)*2*np.pi 12 | rnd = np.c_[np.cos(phi), np.sin(phi)] 13 | path += rnd*noise[:, np.newaxis] 14 | if periodic: 15 | path[-1] = path[0] 16 | 17 | def update_img(img, path, xs_func, 18 | x=None, 19 | nrep=300, 20 | periodic=True, 21 | scale_color = .005, 22 | color=[0.0, 0.41568627450980394, 0.61960784313725492, 1.], 23 | scale_value = .00001): 24 | 25 | xs = xs_func() 26 | 27 | if x is not None: 28 | ys = np.zeros((xs.size, 2)) 29 | else: 30 | ys = np.zeros(xs.size) 31 | 32 | for i in range(nrep): 33 | if x is not None: 34 | y2 = spline(x, path) 35 | xs = xs_func() 36 | splint(x, path, y2, xs, ys) 37 | draw_pixel(img, ys[:, 0], ys[:, 1], scale_color, color) 38 | else: 39 | y2 = spline(path[:, 0], path[:, 1]) 40 | xs = xs_func() 41 | splint(path[:, 0], path[:, 1], y2, xs, ys) 42 | draw_pixel(img, ys, xs, scale_color, color) 43 | update_path(path, scale_value=scale_value, periodic=periodic) 44 | -------------------------------------------------------------------------------- /TPs/1.packaging/step0/draw.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | import os 4 | 5 | def draw_pixel(img, xs, ys, scale_color=.0005, color=[0.0, 0.41568627450980394, 0.61960784313725492, 1.]): 6 | size = img.shape[0] 7 | newxs = np.floor(xs*size) 8 | xs_mask = np.logical_and(newxs>=0, newxs=0, newys=0, newxs=0, newys=0, newxs=0, newys=0, newxs=0, newys 3 | # 4 | # License: BSD 3 clause -------------------------------------------------------------------------------- /TPs/1.packaging/step4/scripts/cli_splinart.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function, division, absolute_import 2 | # Author: 3 | # Loic Gouarin 4 | # 5 | # License: BSD 3 clause 6 | import splinart as spl 7 | import numpy as np 8 | import argparse 9 | 10 | def circle(img): 11 | def xs_func(): 12 | nsamples = 500 13 | return (np.random.random() + 2 * np.pi * np.linspace(0, 1, nsamples))%(2*np.pi) 14 | 15 | theta, path = spl.circle([.5, .5], .3, npoints=40) 16 | spl.update_img(img, path, xs_func, nrep=4000, x=theta, scale_value=.00005) 17 | 18 | def line(img): 19 | def xs_func(): 20 | nsamples = 500 21 | return .001*np.random.random() + np.linspace(lo+.1,up-.1, nsamples) 22 | 23 | lo, up = .2, .8 24 | path = spl.line(lo, up, .5) 25 | spl.update_img(img, path, xs_func, nrep=1000, periodic=False) 26 | 27 | def main(): 28 | parser = argparse.ArgumentParser(description="Splinart generator") 29 | parser.add_argument('-f', '--filename', type=str, 30 | help="filename where the output is stored", 31 | default='output.png') 32 | parser.add_argument('--path', type=str, 33 | help="path where to store the results", 34 | default='.') 35 | parser.add_argument('-s', '--shape', type=str, 36 | help='apply spline on this shape', 37 | default='circle', 38 | choices=['circle', 'line']) 39 | parser.add_argument('--show', 40 | help='show the result using matplotlib', 41 | action='store_true') 42 | args = parser.parse_args() 43 | 44 | img_size, channels = 1000, 4 45 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 46 | 47 | if args.shape == 'circle': 48 | circle(img) 49 | else: 50 | line(img) 51 | 52 | if args.show: 53 | spl.show_img(img) 54 | else: 55 | spl.save_img(img, args.path, args.filename) 56 | 57 | -------------------------------------------------------------------------------- /TPs/1.packaging/step4/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | MAJOR = 0 4 | MINOR = 1 5 | PATCH = 0 6 | VERSION = "{}.{}.{}".format(MAJOR, MINOR, PATCH) 7 | 8 | with open("splinart/version.py", "w") as f: 9 | f.write("__version__ = '{}'\n".format(VERSION)) 10 | 11 | setup( 12 | name = "splinart", 13 | version = VERSION, 14 | packages = find_packages(exclude=["demos"]), 15 | entry_points={ 'console_scripts': [ 16 | 'splinart=scripts.cli_splinart:main', 17 | ], 18 | }, 19 | ) -------------------------------------------------------------------------------- /TPs/1.packaging/step4/splinart/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function, division, absolute_import 2 | from .shapes import * 3 | from .compute import update_img 4 | from .draw import save_img, show_img -------------------------------------------------------------------------------- /TPs/1.packaging/step4/splinart/compute.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function, division, absolute_import 2 | import numpy as np 3 | from six.moves import range 4 | 5 | from .spline import spline, splint 6 | from .draw import draw_pixel 7 | 8 | def update_path(path, periodic=False, scale_value=0.00001): 9 | n = path.shape[0] 10 | scale = np.arange(n)*scale_value 11 | r = 1.0-2.0*np.random.random(n) 12 | noise = r*scale 13 | phi = np.random.random(n)*2*np.pi 14 | rnd = np.c_[np.cos(phi), np.sin(phi)] 15 | path += rnd*noise[:, np.newaxis] 16 | if periodic: 17 | path[-1] = path[0] 18 | 19 | def update_img(img, path, xs_func, 20 | x=None, 21 | nrep=300, 22 | periodic=True, 23 | scale_color = .005, 24 | color=[0.0, 0.41568627450980394, 0.61960784313725492, 1.], 25 | scale_value = .00001): 26 | 27 | xs = xs_func() 28 | 29 | if x is not None: 30 | ys = np.zeros((xs.size, 2)) 31 | else: 32 | ys = np.zeros(xs.size) 33 | 34 | for i in range(nrep): 35 | if x is not None: 36 | y2 = spline(x, path) 37 | xs = xs_func() 38 | splint(x, path, y2, xs, ys) 39 | draw_pixel(img, ys[:, 0], ys[:, 1], scale_color, color) 40 | else: 41 | y2 = spline(path[:, 0], path[:, 1]) 42 | xs = xs_func() 43 | splint(path[:, 0], path[:, 1], y2, xs, ys) 44 | draw_pixel(img, ys, xs, scale_color, color) 45 | update_path(path, scale_value=scale_value, periodic=periodic) 46 | -------------------------------------------------------------------------------- /TPs/1.packaging/step4/splinart/draw.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function, division, absolute_import 2 | import numpy as np 3 | import matplotlib.pyplot as plt 4 | import os 5 | 6 | def draw_pixel(img, xs, ys, scale_color=.0005, color=[0.0, 0.41568627450980394, 0.61960784313725492, 1.]): 7 | size = img.shape[0] 8 | newxs = np.floor(xs*size) 9 | xs_mask = np.logical_and(newxs>=0, newxs=0, newys 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | import splinart as spl 8 | 9 | img_size, channels = 1000, 4 10 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 11 | 12 | theta, path = spl.circle([.5, .5], .3, npoints=40) 13 | 14 | def xs_func(): 15 | nsamples = 500 16 | return (np.random.random() + 2 * np.pi * np.linspace(0, 1, nsamples))%(2*np.pi) 17 | 18 | spl.update_img(img, path, xs_func, nrep=4000, x=theta, scale_value=.00005) 19 | 20 | spl.save_img(img, './output', 'circle.png') 21 | -------------------------------------------------------------------------------- /TPs/2.pylint/final_step/demos/circles.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | from six.moves import range 8 | import splinart as spl 9 | 10 | img_size, channels = 1000, 4 11 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 12 | 13 | nb_circles = 10 14 | theta_circles = [] 15 | path_circles = [] 16 | color_circles = [] 17 | for i in range(nb_circles): 18 | radius = .1 + np.random.random()*.1 19 | center = .2 + np.random.random(2)*.6 20 | theta, path = spl.circle(center, radius, npoints=75) 21 | theta_circles.append(theta) 22 | path_circles.append(path) 23 | color = np.random.random(4)*.3 24 | color[-1] = 1. 25 | color_circles.append(color) 26 | 27 | def xs_func(): 28 | nsamples = 500 29 | return (np.random.random() + 2 * np.pi * np.linspace(0, 1, nsamples))%(2*np.pi) 30 | 31 | for i in range(nb_circles): 32 | img1 = np.ones_like(img) 33 | spl.update_img(img1, path_circles[i], xs_func, nrep=1000, scale_value=.00005, x=theta_circles[i], color=color_circles[i]) 34 | mask = img1 < 1. 35 | img[mask] += img1[mask] 36 | 37 | spl.save_img(img, './output', 'circles.png') 38 | -------------------------------------------------------------------------------- /TPs/2.pylint/final_step/demos/line.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | import splinart as spl 8 | 9 | img_size, channels = 1000, 4 10 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 11 | 12 | def xs_func(): 13 | nsamples = 500 14 | return .001*np.random.random() + np.linspace(lo+.1,up-.1, nsamples) 15 | 16 | lo, up = .2, .8 17 | path = spl.line(lo, up, .5) 18 | 19 | spl.update_img(img, path, xs_func, nrep=1000, periodic=False) 20 | 21 | spl.save_img(img, "./output", "line.png") 22 | -------------------------------------------------------------------------------- /TPs/2.pylint/final_step/demos/lines.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | from six.moves import range 8 | import splinart as spl 9 | 10 | img_size, channels = 1000, 4 11 | img = np.ones((img_size, img_size, channels)), dtype=np.float32) 12 | 13 | lo, up = .2, .8 14 | path = [] 15 | color_lines = [] 16 | npoints = 20 17 | for iy, y in enumerate(np.linspace(lo, up, 10)): 18 | npoints += 5 19 | path.append(spl.line(lo, up, y, npoints)) 20 | color = np.random.random(4)*.3 21 | color[-1] = 1. 22 | color_lines.append(color) 23 | 24 | def xs_func(): 25 | nsamples = 500 26 | return .001*np.random.random() + np.linspace(lo+.02,up-.02, nsamples) 27 | 28 | for i in range(len(path)): 29 | img1 = np.ones_like(img) 30 | spl.update_img(img1, path[i], xs_func, nrep=1000, periodic=False, color=color_lines[i]) 31 | mask = img1 < 1. 32 | img[mask] += img1[mask] 33 | 34 | spl.save_img(img, "./output", "lines.png") 35 | -------------------------------------------------------------------------------- /TPs/2.pylint/final_step/recipes/meta.yaml: -------------------------------------------------------------------------------- 1 | {% set data = load_setup_py_data() %} 2 | 3 | package: 4 | name: splinart 5 | version: {{ data.get('version') }} 6 | 7 | source: 8 | path: ../ 9 | 10 | build: 11 | number: 0 12 | script: python setup.py install --single-version-externally-managed --record=record.txt 13 | 14 | requirements: 15 | build: 16 | - python 17 | - setuptools 18 | run: 19 | - python 20 | - numpy 21 | - matplotlib 22 | - six 23 | 24 | test: 25 | imports: 26 | - splinart 27 | 28 | about: 29 | home: http://github.com/gouarin/splinart 30 | license: BSD 31 | license_family: BSD 32 | license_file: '' 33 | summary: 'spline art generator' 34 | description: 'spline art generator' 35 | doc_url: '' 36 | dev_url: '' 37 | 38 | extra: 39 | recipe-maintainers: 'loic.gouarin@gmail.com' 40 | -------------------------------------------------------------------------------- /TPs/2.pylint/final_step/scripts/__init__.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause -------------------------------------------------------------------------------- /TPs/2.pylint/final_step/setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal=1 -------------------------------------------------------------------------------- /TPs/2.pylint/final_step/setup.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from setuptools import setup, find_packages 6 | 7 | CLASSIFIERS = [ 8 | "Development Status :: 3 - Alpha", 9 | "Intended Audience :: Science/Research", 10 | "Intended Audience :: Developers", 11 | "License :: OSI Approved :: BSD License", 12 | "Programming Language :: Python", 13 | "Programming Language :: Python :: 2", 14 | "Programming Language :: Python :: 2.7", 15 | "Programming Language :: Python :: 3", 16 | "Programming Language :: Python :: 3.4", 17 | "Programming Language :: Python :: 3.5", 18 | "Topic :: Software Development", 19 | "Topic :: Scientific/Engineering", 20 | "Operating System :: Microsoft :: Windows", 21 | "Operating System :: POSIX", 22 | "Operating System :: Unix", 23 | "Operating System :: MacOS" 24 | ] 25 | 26 | name = "splinart" 27 | 28 | MAJOR = 0 29 | MINOR = 1 30 | PATCH = 2 31 | VERSION = "{}.{}.{}".format(MAJOR, MINOR, PATCH) 32 | 33 | with open("splinart/version.py", "w") as f: 34 | f.write("__version__ = '{}'\n".format(VERSION)) 35 | 36 | setup( 37 | name = "splinart", 38 | author = "loic.gouarin@gmail.com", 39 | description = "spline art generator", 40 | version = VERSION, 41 | license = "BSD", 42 | classifiers = CLASSIFIERS, 43 | packages = find_packages(exclude=["demos"]), 44 | install_requires = ["numpy", 45 | "matplotlib>=2", 46 | "six"], 47 | entry_points={ 'console_scripts': [ 48 | 'splinart=scripts.cli_splinart:main', 49 | ], 50 | }, 51 | ) -------------------------------------------------------------------------------- /TPs/2.pylint/final_step/splinart/__init__.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | splinart 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | from .shapes import circle, line 10 | from .compute import update_img 11 | from .draw import save_img, show_img 12 | -------------------------------------------------------------------------------- /TPs/2.pylint/final_step/splinart/color.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | color 7 | """ 8 | DEFAULT_COLOR = (0.0, 0.41568627450980394, 0.61960784313725492, 1.) 9 | -------------------------------------------------------------------------------- /TPs/2.pylint/final_step/splinart/compute.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | Compute module 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | 10 | import numpy as np 11 | from six.moves import range 12 | 13 | from .spline import spline, splint 14 | from .draw import draw_pixel 15 | from .color import DEFAULT_COLOR 16 | 17 | def update_path(path, periodic=False, scale_value=0.00001): 18 | """ 19 | update the path 20 | """ 21 | n = path.shape[0] 22 | scale = np.arange(n)*scale_value 23 | radius = 1.0-2.0*np.random.random(n) 24 | noise = radius*scale 25 | phi = np.random.random(n)*2*np.pi 26 | rnd = np.c_[np.cos(phi), np.sin(phi)] 27 | path += rnd*noise[:, np.newaxis] 28 | if periodic: 29 | path[-1] = path[0] 30 | 31 | # pylint: disable=too-many-arguments 32 | def update_img(img, path, xs_func, 33 | x=None, 34 | nrep=300, 35 | periodic=True, 36 | scale_color=.005, 37 | color=DEFAULT_COLOR, 38 | scale_value=.00001): 39 | """ 40 | update image 41 | """ 42 | xspline = xs_func() 43 | 44 | if x is not None: 45 | yspline = np.zeros((xspline.size, 2)) 46 | else: 47 | yspline = np.zeros(xspline.size) 48 | 49 | for i in range(nrep):#pylint: disable=unused-variable 50 | if x is not None: 51 | yder2 = spline(x, path) 52 | xspline = xs_func() 53 | splint(x, path, yder2, xspline, yspline) 54 | draw_pixel(img, yspline[:, 0], yspline[:, 1], scale_color, color) 55 | else: 56 | yder2 = spline(path[:, 0], path[:, 1]) 57 | xspline = xs_func() 58 | splint(path[:, 0], path[:, 1], yder2, xspline, yspline) 59 | draw_pixel(img, yspline, xspline, scale_color, color) 60 | update_path(path, scale_value=scale_value, periodic=periodic) 61 | -------------------------------------------------------------------------------- /TPs/2.pylint/final_step/splinart/draw.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | draw module 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | import os 10 | import numpy as np 11 | import matplotlib.pyplot as plt 12 | from .color import DEFAULT_COLOR 13 | 14 | def draw_pixel(img, xs, ys, scale_color=.0005, 15 | color=DEFAULT_COLOR): 16 | """ 17 | draw pixel 18 | """ 19 | size = img.shape[0] 20 | newxs = np.floor(xs*size) 21 | xs_mask = np.logical_and(newxs >= 0, newxs < size) 22 | newys = np.floor(ys*size) 23 | ys_mask = np.logical_and(newys >= 0, newys < size) 24 | mask = np.logical_and(xs_mask, ys_mask) 25 | coords = np.asarray([newxs[mask], newys[mask]], dtype='i8') 26 | img_color = np.asarray(color)*scale_color 27 | pixels = img[coords[0, :], coords[1, :], :] 28 | alpha = 1. - img_color[3] 29 | img[coords[0, :], coords[1, :], :] = img_color + pixels*alpha 30 | 31 | def save_img(img, path, filename): 32 | """ 33 | save image 34 | """ 35 | plt.imshow(img) 36 | plt.axes().set_aspect('equal') 37 | plt.axis('off') 38 | 39 | if not os.path.exists(path): 40 | os.makedirs(path) 41 | 42 | plt.savefig(path + '/' + filename, dpi=300, bbox_inches='tight') 43 | 44 | def show_img(img): 45 | """ 46 | show image 47 | """ 48 | plt.imshow(img) 49 | plt.axes().set_aspect('equal') 50 | plt.axis('off') 51 | plt.show() 52 | -------------------------------------------------------------------------------- /TPs/2.pylint/final_step/splinart/shapes/__init__.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | shape 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | from .base import line, circle 10 | -------------------------------------------------------------------------------- /TPs/2.pylint/final_step/splinart/shapes/base.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | base shape module 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | import numpy as np 10 | 11 | def circle(center, radius, npoints=50): 12 | """ 13 | return a circle 14 | """ 15 | theta = 2 * np.pi * np.linspace(0, 1, npoints) 16 | path = np.c_[center[0]+radius*np.cos(theta), center[1]+radius*np.sin(theta)] 17 | return theta, path 18 | 19 | def line(begin, end, ypos=0.5, npoints=50): 20 | """ 21 | return a line 22 | """ 23 | x = np.linspace(begin, end, npoints) 24 | y = ypos*np.ones(npoints) 25 | return np.c_[x, y] 26 | -------------------------------------------------------------------------------- /TPs/2.pylint/final_step/splinart/spline/__init__.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | spline 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | from .spline import spline 10 | from .splint import splint 11 | -------------------------------------------------------------------------------- /TPs/2.pylint/final_step/splinart/spline/spline.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | spline module 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | import numpy as np 10 | from six.moves import range 11 | 12 | def spline(xs, ys): 13 | """ 14 | return spline 15 | """ 16 | n = xs.shape[0] 17 | u_i = np.zeros_like(ys) 18 | y2s = np.zeros_like(ys) 19 | 20 | dif = np.diff(xs) 21 | sig = dif[:-1]/(xs[2:]-xs[:-2]) 22 | 23 | if ys.ndim == 2: 24 | dif = dif[:, np.newaxis] 25 | 26 | u_i[1:-1] = (ys[2:]- ys[1:-1])/dif[1:] - (ys[1:-1]-ys[:-2])/dif[:-1] 27 | 28 | for i in range(1, n-1): 29 | p_i = sig[i-1]*y2s[i-1] + 2. 30 | y2s[i] = (sig[i-1]-1)/p_i 31 | u_i[i] = (6*u_i[i]/(xs[i+1]-xs[i-1])-sig[i-1]*u_i[i-1])/p_i 32 | 33 | for i in range(n-2, -1, -1): 34 | y2s[i] = y2s[i]*y2s[i+1]+u_i[i] 35 | 36 | return y2s 37 | -------------------------------------------------------------------------------- /TPs/2.pylint/final_step/splinart/spline/splint.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | splint module 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | import numpy as np 10 | 11 | def splint(xs, ys, y2s, x, y): 12 | """ 13 | splint function 14 | """ 15 | khi = np.searchsorted(xs, x) 16 | klo = khi-1 17 | step = xs[khi] - xs[klo] 18 | x_right = ((xs[khi]-x)/step) 19 | x_left = ((x-xs[klo])/step) 20 | 21 | if y.ndim == 2: 22 | step = step[:, np.newaxis] 23 | x_right = x_right[:, np.newaxis] 24 | x_left = x_left[:, np.newaxis] 25 | 26 | y[:] = x_right*ys[klo]+x_left*ys[khi]+( 27 | (x_right**3-x_right)*y2s[klo]+ 28 | (x_left**3-x_left)*y2s[khi])*step**2/6 29 | -------------------------------------------------------------------------------- /TPs/2.pylint/step0/LICENSE: -------------------------------------------------------------------------------- 1 | New BSD License 2 | 3 | Copyright (c) 2017, the splinart Developers. 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, 7 | are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its contributors 17 | may be used to endorse or promote products derived from this software without 18 | specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /TPs/2.pylint/step0/demos/circle.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | import splinart as spl 8 | 9 | img_size, channels = 1000, 4 10 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 11 | 12 | theta, path = spl.circle([.5, .5], .3, npoints=40) 13 | 14 | def xs_func(): 15 | nsamples = 500 16 | return (np.random.random() + 2 * np.pi * np.linspace(0, 1, nsamples))%(2*np.pi) 17 | 18 | spl.update_img(img, path, xs_func, nrep=4000, x=theta, scale_value=.00005) 19 | 20 | spl.save_img(img, './output', 'circle.png') 21 | -------------------------------------------------------------------------------- /TPs/2.pylint/step0/demos/circles.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | from six.moves import range 8 | import splinart as spl 9 | 10 | img_size, channels = 1000, 4 11 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 12 | 13 | nb_circles = 10 14 | theta_circles = [] 15 | path_circles = [] 16 | color_circles = [] 17 | for i in range(nb_circles): 18 | radius = .1 + np.random.random()*.1 19 | center = .2 + np.random.random(2)*.6 20 | theta, path = spl.circle(center, radius, npoints=75) 21 | theta_circles.append(theta) 22 | path_circles.append(path) 23 | color = np.random.random(4)*.3 24 | color[-1] = 1. 25 | color_circles.append(color) 26 | 27 | def xs_func(): 28 | nsamples = 500 29 | return (np.random.random() + 2 * np.pi * np.linspace(0, 1, nsamples))%(2*np.pi) 30 | 31 | for i in range(nb_circles): 32 | img1 = np.ones_like(img) 33 | spl.update_img(img1, path_circles[i], xs_func, nrep=1000, scale_value=.00005, x=theta_circles[i], color=color_circles[i]) 34 | mask = img1 < 1. 35 | img[mask] += img1[mask] 36 | 37 | spl.save_img(img, './output', 'circles.png') 38 | -------------------------------------------------------------------------------- /TPs/2.pylint/step0/demos/line.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | import splinart as spl 8 | 9 | img_size, channels = 1000, 4 10 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 11 | 12 | def xs_func(): 13 | nsamples = 500 14 | return .001*np.random.random() + np.linspace(lo+.1,up-.1, nsamples) 15 | 16 | lo, up = .2, .8 17 | path = spl.line(lo, up, .5) 18 | 19 | spl.update_img(img, path, xs_func, nrep=1000, periodic=False) 20 | 21 | spl.save_img(img, "./output", "line.png") 22 | -------------------------------------------------------------------------------- /TPs/2.pylint/step0/demos/lines.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | from six.moves import range 8 | import splinart as spl 9 | 10 | img_size, channels = 1000, 4 11 | img = np.ones((img_size, img_size, channels)), dtype=np.float32) 12 | 13 | lo, up = .2, .8 14 | path = [] 15 | color_lines = [] 16 | npoints = 20 17 | for iy, y in enumerate(np.linspace(lo, up, 10)): 18 | npoints += 5 19 | path.append(spl.line(lo, up, y, npoints)) 20 | color = np.random.random(4)*.3 21 | color[-1] = 1. 22 | color_lines.append(color) 23 | 24 | def xs_func(): 25 | nsamples = 500 26 | return .001*np.random.random() + np.linspace(lo+.02,up-.02, nsamples) 27 | 28 | for i in range(len(path)): 29 | img1 = np.ones_like(img) 30 | spl.update_img(img1, path[i], xs_func, nrep=1000, periodic=False, color=color_lines[i]) 31 | mask = img1 < 1. 32 | img[mask] += img1[mask] 33 | 34 | spl.save_img(img, "./output", "lines.png") 35 | -------------------------------------------------------------------------------- /TPs/2.pylint/step0/recipes/meta.yaml: -------------------------------------------------------------------------------- 1 | {% set data = load_setup_py_data() %} 2 | 3 | package: 4 | name: splinart 5 | version: {{ data.get('version') }} 6 | 7 | source: 8 | path: ../ 9 | 10 | build: 11 | number: 0 12 | script: python setup.py install --single-version-externally-managed --record=record.txt 13 | 14 | requirements: 15 | build: 16 | - python 17 | - setuptools 18 | run: 19 | - python 20 | - numpy 21 | - matplotlib 22 | - six 23 | 24 | test: 25 | imports: 26 | - splinart 27 | 28 | about: 29 | home: http://github.com/gouarin/splinart 30 | license: BSD 31 | license_family: BSD 32 | license_file: '' 33 | summary: 'spline art generator' 34 | description: 'spline art generator' 35 | doc_url: '' 36 | dev_url: '' 37 | 38 | extra: 39 | recipe-maintainers: 'loic.gouarin@gmail.com' 40 | -------------------------------------------------------------------------------- /TPs/2.pylint/step0/scripts/__init__.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause -------------------------------------------------------------------------------- /TPs/2.pylint/step0/scripts/cli_splinart.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import splinart as spl 7 | import numpy as np 8 | import argparse 9 | 10 | def circle(img): 11 | def xs_func(): 12 | nsamples = 500 13 | return (np.random.random() + 2 * np.pi * np.linspace(0, 1, nsamples))%(2*np.pi) 14 | 15 | theta, path = spl.circle([.5, .5], .3, npoints=40) 16 | spl.update_img(img, path, xs_func, nrep=4000, x=theta, scale_value=.00005) 17 | 18 | def line(img): 19 | def xs_func(): 20 | nsamples = 500 21 | return .001*np.random.random() + np.linspace(lo+.1,up-.1, nsamples) 22 | 23 | lo, up = .2, .8 24 | path = spl.line(lo, up, .5) 25 | spl.update_img(img, path, xs_func, nrep=1000, periodic=False) 26 | 27 | def main(): 28 | parser = argparse.ArgumentParser(description="Splinart generator") 29 | parser.add_argument('-f', '--filename', type=str, 30 | help="filename where the output is stored", 31 | default='output.png') 32 | parser.add_argument('--path', type=str, 33 | help="path where to store the results", 34 | default='.') 35 | parser.add_argument('-s', '--shape', type=str, 36 | help='apply spline on this shape', 37 | default='circle', 38 | choices=['circle', 'line']) 39 | parser.add_argument('--show', 40 | help='show the result using matplotlib', 41 | action='store_true') 42 | args = parser.parse_args() 43 | 44 | img_size, channels = 1000, 4 45 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 46 | 47 | if args.shape == 'circle': 48 | circle(img) 49 | else: 50 | line(img) 51 | 52 | if args.show: 53 | spl.show_img(img) 54 | else: 55 | spl.save_img(img, args.path, args.filename) 56 | 57 | -------------------------------------------------------------------------------- /TPs/2.pylint/step0/setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal=1 -------------------------------------------------------------------------------- /TPs/2.pylint/step0/setup.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from setuptools import setup, find_packages 6 | 7 | CLASSIFIERS = [ 8 | "Development Status :: 3 - Alpha", 9 | "Intended Audience :: Science/Research", 10 | "Intended Audience :: Developers", 11 | "License :: OSI Approved :: BSD License", 12 | "Programming Language :: Python", 13 | "Programming Language :: Python :: 2", 14 | "Programming Language :: Python :: 2.7", 15 | "Programming Language :: Python :: 3", 16 | "Programming Language :: Python :: 3.4", 17 | "Programming Language :: Python :: 3.5", 18 | "Topic :: Software Development", 19 | "Topic :: Scientific/Engineering", 20 | "Operating System :: Microsoft :: Windows", 21 | "Operating System :: POSIX", 22 | "Operating System :: Unix", 23 | "Operating System :: MacOS" 24 | ] 25 | 26 | MAJOR = 0 27 | MINOR = 1 28 | PATCH = 1 29 | VERSION = "{}.{}.{}".format(MAJOR, MINOR, PATCH) 30 | 31 | with open("splinart/version.py", "w") as f: 32 | f.write("__version__ = '{}'\n".format(VERSION)) 33 | 34 | setup( 35 | name = "splinart", 36 | author = "loic.gouarin@gmail.com", 37 | description = "spline art generator", 38 | version = VERSION, 39 | license = "BSD", 40 | classifiers = CLASSIFIERS, 41 | packages = find_packages(exclude=["demos"]), 42 | install_requires = ["numpy", 43 | "matplotlib>=2", 44 | "six"], 45 | entry_points={ 'console_scripts': [ 46 | 'splinart=scripts.cli_splinart:main', 47 | ], 48 | }, 49 | ) -------------------------------------------------------------------------------- /TPs/2.pylint/step0/splinart/__init__.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | from .shapes import * 7 | from .compute import update_img 8 | from .draw import save_img, show_img -------------------------------------------------------------------------------- /TPs/2.pylint/step0/splinart/compute.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | from six.moves import range 8 | 9 | from .spline import spline, splint 10 | from .draw import draw_pixel 11 | 12 | def update_path(path, periodic=False, scale_value=0.00001): 13 | n = path.shape[0] 14 | scale = np.arange(n)*scale_value 15 | r = 1.0-2.0*np.random.random(n) 16 | noise = r*scale 17 | phi = np.random.random(n)*2*np.pi 18 | rnd = np.c_[np.cos(phi), np.sin(phi)] 19 | path += rnd*noise[:, np.newaxis] 20 | if periodic: 21 | path[-1] = path[0] 22 | 23 | def update_img(img, path, xs_func, 24 | x=None, 25 | nrep=300, 26 | periodic=True, 27 | scale_color = .005, 28 | color=[0.0, 0.41568627450980394, 0.61960784313725492, 1.], 29 | scale_value = .00001): 30 | 31 | xs = xs_func() 32 | 33 | if x is not None: 34 | ys = np.zeros((xs.size, 2)) 35 | else: 36 | ys = np.zeros(xs.size) 37 | 38 | for i in range(nrep): 39 | if x is not None: 40 | y2 = spline(x, path) 41 | xs = xs_func() 42 | splint(x, path, y2, xs, ys) 43 | draw_pixel(img, ys[:, 0], ys[:, 1], scale_color, color) 44 | else: 45 | y2 = spline(path[:, 0], path[:, 1]) 46 | xs = xs_func() 47 | splint(path[:, 0], path[:, 1], y2, xs, ys) 48 | draw_pixel(img, ys, xs, scale_color, color) 49 | update_path(path, scale_value=scale_value, periodic=periodic) 50 | -------------------------------------------------------------------------------- /TPs/2.pylint/step0/splinart/draw.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | import matplotlib.pyplot as plt 8 | import os 9 | 10 | def draw_pixel(img, xs, ys, scale_color=.0005, color=[0.0, 0.41568627450980394, 0.61960784313725492, 1.]): 11 | size = img.shape[0] 12 | newxs = np.floor(xs*size) 13 | xs_mask = np.logical_and(newxs>=0, newxs=0, newys 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | from .base import line, circle -------------------------------------------------------------------------------- /TPs/2.pylint/step0/splinart/shapes/base.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | 8 | def circle(center, radius, npoints = 50): 9 | theta = 2 * np.pi * np.linspace(0, 1, npoints) 10 | path = np.c_[center[0]+radius*np.cos(theta), center[1]+radius*np.sin(theta)] 11 | return theta, path 12 | 13 | def line(begin, end, ypos=0.5, npoints = 50): 14 | x = np.linspace(begin, end, npoints) 15 | yy = ypos*np.ones(npoints) 16 | return np.c_[x, yy] 17 | -------------------------------------------------------------------------------- /TPs/2.pylint/step0/splinart/spline/__init__.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | from .spline import spline 7 | from .splint import splint 8 | -------------------------------------------------------------------------------- /TPs/2.pylint/step0/splinart/spline/spline.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | from six.moves import range 8 | 9 | def spline(x, y): 10 | n = x.shape[0] 11 | u = np.zeros_like(y) 12 | y2 = np.zeros_like(y) 13 | 14 | dif = np.diff(x) 15 | sig = dif[:-1]/(x[2:]-x[:-2]) 16 | 17 | if y.ndim == 2: 18 | dif = dif[:, np.newaxis] 19 | 20 | u[1:-1] = (y[2:]- y[1:-1])/dif[1:] - (y[1:-1]-y[:-2])/dif[:-1] 21 | 22 | for i in range(1, n-1): 23 | p = sig[i-1]*y2[i-1] + 2. 24 | y2[i] = (sig[i-1]-1)/p 25 | u[i] = (6*u[i]/(x[i+1]-x[i-1])-sig[i-1]*u[i-1])/p 26 | 27 | for i in range(n-2, -1, -1): 28 | y2[i] = y2[i]*y2[i+1]+u[i] 29 | 30 | return y2 31 | -------------------------------------------------------------------------------- /TPs/2.pylint/step0/splinart/spline/splint.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | 8 | def splint(xa, ya, y2a, x, y): 9 | khi = np.searchsorted(xa, x) 10 | klo = khi-1 11 | h = xa[khi] - xa[klo] 12 | a = ((xa[khi]-x)/h) 13 | b = ((x-xa[klo])/h) 14 | 15 | if y.ndim == 2: 16 | h = h[:, np.newaxis] 17 | a = a[:, np.newaxis] 18 | b = b[:, np.newaxis] 19 | 20 | y[:] = a*ya[klo]+b*ya[khi]+((a**3-a)*y2a[klo]+(b**3-b)*y2a[khi])*h**2/6 21 | -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/LICENSE: -------------------------------------------------------------------------------- 1 | New BSD License 2 | 3 | Copyright (c) 2017, the splinart Developers. 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, 7 | are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its contributors 17 | may be used to endorse or promote products derived from this software without 18 | specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/demos/circle.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | from six.moves import range 8 | import splinart as spl 9 | 10 | img_size, channels = 1000, 4 11 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 12 | 13 | theta, path = spl.circle([.5, .5], .3, npoints=40) 14 | 15 | def xs_func(): 16 | nsamples = 500 17 | return (np.random.random() + 2 * np.pi * np.linspace(0, 1, nsamples))%(2*np.pi) 18 | 19 | spl.update_img(img, path, xs_func, nrep=4000, x=theta, scale_value=.00005) 20 | 21 | spl.save_img(img, './output', 'circle.png') 22 | -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/demos/circles.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | from six.moves import range 8 | import splinart as spl 9 | 10 | img_size, channels = 1000, 4 11 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 12 | 13 | nb_circles = 10 14 | theta_circles = [] 15 | path_circles = [] 16 | color_circles = [] 17 | for i in range(nb_circles): 18 | radius = .1 + np.random.random()*.1 19 | center = .2 + np.random.random(2)*.6 20 | theta, path = spl.circle(center, radius, npoints=75) 21 | theta_circles.append(theta) 22 | path_circles.append(path) 23 | color = np.random.random(4)*.3 24 | color[-1] = 1. 25 | color_circles.append(color) 26 | 27 | def xs_func(): 28 | nsamples = 500 29 | return (np.random.random() + 2 * np.pi * np.linspace(0, 1, nsamples))%(2*np.pi) 30 | 31 | for i in range(nb_circles): 32 | img1 = np.ones_like(img) 33 | spl.update_img(img1, path_circles[i], xs_func, nrep=1000, scale_value=.00005, x=theta_circles[i], color=color_circles[i]) 34 | mask = img1 < 1. 35 | img[mask] += img1[mask] 36 | 37 | spl.save_img(img, './output', 'circles.png') 38 | -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/demos/line.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | from six.moves import range 8 | import splinart as spl 9 | 10 | img_size, channels = 1000, 4 11 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 12 | 13 | def xs_func(): 14 | nsamples = 500 15 | return .001*np.random.random() + np.linspace(lo+.1,up-.1, nsamples) 16 | 17 | lo, up = .2, .8 18 | path = spl.line(lo, up, .5) 19 | 20 | spl.update_img(img, path, xs_func, nrep=1000, periodic=False) 21 | 22 | spl.save_img(img, "./output", "line.png") 23 | -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/demos/lines.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | from six.moves import range 8 | import splinart as spl 9 | 10 | img_size, channels = 1000, 4 11 | img = np.ones((img_size, img_size, channels)), dtype=np.float32) 12 | 13 | lo, up = .2, .8 14 | path = [] 15 | color_lines = [] 16 | npoints = 20 17 | for iy, y in enumerate(np.linspace(lo, up, 10)): 18 | npoints += 5 19 | path.append(spl.line(lo, up, y, npoints)) 20 | color = np.random.random(4)*.3 21 | color[-1] = 1. 22 | color_lines.append(color) 23 | 24 | def xs_func(): 25 | nsamples = 500 26 | return .001*np.random.random() + np.linspace(lo+.02,up-.02, nsamples) 27 | 28 | for i in range(len(path)): 29 | img1 = np.ones_like(img) 30 | spl.update_img(img1, path[i], xs_func, nrep=1000, periodic=False, color=color_lines[i]) 31 | mask = img1 < 1. 32 | img[mask] += img1[mask] 33 | 34 | spl.save_img(img, "./output", "lines.png") 35 | -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/doc/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SPHINXPROJ = splinart 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/doc/api/modules.rst: -------------------------------------------------------------------------------- 1 | splinart 2 | ======== 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | splinart 8 | -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/doc/api/splinart.rst: -------------------------------------------------------------------------------- 1 | splinart package 2 | ================ 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | 9 | splinart.shapes 10 | splinart.spline 11 | 12 | Submodules 13 | ---------- 14 | 15 | splinart\.color module 16 | ---------------------- 17 | 18 | .. automodule:: splinart.color 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | splinart\.compute module 24 | ------------------------ 25 | 26 | .. automodule:: splinart.compute 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | splinart\.draw module 32 | --------------------- 33 | 34 | .. automodule:: splinart.draw 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | splinart\.version module 40 | ------------------------ 41 | 42 | .. automodule:: splinart.version 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | 47 | 48 | Module contents 49 | --------------- 50 | 51 | .. automodule:: splinart 52 | :members: 53 | :undoc-members: 54 | :show-inheritance: 55 | -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/doc/api/splinart.shapes.rst: -------------------------------------------------------------------------------- 1 | splinart\.shapes package 2 | ======================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | splinart\.shapes\.base module 8 | ----------------------------- 9 | 10 | .. automodule:: splinart.shapes.base 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | 16 | Module contents 17 | --------------- 18 | 19 | .. automodule:: splinart.shapes 20 | :members: 21 | :undoc-members: 22 | :show-inheritance: 23 | -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/doc/api/splinart.spline.rst: -------------------------------------------------------------------------------- 1 | splinart\.spline package 2 | ======================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | splinart\.spline\.spline module 8 | ------------------------------- 9 | 10 | .. automodule:: splinart.spline.spline 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | splinart\.spline\.splint module 16 | ------------------------------- 17 | 18 | .. automodule:: splinart.spline.splint 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | 24 | Module contents 25 | --------------- 26 | 27 | .. automodule:: splinart.spline 28 | :members: 29 | :undoc-members: 30 | :show-inheritance: 31 | -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/doc/index.rst: -------------------------------------------------------------------------------- 1 | .. splinart documentation master file, created by 2 | sphinx-quickstart on Fri Nov 17 10:27:27 2017. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to splinart's documentation! 7 | ==================================== 8 | 9 | splinart is a package used for a tutorial which explains how to do the Python packaging using 10 | 11 | - `PyPi `_ 12 | - `conda build `_ 13 | - `pytest `_ 14 | - `Pylint `_ 15 | - `Sphinx `_ 16 | 17 | And automate the process to distribute this package using github. 18 | 19 | The original idea of splinart comes from the great `invonvergent `_ website. 20 | 21 | If you want to install splinart:: 22 | 23 | pip install splinart 24 | 25 | or:: 26 | 27 | conda install -c gouarin splinart 28 | 29 | User manual 30 | =========== 31 | .. toctree:: 32 | :maxdepth: 2 33 | 34 | spline 35 | 36 | Tutorial 37 | ======== 38 | .. toctree:: 39 | :maxdepth: 2 40 | 41 | notebooks/circle 42 | 43 | Reference manual 44 | ================ 45 | 46 | .. toctree:: 47 | :maxdepth: 2 48 | 49 | api/modules 50 | 51 | Indices and tables 52 | ================== 53 | 54 | * :ref:`genindex` 55 | * :ref:`modindex` 56 | * :ref:`search` 57 | -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/doc/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | set SPHINXPROJ=splinart 13 | 14 | if "%1" == "" goto help 15 | 16 | %SPHINXBUILD% >NUL 2>NUL 17 | if errorlevel 9009 ( 18 | echo. 19 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 20 | echo.installed, then set the SPHINXBUILD environment variable to point 21 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 22 | echo.may add the Sphinx directory to PATH. 23 | echo. 24 | echo.If you don't have Sphinx installed, grab it from 25 | echo.http://sphinx-doc.org/ 26 | exit /b 1 27 | ) 28 | 29 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 30 | goto end 31 | 32 | :help 33 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 34 | 35 | :end 36 | popd 37 | -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/recipes/meta.yaml: -------------------------------------------------------------------------------- 1 | {% set data = load_setup_py_data() %} 2 | 3 | package: 4 | name: splinart 5 | version: {{ data.get('version') }} 6 | 7 | source: 8 | path: ../ 9 | 10 | build: 11 | number: 0 12 | script: python setup.py install --single-version-externally-managed --record=record.txt 13 | 14 | requirements: 15 | build: 16 | - python 17 | - setuptools 18 | run: 19 | - python 20 | - numpy 21 | - matplotlib 22 | - six 23 | 24 | test: 25 | imports: 26 | - splinart 27 | 28 | about: 29 | home: http://github.com/gouarin/splinart 30 | license: BSD 31 | license_family: BSD 32 | license_file: '' 33 | summary: 'spline art generator' 34 | description: 'spline art generator' 35 | doc_url: '' 36 | dev_url: '' 37 | 38 | extra: 39 | recipe-maintainers: 'loic.gouarin@gmail.com' 40 | -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/scripts/__init__.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal=1 -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/setup.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from setuptools import setup, find_packages 6 | 7 | CLASSIFIERS = [ 8 | "Development Status :: 3 - Alpha", 9 | "Intended Audience :: Science/Research", 10 | "Intended Audience :: Developers", 11 | "License :: OSI Approved :: BSD License", 12 | "Programming Language :: Python", 13 | "Programming Language :: Python :: 2", 14 | "Programming Language :: Python :: 2.7", 15 | "Programming Language :: Python :: 3", 16 | "Programming Language :: Python :: 3.4", 17 | "Programming Language :: Python :: 3.5", 18 | "Topic :: Software Development", 19 | "Topic :: Scientific/Engineering", 20 | "Operating System :: Microsoft :: Windows", 21 | "Operating System :: POSIX", 22 | "Operating System :: Unix", 23 | "Operating System :: MacOS" 24 | ] 25 | 26 | name = "splinart" 27 | 28 | MAJOR = 0 29 | MINOR = 1 30 | MAINTENANCE = 2 31 | VERSION = "{}.{}.{}".format(MAJOR, MINOR, MAINTENANCE) 32 | 33 | with open("splinart/version.py", "w") as f: 34 | f.write("__version__ = '{}'\n".format(VERSION)) 35 | 36 | setup( 37 | name = "splinart", 38 | author = "loic.gouarin@gmail.com", 39 | description = "spline art generator", 40 | version = VERSION, 41 | license = "BSD", 42 | classifiers = CLASSIFIERS, 43 | packages = find_packages(exclude=["demos"]), 44 | install_requires = ["numpy", 45 | "matplotlib==2.1", 46 | "six"], 47 | entry_points={ 'console_scripts': [ 48 | 'splinart=scripts.cli_splinart:main', 49 | ], 50 | }, 51 | ) -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/splinart/__init__.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | Splinart package 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | from .shapes import circle, line 10 | from .compute import update_img 11 | from .draw import save_img, show_img 12 | -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/splinart/color.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | Define the default color of the output. 7 | """ 8 | DEFAULT_COLOR = (0.0, 0.41568627450980394, 0.61960784313725492, 1.) 9 | -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/splinart/shapes/__init__.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | Shape package 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | from .base import line, circle 10 | -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/splinart/shapes/base.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | Define basic shapes. 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | import numpy as np 10 | 11 | def circle(center, radius, npoints=50): 12 | """ 13 | Discretization of a circle. 14 | 15 | Parameters 16 | ---------- 17 | center : list(2) 18 | 2d coordinates of the center. 19 | radius : float 20 | Radius of the circle. 21 | npoints : int 22 | Number of discretization points (the default value is 50). 23 | 24 | Returns 25 | ------- 26 | np.ndarray 27 | The theta angle. 28 | np.ndarray 29 | The 2d coordinates of the circle. 30 | 31 | """ 32 | theta = 2 * np.pi * np.linspace(0, 1, npoints) 33 | path = np.c_[center[0]+radius*np.cos(theta), center[1]+radius*np.sin(theta)] 34 | return theta, path 35 | 36 | def line(begin, end, ypos=0.5, npoints=50): 37 | """ 38 | Discretization of a horizontal line. 39 | 40 | Parameters 41 | ---------- 42 | 43 | begin : float 44 | The left point of the line. 45 | 46 | end : float 47 | The right point of the line. 48 | 49 | ypos : float 50 | The position of the y coordinate (the default value is 0.5). 51 | 52 | npoints : int 53 | Number of discretization points (the default value is 50). 54 | 55 | Returns 56 | ------- 57 | np.ndarray 58 | The 2d coordinates of the line. 59 | 60 | """ 61 | x = np.linspace(begin, end, npoints) 62 | y = ypos*np.ones(npoints) 63 | return np.c_[x, y] 64 | -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/splinart/spline/__init__.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | Spline package 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | from .spline import spline 10 | from .splint import splint 11 | -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/splinart/spline/spline.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | Cubic spline 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | import numpy as np 10 | from six.moves import range 11 | 12 | def spline(xs, ys): 13 | """ 14 | Return the second derivative of a cubic spline. 15 | 16 | Parameters 17 | ---------- 18 | 19 | xs : np.ndarray 20 | The x coordinate of the cubic spline. 21 | 22 | ys : np.ndarray 23 | The y coordinate of the cubic spline. 24 | 25 | Returns 26 | ------- 27 | np.ndarray 28 | The second derivative of the cubic spline. 29 | 30 | """ 31 | n = xs.shape[0] 32 | u_i = np.zeros_like(ys) 33 | y2s = np.zeros_like(ys) 34 | 35 | dif = np.diff(xs) 36 | sig = dif[:-1]/(xs[2:]-xs[:-2]) 37 | 38 | if ys.ndim == 2: 39 | dif = dif[:, np.newaxis] 40 | 41 | u_i[1:-1] = (ys[2:]- ys[1:-1])/dif[1:] - (ys[1:-1]-ys[:-2])/dif[:-1] 42 | 43 | for i in range(1, n-1): 44 | p_i = sig[i-1]*y2s[i-1] + 2. 45 | y2s[i] = (sig[i-1]-1)/p_i 46 | u_i[i] = (6*u_i[i]/(xs[i+1]-xs[i-1])-sig[i-1]*u_i[i-1])/p_i 47 | 48 | for i in range(n-2, -1, -1): 49 | y2s[i] = y2s[i]*y2s[i+1]+u_i[i] 50 | 51 | return y2s 52 | -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/splinart/spline/splint.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | Integration of a cubic spline. 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | import numpy as np 10 | 11 | def splint(xs, ys, y2s, x, y): 12 | """ 13 | Evaluate a sample on a cubic pline. 14 | 15 | Parameters 16 | ---------- 17 | xs 18 | The x coordinates of the cubic spline. 19 | ys 20 | The y coordinates of the cubic spline. 21 | y2s 22 | The second derivative of the cubic spline. 23 | x 24 | The sample where to evaluation the cubic spline. 25 | y 26 | The y coordinates of the sample. 27 | 28 | See also 29 | -------- 30 | splinart.spline.spline 31 | 32 | """ 33 | khi = np.searchsorted(xs, x) 34 | klo = khi-1 35 | step = xs[khi] - xs[klo] 36 | x_right = ((xs[khi]-x)/step) 37 | x_left = ((x-xs[klo])/step) 38 | 39 | if y.ndim == 2: 40 | step = step[:, np.newaxis] 41 | x_right = x_right[:, np.newaxis] 42 | x_left = x_left[:, np.newaxis] 43 | 44 | y[:] = x_right*ys[klo]+x_left*ys[khi]+( 45 | (x_right**3-x_right)*y2s[klo]+ 46 | (x_left**3-x_left)*y2s[khi])*step**2/6 47 | -------------------------------------------------------------------------------- /TPs/3.sphinx/final_step/splinart/version.py: -------------------------------------------------------------------------------- 1 | __version__ = '0.1.2' 2 | -------------------------------------------------------------------------------- /TPs/3.sphinx/step0/LICENSE: -------------------------------------------------------------------------------- 1 | New BSD License 2 | 3 | Copyright (c) 2017, the splinart Developers. 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, 7 | are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its contributors 17 | may be used to endorse or promote products derived from this software without 18 | specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /TPs/3.sphinx/step0/demos/circle.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | import splinart as spl 8 | 9 | img_size, channels = 1000, 4 10 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 11 | 12 | theta, path = spl.circle([.5, .5], .3, npoints=40) 13 | 14 | def xs_func(): 15 | nsamples = 500 16 | return (np.random.random() + 2 * np.pi * np.linspace(0, 1, nsamples))%(2*np.pi) 17 | 18 | spl.update_img(img, path, xs_func, nrep=4000, x=theta, scale_value=.00005) 19 | 20 | spl.save_img(img, './output', 'circle.png') 21 | -------------------------------------------------------------------------------- /TPs/3.sphinx/step0/demos/circles.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | from six.moves import range 8 | import splinart as spl 9 | 10 | img_size, channels = 1000, 4 11 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 12 | 13 | nb_circles = 10 14 | theta_circles = [] 15 | path_circles = [] 16 | color_circles = [] 17 | for i in range(nb_circles): 18 | radius = .1 + np.random.random()*.1 19 | center = .2 + np.random.random(2)*.6 20 | theta, path = spl.circle(center, radius, npoints=75) 21 | theta_circles.append(theta) 22 | path_circles.append(path) 23 | color = np.random.random(4)*.3 24 | color[-1] = 1. 25 | color_circles.append(color) 26 | 27 | def xs_func(): 28 | nsamples = 500 29 | return (np.random.random() + 2 * np.pi * np.linspace(0, 1, nsamples))%(2*np.pi) 30 | 31 | for i in range(nb_circles): 32 | img1 = np.ones_like(img) 33 | spl.update_img(img1, path_circles[i], xs_func, nrep=1000, scale_value=.00005, x=theta_circles[i], color=color_circles[i]) 34 | mask = img1 < 1. 35 | img[mask] += img1[mask] 36 | 37 | spl.save_img(img, './output', 'circles.png') 38 | -------------------------------------------------------------------------------- /TPs/3.sphinx/step0/demos/line.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | import splinart as spl 8 | 9 | img_size, channels = 1000, 4 10 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 11 | 12 | def xs_func(): 13 | nsamples = 500 14 | return .001*np.random.random() + np.linspace(lo+.1,up-.1, nsamples) 15 | 16 | lo, up = .2, .8 17 | path = spl.line(lo, up, .5) 18 | 19 | spl.update_img(img, path, xs_func, nrep=1000, periodic=False) 20 | 21 | spl.save_img(img, "./output", "line.png") 22 | -------------------------------------------------------------------------------- /TPs/3.sphinx/step0/demos/lines.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from __future__ import print_function, division, absolute_import 6 | import numpy as np 7 | from six.moves import range 8 | import splinart as spl 9 | 10 | img_size, channels = 1000, 4 11 | img = np.ones((img_size, img_size, channels)), dtype=np.float32) 12 | 13 | lo, up = .2, .8 14 | path = [] 15 | color_lines = [] 16 | npoints = 20 17 | for iy, y in enumerate(np.linspace(lo, up, 10)): 18 | npoints += 5 19 | path.append(spl.line(lo, up, y, npoints)) 20 | color = np.random.random(4)*.3 21 | color[-1] = 1. 22 | color_lines.append(color) 23 | 24 | def xs_func(): 25 | nsamples = 500 26 | return .001*np.random.random() + np.linspace(lo+.02,up-.02, nsamples) 27 | 28 | for i in range(len(path)): 29 | img1 = np.ones_like(img) 30 | spl.update_img(img1, path[i], xs_func, nrep=1000, periodic=False, color=color_lines[i]) 31 | mask = img1 < 1. 32 | img[mask] += img1[mask] 33 | 34 | spl.save_img(img, "./output", "lines.png") 35 | -------------------------------------------------------------------------------- /TPs/3.sphinx/step0/recipes/meta.yaml: -------------------------------------------------------------------------------- 1 | {% set data = load_setup_py_data() %} 2 | 3 | package: 4 | name: splinart 5 | version: {{ data.get('version') }} 6 | 7 | source: 8 | path: ../ 9 | 10 | build: 11 | number: 0 12 | script: python setup.py install --single-version-externally-managed --record=record.txt 13 | 14 | requirements: 15 | build: 16 | - python 17 | - setuptools 18 | run: 19 | - python 20 | - numpy 21 | - matplotlib 22 | - six 23 | 24 | test: 25 | imports: 26 | - splinart 27 | 28 | about: 29 | home: http://github.com/gouarin/splinart 30 | license: BSD 31 | license_family: BSD 32 | license_file: '' 33 | summary: 'spline art generator' 34 | description: 'spline art generator' 35 | doc_url: '' 36 | dev_url: '' 37 | 38 | extra: 39 | recipe-maintainers: 'loic.gouarin@gmail.com' 40 | -------------------------------------------------------------------------------- /TPs/3.sphinx/step0/scripts/__init__.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause -------------------------------------------------------------------------------- /TPs/3.sphinx/step0/setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal=1 -------------------------------------------------------------------------------- /TPs/3.sphinx/step0/setup.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from setuptools import setup, find_packages 6 | 7 | CLASSIFIERS = [ 8 | "Development Status :: 3 - Alpha", 9 | "Intended Audience :: Science/Research", 10 | "Intended Audience :: Developers", 11 | "License :: OSI Approved :: BSD License", 12 | "Programming Language :: Python", 13 | "Programming Language :: Python :: 2", 14 | "Programming Language :: Python :: 2.7", 15 | "Programming Language :: Python :: 3", 16 | "Programming Language :: Python :: 3.4", 17 | "Programming Language :: Python :: 3.5", 18 | "Topic :: Software Development", 19 | "Topic :: Scientific/Engineering", 20 | "Operating System :: Microsoft :: Windows", 21 | "Operating System :: POSIX", 22 | "Operating System :: Unix", 23 | "Operating System :: MacOS" 24 | ] 25 | 26 | name = "splinart" 27 | 28 | MAJOR = 0 29 | MINOR = 1 30 | PATCH = 2 31 | VERSION = "{}.{}.{}".format(MAJOR, MINOR, PATCH) 32 | 33 | with open("splinart/version.py", "w") as f: 34 | f.write("__version__ = '{}'\n".format(VERSION)) 35 | 36 | setup( 37 | name = "splinart", 38 | author = "loic.gouarin@gmail.com", 39 | description = "spline art generator", 40 | version = VERSION, 41 | license = "BSD", 42 | classifiers = CLASSIFIERS, 43 | packages = find_packages(exclude=["demos"]), 44 | install_requires = ["numpy", 45 | "matplotlib>=2", 46 | "six"], 47 | entry_points={ 'console_scripts': [ 48 | 'splinart=scripts.cli_splinart:main', 49 | ], 50 | }, 51 | ) -------------------------------------------------------------------------------- /TPs/3.sphinx/step0/splinart/__init__.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | Splinart package 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | from .shapes import circle, line 10 | from .compute import update_img 11 | from .draw import save_img, show_img 12 | -------------------------------------------------------------------------------- /TPs/3.sphinx/step0/splinart/color.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | Define the default color of the output. 7 | """ 8 | DEFAULT_COLOR = (0.0, 0.41568627450980394, 0.61960784313725492, 1.) 9 | -------------------------------------------------------------------------------- /TPs/3.sphinx/step0/splinart/shapes/__init__.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | Shape package 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | from .base import line, circle 10 | -------------------------------------------------------------------------------- /TPs/3.sphinx/step0/splinart/shapes/base.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | Define basic shapes. 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | import numpy as np 10 | 11 | def circle(center, radius, npoints=50): 12 | """ 13 | Discretization of a circle. 14 | 15 | Parameters 16 | ---------- 17 | center : list(2) 18 | 2d coordinates of the center. 19 | radius : float 20 | Radius of the circle. 21 | npoints : int 22 | Number of discretization points (the default value is 50). 23 | 24 | Returns 25 | ------- 26 | np.ndarray 27 | The theta angle. 28 | np.ndarray 29 | The 2d coordinates of the circle. 30 | 31 | """ 32 | theta = 2 * np.pi * np.linspace(0, 1, npoints) 33 | path = np.c_[center[0]+radius*np.cos(theta), center[1]+radius*np.sin(theta)] 34 | return theta, path 35 | 36 | def line(begin, end, ypos=0.5, npoints=50): 37 | """ 38 | Discretization of a horizontal line. 39 | 40 | Parameters 41 | ---------- 42 | 43 | begin : float 44 | The left point of the line. 45 | 46 | end : float 47 | The right point of the line. 48 | 49 | ypos : float 50 | The position of the y coordinate (the default value is 0.5). 51 | 52 | npoints : int 53 | Number of discretization points (the default value is 50). 54 | 55 | Returns 56 | ------- 57 | np.ndarray 58 | The 2d coordinates of the line. 59 | 60 | """ 61 | x = np.linspace(begin, end, npoints) 62 | y = ypos*np.ones(npoints) 63 | return np.c_[x, y] 64 | -------------------------------------------------------------------------------- /TPs/3.sphinx/step0/splinart/spline/__init__.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | Spline package 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | from .spline import spline 10 | from .splint import splint 11 | -------------------------------------------------------------------------------- /TPs/3.sphinx/step0/splinart/spline/spline.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | Cubic spline 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | import numpy as np 10 | from six.moves import range 11 | 12 | def spline(xs, ys): 13 | """ 14 | Return the second derivative of a cubic spline. 15 | 16 | Parameters 17 | ---------- 18 | 19 | xs : np.ndarray 20 | The x coordinate of the cubic spline. 21 | 22 | ys : np.ndarray 23 | The y coordinate of the cubic spline. 24 | 25 | Returns 26 | ------- 27 | np.ndarray 28 | The second derivative of the cubic spline. 29 | 30 | """ 31 | n = xs.shape[0] 32 | u_i = np.zeros_like(ys) 33 | y2s = np.zeros_like(ys) 34 | 35 | dif = np.diff(xs) 36 | sig = dif[:-1]/(xs[2:]-xs[:-2]) 37 | 38 | if ys.ndim == 2: 39 | dif = dif[:, np.newaxis] 40 | 41 | u_i[1:-1] = (ys[2:]- ys[1:-1])/dif[1:] - (ys[1:-1]-ys[:-2])/dif[:-1] 42 | 43 | for i in range(1, n-1): 44 | p_i = sig[i-1]*y2s[i-1] + 2. 45 | y2s[i] = (sig[i-1]-1)/p_i 46 | u_i[i] = (6*u_i[i]/(xs[i+1]-xs[i-1])-sig[i-1]*u_i[i-1])/p_i 47 | 48 | for i in range(n-2, -1, -1): 49 | y2s[i] = y2s[i]*y2s[i+1]+u_i[i] 50 | 51 | return y2s 52 | -------------------------------------------------------------------------------- /TPs/3.sphinx/step0/splinart/spline/splint.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | Integration of a cubic spline. 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | import numpy as np 10 | 11 | def splint(xs, ys, y2s, x, y): 12 | """ 13 | Evaluate a sample on a cubic pline. 14 | 15 | Parameters 16 | ---------- 17 | xs 18 | The x coordinates of the cubic spline. 19 | ys 20 | The y coordinates of the cubic spline. 21 | y2s 22 | The second derivative of the cubic spline. 23 | x 24 | The sample where to evaluation the cubic spline. 25 | y 26 | The y coordinates of the sample. 27 | 28 | See also 29 | -------- 30 | splinart.spline.spline 31 | 32 | """ 33 | khi = np.searchsorted(xs, x) 34 | klo = khi-1 35 | step = xs[khi] - xs[klo] 36 | x_right = ((xs[khi]-x)/step) 37 | x_left = ((x-xs[klo])/step) 38 | 39 | if y.ndim == 2: 40 | step = step[:, np.newaxis] 41 | x_right = x_right[:, np.newaxis] 42 | x_left = x_left[:, np.newaxis] 43 | 44 | y[:] = x_right*ys[klo]+x_left*ys[khi]+( 45 | (x_right**3-x_right)*y2s[klo]+ 46 | (x_left**3-x_left)*y2s[khi])*step**2/6 47 | -------------------------------------------------------------------------------- /TPs/3.sphinx/step0/splinart/version.py: -------------------------------------------------------------------------------- 1 | __version__ = '0.1.2' 2 | -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/.coverage: -------------------------------------------------------------------------------- 1 | !coverage.py: This is a private format, don't read it directly!{"lines":{"/home/loic/Formations/2017/python/cnrs/TPs/4.pytest/final_step/splinart/__init__.py":[7,8,9,10,11],"/home/loic/Formations/2017/python/cnrs/TPs/4.pytest/final_step/splinart/shapes/__init__.py":[7,8,9],"/home/loic/Formations/2017/python/cnrs/TPs/4.pytest/final_step/splinart/shapes/base.py":[7,8,9,11,36,32,33,34,61,62,63],"/home/loic/Formations/2017/python/cnrs/TPs/4.pytest/final_step/splinart/compute.py":[7,8,10,11,13,14,15,17,53,54,55,56,57,58,101,103,104,108,109,110,111,112,113,119,41,42,43,44,45,46,47,48,49],"/home/loic/Formations/2017/python/cnrs/TPs/4.pytest/final_step/splinart/spline/__init__.py":[7,8,9,10],"/home/loic/Formations/2017/python/cnrs/TPs/4.pytest/final_step/splinart/spline/spline.py":[7,8,9,10,12,31,32,33,35,36,38,39,41,43,44,45,46,48,49,51],"/home/loic/Formations/2017/python/cnrs/TPs/4.pytest/final_step/splinart/spline/splint.py":[7,8,9,11,33,34,35,36,37,39,40,41,42,44,46],"/home/loic/Formations/2017/python/cnrs/TPs/4.pytest/final_step/splinart/draw.py":[8,9,10,11,12,13,15,16,51,77,39,40,41,42,43,44,45,46,47,48,49,68,69,70,72,75],"/home/loic/Formations/2017/python/cnrs/TPs/4.pytest/final_step/splinart/color.py":[7,8],"/home/loic/Formations/2017/python/cnrs/TPs/4.pytest/final_step/splinart/version.py":[]}} -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/LICENSE: -------------------------------------------------------------------------------- 1 | New BSD License 2 | 3 | Copyright (c) 2017, the splinart Developers. 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, 7 | are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its contributors 17 | may be used to endorse or promote products derived from this software without 18 | specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/demos/circle.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from six.moves import range 3 | import splinart as spl 4 | 5 | np.random.seed(42) 6 | img_size, channels = 1000, 4 7 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 8 | 9 | theta, path = spl.circle([.5, .5], .3, npoints=40) 10 | 11 | def xs_func(): 12 | nsamples = 500 13 | return (np.random.random() + 2 * np.pi * np.linspace(0, 1, nsamples))%(2*np.pi) 14 | 15 | spl.update_img(img, path, xs_func, nrep=4000, x=theta, scale_value=.00005) 16 | 17 | spl.save_img(img, './output', 'circle.png') 18 | -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/demos/circles.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from six.moves import range 3 | import splinart as spl 4 | 5 | img_size, channels = 1000, 4 6 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 7 | 8 | nb_circles = 10 9 | theta_circles = [] 10 | path_circles = [] 11 | color_circles = [] 12 | for i in range(nb_circles): 13 | radius = .1 + np.random.random()*.1 14 | center = .2 + np.random.random(2)*.6 15 | theta, path = spl.circle(center, radius, npoints=75) 16 | theta_circles.append(theta) 17 | path_circles.append(path) 18 | color = np.random.random(4)*.3 19 | color[-1] = 1. 20 | color_circles.append(color) 21 | 22 | def xs_func(): 23 | nsamples = 500 24 | return (np.random.random() + 2 * np.pi * np.linspace(0, 1, nsamples))%(2*np.pi) 25 | 26 | for i in range(nb_circles): 27 | img1 = np.ones_like(img) 28 | spl.update_img(img1, path_circles[i], xs_func, nrep=1000, scale_value=.00005, x=theta_circles[i], color=color_circles[i]) 29 | mask = img1 < 1. 30 | img[mask] += img1[mask] 31 | 32 | spl.save_img(img, './output', 'circles.png') 33 | -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/demos/line.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from six.moves import range 3 | import splinart as spl 4 | 5 | img_size, channels = 1000, 4 6 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 7 | 8 | def xs_func(): 9 | nsamples = 500 10 | return .001*np.random.random() + np.linspace(lo+.1,up-.1, nsamples) 11 | 12 | lo, up = .2, .8 13 | path = spl.line(lo, up, .5) 14 | 15 | spl.update_img(img, path, xs_func, nrep=1000, periodic=False) 16 | 17 | spl.save_img(img, "./output", "line.png") 18 | -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/demos/lines.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from six.moves import range 3 | import splinart as spl 4 | 5 | img_size, channels = 1000, 4 6 | img = np.ones((img_size, img_size, channels))#, dtype=np.float32) 7 | 8 | lo, up = .2, .8 9 | path = [] 10 | color_lines = [] 11 | npoints = 20 12 | for iy, y in enumerate(np.linspace(lo, up, 10)): 13 | npoints += 5 14 | path.append(spl.line(lo, up, y, npoints)) 15 | color = np.random.random(4)*.3 16 | color[-1] = 1. 17 | color_lines.append(color) 18 | 19 | def xs_func(): 20 | nsamples = 500 21 | return .001*np.random.random() + np.linspace(lo+.02,up-.02, nsamples) 22 | 23 | for i in range(len(path)): 24 | img1 = np.ones_like(img) 25 | spl.update_img(img1, path[i], xs_func, nrep=1000, periodic=False, color=color_lines[i]) 26 | mask = img1 < 1. 27 | img[mask] += img1[mask] 28 | 29 | spl.save_img(img, "./output", "lines.png") 30 | -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/doc/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SPHINXPROJ = splinart 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/doc/api/modules.rst: -------------------------------------------------------------------------------- 1 | splinart 2 | ======== 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | splinart 8 | -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/doc/api/splinart.rst: -------------------------------------------------------------------------------- 1 | splinart package 2 | ================ 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | 9 | splinart.shapes 10 | splinart.spline 11 | 12 | Submodules 13 | ---------- 14 | 15 | splinart\.color module 16 | ---------------------- 17 | 18 | .. automodule:: splinart.color 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | splinart\.compute module 24 | ------------------------ 25 | 26 | .. automodule:: splinart.compute 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | splinart\.draw module 32 | --------------------- 33 | 34 | .. automodule:: splinart.draw 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | splinart\.version module 40 | ------------------------ 41 | 42 | .. automodule:: splinart.version 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | 47 | 48 | Module contents 49 | --------------- 50 | 51 | .. automodule:: splinart 52 | :members: 53 | :undoc-members: 54 | :show-inheritance: 55 | -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/doc/api/splinart.shapes.rst: -------------------------------------------------------------------------------- 1 | splinart\.shapes package 2 | ======================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | splinart\.shapes\.base module 8 | ----------------------------- 9 | 10 | .. automodule:: splinart.shapes.base 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | 16 | Module contents 17 | --------------- 18 | 19 | .. automodule:: splinart.shapes 20 | :members: 21 | :undoc-members: 22 | :show-inheritance: 23 | -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/doc/api/splinart.spline.rst: -------------------------------------------------------------------------------- 1 | splinart\.spline package 2 | ======================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | splinart\.spline\.spline module 8 | ------------------------------- 9 | 10 | .. automodule:: splinart.spline.spline 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | splinart\.spline\.splint module 16 | ------------------------------- 17 | 18 | .. automodule:: splinart.spline.splint 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | 24 | Module contents 25 | --------------- 26 | 27 | .. automodule:: splinart.spline 28 | :members: 29 | :undoc-members: 30 | :show-inheritance: 31 | -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/doc/index.rst: -------------------------------------------------------------------------------- 1 | .. splinart documentation master file, created by 2 | sphinx-quickstart on Fri Nov 17 10:27:27 2017. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to splinart's documentation! 7 | ==================================== 8 | 9 | splinart is a package used for a tutorial which explains how to do the Python packaging using 10 | 11 | - `PyPi `_ 12 | - `conda build `_ 13 | - `pytest `_ 14 | - `Pylint `_ 15 | - `Sphinx `_ 16 | 17 | And automate the process to distribute this package using github. 18 | 19 | The original idea of splinart is found on the great invonvergent website. 20 | 21 | If you want to install splinart:: 22 | 23 | pip install splpinart 24 | 25 | or:: 26 | 27 | conda install -c gouarin splinart 28 | 29 | User manual 30 | =========== 31 | .. toctree:: 32 | :maxdepth: 2 33 | 34 | spline 35 | 36 | Tutorial 37 | ======== 38 | .. toctree:: 39 | :maxdepth: 2 40 | 41 | notebooks/circle 42 | 43 | Reference manual 44 | ================ 45 | 46 | .. toctree:: 47 | :maxdepth: 2 48 | 49 | api/modules 50 | 51 | Indices and tables 52 | ================== 53 | 54 | * :ref:`genindex` 55 | * :ref:`modindex` 56 | * :ref:`search` 57 | -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/doc/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | set SPHINXPROJ=splinart 13 | 14 | if "%1" == "" goto help 15 | 16 | %SPHINXBUILD% >NUL 2>NUL 17 | if errorlevel 9009 ( 18 | echo. 19 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 20 | echo.installed, then set the SPHINXBUILD environment variable to point 21 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 22 | echo.may add the Sphinx directory to PATH. 23 | echo. 24 | echo.If you don't have Sphinx installed, grab it from 25 | echo.http://sphinx-doc.org/ 26 | exit /b 1 27 | ) 28 | 29 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 30 | goto end 31 | 32 | :help 33 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 34 | 35 | :end 36 | popd 37 | -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/recipes/meta.yaml: -------------------------------------------------------------------------------- 1 | {% set data = load_setup_py_data() %} 2 | 3 | package: 4 | name: splinart 5 | version: {{ data.get('version') }} 6 | 7 | source: 8 | path: ../ 9 | 10 | build: 11 | number: 0 12 | script: python setup.py install --single-version-externally-managed --record=record.txt 13 | 14 | requirements: 15 | build: 16 | - python 17 | - setuptools 18 | run: 19 | - python 20 | - numpy 21 | - matplotlib 22 | - six 23 | 24 | test: 25 | imports: 26 | - splinart 27 | 28 | about: 29 | home: http://github.com/gouarin/splinart 30 | license: BSD 31 | license_family: BSD 32 | license_file: '' 33 | summary: 'spline art generator' 34 | description: 'spline art generator' 35 | doc_url: '' 36 | dev_url: '' 37 | 38 | extra: 39 | recipe-maintainers: 'loic.gouarin@gmail.com' 40 | -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/scripts/__init__.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal=1 -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/setup.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | from setuptools import setup, find_packages 6 | 7 | CLASSIFIERS = [ 8 | "Development Status :: 3 - Alpha", 9 | "Intended Audience :: Science/Research", 10 | "Intended Audience :: Developers", 11 | "License :: OSI Approved :: BSD License", 12 | "Programming Language :: Python", 13 | "Programming Language :: Python :: 2", 14 | "Programming Language :: Python :: 2.7", 15 | "Programming Language :: Python :: 3", 16 | "Programming Language :: Python :: 3.4", 17 | "Programming Language :: Python :: 3.5", 18 | "Topic :: Software Development", 19 | "Topic :: Scientific/Engineering", 20 | "Operating System :: Microsoft :: Windows", 21 | "Operating System :: POSIX", 22 | "Operating System :: Unix", 23 | "Operating System :: MacOS" 24 | ] 25 | 26 | name = "splinart" 27 | 28 | MAJOR = 0 29 | MINOR = 1 30 | PATCH = 2 31 | VERSION = "{}.{}.{}".format(MAJOR, MINOR, PATCH) 32 | 33 | with open("splinart/version.py", "w") as f: 34 | f.write("__version__ = '{}'\n".format(VERSION)) 35 | 36 | setup( 37 | name = "splinart", 38 | author = "loic.gouarin@gmail.com", 39 | description = "spline art generator", 40 | version = VERSION, 41 | license = "BSD", 42 | classifiers = CLASSIFIERS, 43 | packages = find_packages(exclude=["demos"]), 44 | install_requires = ["numpy", 45 | "matplotlib>=2", 46 | "six"], 47 | entry_points={ 'console_scripts': [ 48 | 'splinart=scripts.cli_splinart:main', 49 | ], 50 | }, 51 | ) -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/splinart/__init__.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | Splinart package 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | from .shapes import circle, line 10 | from .compute import update_img 11 | from .draw import save_img, show_img 12 | -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/splinart/color.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | Define the default color of the output. 7 | """ 8 | DEFAULT_COLOR = (0.0, 0.41568627450980394, 0.61960784313725492, 1.) 9 | -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/splinart/shapes/__init__.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | Shape package 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | from .base import line, circle 10 | -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/splinart/shapes/base.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | Define basic shapes. 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | import numpy as np 10 | 11 | def circle(center, radius, npoints=50): 12 | """ 13 | Discretization of a circle. 14 | 15 | Parameters 16 | ---------- 17 | center : list(2) 18 | 2d coordinates of the center. 19 | radius : float 20 | Radius of the circle. 21 | npoints : int 22 | Number of discretization points (the default value is 50). 23 | 24 | Returns 25 | ------- 26 | np.ndarray 27 | The theta angle. 28 | np.ndarray 29 | The 2d coordinates of the circle. 30 | 31 | """ 32 | theta = 2 * np.pi * np.linspace(0, 1, npoints) 33 | path = np.c_[center[0]+radius*np.cos(theta), center[1]+radius*np.sin(theta)] 34 | return theta, path 35 | 36 | def line(begin, end, ypos=0.5, npoints=50): 37 | """ 38 | Discretization of a horizontal line. 39 | 40 | Parameters 41 | ---------- 42 | 43 | begin : float 44 | The left point of the line. 45 | 46 | end : float 47 | The right point of the line. 48 | 49 | ypos : float 50 | The position of the y coordinate (the default value is 0.5). 51 | 52 | npoints : int 53 | Number of discretization points (the default value is 50). 54 | 55 | Returns 56 | ------- 57 | np.ndarray 58 | The 2d coordinates of the line. 59 | 60 | """ 61 | x = np.linspace(begin, end, npoints) 62 | y = ypos*np.ones(npoints) 63 | return np.c_[x, y] 64 | -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/splinart/spline/__init__.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | Spline package 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | from .spline import spline 10 | from .splint import splint 11 | -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/splinart/spline/spline.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | Cubic spline 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | import numpy as np 10 | from six.moves import range 11 | 12 | def spline(xs, ys): 13 | """ 14 | Return the second derivative of a cubic spline. 15 | 16 | Parameters 17 | ---------- 18 | 19 | xs : np.ndarray 20 | The x coordinate of the cubic spline. 21 | 22 | ys : np.ndarray 23 | The y coordinate of the cubic spline. 24 | 25 | Returns 26 | ------- 27 | np.ndarray 28 | The second derivative of the cubic spline. 29 | 30 | """ 31 | n = xs.shape[0] 32 | u_i = np.zeros_like(ys) 33 | y2s = np.zeros_like(ys) 34 | 35 | dif = np.diff(xs) 36 | sig = dif[:-1]/(xs[2:]-xs[:-2]) 37 | 38 | if ys.ndim == 2: 39 | dif = dif[:, np.newaxis] 40 | 41 | u_i[1:-1] = (ys[2:]- ys[1:-1])/dif[1:] - (ys[1:-1]-ys[:-2])/dif[:-1] 42 | 43 | for i in range(1, n-1): 44 | p_i = sig[i-1]*y2s[i-1] + 2. 45 | y2s[i] = (sig[i-1]-1)/p_i 46 | u_i[i] = (6*u_i[i]/(xs[i+1]-xs[i-1])-sig[i-1]*u_i[i-1])/p_i 47 | 48 | for i in range(n-2, -1, -1): 49 | y2s[i] = y2s[i]*y2s[i+1]+u_i[i] 50 | 51 | return y2s 52 | -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/splinart/spline/splint.py: -------------------------------------------------------------------------------- 1 | # Author: 2 | # Loic Gouarin 3 | # 4 | # License: BSD 3 clause 5 | """ 6 | Integration of a cubic spline. 7 | """ 8 | from __future__ import print_function, division, absolute_import 9 | import numpy as np 10 | 11 | def splint(xs, ys, y2s, x, y): 12 | """ 13 | Evaluate a sample on a cubic pline. 14 | 15 | Parameters 16 | ---------- 17 | xs 18 | The x coordinates of the cubic spline. 19 | ys 20 | The y coordinates of the cubic spline. 21 | y2s 22 | The second derivative of the cubic spline. 23 | x 24 | The sample where to evaluation the cubic spline. 25 | y 26 | The y coordinates of the sample. 27 | 28 | See also 29 | -------- 30 | splinart.spline.spline 31 | 32 | """ 33 | khi = np.searchsorted(xs, x) 34 | klo = khi-1 35 | step = xs[khi] - xs[klo] 36 | x_right = ((xs[khi]-x)/step) 37 | x_left = ((x-xs[klo])/step) 38 | 39 | if y.ndim == 2: 40 | step = step[:, np.newaxis] 41 | x_right = x_right[:, np.newaxis] 42 | x_left = x_left[:, np.newaxis] 43 | 44 | y[:] = x_right*ys[klo]+x_left*ys[khi]+( 45 | (x_right**3-x_right)*y2s[klo]+ 46 | (x_left**3-x_left)*y2s[khi])*step**2/6 47 | -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/splinart/version.py: -------------------------------------------------------------------------------- 1 | __version__ = '0.1.2' 2 | -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/tests/baseline/test_circle_case.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/TPs/4.pytest/final_step/tests/baseline/test_circle_case.png -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/tests/test_all.py: -------------------------------------------------------------------------------- 1 | import splinart as spl 2 | import numpy as np 3 | import pytest 4 | import matplotlib.pyplot as plt 5 | 6 | @pytest.mark.long 7 | @pytest.mark.mpl_image_compare 8 | def test_circle_case(): 9 | 10 | np.random.seed(42) 11 | 12 | img_size, channels = 1000, 4 13 | img = np.ones((img_size, img_size, channels), dtype=np.float32) 14 | 15 | theta, path = spl.circle([0.5, 0.5], 0.3) 16 | 17 | def xs_func(): 18 | nsamples = 500 19 | return (np.random.random() + 2 * np.pi * np.linspace(0, 1, nsamples))%(2*np.pi) 20 | 21 | spl.update_img(img, path, xs_func, nrep=4000, x=theta) 22 | 23 | fig = plt.figure() 24 | ax = fig.add_subplot(1,1,1) 25 | ax.imshow(img) 26 | return fig -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/tests/test_shape.py: -------------------------------------------------------------------------------- 1 | import splinart as spl 2 | import numpy as np 3 | import pytest 4 | from pytest import approx 5 | 6 | def test_circle_1(): 7 | theta, path = spl.circle([0, 0], 1, npoints=2) 8 | 9 | assert theta == approx([0, 2*np.pi]) 10 | assert path == approx(np.array([[1, 0], [1, 0]])) 11 | 12 | def test_circle_2(): 13 | theta, path = spl.circle([0, 0], 1, npoints=5) 14 | 15 | assert theta == approx(np.linspace(0, 2*np.pi, 5)) 16 | assert path == approx(np.array([[1, 0], [0, 1], [-1, 0], [0, -1], [1, 0]])) 17 | 18 | def test_line_1(): 19 | path = spl.line(0, 1, npoints=2) 20 | 21 | assert path == approx(np.array([[0, 0.5], [1, 0.5]])) 22 | 23 | def test_line_2(): 24 | path = spl.line(0, 1, npoints=3) 25 | 26 | assert path == approx(np.array([[0, 0.5], [0.5, 0.5], [1, 0.5]])) 27 | 28 | @pytest.mark.parametrize("nbpoints,expected", [ 29 | (2, np.array([[1, 0], [1, 0]])), 30 | (5, np.array([[1, 0], [0, 1], [-1, 0], [0, -1], [1, 0]])) 31 | ]) 32 | def test_circle(nbpoints, expected): 33 | theta, path = spl.circle([0, 0], 1, npoints=nbpoints) 34 | assert path == approx(expected) 35 | 36 | @pytest.mark.parametrize("nbpoints,expected", [ 37 | (2, np.array([[0, 0.5], [1, 0.5]])), 38 | (3, np.array([[0, 0.5], [0.5, 0.5], [1, 0.5]])) 39 | ]) 40 | def test_line(nbpoints, expected): 41 | path = spl.line(0, 1, npoints=nbpoints) 42 | assert path == approx(expected) 43 | -------------------------------------------------------------------------------- /TPs/4.pytest/final_step/tests/test_spline.py: -------------------------------------------------------------------------------- 1 | import splinart as spl 2 | import numpy as np 3 | import pytest 4 | 5 | @pytest.mark.parametrize("beg, end", [ 6 | (0 , 1), 7 | (-2, -1), 8 | (-20, 10), 9 | ]) 10 | @pytest.mark.parametrize("nbpoints", [ 11 | (10), 12 | (20), 13 | (30) 14 | ]) 15 | def test_spline(beg, end, nbpoints): 16 | path = spl.line(beg, end, npoints=nbpoints) 17 | y2s = spl.spline.spline(path[:, 0], path[:, 1]) 18 | assert y2s == pytest.approx(np.zeros(nbpoints)) 19 | 20 | @pytest.mark.parametrize("center, radius", [ 21 | ([0, 0] , 1), 22 | ([0.5, 0.1] , .1), 23 | ([-0.5, 0.6] , .3), 24 | ]) 25 | @pytest.mark.parametrize("nbpoints", [ 26 | (10), 27 | (20), 28 | (30) 29 | ]) 30 | def test_spline_circle(center, radius, nbpoints): 31 | theta, path = spl.circle(center, radius, npoints=nbpoints) 32 | y2s = spl.spline.spline(theta, path) 33 | y_new = np.zeros_like(path) 34 | spl.spline.splint(theta, path, y2s, theta, y_new) 35 | assert path == pytest.approx(y_new) -------------------------------------------------------------------------------- /environment.yml: -------------------------------------------------------------------------------- 1 | name: packaging-environment 2 | channels: 3 | - damianavila82 4 | - conda-forge 5 | dependencies: 6 | - python=3.6 7 | - numpy 8 | - matplotlib 9 | - sphinx 10 | - nbsphinx 11 | - rise 12 | - pip: 13 | - pytest 14 | - pylint 15 | - pytest-cov 16 | - pytest-pylint 17 | - pytest-mpl 18 | -------------------------------------------------------------------------------- /examples/calculator/MANIFEST.in: -------------------------------------------------------------------------------- 1 | #recursive-include calculator *.txt 2 | #include calculator/*.txt 3 | global-include *.txt -------------------------------------------------------------------------------- /examples/calculator/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/calculator/README -------------------------------------------------------------------------------- /examples/calculator/calculator/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Calculator module 3 | """ 4 | 5 | from .parser import parser 6 | -------------------------------------------------------------------------------- /examples/calculator/calculator/command_line.py: -------------------------------------------------------------------------------- 1 | """ 2 | try calculator module using the command line 3 | """ 4 | from .parser import parser 5 | 6 | def main(): 7 | """ 8 | compute input line 9 | """ 10 | print(parser("2.56+5*9/1+9*7")) 11 | -------------------------------------------------------------------------------- /examples/calculator/calculator/cython_mod.pyx: -------------------------------------------------------------------------------- 1 | def test(double a, double b): 2 | return a + b 3 | -------------------------------------------------------------------------------- /examples/calculator/calculator/data.txt: -------------------------------------------------------------------------------- 1 | a = 23 -------------------------------------------------------------------------------- /examples/calculator/calculator/data/data1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/calculator/calculator/data/data1.txt -------------------------------------------------------------------------------- /examples/calculator/calculator/data/data2.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/calculator/calculator/data/data2.txt -------------------------------------------------------------------------------- /examples/calculator/calculator/operator_/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/calculator/calculator/operator_/README -------------------------------------------------------------------------------- /examples/calculator/calculator/operator_/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | operator_ module 3 | """ 4 | 5 | __all__ = ["add", "sub"] 6 | -------------------------------------------------------------------------------- /examples/calculator/calculator/operator_/add.py: -------------------------------------------------------------------------------- 1 | """ 2 | sum operator 3 | """ 4 | 5 | def add(value1, value2): 6 | """ 7 | return the sum of value1 and value2 8 | """ 9 | return value1 + value2 10 | -------------------------------------------------------------------------------- /examples/calculator/calculator/operator_/data/data_op1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/calculator/calculator/operator_/data/data_op1.txt -------------------------------------------------------------------------------- /examples/calculator/calculator/operator_/data/data_op2.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/calculator/calculator/operator_/data/data_op2.txt -------------------------------------------------------------------------------- /examples/calculator/calculator/operator_/data_op.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/calculator/calculator/operator_/data_op.txt -------------------------------------------------------------------------------- /examples/calculator/calculator/operator_/div.py: -------------------------------------------------------------------------------- 1 | """ 2 | division operator 3 | """ 4 | 5 | def division(value1, value2): 6 | """ 7 | return the division of value1 by value2 8 | """ 9 | return value1/value2 10 | -------------------------------------------------------------------------------- /examples/calculator/calculator/operator_/mult.py: -------------------------------------------------------------------------------- 1 | """ 2 | multiplication operator 3 | """ 4 | 5 | def mult(value1, value2): 6 | """ 7 | return the multiplication of value1 by value2. 8 | """ 9 | return value1 * value2 10 | -------------------------------------------------------------------------------- /examples/calculator/calculator/operator_/sub.py: -------------------------------------------------------------------------------- 1 | """ 2 | substraction operator 3 | """ 4 | 5 | def sub(value1, value2): 6 | """ 7 | return the substraction of value1 by value2 8 | """ 9 | return value1 - value2 10 | -------------------------------------------------------------------------------- /examples/calculator/calculator/parser.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | def parser_mult(input_str): 4 | pattern = r"[\d.]+|[\*\/]" 5 | match = re.findall(pattern, input_str) 6 | 7 | if not len(match)&1: 8 | raise Exception("Error") 9 | 10 | result = float(match[0]) 11 | 12 | for i in range(1, len(match), 2): 13 | if match[i] == '*': 14 | result *= float(match[i+1]) 15 | if match[i] == '/': 16 | result /= float(match[i+1]) 17 | 18 | return result 19 | 20 | def parser(input_str): 21 | pattern = r"[\w.\*\/]+|[\+\-]" 22 | match = re.findall(pattern, input_str) 23 | 24 | if not len(match)&1: 25 | raise Exception("Error") 26 | 27 | result = parser_mult(match[0]) 28 | 29 | for i in range(1, len(match), 2): 30 | if match[i] == '+': 31 | result += parser_mult(match[i+1]) 32 | if match[i] == '-': 33 | result -= parser_mult(match[i+1]) 34 | 35 | return result 36 | 37 | if __name__ == "__main__": 38 | try: 39 | print(parser("2.56+5*9/1+9*7")) 40 | except: 41 | print("Error") 42 | #m = parser("2.56+5+9.7") 43 | print(2.56+5*9/1+9*7) 44 | -------------------------------------------------------------------------------- /examples/calculator/calculator/version.py: -------------------------------------------------------------------------------- 1 | __version__ = '0.1.1' 2 | -------------------------------------------------------------------------------- /examples/calculator/doc/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = python -msphinx 7 | SPHINXPROJ = calculator 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -------------------------------------------------------------------------------- /examples/calculator/doc/doc1.rst: -------------------------------------------------------------------------------- 1 | .. _my-reference-label: 2 | 3 | Section to cross-reference 4 | -------------------------- 5 | 6 | This is the text of the section. 7 | 8 | It refers to the section itself, see :ref:`my-reference-label`. 9 | -------------------------------------------------------------------------------- /examples/calculator/doc/index.rst: -------------------------------------------------------------------------------- 1 | .. calculator documentation master file, created by 2 | sphinx-quickstart on Sun Nov 12 14:47:58 2017. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to calculator's documentation! 7 | ====================================== 8 | 9 | .. toctree:: 10 | :maxdepth: 2 11 | 12 | notebooks/test 13 | 14 | It refers to the section itself, see :ref:`my-reference-label`. 15 | 16 | 17 | Indices and tables 18 | ================== 19 | 20 | * :ref:`genindex` 21 | * :ref:`modindex` 22 | * :ref:`search` 23 | -------------------------------------------------------------------------------- /examples/calculator/doc/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=python -msphinx 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | set SPHINXPROJ=calculator 13 | 14 | if "%1" == "" goto help 15 | 16 | %SPHINXBUILD% >NUL 2>NUL 17 | if errorlevel 9009 ( 18 | echo. 19 | echo.The Sphinx module was not found. Make sure you have Sphinx installed, 20 | echo.then set the SPHINXBUILD environment variable to point to the full 21 | echo.path of the 'sphinx-build' executable. Alternatively you may add the 22 | echo.Sphinx directory to PATH. 23 | echo. 24 | echo.If you don't have Sphinx installed, grab it from 25 | echo.http://sphinx-doc.org/ 26 | exit /b 1 27 | ) 28 | 29 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 30 | goto end 31 | 32 | :help 33 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 34 | 35 | :end 36 | popd 37 | -------------------------------------------------------------------------------- /examples/calculator/doc/notebooks: -------------------------------------------------------------------------------- 1 | ../notebooks/ -------------------------------------------------------------------------------- /examples/calculator/notebooks/test.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Test" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 2, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "import numpy as np" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 3, 22 | "metadata": { 23 | "collapsed": true 24 | }, 25 | "outputs": [], 26 | "source": [ 27 | "a = np.zeros(4)" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": 4, 33 | "metadata": {}, 34 | "outputs": [ 35 | { 36 | "data": { 37 | "text/plain": [ 38 | "array([ 0., 0., 0., 0.])" 39 | ] 40 | }, 41 | "execution_count": 4, 42 | "metadata": {}, 43 | "output_type": "execute_result" 44 | } 45 | ], 46 | "source": [ 47 | "a" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": null, 53 | "metadata": { 54 | "collapsed": true 55 | }, 56 | "outputs": [], 57 | "source": [] 58 | } 59 | ], 60 | "metadata": { 61 | "kernelspec": { 62 | "display_name": "Python 3", 63 | "language": "python", 64 | "name": "python3" 65 | }, 66 | "language_info": { 67 | "codemirror_mode": { 68 | "name": "ipython", 69 | "version": 3 70 | }, 71 | "file_extension": ".py", 72 | "mimetype": "text/x-python", 73 | "name": "python", 74 | "nbconvert_exporter": "python", 75 | "pygments_lexer": "ipython3", 76 | "version": "3.6.2" 77 | } 78 | }, 79 | "nbformat": 4, 80 | "nbformat_minor": 2 81 | } 82 | -------------------------------------------------------------------------------- /examples/calculator/readme.md: -------------------------------------------------------------------------------- 1 | # Installation sur conda 2 | 3 | 4 | conda install conda-build 5 | 6 | aller dans le répertoire `calculator` 7 | 8 | conda skeleton pypi recipes 9 | 10 | (crée un répertoire recipes contenant un fichier meta.yaml à modifier) 11 | 12 | Copier les fichiers si nécessaire (pas ici) 13 | 14 | - build.sh : https://conda.io/docs/_downloads/build1.sh 15 | - build.bat : https://conda.io/docs/_downloads/bld.bat 16 | 17 | Normalement il n'est pas nécessaire d'avoir ces fichiers pour une installation de type pypi puisque l'installation est la même commande pour linux et windows 18 | 19 | python setup.py install 20 | 21 | Une fois les fichiers du répertoire recipes modifiés, il faut exécuter la commande suivante 22 | 23 | conda build recipes 24 | 25 | Pour tester en local 26 | 27 | conda install --use-local calculator 28 | 29 | Pour mettre en ligne 30 | 31 | conda install anaconda-client 32 | anaconda upload /home/loic/miniconda3/conda-bld/linux-64/calculator-0.1.1-py36h585410b_0.tar.bz2 33 | 34 | Pour voir le fichier yaml final 35 | 36 | conda render recipes 37 | 38 | -------------------------------------------------------------------------------- /examples/calculator/recipes/bld.bat: -------------------------------------------------------------------------------- 1 | "%PYTHON%" setup.py install 2 | if errorlevel 1 exit 1 3 | -------------------------------------------------------------------------------- /examples/calculator/recipes/build1.sh: -------------------------------------------------------------------------------- 1 | $PYTHON setup.py install 2 | -------------------------------------------------------------------------------- /examples/calculator/recipes/meta.yaml: -------------------------------------------------------------------------------- 1 | {% set name = "calculator" %} 2 | {% set version = "0.1.1" %} 3 | 4 | package: 5 | name: '{{ name|lower }}' 6 | version: '{{ version }}' 7 | 8 | source: 9 | path: ../ 10 | 11 | build: 12 | number: 0 13 | script: python setup.py install --single-version-externally-managed --record=record.txt 14 | 15 | requirements: 16 | build: 17 | - python 18 | - setuptools 19 | run: 20 | - python 21 | 22 | test: 23 | imports: 24 | - calculator 25 | 26 | about: 27 | home: http://github.com/gouarin/calculator 28 | license: MIT 29 | description: Simple calculator project 30 | 31 | extra: 32 | recipe-maintainers: Loic Gouarin 33 | -------------------------------------------------------------------------------- /examples/calculator/scripts/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/calculator/scripts/__init__.py -------------------------------------------------------------------------------- /examples/calculator/scripts/calculator: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from calculator import parser 3 | 4 | print(parser("2.56+5*9/1+9*7")) -------------------------------------------------------------------------------- /examples/calculator/scripts/command_line.py: -------------------------------------------------------------------------------- 1 | from calculator import parser 2 | 3 | def main(): 4 | print(parser("2.56+5*9/1+9*7")) -------------------------------------------------------------------------------- /examples/calculator_1/__init__.py: -------------------------------------------------------------------------------- 1 | from .operator2 import mult -------------------------------------------------------------------------------- /examples/calculator_1/operator1/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = ["add", "sub"] -------------------------------------------------------------------------------- /examples/calculator_1/operator1/add.py: -------------------------------------------------------------------------------- 1 | def add(a, b): 2 | return a + b -------------------------------------------------------------------------------- /examples/calculator_1/operator1/sub.py: -------------------------------------------------------------------------------- 1 | def sub(a, b): 2 | return a - b -------------------------------------------------------------------------------- /examples/calculator_1/operator2/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/calculator_1/operator2/__init__.py -------------------------------------------------------------------------------- /examples/calculator_1/operator2/mult.py: -------------------------------------------------------------------------------- 1 | def mult(a, b): 2 | return a * b -------------------------------------------------------------------------------- /examples/data_example/MANIFEST.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/data_example/MANIFEST.in -------------------------------------------------------------------------------- /examples/data_example/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/data_example/README -------------------------------------------------------------------------------- /examples/data_example/calculator/...: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/data_example/calculator/... -------------------------------------------------------------------------------- /examples/data_example/calculator/data/data1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/data_example/calculator/data/data1.txt -------------------------------------------------------------------------------- /examples/data_example/calculator/data/data2.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/data_example/calculator/data/data2.txt -------------------------------------------------------------------------------- /examples/data_example/calculator/data_calc.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/data_example/calculator/data_calc.txt -------------------------------------------------------------------------------- /examples/data_example/calculator/op/...: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/data_example/calculator/op/... -------------------------------------------------------------------------------- /examples/data_example/calculator/op/__init_.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/data_example/calculator/op/__init_.py -------------------------------------------------------------------------------- /examples/data_example/calculator/op/data_op.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/data_example/calculator/op/data_op.txt -------------------------------------------------------------------------------- /examples/data_example/calculator/parser/...: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/data_example/calculator/parser/... -------------------------------------------------------------------------------- /examples/data_example/calculator/parser/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/data_example/calculator/parser/README -------------------------------------------------------------------------------- /examples/data_example/calculator/parser/__init_.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/data_example/calculator/parser/__init_.py -------------------------------------------------------------------------------- /examples/data_example/setup.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/data_example/setup.py -------------------------------------------------------------------------------- /examples/linter/correction/example2.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function, division, absolute_import 2 | from six.moves import range 3 | 4 | def div(a, b): 5 | for i in range(5): 6 | print(i) 7 | return a/b 8 | -------------------------------------------------------------------------------- /examples/linter/disable.py: -------------------------------------------------------------------------------- 1 | 2 | # pylint: disable=invalid-name 3 | def function1(): 4 | for a in range(10): 5 | print(a) -------------------------------------------------------------------------------- /examples/linter/example1.py: -------------------------------------------------------------------------------- 1 | class maCLasse: 2 | def __init__(a, b = 4): 3 | self.a = 5 4 | 5 | def fonctionADD(a, b,c): 6 | return a+b -------------------------------------------------------------------------------- /examples/linter/example2.py: -------------------------------------------------------------------------------- 1 | def div(a, b): 2 | for i in xrange(5): 3 | print i 4 | return a/b 5 | -------------------------------------------------------------------------------- /examples/linter/example3.py: -------------------------------------------------------------------------------- 1 | print "coucou" 2 | print 1/3 -------------------------------------------------------------------------------- /examples/linter/example4.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from module1 import * 3 | 4 | def g(a): 5 | """ 6 | fonction g 7 | 8 | Parameters 9 | ---------- 10 | a: test 11 | 12 | """ 13 | for i in range(n): 14 | for j in range(n): 15 | if (a[i, j] < 0): 16 | a[i, j] = 0 17 | else: 18 | a[i, j] = 1 19 | 20 | # def f(a): 21 | # for i in range(n): 22 | # for j in range(n): 23 | # if (a[i, j] < 0): 24 | # a[i, j] = 0 25 | # else: 26 | # a[i, j] = 1 27 | 28 | # # def g(a): 29 | # # for i in range(n): 30 | # # for j in range(n): 31 | # # if (a[i, j] < 0): 32 | # # a[i, j] = 0 33 | # # else: 34 | # # a[i, j] = 1 35 | 36 | n = 10 37 | a = np.random.rand(n, n) 38 | 39 | def toto(a, b, c, d, e, f): 40 | pass 41 | 42 | f(a) 43 | g(a) -------------------------------------------------------------------------------- /examples/linter/example5.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | a = np.zeros((10, 10), dtype=np.int322) 4 | np.sum(a, axes=0) -------------------------------------------------------------------------------- /examples/linter/missing.py: -------------------------------------------------------------------------------- 1 | def process_stuff(params): 2 | executed = False 3 | if not params: 4 | raise ValueError('empty command list') 5 | for foo in params: 6 | foo.execute -------------------------------------------------------------------------------- /examples/linter/module1.py: -------------------------------------------------------------------------------- 1 | def f(a): 2 | for i in range(n): 3 | for j in range(n): 4 | if (a[i, j] < 0): 5 | a[i, j] = 0 6 | else: 7 | a[i, j] = 1 8 | 9 | -------------------------------------------------------------------------------- /examples/linter/numpy_check.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | a = np.zeros((10, 10), dtype=np.int322) 4 | np.sum(a, axes=0) -------------------------------------------------------------------------------- /examples/linter/numpy_doc.py: -------------------------------------------------------------------------------- 1 | 2 | def awesome_function(tomatoes, banana): 3 | """ 4 | This is an awesome function !! 5 | 6 | Parameters 7 | ---------- 8 | 9 | tomatoes: 10 | red fruits 11 | 12 | apple : int 13 | number of apple 14 | """ 15 | 16 | print(tomatoes) 17 | print(banana) 18 | 19 | return tomatoes[0] -------------------------------------------------------------------------------- /examples/linter/pep8.py: -------------------------------------------------------------------------------- 1 | class maCLasse: 2 | def __init__(a, b = 4): 3 | self.a = 5 4 | 5 | def fonctionADD(a, b,c): 6 | return a+b -------------------------------------------------------------------------------- /examples/linter/py2to3.py: -------------------------------------------------------------------------------- 1 | def div(a, b): 2 | for i in xrange(5): 3 | print i 4 | return a/b -------------------------------------------------------------------------------- /examples/linter/similarities/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/linter/similarities/__init__.py -------------------------------------------------------------------------------- /examples/linter/similarities/module1.py: -------------------------------------------------------------------------------- 1 | 2 | def function1(array): 3 | for i in range(10): 4 | for j in range(10): 5 | if (i+j) & 1: 6 | array[i][j] = 1 7 | else: 8 | array[i][j] = 0 -------------------------------------------------------------------------------- /examples/linter/similarities/module2.py: -------------------------------------------------------------------------------- 1 | 2 | def function2(array): 3 | print(array[0]) 4 | for i in range(10): 5 | for j in range(10): 6 | if (i+j) & 1: 7 | array[i][j] = 1 8 | else: 9 | array[i][j] = 0 -------------------------------------------------------------------------------- /examples/linter/spellcheck.py: -------------------------------------------------------------------------------- 1 | 2 | def some_function(): 3 | """ 4 | This fonction does nothing. 5 | 6 | But it's a example of spell checking 7 | using pylint. 8 | 9 | Don't look at the grammar and work only 10 | for doc strings and comments. 11 | """ 12 | pass -------------------------------------------------------------------------------- /examples/tests/conftest.py: -------------------------------------------------------------------------------- 1 | 2 | import pytest 3 | 4 | @pytest.fixture() 5 | def hello(): 6 | print('Hello !!') 7 | -------------------------------------------------------------------------------- /examples/tests/fibonacci.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | def factorielle(n): 4 | """ 5 | calcul de n! 6 | 7 | >>> factorielle(0) 8 | 10 9 | >>> factorielle(5) 10 | 120 11 | 12 | """ 13 | if n==1 or n==0: 14 | return 1 15 | else: 16 | return n*factorielle(n-1) 17 | 18 | def somme(deb, fin, f, fargs=()): 19 | """ 20 | calcul de 21 | 22 | $$ 23 | \sum_{k=deb}^fin f(k, *fargs) 24 | $$ 25 | 26 | test d'une suite arithmetique 27 | >>> somme(0, 10, lambda k:k) 28 | 55.0 29 | 30 | test d'une suite geometrique 31 | >>> somme(1, 8, lambda k: 2**k) 32 | 510.0 33 | 34 | """ 35 | 36 | som = 0. 37 | for k in range(deb, fin + 1): 38 | som += f(k, *fargs) 39 | return som 40 | 41 | def coef_binomial(n, k): 42 | """ 43 | calcul de $C_n^k$ 44 | 45 | >>> coef_binomial(4, 2) 46 | 6 47 | 48 | """ 49 | if k > n or k < 0: 50 | return 0. 51 | return factorielle(n)//(factorielle(k)*factorielle(n-k)) 52 | 53 | def fibonacci(n): 54 | """ 55 | Renvoie la liste des n premiers termes de la suite de Fibonacci 56 | 57 | >>> fibonacci(10) 58 | [1, 1, 2, 3, 5, 8, 13, 21, 34, 55] 59 | 60 | """ 61 | def g(k, n): 62 | return coef_binomial(n - k, k) 63 | 64 | fibo = [] 65 | for i in range(n): 66 | fibo.append(int(somme(0, i, g, fargs=(i,)))) 67 | 68 | return fibo 69 | 70 | if __name__ == '__main__': 71 | import doctest 72 | doctest.testmod(verbose=True) -------------------------------------------------------------------------------- /examples/tests/numpy/baseline/test_npz_1.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/tests/numpy/baseline/test_npz_1.npz -------------------------------------------------------------------------------- /examples/tests/numpy/baseline/test_npz_2.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/tests/numpy/baseline/test_npz_2.npz -------------------------------------------------------------------------------- /examples/tests/numpy/reference/test_npz_1.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/tests/numpy/reference/test_npz_1.npz -------------------------------------------------------------------------------- /examples/tests/numpy/reference/test_npz_2.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/tests/numpy/reference/test_npz_2.npz -------------------------------------------------------------------------------- /examples/tests/numpy/reference/test_npz_arange.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/tests/numpy/reference/test_npz_arange.npz -------------------------------------------------------------------------------- /examples/tests/numpy/reference/test_npz_random.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/tests/numpy/reference/test_npz_random.npz -------------------------------------------------------------------------------- /examples/tests/numpy/reference/test_npz_two_arange.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/examples/tests/numpy/reference/test_npz_two_arange.npz -------------------------------------------------------------------------------- /examples/tests/numpy/test_numpy.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import pytest 3 | 4 | @pytest.mark.npz_compare 5 | def test_npz_arange(): 6 | return np.arange(10) 7 | 8 | @pytest.mark.npz_compare 9 | def test_npz_two_arange(): 10 | return np.arange(10), np.arange(30) 11 | 12 | @pytest.mark.npz_compare(rel=1e-6) 13 | def test_npz_random(): 14 | return 1 + 1e-5*np.random.random(10) -------------------------------------------------------------------------------- /examples/tests/test_approx_1.py: -------------------------------------------------------------------------------- 1 | 2 | from pytest import approx 3 | 4 | def test_approx_1(): 5 | assert 1.001 == approx(1) 6 | 7 | def test_approx_2(): 8 | assert 1.001 == approx(1, rel=1e-3) -------------------------------------------------------------------------------- /examples/tests/test_approx_2.py: -------------------------------------------------------------------------------- 1 | 2 | import numpy as np 3 | import pytest 4 | from pytest import approx 5 | 6 | def ones_array(shape): 7 | return np.ones(shape) 8 | 9 | @pytest.fixture(params=[5, (3,2), (5, 4, 3)]) 10 | def init_array(request): 11 | return ones_array(request.param) 12 | 13 | def test_approx(init_array): 14 | shape = init_array.shape 15 | random_array = 1 + 1e-5*np.random.random(shape) 16 | assert random_array == approx(init_array, rel=1e-5) -------------------------------------------------------------------------------- /examples/tests/test_approx__id_2.py: -------------------------------------------------------------------------------- 1 | 2 | import numpy as np 3 | import pytest 4 | from pytest import approx 5 | 6 | def ones_array(shape): 7 | return np.ones(shape) 8 | 9 | @pytest.fixture(params=[5, (3,2), (5, 4, 3)], 10 | ids=['1d', '2d', '3d']) 11 | def init_array(request): 12 | return ones_array(request.param) 13 | 14 | def test_approx(init_array): 15 | shape = init_array.shape 16 | random_array = 1 + 1e-5*np.random.random(shape) 17 | assert random_array == approx(init_array, rel=1e-5) -------------------------------------------------------------------------------- /examples/tests/test_approx_id_2.py: -------------------------------------------------------------------------------- 1 | 2 | import numpy as np 3 | import pytest 4 | from pytest import approx 5 | 6 | def ones_array(shape): 7 | return np.ones(shape) 8 | 9 | @pytest.fixture(params=[5, (3,2), (5, 4, 3)], 10 | ids=['1d', '2d', '3d']) 11 | def init_array(request): 12 | return ones_array(request.param) 13 | 14 | def test_approx(init_array): 15 | shape = init_array.shape 16 | random_array = 1 + 1e-5*np.random.random(shape) 17 | assert random_array == approx(init_array, rel=1e-5) -------------------------------------------------------------------------------- /examples/tests/test_capture.py: -------------------------------------------------------------------------------- 1 | 2 | def test_capture(): 3 | print("coucou") 4 | assert True -------------------------------------------------------------------------------- /examples/tests/test_conftest_fixture.py: -------------------------------------------------------------------------------- 1 | 2 | def test_conftest_fixture(hello): 3 | assert True 4 | -------------------------------------------------------------------------------- /examples/tests/test_fibo.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import sys 3 | sys.path.append("./examples/tests") 4 | from fibonacci import * 5 | 6 | class TestFibo(unittest.TestCase): 7 | def test_factorielle_0(self): 8 | self.assertEqual(factorielle(0), 10) 9 | 10 | def test_factorielle_5(self): 11 | self.assertEqual(factorielle(5), 120) 12 | 13 | def test_somme(self): 14 | self.assertEqual(somme(0, 10, lambda k:k), 55) 15 | 16 | def test_coef_binomial(self): 17 | self.assertEqual(coef_binomial(4, 2), 6) 18 | 19 | def test_fibo(self): 20 | self.assertEqual(fibonacci(10), [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]) 21 | 22 | if __name__ == '__main__': 23 | unittest.main() -------------------------------------------------------------------------------- /examples/tests/test_fixture_1.py: -------------------------------------------------------------------------------- 1 | 2 | import pytest 3 | 4 | @pytest.fixture() 5 | def tmpfile(): 6 | with open("tmp_fixture.txt", "w") as f: 7 | yield f 8 | 9 | def test_file(tmpfile): 10 | print(dir(tmpfile)) 11 | tmpfile.write("temporary file : " + tmpfile.name) 12 | assert True -------------------------------------------------------------------------------- /examples/tests/test_key.py: -------------------------------------------------------------------------------- 1 | 2 | def test_foo_1(): 3 | assert True 4 | 5 | def test_foo_2(): 6 | assert True 7 | 8 | def test_bar_1(): 9 | assert True 10 | 11 | def test_bar_2(): 12 | assert True 13 | 14 | def test_bar_3(): 15 | assert True 16 | -------------------------------------------------------------------------------- /examples/tests/test_mark.py: -------------------------------------------------------------------------------- 1 | 2 | import pytest 3 | 4 | @pytest.mark.slow 5 | def test_slow(): 6 | assert True 7 | 8 | def test_not_slow(): 9 | assert True -------------------------------------------------------------------------------- /examples/tests/test_parametrize.py: -------------------------------------------------------------------------------- 1 | 2 | import sys 3 | sys.path.append("./examples/tests") 4 | import pytest 5 | 6 | from fibonacci import * 7 | 8 | @pytest.mark.parametrize('fact_number, expected', [ 9 | (0, 1), 10 | (1, 1), 11 | (2, 2), 12 | (3, 6), 13 | (4, 24), 14 | (5, 120) 15 | ]) 16 | def test_methods(fact_number, expected): 17 | assert factorielle(fact_number) == expected -------------------------------------------------------------------------------- /examples/tests/test_parametrize_1.py: -------------------------------------------------------------------------------- 1 | 2 | import sys 3 | sys.path.append("./examples/tests") 4 | import pytest 5 | 6 | from fibonacci import * 7 | 8 | @pytest.mark.parametrize('fact_number, expected', [ 9 | (0, 1), 10 | (1, 1), 11 | (2, 2), 12 | (3, 6), 13 | (4, 24), 14 | (5, 120) 15 | ]) 16 | def test_methods(fact_number, expected): 17 | assert factorielle(fact_number) == expected -------------------------------------------------------------------------------- /examples/tests/test_parametrize_2.py: -------------------------------------------------------------------------------- 1 | 2 | import pytest 3 | 4 | from fibonacci import * 5 | 6 | @pytest.mark.parametrize('value1', range(5)) 7 | @pytest.mark.parametrize('value2', range(0,10,2)) 8 | def test_methods(value1, value2): 9 | assert not (value1*value2 & 1) -------------------------------------------------------------------------------- /examples/tests/test_skip.py: -------------------------------------------------------------------------------- 1 | 2 | import sys 3 | import pytest 4 | 5 | @pytest.mark.skip(reason="doesn't work !!") 6 | def test_skip(): 7 | assert True 8 | 9 | @pytest.mark.skipif(sys.version_info < (3, 6), reason="Python version too old") 10 | def test_skipif(): 11 | assert True -------------------------------------------------------------------------------- /images/Octocat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/Octocat.png -------------------------------------------------------------------------------- /images/black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/black.png -------------------------------------------------------------------------------- /images/but.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/but.png -------------------------------------------------------------------------------- /images/but1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/but1.png -------------------------------------------------------------------------------- /images/but2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/but2.png -------------------------------------------------------------------------------- /images/but3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/but3.png -------------------------------------------------------------------------------- /images/but4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/but4.png -------------------------------------------------------------------------------- /images/but5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/but5.png -------------------------------------------------------------------------------- /images/computer-user-icon-16386.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/computer-user-icon-16386.jpg -------------------------------------------------------------------------------- /images/data/manifest_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/data/manifest_1.png -------------------------------------------------------------------------------- /images/data/manifest_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/data/manifest_2.png -------------------------------------------------------------------------------- /images/data/manifest_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/data/manifest_3.png -------------------------------------------------------------------------------- /images/data/manifest_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/data/manifest_4.png -------------------------------------------------------------------------------- /images/data/package_data_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/data/package_data_1.png -------------------------------------------------------------------------------- /images/data/package_data_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/data/package_data_2.png -------------------------------------------------------------------------------- /images/data/package_data_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/data/package_data_3.png -------------------------------------------------------------------------------- /images/data/package_data_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/data/package_data_4.png -------------------------------------------------------------------------------- /images/data_setup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/data_setup.png -------------------------------------------------------------------------------- /images/group-png-3216.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/group-png-3216.png -------------------------------------------------------------------------------- /images/idea.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/idea.png -------------------------------------------------------------------------------- /images/pip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/pip.png -------------------------------------------------------------------------------- /images/pytest1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/pytest1.png -------------------------------------------------------------------------------- /images/readthedocs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/readthedocs.png -------------------------------------------------------------------------------- /images/sphinx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/sphinx.png -------------------------------------------------------------------------------- /images/travis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/images/travis.png -------------------------------------------------------------------------------- /sphinx/cheatsheet-back-full.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/sphinx/cheatsheet-back-full.png -------------------------------------------------------------------------------- /sphinx/cheatsheet-front-full.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gouarin/python_packaging_course/f6ce09a644a9483bff3468369820192f1cbad2b2/sphinx/cheatsheet-front-full.png -------------------------------------------------------------------------------- /style/custom.css: -------------------------------------------------------------------------------- 1 | --------------------------------------------------------------------------------