tkp.utility.coordinates – Coordinate routines

General purpose astronomical coordinate handling routines.

class tkp.utility.coordinates.CoordSystem[source]

A container for constant strings representing different coordinate systems.

FK4 = 'B1950 (FK4)'
FK5 = 'J2000 (FK5)'
class tkp.utility.coordinates.WCS[source]

Wrapper around pywcs.WCS.

This is primarily to preserve API compatibility with the earlier, home-brewed python-wcslib wrapper. It includes:

  • A fix for the reference pixel lying at the zenith;
  • Raises ValueError if coordinates are invalid.
ORIGIN = 1
WCS_ATTRS = ('crpix', 'cdelt', 'crval', 'ctype', 'cunit', 'crota')
p2s(pixpos)[source]

Pixel to Spatial coordinate conversion.

Parameters:pixpos (list) – [x, y] pixel position
Returns:ra – Right ascension corresponding to position [x, y] dec (float): Declination corresponding to position [x, y]
Return type:float
s2p(spatialpos)[source]

Spatial to Pixel coordinate conversion.

Parameters:pixpos (list) – [ra, dec] spatial position
Returns:x – X pixel value corresponding to position [ra, dec] y (float): Y pixel value corresponding to position [ra, dec]
Return type:float
tkp.utility.coordinates.alpha(l, m, alpha0, delta0)[source]

Convert a coordinate in l,m into an coordinate in RA

Keyword arguments: l,m – direction cosines, given by (offset in cells) x cellsi (radians) alpha_0, delta_0 – centre of the field

Return value: alpha – RA in decimal degrees

tkp.utility.coordinates.alpha_inflate(theta, decl)[source]

Compute the ra expansion for a given theta at a given declination

Keyword arguments: theta, decl are both in decimal degrees.

Return value: alpha – RA inflation in decimal degrees

For a derivation, see MSR TR 2006 52, Section 2.1 http://research.microsoft.com/apps/pubs/default.aspx?id=64524

tkp.utility.coordinates.alphasep(ra1, ra2, dec1, dec2)[source]

Find the angular separation of two sources in RA, in arcseconds

Keyword arguments: ra1,dec1 - RA and Dec of the first source, in decimal degrees ra2,dec2 - RA and Dec of the second source, in decimal degrees

Return value: angsep - Angular separation, in arcseconds

tkp.utility.coordinates.altaz(mjds, ra, dec, lat=52.9088)[source]

Calculates the azimuth and elevation of source from time and position on sky. Takes MJD in seconds and ra, dec in degrees. Returns (alt, az) in degrees.

tkp.utility.coordinates.angsep(ra1, dec1, ra2, dec2)[source]

Find the angular separation of two sources, in arcseconds, using the proper spherical trig formula

Keyword arguments: ra1,dec1 - RA and Dec of the first source, in decimal degrees ra2,dec2 - RA and Dec of the second source, in decimal degrees

Return value: angsep - Angular separation, in arcseconds

tkp.utility.coordinates.convert_coordsystem(ra, dec, insys, outsys)[source]

Convert RA & dec (given in decimal degrees) between equinoxes.

tkp.utility.coordinates.coordsystem(name)[source]

Given a string, return a constant from class CoordSystem.

tkp.utility.coordinates.dectodms(decdegs)[source]

Convert Declination in decimal degrees format to hours, minutes, seconds format.

Keyword arguments: decdegs – Dec. in degrees format

Return value: dec – list of 3 values, [degrees,minutes,seconds]

tkp.utility.coordinates.delta(l, m, delta0)[source]

Convert a coordinate in l, m into an coordinate in Dec

Keyword arguments: l, m – direction cosines, given by (offset in cells) x cellsi (radians) alpha_0, delta_0 – centre of the field

Return value: delta – Dec in decimal degrees

tkp.utility.coordinates.deltasep(dec1, dec2)[source]

Find the angular separation of two sources in Dec, in arcseconds

Keyword arguments: dec1 - Dec of the first source, in decimal degrees dec2 - Dec of the second source, in decimal degrees

Return value: angsep - Angular separation, in arcseconds

tkp.utility.coordinates.dmstodec(decd, decm, decs)[source]

Convert Dec in degrees, minutes, seconds format to decimal degrees format.

Keyword arguments: decd, decm, decs – list of Dec values (d,m,s)

Return value: decdegs – Dec in decimal degrees

tkp.utility.coordinates.eq_to_cart(ra, dec)[source]

Find the cartesian co-ordinates on the unit sphere given the eq. co-ords.

ra, dec should be in degrees.

tkp.utility.coordinates.eq_to_gal(ra, dec)[source]

Find the Galactic co-ordinates of a source given the equatorial co-ordinates

Keyword arguments: (alpha,delta) – RA, Dec in decimal degrees

Return value: (l,b) – Galactic longitude and latitude, in decimal degrees

tkp.utility.coordinates.gal_to_eq(lon_l, lat_b)[source]

Find the Galactic co-ordinates of a source given the equatorial co-ordinates

Keyword arguments: (l, b) – Galactic longitude and latitude, in decimal degrees

Return value: (alpha, delta) – RA, Dec in decimal degrees

tkp.utility.coordinates.hmstora(rah, ram, ras)[source]

Convert RA in hours, minutes, seconds format to decimal degrees format.

Keyword arguments: rah,ram,ras – RA values (h,m,s)

Return value: radegs – RA in decimal degrees

tkp.utility.coordinates.jd2lst(jd, position=None)[source]

Converts a Julian Date into Local Apparent Sidereal Time in seconds at a given position. If position is None, we default to the reference position of CS002.

Parameters:
  • jd (float) – Julian Date
  • position (pyrap measure) – Position for LST calcs.
tkp.utility.coordinates.julian2unix(timestamp)[source]

Convert a modifed julian timestamp (number of seconds since 17 November 1858) to Unix timestamp (number of seconds since 1 January 1970).

Parameters:timestamp (numbers.Number) – Number of seconds since the Unix epoch.
Returns:Number of seconds since the modified Julian epoch.
Return type:numbers.Number
tkp.utility.coordinates.julian_date(time=None, modified=False)[source]

Calculate the Julian date at a given timestamp.

Parameters:
  • time (datetime.datetime) – Timestamp to calculate JD for.
  • modified (bool) – If True, return the Modified Julian Date: the number of days (including fractions) which have elapsed between the start of 17 November 1858 AD and the specified time.
Returns:

Julian date value.

Return type:

float

tkp.utility.coordinates.l(ra, dec, cra, incr)[source]

Convert a coordinate in RA,Dec into a direction cosine l

Keyword arguments: ra,dec – Source location cra – RA centre of the field incr – number of degrees per pixel (negative in the case of RA)

Return value: l – Direction cosine

tkp.utility.coordinates.lm_to_radec(ra0, dec0, l, m)[source]

Find the l direction cosine in a radio image, given an RA and Dec and the field centre

tkp.utility.coordinates.m(ra, dec, cra, cdec, incr)[source]

Convert a coordinate in RA,Dec into a direction cosine m

Keyword arguments: ra,dec – Source location cra,cdec – centre of the field incr – number of degrees per pixel

Return value: m – direction cosine

tkp.utility.coordinates.mjd2datetime(mjd)[source]

Convert a Modified Julian Date to datetime via ‘unix time’ representation.

NB ‘unix time’ is defined by the casacore/pyrap package.

tkp.utility.coordinates.mjd2lst(mjd, position=None)[source]

Converts a Modified Julian Date into Local Apparent Sidereal Time in seconds at a given position. If position is None, we default to the reference position of CS002.

mjd – Modified Julian Date (float, in days) position – Position (pyrap measure)

tkp.utility.coordinates.mjds2lst(mjds, position=None)[source]

As mjd2lst(), but takes an argument in seconds rather than days.

Parameters:
  • mjds (float) – Modified Julian Date (in seconds)
  • position (pyrap measure) – Position for LST calcs
tkp.utility.coordinates.propagate_sign(val1, val2, val3)[source]

casacore (reasonably enough) demands that a minus sign (if required) comes at the start of the quantity. Thus “-0D30M” rather than “0D-30M”. Python regards “-0” as equal to “0”; we need to split off a separate sign field.

If more than one of our inputs is negative, it’s not clear what the user meant: we raise.

Parameters:val1 (float) – (,val2,val3) input values (hour/min/sec or deg/min/sec)
Returns:“+” or “-” string denoting sign, val1, val2, val3 (numeric) denoting absolute values of inputs.
Return type:tuple
tkp.utility.coordinates.radec_to_lmn(ra0, dec0, ra, dec)[source]
tkp.utility.coordinates.ratohms(radegs)[source]

Convert RA in decimal degrees format to hours, minutes, seconds format.

Keyword arguments: radegs – RA in degrees format

Return value: ra – tuple of 3 values, [hours,minutes,seconds]

tkp.utility.coordinates.sec2days(seconds)[source]

Seconds to number of days

tkp.utility.coordinates.sec2deg(seconds)[source]

Seconds of time to degrees of arc

tkp.utility.coordinates.sec2hms(seconds)[source]

Seconds to hours, minutes, seconds

tkp.utility.coordinates.unix2julian(timestamp)[source]

Convert a Unix timestamp (number of seconds since 1 January 1970) to a modified Julian timestamp (number of seconds since 17 November 1858).

Parameters:timestamp (numbers.Number) – Number of seconds since the modified Julian epoch.
Returns:Number of seconds since the Unix epoch.
Return type:numbers.Number