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

low-level-file-access.mddocs/

0

# Low-Level File Access (DAF/DAS)

1

2

Low-level functions for direct access to SPICE data files using DAF (Double Precision Array Files) and DAS (Direct Access, Segregated) architectures. These functions provide advanced file manipulation capabilities for users who need direct control over SPICE file structures.

3

4

## Capabilities

5

6

### DAF (Double Precision Array Files)

7

8

Direct access to double precision array files like SPK and CK kernels.

9

10

```python { .api }

11

def dafopr(fname: str) -> int:

12

"""

13

Open DAF for reading.

14

15

Parameters:

16

- fname: str, DAF file name

17

18

Returns:

19

int: file handle

20

"""

21

22

def dafopw(fname: str) -> int:

23

"""

24

Open DAF for writing.

25

26

Parameters:

27

- fname: str, DAF file name

28

29

Returns:

30

int: file handle

31

"""

32

33

def dafcls(handle: int) -> None:

34

"""

35

Close DAF file.

36

37

Parameters:

38

- handle: int, file handle

39

40

Returns:

41

None

42

"""

43

```

44

45

### DAF Search Operations

46

47

Search for segments and arrays within DAF files.

48

49

```python { .api }

50

def dafbfs(handle: int) -> None:

51

"""

52

Begin forward search in DAF.

53

54

Parameters:

55

- handle: int, DAF file handle

56

57

Returns:

58

None

59

"""

60

61

def dafbbs(handle: int) -> None:

62

"""

63

Begin backward search in DAF.

64

65

Parameters:

66

- handle: int, DAF file handle

67

68

Returns:

69

None

70

"""

71

72

def daffna() -> bool:

73

"""

74

Find next array in DAF.

75

76

Returns:

77

bool: True if array found

78

"""

79

80

def daffpa() -> bool:

81

"""

82

Find previous array in DAF.

83

84

Returns:

85

bool: True if array found

86

"""

87

88

def dafgn() -> str:

89

"""

90

Get name of current DAF array.

91

92

Returns:

93

str: array name

94

"""

95

96

def dafgs() -> ndarray:

97

"""

98

Get summary of current DAF array.

99

100

Returns:

101

ndarray: array summary (double precision)

102

"""

103

```

104

105

### DAF Data Access

106

107

Read and write data arrays within DAF files.

108

109

```python { .api }

110

def dafgda(handle: int, begin: int, end: int) -> ndarray:

111

"""

112

Get data from DAF array.

113

114

Parameters:

115

- handle: int, DAF file handle

116

- begin: int, starting address

117

- end: int, ending address

118

119

Returns:

120

ndarray: data array

121

"""

122

123

def dafrda(handle: int, begin: int, end: int) -> ndarray:

124

"""

125

Read data from DAF file.

126

127

Parameters:

128

- handle: int, DAF file handle

129

- begin: int, starting address

130

- end: int, ending address

131

132

Returns:

133

ndarray: data array

134

"""

135

136

def dafada(handle: int, data: ndarray) -> None:

137

"""

138

Add data to DAF array.

139

140

Parameters:

141

- handle: int, DAF file handle

142

- data: ndarray, data to add

143

144

Returns:

145

None

146

"""

147

```

148

149

### DAF File Structure

150

151

Manage DAF file structure and metadata.

152

153

```python { .api }

154

def dafhsf(handle: int, nd: int, ni: int) -> bool:

155

"""

156

Does DAF handle have a specific structure.

157

158

Parameters:

159

- handle: int, DAF file handle

160

- nd: int, number of double precision components

161

- ni: int, number of integer components

162

163

Returns:

164

bool: True if structure matches

165

"""

166

167

def dafps(nd: int, ni: int, dc: ndarray, ic: ndarray) -> ndarray:

168

"""

169

Pack DAF summary.

170

171

Parameters:

172

- nd: int, number of double precision components

173

- ni: int, number of integer components

174

- dc: ndarray, double precision components

175

- ic: ndarray, integer components

176

177

Returns:

178

ndarray: packed summary

179

"""

180

181

def dafus(sum: ndarray, nd: int, ni: int) -> Tuple[ndarray, ndarray]:

182

"""

183

Unpack DAF summary.

184

185

Parameters:

186

- sum: ndarray, packed summary

187

- nd: int, number of double precision components

188

- ni: int, number of integer components

189

190

Returns:

191

Tuple[ndarray, ndarray]: (dc, ic) components

192

"""

193

```

194

195

### DAS (Direct Access, Segregated)

196

197

Direct access to segregated data files with support for multiple data types.

198

199

```python { .api }

200

def dasopn(fname: str, ftype: str, ncomch: int) -> int:

201

"""

202

Open new DAS file for writing.

203

204

Parameters:

205

- fname: str, DAS file name

206

- ftype: str, file type

207

- ncomch: int, number of comment characters

208

209

Returns:

210

int: file handle

211

"""

212

213

def dasopr(fname: str) -> int:

214

"""

215

Open DAS file for reading.

216

217

Parameters:

218

- fname: str, DAS file name

219

220

Returns:

221

int: file handle

222

"""

223

224

def dascls(handle: int) -> None:

225

"""

226

Close DAS file.

227

228

Parameters:

229

- handle: int, file handle

230

231

Returns:

232

None

233

"""

234

```

235

236

### DAS Data Operations

237

238

Read and write different data types to DAS files.

239

240

```python { .api }

241

def dasadd(handle: int, data: ndarray) -> None:

242

"""

243

Add double precision data to DAS file.

244

245

Parameters:

246

- handle: int, DAS file handle

247

- data: ndarray, double precision data

248

249

Returns:

250

None

251

"""

252

253

def dasadi(handle: int, data: ndarray) -> None:

254

"""

255

Add integer data to DAS file.

256

257

Parameters:

258

- handle: int, DAS file handle

259

- data: ndarray, integer data

260

261

Returns:

262

None

263

"""

264

265

def dasadc(handle: int, data: List[str]) -> None:

266

"""

267

Add character data to DAS file.

268

269

Parameters:

270

- handle: int, DAS file handle

271

- data: List[str], character data

272

273

Returns:

274

None

275

"""

276

277

def dasrdd(handle: int, first: int, last: int) -> ndarray:

278

"""

279

Read double precision data from DAS file.

280

281

Parameters:

282

- handle: int, DAS file handle

283

- first: int, first address

284

- last: int, last address

285

286

Returns:

287

ndarray: double precision data

288

"""

289

290

def dasrdi(handle: int, first: int, last: int) -> ndarray:

291

"""

292

Read integer data from DAS file.

293

294

Parameters:

295

- handle: int, DAS file handle

296

- first: int, first address

297

- last: int, last address

298

299

Returns:

300

ndarray: integer data

301

"""

302

303

def dasrdc(handle: int, first: int, last: int, lenout: int) -> List[str]:

304

"""

305

Read character data from DAS file.

306

307

Parameters:

308

- handle: int, DAS file handle

309

- first: int, first address

310

- last: int, last address

311

- lenout: int, maximum string length

312

313

Returns:

314

List[str]: character data

315

"""

316

```

317

318

### DAS File Information

319

320

Query DAS file properties and metadata.

321

322

```python { .api }

323

def dashfs(handle: int) -> Tuple[int, int, int, int, int, int, int, int, int]:

324

"""

325

Get DAS file summary.

326

327

Parameters:

328

- handle: int, DAS file handle

329

330

Returns:

331

Tuple[int, ...]: (nresvr, nresvc, ncomr, ncomc, free, lastla, lastrc, lastwd, lastc)

332

"""

333

334

def daslla(handle: int, dtype: int) -> int:

335

"""

336

Get last logical address for data type in DAS file.

337

338

Parameters:

339

- handle: int, DAS file handle

340

- dtype: int, data type (1=char, 2=double, 3=int)

341

342

Returns:

343

int: last logical address

344

"""

345

346

def dasluh(handle: int) -> int:

347

"""

348

Get last used handle in DAS file system.

349

350

Parameters:

351

- handle: int, DAS file handle

352

353

Returns:

354

int: highest handle in use

355

"""

356

```

357

358

## Common Usage Patterns

359

360

### Reading DAF File Contents

361

```python

362

import spiceypy as spice

363

import numpy as np

364

365

# Open DAF file for reading

366

handle = spice.dafopr("ephemeris.bsp")

367

368

try:

369

# Begin forward search

370

spice.dafbfs(handle)

371

372

# Search through all arrays

373

found = spice.daffna()

374

array_count = 0

375

376

while found:

377

# Get array information

378

name = spice.dafgn()

379

summary = spice.dafgs()

380

381

print(f"Array {array_count}: {name}")

382

print(f" Summary: {summary[:8]}") # First 8 elements

383

384

# Unpack summary (assuming SPK structure: 2 doubles, 6 integers)

385

dc, ic = spice.dafus(summary, 2, 6)

386

print(f" Time range: {dc[0]} to {dc[1]}")

387

print(f" Body ID: {ic[0]}, Center: {ic[1]}")

388

389

# Find next array

390

found = spice.daffna()

391

array_count += 1

392

393

print(f"Total arrays found: {array_count}")

394

395

finally:

396

# Always close the file

397

spice.dafcls(handle)

398

```

399

400

### Extracting Data from DAF Array

401

```python

402

import spiceypy as spice

403

404

# Open SPK file

405

handle = spice.dafopr("ephemeris.bsp")

406

407

try:

408

# Search for specific body

409

target_body = 399 # Earth

410

spice.dafbfs(handle)

411

found = spice.daffna()

412

413

while found:

414

summary = spice.dafgs()

415

dc, ic = spice.dafus(summary, 2, 6)

416

417

if ic[0] == target_body: # Found target body

418

print(f"Found data for body {target_body}")

419

420

# Calculate data addresses (simplified example)

421

# Note: Real SPK parsing is much more complex

422

begin_addr = int(ic[4]) # Starting address

423

end_addr = int(ic[5]) # Ending address

424

425

if end_addr > begin_addr:

426

# Extract some data (first 10 values as example)

427

data = spice.dafgda(handle, begin_addr, min(begin_addr + 9, end_addr))

428

print(f"First 10 data values: {data}")

429

break

430

431

found = spice.daffna()

432

433

finally:

434

spice.dafcls(handle)

435

```

436

437

### Working with DAS Files

438

```python

439

import spiceypy as spice

440

import numpy as np

441

442

# Create new DAS file

443

handle = spice.dasopn("test_data.das", "TEST", 0)

444

445

try:

446

# Add different types of data

447

double_data = np.array([1.1, 2.2, 3.3, 4.4, 5.5])

448

integer_data = np.array([10, 20, 30, 40, 50], dtype=int)

449

char_data = ["Hello", "World", "DAS", "File"]

450

451

# Write data to file

452

spice.dasadd(handle, double_data)

453

spice.dasadi(handle, integer_data)

454

spice.dasadc(handle, char_data)

455

456

print("Data written to DAS file")

457

458

# Get file summary

459

summary = spice.dashfs(handle)

460

print(f"File summary: {summary}")

461

462

finally:

463

# Close file

464

spice.dascls(handle)

465

466

# Read data back

467

handle = spice.dasopr("test_data.das")

468

469

try:

470

# Get last addresses for each data type

471

last_double = spice.daslla(handle, 2) # Double precision

472

last_int = spice.daslla(handle, 3) # Integer

473

last_char = spice.daslla(handle, 1) # Character

474

475

print(f"Last addresses - Double: {last_double}, Int: {last_int}, Char: {last_char}")

476

477

if last_double > 0:

478

# Read double precision data

479

doubles = spice.dasrdd(handle, 1, last_double)

480

print(f"Double data: {doubles}")

481

482

if last_int > 0:

483

# Read integer data

484

integers = spice.dasrdi(handle, 1, last_int)

485

print(f"Integer data: {integers}")

486

487

if last_char > 0:

488

# Read character data

489

chars = spice.dasrdc(handle, 1, last_char, 10)

490

print(f"Character data: {chars}")

491

492

finally:

493

spice.dascls(handle)

494

```

495

496

### DAF File Structure Analysis

497

```python

498

import spiceypy as spice

499

500

# Analyze DAF file structure

501

def analyze_daf_structure(filename):

502

handle = spice.dafopr(filename)

503

504

try:

505

print(f"Analyzing DAF file: {filename}")

506

507

# Check file structure for different kernel types

508

structures = [

509

(2, 6, "SPK"), # SPK: 2 doubles, 6 integers

510

(1, 5, "CK"), # CK: 1 double, 5 integers

511

(2, 5, "PCK"), # PCK: 2 doubles, 5 integers

512

]

513

514

detected_type = None

515

for nd, ni, ktype in structures:

516

if spice.dafhsf(handle, nd, ni):

517

detected_type = ktype

518

break

519

520

if detected_type:

521

print(f"Detected kernel type: {detected_type}")

522

else:

523

print("Unknown kernel type")

524

525

# Count arrays

526

spice.dafbfs(handle)

527

count = 0

528

found = spice.daffna()

529

530

while found:

531

count += 1

532

found = spice.daffna()

533

534

print(f"Number of data arrays: {count}")

535

536

finally:

537

spice.dafcls(handle)

538

539

# Example usage

540

analyze_daf_structure("ephemeris.bsp")

541

```

542

543

**Note**: These low-level functions require deep understanding of SPICE file formats and are primarily intended for advanced users developing custom tools or debugging SPICE data files. Most users should prefer the higher-level functions in other capability areas.