Skip to content

Instantly share code, notes, and snippets.

@phn
phn / part1.rst
Created July 5, 2012 17:15
Astropython.org PyFits tutorial

PyFITS: FITS files in Python

In this article, we provide examples of using the python module PyFITS for working with FITS data. We first go through a brief

@phn
phn / year_to_jd.py
Created May 4, 2012 11:11
Julian dates, decimal years, Gregorian calendar dates, and Julian epochs.
import jdcal
from jdcal import ipart, fpart, is_leap, gcal2jd, jd2gcal
CJ = 36525.0
def days_in_year(year, c="g"):
"""Number of days in a calendar year (Gregorian/Julian)."""
if c.lower() == "g":
return 366 if is_leap(year) else 365
@phn
phn / c6d_s6d.py
Created April 22, 2012 05:57
6D Cartesian and Spherical coordinates.
"""Conversion between 6D Cartesian and spherical coordinates.
Cartesian6D represents the coordinates (x, y, z, xdot, ydot, zdot).
Spherical6D represents the coordinates (r, alpha, delta, rdot,
alphadot, deltadot). Alpha is the longitudinal angle and delta is the
latitudinal angle. The latter goes from 90 degrees at the +ve z-axis to
-90 at the -ve z-axis.
The Cartesian coordinates can have any units. The radial spherical
coordinate has the some unit as the input Cartesian
@phn
phn / lineid_utils.py
Created April 7, 2012 08:03
lineid_plot_utils
import matplotlib as mpl
import lineid_plot
def color_text_boxes(ax, labels, colors, color_arrow=True):
assert len(labels) == len(colors), \
"Equal no. of colors and lables must be given"
boxes = ax.findobj(mpl.text.Annotation)
box_lables = lineid_plot.unique_labels(labels)
for box in boxes:
@phn
phn / jdcal.py
Created August 30, 2011 06:01
Julian date calculator for proleptic Gregorian and Julian calendars.
# Code moved to http://github.com/phn/jdcal.
@phn
phn / angles.py
Created July 28, 2011 15:09
Python classes and functions for working with angles.
# Code moved to http://github.com/phn/angles.