or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

ck-orientation.mdcoordinate-systems.mddata-structures.mddsk-shape-models.mde-kernels.mdephemeris-trajectories.mderror-handling.mdevent-finding.mdgeometry-surface.mdindex.mdkernel-management.mdlow-level-file-access.mdphysical-constants.mdreference-frames.mdspacecraft-clock.mdtime-systems.mdvector-matrix.md

kernel-management.mddocs/

0

# Kernel Management

1

2

Essential functions for loading and managing SPICE data files (kernels) that contain ephemeris, attitude, instrument, and reference frame information. Kernel management is fundamental to all SPICE operations as kernels provide the data needed for computations.

3

4

## Capabilities

5

6

### Loading Kernels

7

8

Load SPICE kernels (data files) into the kernel pool for use by other SPICE functions.

9

10

```python { .api }

11

def furnsh(kernel: str) -> None:

12

"""

13

Load a SPICE kernel file into the kernel pool.

14

15

Parameters:

16

- kernel: str, path to kernel file or meta-kernel file

17

18

Returns:

19

None

20

21

Raises:

22

SpiceyError: if kernel file cannot be loaded

23

"""

24

```

25

26

Usage example:

27

```python

28

import spiceypy as spice

29

30

# Load a single kernel file

31

spice.furnsh("de430.bsp")

32

33

# Load a meta-kernel (contains list of other kernels to load)

34

spice.furnsh("cassini_metakernel.mk")

35

```

36

37

### Unloading Kernels

38

39

Remove specific kernels or clear all loaded kernels from memory.

40

41

```python { .api }

42

def unload(kernel: str) -> None:

43

"""

44

Unload a specific SPICE kernel file from the kernel pool.

45

46

Parameters:

47

- kernel: str, path to kernel file to unload

48

49

Returns:

50

None

51

"""

52

53

def kclear() -> None:

54

"""

55

Clear the kernel pool by unloading all loaded kernels.

56

57

Parameters:

58

None

59

60

Returns:

61

None

62

"""

63

```

64

65

Usage example:

66

```python

67

# Unload a specific kernel

68

spice.unload("de430.bsp")

69

70

# Clear all loaded kernels (recommended cleanup)

71

spice.kclear()

72

```

73

74

### Kernel Information

75

76

Query information about loaded kernels and kernel pool contents.

77

78

```python { .api }

79

def ktotal(kind: str) -> int:

80

"""

81

Return the number of loaded kernels of a specified type.

82

83

Parameters:

84

- kind: str, kernel type ("SPK", "CK", "PCK", "EK", "IK", "LSK", "SCLK", "META", "TEXT", "ALL")

85

86

Returns:

87

int: number of loaded kernels of specified type

88

"""

89

90

def kdata(which: int, kind: str) -> Tuple[str, str, str, bool]:

91

"""

92

Return data for the nth kernel of a specified type.

93

94

Parameters:

95

- which: int, index of kernel (0-based)

96

- kind: str, kernel type

97

98

Returns:

99

Tuple[str, str, str, bool]: (file, filetype, source, found)

100

"""

101

102

def kinfo(file: str) -> Tuple[str, str, int, bool]:

103

"""

104

Return information about a loaded kernel file.

105

106

Parameters:

107

- file: str, kernel file path

108

109

Returns:

110

Tuple[str, str, int, bool]: (filetype, source, handle, found)

111

"""

112

```

113

114

### Kernel Pool Variables

115

116

Access and modify variables stored in the kernel pool.

117

118

```python { .api }

119

def gcpool(name: str, start: int, room: int) -> Tuple[int, List[str], bool]:

120

"""

121

Get character data from the kernel pool.

122

123

Parameters:

124

- name: str, variable name

125

- start: int, starting index

126

- room: int, maximum number of values to return

127

128

Returns:

129

Tuple[int, List[str], bool]: (n, cvals, found)

130

"""

131

132

def gdpool(name: str, start: int, room: int) -> Tuple[int, ndarray, bool]:

133

"""

134

Get double precision data from the kernel pool.

135

136

Parameters:

137

- name: str, variable name

138

- start: int, starting index

139

- room: int, maximum number of values to return

140

141

Returns:

142

Tuple[int, ndarray, bool]: (n, values, found)

143

"""

144

145

def gipool(name: str, start: int, room: int) -> Tuple[int, List[int], bool]:

146

"""

147

Get integer data from the kernel pool.

148

149

Parameters:

150

- name: str, variable name

151

- start: int, starting index

152

- room: int, maximum number of values to return

153

154

Returns:

155

Tuple[int, List[int], bool]: (n, ivals, found)

156

"""

157

```

158

159

### Kernel Pool Management

160

161

Advanced kernel pool operations for watching variables and managing updates.

162

163

```python { .api }

164

def swpool(agent: str, nnames: int, names: List[str]) -> None:

165

"""

166

Set up watchers for kernel pool variables.

167

168

Parameters:

169

- agent: str, name of the agent watching variables

170

- nnames: int, number of variable names

171

- names: List[str], variable names to watch

172

173

Returns:

174

None

175

"""

176

177

def cvpool(agent: str) -> bool:

178

"""

179

Check if any watched variables have been updated.

180

181

Parameters:

182

- agent: str, name of the watching agent

183

184

Returns:

185

bool: True if watched variables were updated

186

"""

187

188

def clpool() -> None:

189

"""

190

Clear the kernel pool of all variables.

191

192

Returns:

193

None

194

"""

195

```

196

197

## Common Usage Patterns

198

199

### Basic Kernel Loading Workflow

200

```python

201

import spiceypy as spice

202

203

try:

204

# Load kernels

205

spice.furnsh("metakernel.mk")

206

207

# Perform SPICE computations here

208

# ...

209

210

finally:

211

# Always clean up

212

spice.kclear()

213

```

214

215

### Checking Loaded Kernels

216

```python

217

# Check how many SPK kernels are loaded

218

n_spk = spice.ktotal("SPK")

219

print(f"Loaded SPK kernels: {n_spk}")

220

221

# Get information about the first SPK kernel

222

if n_spk > 0:

223

file, filetype, source, found = spice.kdata(0, "SPK")

224

print(f"First SPK kernel: {file}")

225

```

226

227

### Context Manager Pattern

228

```python

229

from spiceypy import KernelPool

230

231

# Temporary kernel loading

232

with KernelPool("metakernel.mk"):

233

# Kernels are loaded for this block

234

position, lt = spice.spkpos("MARS", et, "J2000", "NONE", "EARTH")

235

# Kernels are automatically unloaded when exiting the block

236

```