def kernels(self): if not hasattr(self, '_kernels'): if 'kernels' in self._props.keys(): try: self._kernels = util.get_kernels_from_isis_pvl( self._props['kernels']) except Exception as e: self._kernels = self._props['kernels'] else: if not ale.spice_root: raise EnvironmentError( f'ale.spice_root is not set, cannot search for metakernels. ale.spice_root = "{ale.spice_root}"' ) search_results = util.get_metakernels( ale.spice_root, missions=self.short_mission_name, years=self.utc_start_time.year, versions='latest') if search_results['count'] == 0: raise ValueError( f'Failed to find metakernels. mission: {self.short_mission_name}, year:{self.utc_start_time.year}, versions="latest" spice root = "{ale.spice_root}"' ) self._kernels = [search_results['data'][0]['path']] return self._kernels
def test_get_metakernels_search_args(tmpdir, search_kwargs): tmpdir.mkdir('foo-b-v01') tmpdir.mkdir('bar-b-v01') open(tmpdir.join('foo-b-v01', 'foo_2009_v01.tm'), 'w').close() open(tmpdir.join('bar-b-v01', 'bar_9009_v01.tm'), 'w').close() open(tmpdir.join('bar-b-v01', 'bar_2009_v10.tm'), 'w').close() test_mk = tmpdir.join('bar-b-v01', 'bar_2010_v20.tm') open(test_mk, 'w').close() search_result = util.get_metakernels(str(tmpdir), **search_kwargs) expected = { 'count': 1, 'data': [{ 'year': '2010', 'mission': 'bar', 'version': 'v20', 'path': test_mk }] } assert search_result == expected
def test_get_metakernels(tmpdir, search_kwargs, expected): tmpdir.mkdir('foo-b-v01') tmpdir.mkdir('bar-b-v01') open(tmpdir.join('foo-b-v01', 'foo_2009_v01.tm'), 'w').close() open(tmpdir.join('bar-b-v01', 'bar_2010_v02.tm'), 'w').close() search_result = util.get_metakernels(str(tmpdir), **search_kwargs) # we can't know the tmpdir at parameterization, append it here for r in expected['data']: r['path'] = str(tmpdir.join(r['path'])) assert search_result == expected
def kernels(self): """ Get the NAIF SPICE Kernels to furnish There are two ways to specify which kernels a driver will use: 1. Passing the 'kernels' property into load(s) or at instantiation. This can be either a straight iterable or a dictionary that specifies the kernels in ISIS style ('TargetPosition', 'InstrumentPosition', etc). 2. Set the ALESPICEROOT environment variable. This variable should be the path to a directory that contains directories whose naming convention matches the PDS Kernel Archives format, `shortMissionName-versionInfo`. The directory corresponding to the driver's mission will be searched for the approriate meta kernel to load. See Also -------- ale.util.get_kernels_from_isis_pvl : Function used to parse ISIS style dict ale.util.get_metakernels : Function that searches ALESPICEROOT for meta kernels ale.util.generate_kernels_from_cube : Helper function to get an ISIS style dict from an ISIS cube that has been through spiceinit """ if not hasattr(self, '_kernels'): if 'kernels' in self._props.keys(): try: self._kernels = util.get_kernels_from_isis_pvl( self._props['kernels']) except Exception as e: self._kernels = self._props['kernels'] else: if not ale.spice_root: raise EnvironmentError( f'ale.spice_root is not set, cannot search for metakernels. ale.spice_root = "{ale.spice_root}"' ) search_results = util.get_metakernels( ale.spice_root, missions=self.short_mission_name, years=self.utc_start_time.year, versions='latest') if search_results['count'] == 0: raise ValueError( f'Failed to find metakernels. mission: {self.short_mission_name}, year:{self.utc_start_time.year}, versions="latest" spice root = "{ale.spice_root}"' ) self._kernels = [search_results['data'][0]['path']] return self._kernels
def test_get_metakernels_search_counts(tmpdir, search_kwargs, expected_count): tmpdir.mkdir('foo-b-v01') tmpdir.mkdir('bar-b-v01') tmpdir.mkdir('baz-b-v100') open(tmpdir.join('foo-b-v01', 'foo_2009_v01.tm'), 'w').close() open(tmpdir.join('foo-b-v01', 'foo_2009_v20.tm'), 'w').close() open(tmpdir.join('foo-b-v01', 'foo_2010_v20.tm'), 'w').close() open(tmpdir.join('bar-b-v01', 'bar_9009_v01.tm'), 'w').close() open(tmpdir.join('bar-b-v01', 'bar_2009_v10.tm'), 'w').close() open(tmpdir.join('bar-b-v01', 'bar_2010_v02.tm'), 'w').close() open(tmpdir.join('baz-b-v100', 'baz_1990_v10.tm'), 'w').close() search_result = util.get_metakernels(str(tmpdir), **search_kwargs) assert search_result['count'] == expected_count