irfpy.mexpvat.mexspice

MEX spice related module

This module provide the MEX-related spice access simpler.

.irfpyrc file should have following entry.

[mexpvat] spiceroot = /Volumes/scidata/data/mars/spice/kernels/

The above path is looked through as root path of SPICE kernel.

There are three levels of the kernel set.

  • ‘full’ kernel set is to load all the kernels.

  • ‘noatt’ kernel set does not load attitude file. One may use this option if one only wants the orbit data.

  • ‘min’ kernel set provide minimum set, namely no attitude/no orbit but for example, Mars position or spacecraft frames are defined.

Obviously if you choose ‘min’ set, it is much faster than ‘full’ set for calculation.

>>> init(level='min')

You may overwrite the level. In this case, only the kernel not to be furnshed is loaded.

>>> init(level='noatt')

Each file can also be furnshed.

mexspice.furnsh('sp/EARTH.BSP')

A sample code is seen in snippet.mexspicesample.

Todo

SpiceFactory should not check the kernels if they have been loaded. In SPICE, the last kernel loaded is in priority, user have to add specific kernel in the end, if necessarily.

Note

Since March 2017, ESA looks to provide MK file, which contains the meta data of SPICE. The current version just ignores this file.

For the future development, the MK file will be used.

irfpy.mexpvat.mexspice.isdb()[source]
class irfpy.mexpvat.mexspice.Attfiles[source]

Bases: object

Attitude file handling class.

Intention is to implement the automatic furnsh routine for attitude file from time, but it may need a moderate job.

Now, the implementaion of that functionality is on hold.

Todo

Implement the auto-load function of attitude file (and orbit file) from the given time.

class Attfile(fn)[source]

Bases: object

makelist()[source]
class irfpy.mexpvat.mexspice.MexSpiceFactory[source]

Bases: object

Use create() function for creating the object.

exclude_kernel

List of filename to remove from the get_xxxx method

showstatus()[source]
get(level='full', dataonly=True)[source]

Return the filename list of kernel.

Parameters

level – “full”, “noatt”, or “min”.

get_full(), get_noatt(), or get_min().

get_full(dataonly=True)[source]

Get the kernel file name list.

get_noatt(dataonly=True)[source]

Update the nonatt MK file.

Update MK file that does not include attitude file.

get_min(dataonly=True)[source]

Update the minimum MK file.

Minimum MK file contains all the files except for orbit and attitude.

Parameters

dataonly – If set to True (default), only the kernels related to data analysis is returned. Otherwise, all the data below the specific directory is returned.

furnsheach(fname)[source]
furnsh(fnames)[source]

Furnsh a file, file list, or the name of the set

Parameters

fnames – Single file, file list, or the name of the set. Name of the set is eithr “full”, “noatt”, “min”.

irfpy.mexpvat.mexspice.init_full(update=True)[source]

Furnsh default kernels.

Parameters

update – No effect anymore.

irfpy.mexpvat.mexspice.init_noatt(update=True)[source]

Furnsh default kernels.

Parameters

update – No effect anymore.

irfpy.mexpvat.mexspice.init_min(update=True)[source]

Furnsh minimum kernels.

Parameters

update – No effect anymore.

irfpy.mexpvat.mexspice.init(level='full')[source]
irfpy.mexpvat.mexspice.furnsh(kernel_file)[source]

Furnsh additional kernel file

irfpy.mexpvat.mexspice.updatemk(noatt=False, mkfile=None)[source]

(DEPRECATED) Update the mk file.

Walk throught the path under spiceroot, create mk file.

Excluding *.txt

>>> updatemk()
irfpy.mexpvat.mexspice.get_position(t, target='MEX', origin='MARS', frame='MSO', correction='LT+S')[source]

Get the position. By default, MEX in MSO.

>>> if not isdb():
...     pass  
... else:
...     pos = get_position(datetime.datetime(2006, 12, 2, 15, 30))
...     print('%.2f %.2f %.2f' % (pos[0], pos[1], pos[2]))  # may change slightly
6265.30 -4041.08 -5409.83
irfpy.mexpvat.mexspice.height(t)[source]

The height at the time of t.

Parameters

t

Returns

The height above Mars (r=3396)

irfpy.mexpvat.mexspice.get_positions(tlist, target='MEX', origin='MARS', frame='MSO', correction='LT+S')[source]

Get the time series of the position.

Parameters

tlist – Iterable of datetime.datetime object.

Returns

(N, 3) array of the position vector.

>>> tlist = [datetime.datetime(2012, 1, 1, 12), datetime.datetime(2012, 1, 1, 13)]
>>> positions = get_positions(tlist)
>>> print(positions.shape)
(2, 3)
>>> print("{p[0]:.2f} {p[1]:.2f} {p[2]:.2f}".format(p=positions[0, :]))
-1459.99 -4650.47 -7384.98
>>> print("{p[0]:.2f} {p[1]:.2f} {p[2]:.2f}".format(p=positions[1, :]))
-1461.35 3435.04 -1096.03
irfpy.mexpvat.mexspice.state_generator(t0, t1=None, dt=datetime.timedelta(seconds=60), target='MEX', origin='MARS', frame='MSO', correction='LT+S')[source]

Return a generator to get state vector.

Parameters

t1 – Time to stop (Default is None, meaning 100*dt)

>>> init_noatt()
>>> t0 = datetime.datetime(2014, 10, 19, 18, 30)
>>> dt = datetime.timedelta(minutes=1)
>>> t1 = datetime.datetime(2014, 10, 19, 18, 33)
>>> for t, pv in state_generator(t0, dt=dt, t1=t1):
...      print("{t} {pv[0]:.1f} {pv[1]:.1f} {pv[2]:.1f}".format(t=t, pv=pv))
2014-10-19 18:30:00 1833.9 2689.1 2343.6
2014-10-19 18:31:00 1927.6 2840.0 2178.1
2014-10-19 18:32:00 2016.9 2984.4 2007.5
2014-10-19 18:33:00 2101.7 3122.2 1832.6
irfpy.mexpvat.mexspice.pericenter(t0, dt=datetime.timedelta(seconds=1))[source]

Return the first pericenter around the time t0 from BC kernel.

>>> init_noatt()
>>> t0 = datetime.datetime(2014, 10, 19, 17)
>>> tp, hp = pericenter(t0)   # The pericenter time after t0 from SPICE.
>>> print(tp, '{:.1f}'.format(hp))
2014-10-19 18:20:47 362.2
>>> tp, hp = pericenter(datetime.datetime(2014, 10, 18, 17))   # Given is ascending
>>> print(tp, '{:.1f}'.format(hp))
2014-10-18 14:22:52 362.2

See also irfpy.mexpvat.orbnum.OrbnumKernel, but from Orbit file kernel.

irfpy.mexpvat.mexspice.when_at_height(t0, h, t1=None, dt=datetime.timedelta(seconds=1))[source]

Return the time after t0 when the altitude (from the surface) crosses the given altitude.

Parameters
  • t0 – Time to start calculation

  • h – Height in km.

  • end – Time to stop the investigate. Default is None, which gives 12 hours (to give more than 1 orbit).

Keywrod dt

Time resolution to calculate

Returns

The time.

>>> init_noatt()
>>> t0 = datetime.datetime(2014, 10, 19, 16)
>>> t_at_1000 = when_at_height(t0, 1000)   # Want to know the time of 1000 km altitude crossing
>>> print(t_at_1000)
2014-10-19 18:05:34
>>> p = get_position(datetime.datetime(2014, 10, 19, 18, 5, 34))
>>> print('{:.2f}'.format(np.sqrt((p ** 2).sum())-3396))
998.78
irfpy.mexpvat.mexspice.get_posvel(t, target='MEX', origin='MARS', correction='LT+S', frame='MSO')[source]
irfpy.mexpvat.mexspice.get_scannerangle(t)[source]

Return the scanner angle in degrees.

irfpy.mexpvat.mexspice.et(t)[source]

Return the et from the given datetime object.

irfpy.mexpvat.mexspice.showstatus()[source]
irfpy.mexpvat.mexspice.loaded_kernels()[source]
irfpy.mexpvat.mexspice.init_sidingspring()[source]

Initialize the siding spring kernel. Also defines the name ‘CSS’

>>> init()   
>>> init_sidingspring()   
>>> sspos = get_position(datetime.datetime(2014, 9, 18, 17, 30), target='CSS', origin='Mars', frame='MSO')   
>>> print('{x[0]:.3e} {x[1]:.3e} {x[2]:.3e}'.format(x=sspos))   
4.079e+07 -1.221e+08 -7.222e+07
[mexpvat]
sidingspring_bsp = /path/to/siding_spring_s46.bsp