@loaders.gl/netcdf 3.1.0-alpha.4 → 3.1.0-beta.3
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/dist/es5/index.js +2 -2
- package/dist/es5/iobuffer/iobuffer.js +259 -318
- package/dist/es5/iobuffer/iobuffer.js.map +1 -1
- package/dist/es5/netcdf-loader.js +11 -62
- package/dist/es5/netcdf-loader.js.map +1 -1
- package/dist/es5/netcdfjs/netcdf-reader.js +97 -155
- package/dist/es5/netcdfjs/netcdf-reader.js.map +1 -1
- package/dist/es5/netcdfjs/read-data.js +12 -12
- package/dist/es5/netcdfjs/read-data.js.map +1 -1
- package/dist/es5/netcdfjs/read-header.js +58 -58
- package/dist/es5/netcdfjs/read-header.js.map +1 -1
- package/dist/es5/netcdfjs/read-type.js +3 -3
- package/dist/es5/netcdfjs/read-type.js.map +1 -1
- package/dist/esm/netcdf-loader.js +1 -1
- package/dist/esm/netcdf-loader.js.map +1 -1
- package/dist/esm/netcdfjs/netcdf-reader.js +7 -7
- package/dist/esm/netcdfjs/netcdf-reader.js.map +1 -1
- package/dist/esm/netcdfjs/read-header.js +2 -2
- package/dist/esm/netcdfjs/read-header.js.map +1 -1
- package/dist/esm/netcdfjs/read-type.js +1 -1
- package/dist/esm/netcdfjs/read-type.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/iobuffer/iobuffer.d.ts +254 -0
- package/dist/iobuffer/iobuffer.d.ts.map +1 -0
- package/dist/iobuffer/iobuffer.js +427 -0
- package/dist/netcdf-loader.d.ts +52 -0
- package/dist/netcdf-loader.d.ts.map +1 -0
- package/dist/netcdf-loader.js +52 -0
- package/dist/netcdfjs/netcdf-reader.d.ts +68 -0
- package/dist/netcdfjs/netcdf-reader.d.ts.map +1 -0
- package/dist/netcdfjs/netcdf-reader.js +165 -0
- package/dist/netcdfjs/netcdf-types.d.ts +70 -0
- package/dist/netcdfjs/netcdf-types.d.ts.map +1 -0
- package/dist/netcdfjs/netcdf-types.js +2 -0
- package/dist/netcdfjs/read-data.d.ts +18 -0
- package/dist/netcdfjs/read-data.d.ts.map +1 -0
- package/dist/netcdfjs/read-data.js +49 -0
- package/dist/netcdfjs/read-header.d.ts +16 -0
- package/dist/netcdfjs/read-header.d.ts.map +1 -0
- package/dist/netcdfjs/read-header.js +230 -0
- package/dist/netcdfjs/read-type.d.ts +36 -0
- package/dist/netcdfjs/read-type.d.ts.map +1 -0
- package/dist/netcdfjs/read-type.js +140 -0
- package/package.json +7 -8
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IOBuffer = void 0;
|
|
4
|
+
const DEFAULT_BYTE_LENGTH = 1024 * 8;
|
|
5
|
+
class IOBuffer {
|
|
6
|
+
/**
|
|
7
|
+
* @param data - The data to construct the IOBuffer with.
|
|
8
|
+
* If data is a number, it will be the new buffer's length<br>
|
|
9
|
+
* If data is `undefined`, the buffer will be initialized with a default length of 8Kb<br>
|
|
10
|
+
* If data is an ArrayBuffer, SharedArrayBuffer, an ArrayBufferView (Typed Array), an IOBuffer instance,
|
|
11
|
+
* or a Node.js Buffer, a view will be created over the underlying ArrayBuffer.
|
|
12
|
+
* @param options
|
|
13
|
+
*/
|
|
14
|
+
constructor(data = DEFAULT_BYTE_LENGTH, options = {}) {
|
|
15
|
+
this.textDecoder = new TextDecoder();
|
|
16
|
+
this.textEncoder = new TextEncoder();
|
|
17
|
+
let dataIsGiven = false;
|
|
18
|
+
if (typeof data === 'number') {
|
|
19
|
+
data = new ArrayBuffer(data);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
dataIsGiven = true;
|
|
23
|
+
this.lastWrittenByte = data.byteLength;
|
|
24
|
+
}
|
|
25
|
+
const offset = options.offset ? options.offset >>> 0 : 0;
|
|
26
|
+
const byteLength = data.byteLength - offset;
|
|
27
|
+
let dvOffset = offset;
|
|
28
|
+
if (ArrayBuffer.isView(data) || data instanceof IOBuffer) {
|
|
29
|
+
if (data.byteLength !== data.buffer.byteLength) {
|
|
30
|
+
dvOffset = data.byteOffset + offset;
|
|
31
|
+
}
|
|
32
|
+
data = data.buffer;
|
|
33
|
+
}
|
|
34
|
+
if (dataIsGiven) {
|
|
35
|
+
this.lastWrittenByte = byteLength;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
this.lastWrittenByte = 0;
|
|
39
|
+
}
|
|
40
|
+
this.buffer = data;
|
|
41
|
+
this.length = byteLength;
|
|
42
|
+
this.byteLength = byteLength;
|
|
43
|
+
this.byteOffset = dvOffset;
|
|
44
|
+
this.offset = 0;
|
|
45
|
+
this.littleEndian = true;
|
|
46
|
+
this._data = new DataView(this.buffer, dvOffset, byteLength);
|
|
47
|
+
this._mark = 0;
|
|
48
|
+
this._marks = [];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Checks if the memory allocated to the buffer is sufficient to store more
|
|
52
|
+
* bytes after the offset.
|
|
53
|
+
* @param byteLength - The needed memory in bytes.
|
|
54
|
+
* @returns `true` if there is sufficient space and `false` otherwise.
|
|
55
|
+
*/
|
|
56
|
+
available(byteLength = 1) {
|
|
57
|
+
return this.offset + byteLength <= this.length;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Check if little-endian mode is used for reading and writing multi-byte
|
|
61
|
+
* values.
|
|
62
|
+
* @returns `true` if little-endian mode is used, `false` otherwise.
|
|
63
|
+
*/
|
|
64
|
+
isLittleEndian() {
|
|
65
|
+
return this.littleEndian;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Set little-endian mode for reading and writing multi-byte values.
|
|
69
|
+
*/
|
|
70
|
+
setLittleEndian() {
|
|
71
|
+
this.littleEndian = true;
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Check if big-endian mode is used for reading and writing multi-byte values.
|
|
76
|
+
* @returns `true` if big-endian mode is used, `false` otherwise.
|
|
77
|
+
*/
|
|
78
|
+
isBigEndian() {
|
|
79
|
+
return !this.littleEndian;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Switches to big-endian mode for reading and writing multi-byte values.
|
|
83
|
+
*/
|
|
84
|
+
setBigEndian() {
|
|
85
|
+
this.littleEndian = false;
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Move the pointer n bytes forward.
|
|
90
|
+
* @param n - Number of bytes to skip.
|
|
91
|
+
*/
|
|
92
|
+
skip(n = 1) {
|
|
93
|
+
this.offset += n;
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Move the pointer to the given offset.
|
|
98
|
+
* @param offset
|
|
99
|
+
*/
|
|
100
|
+
seek(offset) {
|
|
101
|
+
this.offset = offset;
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Store the current pointer offset.
|
|
106
|
+
* @see {@link IOBuffer#reset}
|
|
107
|
+
*/
|
|
108
|
+
mark() {
|
|
109
|
+
this._mark = this.offset;
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Move the pointer back to the last pointer offset set by mark.
|
|
114
|
+
* @see {@link IOBuffer#mark}
|
|
115
|
+
*/
|
|
116
|
+
reset() {
|
|
117
|
+
this.offset = this._mark;
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Push the current pointer offset to the mark stack.
|
|
122
|
+
* @see {@link IOBuffer#popMark}
|
|
123
|
+
*/
|
|
124
|
+
pushMark() {
|
|
125
|
+
this._marks.push(this.offset);
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Pop the last pointer offset from the mark stack, and set the current
|
|
130
|
+
* pointer offset to the popped value.
|
|
131
|
+
* @see {@link IOBuffer#pushMark}
|
|
132
|
+
*/
|
|
133
|
+
popMark() {
|
|
134
|
+
const offset = this._marks.pop();
|
|
135
|
+
if (offset === undefined) {
|
|
136
|
+
throw new Error('Mark stack empty');
|
|
137
|
+
}
|
|
138
|
+
this.seek(offset);
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Move the pointer offset back to 0.
|
|
143
|
+
*/
|
|
144
|
+
rewind() {
|
|
145
|
+
this.offset = 0;
|
|
146
|
+
return this;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Make sure the buffer has sufficient memory to write a given byteLength at
|
|
150
|
+
* the current pointer offset.
|
|
151
|
+
* If the buffer's memory is insufficient, this method will create a new
|
|
152
|
+
* buffer (a copy) with a length that is twice (byteLength + current offset).
|
|
153
|
+
* @param byteLength
|
|
154
|
+
*/
|
|
155
|
+
ensureAvailable(byteLength = 1) {
|
|
156
|
+
if (!this.available(byteLength)) {
|
|
157
|
+
const lengthNeeded = this.offset + byteLength;
|
|
158
|
+
const newLength = lengthNeeded * 2;
|
|
159
|
+
const newArray = new Uint8Array(newLength);
|
|
160
|
+
newArray.set(new Uint8Array(this.buffer));
|
|
161
|
+
this.buffer = newArray.buffer;
|
|
162
|
+
this.length = this.byteLength = newLength;
|
|
163
|
+
this._data = new DataView(this.buffer);
|
|
164
|
+
}
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Read a byte and return false if the byte's value is 0, or true otherwise.
|
|
169
|
+
* Moves pointer forward by one byte.
|
|
170
|
+
*/
|
|
171
|
+
readBoolean() {
|
|
172
|
+
return this.readUint8() !== 0;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Read a signed 8-bit integer and move pointer forward by 1 byte.
|
|
176
|
+
*/
|
|
177
|
+
readInt8() {
|
|
178
|
+
return this._data.getInt8(this.offset++);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Read an unsigned 8-bit integer and move pointer forward by 1 byte.
|
|
182
|
+
*/
|
|
183
|
+
readUint8() {
|
|
184
|
+
return this._data.getUint8(this.offset++);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Alias for {@link IOBuffer#readUint8}.
|
|
188
|
+
*/
|
|
189
|
+
readByte() {
|
|
190
|
+
return this.readUint8();
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Read `n` bytes and move pointer forward by `n` bytes.
|
|
194
|
+
*/
|
|
195
|
+
readBytes(n = 1) {
|
|
196
|
+
const bytes = new Uint8Array(n);
|
|
197
|
+
for (let i = 0; i < n; i++) {
|
|
198
|
+
bytes[i] = this.readByte();
|
|
199
|
+
}
|
|
200
|
+
return bytes;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Read a 16-bit signed integer and move pointer forward by 2 bytes.
|
|
204
|
+
*/
|
|
205
|
+
readInt16() {
|
|
206
|
+
const value = this._data.getInt16(this.offset, this.littleEndian);
|
|
207
|
+
this.offset += 2;
|
|
208
|
+
return value;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Read a 16-bit unsigned integer and move pointer forward by 2 bytes.
|
|
212
|
+
*/
|
|
213
|
+
readUint16() {
|
|
214
|
+
const value = this._data.getUint16(this.offset, this.littleEndian);
|
|
215
|
+
this.offset += 2;
|
|
216
|
+
return value;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Read a 32-bit signed integer and move pointer forward by 4 bytes.
|
|
220
|
+
*/
|
|
221
|
+
readInt32() {
|
|
222
|
+
const value = this._data.getInt32(this.offset, this.littleEndian);
|
|
223
|
+
this.offset += 4;
|
|
224
|
+
return value;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Read a 32-bit unsigned integer and move pointer forward by 4 bytes.
|
|
228
|
+
*/
|
|
229
|
+
readUint32() {
|
|
230
|
+
const value = this._data.getUint32(this.offset, this.littleEndian);
|
|
231
|
+
this.offset += 4;
|
|
232
|
+
return value;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Read a 32-bit floating number and move pointer forward by 4 bytes.
|
|
236
|
+
*/
|
|
237
|
+
readFloat32() {
|
|
238
|
+
const value = this._data.getFloat32(this.offset, this.littleEndian);
|
|
239
|
+
this.offset += 4;
|
|
240
|
+
return value;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Read a 64-bit floating number and move pointer forward by 8 bytes.
|
|
244
|
+
*/
|
|
245
|
+
readFloat64() {
|
|
246
|
+
const value = this._data.getFloat64(this.offset, this.littleEndian);
|
|
247
|
+
this.offset += 8;
|
|
248
|
+
return value;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Read a 1-byte ASCII character and move pointer forward by 1 byte.
|
|
252
|
+
*/
|
|
253
|
+
readChar() {
|
|
254
|
+
return String.fromCharCode(this.readInt8());
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Read `n` 1-byte ASCII characters and move pointer forward by `n` bytes.
|
|
258
|
+
*/
|
|
259
|
+
readChars(n = 1) {
|
|
260
|
+
let result = '';
|
|
261
|
+
for (let i = 0; i < n; i++) {
|
|
262
|
+
result += this.readChar();
|
|
263
|
+
}
|
|
264
|
+
return result;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Read the next `n` bytes, return a UTF-8 decoded string and move pointer
|
|
268
|
+
* forward by `n` bytes.
|
|
269
|
+
*/
|
|
270
|
+
readUtf8(n = 1) {
|
|
271
|
+
return this.textDecoder.decode(this.readBytes(n));
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Write 0xff if the passed value is truthy, 0x00 otherwise and move pointer
|
|
275
|
+
* forward by 1 byte.
|
|
276
|
+
*/
|
|
277
|
+
writeBoolean(value) {
|
|
278
|
+
this.writeUint8(value ? 0xff : 0x00);
|
|
279
|
+
return this;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Write `value` as an 8-bit signed integer and move pointer forward by 1 byte.
|
|
283
|
+
*/
|
|
284
|
+
writeInt8(value) {
|
|
285
|
+
this.ensureAvailable(1);
|
|
286
|
+
this._data.setInt8(this.offset++, value);
|
|
287
|
+
this._updateLastWrittenByte();
|
|
288
|
+
return this;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Write `value` as an 8-bit unsigned integer and move pointer forward by 1
|
|
292
|
+
* byte.
|
|
293
|
+
*/
|
|
294
|
+
writeUint8(value) {
|
|
295
|
+
this.ensureAvailable(1);
|
|
296
|
+
this._data.setUint8(this.offset++, value);
|
|
297
|
+
this._updateLastWrittenByte();
|
|
298
|
+
return this;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* An alias for {@link IOBuffer#writeUint8}.
|
|
302
|
+
*/
|
|
303
|
+
writeByte(value) {
|
|
304
|
+
return this.writeUint8(value);
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Write all elements of `bytes` as uint8 values and move pointer forward by
|
|
308
|
+
* `bytes.length` bytes.
|
|
309
|
+
*/
|
|
310
|
+
writeBytes(bytes) {
|
|
311
|
+
this.ensureAvailable(bytes.length);
|
|
312
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
313
|
+
this._data.setUint8(this.offset++, bytes[i]);
|
|
314
|
+
}
|
|
315
|
+
this._updateLastWrittenByte();
|
|
316
|
+
return this;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Write `value` as a 16-bit signed integer and move pointer forward by 2
|
|
320
|
+
* bytes.
|
|
321
|
+
*/
|
|
322
|
+
writeInt16(value) {
|
|
323
|
+
this.ensureAvailable(2);
|
|
324
|
+
this._data.setInt16(this.offset, value, this.littleEndian);
|
|
325
|
+
this.offset += 2;
|
|
326
|
+
this._updateLastWrittenByte();
|
|
327
|
+
return this;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Write `value` as a 16-bit unsigned integer and move pointer forward by 2
|
|
331
|
+
* bytes.
|
|
332
|
+
*/
|
|
333
|
+
writeUint16(value) {
|
|
334
|
+
this.ensureAvailable(2);
|
|
335
|
+
this._data.setUint16(this.offset, value, this.littleEndian);
|
|
336
|
+
this.offset += 2;
|
|
337
|
+
this._updateLastWrittenByte();
|
|
338
|
+
return this;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Write `value` as a 32-bit signed integer and move pointer forward by 4
|
|
342
|
+
* bytes.
|
|
343
|
+
*/
|
|
344
|
+
writeInt32(value) {
|
|
345
|
+
this.ensureAvailable(4);
|
|
346
|
+
this._data.setInt32(this.offset, value, this.littleEndian);
|
|
347
|
+
this.offset += 4;
|
|
348
|
+
this._updateLastWrittenByte();
|
|
349
|
+
return this;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Write `value` as a 32-bit unsigned integer and move pointer forward by 4
|
|
353
|
+
* bytes.
|
|
354
|
+
*/
|
|
355
|
+
writeUint32(value) {
|
|
356
|
+
this.ensureAvailable(4);
|
|
357
|
+
this._data.setUint32(this.offset, value, this.littleEndian);
|
|
358
|
+
this.offset += 4;
|
|
359
|
+
this._updateLastWrittenByte();
|
|
360
|
+
return this;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Write `value` as a 32-bit floating number and move pointer forward by 4
|
|
364
|
+
* bytes.
|
|
365
|
+
*/
|
|
366
|
+
writeFloat32(value) {
|
|
367
|
+
this.ensureAvailable(4);
|
|
368
|
+
this._data.setFloat32(this.offset, value, this.littleEndian);
|
|
369
|
+
this.offset += 4;
|
|
370
|
+
this._updateLastWrittenByte();
|
|
371
|
+
return this;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Write `value` as a 64-bit floating number and move pointer forward by 8
|
|
375
|
+
* bytes.
|
|
376
|
+
*/
|
|
377
|
+
writeFloat64(value) {
|
|
378
|
+
this.ensureAvailable(8);
|
|
379
|
+
this._data.setFloat64(this.offset, value, this.littleEndian);
|
|
380
|
+
this.offset += 8;
|
|
381
|
+
this._updateLastWrittenByte();
|
|
382
|
+
return this;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Write the charCode of `str`'s first character as an 8-bit unsigned integer
|
|
386
|
+
* and move pointer forward by 1 byte.
|
|
387
|
+
*/
|
|
388
|
+
writeChar(str) {
|
|
389
|
+
return this.writeUint8(str.charCodeAt(0));
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Write the charCodes of all `str`'s characters as 8-bit unsigned integers
|
|
393
|
+
* and move pointer forward by `str.length` bytes.
|
|
394
|
+
*/
|
|
395
|
+
writeChars(str) {
|
|
396
|
+
for (let i = 0; i < str.length; i++) {
|
|
397
|
+
this.writeUint8(str.charCodeAt(i));
|
|
398
|
+
}
|
|
399
|
+
return this;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* UTF-8 encode and write `str` to the current pointer offset and move pointer
|
|
403
|
+
* forward according to the encoded length.
|
|
404
|
+
*/
|
|
405
|
+
writeUtf8(str) {
|
|
406
|
+
const bytes = this.textEncoder.encode(str);
|
|
407
|
+
return this.writeBytes(bytes);
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Export a Uint8Array view of the internal buffer.
|
|
411
|
+
* The view starts at the byte offset and its length
|
|
412
|
+
* is calculated to stop at the last written byte or the original length.
|
|
413
|
+
*/
|
|
414
|
+
toArray() {
|
|
415
|
+
return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte);
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Update the last written byte offset
|
|
419
|
+
* @private
|
|
420
|
+
*/
|
|
421
|
+
_updateLastWrittenByte() {
|
|
422
|
+
if (this.offset > this.lastWrittenByte) {
|
|
423
|
+
this.lastWrittenByte = this.offset;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
exports.IOBuffer = IOBuffer;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Loader, LoaderWithParser, LoaderOptions } from '@loaders.gl/loader-utils';
|
|
2
|
+
import type { NetCDFHeader } from './netcdfjs/netcdf-types';
|
|
3
|
+
export declare type NetCDF = {
|
|
4
|
+
loaderData: NetCDFHeader;
|
|
5
|
+
data: {
|
|
6
|
+
[variableName: string]: any[][];
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export declare type NetCDFLoaderOptions = LoaderOptions & {
|
|
10
|
+
netcdf?: {
|
|
11
|
+
loadData?: boolean;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Worker loader for NETCDF
|
|
16
|
+
*/
|
|
17
|
+
export declare const NetCDFWorkerLoader: {
|
|
18
|
+
name: string;
|
|
19
|
+
id: string;
|
|
20
|
+
module: string;
|
|
21
|
+
version: any;
|
|
22
|
+
extensions: string[];
|
|
23
|
+
mimeTypes: string[];
|
|
24
|
+
category: string;
|
|
25
|
+
options: {
|
|
26
|
+
netcdf: {
|
|
27
|
+
loadVariables: boolean;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Loader for the NetCDF format
|
|
33
|
+
*/
|
|
34
|
+
export declare const NetCDFLoader: {
|
|
35
|
+
parse: (arrayBuffer: any, options: any) => Promise<NetCDF>;
|
|
36
|
+
binary: boolean;
|
|
37
|
+
name: string;
|
|
38
|
+
id: string;
|
|
39
|
+
module: string;
|
|
40
|
+
version: any;
|
|
41
|
+
extensions: string[];
|
|
42
|
+
mimeTypes: string[];
|
|
43
|
+
category: string;
|
|
44
|
+
options: {
|
|
45
|
+
netcdf: {
|
|
46
|
+
loadVariables: boolean;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export declare const _typecheckNetCDFWorkerLoader: Loader;
|
|
51
|
+
export declare const _typecheckNetCDFLoader: LoaderWithParser;
|
|
52
|
+
//# sourceMappingURL=netcdf-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"netcdf-loader.d.ts","sourceRoot":"","sources":["../src/netcdf-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,gBAAgB,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACtF,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,yBAAyB,CAAC;AAO1D,oBAAY,MAAM,GAAG;IACnB,UAAU,EAAE,YAAY,CAAC;IACzB,IAAI,EAAE;QAAC,CAAC,YAAY,EAAE,MAAM,GAAG,GAAG,EAAE,EAAE,CAAA;KAAC,CAAC;CACzC,CAAC;AAEF,oBAAY,mBAAmB,GAAG,aAAa,GAAG;IAChD,MAAM,CAAC,EAAE;QACP,QAAQ,CAAC,EAAE,OAAO,CAAC;KACpB,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;CAiB9B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;CAIxB,CAAC;AAiBF,eAAO,MAAM,4BAA4B,EAAE,MAA2B,CAAC;AACvE,eAAO,MAAM,sBAAsB,EAAE,gBAA+B,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._typecheckNetCDFLoader = exports._typecheckNetCDFWorkerLoader = exports.NetCDFLoader = exports.NetCDFWorkerLoader = void 0;
|
|
4
|
+
const netcdf_reader_1 = require("./netcdfjs/netcdf-reader");
|
|
5
|
+
// __VERSION__ is injected by babel-plugin-version-inline
|
|
6
|
+
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
7
|
+
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
8
|
+
/**
|
|
9
|
+
* Worker loader for NETCDF
|
|
10
|
+
*/
|
|
11
|
+
exports.NetCDFWorkerLoader = {
|
|
12
|
+
name: 'NetCDF',
|
|
13
|
+
id: 'mvt',
|
|
14
|
+
module: 'mvt',
|
|
15
|
+
version: VERSION,
|
|
16
|
+
extensions: ['cdf', 'nc'],
|
|
17
|
+
mimeTypes: [
|
|
18
|
+
'application/netcdf',
|
|
19
|
+
'application/x-netcdf'
|
|
20
|
+
// 'application/octet-stream'
|
|
21
|
+
],
|
|
22
|
+
category: 'image',
|
|
23
|
+
options: {
|
|
24
|
+
netcdf: {
|
|
25
|
+
loadVariables: false
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Loader for the NetCDF format
|
|
31
|
+
*/
|
|
32
|
+
exports.NetCDFLoader = {
|
|
33
|
+
...exports.NetCDFWorkerLoader,
|
|
34
|
+
parse: async (arrayBuffer, options) => parseNetCDF(arrayBuffer, options),
|
|
35
|
+
binary: true
|
|
36
|
+
};
|
|
37
|
+
function parseNetCDF(arrayBuffer, options) {
|
|
38
|
+
const reader = new netcdf_reader_1.NetCDFReader(arrayBuffer);
|
|
39
|
+
const variables = {};
|
|
40
|
+
if (options?.netcdf?.loadData) {
|
|
41
|
+
for (const variable of reader.variables) {
|
|
42
|
+
variables[variable.name] = reader.getDataVariable(variable);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
loaderData: reader.header,
|
|
47
|
+
data: variables
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// Type tests
|
|
51
|
+
exports._typecheckNetCDFWorkerLoader = exports.NetCDFWorkerLoader;
|
|
52
|
+
exports._typecheckNetCDFLoader = exports.NetCDFLoader;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { IOBuffer } from '../iobuffer/iobuffer';
|
|
2
|
+
import type { NetCDFHeader, NetCDFDimension, NetCDFRecordDimension, NetCDFAttribute, NetCDFVariable } from './netcdf-types';
|
|
3
|
+
/**
|
|
4
|
+
* Reads a NetCDF v3.x file
|
|
5
|
+
* https://www.unidata.ucar.edu/software/netcdf/docs/file_format_specifications.html
|
|
6
|
+
* @param {ArrayBuffer} data - ArrayBuffer or any Typed Array (including Node.js' Buffer from v4) with the data
|
|
7
|
+
* @constructor
|
|
8
|
+
*/
|
|
9
|
+
export declare class NetCDFReader {
|
|
10
|
+
header: NetCDFHeader;
|
|
11
|
+
buffer: IOBuffer;
|
|
12
|
+
constructor(data: any);
|
|
13
|
+
/**
|
|
14
|
+
* @return {string} - Version for the NetCDF format
|
|
15
|
+
*/
|
|
16
|
+
get version(): "classic format" | "64-bit offset format";
|
|
17
|
+
/**
|
|
18
|
+
* Get metadata for the record dimension
|
|
19
|
+
*/
|
|
20
|
+
get recordDimension(): NetCDFRecordDimension;
|
|
21
|
+
/**
|
|
22
|
+
* Get list of dimensions (each with `name` and `size`)
|
|
23
|
+
*/
|
|
24
|
+
get dimensions(): NetCDFDimension[];
|
|
25
|
+
/**
|
|
26
|
+
* Get list of global attributes with:
|
|
27
|
+
* * `name`: String with the name of the attribute
|
|
28
|
+
* * `type`: String with the type of the attribute
|
|
29
|
+
* * `value`: A number or string with the value of the attribute
|
|
30
|
+
*/
|
|
31
|
+
get attributes(): NetCDFAttribute[];
|
|
32
|
+
/**
|
|
33
|
+
* Get list of variables
|
|
34
|
+
*/
|
|
35
|
+
get variables(): NetCDFVariable[];
|
|
36
|
+
/**
|
|
37
|
+
* Check if an attribute exists
|
|
38
|
+
* @param attributeName - Name of the attribute to find
|
|
39
|
+
* @return
|
|
40
|
+
*/
|
|
41
|
+
attributeExists(attributeName: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Returns the value of an attribute
|
|
44
|
+
* @param attributeName
|
|
45
|
+
* @return Value of the attributeName or null
|
|
46
|
+
*/
|
|
47
|
+
getAttribute(attributeName: string): string | null;
|
|
48
|
+
/**
|
|
49
|
+
* Check if a dataVariable exists
|
|
50
|
+
* @param variableName - Name of the variable to find
|
|
51
|
+
* @return
|
|
52
|
+
*/
|
|
53
|
+
dataVariableExists(variableName: string): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the value of a variable as a string
|
|
56
|
+
* @param variableName
|
|
57
|
+
* @return Value of the variable as a string or null
|
|
58
|
+
*/
|
|
59
|
+
getDataVariableAsString(variableName: string): string | null;
|
|
60
|
+
/**
|
|
61
|
+
* Retrieves the data for a given variable
|
|
62
|
+
* @param variableName - Name of the variable to search or variable object
|
|
63
|
+
* @return List with the variable values
|
|
64
|
+
*/
|
|
65
|
+
getDataVariable(variableName: string | object): any[];
|
|
66
|
+
toString(): string;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=netcdf-reader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"netcdf-reader.d.ts","sourceRoot":"","sources":["../../src/netcdfjs/netcdf-reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAC9C,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,eAAe,EACf,cAAc,EACf,MAAM,gBAAgB,CAAC;AAIxB;;;;;GAKG;AACH,qBAAa,YAAY;IAChB,MAAM,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE,QAAQ,CAAC;gBAEZ,IAAI,KAAA;IAqBhB;;OAEG;IACH,IAAI,OAAO,8CAKV;IAED;;OAEG;IACH,IAAI,eAAe,IAAI,qBAAqB,CAE3C;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,eAAe,EAAE,CAElC;IAED;;;;;OAKG;IACH,IAAI,UAAU,IAAI,eAAe,EAAE,CAElC;IAED;;OAEG;IACH,IAAI,SAAS,IAAI,cAAc,EAAE,CAEhC;IAED;;;;OAIG;IACH,eAAe,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO;IAK/C;;;;OAIG;IACH,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAMlD;;;;OAIG;IACH,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO;IAOjD;;;;OAIG;IACH,uBAAuB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAM5D;;;;OAIG;IACH,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,EAAE;IA2BrD,QAAQ,IAAI,MAAM;CA4BnB"}
|