Functions and constants in PyTPM

Most of the functions in TPM can be called from PyTPM, using functions of the same name. These call the TPM function of the same name, with the arguments provided and returns the value returned by the TPM function.

Functions

Main TPM functions

pytpm.tpm.tpm_state(s)

Return state name given state id.

Given an integer id for a state, this function returns a descriptive name for the state.

Parameters :

s : int

State id.

Returns :

n : str

State name.

Examples

>>> tpm.tpm_state(tpm.TPM_S06)
'Helio. mean FK5'
>>> tpm.tpm_state(tpm.TPM_S04)
'IAU 1958 Galactic'
>>> tpm.tpm_state(tpm.TPM_S20)
'Topo. obs. HA/Dec'
>>> tpm.tpm_state(tpm.TPM_S19)
'Topo. obs. Az/El'
pytpm.tpm.tpm_data(tstate, action)

Compute and set dependent TSTATE data.

Given a TSTATE and an action, this function will perform the action and set the various dependent properties of the TSTATE object.

Parameters :

tstate : tpm.TSTATE

The TPM state structure to be changed.

action : int

The action to perform.

Notes

The action can be one of

  • TPM_INIT

    Perform initialization.

  • TPM_FAST

    Calculate all fast changing properties.

  • TPM_MEDIUM

    Calculate all properties that change at a medium rate.

  • TPM_SLOW

    Calculate all properties that change slowly.

  • TPM_REFRACTION

    Cacluate refraction coefficients.

  • TPM_ALL

    Perform all calculations except TPM_REFRACTION.

The TPM manual has more details on these quantities.

pytpm.tpm.proper_motion(v6, end, start)

Apply proper motion to the given V6C vector.

Parameters :

v6 : tpm.V6C

A V6C object containing positions and velocities.

end : float

Ending/final time in days (can be Julian date).

start : float

Starting/initial time in days (can be Julian date).

Returns :

v : tpm.V6C

A V6C object containing the new position.

Notes

Given starting time and end time, this function applies proper motion to the coordinates in the given V6C object. A simple linear multiplication of velocity with time is performed, followed by addition of this increment to the position coordinates.

The difference, end - start, should be the number of days in the time interval. Hence Julian dates can be used. The velocities in V6C are stored as AU/day and hence time interval must be in days.

pytpm.tpm.tpm(pvec, s1, s2, ep, eq, tstate)

Apply transition between to states.

On completion the pvec object will contain state vectors obtained during all transitions needed for the s1 to s2 transition. Specifically, pvec[s2] will have the V6C vector corresponding to the target state s2.

Parameters :

pvec : tpm.PVEC

A PVEC object with appropriate V6 members.

s1 : int

Starting state (0 <= s1 < N_TPM_STATES).

s2 : int

End state (0 <= s2 < N_TPM_STATES).

ep : float

Epoch of state vector corresponding to s1, as a Julian date.

eq : float

Equinox as a Julian date. It can be of s1 and or s2, depending on the specific transition.

tstate : tpm.TSTATE

A TSTATE object with appropriate initial values.

Returns :

s : int

Final state (must be equal to s2).

Notes

This is the main TPM function. It looks up the state tables and performs all required transformations to take the state vector at pvec[s1] from state s1 to state s2. It stores the resulting state vector in pvec[s2]. Intermediate states are stored in their respective positions in pvec.

For more information see the TPM manual.

Functions in the convert module

pytpm.convert.convertv6(v6=None, utc=-999, delta_at=-999, delta_ut=-999, s1=tpm.TPM_S06, s2=tpm.TARGET_OBS_AZEL, epoch=tpm.J2000, equinox=tpm.J2000, lon=-111.598333, lat=31.956389, alt=2093.093, xpole=0.0, ypole=0.0, T=273.15, P=1013.25, H=0.0, wavelength=0.550)

Utility function for performing coordinate conversions.

Parameters :

v6 : tpm.V6C or a list of tpm.V6C vectors.

The V6C vector to be trasnformed.

utc : float

“Current” UTC time as a Julian date.

delta_at : float

TAI - UTC in seconds.

delta_ut : float

UT1 - UTC in seconds.

s1 : int

Initial state.

s2 : int

Final state.

epoch : float

Epoch of input coordinates as a Julian date.

equniox : float

Equinox of input or output coordinates.

lon : float

Geodetic longitude in degeres.

lat : float

Geodetic latitude in degrees.

alt : float

Altitude in meters.

xpole : float

Polar motion in radians.

ypole : float

Ploar motion in radians.

T : float

Ambient temperature in Kelvin.

P : float

Ambient pressure in millibars.

H : float

Ambient humidity in the range 0-1.

wavelength : float

Wavelength of observation in microns.

Returns :

v : tpm.V6C or list of tpm.V6C vectors.

The transformed V6C vector.

Notes

The input v6 can be a single V6C object or a list/tuple of V6C objects. The independent parameters will be the same for all of the V6C object and the dependent parameters will be calculated only once.

The default location is KPNO and the values are taken from the TPM C code.

If utc is not provided then it is set to J2000.0 AND BOTH delta_at and delta_ut ARE SET TO THEIR VALUES AT J2000.0. That is, if utc is not given then the specified values for these two are ignored. If utc is given but delta_at and/or delta_ut is not given, then the missing value is set to that at the given utc.

The TPM state data structure is initialized, the independent parameters are set, and all the dependent parameters are calculated using tpm_data(tstate, TPM_INIT). This calculation is done only once. Then each of the coordinates are converted, by creating a V6 vector and calling tpm().

The value returned is either a single V6C object or a list of V6C objects, depending on the input.

For details on the parameters see the PyTPM reference documentation and the TPM manual. The latter gives an example for the usage of this function.

pytpm.convert.precess()

Precess list of alpha and delta values.

Parameters :

alpha : float or list of floats or 1D Numpy array.

Longitudinal angle in degrees.

dec : float or list of floats or 1D Numpy array.

Latitudinal angle in degrees.

start : float

Starting time for precession, as a Julian date.

end : float

End time for precession, as a Julian date.

pflag : int

The precession model to use.

Returns :

(a, d) : 2-element tuple or list of 2-element tuples

Precessed longitudinal and latitudinal angles.

Notes

This function can be used to precess equatorial (ra,dec) coordinates using a particular model of precession. The input coordinates can be in the FK5 or FK4 systems. In the FK5 system there is only one precession model, which is selected using pflag == tpm.PRECESS_FK5. The FK4 system has several models, and can be selected by setting appropriate constants as the value of pflag:

PRECESS_ANDOYER, PRECESS_NEWCOMB, PRECESS_KINOSHITA, PRECESS_LIESKE

See the tpm manual for definitions of these constants.

pytpm.convert.precessv6()

Precess a list of V6C vectors.

Parameters :

v6 : tpm.V6C or list of tpm.V6C

V6C vector to be precessed.

start : float

Starting time for precession, as a Julian date.

end : float

End time for precession, as a Julian date.

pflag : int

The precession model to use.

Returns :

v6 : tpm.V6C or list of tpm.V6C objects.

Precessed V6C vector.

Notes

This function can be used to precess equatorial in a V6C vector using a particular model of precession. The input coordinates can be in the FK5 or FK4 systems. In the FK5 system there is only one precession model, which is selected using pflag == tpm.PRECESS_FK5. The FK4 system has several models, and can be selected by setting appropriate constants as the value of pflag:

PRECESS_ANDOYER, PRECESS_NEWCOMB, PRECESS_KINOSHITA,
PRECESS_LIESKE

See the tpm manual for definitions of these constants.

pytpm.convert.cat2v6()

Convert catalog entires into V6C vectors.

Parameters :

alpha : float

Longitudinal coordinate (e.g., RA) in radians.

delta : float

Latitudinal coordinate (e.g., Dec) in radians.

pma : float

Proper motion in alpha (not alpha*cos(delta) in “/century.

pmd : float

Proper motion in delta in “/century.

px : float

Parallax in arc-seconds.

rv : float

Radial velocity in km/s.

C : float

Number of days in a century, as used in pma and pmd.

Returns :

v : one or a list of V6C vectors

V6C vectors corresponding to the input catalog quantities.

See also

tpm.cat2v6

pytpm.convert.v62cat()

Convert V6C vectors into catalog entries.

Parameters :

v6 : tpm.V6C or a list of tpm.V6C objects.

V6C object containing positions and velocities.

C : float

Number of days in a century, as used in proper motions in the given V6C vectors.

Returns :

cat : dict or list of dictionaries.

Each distionary contains the catalog quantites for the corresponding V6C vector.

The keys are:
  • alpha : float

    Longitudinal coordinate (e.g., RA) in radians.

  • delta : float

    Latitudinal coordinate (e.g., Dec) in radians.

  • pma : float

    Proper motion in alpha (not alpha*cos(delta) in “/century

  • pmd : float

    Proper motion in delta in “/century.

  • px : float

    Parallax in arc-seconds.

  • rv : float

    Radial velocity in km/s.

See also

tpm.v62cat

pytpm.convert.proper_motion()

Apply proper motion to tpm.V6C vectors.

Parameters :

v6 : tpm.V6C or a list of tpm.V6C objects.

V6C object containing positions and velocities.

end : float

Ending/final time in days (can be Julian date).

start : float

Starting/initial time in days (can be Julian date).

Returns :

v : tpm.V6C or a list of tpm.V6C objects.

V6C object containing the coordinates obtained after applying proper motion.

Notes

Given starting time and end time, this function applies proper motion to the coordinates in the given V6C object. A simple linear multiplication of velocity with time is performed, followed by addition of this increment to the position coordinates.

The difference, end - start, should be the number of days in the time interval. Hence Julian dates can be used. The velocities in V6C are stored as AU/day and hence time interval must be in days.

This function calls tpm.proper_motion repeatedly to perform the calculations.

Date and time calculations and conversions

The current Julian date can be calculated using the following two functions. The first function returns a JD object and the second returns a scalar.

pytpm.tpm.jd_now()

Return current Julian date as a JD object.

This function is only accurate to the nearest second.

Returns :

jd : tpm.JD

Julian date as a JD object.

pytpm.tpm.utc_now()

Current UTC as a Julian date.

This function is only accurate to the nearest second.

Returns :

jd : float

Julian date.

The following functions convert a Julian date into a Basselian year and and vice-versa.

pytpm.tpm.byear2jd(byear)

Convert Besselian year into a Julian date.

Parameters :

byear: float :

Besselian year.

Returns :

j : float

Julian date corresponding to the given Besselian year.

Examples

>>> tpm.byear2jd(1950.0)
2433282.4234590498
>>> tpm.byear2jd(2000.0)
2451544.5333981365
pytpm.tpm.jd2byear(jd)

Convert Julian date into a Besselian year.

Parameters :

jd: float :

Julian date.

Returns :

byear : float

Besselian year corresponding to the given Julian date.

Examples

>>> tpm.jd2byear(tpm.B1950)
1950.0
>>> tpm.jd2byear(tpm.J2000)
2000.0012775135656

The following functions convert a Julian date into a Julian year and vice-versa.

pytpm.tpm.jyear2jd(jyear)

Convert Julian year into a Julian date.

Parameters :

jyear : float

Julian year.

Returns :

jd : float

Julian date corresponding to the given Julian year.

Examples

>>> tpm.jyear2jd(2000.0)
2451545.0
>>> tpm.jyear2jd(1950.0)
2433282.5
pytpm.tpm.jd2jyear(jd)

Convert Julian date into Julian year.

Parameters :

jd : float

Julian date.

Returns :

jyear : float

Julian year corresponding to the given Juilan date.

Examples

>>> tpm.jd2jyear(tpm.J2000)
2000.0
>>> tpm.jd2jyear(tpm.B1950)
1949.9997904422992

The functions below convert a Gregorian calendar date and a Julian calendar date into Julian dates.

pytpm.tpm.gcal2j(year, month, day)

Return Julian day number for the Gregorian calendar date.

Returns the Julian date for mid-night of the given date.

Parameters :

y : int

Year in the Gregorian calendar.

m : int

Month in the Gregorian calendar.

dd : int

Day in the Gregorian calendar.

Returns :

jd : float

Julian date corresponding to the given date.

Examples

>>> tpm.gcal2j(2000,1,1)
2451545.0
>>> tpm.gcal2j(2010,1,1)
2455198.0
>>> tpm.gcal2j(1950,1,1)
2433283.0
pytpm.tpm.jcal2j(year, month, day)

Return Julian day number for the Julian calendar date.

Returns the Julian date for mid-night of the given date.

Parameters :

y : int

Year in the Julian calendar.

m : int

Month in the Julian calendar.

dd : int

Day in the Julian calendar.

Returns :

jd : float

Julian date corresponding to the given date.

Examples

>>> tpm.jcal2j(1950,1,1)
2433296.0
>>> tpm.jcal2j(2000,1,1)
2451558.0
>>> tpm.jcal2j(2010,1,1)
2455211.0
>>> tpm.jcal2j(1950,1,1)
2433296.0

The function j2dow() return the day of the week corresponding to the given Julian date.

pytpm.tpm.j2dow(j)

Return day of week for the given Julian date.

Parameters :

j : float

Julian date (Gregorian calendar).

Returns :

dow : int

Day of the week: 0 - Sunday, 6 - Saturday.

Examples

>>> j = tpm.gcal2j(2010,1,1)
>>> tpm.fmt_y(tpm.j2y(j))
'Fri Jan  1 12:00:00.000 2010'
>>> tpm.j2dow(j)
5

The function y2doy() returns the number or days in the given year.

pytpm.tpm.y2doy(j)

Return number of days in the given Gregorian calendar year.

Parameters :

y : int

Year in the Gregorian calendar.

Returns :

doy : int

Number of days in the year.

Examples

>>> tpm.y2doy(2000)
366
>>> tpm.y2doy(2001)
365
>>> tpm.y2doy(2002)
365
>>> tpm.y2doy(2003)
365
>>> tpm.y2doy(2004)
366

The following two functions convert a Julian date into a year with fractional part.

pytpm.tpm.j2y(j)

Convert Julian date into Gregorian calendar year with fractional part.

Parameters :

j : float

Julian date

Returns :

year : float

Year, including fractional part, in the Gregorian

calendar. This is just (integer_year + day / num_of_days.) :

Examples

>>> tpm.j2y(tpm.J2000)
2000.0040983606557
>>> 2000+(1.5/366)
2000.0040983606557
>>> tpm.j2y(tpm.J2000+366)
2001.004109589041
pytpm.tpm.y2j(y)

Convert Gregorian calendar year with fractional part into Julian date.

Parameters :

y : float

Gregorian calendar year with fractional part.

Returns :

j : float

Julian date.

Examples

>>> tpm.y2j(2000.0040983606557)
2451545.0
>>> tpm.y2j(2001.004109589041)
2451911.0
>>> tpm.j2gcal(tpm.y2j(2001.004109589041))
{'dd': 1, 'm': 1, 'y': 2001}

Conversion between time scales

pytpm.tpm.delta_AT(utc)

Return Delta AT = TAI - UTC for the given UTC.

Warning

The file src/tpm/delta_AT.c must be updated when Delta AT is changed by the IERS, and PyTPM Cython code must re-compiled.

Parameters :

utc : float

UTC as a Julian date.

Returns :

d : float

Delta AT = TAI - UTC in seconds.

pytpm.tpm.delta_T(ut1)

Return Delta T = TT - UT1 for the given UT1.

Parameters :

ut1 : float

UT1 as a Julian date.

Returns :

dt : float

Delta T = TT - UT1 in seconds.

Notes

This function returns the TT - UT1 value for the given UT1. The value returned is ET - UT1 for dates before 1984.0 and TDT - UT1 for dates on and after 1984.0. TDT was the name of TT between 1984.0 and 2000.0.

Warning

A simple linear interpolation is carried out over a list of historical values.

pytpm.tpm.delta_UT(utc)

Return Delta UT = UT1 - UTC for the given UTC.

Parameters :

utc : float

UTC as a Julian date.

Returns :

dt : float

UT1 - UTC for in seconds.

Notes

The value of UT1 - UTC is calculated by taking the difference of delta_ET and delta_T. The later is calculated using a built-in model. For the latter the input time argument must be UT1, but the error in using UTC should be small.

pytpm.tpm.delta_ET(utc)

Return Delta ET = ET - UTC for the given UTC.

Parameters :

utc : float

UTC as a Julian date.

Returns :

dt : float

Delta ET = ET - UTC in seconds.

pytpm.tpm.delta_TT(utc)

Return Delta TT = TDT - UTC for the given UTC.

Parameters :

utc : float

UTC as a Julian date.

Returns :

dt : float

Delta TT = TDT - UTC.

pytpm.tpm.tdt2tdb(tdt)

Return TDB for the given TDT.

Parameters :

tdt : float

TDT as a Julian date.

Returns :

dt : float

TDB as a Julian date.

pytpm.tpm.ut12gmst(ut1)

Return GMST for the given UT1.

Given a UT1 Julian date, this function returns the Greenwich Mean Sidereal Time as an angle in radians in the range (0, 2π).

Parameters :

ut1 : float

UT1 as a Julian date.

Returns :

gmst : float

GMST as an angle in radians in the range 0-2π.

pytpm.tpm.et2tdt(et)

Return TDT for the given ET.

Parameters :

et : float

ET as a Julian date.

Returns :

tdt : float

TDT as a Julian date.

pytpm.tpm.tai2tdt(tai)

Return TDT for the given TAI.

Parameters :

tai : float

TAI as a Julian date.

Returns :

tdt : float

TDT as a Julian date.

pytpm.tpm.tdt2et(tdt)

Return ET for the given TDT.

Parameters :

tdt : float

TDT as a Julian date.

Returns :

et : float

ET as a Julian date.

pytpm.tpm.ut12et(ut1)

Return ET for the given UT1.

Parameters :

ut1 : float

UT1 as a Julian date.

Returns :

et : float

ET as a Julian date.

pytpm.tpm.utc2et(utc)

Return ET for the given UTC.

Parameters :

utc : float

UTC as a Julian date.

Returns :

et : float

ET as a Julian date.

pytpm.tpm.utc2tdt(utc)

Return TDT for the given UTC.

Parameters :

utc : float

UTC as a Julian date.

Returns :

tdt : float

TDT as a Julian date.

pytpm.tpm.utc2ut1(utc)

Return UT1 for the given UTC.

Parameters :

utcv: float :

UTC as a Julian date.

Returns :

ut1 : float

UT1 as a Julian date.

pytpm.tpm.et2ut1(et)

Return UT1 for the given ET.

Parameters :

et : float

ET as a Julian date.

Returns :

ut1 : float

UT1 as a Julian date.

pytpm.tpm.et2utc(et)

Return UTC for the given ET.

Parameters :

et : float

ET as a Julian date.

Returns :

utc : float

UTC as a Julian date.

pytpm.tpm.tai2utc(tai)

Return UTC for the given TAI.

Parameters :

tai : float

TAI as a Julian date.

Returns :

utc : float

UTC as a Julian date.

pytpm.tpm.tdt2tai(tdt)

Return TAI for the given TDT.

Parameters :

tdt : float

TDT as a Julian date.

Returns :

tai : float

TAI as a Julian date.

pytpm.tpm.tdt2utc(tdt)

Return UTC for the given TDT.

Parameters :

tdt : float

TDT as a Julian date.

Returns :

utc : float

UTC as a Julian date.

pytpm.tpm.ut12utc(ut1)

Return UTC for the given UT1.

Parameters :

ut1 : float

UT1 as a Julian date.

Returns :

utc : float

UTC as a Julian date.

pytpm.tpm.et2tai(et)

Return TAI for the given ET.

Parameters :

et : float

ET as a Julian date.

Returns :

tai : float

TAI as a Julian date.

pytpm.tpm.et2tdb(et)

Return TDB for the given ET.

Parameters :

et : float

ET as a Julian date.

Returns :

tdb : float

TDB as a Julian date.

pytpm.tpm.tai2et(tai)

Return ET for the given TAI.

Parameters :

tai : float

TAI as a Julian date.

Returns :

et : float

ET as a Julian date.

pytpm.tpm.tai2tdb(tai)

Return TDB for the given TAI.

Parameters :

tai : float

TAI as a Julian date.

Returns :

tdb : float

TDB as a Julian date.

pytpm.tpm.tai2ut1(tai)

Return UT1 for the given TAI.

Parameters :

tai : float

TAI as a Julian date.

Returns :

ut1 : float

UT1 as a Julian date.

pytpm.tpm.tdt2ut1(tdt)

Return UT1 for the given TDT.

Parameters :

tdt : float

TDT as a Julian date.

Returns :

ut1 : float

UT1 as a Julian date.

pytpm.tpm.ut12tai(ut1)

Return TAI for the given UT1.

Parameters :

ut1 : float

UT1 as a Julian date.

Returns :

tai : float

TAI as a Julian date.

pytpm.tpm.ut12tdb(ut1)

Return TDB for the given UT1.

Parameters :

ut1 : float

UT1 as a Julian date.

Returns :

tdb : float

TDB as a Julian date.

pytpm.tpm.ut12tdt(ut1)

Return TDT for the given UT1.

Parameters :

ut1 : float

UT1 as a Julian date.

Returns :

tdt : float

TDT as a Julian date.

pytpm.tpm.utc2tdb(utc)

Return TDB for the given UTC.

Parameters :

utc : float

UTC as a Julian date.

Returns :

tdb : float

TDB as a Julian date.

pytpm.tpm.et2ut(et)

Return UT for the given ET; same as et2ut1(et).

pytpm.tpm.ut2et(ut)

Return ET for the given UT; same as ut12et(ut).

pytpm.tpm.ut2gmst(ut)

Return GMST for the given UT; same as ut12gmst(ut)

Conversion of angles between different units

The following functions are provided for converting angles between four different units: degrees, arc-seconds, radians and hours. Many of these conversions can also be performed by using DMS and HMS objects.

pytpm.tpm.ndelta(delta, degrees=True)

Normalize angle out of the x-y plane, i.e., latitudinal angle.

This function takes an angle and normalizes it into the range [-90, 90] if it is in degrees and into the range [-π/2, π/2] if it is in radians. This is useful for angles such as declination and latitude.

Parameters :

alpha : float

Angle out of the x-y plane such as Dec.

degrees: bool :

If True then alpha in in degrees (default), else it is in radians.

Returns :

ndelta : float

Angle normalized into the range [-90, 90] or [-π/2, π/2].

See also

fmt_delta

Notes

For normalizing alpha and delta in V6S or V3SP objects, use the nalpha and ndelta attributes; they store properly normalized values, taking into account the sign of r. This function is for situations were we have a scalar angle and don’t want to create a V6S or V6SP object just for normalizing the angle.

pytpm.tpm.nalpha(alpha, degrees=True)

Normalize angle in the x-y plane, i.e., longitudinal angle.

Normalize angles to the range [0, 360.0) degrees or [0, 2π) radians. This is useful for longitudinal angles, such as right ascension and longitude.

Parameters :

alpha : float

Angle in the x-y plane, such as RA and Longitude.

degrees : bool

If True then alpha is in degrees (default), else it is in radians.

Returns :

nalpha : float

Angle normalized into the range [0, 360) or [0, 2π).

See also

r2r, h2h

Notes

For normalizing alpha and delta in V6S or V3SP objects, use the nalpha and ndelta attributes; they store properly normalized values, taking into account the sign of r. This function is for situations were we have a scalar angle and don’t want to create a V6S or V6SP object just for normalizing the angle.

pytpm.tpm.d2d(d)

Normalize angle in degrees into (-360, 360).

Parameters :

d : float

Angle in degrees.

Returns :

d : float

Angle in degrees normalized into (-360, 360).

Examples

>>> tpm.d2d(0.0)
0.0
>>> tpm.d2d(-360.0)
0.0
>>> tpm.d2d(360.0)
0.0
>>> tpm.d2d(361.0)
1.0
>>> tpm.d2d(-361.0)
359.0
pytpm.tpm.h2h(h)

Normalize angle in hours into [0, 24).

Parameters :

h : float

Angle in hours.

Returns :

h : float

Angle in hours normalized into [0, 24).

Examples

>>> tpm.h2h(0.0)
0.0
>>> tpm.h2h(24.0)
0.0
>>> tpm.h2h(25.0)
1.0
>>> tpm.h2h(-25.0)
23.0
>>> tpm.h2h(-1)
23.0
>>> tpm.h2h(1)
1.0
pytpm.tpm.r2r(r)

Normalize angle in radians into [0, 2π).

Parameters :

r : float

Angle in radians.

Returns :

r : float

Angle in radians normalized into [0, 2π).

Examples

>>> tpm.r2r(0.0)
0.0
>>> tpm.r2r(2*tpm.M_PI)
0.0
>>> tpm.r2r(tpm.M_PI)
3.1415926535897931
>>> tpm.r2r(-tpm.M_PI)
3.1415926535897931
>>> tpm.r2r(-2*tpm.M_PI)
0.0
>>> tpm.r2r(-tpm.M_PI/2.0)
4.7123889803846897
pytpm.tpm.d2h(d)

Convert angle in degrees into hours.

Parameters :

d : float

Angle in degrees.

Returns :

h : float

Angle in hours.

Examples

>>> tpm.d2h(180.0)
12.0
>>> tpm.d2h(-180.0)
-12.0
>>> tpm.d2h(12.3456)
0.82303999999999999
pytpm.tpm.h2d(h)

Convert angle in hours into degrees.

Parameters :

h : float

Angle in hours.

Returns :

d : float

Angle in degrees.

Examples

>>> tpm.h2d(12.0)
180.0
>>> tpm.h2d(-12.0)
-180.0
>>> tpm.h2d(-25)
-375.0
pytpm.tpm.d2r(d)

Convert angle in degrees into degrees.

Parameters :

d : float

Angle in degrees.

Returns :

d : float

Angle in radians.

Examples

>>> tpm.d2r(180.0)
3.1415926535897931
>>> tpm.d2r(-180.0)
-3.1415926535897931
>>> tpm.d2r(361.0)
6.3006385996995293
pytpm.tpm.r2d(r)

Convert angle in radians into degrees.

Parameters :

r : float

Angle in radians.

Returns :

d : float

Angle in degrees.

Examples

>>> tpm.r2d(tpm.M_PI)
180.0
>>> tpm.r2d(tpm.M_PI/4.0)
45.0
>>> tpm.r2d(-tpm.M_PI/4.0)
-45.0
>>> tpm.r2d(-2*tpm.M_PI)
-360.0
pytpm.tpm.h2r(h)

Convert angle in hours into radians.

Parameters :

h : float

Angle in hours.

Returns :

r : float

Angle in radians.

Examples

>>> tpm.h2r(12.0)
3.1415926535897931
>>> tpm.h2r(-12.0)
-3.1415926535897931
pytpm.tpm.r2h(r)

Convert angle in radians into hours.

Parameters :

r : float

Angle in radians.

Returns :

h : float

Angle in hours.

Examples

>>> tpm.r2h(tpm.M_PI)
12.0
>>> tpm.r2h(-tpm.M_PI)
-12.0
pytpm.tpm.d2as(d)

Convert angle in degrees into arc-seconds.

Parameters :

d : float

Angle in degrees.

Returns :

arcs : float

Angle in arc-seconds.

Examples

>>> tpm.d2as(1.0)
3600.0
>>> tpm.d2as(-1.0)
-3600.0
pytpm.tpm.as2d(arcs)

Convert angle in arc-seconds into degrees.

Parameters :

arcs : float

Angle in arc-seconds.

Returns :

d : float

Angle in degrees.

Examples

>>> tpm.as2d(3600.0)
1.0
>>> tpm.as2d(-3600.0)
-1.0
pytpm.tpm.h2as(h)

Convert angle in hours into arc-seconds.

Parameters :

h : float

Angle in hours.

Returns :

arcs : float

Angle in arc-seconds.

Examples

>>> tpm.h2as(12.0)
648000.0
>>> tpm.h2as(-12.0)
-648000.0
pytpm.tpm.as2h(arcs)

Convert angle in arc-seconds into hours.

Parameters :

arcs : float

Angle in arc-seconds.

Returns :

h : float

Angle in hours.

Examples

>>> tpm.as2h(3600.0*180.0)
12.0
>>> tpm.as2h(-3600.0*180.0)
-12.0
pytpm.tpm.r2as(r)

Convert angle in radians into arc-seconds.

Parameters :

r : float

Angle in radians.

Returns :

arcs : float

Angle in arc-seconds.

Examples

>>> tpm.r2as(tpm.M_PI)
648000.0
>>> tpm.r2as(-tpm.M_PI)
-648000.0
pytpm.tpm.as2r(arcs)

Convert angle in arc-seconds into radians.

Parameters :

arcs : float

Angle in arc-seconds.

Returns :

r : float

Angle in radians.

Examples

>>> tpm.as2r(3600.0*180.0)
3.1415926535897931
>>> tpm.as2r(-3600.0*180.0)
-3.1415926535897931

Formatting angles and dates

Formatted string representations of angles can be generated using the following functions.

pytpm.tpm.fmt_alpha(alpha)

Normalize and format angle in radians into a str: ‘ ##H ##M ##.###S’.

Parameters :

alpha : float

Angle in radians.

Returns :

fmts : str

String of the form ‘ ##H ##M ##.###S’.

Notes

This function normalizes the given angle in radians into the range [0,360) and then converts it into a string that represents angle/time in the 24-hour format. The angle is properly divided into hours, minutes and seconds.

This is useful for formatting “longitudinal” angles, such as right ascension.

Examples

>>> tpm.fmt_alpha(tpm.M_PI)
' 12H 00M 00.000S'
>>> tpm.fmt_alpha(-tpm.M_PI)
' 12H 00M 00.000S'
>>> tpm.fmt_alpha(2*tpm.M_PI)
' 00H 00M 00.000S'
>>> tpm.fmt_alpha(tpm.M_PI/2.0)
' 06H 00M 00.000S'
>>> tpm.fmt_alpha(-tpm.M_PI/2.0)
' 18H 00M 00.000S'
>>> tpm.fmt_alpha(2*tpm.M_PI+(tpm.M_PI/12.0))
' 00H 59M 59.999S'
>>> tpm.fmt_alpha(-(2*tpm.M_PI+(tpm.M_PI/12.0)))
' 23H 00M 00.000S'
pytpm.tpm.fmt_d(d)

Format angle in degrees into a string: ±###D ##’ ##.###”.

Parameters :

d : float

Angle in degrees.

Returns :

fmts : str

String of the form ±###D ##’ ##.###”.

Notes

This function will format the given angle in degrees, into a string containing degrees, arc-minutes and arc-seconds. The angle is not normalized into any range, but is used as such.

The degrees part can be two or three digits long.

Examples

>>> tpm.fmt_d(1.234567)
'+01D 14' 04.441"'
>>> tpm.fmt_d(256.9)
'+256D 53' 59.999"'
>>> tpm.fmt_d(-256.9)
'-256D 53' 59.999"'
>>> tpm.fmt_d(6.9)
'+06D 54' 00.000"'
>>> tpm.fmt_d(-361)
'-361D 00' 00.000"'
>>> tpm.fmt_d(720)
'+720D 00' 00.000"'
pytpm.tpm.fmt_delta(delta)

Normalize and format angle in radians into a str: ±###D ##’ ##.###”.

Parameters :

alpha : float

Angle in radians.

Notes

This function normalizes the given angle in radians into the range [-π/2, π/2] and then formats it into a string of the form ±###D ##’ ##.###”, where each part of the string corresponds to degrees, arc-minutes and arc-seconds.

This is useful for formatted output of “latitudinal” angles, such as declination.

Examples

>>> tpm.fmt_delta(tpm.M_PI/2.0)
'+90D 00' 00.000"'
>>> tpm.fmt_delta(-tpm.M_PI/2.0)
'-90D 00' 00.000"'
>>> tpm.fmt_delta(tpm.M_PI/4.0)
'+45D 00' 00.000"'
>>> tpm.fmt_delta(tpm.M_PI)
'+00D 00' 00.000"'
>>> tpm.fmt_delta(-tpm.M_PI)
'+00D 00' 00.000"'
pytpm.tpm.fmt_h(h)

Format hours into a string: ±##H ##M ##.###S”.

Parameters :

d : float

Angle in hours.

Returns :

fmts : str

String of the form ±##H ##M ##.###S.

Notes

This function will format the given angle in hours, into a string containing hours, minutes and seconds. The angle is not normalized into any range, but is used as such.

Examples

>>> tpm.fmt_h(1.23456)
' 01H 14M 04.416S'
>>> tpm.fmt_h(13.456)
' 13H 27M 21.599S'
>>> tpm.fmt_h(-13.456)
'-13H 27M 21.599S'
>>> tpm.fmt_h(-133.456)
'-133H 27M 21.599S'
pytpm.tpm.fmt_j(j)

Format Julian date into a string.

Parameters :

j : float

Julian date.

Returns :

fmts : str

String of the form: JD ##H ##M ##.###S.

Notes

This function takes a Julian date and returns a string that has a whole number Julian date and the fraction of the day expressed as hours, minutes and seconds in the 24-hour format.

Examples

>>> tpm.fmt_j(tpm.J2000)
' 2451545  00H 00M 00.000S'
>>> tpm.fmt_j(tpm.J2000+0.5)
' 2451545  12H 00M 00.000S'
>>> tpm.fmt_j(tpm.J2000+0.75)
' 2451545  18H 00M 00.000S'
>>> tpm.fmt_j(tpm.J2000+0.7)
' 2451545  16H 48M 00.000S'
>>> tpm.fmt_j(tpm.J2000-0.7)
' 2451544  07H 11M 59.999S'
pytpm.tpm.fmt_r(r)

Format radians into a string with angle expressed as degrees.

Parameters :

r : float

Angle in radians.

Returns :

fmts : str

String of the form: ±###D ##’ ##.###”.

Notes

The function converts the angle given in radians into degrees and then return a string of the format ±###D ##’ ##.###”. The fractional part of the angle is converted into arc-minutes and arc-seconds, but otherwise no normalization is done.

Examples

>>> tpm.fmt_r(1.0)
'+57D 17' 44.806"'
>>> tpm.fmt_r(1.2345)
'+70D 43' 53.903"'
>>> tpm.fmt_r(-2*tpm.M_PI)
'-360D 00' 00.000"'
>>> tpm.fmt_r(-3*tpm.M_PI)
'-540D 00' 00.000"'
>>> tpm.fmt_r(3*tpm.M_PI)
'+540D 00' 00.000"'
pytpm.tpm.fmt_y(y)

Format years, including fractional part, into a string.

Parameters :

y : float

Year, including fractional part.

Returns :

fmts : str

String of the form: AAA BBB DD HH:MM:SS.SSS YYYY, where AAA is the week day, BBB is the month and then the numbers that follow are indicate the day, the time in 24-hour format and the year.

Examples

>>> tpm.fmt_y(2000.0)
'Fri Dec 31 00:00:00.000 1999'
>>> tpm.fmt_y(2000.0+1.0/366)
'Sat Jan  1 00:00:00.000 2000'
>>> tpm.fmt_y(2000.0+1.25/366)
'Sat Jan  1 06:00:00.000 2000'
>>> tpm.fmt_y(2000.0+1.7/366)
'Sat Jan  1 16:48:00.000 2000'
>>> tpm.fmt_y(2001.0+32/365.0)
'Thu Feb  1 00:00:00.000 2001'

Functions for creating matrices

pytpm.tpm.m3rx()

A rotation matrix for rotation about X-axis.

Parameters :

theta : float

Rotation angle in radians.

Returns :

m3 : tpm.M3

A rotation matrix about X-axis.

Notes

The rotation matrix:

1      0          0
0 cos(theta)  sin(theta)
0 -sin(theta) cos(theta)
pytpm.tpm.m3rxdot()

Derivative of rotation matrix for rotation about X-axis.

Parameters :

theta : float

Rotation angle in radians.

thetadot : float

Rate of change of theta in radians/second.

Returns :

m3 : tpm.M3

A rotation matrix about X-axis.

Notes

The rotation matrix:

              0        0          0
thetadot *    0  -sin(theta) cos(theta)
              0  -cos(theta) -sin(theta)
pytpm.tpm.m3ry()

A rotation matrix for rotation about Y-axis.

Parameters :

theta : float

Rotation angle in radians.

Returns :

m3 : tpm.M3

A rotation matrix about Y-axis.

Notes

The rotation matrix:

cos(theta)  0  -sin(theta)
      0     1        0
sin(theta)  0   cos(theta)
pytpm.tpm.m3rydot()

Derivative of rotation matrix for rotation about Y-axis.

Parameters :

theta : float

Rotation angle in radians.

thetadot : float

Rate of change of theta in radians/second.

Returns :

m3 : tpm.M3

A rotation matrix about Y-axis.

Notes

The rotation matrix:

              -sin(theta) 0  -cos(theta)
thetadot *         0      0       0
              cos(theta)  0  -sin(theta)
pytpm.tpm.m3rz()

Rotation matrix for rotation about Z-axis.

Parameters :

theta : float

Rotation angle in radians.

Returns :

m3 : tpm.M3

A rotation matrix about Z-axis.

Notes

The rotation matrix:

 cos(theta) sin(theta) 0
-sin(theta) cos(theta) 0
      0          0     1
pytpm.tpm.m3rzdot()

Derivative of rotation matrix for rotation about Z-axis.

Parameters :

theta : float

Rotation angle in radians.

thetadot : float

Rate of change of theta in radians/second.

Returns :

m3 : tpm.M3

A rotation matrix about Z-axis.

Notes

The rotation matrix:

              -sin(theta)  cos(theta)  0
thetadot *    -cos(theta) -sin(theta)  0
                    0            0     0
pytpm.tpm.m6qx()

An M6 matrix for rotation about X-axis.

Parameters :

x : float

Angle of rotation in radians.

xdot : float

Rate of change angle of rotation in radians/second.

Returns :

m : tpm.M6

An M6 matrix for rotating a V6 vector about the X-axis.

pytpm.tpm.m6qy()

An M6 matrix for rotation about Y-axis.

Parameters :

x : float

Angle of rotation in radians.

xdot : float

Rate of change of angle of rotation in radians/second.

Returns :

m : tpm.M6

An M6 matrix for rotating a V6 vector about the Y-axis.

pytpm.tpm.m6qz()

An M6 matrix for rotation about Z-axis.

Parameters :

x : float

Angle of rotation in radians.

xdot : float

Rate of change or angle of rotation in radians/second.

Returns :

m : tpm.M6

An M6 matrix for rotating a V6 vector about the Z-axis.

Constants

Some frequently used constants. There are several more constants available, but they are mostly for internal use. See TPM headers and manual for more information on these.

M_PI Pi
MJD_0 Starting point for modified Julian dates.
B1950 Epoch B1950.0.
J2000 Epoch J2000.0.
J1984 Epoch J1984.0.
CB Number of days in a Besselian century.
CJ Number of days in a Julian century.