Skip to content

Commit

Permalink
Merge f096f45 into d670471
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewAnnex committed Jan 28, 2019
2 parents d670471 + f096f45 commit 760d199
Show file tree
Hide file tree
Showing 6 changed files with 397 additions and 157 deletions.
50 changes: 50 additions & 0 deletions docs/cells.rst
@@ -0,0 +1,50 @@
===============
Cells Explained
===============

Spice Cells are data structures included in SPICE and serve as the equivalents to lists and sets for CSPICE.
For more primary documentation on cells, please see the `Cells required reading <https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/req/cells.html>`_.
For SpiceyPy, cells can be constructed in a variety of ways, shown below.

.. code:: python
import spiceypy as spice
# create a spice bool cell using a function
bool_cell = spice.cell_bool(10)
# create a spice time cell using a function
time_cell = spice.cell_time(10)
# create a spice int cell using a function
int_cell = spice.cell_int(10)
# create a spice double cell using a function
double_cell = spice.cell_double(10)
# create a spice char cell using a function
char_cell = spice.cell_char(10, 10)
One can also use provided classes to provide easier type checking,
in future versions SpiceyPy this may become default.

.. code:: python
import spiceypy as spice
# create a spice bool cell using a function
bool_cell = spice.Cell_Bool(10)
# create a spice time cell using a function
time_cell = spice.Cell_Time(10)
# create a spice int cell using a function
int_cell = spice.Cell_Int(10)
# create a spice double cell using a function
double_cell = spice.Cell_Double(10)
# create a spice char cell using a function
char_cell = spice.Cell_Char(10, 10)
1 change: 1 addition & 0 deletions docs/index.rst
Expand Up @@ -22,6 +22,7 @@ Contents:

installation
exampleone
cells
lessonindex
documentation

Expand Down
16 changes: 16 additions & 0 deletions spiceypy/spiceypy.py
Expand Up @@ -24,6 +24,7 @@

import ctypes
from .utils import support_types as stypes
from .utils.support_types import Cell_Char, Cell_Bool, Cell_Double, Cell_Int, Cell_Time
from .utils.libspicehelper import libspice
from . import config
from .utils.callbacks import SpiceUDFUNS, SpiceUDFUNB
Expand Down Expand Up @@ -193,6 +194,21 @@ def get_found_catch_state():
"""
return config.catch_false_founds

def cell_double(cell_size):
return stypes.SPICEDOUBLE_CELL(cell_size)

def cell_int(cell_size):
return stypes.SPICEINT_CELL(cell_size)

def cell_char(cell_size, length):
return stypes.SPICECHAR_CELL(cell_size, length)

def cell_bool(cell_size):
return stypes.SPICEBOOL_CELL(cell_size)

def cell_time(cell_size):
return stypes.SPICETIME_CELL(cell_size)


################################################################################
# A
Expand Down
59 changes: 59 additions & 0 deletions spiceypy/tests/test_support_types.py
Expand Up @@ -200,4 +200,63 @@ def test_to_improve_coverage():
assert stsct.is_time()
stscb = stypes.SPICEBOOL_CELL(10)
assert stscb.is_bool()
stsct2 = stypes.Cell_Time(10)
assert stsct2.is_time()
stscb2 = stypes.Cell_Bool(10)
assert stscb2.is_bool()
assert stscb.reset() is None


def test_Cell_Double_empty():
cell = stypes.Cell_Double(1)
assert isinstance(cell, stypes.Cell_Double)
assert isinstance(cell, stypes.SpiceCell)
assert cell[0:1] == []

def test_Cell_Double():
cell = stypes.Cell_Double(8)
spice.appndd(1.1, cell)
spice.appndd(2.2, cell)
spice.appndd(3.3, cell)
assert [x for x in cell] == [1.1,2.2,3.3]

def test_Cell_Int_empty():
cell = stypes.Cell_Int(1)
assert isinstance(cell, stypes.Cell_Int)
assert isinstance(cell, stypes.SpiceCell)
assert cell[0:1] == []

def test_Cell_Int():
cell = stypes.Cell_Int(8)
spice.appndi(1, cell)
spice.appndi(2, cell)
spice.appndi(3, cell)
assert [x for x in cell] == [1,2,3]

def test_Cell_Char():
testCell = stypes.Cell_Char(10,10)
spice.appndc("one", testCell)
spice.appndc("two", testCell)
spice.appndc("three", testCell)
assert testCell[0] == "one"
assert testCell[1] == "two"
assert testCell[2] == "three"

def test_cell_equality():
cell = stypes.Cell_Int(8)
assert cell == []
spice.appndi(1, cell)
spice.appndi(2, cell)
spice.appndi(3, cell)
assert not cell == []
assert not cell == [1]
assert not cell == [1, 2]
assert cell == [1, 2, 3]
assert not cell == [1, 2, 3, 4]
celld = stypes.Cell_Double(8)
spice.appndd(1.1, celld)
spice.appndd(2.2, celld)
spice.appndd(3.3, celld)
assert celld == [1.1, 2.2, 3.3]
assert not celld == cell

0 comments on commit 760d199

Please sign in to comment.