├── LICENSE ├── README.md └── snippets └── matplotlib-example.py /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Computer Aided Chemical Engineering 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python for Chemical Engineers 2 | Python crash course designed for chemical engineers and scientists with no previous knowledge. The real goal here isn’t to teach you everything about Python, but you will learn basic concepts via something you will need to do soon or later: analyze data. These informal lessons are divided into 1 hour/week and will be based on [Software-Carpentry Lessons](http://software-carpentry.org/lessons.html) 3 | 4 | ## Day #0 5 | * Motivation of learning Python and [why Nature recommends it](http://www.nature.com/news/programming-pick-up-python-1.16833) ([live demo!](http://www.nature.com/news/ipython-interactive-demo-7.21492)). [[1](https://speakerdeck.com/fperez/ipython-and-project-jupyter-a-language-independent-architecture-for-open-computing-and-data-science), [2](http://www.slideshare.net/teoliphant/python-as-the-zen-of-data-science), [3](http://nbviewer.ipython.org/github/fperez/pycon2014-keynote/blob/master/Index.ipynb)] 6 | * Installation of Python in your computer. Please, [download Anaconda](https://www.continuum.io/downloads) Python 3.5 (64-bit) [(why?)](http://www.slideshare.net/continuumio/distributed-computing-on-your-cluster-with-anaconda-webinar-2015) 7 | * Introduction to the material we will follow: [Software-Carpentry Lessons](http://software-carpentry.org/lessons.html) (+[other](https://github.com/ipython/ipython/wiki/A-gallery-of-interesting-IPython-Notebooks) [resources](https://automatetheboringstuff.com/)) 8 | * Open discussion 9 | 10 | 11 | ## Day #1: NumPy 12 | * Explain what a library is, and what libraries are used for. 13 | * Load a Python library and use the things it contains. 14 | * Read tabular data from a file into a program. 15 | * Assign values to variables. 16 | * Select individual values and subsections from data. 17 | * Perform operations on arrays of data. 18 | * Display simple graphs. 19 | 20 | Materials: 21 | - [Download the data](http://swcarpentry.github.io/python-novice-inflammation/setup/) 22 | - [Read the full lesson](http://swcarpentry.github.io/python-novice-inflammation/01-numpy/) 23 | 24 | ## Day #2: Loops and lists 25 | * Explain what a for loop does. 26 | * Correctly write for loops to repeat simple calculations. 27 | * Trace changes to a loop variable as the loop runs. 28 | * Trace changes to other variables as they are updated by a for loop. 29 | * Explain what a list is. 30 | * Create and index lists of simple values. 31 | 32 | Materials: 33 | - Read the full lessons:[L2](http://swcarpentry.github.io/python-novice-inflammation/02-loop), [L3](http://swcarpentry.github.io/python-novice-inflammation/03-lists) 34 | - [matplotlib gallery](http://matplotlib.org/gallery) 35 | - NumPy - MATLAB: [CheatSheet](http://sebastianraschka.com/Articles/2014_matlab_vs_numpy) and [differences](https://docs.scipy.org/doc/numpy-dev/user/numpy-for-matlab-users). 36 | - [Python tutor](http://www.pythontutor.com/) (to visualize Python programs) 37 | *** 38 | 39 | ## Day #3: Lists and how to proces multiple files 40 | * Explain what a list is (recap). 41 | * Create and index lists of simple values (recap). 42 | 43 | ## Day #5: Lists and how to proces multiple files 44 | 45 | * Use a library function to get a list of filenames that match a simple wildcard pattern. 46 | * Use a for loop to process multiple files. 47 | * Plotting graphs (recap) 48 | 49 | Materials: 50 | - Read the full lessons:[L3](http://swcarpentry.github.io/python-novice-inflammation/03-lists), [L4](http://swcarpentry.github.io/python-novice-inflammation/04-files) 51 | - [Python tutor](http://www.pythontutor.com/) (to visualize Python programs) 52 | 53 | ## Day #6: Analyzing Data from Multiple Files 54 | [How to repeat operations on many different files?](http://swcarpentry.github.io/python-novice-inflammation/04-files/) 55 | 56 | ## Day #7: Making Choices and Functions 57 | [How can my programs do different things based on data values?](http://swcarpentry.github.io/python-novice-inflammation/) 58 | [Creating Functions](http://swcarpentry.github.io/python-novice-inflammation/06-func/) 59 | 60 | ___ 61 | ___ 62 | 63 | Where to go from here? 64 | * [Rest of Software Carpentry Lessons](http://swcarpentry.github.io/python-novice-inflammation/) 65 | * [Prof. Kitchin blog](http://kitchingroup.cheme.cmu.edu/blog/2013/12/30/Python-as-alternative-to-Matlab-for-engineering-calculations/) and [free book](http://kitchingroup.cheme.cmu.edu/pycse/) 66 | * [CAChemE learn](https://github.com/CAChemE/learn#chemical-and-process-engineering-interactive-simulations) (Education resources for Chemical and Process Engineering written as interactive Jupyter Notebooks) 67 | * Lorena Barba tutorials: [12 Steps to Navier Stokes](https://github.com/barbagroup/CFDPython#welcome-to-cfd-python), [Numerical-mooc](https://github.com/numerical-mooc/numerical-mooc), [AeroPython](https://github.com/barbagroup/AeroPython#aerodynamics-hydrodynamics-with-python) 68 | * **[A gallery of interesting IPython Notebooks](https://github.com/ipython/ipython/wiki/A-gallery-of-interesting-IPython-Notebooks)** 69 | * [Introduction to Chemical Engineering Analysis](http://jckantor.github.io/CBE20255/) 70 | 71 | 72 | -------------------------------------------------------------------------------- /snippets/matplotlib-example.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | """ 3 | Matplotlib example 4 | Dependencies: Python, NumPy, matplotlib 5 | """ 6 | 7 | import matplotlib as mpl 8 | from mpl_toolkits.mplot3d import Axes3D 9 | import numpy as np 10 | import matplotlib.pyplot as plt 11 | 12 | # Calculate spiral coordinates 13 | theta = np.linspace(-8 * np.pi, 8 * np.pi, 200) 14 | z = np.linspace(-3, 0, 200) 15 | r = 5 16 | x = r * np.sin(theta)*z 17 | y = r * np.cos(theta)*z 18 | 19 | # Use matplotib and its OOP interface to draw it 20 | fig = plt.figure() # Create figure 21 | ax = fig.gca(projection='3d') # 3D 22 | ax.view_init(15, 0) # Set view angle 23 | ax._axis3don = False # Hide the 3d axes 24 | 25 | # Plot figure 26 | ax.plot(x, y, z, 27 | c='green', linewidth=2.5) 28 | 29 | # Add a new plot 30 | ax.scatter(0, 0, 0.2, 31 | c='red', s=250, marker='*') 32 | 33 | # Type here your best whishes 34 | ax.set_title(u"title_text") 35 | 36 | plt.show() --------------------------------------------------------------------------------