A very up-to-date (august 2014) electronic book on python named "Introduction to Python for Econometrics, Statistics and Data Analysis" from Kevin Sheppard is available here:
https://www.kevinsheppard.com/images/0/09/Python_introduction.pdf
It's mainly on econometric, but most of the tools described there are also useful for astronomers.
This is a support for a lecture on Python given at the Instituto de Astronomia at the UNAM (Universidad Nacional Autonoma de Mexico) by Christophe Morisset.
Monday, December 1, 2014
Tuesday, November 11, 2014
Sending requests to MySQL and receiving the result from python, using PyMySQL
Modern astrophysics is using every day more big databases. One of the mostly used interface to databases is MySQl (or its recent free fork MariaDB). I present in this lecture a python library to deal with MySQL databases: PyMySQL. In the lecture the examples are using access to 3MdB (https://sites.google.com/site/mexicanmillionmodels/), which requires a password. You can ask for it to me, or adapt the example to connect to other databases.
The lecture is here:
https://github.com/Morisset/Python-lectures-Notebooks/blob/master/Notebooks/Using_PyMySQL.ipynb
An introduction to MySQL can be found here: https://github.com/Morisset/Python-lectures-Notebooks/blob/master/MySQL.pdf
The lecture is here:
https://github.com/Morisset/Python-lectures-Notebooks/blob/master/Notebooks/Using_PyMySQL.ipynb
An introduction to MySQL can be found here: https://github.com/Morisset/Python-lectures-Notebooks/blob/master/MySQL.pdf
Wednesday, October 8, 2014
Optimization, calling Fortran
2014 Python Lecture. Part IX
In this latest lecture of this series, I'll present some tools to optimize your code by CPU and memory profiling. It also contains some tips on using the python debugger.
The notebook is there:
https://github.com/Morisset/Python-lectures-Notebooks/blob/master/Notebooks/Optimization.ipynb
I also give some indications on how one can call Fortran routines from within python, to accelerate the execution of some part the the code.
Here are small examples: https://github.com/Morisset/Python-lectures-Notebooks/blob/master/Notebooks/Calling%20Fortran.ipynb
Wednesday, October 1, 2014
Object Oriented Programing. Objects, classes, etc...
2014 Python Lecture. Part VIII
In this lecture I'll introduce the basic (and some not that basic) concepts of Object Oriented Programing. I'll use an example to show how to:- use functions to do simple jobs
- but use objects when things start to be more complex
- define classes, objects, attributes, methods, etc...
- use *args and **kwargs in functions calls
- use the class variables
- add functionalities to classes and objects
- use class inheritance
- use attributes properties
https://github.com/Morisset/Python-lectures-Notebooks/blob/master/Notebooks/OOP.ipynb
Thursday, September 25, 2014
The astropy library
2014 Python Lecture. Part VII
The Astropy Project is a community effort to develop a single core package for Astronomy in Python and foster interoperability between Python astronomy packages. More informations here: http://www.astropy.org/In this lecture we will see some of the facilities of the astorpy library, including:
- Constants and Units
- Data Table (a very useful one!)
- Time and Dates
- Etc...
The lecture is here:
https://github.com/Morisset/Python-lectures-Notebooks/blob/master/Notebooks/Using_astropy.ipynb
Thursday, September 18, 2014
Useful libraries
2014 Python Lecture. Part VI
This lecture will give some insights to the most useful python
libraries. It is NOT exhaustive, you have to read the corresponding
manual pages to find the best use you can have of them. The list of all
python-included libraries is here: https://docs.python.org/2/library/
I mention in this lecture:
- time and datetime
- timeit
- os
- sys
- subprocess
- glob
- re
- urllib2
Wednesday, September 17, 2014
Introduction to Scipy
2014 Python Lecture. Part V
SciPy (pronounced “Sigh Pie”) is a Python-based ecosystem of open-source software for mathematics, science, and engineering. In particular, these are some of the core packages: Numpy, Scipy library, Matplotlib, ipython, Simpy, and Panda.In this lecture, I will show exemples covering:
- Some useful methods
- nanmean
- constants
- Integrations
- Interpolations
- 2D-interpolations
- data fitting
- multivariate estimation
https://github.com/Morisset/Python-lectures-Notebooks/blob/master/Notebooks/intro_Scipy.ipynb
Wednesday, September 10, 2014
How to make plots, images, 3D, etc, using Matplotlib
2014 Python Lecture. Part IV
This lecture is dedicated to the plotting library matplotlib. The topics are:
- Simple plot
- Controlling colors ans symbols
- Overplot
- Fixing axes limits
- Labels, titles
- Legends
- The object oriented way to use Matplotlib
- Scatter
- log plots
- Multiple plots
- Everything is object
- Error bars
- Sharing axes
- Histograms
- Boxplots
- Ticks, axes and spines
- A plot inside a plot
- Play with all the objects of a plot
- Filled regions
- 2D-histograms
- 2D data sets and images
- Contour
- 3D scatter plots
- Saving plots
- Access and clear the current figure and axe
- What's happen when not in a Notebook? plt.show() and plt.ion() commands
https://github.com/Morisset/Python-lectures-Notebooks/blob/master/Notebooks/intro_Matplotlib.ipynb
Wednesday, September 3, 2014
Interacting with files: reading writing, ascii and fits
2014 Python lecture. Part III
It's time to play with files containing data! In this lecture, we'll see how to read and write files (ascii and fits).
- Reading a simple ASCII file
- How to treat special rows (comments, header)
- classical way
- using numpy.loadtxt
- using numpy.genfromtxt
- Dealing with missing data
- Data in a fixed size format
- Writing files
- simple method
- Pickle files (python format)
- FITS files
https://github.com/Morisset/Python-lectures-Notebooks/blob/master/Notebooks/Interact%20with%20files.ipynb
Wednesday, August 20, 2014
Introduction to Numpy
2014 Python lecture. Part II
The introduction to Numpy can be seen here:
https://github.com/Morisset/Python-lectures-Notebooks/blob/master/Notebooks/intro_numpy.ipynb
The topics that are presented are:
- The Array class
- create an array
- 1D, 2D 3D arrays
- creating array from scratch
- arrays share memory (views)
- random generator
- timing a command
- slicing arrays
- assignments
- using masks
- the where function
- some operations with arrays
- broadcasting
- calling scripts
- structured arrays and record arrays
- NaN other ANSI values.
Any comments are welcome.
Chris.Morisset a t Gmail.com
Wednesday, August 13, 2014
Python: Basics
2014 Python lecture. Part I
The introduction to Python I'm giving at IA-UNAM is accessible here:
https://github.com/Morisset/Python-lectures-Notebooks/blob/master/Notebooks/intro_Python.ipynb
I will modify this notebook during the lecture (August 2014), so reload it to have the latest version.
The topics of this first lecture are:
- Using python as a calculator
- assignments
- comments
- types
- complex numbers
- booleans
- printing strings
- strings
- Tuples, lists and dictionaries
- Blocks
- List and dictionary comprehension
- Functions, procedures
- Scripting
- Importing libraries
ipython notebook
It should open a new tab in your web browser, with the list of ipynb files in the directory. Click on the one you want, will open a new tab similar to the first one, but this one is executed on YOUR computer, it means you are able to interact with the commands. You can change the commands, and execute a cell by SHIFT-ENTER. You can add comments in new cells, and save the result.
Any comments are welcome.
Thursday, August 7, 2014
Brief introduction to Python
2014 Python lecture. Part 0
Back to the Python lecture, I want to share here the very quick introduction I gave before starting to play with python: https://github.com/Morisset/Python-lectures-Notebooks/blob/master/Notebooks/Intro_1.pdf
You may want to install python from Ureka from this site: http://ssb.stsci.edu/ureka/
Wednesday, March 19, 2014
Using ipython Notebook to teach scientific python
A very good and efficient way to teach python and python related tools, is to use ipython Notebook: http://ipython.org/notebook.html
As example of this use, the following link is a collection of lectures on python, numpy, scipy, matplotlib, use of Fortran from python, etc:
https://github.com/jrjohansson/scientific-python-lectures
Enjoy them.
As example of this use, the following link is a collection of lectures on python, numpy, scipy, matplotlib, use of Fortran from python, etc:
https://github.com/jrjohansson/scientific-python-lectures
Enjoy them.
Subscribe to:
Posts (Atom)