diff --git a/docs/cells.rst b/docs/cells.rst new file mode 100644 index 00000000..904233c0 --- /dev/null +++ b/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 `_. +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) diff --git a/docs/index.rst b/docs/index.rst index 5dc5f7ca..1ded10c2 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -22,6 +22,7 @@ Contents: installation exampleone + cells lessonindex documentation diff --git a/spiceypy/spiceypy.py b/spiceypy/spiceypy.py index b361ae8b..4338be1c 100644 --- a/spiceypy/spiceypy.py +++ b/spiceypy/spiceypy.py @@ -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 @@ -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 diff --git a/spiceypy/tests/test_support_types.py b/spiceypy/tests/test_support_types.py index e229908d..9ac30ad2 100644 --- a/spiceypy/tests/test_support_types.py +++ b/spiceypy/tests/test_support_types.py @@ -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 + diff --git a/spiceypy/tests/test_wrapper.py b/spiceypy/tests/test_wrapper.py index 12d3115b..ee59dd7a 100644 --- a/spiceypy/tests/test_wrapper.py +++ b/spiceypy/tests/test_wrapper.py @@ -45,7 +45,7 @@ def setup_module(module): def test_appndc(): - testCell = spice.stypes.SPICECHAR_CELL(10, 10) + testCell = spice.cell_char(10, 10) spice.appndc("one", testCell) spice.appndc("two", testCell) spice.appndc("three", testCell) @@ -53,9 +53,17 @@ def test_appndc(): assert testCell[1] == "two" assert testCell[2] == "three" +def test_appndc2(): + testCell = spice.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_appndc_vectorized(): - testCell = spice.stypes.SPICECHAR_CELL(10, 10) + testCell = spice.cell_char(10, 10) spice.appndc(["one", "two", "three"], testCell) assert testCell[0] == "one" assert testCell[1] == "two" @@ -63,7 +71,7 @@ def test_appndc_vectorized(): def test_appndd(): - testCell = spice.stypes.SPICEDOUBLE_CELL(8) + testCell = spice.cell_double(8) spice.appndd(1.0, testCell) spice.appndd(2.0, testCell) spice.appndd(3.0, testCell) @@ -71,13 +79,13 @@ def test_appndd(): def test_appndd_vectorized(): - testCell = spice.stypes.SPICEDOUBLE_CELL(8) + testCell = spice.cell_double(8) spice.appndd([1.0, 2.0, 3.0], testCell) assert [x for x in testCell] == [1.0, 2.0, 3.0] def test_appndi(): - testCell = spice.stypes.SPICEINT_CELL(8) + testCell = spice.cell_int(8) spice.appndi(1, testCell) spice.appndi(2, testCell) spice.appndi(3, testCell) @@ -85,7 +93,7 @@ def test_appndi(): def test_appndi_vectorized(): - testCell = spice.stypes.SPICEINT_CELL(8) + testCell = spice.cell_int(8) spice.appndi([1, 2, 3], testCell) assert [x for x in testCell] == [1, 2, 3] @@ -260,7 +268,7 @@ def test_bsrchi(): def test_card(): - testCell = spice.stypes.SPICEDOUBLE_CELL(8) + testCell = spice.cell_double(8) assert spice.card(testCell) == 0 spice.appndd(1.0, testCell) assert spice.card(testCell) == 1 @@ -719,7 +727,7 @@ def test_copy(): assert cellCopy is not outCell assert cellCopy.dtype is 2 # SPICECHAR_CELL; dtype=0 - cellSrc = spice.stypes.SPICECHAR_CELL(10,10) + cellSrc = spice.cell_char(10,10) tmpRtn = [spice.appndc('{}'.format(i), cellSrc) for i in range(5)] cellCopy = spice.copy(cellSrc) assert cellCopy.dtype is 0 @@ -728,7 +736,7 @@ def test_copy(): assert cellCopy[:] == cellSrc[:] assert cellCopy.length >= cellSrc.length # SPICEDOUBLE_CELL; dtype=1 - cellSrc = spice.stypes.SPICEDOUBLE_CELL(10) + cellSrc = spice.cell_double(10) tmpRtn = [spice.appndd(float(i), cellSrc) for i in range(8)] cellCopy = spice.copy(cellSrc) assert cellCopy.dtype is 1 @@ -736,7 +744,7 @@ def test_copy(): assert cellCopy.card == cellSrc.card assert cellCopy[:] == cellSrc[:] # SPICEBOOLEAN_CELL; dtype=4 - cellSrc = spice.stypes.SpiceCell(dtype=spice.stypes.SpiceCell.DATATYPES_ENUM['bool'], size=9, length=0, card=0, isSet=False) + cellSrc = spice.cell_bool(9) with pytest.raises(NotImplementedError): spice.copy(cellSrc) @@ -1037,7 +1045,7 @@ def test_dafgsr(): handle = spice.dafopr(CoreKernels.spk) # get ND, NI (N.B. for SPKs, ND=2 and NI=6), # and first, last and free record numbers - nd, ni, ifname, fward, bward, free = rtnDafrfr = spice.dafrfr(handle) + nd, ni, ifname, fward, bward, free = spice.dafrfr(handle) assert nd == 2 and ni == 6 # Calculate Single Summary size ss = nd + ((ni+1) >> 1) @@ -1157,7 +1165,7 @@ def test_dafrda(): handle = spice.dafopr(CoreKernels.spk) # get ND, NI (N.B. for SPKs, ND=2 and NI=6), # and first, last and free record numbers - nd, ni, ifname, fward, bward, free = rtnDafrfr = spice.dafrfr(handle) + nd, ni, ifname, fward, bward, free = spice.dafrfr(handle) assert nd == 2 and ni == 6 # Calculate Single Summary size ss = nd + ((ni+1) >> 1) @@ -1368,8 +1376,8 @@ def test_diags2(): def test_diff(): # SPICEINT_CELL - testCellOne = spice.stypes.SPICEINT_CELL(8) - testCellTwo = spice.stypes.SPICEINT_CELL(8) + testCellOne = spice.cell_int(8) + testCellTwo = spice.cell_int(8) spice.insrti(1, testCellOne) spice.insrti(2, testCellOne) spice.insrti(3, testCellOne) @@ -1381,8 +1389,8 @@ def test_diff(): outCell = spice.diff(testCellTwo, testCellOne) assert [x for x in outCell] == [4] # SPICECHAR_CELL - testCellOne = spice.stypes.SPICECHAR_CELL(8, 8) - testCellTwo = spice.stypes.SPICECHAR_CELL(8, 8) + testCellOne = spice.cell_char(8, 8) + testCellTwo = spice.cell_char(8, 8) spice.insrtc('1', testCellOne) spice.insrtc('2', testCellOne) spice.insrtc('3', testCellOne) @@ -1394,8 +1402,8 @@ def test_diff(): outCell = spice.diff(testCellTwo, testCellOne) assert [x for x in outCell] == ['4'] # SPICEDOUBLE_CELL - testCellOne = spice.stypes.SPICEDOUBLE_CELL(8) - testCellTwo = spice.stypes.SPICEDOUBLE_CELL(8) + testCellOne = spice.cell_double(8) + testCellTwo = spice.cell_double(8) spice.insrtd(1.0, testCellOne) spice.insrtd(2.0, testCellOne) spice.insrtd(3.0, testCellOne) @@ -1407,8 +1415,8 @@ def test_diff(): outCell = spice.diff(testCellTwo, testCellOne) assert [x for x in outCell] == [4.0] # SPICEBOOLEAN_CELL; dtype=4 - testCellOne = spice.stypes.SpiceCell(dtype=spice.stypes.SpiceCell.DATATYPES_ENUM['bool'], size=9, length=0, card=0, isSet=False) - testCellTwo = spice.stypes.SpiceCell(dtype=spice.stypes.SpiceCell.DATATYPES_ENUM['bool'], size=9, length=0, card=0, isSet=False) + testCellOne = spice.cell_bool(9) + testCellTwo = spice.cell_bool(9) with pytest.raises(NotImplementedError): spice.diff(testCellOne, testCellTwo) @@ -2764,7 +2772,7 @@ def test_el2cgv(): def test_elemc(): - testCellOne = spice.stypes.SPICECHAR_CELL(10, 10) + testCellOne = spice.cell_char(10, 10) spice.insrtc("one", testCellOne) spice.insrtc("two", testCellOne) spice.insrtc("three", testCellOne) @@ -2776,7 +2784,7 @@ def test_elemc(): def test_elemd(): - testCellOne = spice.stypes.SPICEDOUBLE_CELL(8) + testCellOne = spice.cell_double(8) spice.insrtd(1.0, testCellOne) spice.insrtd(2.0, testCellOne) spice.insrtd(3.0, testCellOne) @@ -2788,7 +2796,7 @@ def test_elemd(): def test_elemi(): - testCellOne = spice.stypes.SPICEINT_CELL(8) + testCellOne = spice.cell_int(8) spice.insrti(1, testCellOne) spice.insrti(2, testCellOne) spice.insrti(3, testCellOne) @@ -3151,9 +3159,9 @@ def test_gfdist(): spice.furnsh(CoreKernels.testMetaKernel) et0 = spice.str2et('2007 JAN 01 00:00:00 TDB') et1 = spice.str2et('2007 APR 01 00:00:00 TDB') - cnfine = spice.stypes.SPICEDOUBLE_CELL(2) + cnfine = spice.cell_double(2) spice.wninsd(et0, et1, cnfine) - result = spice.stypes.SPICEDOUBLE_CELL(1000) + result = spice.cell_double(1000) spice.gfdist("moon", "none", "earth", ">", 400000, 0.0, spice.spd(), 1000, cnfine, result) count = spice.wncard(result) assert count == 4 @@ -3178,9 +3186,9 @@ def test_gfevnt(): # et_start = spice.str2et("2001 jan 01 00:00:00.000") et_end = spice.str2et("2001 dec 31 00:00:00.000") - cnfine = spice.stypes.SPICEDOUBLE_CELL(2) + cnfine = spice.cell_double(2) spice.wninsd(et_start, et_end, cnfine) - result = spice.stypes.SPICEDOUBLE_CELL(1000) + result = spice.cell_double(1000) qpnams = ["TARGET", "OBSERVER", "ABCORR"] qcpars = ["MOON ", "EARTH ", "LT+S "] # Set the step size to 1/1000 day and convert to seconds @@ -3229,9 +3237,9 @@ def test_gffove(): # Split confinement window, from continuous CK coverage, into two pieces et_start = spice.str2et("2013-FEB-25 10:00:00.000") et_end = spice.str2et("2013-FEB-25 11:45:00.000") - cnfine = spice.stypes.SPICEDOUBLE_CELL(2) + cnfine = spice.cell_double(2) spice.wninsd(et_start, et_end, cnfine) - result = spice.stypes.SPICEDOUBLE_CELL(1000) + result = spice.cell_double(1000) # call gffove udstep = spiceypy.utils.callbacks.SpiceUDSTEP(spice.gfstep) udrefn = spiceypy.utils.callbacks.SpiceUDREFN(spice.gfrefn) @@ -3268,16 +3276,16 @@ def test_gfilum(): startET = spice.str2et("1971 OCT 02 00:00:00 UTC") endET = spice.str2et("1971 NOV 30 12:00:00 UTC") # Create confining and result windows for incidence angle GF check - cnfine = spice.stypes.SPICEDOUBLE_CELL(2000) + cnfine = spice.cell_double(2000) spice.wninsd(startET, endET, cnfine) - wnsolr = spice.stypes.SPICEDOUBLE_CELL(2000) + wnsolr = spice.cell_double(2000) # Find windows where solar incidence angle at MER-1 position is < 60deg spice.gfilum("Ellipsoid", "INCIDENCE", "Mars", "Sun", "iau_mars", "CN+S", "PHOBOS", pos, "<", 60.0 * spice.rpd(), 0.0, 21600.0, 1000, cnfine, wnsolr) # Create result window for emission angle GF check - result = spice.stypes.SPICEDOUBLE_CELL(2000) + result = spice.cell_double(2000) # Find windows, within solar incidence angle windows found above (wnsolar), # where emission angle from MER-1 position to Phobos is < 20deg spice.gfilum("Ellipsoid", "EMISSION", "Mars", "Sun", @@ -3308,9 +3316,9 @@ def test_gfocce(): spice.furnsh(CoreKernels.testMetaKernel) et0 = spice.str2et('2001 DEC 01 00:00:00 TDB') et1 = spice.str2et('2002 JAN 01 00:00:00 TDB') - cnfine = spice.stypes.SPICEDOUBLE_CELL(2) + cnfine = spice.cell_double(2) spice.wninsd(et0, et1, cnfine) - result = spice.stypes.SPICEDOUBLE_CELL(1000) + result = spice.cell_double(1000) spice.gfsstp(20.0) udstep = spiceypy.utils.callbacks.SpiceUDSTEP(spice.gfstep) udrefn = spiceypy.utils.callbacks.SpiceUDREFN(spice.gfrefn) @@ -3335,9 +3343,9 @@ def test_gfoclt(): spice.furnsh(CoreKernels.testMetaKernel) et0 = spice.str2et('2001 DEC 01 00:00:00 TDB') et1 = spice.str2et('2002 JAN 01 00:00:00 TDB') - cnfine = spice.stypes.SPICEDOUBLE_CELL(2) + cnfine = spice.cell_double(2) spice.wninsd(et0, et1, cnfine) - result = spice.stypes.SPICEDOUBLE_CELL(1000) + result = spice.cell_double(1000) spice.gfoclt("any", "moon", "ellipsoid", "iau_moon", "sun", "ellipsoid", "iau_sun", "lt", "earth", 180.0, cnfine, result) count = spice.wncard(result) @@ -3367,9 +3375,9 @@ def test_gfpa(): spice.furnsh(CoreKernels.testMetaKernel) et0 = spice.str2et('2006 DEC 01') et1 = spice.str2et('2007 JAN 31') - cnfine = spice.stypes.SPICEDOUBLE_CELL(2) + cnfine = spice.cell_double(2) spice.wninsd(et0, et1, cnfine) - result = spice.stypes.SPICEDOUBLE_CELL(2000) + result = spice.cell_double(2000) for relation in relate: spice.gfpa("Moon", "Sun", "LT+S", "Earth", relation, 0.57598845, 0.0, spice.spd(), 5000, cnfine, result) @@ -3391,9 +3399,9 @@ def test_gfposc(): spice.furnsh(CoreKernels.testMetaKernel) et0 = spice.str2et('2007 JAN 01') et1 = spice.str2et('2008 JAN 01') - cnfine = spice.stypes.SPICEDOUBLE_CELL(2) + cnfine = spice.cell_double(2) spice.wninsd(et0, et1, cnfine) - result = spice.stypes.SPICEDOUBLE_CELL(1000) + result = spice.cell_double(1000) spice.gfposc("sun", "iau_earth", "none", "earth", "latitudinal", "latitude", "absmax", 0.0, 0.0, 90.0 * spice.spd(), 1000, cnfine, result) count = spice.wncard(result) @@ -3440,7 +3448,7 @@ def test_gfrepf(): def test_gfrepi(): - window = spice.stypes.SPICEDOUBLE_CELL(4) + window = spice.cell_double(4) spice.wninsd(0., 100., window) spice.gfrepi(window, 'x', 'y') # BEGMSS or ENDMSS empty, too long, or containing non-printing characters @@ -3460,7 +3468,7 @@ def test_gfrepi(): def test_gfrepu(): - window = spice.stypes.SPICEDOUBLE_CELL(4) + window = spice.cell_double(4) spice.wninsd(0., 100., window) spice.gfrepi(window, 'x', 'y') spice.gfrepu(0., 100., 50.) @@ -3494,13 +3502,13 @@ def test_gfrfov(): et_end1 = spice.str2et("2013-FEB-25 11:45:00.000") #\ et_start2 = spice.str2et("2013-FEB-25 11:55:00.000") #_>synthetic 10min gap et_end2 = spice.str2et("2013-FEB-26 14:25:00.000") - cnfine = spice.stypes.SPICEDOUBLE_CELL(4) + cnfine = spice.cell_double(4) spice.wninsd(et_start1, et_end1, cnfine) spice.wninsd(et_start2, et_end2, cnfine) # The ray direction vector is from Cassini toward Enceladus during the gap et_nom = spice.str2et("2013-FEB-25 11:50:00.000") #\ raydir, lt = spice.spkpos("Enceladus", et_nom, "J2000", "NONE", "Cassini") - result = spice.stypes.SPICEDOUBLE_CELL(2000) + result = spice.cell_double(2000) spice.gfrfov(inst, raydir, "J2000", "NONE", "Cassini", 10.0, cnfine, result) # Verify the expected results assert len(result) == 4 @@ -3536,10 +3544,10 @@ def test_gfrr(): spice.furnsh(CoreKernels.testMetaKernel) et0 = spice.str2et('2007 JAN 01') et1 = spice.str2et('2007 APR 01') - cnfine = spice.stypes.SPICEDOUBLE_CELL(2) + cnfine = spice.cell_double(2) spice.wninsd(et0, et1, cnfine) for relation in relate: - result = spice.stypes.SPICEDOUBLE_CELL(2000) + result = spice.cell_double(2000) spice.gfrr("moon", "none", "sun", relation, 0.3365, 0.0, spice.spd(), 2000, cnfine, result) count = spice.wncard(result) if count > 0: @@ -3566,9 +3574,9 @@ def test_gfsep(): '2007-DEC-24 01:40:12.245932 (TDB)'] et0 = spice.str2et('2007 JAN 01') et1 = spice.str2et('2008 JAN 01') - cnfine = spice.stypes.SPICEDOUBLE_CELL(2) + cnfine = spice.cell_double(2) spice.wninsd(et0, et1, cnfine) - result = spice.stypes.SPICEDOUBLE_CELL(2000) + result = spice.cell_double(2000) spice.gfsep("MOON", "SPHERE", "NULL", "SUN", "SPHERE", "NULL", "NONE", "EARTH", "LOCMAX", 0.0, 0.0, 6.0 * spice.spd(), 1000, cnfine, result) count = spice.wncard(result) @@ -3613,9 +3621,9 @@ def test_gfsntc(): spice.furnsh(kernel) et0 = spice.str2et('2007 JAN 01') et1 = spice.str2et('2008 JAN 01') - cnfine = spice.stypes.SPICEDOUBLE_CELL(2) + cnfine = spice.cell_double(2) spice.wninsd(et0, et1, cnfine) - result = spice.stypes.SPICEDOUBLE_CELL(2000) + result = spice.cell_double(2000) spice.gfsntc("EARTH", "IAU_EARTH", "Ellipsoid", "NONE", "SUN", "SEM", [1.0, 0.0, 0.0], "LATITUDINAL", "LATITUDE", "=", 0.0, 0.0, 90.0 * spice.spd(), 1000, cnfine, result) count = spice.wncard(result) @@ -3655,9 +3663,9 @@ def test_gfsubc(): spice.furnsh(CoreKernels.testMetaKernel) et0 = spice.str2et('2007 JAN 01') et1 = spice.str2et('2008 JAN 01') - cnfine = spice.stypes.SPICEDOUBLE_CELL(2) + cnfine = spice.cell_double(2) spice.wninsd(et0, et1, cnfine) - result = spice.stypes.SPICEDOUBLE_CELL(2000) + result = spice.cell_double(2000) spice.gfsubc("earth", "iau_earth", "Near point: ellipsoid", "none", "sun", "geodetic", "latitude", ">", 16.0 * spice.rpd(), 0.0, spice.spd() * 90.0, 1000, cnfine, result) count = spice.wncard(result) @@ -3688,7 +3696,7 @@ def test_gftfov(): et_end1 = spice.str2et("2013-FEB-25 11:45:00.000") #\ et_start2 = spice.str2et("2013-FEB-25 11:55:00.000") #_>synthetic 10min gap et_end2 = spice.str2et("2013-FEB-26 14:25:00.000") - cnfine = spice.stypes.SPICEDOUBLE_CELL(4) + cnfine = spice.cell_double(4) spice.wninsd(et_start1, et_end1, cnfine) spice.wninsd(et_start2, et_end2, cnfine) # Subtract off the position of the spacecraft relative to the solar system barycenter the result is the ray's direction vector. @@ -3711,8 +3719,8 @@ def test_gfudb(): # begin test et_start = spice.str2et("Jan 1 2001") et_end = spice.str2et("Jan 1 2002") - result = spice.stypes.SPICEDOUBLE_CELL(40000) - cnfine = spice.stypes.SPICEDOUBLE_CELL(2) + result = spice.cell_double(40000) + cnfine = spice.cell_double(2) spice.wninsd(et_start, et_end, cnfine) step = 5.0 * spice.spd() @@ -3740,8 +3748,8 @@ def test_gfudb2(): # begin test et_start = spice.str2et("Jan 1 2001") et_end = spice.str2et("Jan 1 2002") - result = spice.stypes.SPICEDOUBLE_CELL(40000) - cnfine = spice.stypes.SPICEDOUBLE_CELL(2) + result = spice.cell_double(40000) + cnfine = spice.cell_double(2) spice.wninsd(et_start, et_end, cnfine) step = 60.0 * 60.0 @@ -3788,8 +3796,8 @@ def gfdecrx(udfuns, et): # loop through to test each relation type for i, r in enumerate(relations): - result = spice.stypes.SPICEDOUBLE_CELL(40000) - cnfine = spice.stypes.SPICEDOUBLE_CELL(2) + result = spice.cell_double(40000) + cnfine = spice.cell_double(2) spice.wninsd(et_start, et_end, cnfine) # call gfuds result = spice.gfuds(gfq, gfdecrx, r, refval, adjust, step, 20000, cnfine, result) @@ -4012,7 +4020,7 @@ def test_inrypl(): def test_insrtc(): - testCell = spice.stypes.SPICECHAR_CELL(10, 10) + testCell = spice.cell_char(10, 10) cList = ["aaa", "bbb", "ccc", "bbb"] for c in cList: spice.insrtc(c, testCell) @@ -4020,14 +4028,14 @@ def test_insrtc(): def test_insrtc_vectorized(): - testCell = spice.stypes.SPICECHAR_CELL(10, 10) + testCell = spice.cell_char(10, 10) cList = ["aaa", "bbb", "ccc", "bbb"] spice.insrtc(cList, testCell) assert [x for x in testCell] == ["aaa", "bbb", "ccc"] def test_insrtd(): - testCell = spice.stypes.SPICEDOUBLE_CELL(8) + testCell = spice.cell_double(8) dlist = [0.5, 2.0, 30.0, 0.01, 30.0] for d in dlist: spice.insrtd(d, testCell) @@ -4035,14 +4043,14 @@ def test_insrtd(): def test_insrtd_vectorized(): - testCell = spice.stypes.SPICEDOUBLE_CELL(8) + testCell = spice.cell_double(8) dList = [0.5, 2.0, 30.0, 0.01, 30.0] spice.insrtd(dList, testCell) assert [x for x in testCell] == [0.01, 0.5, 2.0, 30.0] def test_insrti(): - testCell = spice.stypes.SPICEINT_CELL(8) + testCell = spice.cell_int(8) ilist = [1, 2, 30, 1, 30] for i in ilist: spice.insrti(i, testCell) @@ -4050,15 +4058,15 @@ def test_insrti(): def test_insrti_vectorized(): - testCell = spice.stypes.SPICEINT_CELL(8) + testCell = spice.cell_int(8) iList = [1, 2, 30, 1, 30] spice.insrti(iList, testCell) assert [x for x in testCell] == [1, 2, 30] def test_inter(): - testCellOne = spice.stypes.SPICEINT_CELL(8) - testCellTwo = spice.stypes.SPICEINT_CELL(8) + testCellOne = spice.cell_int(8) + testCellTwo = spice.cell_int(8) spice.insrti(1, testCellOne) spice.insrti(2, testCellOne) spice.insrti(1, testCellTwo) @@ -4066,8 +4074,8 @@ def test_inter(): outCell = spice.inter(testCellOne, testCellTwo) assert [x for x in outCell] == [1] # SPICECHAR_CELL - testCellOne = spice.stypes.SPICECHAR_CELL(8, 8) - testCellTwo = spice.stypes.SPICECHAR_CELL(8, 8) + testCellOne = spice.cell_char(8, 8) + testCellTwo = spice.cell_char(8, 8) spice.insrtc('1', testCellOne) spice.insrtc('2', testCellOne) spice.insrtc('1', testCellTwo) @@ -4075,8 +4083,8 @@ def test_inter(): outCell = spice.inter(testCellOne, testCellTwo) assert [x for x in outCell] == ['1'] # SPICEDOUBLE_CELL - testCellOne = spice.stypes.SPICEDOUBLE_CELL(8) - testCellTwo = spice.stypes.SPICEDOUBLE_CELL(8) + testCellOne = spice.cell_double(8) + testCellTwo = spice.cell_double(8) spice.insrtd(1.0, testCellOne) spice.insrtd(2.0, testCellOne) spice.insrtd(1.0, testCellTwo) @@ -4084,8 +4092,8 @@ def test_inter(): outCell = spice.inter(testCellOne, testCellTwo) assert [x for x in outCell] == [1.0] # SPICEBOOLEAN_CELL; dtype=4 - testCellOne = spice.stypes.SpiceCell(dtype=spice.stypes.SpiceCell.DATATYPES_ENUM['bool'], size=9, length=0, card=0, isSet=False) - testCellTwo = spice.stypes.SpiceCell(dtype=spice.stypes.SpiceCell.DATATYPES_ENUM['bool'], size=9, length=0, card=0, isSet=False) + testCellOne = spice.cell_bool(9) + testCellTwo = spice.cell_bool(9) with pytest.raises(NotImplementedError): spice.inter(testCellOne, testCellTwo) @@ -4815,7 +4823,7 @@ def test_occult(): def test_ordc(): - charset = spice.stypes.SPICECHAR_CELL(10, 10) + charset = spice.cell_char(10, 10) inputs = ["8", "1", "2", "9", "7", "4", "10"] expected = [5, 0, 2, 6, 4, 3, 1] for c in inputs: @@ -4825,7 +4833,7 @@ def test_ordc(): def test_ordd(): - doubleset = spice.stypes.SPICEDOUBLE_CELL(7) + doubleset = spice.cell_double(7) inputs = [8.0, 1.0, 2.0, 9.0, 7.0, 4.0, 10.0] expected = [4, 0, 1, 5, 3, 2, 6] for d in inputs: @@ -4835,7 +4843,7 @@ def test_ordd(): def test_ordi(): - intset = spice.stypes.SPICEINT_CELL(7) + intset = spice.cell_int(7) inputs = [8, 1, 2, 9, 7, 4, 10] expected = [4, 0, 1, 5, 3, 2, 6] for i in inputs: @@ -4926,8 +4934,8 @@ def test_pckopn_pckw02_pckcls(): def test_pckcov(): spice.kclear() - ids = spice.stypes.SPICEINT_CELL(1000) - cover = spice.stypes.SPICEDOUBLE_CELL(2000) + ids = spice.cell_int(1000) + cover = spice.cell_double(2000) spice.pckfrm(ExtraKernels.earthHighPerPck, ids) spice.scard(0, cover) spice.pckcov(ExtraKernels.earthHighPerPck, ids[0], cover) @@ -4939,7 +4947,7 @@ def test_pckcov(): def test_pckfrm(): spice.kclear() - ids = spice.stypes.SPICEINT_CELL(1000) + ids = spice.cell_int(1000) spice.pckfrm(ExtraKernels.earthHighPerPck, ids) assert ids[0] == 3000 spice.kclear() @@ -5008,9 +5016,9 @@ def test_phaseq(): spice.furnsh(CoreKernels.testMetaKernel) et0 = spice.str2et('2006 DEC 01') et1 = spice.str2et('2007 JAN 31') - cnfine = spice.stypes.SPICEDOUBLE_CELL(2) + cnfine = spice.cell_double(2) spice.wninsd(et0, et1, cnfine) - result = spice.stypes.SPICEDOUBLE_CELL(10000) + result = spice.cell_double(10000) for relation in relate: spice.gfpa("Moon", "Sun", "LT+S", "Earth", relation, 0.57598845, 0.0, spice.spd(), 5000, cnfine, result) @@ -5448,7 +5456,7 @@ def test_recsph(): def test_removc(): - cell = spice.stypes.SPICECHAR_CELL(10, 10) + cell = spice.cell_char(10, 10) items = ["one", "two", "three", "four"] for i in items: spice.insrtc(i, cell) @@ -5460,7 +5468,7 @@ def test_removc(): def test_removd(): - cell = spice.stypes.SPICEDOUBLE_CELL(10) + cell = spice.cell_double(10) items = [0.0, 1.0, 1.0, 2.0, 3.0, 5.0, 8.0, 13.0, 21.0] for i in items: spice.insrtd(i, cell) @@ -5473,7 +5481,7 @@ def test_removd(): def test_removi(): - cell = spice.stypes.SPICEINT_CELL(10) + cell = spice.cell_int(10) items = [0, 1, 1, 2, 3, 5, 8, 13, 21] for i in items: spice.insrti(i, cell) @@ -5617,7 +5625,7 @@ def test_saelgv(): def test_scard(): - cell = spice.stypes.SPICEDOUBLE_CELL(10) + cell = spice.cell_double(10) darray = [[1.0, 3.0], [7.0, 11.0], [23.0, 27.0]] assert spice.card(cell) == 0 for w in darray: @@ -5732,8 +5740,8 @@ def test_sctiks(): def test_sdiff(): # SPICEINT_CELL - a = spice.stypes.SPICEINT_CELL(8) - b = spice.stypes.SPICEINT_CELL(8) + a = spice.cell_int(8) + b = spice.cell_int(8) spice.insrti(1, a) spice.insrti(2, a) spice.insrti(5, a) @@ -5743,8 +5751,8 @@ def test_sdiff(): c = spice.sdiff(a, b) assert [x for x in c] == [1, 2, 3, 4] # SPICECHAR_CELL - a = spice.stypes.SPICECHAR_CELL(8, 8) - b = spice.stypes.SPICECHAR_CELL(8, 8) + a = spice.cell_char(8, 8) + b = spice.cell_char(8, 8) spice.insrtc('1', a) spice.insrtc('2', a) spice.insrtc('5', a) @@ -5754,8 +5762,8 @@ def test_sdiff(): c = spice.sdiff(a, b) assert [x for x in c] == ['1', '2', '3', '4'] # SPICEDOUBLE_CELL - a = spice.stypes.SPICEDOUBLE_CELL(8) - b = spice.stypes.SPICEDOUBLE_CELL(8) + a = spice.cell_double(8) + b = spice.cell_double(8) spice.insrtd(1., a) spice.insrtd(2., a) spice.insrtd(5., a) @@ -5765,16 +5773,16 @@ def test_sdiff(): c = spice.sdiff(a, b) assert [x for x in c] == [1., 2., 3., 4.] # SPICEBOOLEAN_CELL - testCellOne = spice.stypes.SpiceCell(dtype=spice.stypes.SpiceCell.DATATYPES_ENUM['bool'], size=9, length=0, card=0, isSet=False) - testCellTwo = spice.stypes.SpiceCell(dtype=spice.stypes.SpiceCell.DATATYPES_ENUM['bool'], size=9, length=0, card=0, isSet=False) + testCellOne = spice.cell_bool(9) + testCellTwo = spice.cell_bool(9) with pytest.raises(NotImplementedError): spice.sdiff(testCellOne, testCellTwo) def test_set_c(): - a = spice.stypes.SPICEINT_CELL(8) - b = spice.stypes.SPICEINT_CELL(8) - c = spice.stypes.SPICEINT_CELL(8) + a = spice.cell_int(8) + b = spice.cell_int(8) + c = spice.cell_int(8) spice.insrti(1, a) spice.insrti(2, a) spice.insrti(3, a) @@ -5855,7 +5863,7 @@ def test_sincpt(): def test_size(): - testCellOne = spice.stypes.SPICEINT_CELL(8) + testCellOne = spice.cell_int(8) assert spice.size(testCellOne) == 8 @@ -6127,7 +6135,7 @@ def test_spkcov(): npt.assert_array_almost_equal(result, expected) #Checks for old way, where if cover is pre-set, it should remain set - cover = spice.stypes.SPICEDOUBLE_CELL(2000) + cover = spice.cell_double(2000) spice.scard(0, cover) spice.spkcov(CoreKernels.spk, tempObj, cover) result = [x for x in cover] @@ -6320,7 +6328,7 @@ def test_spkltc(): def test_spkobj(): # Same as test_spkcov spice.kclear() - cover = spice.stypes.SPICEDOUBLE_CELL(2000) + cover = spice.cell_double(2000) ids = spice.spkobj(CoreKernels.spk) tempObj = ids[0] spice.scard(0, cover) @@ -7084,7 +7092,7 @@ def test_srfxpt(): def test_ssize(): - cell = spice.stypes.SPICEDOUBLE_CELL(10) + cell = spice.cell_double(10) assert cell.size == 10 spice.ssize(5, cell) assert cell.size == 5 @@ -7613,8 +7621,8 @@ def test_udf(): def test_union(): # SPICEINT_CELL - testCellOne = spice.stypes.SPICEINT_CELL(8) - testCellTwo = spice.stypes.SPICEINT_CELL(8) + testCellOne = spice.cell_int(8) + testCellTwo = spice.cell_int(8) spice.insrti(1, testCellOne) spice.insrti(2, testCellOne) spice.insrti(3, testCellOne) @@ -7624,8 +7632,8 @@ def test_union(): outCell = spice.union(testCellOne, testCellTwo) assert [x for x in outCell] == [1, 2, 3, 4] # SPICECHAR_CELL - testCellOne = spice.stypes.SPICECHAR_CELL(8, 8) - testCellTwo = spice.stypes.SPICECHAR_CELL(8, 8) + testCellOne = spice.cell_char(8, 8) + testCellTwo = spice.cell_char(8, 8) spice.insrtc('1', testCellOne) spice.insrtc('2', testCellOne) spice.insrtc('3', testCellOne) @@ -7635,8 +7643,8 @@ def test_union(): outCell = spice.union(testCellOne, testCellTwo) assert [x for x in outCell] == ['1', '2', '3', '4'] # SPICEDOUBLE_CELL - testCellOne = spice.stypes.SPICEDOUBLE_CELL(8) - testCellTwo = spice.stypes.SPICEDOUBLE_CELL(8) + testCellOne = spice.cell_double(8) + testCellTwo = spice.cell_double(8) spice.insrtd(1., testCellOne) spice.insrtd(2., testCellOne) spice.insrtd(3., testCellOne) @@ -7646,8 +7654,8 @@ def test_union(): outCell = spice.union(testCellOne, testCellTwo) assert [x for x in outCell] == [1., 2., 3., 4.] # SPICEBOOLEAN_CELL - testCellOne = spice.stypes.SpiceCell(dtype=spice.stypes.SpiceCell.DATATYPES_ENUM['bool'], size=9, length=0, card=0, isSet=False) - testCellTwo = spice.stypes.SpiceCell(dtype=spice.stypes.SpiceCell.DATATYPES_ENUM['bool'], size=9, length=0, card=0, isSet=False) + testCellOne = spice.cell_bool(9) + testCellTwo = spice.cell_bool(9) with pytest.raises(NotImplementedError): spice.union(testCellOne, testCellTwo) @@ -7734,7 +7742,7 @@ def test_vaddg(): def test_valid(): data = np.arange(0, 10)[::-1] - a = spice.stypes.SPICEDOUBLE_CELL(20) + a = spice.cell_double(20) for x in data: spice.appndd(x, a) assert a.is_set() is False @@ -7975,7 +7983,7 @@ def test_vzerog(): def test_wncard(): - window = spice.stypes.SPICEDOUBLE_CELL(8) + window = spice.cell_double(8) darray = [[1.0, 3.0], [7.0, 11.0], [23.0, 27.0]] for d in darray: spice.wninsd(d[0], d[1], window) @@ -7983,7 +7991,7 @@ def test_wncard(): def test_wncomd(): - window1 = spice.stypes.SPICEDOUBLE_CELL(8) + window1 = spice.cell_double(8) darray = [[1.0, 3.0], [7.0, 11.0], [23.0, 27.0]] for d in darray: spice.wninsd(d[0], d[1], window1) @@ -7995,7 +8003,7 @@ def test_wncomd(): def test_wncond(): - window = spice.stypes.SPICEDOUBLE_CELL(8) + window = spice.cell_double(8) darray = [[1.0, 3.0], [7.0, 11.0], [23.0, 27.0]] for d in darray: spice.wninsd(d[0], d[1], window) @@ -8007,8 +8015,8 @@ def test_wncond(): def test_wndifd(): - window1 = spice.stypes.SPICEDOUBLE_CELL(8) - window2 = spice.stypes.SPICEDOUBLE_CELL(8) + window1 = spice.cell_double(8) + window2 = spice.cell_double(8) darray1 = [[1.0, 3.0], [7.0, 11.0], [23.0, 27.0]] darray2 = [[2.0, 6.0], [8.0, 10.0], [16.0, 18.0]] for d in darray1: @@ -8026,7 +8034,7 @@ def test_wndifd(): def test_wnelmd(): - window = spice.stypes.SPICEDOUBLE_CELL(8) + window = spice.cell_double(8) darray = [[1.0, 3.0], [7.0, 11.0], [23.0, 27.0]] for d in darray: spice.wninsd(d[0], d[1], window) @@ -8038,7 +8046,7 @@ def test_wnelmd(): def test_wnexpd(): - window = spice.stypes.SPICEDOUBLE_CELL(8) + window = spice.cell_double(8) darray = [[1.0, 3.0], [7.0, 11.0], [23.0, 27.0], [29.0, 29.0]] for d in darray: spice.wninsd(d[0], d[1], window) @@ -8051,7 +8059,7 @@ def test_wnexpd(): def test_wnextd(): - window = spice.stypes.SPICEDOUBLE_CELL(8) + window = spice.cell_double(8) darray = [[1.0, 3.0], [7.0, 11.0], [23.0, 27.0], [29.0, 29.0]] for d in darray: spice.wninsd(d[0], d[1], window) @@ -8065,7 +8073,7 @@ def test_wnextd(): def test_wnfetd(): - window = spice.stypes.SPICEDOUBLE_CELL(8) + window = spice.cell_double(8) darray = [[1.0, 3.0], [7.0, 11.0], [23.0, 27.0]] for d in darray: spice.wninsd(d[0], d[1], window) @@ -8076,7 +8084,7 @@ def test_wnfetd(): def test_wnfild(): - window = spice.stypes.SPICEDOUBLE_CELL(8) + window = spice.cell_double(8) darray = [[1.0, 3.0], [7.0, 11.0], [23.0, 27.0], [29.0, 29.0]] for d in darray: spice.wninsd(d[0], d[1], window) @@ -8089,7 +8097,7 @@ def test_wnfild(): def test_wnfltd(): - window = spice.stypes.SPICEDOUBLE_CELL(8) + window = spice.cell_double(8) darray = [[1.0, 3.0], [7.0, 11.0], [23.0, 27.0], [29.0, 29.0]] for d in darray: spice.wninsd(d[0], d[1], window) @@ -8101,7 +8109,7 @@ def test_wnfltd(): def test_wnincd(): - window = spice.stypes.SPICEDOUBLE_CELL(8) + window = spice.cell_double(8) darray = [[1.0, 3.0], [7.0, 11.0], [23.0, 27.0]] for d in darray: spice.wninsd(d[0], d[1], window) @@ -8113,7 +8121,7 @@ def test_wnincd(): def test_wninsd(): - window = spice.stypes.SPICEDOUBLE_CELL(8) + window = spice.cell_double(8) darray = [[1.0, 3.0], [7.0, 11.0], [23.0, 27.0]] for d in darray: spice.wninsd(d[0], d[1], window) @@ -8122,8 +8130,8 @@ def test_wninsd(): def test_wnintd(): - window1 = spice.stypes.SPICEDOUBLE_CELL(8) - window2 = spice.stypes.SPICEDOUBLE_CELL(8) + window1 = spice.cell_double(8) + window2 = spice.cell_double(8) darray1 = [[1.0, 3.0], [7.0, 11.0], [23.0, 27.0]] darray2 = [[2.0, 6.0], [8.0, 10.0], [16.0, 18.0]] for d in darray1: @@ -8139,8 +8147,8 @@ def test_wnintd(): def test_wnreld(): - window1 = spice.stypes.SPICEDOUBLE_CELL(8) - window2 = spice.stypes.SPICEDOUBLE_CELL(8) + window1 = spice.cell_double(8) + window2 = spice.cell_double(8) darray1 = [[1.0, 3.0], [7.0, 11.0], [23.0, 27.0]] darray2 = [[1.0, 2.0], [9.0, 9.0], [24.0, 27.0]] for d in darray1: @@ -8156,7 +8164,7 @@ def test_wnreld(): def test_wnsumd(): - window = spice.stypes.SPICEDOUBLE_CELL(12) + window = spice.cell_double(12) darray = [[1.0, 3.0], [7.0, 11.0], [18.0, 18.0], [23.0, 27.0], [30.0, 69.0], [72.0, 80.0]] for d in darray: spice.wninsd(d[0], d[1], window) @@ -8169,8 +8177,8 @@ def test_wnsumd(): def test_wnunid(): - window1 = spice.stypes.SPICEDOUBLE_CELL(8) - window2 = spice.stypes.SPICEDOUBLE_CELL(8) + window1 = spice.cell_double(8) + window2 = spice.cell_double(8) darray1 = [[1.0, 3.0], [7.0, 11.0], [23.0, 27.0]] darray2 = [[2.0, 6.0], [8.0, 10.0], [16.0, 18.0]] for d in darray1: @@ -8188,7 +8196,7 @@ def test_wnunid(): def test_wnvald(): - window = spice.stypes.SPICEDOUBLE_CELL(30) + window = spice.cell_double(30) array = [[0.0, 0.0], [10.0, 12.0], [2.0, 7.0], [13.0, 15.0], [1.0, 5.0], [23.0, 29.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]] diff --git a/spiceypy/utils/support_types.py b/spiceypy/utils/support_types.py index de056fb0..e927d878 100644 --- a/spiceypy/utils/support_types.py +++ b/spiceypy/utils/support_types.py @@ -703,20 +703,55 @@ def _int_getter(data_p, index, length): def SPICEDOUBLE_CELL(size): + """ + Returns a Double Spice Cell with a given size + :param size: number of elements + :type size: int + :return: empty Spice Cell + :rtype: spiceypy.utils.support_types.SpiceCell + """ return SpiceCell.double(size) - def SPICEINT_CELL(size): + """ + Returns a Int Spice Cell with a given size + :param size: number of elements + :type size: int + :return: empty Spice Cell + :rtype: spiceypy.utils.support_types.SpiceCell + """ return SpiceCell.integer(size) - def SPICECHAR_CELL(size, length): + """ + Returns a Char Spice Cell with a given size + :param size: number of elements + :type size: int + :param length: width of elements + :type length: int + :return: empty Spice Cell + :rtype: spiceypy.utils.support_types.SpiceCell + """ return SpiceCell.character(size, length) def SPICEBOOL_CELL(size): + """ + Returns a Bool Spice Cell with a given size + :param size: number of elements + :type size: int + :return: empty Spice Cell + :rtype: spiceypy.utils.support_types.SpiceCell + """ return SpiceCell.bool(size) def SPICETIME_CELL(size): + """ + Returns a Time Spice Cell with a given size + :param size: number of elements + :type size: int + :return: empty Spice Cell + :rtype: spiceypy.utils.support_types.SpiceCell + """ return SpiceCell.time(size) @@ -778,51 +813,36 @@ def is_set(self): @classmethod def character(cls, size, length): base = (c_char * ((cls.CTRLBLOCK + size) * length))() - data = (c_char * (size * length)).from_buffer( - base, cls.CTRLBLOCK * BITSIZE['char'] * length) - instance = cls(cls.DATATYPES_ENUM['char'], length, size, 0, 1, - cast(base, c_void_p), - cast(data, c_void_p)) + data = (c_char * (size * length)).from_buffer(base, cls.CTRLBLOCK * BITSIZE['char'] * length) + instance = cls(cls.DATATYPES_ENUM['char'], length, size, 0, 1, cast(base, c_void_p), cast(data, c_void_p)) return instance @classmethod def integer(cls, size): base = (c_int * (cls.CTRLBLOCK + size))() - data = (c_int * size).from_buffer( - base, cls.CTRLBLOCK * BITSIZE['int']) - instance = cls(cls.DATATYPES_ENUM['int'], 0, size, 0, 1, - cast(base, c_void_p), - cast(data, c_void_p)) + data = (c_int * size).from_buffer(base, cls.CTRLBLOCK * BITSIZE['int']) + instance = cls(cls.DATATYPES_ENUM['int'], 0, size, 0, 1, cast(base, c_void_p), cast(data, c_void_p)) return instance @classmethod def double(cls, size): base = (c_double * (cls.CTRLBLOCK + size))() - data = (c_double * size).from_buffer( - base, cls.CTRLBLOCK * BITSIZE['double']) - instance = cls(cls.DATATYPES_ENUM['double'], 0, size, 0, 1, - cast(base, c_void_p), - cast(data, c_void_p)) + data = (c_double * size).from_buffer(base, cls.CTRLBLOCK * BITSIZE['double']) + instance = cls(cls.DATATYPES_ENUM['double'], 0, size, 0, 1, cast(base, c_void_p), cast(data, c_void_p)) return instance @classmethod def bool(cls, size): base = (c_int * (cls.CTRLBLOCK + size))() - data = (c_int * size).from_buffer( - base, cls.CTRLBLOCK * BITSIZE['bool']) - instance = cls(cls.DATATYPES_ENUM['bool'], 0, size, 0, 1, - cast(base, c_void_p), - cast(data, c_void_p)) + data = (c_int * size).from_buffer(base, cls.CTRLBLOCK * BITSIZE['bool']) + instance = cls(cls.DATATYPES_ENUM['bool'], 0, size, 0, 1, cast(base, c_void_p), cast(data, c_void_p)) return instance @classmethod def time(cls, size): base = (c_int * (cls.CTRLBLOCK + size))() - data = (c_int * size).from_buffer( - base, cls.CTRLBLOCK * BITSIZE['time']) - instance = cls(cls.DATATYPES_ENUM['time'], 0, size, 0, 1, - cast(base, c_void_p), - cast(data, c_void_p)) + data = (c_int * size).from_buffer(base, cls.CTRLBLOCK * BITSIZE['time']) + instance = cls(cls.DATATYPES_ENUM['time'], 0, size, 0, 1, cast(base, c_void_p), cast(data, c_void_p)) return instance def __len__(self): @@ -857,3 +877,89 @@ def __getitem__(self, key): def reset(self): self.card = 0 self.init = 0 + + def __eq__(self, other): + """ + element wise equality, other can be a list or cell + I think sets should not equal a non set even if + elements are equal... might be a bad idea + :param other: + :return: + """ + if len(self) != len(other): + return False + if not hasattr(other, '__iter__'): + return False + if isinstance(other, SpiceCell): + if other.dtype != self.dtype: + return False + if other.isSet != self.isSet: + return False + for x, y in zip(self, other): + if x != y: + return False + return True + +# Spice Cell classes + +class Cell_Time(SpiceCell): + + def __init__(self, size): + """ + Init a Time Spice Cell with a given size and length + :param size: number of elements + :type size: int + """ + base = (c_int * (6 + size))() + data = (c_int * size).from_buffer(base, 6 * BITSIZE['time']) + super(Cell_Time, self).__init__(3, 0, size, 0, 1, cast(base, c_void_p), cast(data, c_void_p)) + +class Cell_Bool(SpiceCell): + + def __init__(self, size): + """ + Init a Bool Spice Cell with a given size and length + :param size: number of elements + :type size: int + """ + base = (c_int * (6 + size))() + data = (c_int * size).from_buffer(base, 6 * BITSIZE['bool']) + super(Cell_Bool, self).__init__(4, 0, size, 0, 1, cast(base, c_void_p), cast(data, c_void_p)) + +class Cell_Int(SpiceCell): + + def __init__(self, size): + """ + Init a Int Spice Cell with a given size and length + :param size: number of elements + :type size: int + """ + base = (c_int * (6 + size))() + data = (c_int * size).from_buffer(base, 6 * BITSIZE['int']) + super(Cell_Int, self).__init__(2, 0, size, 0, 1, cast(base, c_void_p), cast(data, c_void_p)) + +class Cell_Double(SpiceCell): + + def __init__(self, size): + """ + Init a Double Spice Cell with a given size and length + :param size: number of elements + :type size: int + """ + base = (c_double * (6 + size))() + data = (c_double * size).from_buffer(base, 6 * BITSIZE['double']) + super(Cell_Double, self).__init__(1, 0, size, 0, 1, cast(base, c_void_p), cast(data, c_void_p)) + +class Cell_Char(SpiceCell): + + def __init__(self, size, length): + """ + Init a Char Spice Cell with a given size and length + :param size: number of elements + :type size: int + :param length: width of elements + :type length: int + """ + base = (c_char * ((6 + size) * length))() + data = (c_char * (size * length)).from_buffer(base, 6 * BITSIZE['char'] * length) + super(Cell_Char, self).__init__(0, length, size, 0, 1, cast(base, c_void_p), cast(data, c_void_p))