Difference between revisions of "Pytuts"
Line 98: | Line 98: | ||
: Tuesday, 6/24/2014 | : Tuesday, 6/24/2014 | ||
: 3:30 pm, PDT = 6:30 pm, EDT | : 3:30 pm, PDT = 6:30 pm, EDT | ||
+ | : http://www.youtube.com/watch?v=KtW0enPpgZI&feature=youtu.be | ||
: [[File:python-tutorial-4.pdf | Link to Presentation]] | : [[File:python-tutorial-4.pdf | Link to Presentation]] | ||
: [[File:ipac-table-demo.txt | IPAC table demo]] | : [[File:ipac-table-demo.txt | IPAC table demo]] | ||
Line 105: | Line 106: | ||
:: [[File:maybefinaltable.txt | maybefinaltable.txt]] | :: [[File:maybefinaltable.txt | maybefinaltable.txt]] | ||
: Solutions | : Solutions | ||
+ | |||
==Session 5: Plotting and other miscellanea.== | ==Session 5: Plotting and other miscellanea.== |
Revision as of 03:34, 25 June 2014
Python programming for non-programmers
This tutorial series will walk you through the very basics of computer programming using the python scripting language. The course is targeted towards the complete novice programmer. That is, someone who has never programmed in any language, or has very little experience in programming.
Programming is an essentially requirement for modern scientific research. Python, in particular, is heavily used in astronomy for its relative ease of use and power.
Registration
You are not required to register for the course, but it will be helpful for me to know how many will attend in person. To do that,
- please send me and e-mail at babar@ipac.caltech.edu with your e-mail address and use the subject line: nitarp python.
Prerequisites
To join the online course and participate in python programming exercises, you will need the following:
- Python installed on your computer. We will use the anaconda distribution
- http://continuum.io/downloads
- How do I know its installed and ready to be used Or, testing your python.
- webEx software. We will use this online collaboration tool for viewing the presentation. You don't need to do anything right now. But, be prepared to let webEx download their app on your computer on the first session. I'll allow time to tweak webEx installation during the first session.
- Audio: You need a phone connection to dial into a toll-free number for 1-1.5 hours.
Instructions for joining the live sessions
To join live to view the presentation slides:
- go to http://caltech.webex.com on the day and time of the session.
- If requested, enter your name and e-mail address.
- Enter the meeting password
- Click "Join"
- Please ignore whatever pleas webEx makes about connecting to the audio channel by selecting 'NO' or 'Cancel', or whatever other appropriate options gets you out of the audio line. Using webEx audio is expensive. Instead, use the audio line instructions listed below.
NOTE:
- If this is your first webEx call, a java-based app will be installed on your computer.
- By default video will be ON if your computer is equipped with it.
To join live to the audio line.
- dial 866-524-3365
- Enter telecon code.
NOTE: Password and telecon code will be sent to those who provide me with their e-mail addresses.
Schedule
Session 1: Introduction to programming, spyder and python.
- Tuesday, 5/27/2014
- 3:30 pm, PDT = 6:30 pm, EDT
- File:Python-tutorial-1.pdf
- https://www.youtube.com/watch?v=5GHq0sAbPhM
- Exercise:
- What is the maximum? You are given a list of numbers. Describe (no programming here) how you will determine which of the numbers is the largest. I am looking for step-by-step direction at the very basic level. If your answer is something like "I will sort the numbers ....", you are on the wrong track. I am asking how you will start to sort the numbers to begin with. The answer I am looking is more along these lines: 'Take the first two numbers. Compare the first two numbers, etc.'
- Solution:
- File:Python1 solution.pdf
- File:Python-1-solution.txt Note: I had to use .txt extension to post it to wiki.
Session 2: Data, variables, and mathematical operations.
- Tuesday, 6/3/2014
- 3:30 pm, PDT = 6:30 pm, EDT
- File:Python-tutorial-2.pdf
- https://www.youtube.com/watch?v=o8bmDLjJBqs
- Exercises:
- Evaluate the square root of 10.1*10.2 + 15.3*15.4
- What happens when you add two string variables together?
- Create a numpy integer array of values from 0 to 100, incrementing in steps of 2
- Create a numpy floating-point array of 101 elements that range in value from 0.0 to 1.0
- Find the minimum and maximum value of the resulting array in previous exercise.
- Find the sum total of all elements of the resulting array.
- What is the length of the array 'a' created by the following numpy command: a = np.zeros( int(np.sqrt(np.pi*100)+3.) )?
- What is the data type of the array 'a' in the previous exercise?
- Create an array 'x' of size 20 with floating point values between 1 and 20. Create a second array 'y' of size 20 with floating point values between 1 and 20. These represent the (x,y) coordinate values of 20 objects on a Cartesian grid. Calculate the distance between a point at (2.5,7.8) and all (x,y) pair objects, and store the resulting distance values in a variable 'dist'.
- Create a 2-Dimensional numpy array of size 15 columns X 17 rows filled with zeros. Set the middle column to 10. Set the last five rows to 20.
- Solutions
- File:Python-2-solution.txt Note: I had to use .txt extension to post it to wiki.
Session 3: Controlling your program's flow.
- Tuesday, 6/10/2014
- 3:30 pm, PDT = 6:30 pm, EDT
- File:Python-tutorial-3.pdf
- https://www.youtube.com/watch?v=NIRlctGj_Ag
- Exercises:
- Find the maximum of a list of numbers [2, 10, 4, 7] by coding our flow-chart example from tutorial 1. Compare it to np.max() value.
- For all prime numbers up to 13, calculate and print the square of the prime number.
- A star has a position as follows: ra = 15.2345 (degrees), dec = -45.23435 (degrees) in epoch J2000.0 measurements. It has a proper motion of -1.2 "/yr in right ascension and +0.35 "/yr in declination. Write a program to print the right ascension and declination of the object when WISE looks at it in April of 2009? We ignore parallax here.
- Write a script to calculate and print when this object cross the declination line at -45.00000?
- Solutions
- File:Python-3-solutions.txt
Session 4 Rescheduled
- 6/17 Session cancelled
- See below.
Session 4: Working with files and functions.
- Tuesday, 6/24/2014
- 3:30 pm, PDT = 6:30 pm, EDT
- http://www.youtube.com/watch?v=KtW0enPpgZI&feature=youtu.be
- File:Python-tutorial-4.pdf
- File:Ipac-table-demo.txt
- File:Wise allsky.wise allsky 4band p3as psd13598.txt Please note the change of extension to .txt for the wiki.
- Exercises:
- Read the data file from C-WAYS 2012 NITARP team.
- File:Maybefinaltable.txt
- Solutions
Session 5: Plotting and other miscellanea.
- Tuesday, 7/1/2014
- 3:30 pm, PDT = 6:30 pm, EDT
- Link to Presentation
- Exercises:
- Solutions