Skip to content
Snippets Groups Projects
Commit 88ebea70 authored by Jesse Mapel's avatar Jesse Mapel Committed by Summer Stapleton
Browse files

Added first steps at cube reading notebook (#58)

parent f04a565a
No related branches found
No related tags found
No related merge requests found
......@@ -72,3 +72,6 @@ build
*/build
install
*/install
# Jupyter ignores
.ipynb_checkpoints
%% Cell type:code id: tags:
``` python
import pvl, struct, quaternion
import numpy as np
```
%% Cell type:code id: tags:
``` python
def read_position_table(label, file):
with open(file, 'rb') as f:
f.seek(int(label['StartByte']))
data = f.read(int(label['Bytes']))
field_count = len(label.getlist('Field'))
record_count = int(label['Records'])
format = 'd' * field_count
positions = []
velocities = []
times = []
for index in range(record_count):
doubles = struct.unpack_from(format, data, index * field_count * 8)
positions.append(doubles[:3])
if field_count > 3:
times.append(doubles[-1])
if field_count == 7:
velocities.append(doubles[3:6])
return positions, velocities, times
```
%% Cell type:code id: tags:
``` python
def read_rotation_table(label, file):
with open(file, 'rb') as f:
f.seek(int(label['StartByte']))
data = f.read(int(label['Bytes']))
field_count = len(label.getlist('Field'))
record_count = int(label['Records'])
format = 'd' * field_count
rotations = []
velocities = []
times = []
for index in range(record_count):
doubles = struct.unpack_from(format, data, index * field_count * 8)
# Euler angle functions
if field_count == 3:
rotations.append(doubles[:3])
else:
rotations.append(np.quaternion(doubles[0], doubles[1], doubles[2], doubles[3]))
times.append(doubles[-1])
if field_count == 8:
velocities.append(doubles[4:7])
const_rotation_mat = np.array(label['ConstantRotation'])
const_rotation = quaternion.from_rotation_matrix(np.reshape(const_rotation_mat, (3, 3)))
return rotations, velocities, times, const_rotation
```
%% Cell type:code id: tags:
``` python
cube_file = '/Users/jmapel/eal/cubes/CAS-MCO-2016-11-22T16.38.39.354-NIR-02036-00.cub'
```
%% Cell type:code id: tags:
``` python
label = pvl.load(cube_file)
tables = label.getlist('Table')
print(tables)
```
%% Output
[PVLObject([
('Name', 'InstrumentPointing')
('StartByte', 336115)
('Bytes', 64)
('Records', 1)
('ByteOrder', 'Lsb')
('TimeDependentFrames', [-143410, -143400, -143000, 1])
('ConstantFrames', [-143420, -143410])
('ConstantRotation',
[6.12323399573677e-17,
0.0,
1.0,
0.98513931843935,
0.17175716364932,
-6.03223856520476e-17,
-0.17175716364932,
0.98513931843935,
1.05170930346882e-17])
('CkTableStartTime', 533104787.53776)
('CkTableEndTime', 533104787.53776)
('CkTableOriginalSize', 1)
('FrameTypeCode', 3)
('Description', 'Created by spiceinit')
('Kernels',
['$tgo/kernels/ck/em16_tgo_sc_fpp_d161102_pointing_20161028_20171129_s20160719_v01.bc',
'$tgo/kernels/ck/em16_tgo_cassis_ipp_tel_20160407_20170309_s20170116_v02.bc',
'$tgo/kernels/fk/em16_tgo_v12.tf',
'$tgo/kernels/fk/rssd0002.tf'])
('Field',
PVLGroup([
('Name', 'J2000Q0')
('Type', 'Double')
('Size', 1)
]))
('Field',
PVLGroup([
('Name', 'J2000Q1')
('Type', 'Double')
('Size', 1)
]))
('Field',
PVLGroup([
('Name', 'J2000Q2')
('Type', 'Double')
('Size', 1)
]))
('Field',
PVLGroup([
('Name', 'J2000Q3')
('Type', 'Double')
('Size', 1)
]))
('Field', PVLGroup([
('Name', 'AV1')
('Type', 'Double')
('Size', 1)
]))
('Field', PVLGroup([
('Name', 'AV2')
('Type', 'Double')
('Size', 1)
]))
('Field', PVLGroup([
('Name', 'AV3')
('Type', 'Double')
('Size', 1)
]))
('Field', PVLGroup([
('Name', 'ET')
('Type', 'Double')
('Size', 1)
]))
]), PVLObject([
('Name', 'InstrumentPosition')
('StartByte', 336179)
('Bytes', 56)
('Records', 1)
('ByteOrder', 'Lsb')
('CacheType', 'Linear')
('SpkTableStartTime', 533104787.53776)
('SpkTableEndTime', 533104787.53776)
('SpkTableOriginalSize', 1.0)
('Description', 'Created by spiceinit')
('Kernels', '$tgo/kernels/spk/em16_tgo_fpp_015_01_20160314_20170315_v01.bsp')
('Field', PVLGroup([
('Name', 'J2000X')
('Type', 'Double')
('Size', 1)
]))
('Field', PVLGroup([
('Name', 'J2000Y')
('Type', 'Double')
('Size', 1)
]))
('Field', PVLGroup([
('Name', 'J2000Z')
('Type', 'Double')
('Size', 1)
]))
('Field',
PVLGroup([
('Name', 'J2000XV')
('Type', 'Double')
('Size', 1)
]))
('Field',
PVLGroup([
('Name', 'J2000YV')
('Type', 'Double')
('Size', 1)
]))
('Field',
PVLGroup([
('Name', 'J2000ZV')
('Type', 'Double')
('Size', 1)
]))
('Field', PVLGroup([
('Name', 'ET')
('Type', 'Double')
('Size', 1)
]))
]), PVLObject([
('Name', 'BodyRotation')
('StartByte', 336235)
('Bytes', 64)
('Records', 1)
('ByteOrder', 'Lsb')
('TimeDependentFrames', [10014, 1])
('CkTableStartTime', 533104787.53776)
('CkTableEndTime', 533104787.53776)
('CkTableOriginalSize', 1)
('FrameTypeCode', 2)
('PoleRa', [317.68143, -0.1061, 0.0])
('PoleDec', [52.8865, -0.0609, 0.0])
('PrimeMeridian', [176.63, 350.89198226, 0.0])
('Description', 'Created by spiceinit')
('Kernels',
['$tgo/kernels/tspk/de430.bsp',
'$tgo/kernels/tspk/mar097.bsp',
'$tgo/kernels/pck/pck00010.tpc',
'$tgo/kernels/pck/de-403-masses.tpc'])
('SolarLongitude', 266.45237441729)
('Field',
PVLGroup([
('Name', 'J2000Q0')
('Type', 'Double')
('Size', 1)
]))
('Field',
PVLGroup([
('Name', 'J2000Q1')
('Type', 'Double')
('Size', 1)
]))
('Field',
PVLGroup([
('Name', 'J2000Q2')
('Type', 'Double')
('Size', 1)
]))
('Field',
PVLGroup([
('Name', 'J2000Q3')
('Type', 'Double')
('Size', 1)
]))
('Field', PVLGroup([
('Name', 'AV1')
('Type', 'Double')
('Size', 1)
]))
('Field', PVLGroup([
('Name', 'AV2')
('Type', 'Double')
('Size', 1)
]))
('Field', PVLGroup([
('Name', 'AV3')
('Type', 'Double')
('Size', 1)
]))
('Field', PVLGroup([
('Name', 'ET')
('Type', 'Double')
('Size', 1)
]))
]), PVLObject([
('Name', 'SunPosition')
('StartByte', 336299)
('Bytes', 56)
('Records', 1)
('ByteOrder', 'Lsb')
('CacheType', 'Linear')
('SpkTableStartTime', 533104787.53776)
('SpkTableEndTime', 533104787.53776)
('SpkTableOriginalSize', 1.0)
('Description', 'Created by spiceinit')
('Kernels', ['$tgo/kernels/tspk/de430.bsp', '$tgo/kernels/tspk/mar097.bsp'])
('Field', PVLGroup([
('Name', 'J2000X')
('Type', 'Double')
('Size', 1)
]))
('Field', PVLGroup([
('Name', 'J2000Y')
('Type', 'Double')
('Size', 1)
]))
('Field', PVLGroup([
('Name', 'J2000Z')
('Type', 'Double')
('Size', 1)
]))
('Field',
PVLGroup([
('Name', 'J2000XV')
('Type', 'Double')
('Size', 1)
]))
('Field',
PVLGroup([
('Name', 'J2000YV')
('Type', 'Double')
('Size', 1)
]))
('Field',
PVLGroup([
('Name', 'J2000ZV')
('Type', 'Double')
('Size', 1)
]))
('Field', PVLGroup([
('Name', 'ET')
('Type', 'Double')
('Size', 1)
]))
])]
%% Cell type:code id: tags:
``` python
read_position_table(tables[1], cube_file)
```
%% Output
([(4.743092590963316e-305, 4.739987214924918e-305, 9.462663060940373e+251)],
[(-1.6878690421469897e+271, 5.29682553422139e-228, -5.8500298023031387e-98)],
[-1.1371270199850502e-143])
%% Cell type:code id: tags:
``` python
read_rotation_table(tables[0], cube_file)
```
%% Output
([quaternion(-1.34337767237385e-225, -5.29807286672666e-110, 8.1011017870871e-115, -1.44413722000277e+194)],
[(-8089.420679908819, -3.5340714299727612e+249, -2.2489288021413767e-100)],
[1.9746554944903616e-307],
quaternion(0.54123866354163, 0.4550392390637, 0.54123866354163, 0.4550392390637))
%% Cell type:code id: tags:
``` python
read_rotation_table(tables[3], cube_file)
```
%% Output
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-28-788ee0080f93> in <module>
----> 1 read_rotation_table(tables[3], cube_file)
<ipython-input-26-ce5af3418c58> in read_rotation_table(label, file)
20 velocities.append(doubles[4:7])
21
---> 22 const_rotation_mat = np.array(label['ConstantRotation'])
23 const_rotation = quaternion.from_rotation_matrix(np.reshape(const_rotation_mat, (3, 3)))
24 return rotations, velocities, times, const_rotation
~/miniconda3/envs/pandas/lib/python3.7/site-packages/pvl/_collections.py in __getitem__(self, key)
121 if isinstance(key, INDEX_TYPES):
122 return self.__items[key]
--> 123 return dict_getitem(self, key)[0]
124
125 def __delitem__(self, key):
KeyError: 'ConstantRotation'
%% Cell type:code id: tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment