Observational Astronomy Primer Exercises: 2.) Python plotting / fitting / etc.

You may find some of these tasks useful as we move forward doing photometry and running HIPE.  This is just some useful material that you can work on over the next few weeks or months.

You can write & run python scripts in a few different ways, and the best way for you is really just up to your preference.  I like to write my code in gedit (Pluma in Ubuntu Mate), and interactively test/run in ipython in the terminal.  But there are also several IDEs such as Spyder, Eclipse, Geany, PyCharm (similar to those used by Matlab or IDL).

There are many great tutorials on the web for learning python.  I started to make a few very simple tutorials elsewhere on this site ( http://research.endlessfernweh.com/tutorials/ ) but there are a variety of better tutorials out there:
Practical Python For Astronomers  https://python4astronomers.github.io/  is a great comprehensive one tailored to astronomy, but I find that it’s a little bit hard to jump right in
Here is a page with powerpoint-style tutorials on many things in python (again, targeted at astronomers): https://astro.uni-bonn.de/~rschaaf/Python2008/
Astrobetter is a blog that often has very useful posts about coding and other important things in astronomy.  Here is one post on python: http://www.astrobetter.com/blog/2014/07/07/astropy-tutorials-learn-how-to-do-common-astro-tasks-with-astropy-and-python/

For plotting (see below as well), I recommend using the pywcsgrid2 module, but you can also use APLpy and kapteyn to make great  images.  Here are a couple pages for using pywcsgrid2:
Kapteyn has many other useful tools for reprojection, image smoothing, etc.  https://www.astro.rug.nl/software/kapteyn/

Here is a list of useful goals & concepts to work on.

  • importing modules, syntax
  • Create some functions (try some useful ones for astronomy, such as a Gaussian, blackbody, Modified BB)
  • Load tables from text files, or DS9 regs.
  • Save data to text files.
  • Fit function parameters – see my web tutorial for a good overview
  • Plot single function and 2D (heatmap, maybe try a 2D gaussian?) – see my web tutorial
    • include labels – title, axis labels (modify size, color, etc.)
    • include legend (1D), colorbar (2D)
  • Plot single images – maybe start with Kepler’s SNR because we already downloaded those fits files
    • Can use APLpy, pywcsgrid2, kapteyn… whatever package you like
    • Include labels
    • include colorbar & units
    • play with colormaps, intensity limits, scaling
    • maybe include size scale bar, compass, beam size…
    • draw a region (e.g., ellipse)
  • Plot two images side by side (say, Kepler infrared and radio; follow the pywcsgrid2 tutorial)
    • match coordinates
    • make contours