I/O — File Format Parsers¶
spectrakit.io.read_jcamp ¶
Read a JCAMP-DX file and return a Spectrum.
Parses ##XYDATA=(X++(Y..Y)) format. Supports AFFN (ASCII free-format numeric) encoding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the .dx / .jdx / .jcamp file. |
required |
Returns:
| Type | Description |
|---|---|
Spectrum
|
Spectrum with intensities shape (W,) and wavenumbers shape (W,). |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If path does not exist. |
ValueError
|
If the file cannot be parsed. |
Source code in src/spectrakit/io/jcamp.py
spectrakit.io.read_spc ¶
Read a Galactic SPC file and return a Spectrum.
Requires the spc-spectra package (install via
pip install spectrakit[io]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the .spc file. |
required |
Returns:
| Type | Description |
|---|---|
Spectrum
|
Spectrum with intensities shape (W,) or (N, W) for multi-trace files. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If spc-spectra is not installed. |
FileNotFoundError
|
If path does not exist. |
Source code in src/spectrakit/io/spc.py
spectrakit.io.read_csv ¶
read_csv(
path: str | Path,
delimiter: str = ",",
x_column: int = 0,
y_column: int = 1,
skip_header: int = 0,
orientation: Literal["columns", "rows"] = "columns",
) -> Spectrum
Read spectral data from a CSV or TSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the CSV file. |
required |
delimiter
|
str
|
Column separator. Use "\t" for TSV. |
','
|
x_column
|
int
|
Index of the wavenumber/wavelength column. Set to -1 to indicate no x-axis column (y data only). |
0
|
y_column
|
int
|
Index of the intensity column (for single-spectrum files). Ignored when orientation="rows". |
1
|
skip_header
|
int
|
Number of header lines to skip. |
0
|
orientation
|
Literal['columns', 'rows']
|
"columns" means each column is a variable (x, y1, y2...); "rows" means each row is a full spectrum. |
'columns'
|
Returns:
| Type | Description |
|---|---|
Spectrum
|
Spectrum with intensities and optional wavenumbers. |
Source code in src/spectrakit/io/csv.py
spectrakit.io.read_opus ¶
Read a Bruker OPUS binary file and return a Spectrum.
Parses the OPUS binary format natively without external dependencies. Extracts the absorbance/transmittance spectrum, wavenumber axis (computed from FXV/LXV parameters), and metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the OPUS file (.0, .1, .2, etc.). |
required |
Returns:
| Type | Description |
|---|---|
Spectrum
|
Spectrum with intensities shape |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If path does not exist. |
FileFormatError
|
If the file cannot be parsed as valid OPUS. |
Source code in src/spectrakit/io/opus.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | |
spectrakit.io.read_hdf5 ¶
read_hdf5(
path: str | Path,
intensities_key: str = "intensities",
wavenumbers_key: str = "wavenumbers",
) -> Spectrum
Read spectral data from an HDF5 file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the .h5 / .hdf5 file. |
required |
intensities_key
|
str
|
Dataset key for intensity values. |
'intensities'
|
wavenumbers_key
|
str
|
Dataset key for wavenumber values. |
'wavenumbers'
|
Returns:
| Type | Description |
|---|---|
Spectrum
|
Spectrum loaded from the HDF5 datasets. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If h5py is not installed. |
FileNotFoundError
|
If path does not exist. |
Source code in src/spectrakit/io/hdf5.py
spectrakit.io.write_hdf5 ¶
write_hdf5(
spectrum: Spectrum,
path: str | Path,
intensities_key: str = "intensities",
wavenumbers_key: str = "wavenumbers",
) -> None
Write a Spectrum to an HDF5 file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spectrum
|
Spectrum
|
Spectrum to save. |
required |
path
|
str | Path
|
Output file path. |
required |
intensities_key
|
str
|
Dataset key for intensity values. |
'intensities'
|
wavenumbers_key
|
str
|
Dataset key for wavenumber values. |
'wavenumbers'
|