irfpy.spice.spicetools

Misc tools related to SPICE

irfpy.spice.spicetools.set_error_action(strategy)[source]
Parameters:

strategy – Strategy, ‘abort’, ‘report’, ‘return’, ‘ignore’, or ‘default’.

See SPICE document (erract_c()) for details.

irfpy.spice.spicetools.get_state(t, target, origin, frame, correction='NONE')[source]

Get the state of target from origin in frame.

Parameters:
  • t – datetime object.

  • target – SPICE name of the target

  • origin – SPICE name of the origin

  • frame – SPICE name of the frame

  • correction – SPICE aberration correction

>>> get_state(datetime.datetime(2014, 10, 5, 3, 20, 15), 'MARS', "SUN", 'J2000', correction='LT+S')
array([  8.39495688e+07,  -1.75490667e+08,  -8.27591341e+07,
     2.31543409e+01,   1.08699922e+01,   4.36065716e+00])
irfpy.spice.spicetools.state(t0, t1, dt, target, origin, frame, correction='NONE')[source]

Generator of the state vector.

Parameters:
  • t0 – Start time

  • t1 – End time (exclusive)

  • dt – Time delta

  • target – SPICE name of target

  • origin – SPICE name of origin

  • frame – SPICE name of the frame

  • correction – SPICE aberration correction

Returns:

Generator, yielding the tuple (t, pos, vel).

>>> t0 = datetime.datetime(2014, 10, 1, 12, 0)
>>> t1 = datetime.datetime(2014, 10, 1, 12, 10)
>>> dt = datetime.timedelta(minutes=2)
>>> for t, xv in state(t0, t1, dt, 'SUN', 'MARS', 'J2000', correction='LT+S'):
...     print(t, xv[:3], xv[3:])
2014-10-01 12:00:00 [ -7.66126240e+07   1.78785069e+08   8.40721063e+07] [-23.50762679 -10.09017858  -3.99343982]
2014-10-01 12:02:00 [ -7.66154449e+07   1.78783858e+08   8.40716271e+07] [-23.50749856 -10.09047781  -3.99358053]
2014-10-01 12:04:00 [ -7.66182658e+07   1.78782647e+08   8.40711478e+07] [-23.50737033 -10.09077705  -3.99372125]
2014-10-01 12:06:00 [ -7.66210866e+07   1.78781436e+08   8.40706686e+07] [-23.50724209 -10.09107629  -3.99386196]
2014-10-01 12:08:00 [ -7.66239075e+07   1.78780225e+08   8.40701893e+07] [-23.50711385 -10.09137552  -3.99400267]
irfpy.spice.spicetools.get_position(t, target, origin, frame, correction='NONE')[source]

Get the position of target from origin in frame.

Parameters:
  • t – datetime object or its list

  • target – SPICE name of the target

  • origin – SPICE name of the origin

  • frame – SPICE name of the frame

  • correction – Correction allowed by SPICE

irfpy.spice.spicetools.position(t0, t1, dt, target, origin, frame, correction='NONE')[source]

Generator of the position vectors.

Parameters:
  • t0 – Start time

  • t1 – End time (exclusive)

  • dt – Time delta

  • target – SPICE name of target

  • origin – SPICE name of origin

  • frame – SPICE name of the frame

  • correction – SPICE aberration correction

Returns:

Generator, yielding the tuple (t, pos).

>>> t0 = datetime.datetime(2014, 10, 1, 12, 0)
>>> t1 = datetime.datetime(2014, 10, 1, 12, 10)
>>> dt = datetime.timedelta(minutes=2)
>>> for t, x in position(t0, t1, dt, 'SUN', 'MARS', 'J2000', correction='LT+S'):
...     print(t, x)
2014-10-01 12:00:00 [ -7.66126240e+07   1.78785069e+08   8.40721063e+07]
2014-10-01 12:02:00 [ -7.66154449e+07   1.78783858e+08   8.40716271e+07]
2014-10-01 12:04:00 [ -7.66182658e+07   1.78782647e+08   8.40711478e+07]
2014-10-01 12:06:00 [ -7.66210866e+07   1.78781436e+08   8.40706686e+07]
2014-10-01 12:08:00 [ -7.66239075e+07   1.78780225e+08   8.40701893e+07]
irfpy.spice.spicetools.get_velocity(t, target, origin, frame, correction='NONE')[source]

Get the velocity of target relative to origin in frame.

Parameters:
  • t – datetime object.

  • target – SPICE name of the target

  • origin – SPICE name of the origin

  • frame – SPICE name of the frame

  • correction – Correction allowed by SPICE

irfpy.spice.spicetools.velocity(t0, t1, dt, target, origin, frame, correction='NONE')[source]

Generator of the velocity vectors.

Parameters:
  • t0 – Start time

  • t1 – End time (exclusive)

  • dt – Time delta

  • target – SPICE name of target

  • origin – SPICE name of origin

  • frame – SPICE name of the frame

  • correction – SPICE aberration correction

Returns:

Generator, yielding the tuple (t, vel).

>>> t0 = datetime.datetime(2014, 10, 1, 12, 0)
>>> t1 = datetime.datetime(2014, 10, 1, 12, 10)
>>> dt = datetime.timedelta(minutes=2)
>>> for t, v in velocity(t0, t1, dt, 'SUN', 'MARS', 'J2000', correction='LT+S'):
...     print(t, v)
2014-10-01 12:00:00 [-23.50762679 -10.09017858  -3.99343982]
2014-10-01 12:02:00 [-23.50749856 -10.09047781  -3.99358053]
2014-10-01 12:04:00 [-23.50737033 -10.09077705  -3.99372125]
2014-10-01 12:06:00 [-23.50724209 -10.09107629  -3.99386196]
2014-10-01 12:08:00 [-23.50711385 -10.09137552  -3.99400267]
irfpy.spice.spicetools.get_distance(t, target, origin, frame='J2000', correction='NONE')[source]

Return the distance.

irfpy.spice.spicetools.distance(t0, t1, dt, target, origin, frame='J2000', correction='NONE')[source]

Generator for distance.

>>> for t, h in distance(datetime.datetime(2014, 10, 1, 15),
...                      datetime.datetime(2014, 10, 1, 16), datetime.timedelta(minutes=1),
...                      'MEX', 'MARS', frame='MSO'):
...     print(t, h)
irfpy.spice.spicetools.get_sza(t, target, origin, frame='J2000', correction='NONE')[source]

Return the solar zenith angle in degrees.

irfpy.spice.spicetools.sza(t0, t1, dt, target, origin, frame='J2000', correction='NONE')[source]
irfpy.spice.spicetools.get_conversion_matrix(t, frame0, frame1)[source]

Return the frame conversion matrix (3x3)

If you want to convert from the MEX_SPACECRAFT frame to MSO frame, you may get a conversion matrix as follows.

>>> m = get_conversion_matrix(datetime.datetime(2014, 1, 23, 15, 30), 'MEX_SPACECRAFT', 'MSO')
>>> print(m.shape)
(3, 3)
irfpy.spice.spicetools.conversion_matrix(t0, t1, dt, frame0, frame1)[source]
irfpy.spice.spicetools.get_conversion_matrix_6d(t, frame0, frame1)[source]

Return the frame conversion matrix (6x6)

If you want to convert from the J2000 frame to IAU_MARS frame, you may get a conversion matrix as follows.

>>> m = get_conversion_matrix(datetime.datetime(2014, 1, 23, 15, 30), 'J2000', 'IAU_MARS')
>>> print(m.shape)
(6, 6)
irfpy.spice.spicetools.conversion_matrix_6d(t0, t1, dt, frame0, frame1)[source]
irfpy.spice.spicetools.et(t)[source]

Get the et from the datetime object.

Preparation. >>> import datetime >>> from irfpy.spice import localize >>> localize.furnsh_tls()

Execution. >>> print(et(datetime.datetime(2020, 1, 1))) 631108869.1839073

>>> print(et([datetime.datetime(2020, 1, 1), datetime.datetime(2020, 1, 2)]))
(631108869.1839073, 631195269.1839362)
class irfpy.spice.spicetools.RVec(x: float, y: float, z: float, frame: str = 'UNDEFINED', origin: str = 'UNDEFINED', target: str = 'UNDEFINED')[source]

Bases: object

Representing a position vector

x: float
y: float
z: float
frame: str = 'UNDEFINED'
origin: str = 'UNDEFINED'
target: str = 'UNDEFINED'
property distance
property longitude
property latitude
class irfpy.spice.spicetools.VVec(vx: float, vy: float, vz: float, frame: str = 'UNDEFINED', observer: str = 'UNDEFINED', target: str = 'UNDEFINED')[source]

Bases: object

Representing a velocity vector

vx: float
vy: float
vz: float
frame: str = 'UNDEFINED'
observer: str = 'UNDEFINED'
target: str = 'UNDEFINED'
property speed
property azimuth
property elevation
class irfpy.spice.spicetools.SpiceEpochData(t, et, y, z, vx, vy, vz, target, frame, origin, lt, corr)[source]

Bases: NamedTuple

Create new instance of SpiceEpochData(t, et, y, z, vx, vy, vz, target, frame, origin, lt, corr)

t: datetime

Alias for field number 0

et: float

Alias for field number 1

y: float

Alias for field number 2

z: float

Alias for field number 3

vx: float

Alias for field number 4

vy: float

Alias for field number 5

vz: float

Alias for field number 6

target: str

Alias for field number 7

frame: str

Alias for field number 8

origin: str

Alias for field number 9

lt: float

Alias for field number 10

corr: str

Alias for field number 11

property distance
property speed
property longitude
property latitude
property vazim
property velev
property rvec
property vvec
property norm
property vnorm
property rlonlat
property vasel
irfpy.spice.spicetools.length(x, y, z)[source]
>>> print(length(3, 0, 4))
5.0
irfpy.spice.spicetools.longitude(x, y, z=None)[source]

Return longitude in degrees, (-180 180].

Parameters:
  • x – X coords

  • y – Y coords

  • z – Z coords, not used for calculation.

>>> print(longitude(1, 0, 0))
0.0
>>> print(longitude(0, 1, 0))
90.0
>>> print(longitude([-1, 0], [0, -1]))
[180. -90.]

For zero vector, it returns 0.

>>> print(longitude(0, 0, 0))
0.0
irfpy.spice.spicetools.latitude(x, y, z)[source]

Return latitude in degrees, [-90, 90].

>>> print(latitude(0, 0, 1))
90.0
>>> print(latitude(1, 3, 0))
0.0

For zero vector, it returns 0.

>>> print(latitude(0, 0, 0))
0.0

Vector support

>>> print(latitude([0, 1], [0, 3], [0, 0]))
[0. 0.]
irfpy.spice.spicetools.get_epoch_data(t, target, origin, frame, correction='NONE')[source]