diff --git a/ale/base/data_naif.py b/ale/base/data_naif.py index faa8e61e4cd9266f90f6d2b472fe60f9d7002315..dd1b5899879fda5883a44b67991413a24fd9aa09 100644 --- a/ale/base/data_naif.py +++ b/ale/base/data_naif.py @@ -68,6 +68,14 @@ class NaifSpice(): def spacecraft_id(self): return spice.bods2c(self.spacecraft_name) + @property + def target_id(self): + return spice.bods2c(self.target_name) + + @property + def body_frame_code(self): + return spice.gipool('BODY_FRAME_CODE', 0, 1) + @property def focal2pixel_lines(self): return list(spice.gdpool('INS{}_ITRANSL'.format(self.ikid), 0, 3)) @@ -80,6 +88,21 @@ class NaifSpice(): def _focal_length(self): return float(spice.gdpool('INS{}_FOCAL_LENGTH'.format(self.ikid), 0, 1)[0]) + @property + def pixel_size(self): + return spice.gdpool('INS{}_PIXEL_SIZE'.format(self.ikid), 0, 1)[0] * 0.001 + + @property + def _radii(self): + """ + Returns + ------- + : list + Radius of all three axis of the target body + """ + rad = spice.bodvrd(self.target_name, 'RADII', 3) + return rad[1] + @property def _semimajor(self): """ @@ -194,3 +217,18 @@ class NaifSpice(): @property def detector_center_line(self): return float(spice.gdpool('INS{}_BORESIGHT_LINE'.format(self.ikid), 0, 1)[0]) + + @property + def _naif_keywords(self): + naif_keywords = dict() + + naif_keywords['BODY{}_RADII'.format(self.target_id)] = self._radii + naif_keywords['BODY_FRAME_CODE'] = self.body_frame_code + naif_keywords['INS{}_PIXEL_SIZE'.format(self.ikid)] = self.pixel_size + naif_keywords['INS{}_ITRANSL'.format(self.ikid)] = self.focal2pixel_lines + naif_keywords['INS{}_ITRANSS'.format(self.ikid)] = self.focal2pixel_samples + naif_keywords['INS{}_FOCAL_LENGTH'.format(self.ikid)] = self._focal_length + naif_keywords['INS{}_BORESIGHT_SAMPLE'.format(self.ikid)] = self.detector_center_sample + naif_keywords['INS{}_BORESIGHT_LINE'.format(self.ikid)] = self.detector_center_line + + return naif_keywords diff --git a/tests/pytests/conftest.py b/tests/pytests/conftest.py index 5a42b283fea8864fcb9798cba936996521d4e233..20f9d811c5780ae52bccc3a2bb3531b5846a2584 100644 --- a/tests/pytests/conftest.py +++ b/tests/pytests/conftest.py @@ -7,6 +7,8 @@ class SimpleSpice(): return -12345 def gdpool(self, key, x, length): return np.ones(length) + def gipool(self, key, x, length): + return np.arange(length) def bodvrd(self, key, x, length): return (3, np.ones(length,)) def spkpos(self, *args): diff --git a/tests/pytests/test_data_naif.py b/tests/pytests/test_data_naif.py new file mode 100644 index 0000000000000000000000000000000000000000..0f9d213d378d19a975ee0d1e2f2f99999d1174cf --- /dev/null +++ b/tests/pytests/test_data_naif.py @@ -0,0 +1,38 @@ +import pytest + +import numpy as np + +from ale.base import data_naif + +# 'Mock' the spice module where it is imported +from conftest import SimpleSpice + +simplespice = SimpleSpice() +data_naif.spice = simplespice + +@pytest.fixture +def test_naif_data(): + naif_data = data_naif.NaifSpice() + naif_data.instrument_id = "INSTRUMENT" + naif_data.target_name = "TARGET" + + return naif_data + +def test_target_id(test_naif_data): + assert test_naif_data.target_id == -12345 + +def test_pixel_size(test_naif_data): + assert test_naif_data.pixel_size == (0.001) + +def test_radii(test_naif_data): + np.testing.assert_equal(test_naif_data._radii, np.ones(3)) + +def test_naif_keywords(test_naif_data): + np.testing.assert_equal(test_naif_data._naif_keywords['BODY-12345_RADII'], np.ones(3)) + np.testing.assert_equal(test_naif_data._naif_keywords['BODY_FRAME_CODE'], np.arange(1)) + np.testing.assert_equal(test_naif_data._naif_keywords['INS-12345_PIXEL_SIZE'], (0.001)) + np.testing.assert_equal(test_naif_data._naif_keywords['INS-12345_ITRANSL'], np.ones(3)) + np.testing.assert_equal(test_naif_data._naif_keywords['INS-12345_ITRANSS'], np.ones(3)) + np.testing.assert_equal(test_naif_data._naif_keywords['INS-12345_FOCAL_LENGTH'], np.ones(1)) + np.testing.assert_equal(test_naif_data._naif_keywords['INS-12345_BORESIGHT_LINE'], np.ones(1)) + np.testing.assert_equal(test_naif_data._naif_keywords['INS-12345_BORESIGHT_SAMPLE'], np.ones(1))