fitsjs-ng 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +180 -0
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +607 -0
- package/dist/index.d.ts +607 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/package.json +108 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FITS standard BITPIX values representing data types in image arrays.
|
|
3
|
+
* Positive values are integer types, negative values are floating point.
|
|
4
|
+
*/
|
|
5
|
+
type BitPix = 8 | 16 | 32 | -32 | -64;
|
|
6
|
+
/**
|
|
7
|
+
* Extended BITPIX values used in compressed images (ZBITPIX).
|
|
8
|
+
*/
|
|
9
|
+
type ZBitPix = 8 | 16 | 32 | 64 | -32 | -64;
|
|
10
|
+
/**
|
|
11
|
+
* Possible value types stored in a FITS header card.
|
|
12
|
+
*/
|
|
13
|
+
type CardValue = string | number | boolean | null;
|
|
14
|
+
/**
|
|
15
|
+
* A single header card entry with its positional index, value, and optional comment.
|
|
16
|
+
*/
|
|
17
|
+
interface HeaderCard {
|
|
18
|
+
index: number;
|
|
19
|
+
value: CardValue;
|
|
20
|
+
comment: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Types of FITS data units.
|
|
24
|
+
*/
|
|
25
|
+
type DataUnitType = 'Image' | 'BinaryTable' | 'Table' | 'CompressedImage';
|
|
26
|
+
/**
|
|
27
|
+
* FITS extension types as stored in the XTENSION keyword.
|
|
28
|
+
*/
|
|
29
|
+
type ExtensionType = 'IMAGE' | 'BINTABLE' | 'TABLE';
|
|
30
|
+
/**
|
|
31
|
+
* Compression algorithms supported by the FITS tiled image convention.
|
|
32
|
+
*/
|
|
33
|
+
type CompressionType = 'GZIP_1' | 'RICE_1' | 'PLIO_1' | 'HCOMPRESS_1';
|
|
34
|
+
/**
|
|
35
|
+
* Quantization methods for compressed images.
|
|
36
|
+
*/
|
|
37
|
+
type QuantizationType = 'LINEAR_SCALING' | 'SUBTRACTIVE_DITHER_1' | 'SUBTRACTIVE_DITHER_2';
|
|
38
|
+
/**
|
|
39
|
+
* Binary table format type codes (single character descriptors).
|
|
40
|
+
*/
|
|
41
|
+
type BinaryTableTypeCode = 'L' | 'B' | 'I' | 'J' | 'K' | 'A' | 'E' | 'D' | 'C' | 'M' | 'X';
|
|
42
|
+
/**
|
|
43
|
+
* ASCII table format type codes.
|
|
44
|
+
*/
|
|
45
|
+
type AsciiTableTypeCode = 'A' | 'I' | 'F' | 'E' | 'D';
|
|
46
|
+
/**
|
|
47
|
+
* A binary table accessor function reads a value from a DataView at the given offset
|
|
48
|
+
* and returns the value plus the new offset.
|
|
49
|
+
*/
|
|
50
|
+
type BinaryAccessor = (view: DataView, offset: number) => [value: unknown, newOffset: number];
|
|
51
|
+
/**
|
|
52
|
+
* An ASCII table accessor transforms a string value into the appropriate type.
|
|
53
|
+
*/
|
|
54
|
+
type AsciiAccessor = (value: string) => CardValue;
|
|
55
|
+
type TypedArrayConstructor = Uint8ArrayConstructor | Int8ArrayConstructor | Uint16ArrayConstructor | Int16ArrayConstructor | Uint32ArrayConstructor | Int32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor;
|
|
56
|
+
type TypedArray = Uint8Array | Int8Array | Uint16Array | Int16Array | Uint32Array | Int32Array | Float32Array | Float64Array;
|
|
57
|
+
/**
|
|
58
|
+
* Warning callback type for non-fatal issues during parsing.
|
|
59
|
+
*/
|
|
60
|
+
type WarningCallback = (message: string) => void;
|
|
61
|
+
/**
|
|
62
|
+
* Options for reading FITS data.
|
|
63
|
+
*/
|
|
64
|
+
interface ReadOptions {
|
|
65
|
+
/** Maximum number of header lines to parse (default: 600) */
|
|
66
|
+
maxHeaderLines?: number;
|
|
67
|
+
/** Callback for non-fatal warnings during parsing (default: console.warn) */
|
|
68
|
+
onWarning?: WarningCallback;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Options for fetching remote FITS files.
|
|
72
|
+
*/
|
|
73
|
+
interface FetchOptions extends ReadOptions {
|
|
74
|
+
/** Additional fetch options (headers, signal, etc.) */
|
|
75
|
+
requestInit?: RequestInit;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Row data from a table, keyed by column name.
|
|
79
|
+
*/
|
|
80
|
+
type TableRow = Record<string, unknown>;
|
|
81
|
+
/**
|
|
82
|
+
* Compression algorithm parameters (e.g., BLOCKSIZE, BYTEPIX).
|
|
83
|
+
*/
|
|
84
|
+
type AlgorithmParameters = Record<string, number>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Context interface for verification functions — represents the header state
|
|
88
|
+
* during parsing so verification functions can access current parse state.
|
|
89
|
+
*/
|
|
90
|
+
interface VerifyContext {
|
|
91
|
+
cardIndex: number;
|
|
92
|
+
primary: boolean;
|
|
93
|
+
extension: boolean;
|
|
94
|
+
extensionType?: ExtensionType;
|
|
95
|
+
warn: WarningCallback;
|
|
96
|
+
get(key: string): CardValue;
|
|
97
|
+
isPrimary(): boolean;
|
|
98
|
+
isExtension(): boolean;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Represents a parsed FITS header.
|
|
103
|
+
*
|
|
104
|
+
* A FITS header consists of 80-character card images containing
|
|
105
|
+
* keyword = value / comment triplets.
|
|
106
|
+
*/
|
|
107
|
+
declare class Header implements VerifyContext {
|
|
108
|
+
private static readonly ARRAY_PATTERN;
|
|
109
|
+
/** Whether this is a primary header (contains SIMPLE keyword). */
|
|
110
|
+
primary: boolean;
|
|
111
|
+
/** Whether this is an extension header (contains XTENSION keyword). */
|
|
112
|
+
extension: boolean;
|
|
113
|
+
/** The extension type if this is an extension header. */
|
|
114
|
+
extensionType?: ExtensionType;
|
|
115
|
+
/** Storage for parsed header cards, keyed by keyword. */
|
|
116
|
+
private cards;
|
|
117
|
+
/** Storage for COMMENT cards. */
|
|
118
|
+
private comments;
|
|
119
|
+
/** Storage for HISTORY cards. */
|
|
120
|
+
private history;
|
|
121
|
+
/** Running index of the current card being parsed. */
|
|
122
|
+
cardIndex: number;
|
|
123
|
+
/** Warning callback for non-fatal issues during parsing. */
|
|
124
|
+
warn: WarningCallback;
|
|
125
|
+
/** Maximum number of header lines to parse. */
|
|
126
|
+
private maxLines;
|
|
127
|
+
/** The raw header block string, preserved for reference. */
|
|
128
|
+
readonly block: string;
|
|
129
|
+
constructor(block: string, maxLines?: number, onWarning?: WarningCallback);
|
|
130
|
+
/**
|
|
131
|
+
* Get the value for a header keyword.
|
|
132
|
+
* Returns `null` if the keyword is not present.
|
|
133
|
+
*/
|
|
134
|
+
get(key: string): CardValue;
|
|
135
|
+
/**
|
|
136
|
+
* Get a numeric value for a header keyword.
|
|
137
|
+
* Returns the `fallback` (default `0`) if the keyword is missing.
|
|
138
|
+
* Throws `HeaderError` if the value is present but not a number.
|
|
139
|
+
*/
|
|
140
|
+
getNumber(key: string, fallback?: number): number;
|
|
141
|
+
/**
|
|
142
|
+
* Get a string value for a header keyword.
|
|
143
|
+
* Returns the `fallback` (default `''`) if the keyword is missing.
|
|
144
|
+
* Throws `HeaderError` if the value is present but not a string.
|
|
145
|
+
*/
|
|
146
|
+
getString(key: string, fallback?: string): string;
|
|
147
|
+
/**
|
|
148
|
+
* Get a boolean value for a header keyword.
|
|
149
|
+
* Returns the `fallback` (default `false`) if the keyword is missing.
|
|
150
|
+
* Throws `HeaderError` if the value is present but not a boolean.
|
|
151
|
+
*/
|
|
152
|
+
getBoolean(key: string, fallback?: boolean): boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Set a keyword with a value and optional comment.
|
|
155
|
+
*/
|
|
156
|
+
set(key: string, value: CardValue, comment?: string): void;
|
|
157
|
+
/**
|
|
158
|
+
* Check if the header contains a specific keyword.
|
|
159
|
+
*/
|
|
160
|
+
contains(key: string): boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Get all COMMENT card values.
|
|
163
|
+
*/
|
|
164
|
+
getComments(): string[];
|
|
165
|
+
/**
|
|
166
|
+
* Get all HISTORY card values.
|
|
167
|
+
*/
|
|
168
|
+
getHistory(): string[];
|
|
169
|
+
/**
|
|
170
|
+
* Returns all keyword names in insertion order.
|
|
171
|
+
*/
|
|
172
|
+
keys(): string[];
|
|
173
|
+
/**
|
|
174
|
+
* Determine if this header has an associated data unit based on NAXIS.
|
|
175
|
+
*/
|
|
176
|
+
hasDataUnit(): boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Calculate the byte length of the associated data unit.
|
|
179
|
+
*/
|
|
180
|
+
getDataLength(): number;
|
|
181
|
+
/**
|
|
182
|
+
* Determine the data unit type from header keywords.
|
|
183
|
+
*/
|
|
184
|
+
getDataType(): DataUnitType | null;
|
|
185
|
+
/** Check if this is a primary header. */
|
|
186
|
+
isPrimary(): boolean;
|
|
187
|
+
/** Check if this is an extension header. */
|
|
188
|
+
isExtension(): boolean;
|
|
189
|
+
private readBlock;
|
|
190
|
+
private readLine;
|
|
191
|
+
private validate;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Base class for FITS data units (Image, BinaryTable, Table, CompressedImage).
|
|
196
|
+
*
|
|
197
|
+
* FITS data is always stored in big-endian format. This base class provides
|
|
198
|
+
* shared infrastructure for endian swapping and buffer management.
|
|
199
|
+
*/
|
|
200
|
+
declare class DataUnit {
|
|
201
|
+
/** The ArrayBuffer containing raw data (available when loaded from buffer). */
|
|
202
|
+
buffer?: ArrayBuffer;
|
|
203
|
+
/** The Blob containing raw data (available when loaded from file). */
|
|
204
|
+
blob?: Blob;
|
|
205
|
+
/** Static endian swap functions keyed by type code or byte size. */
|
|
206
|
+
static readonly swapEndian: Record<string | number, (value: number) => number>;
|
|
207
|
+
constructor(data: ArrayBuffer | Blob);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Header Data Unit — the fundamental building block of a FITS file.
|
|
212
|
+
*
|
|
213
|
+
* Each HDU contains a header and an optional data unit. The header
|
|
214
|
+
* describes the structure and metadata of the data unit.
|
|
215
|
+
*/
|
|
216
|
+
declare class HDU {
|
|
217
|
+
readonly header: Header;
|
|
218
|
+
readonly data?: DataUnit;
|
|
219
|
+
constructor(header: Header, data?: DataUnit);
|
|
220
|
+
/**
|
|
221
|
+
* Check if this HDU has an associated data unit.
|
|
222
|
+
*/
|
|
223
|
+
hasData(): boolean;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Main FITS class — the primary entry point for reading FITS files.
|
|
228
|
+
*
|
|
229
|
+
* Provides static factory methods for creating FITS instances from
|
|
230
|
+
* various data sources (ArrayBuffer, Blob/File, URL, Node.js Buffer).
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```ts
|
|
234
|
+
* // From URL (browser)
|
|
235
|
+
* const fits = await FITS.fromURL('https://example.com/image.fits');
|
|
236
|
+
*
|
|
237
|
+
* // From ArrayBuffer
|
|
238
|
+
* const fits = FITS.fromArrayBuffer(buffer);
|
|
239
|
+
*
|
|
240
|
+
* // From File object (browser)
|
|
241
|
+
* const fits = await FITS.fromBlob(fileInput.files[0]);
|
|
242
|
+
*
|
|
243
|
+
* // Access data
|
|
244
|
+
* const header = fits.getHeader();
|
|
245
|
+
* const image = fits.getDataUnit();
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
declare class FITS {
|
|
249
|
+
/** All Header Data Units in this FITS file. */
|
|
250
|
+
readonly hdus: HDU[];
|
|
251
|
+
private constructor();
|
|
252
|
+
/**
|
|
253
|
+
* Parse a FITS file from an ArrayBuffer (synchronous).
|
|
254
|
+
*/
|
|
255
|
+
static fromArrayBuffer(buffer: ArrayBuffer, options?: ReadOptions): FITS;
|
|
256
|
+
/**
|
|
257
|
+
* Parse a FITS file from a Blob or File object (async).
|
|
258
|
+
*/
|
|
259
|
+
static fromBlob(blob: Blob, options?: ReadOptions): Promise<FITS>;
|
|
260
|
+
/**
|
|
261
|
+
* Fetch a remote FITS file and parse it (async, browser or Node 18+).
|
|
262
|
+
*
|
|
263
|
+
* @param url - URL of the FITS file.
|
|
264
|
+
* @param init - Optional fetch RequestInit (headers, signal, etc.).
|
|
265
|
+
*/
|
|
266
|
+
static fromURL(url: string, options?: FetchOptions): Promise<FITS>;
|
|
267
|
+
/**
|
|
268
|
+
* Parse a FITS file from a Node.js Buffer.
|
|
269
|
+
* The buffer is converted to an ArrayBuffer internally.
|
|
270
|
+
*/
|
|
271
|
+
static fromNodeBuffer(nodeBuffer: {
|
|
272
|
+
buffer: ArrayBuffer;
|
|
273
|
+
byteOffset: number;
|
|
274
|
+
byteLength: number;
|
|
275
|
+
}, options?: ReadOptions): FITS;
|
|
276
|
+
/**
|
|
277
|
+
* Returns the first HDU containing a data unit.
|
|
278
|
+
* If `index` is provided, returns that specific HDU.
|
|
279
|
+
*/
|
|
280
|
+
getHDU(index?: number): HDU | undefined;
|
|
281
|
+
/**
|
|
282
|
+
* Returns the header associated with the first HDU containing a data unit.
|
|
283
|
+
* If `index` is provided, returns the header of that specific HDU.
|
|
284
|
+
*/
|
|
285
|
+
getHeader(index?: number): Header | undefined;
|
|
286
|
+
/**
|
|
287
|
+
* Returns the data unit associated with the first HDU containing a data unit.
|
|
288
|
+
* If `index` is provided, returns the data unit of that specific HDU.
|
|
289
|
+
*/
|
|
290
|
+
getDataUnit(index?: number): DataUnit | undefined;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
interface FrameOffset {
|
|
294
|
+
begin: number;
|
|
295
|
+
buffers?: ArrayBuffer[];
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Represents a standard FITS image stored in the data unit of a FITS file.
|
|
299
|
+
* Supports BITPIX values: 8, 16, 32, -32, -64
|
|
300
|
+
* Supports data cubes (NAXIS > 2) with frame-by-frame reading.
|
|
301
|
+
*/
|
|
302
|
+
declare class Image extends DataUnit {
|
|
303
|
+
readonly bitpix: number;
|
|
304
|
+
readonly naxis: number[];
|
|
305
|
+
readonly width: number;
|
|
306
|
+
readonly height: number;
|
|
307
|
+
readonly depth: number;
|
|
308
|
+
readonly bzero: number;
|
|
309
|
+
readonly bscale: number;
|
|
310
|
+
readonly bytes: number;
|
|
311
|
+
readonly length: number;
|
|
312
|
+
readonly frameLength: number;
|
|
313
|
+
readonly frameOffsets: FrameOffset[];
|
|
314
|
+
constructor(header: Header, data: ArrayBuffer | Blob);
|
|
315
|
+
/**
|
|
316
|
+
* Convert raw buffer bytes into pixel values with endian handling and BZERO/BSCALE.
|
|
317
|
+
*/
|
|
318
|
+
static computeFrame(buffer: ArrayBuffer, bitpix: number, bzero: number, bscale: number): TypedArray;
|
|
319
|
+
/**
|
|
320
|
+
* Read a single frame from the image. For 2D images, frame is always 0.
|
|
321
|
+
* For data cubes, frame selects the z-slice.
|
|
322
|
+
*
|
|
323
|
+
* @returns Promise resolving to pixel data as a typed array.
|
|
324
|
+
*/
|
|
325
|
+
getFrame(frame?: number): Promise<TypedArray>;
|
|
326
|
+
/**
|
|
327
|
+
* Read multiple sequential frames from a data cube.
|
|
328
|
+
*
|
|
329
|
+
* @param startFrame - First frame index to read.
|
|
330
|
+
* @param count - Number of frames to read.
|
|
331
|
+
* @returns Promise resolving to an array of typed arrays, one per frame.
|
|
332
|
+
*/
|
|
333
|
+
getFrames(startFrame: number, count: number): Promise<TypedArray[]>;
|
|
334
|
+
/** Check if the image is a data cube (more than 2 axes). */
|
|
335
|
+
isDataCube(): boolean;
|
|
336
|
+
/**
|
|
337
|
+
* Async iterator for frame-by-frame reading of data cubes.
|
|
338
|
+
* Yields each frame sequentially from index 0 to depth-1.
|
|
339
|
+
*/
|
|
340
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<TypedArray>;
|
|
341
|
+
/** Compute min/max pixel values of an array, ignoring NaN. */
|
|
342
|
+
getExtent(arr: TypedArray): [number, number];
|
|
343
|
+
/** Get a single pixel value at (x, y) from a pixel array. */
|
|
344
|
+
getPixel(arr: TypedArray, x: number, y: number): number;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Abstract base class for tabular FITS extensions (TABLE and BINTABLE).
|
|
349
|
+
*
|
|
350
|
+
* Handles shared logic for row/column access, buffer management,
|
|
351
|
+
* and accessor setup. Derived classes must implement `setAccessors` and `_getRows`.
|
|
352
|
+
*/
|
|
353
|
+
declare abstract class Tabular extends DataUnit {
|
|
354
|
+
/** Maximum memory (bytes) to hold when reading from blob. */
|
|
355
|
+
protected maxMemory: number;
|
|
356
|
+
readonly rowByteSize: number;
|
|
357
|
+
readonly rows: number;
|
|
358
|
+
readonly cols: number;
|
|
359
|
+
readonly length: number;
|
|
360
|
+
readonly heapLength: number;
|
|
361
|
+
readonly columns: string[] | null;
|
|
362
|
+
/** Accessor functions for each column. */
|
|
363
|
+
protected accessors: BinaryAccessor[];
|
|
364
|
+
/** Type descriptor for each column. */
|
|
365
|
+
protected descriptors: string[];
|
|
366
|
+
/** Byte length of each column element. */
|
|
367
|
+
protected elementByteLengths: number[];
|
|
368
|
+
/** TTYPE values for each column (used by subclasses to identify column roles). */
|
|
369
|
+
protected columnTypes: string[];
|
|
370
|
+
/** Heap data for variable-length arrays. */
|
|
371
|
+
heap?: ArrayBuffer;
|
|
372
|
+
/** Typed array constructor map (used by BinaryTable). */
|
|
373
|
+
protected typedArray: Record<string, new (length: number | ArrayBuffer) => TypedArray>;
|
|
374
|
+
private firstRowInBuffer;
|
|
375
|
+
private lastRowInBuffer;
|
|
376
|
+
private nRowsInBuffer;
|
|
377
|
+
private cachedBuffer?;
|
|
378
|
+
constructor(header: Header, data: ArrayBuffer | Blob);
|
|
379
|
+
/**
|
|
380
|
+
* Subclasses must call this at the end of their constructor.
|
|
381
|
+
*/
|
|
382
|
+
protected initAccessors(header: Header): void;
|
|
383
|
+
/**
|
|
384
|
+
* Clear all accessor arrays before re-initialization.
|
|
385
|
+
*/
|
|
386
|
+
private resetAccessors;
|
|
387
|
+
/**
|
|
388
|
+
* Derived classes must set up accessor functions for each column.
|
|
389
|
+
*/
|
|
390
|
+
protected abstract setAccessors(header: Header): void;
|
|
391
|
+
/**
|
|
392
|
+
* Derived classes must implement row parsing from a buffer.
|
|
393
|
+
*/
|
|
394
|
+
protected abstract _getRows(buffer: ArrayBuffer, nRows: number): TableRow[] | Float32Array;
|
|
395
|
+
/**
|
|
396
|
+
* Check if the specified row range is currently in memory.
|
|
397
|
+
*/
|
|
398
|
+
private rowsInMemory;
|
|
399
|
+
/**
|
|
400
|
+
* Get column names from the header.
|
|
401
|
+
*/
|
|
402
|
+
private getColumns;
|
|
403
|
+
/**
|
|
404
|
+
* Read a range of rows from the table.
|
|
405
|
+
*
|
|
406
|
+
* @param row - Starting row index (0-based).
|
|
407
|
+
* @param number_ - Number of rows to read.
|
|
408
|
+
*/
|
|
409
|
+
getRows(row: number, number_: number): Promise<TableRow[] | Float32Array | ArrayLike<number>>;
|
|
410
|
+
/**
|
|
411
|
+
* Read a table buffer for a range of rows.
|
|
412
|
+
* Used internally for column-based reading from blob.
|
|
413
|
+
*/
|
|
414
|
+
private getTableBuffer;
|
|
415
|
+
/**
|
|
416
|
+
* Read all values from a single column.
|
|
417
|
+
*
|
|
418
|
+
* @param name - Column name.
|
|
419
|
+
* @returns Array of column values.
|
|
420
|
+
*/
|
|
421
|
+
getColumn(name: string): Promise<unknown[]>;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Reads ASCII tables from FITS files (XTENSION = 'TABLE').
|
|
426
|
+
*
|
|
427
|
+
* ASCII tables store data as fixed-width text fields where each row
|
|
428
|
+
* is a sequence of ASCII characters.
|
|
429
|
+
*/
|
|
430
|
+
declare class Table extends Tabular {
|
|
431
|
+
private asciiAccessors;
|
|
432
|
+
/** 0-based start positions for each column within a row. */
|
|
433
|
+
private colStarts;
|
|
434
|
+
/** Character widths for each column. */
|
|
435
|
+
private colWidths;
|
|
436
|
+
/** Whether TBCOL keywords were found in the header. */
|
|
437
|
+
private hasTBCOL;
|
|
438
|
+
constructor(header: Header, data: ArrayBuffer | Blob);
|
|
439
|
+
protected setAccessors(header: Header): void;
|
|
440
|
+
protected _getRows(buffer: ArrayBuffer, _nRows?: number): TableRow[];
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Reads binary tables from FITS files (XTENSION = 'BINTABLE').
|
|
445
|
+
*
|
|
446
|
+
* Binary tables support a rich set of data types including logical,
|
|
447
|
+
* integer, float, complex, character, bit arrays, and variable-length
|
|
448
|
+
* array descriptors pointing to a heap area.
|
|
449
|
+
*/
|
|
450
|
+
declare class BinaryTable extends Tabular {
|
|
451
|
+
constructor(header: Header, data: ArrayBuffer | Blob);
|
|
452
|
+
protected setAccessors(header: Header): void;
|
|
453
|
+
/**
|
|
454
|
+
* Read data from the heap area following the main table data.
|
|
455
|
+
*/
|
|
456
|
+
protected getFromHeap(view: DataView, offset: number, descriptor: string): [TypedArray, number];
|
|
457
|
+
private setupArrayAccessor;
|
|
458
|
+
private setupSingleAccessor;
|
|
459
|
+
private setupBitArrayAccessor;
|
|
460
|
+
private setupCharArrayAccessor;
|
|
461
|
+
private setupMultiAccessor;
|
|
462
|
+
protected _getRows(buffer: ArrayBuffer, nRows: number): TableRow[] | Float32Array;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Reads Rice-compressed FITS images stored as binary tables.
|
|
467
|
+
*
|
|
468
|
+
* Compressed images are stored in BINTABLE extensions with ZIMAGE=T.
|
|
469
|
+
* Each row in the table represents one tile of the image.
|
|
470
|
+
* This class decompresses tiles and reconstructs the full image,
|
|
471
|
+
* applying subtractive dithering when appropriate.
|
|
472
|
+
*/
|
|
473
|
+
declare class CompressedImage extends BinaryTable {
|
|
474
|
+
readonly zcmptype: string;
|
|
475
|
+
readonly zbitpix: number;
|
|
476
|
+
readonly znaxis: number;
|
|
477
|
+
readonly zblank: number | null;
|
|
478
|
+
readonly blank: number | null;
|
|
479
|
+
readonly zdither: number;
|
|
480
|
+
readonly ztile: number[];
|
|
481
|
+
readonly width: number;
|
|
482
|
+
readonly height: number;
|
|
483
|
+
readonly bzero: number;
|
|
484
|
+
readonly bscale: number;
|
|
485
|
+
readonly algorithmParameters: AlgorithmParameters;
|
|
486
|
+
readonly zquantiz: string;
|
|
487
|
+
constructor(header: Header, data: ArrayBuffer | Blob);
|
|
488
|
+
/**
|
|
489
|
+
* Override setAccessors to replace compressed data column accessors
|
|
490
|
+
* with decompression-aware versions. Delegates base TFORM parsing to BinaryTable.
|
|
491
|
+
*/
|
|
492
|
+
protected setAccessors(header: Header): void;
|
|
493
|
+
/**
|
|
494
|
+
* Override _getRows to handle compressed image tile decompression
|
|
495
|
+
* and subtractive dithering.
|
|
496
|
+
*/
|
|
497
|
+
protected _getRows(buffer: ArrayBuffer, nRows: number): Float32Array;
|
|
498
|
+
/**
|
|
499
|
+
* Read a frame from the compressed image.
|
|
500
|
+
* Exposes the same API as Image.getFrame() for consistency.
|
|
501
|
+
*/
|
|
502
|
+
getFrame(_nFrame?: number): Promise<Float32Array>;
|
|
503
|
+
/** Compute min/max pixel values, ignoring NaN. */
|
|
504
|
+
getExtent(arr: Float32Array): [number, number];
|
|
505
|
+
/** Get a single pixel value at (x, y). */
|
|
506
|
+
getPixel(arr: Float32Array, x: number, y: number): number;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Compute the minimum and maximum pixel values in a typed array,
|
|
511
|
+
* ignoring NaN values.
|
|
512
|
+
*
|
|
513
|
+
* @returns A tuple [min, max], or [NaN, NaN] if all values are NaN.
|
|
514
|
+
*/
|
|
515
|
+
declare function getExtent(arr: TypedArray | Float32Array): [number, number];
|
|
516
|
+
/**
|
|
517
|
+
* Get a single pixel value from a flat array given x, y coordinates and image width.
|
|
518
|
+
*/
|
|
519
|
+
declare function getPixel(arr: TypedArray | Float32Array, x: number, y: number, width: number): number;
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Setup functions for Rice decompression, keyed by bytepix (1, 2, or 4).
|
|
523
|
+
* Each returns [fsbits, fsmax, lastpix, pointer].
|
|
524
|
+
*/
|
|
525
|
+
declare const RiceSetup: Record<number, (array: Uint8Array) => [number, number, number, number]>;
|
|
526
|
+
/**
|
|
527
|
+
* Rice decompression algorithm.
|
|
528
|
+
*
|
|
529
|
+
* Decompresses a byte array that was compressed using the Rice algorithm,
|
|
530
|
+
* as defined in the FITS tiled image compression convention.
|
|
531
|
+
*
|
|
532
|
+
* @param array - Compressed byte array.
|
|
533
|
+
* @param blocksize - Number of pixels encoded in a block.
|
|
534
|
+
* @param bytepix - Number of bytes per original pixel (1, 2, or 4).
|
|
535
|
+
* @param pixels - Output array to fill with decompressed values.
|
|
536
|
+
* @param nx - Number of output pixels (tile length).
|
|
537
|
+
* @param setup - Setup function map (default: RiceSetup).
|
|
538
|
+
* @returns The filled pixels array.
|
|
539
|
+
*/
|
|
540
|
+
declare function riceDecompress(array: Uint8Array, blocksize: number, bytepix: number, pixels: TypedArray, nx: number, setup?: Record<number, (array: Uint8Array) => [number, number, number, number]>): TypedArray;
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Parse a FITS file from an ArrayBuffer.
|
|
544
|
+
*
|
|
545
|
+
* Reads 2880-byte blocks sequentially, looking for the END keyword
|
|
546
|
+
* to delimit headers. After each header, the corresponding data unit
|
|
547
|
+
* is sliced from the buffer and an HDU is created.
|
|
548
|
+
*
|
|
549
|
+
* @param buffer - The complete FITS file as an ArrayBuffer.
|
|
550
|
+
* @returns Array of parsed HDUs.
|
|
551
|
+
*/
|
|
552
|
+
declare function parseBuffer(buffer: ArrayBuffer, options?: ReadOptions): HDU[];
|
|
553
|
+
/**
|
|
554
|
+
* Parse a FITS file from a Blob (File object) using streaming block reads.
|
|
555
|
+
*
|
|
556
|
+
* Reads header blocks incrementally (2880 bytes at a time) without loading
|
|
557
|
+
* the entire file into memory. Data units are kept as Blob slices for
|
|
558
|
+
* lazy on-demand reading, significantly reducing memory usage for large files.
|
|
559
|
+
*
|
|
560
|
+
* @param blob - The FITS file as a Blob or File object.
|
|
561
|
+
* @returns Promise resolving to an array of parsed HDUs.
|
|
562
|
+
*/
|
|
563
|
+
declare function parseBlob(blob: Blob, options?: ReadOptions): Promise<HDU[]>;
|
|
564
|
+
|
|
565
|
+
/** Width of a single FITS header card in bytes (characters). */
|
|
566
|
+
declare const LINE_WIDTH = 80;
|
|
567
|
+
/** Size of a FITS block in bytes. All FITS structures are padded to this boundary. */
|
|
568
|
+
declare const BLOCK_LENGTH = 2880;
|
|
569
|
+
/** Number of header card lines per FITS block. */
|
|
570
|
+
declare const LINES_PER_BLOCK: number;
|
|
571
|
+
/** Default maximum number of header lines to parse. */
|
|
572
|
+
declare const DEFAULT_MAX_HEADER_LINES = 600;
|
|
573
|
+
/** FITS special integer value representing a NULL pixel in compressed images. */
|
|
574
|
+
declare const NULL_VALUE = -2147483647;
|
|
575
|
+
/** FITS special integer value representing a 0.0 pixel in compressed images. */
|
|
576
|
+
declare const ZERO_VALUE = -2147483646;
|
|
577
|
+
/** Number of random values in the dithering sequence. */
|
|
578
|
+
declare const N_RANDOM = 10000;
|
|
579
|
+
/** Library version. */
|
|
580
|
+
declare const VERSION: string;
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Base error class for all FITS-related errors.
|
|
584
|
+
*/
|
|
585
|
+
declare class FITSError extends Error {
|
|
586
|
+
constructor(message: string);
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Error thrown during header parsing or validation.
|
|
590
|
+
*/
|
|
591
|
+
declare class HeaderError extends FITSError {
|
|
592
|
+
constructor(message: string);
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Error thrown during data unit reading or interpretation.
|
|
596
|
+
*/
|
|
597
|
+
declare class DataError extends FITSError {
|
|
598
|
+
constructor(message: string);
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Error thrown when decompression fails.
|
|
602
|
+
*/
|
|
603
|
+
declare class DecompressionError extends FITSError {
|
|
604
|
+
constructor(message: string);
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
export { type AlgorithmParameters, type AsciiAccessor, type AsciiTableTypeCode, BLOCK_LENGTH, type BinaryAccessor, BinaryTable, type BinaryTableTypeCode, type BitPix, type CardValue, CompressedImage, type CompressionType, DEFAULT_MAX_HEADER_LINES, DataError, DataUnit, type DataUnitType, DecompressionError, type ExtensionType, FITS, FITSError, type FetchOptions, HDU, Header, type HeaderCard, HeaderError, Image, LINES_PER_BLOCK, LINE_WIDTH, NULL_VALUE, N_RANDOM, type QuantizationType, type ReadOptions, RiceSetup, Table, type TableRow, type TypedArray, type TypedArrayConstructor, VERSION, type WarningCallback, type ZBitPix, ZERO_VALUE, getExtent, getPixel, parseBlob, parseBuffer, riceDecompress };
|