Difference between revisions of "PythonOnSHIPs"
From CoolWiki
Jump to navigationJump to search(6 intermediate revisions by the same user not shown) | |||
Line 40: | Line 40: | ||
− | ==Summer Visit | + | ==Tutorial 5: Plotting (demo during summer visit)== |
− | + | :We use matplotlib's plotting library and documentation. | |
− | + | :http://matplotlib.org/users/pyplot_tutorial.html | |
− | + | :'''Exercises''': | |
− | + | ::* Plot a histogram distribution of FWHM values of sources in any of your photometry tables. | |
− | + | ::* Plot 70um flux vs its FWHM as dots, not a line. Annotate any outliers. | |
− | + | ||
− | + | ||
+ | |||
+ | ==Summer Visit Programming Projects== | ||
+ | 1. Basic text file conversion | ||
+ | * Read an APT file (Peggy's list of test objects is fine for this exercise). | ||
+ | * Aperture correct the magnitudes | ||
+ | * Compare Aperture corrected values to APT corrected Aperture values. | ||
+ | * Write the following columns to another file called 'phot.dat': ID, x, y, Ra, Dec, Flux, ApertureCorrected Flux, Aperture Size, Sky Annulus Size | ||
+ | *Write a ds9 region file using only the Ra, Dec and ID columns. | ||
+ | 2. Read FWHMs of a list of stars | ||
+ | * Compute statistics: Median, Mininum, Mean, Maximum, Standard Deviation of FWHM values. | ||
+ | * Plot a distribution of FWHM values. | ||
+ | * Overplot a distribution of FWHM values of known point sources. | ||
+ | * Can you make a judgement on what is an is not a source? | ||
+ | 3. Find the nearest Spitzer 24 micron source to a position. | ||
+ | * Read in Spitzer 24um source list. | ||
+ | * Define a function to: | ||
+ | ** compute radial distance between a position (ra,dec) and all of the Spitzer 24 source positions. | ||
+ | ** Find all Spitzer 24um sources within a specified radius of the position (ra,dec) | ||
+ | ** Report in order of distance, all found sources. |
Latest revision as of 23:15, 25 June 2013
Contents
Tutorial 1: Overview of Programming
- Presents the basic concepts of programming for newbies.
- File:Python1.pdf
Tutorial 2: Data, Variables and Math operators
- An introduction to the python interpreter, variables and types of data they store. Using math functions and python as a calculator.
- File:Python2.pdf
- 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
- Perform the following operations (in order) on the previous array: trignometric cosine, multiply by 1000.0 and convert it to integer format.
- 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.
Tutorial 3: Controlling program flow
- Script writing for python and If/Then/Else constructs and loops.
- File:Python3.pdf
- Exercises:
- For all prime numbers up to 13, calculate and print the square of the prime number.
- Define a list of 5 stars in numpy variables x, y, flux. Where, x, y are the coordinates and flux is the brightness in some units. For the star in the middle of the list (at index position 2) write a script to calculate and print the difference in position and in flux between all stars in the list and that star.
- 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?
- Write a script to calculate and print when this object cross the declination line at -45.00000?
Tutorial 4: Working with files and function
- Input, Output, Try/Except and Functions.
- File:Python4.pdf
- Exercises:
- Define a function that can read an APT table file. Take care to ignore time tags. The input should be an APT table filename. You should return only the ID, the position (ra,dec) and the flux of the source. The remaining columns may be ignored.
- Write a code that uses the above function to read say 70um APT results file and 100um APT results file. Compute simple statistics on these values: number of sources, faintest source, brightest source, and median flux.
Tutorial 5: Plotting (demo during summer visit)
- We use matplotlib's plotting library and documentation.
- http://matplotlib.org/users/pyplot_tutorial.html
- Exercises:
- Plot a histogram distribution of FWHM values of sources in any of your photometry tables.
- Plot 70um flux vs its FWHM as dots, not a line. Annotate any outliers.
Summer Visit Programming Projects
1. Basic text file conversion
- Read an APT file (Peggy's list of test objects is fine for this exercise).
- Aperture correct the magnitudes
- Compare Aperture corrected values to APT corrected Aperture values.
- Write the following columns to another file called 'phot.dat': ID, x, y, Ra, Dec, Flux, ApertureCorrected Flux, Aperture Size, Sky Annulus Size
- Write a ds9 region file using only the Ra, Dec and ID columns.
2. Read FWHMs of a list of stars
- Compute statistics: Median, Mininum, Mean, Maximum, Standard Deviation of FWHM values.
- Plot a distribution of FWHM values.
- Overplot a distribution of FWHM values of known point sources.
- Can you make a judgement on what is an is not a source?
3. Find the nearest Spitzer 24 micron source to a position.
- Read in Spitzer 24um source list.
- Define a function to:
- compute radial distance between a position (ra,dec) and all of the Spitzer 24 source positions.
- Find all Spitzer 24um sources within a specified radius of the position (ra,dec)
- Report in order of distance, all found sources.