Python Resources - WSU-Physics/phys340 GitHub Wiki
A. Python Resources There are many ways to install python on your compute. Most scientists are now using Anaconda Python which you can get here:
https://www.anaconda.com/products/individual
For historical reasons there is a 3.x verions of python and 2.7 version. At this point in time it is recommended to use the 3.x version.
Below are various resources and tutorials for using python for scientific data analysis which you may find useful.
Scipy Lecture Notes - tutorials on using scipy and numpy for scientific computing. http://www.scipy-lectures.org/ PHY 546: Python for Scientific Computing - course notes for a graduate seminar on scientific computing with python. Many excellent links to tutorials and resources. http://bender.astro.sunysb.edu/classes/python-science/ Python Course on Lynda Campus - see directions for setting up an account on learn.winona.edu and then the python course on Lynda Software Carpentry - tutorials and lessons on programing, also a workshop that you can attend: http://software-carpentry.org/lessons/ Astropy Tutorials - tutorials in Jupyter Notebooks that walk through some common python/astropy processes used in astronomy. http://www.astropy.org/astropy-tutorials/ Here are various cookbook and example galleries. If you are looking for how to do something, this is a good place to look.
Plotting Matplotlib Gallery - many many many examples of how to make different types of plots. Also can access the full documentation for all functions here. Data Analysis with Scipy - importing data, exporting data, fitting functions, computing statistics Scipy Cookbook - examples of data analysis like fitting data, importing and export data (like from excel), Scipy Reference Manual - official reference manual for scipy. Includes the documentation for all scipy functions. Also has a very nice and simple intoductory tutorial. Data Arrays - operations on arrays of data that have been imported. Numpy Reference Manual - official reference manual for numpy. Includes the documention for all numpy functions Some specific resources:
Use the symbolic python package to take derivatives symbolically
http://www.sympy.org/en/index.html import sympy as sm x, y, z = sm.symbols('x y z', real=True) f = 4xy + xsm.sin(z) + x3 + z8y sm.diff(f, x)
Returns: 3x**2 + 4y + sin(z)
Use scipy “derivative” function to numerically differentiate:
https://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.misc.derivative.html def f(x): return x3 + x2
derivative(f, 1.0, dx=1e-6)
Returns: 4.9999999999217337
Use numpy “average” and “std”– will work as weighted average too, but std won’t handle weights
https://docs.scipy.org/doc/numpy/reference/generated/numpy.average.html https://docs.scipy.org/doc/numpy/reference/generated/numpy.std.html#numpy.std Define our own equations for mean, average, SD, SDOM, and weighted average!
least_squares
No weights http://scipy-cookbook.readthedocs.io/items/FittingData.html https://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html#least-squares-minimization http://scipy-cookbook.readthedocs.io/items/FittingData.html Curve_fit
Weights in y-data https://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html#least-squares-minimization-least-squares Orthogonal Distance Regression
PREFERED METHOD FOR ALL FITTING Allows for weights in x and y if no weights, will automatically perform least squares https://docs.scipy.org/doc/scipy/reference/odr.html B. OSF Resources OSF has a number of tutorials and help guides on how to do things in there support area.
The OSF Guides are very helpful. Some very useful ones:
Using the Wiki Commenting Organizing Files You may also find helpful theses guides on Markdown (the language used on the OSF wiki and in Jupyter) and Latex (for making math equations).
Markdown Cheat sheet Latex Math Symbols C. Example Notebooks & Group Work Solutions Example Jupyter Notebook we built in class in week 1 is viewable here. I added a few more comments to it as well.
Group Practice 1 - Solutions (notebook) (pdf)- Taylor Problems: 2.4, 2.7, 2.15, 2.22, 2.26
Group Practice 1 - Blank Practice with significant figures, discpreancy, and testing relations. Group Practice 2 - Solutions - Taylor Problems 3.35, 4.47 and 3.5
Group Practice 2 - Blank Error Propagation Group Practice 3 - Solutions (pdf) - Taylor 8.24, 4.2, 4.26
Group Practice 3 - Blank mean, sd, and fitting Averages - Example notebook showing how to define functions to calcuate averages
Fitting - and to use ODR to fit functions. Both with and without errors.