@loaders.gl/netcdf 4.0.0-alpha.4 → 4.0.0-alpha.6
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 +20 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/iobuffer/iobuffer.js +369 -0
- package/dist/es5/iobuffer/iobuffer.js.map +1 -0
- package/dist/es5/netcdf-loader.js +81 -0
- package/dist/es5/netcdf-loader.js.map +1 -0
- package/dist/es5/netcdfjs/netcdf-reader.js +173 -0
- package/dist/es5/netcdfjs/netcdf-reader.js.map +1 -0
- package/dist/es5/netcdfjs/netcdf-types.js +2 -0
- package/dist/es5/netcdfjs/netcdf-types.js.map +1 -0
- package/dist/es5/netcdfjs/read-data.js +31 -0
- package/dist/es5/netcdfjs/read-data.js.map +1 -0
- package/dist/es5/netcdfjs/read-header.js +168 -0
- package/dist/es5/netcdfjs/read-header.js.map +1 -0
- package/dist/es5/netcdfjs/read-type.js +108 -0
- package/dist/es5/netcdfjs/read-type.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/iobuffer/iobuffer.js +270 -0
- package/dist/esm/iobuffer/iobuffer.js.map +1 -0
- package/dist/esm/netcdf-loader.js +38 -0
- package/dist/esm/netcdf-loader.js.map +1 -0
- package/dist/esm/netcdfjs/LICENSE +24 -0
- package/dist/esm/netcdfjs/netcdf-reader.js +104 -0
- package/dist/esm/netcdfjs/netcdf-reader.js.map +1 -0
- package/dist/esm/netcdfjs/netcdf-types.js +2 -0
- package/dist/esm/netcdfjs/netcdf-types.js.map +1 -0
- package/dist/esm/netcdfjs/read-data.js +24 -0
- package/dist/esm/netcdfjs/read-data.js.map +1 -0
- package/dist/esm/netcdfjs/read-header.js +161 -0
- package/dist/esm/netcdfjs/read-header.js.map +1 -0
- package/dist/esm/netcdfjs/read-type.js +97 -0
- package/dist/esm/netcdfjs/read-type.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -3
- package/dist/iobuffer/iobuffer.d.ts +254 -0
- package/dist/iobuffer/iobuffer.d.ts.map +1 -0
- package/dist/iobuffer/iobuffer.js +425 -370
- package/dist/netcdf-loader.d.ts +52 -0
- package/dist/netcdf-loader.d.ts.map +1 -0
- package/dist/netcdf-loader.js +46 -36
- 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 +155 -126
- 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 -2
- 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 +47 -26
- 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 +206 -173
- 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 +130 -117
- package/package.json +7 -7
- package/dist/index.js.map +0 -1
- package/dist/iobuffer/iobuffer.js.map +0 -1
- package/dist/netcdf-loader.js.map +0 -1
- package/dist/netcdfjs/netcdf-reader.js.map +0 -1
- package/dist/netcdfjs/netcdf-types.js.map +0 -1
- package/dist/netcdfjs/read-data.js.map +0 -1
- package/dist/netcdfjs/read-header.js.map +0 -1
- package/dist/netcdfjs/read-type.js.map +0 -1
- /package/dist/{netcdfjs → es5/netcdfjs}/LICENSE +0 -0
|
@@ -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 type NetCDF = {
|
|
4
|
+
loaderData: NetCDFHeader;
|
|
5
|
+
data: {
|
|
6
|
+
[variableName: string]: any[][];
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export 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,MAAM,MAAM,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,MAAM,MAAM,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"}
|
package/dist/netcdf-loader.js
CHANGED
|
@@ -1,42 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
+
}
|
|
14
27
|
}
|
|
15
|
-
}
|
|
16
28
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
20
36
|
};
|
|
21
|
-
|
|
22
37
|
function parseNetCDF(arrayBuffer, options) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
for (const variable of reader.variables) {
|
|
30
|
-
variables[variable.name] = reader.getDataVariable(variable);
|
|
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
|
+
}
|
|
31
44
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
data: variables
|
|
37
|
-
};
|
|
45
|
+
return {
|
|
46
|
+
loaderData: reader.header,
|
|
47
|
+
data: variables
|
|
48
|
+
};
|
|
38
49
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
//# sourceMappingURL=netcdf-loader.js.map
|
|
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"}
|
|
@@ -1,136 +1,165 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NetCDFReader = void 0;
|
|
4
|
+
const iobuffer_1 = require("../iobuffer/iobuffer");
|
|
5
|
+
const read_header_1 = require("./read-header");
|
|
6
|
+
const read_data_1 = require("./read-data");
|
|
7
|
+
/**
|
|
8
|
+
* Reads a NetCDF v3.x file
|
|
9
|
+
* https://www.unidata.ucar.edu/software/netcdf/docs/file_format_specifications.html
|
|
10
|
+
* @param {ArrayBuffer} data - ArrayBuffer or any Typed Array (including Node.js' Buffer from v4) with the data
|
|
11
|
+
* @constructor
|
|
12
|
+
*/
|
|
13
|
+
class NetCDFReader {
|
|
14
|
+
constructor(data) {
|
|
15
|
+
const buffer = new iobuffer_1.IOBuffer(data);
|
|
16
|
+
buffer.setBigEndian();
|
|
17
|
+
// Validate that it's a NetCDF file
|
|
18
|
+
const magic = buffer.readChars(3);
|
|
19
|
+
if (magic !== 'CDF') {
|
|
20
|
+
throw new Error(`NetCDF: file should start with 'CDF', found ${magic}`);
|
|
21
|
+
}
|
|
22
|
+
// Check the NetCDF format
|
|
23
|
+
const version = buffer.readByte();
|
|
24
|
+
if (version > 2) {
|
|
25
|
+
throw new Error(`NetCDF: unsupported version ${version}`);
|
|
26
|
+
}
|
|
27
|
+
// Read the header
|
|
28
|
+
this.header = (0, read_header_1.readNetCDFHeader)(buffer, version);
|
|
29
|
+
this.buffer = buffer;
|
|
17
30
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
31
|
+
/**
|
|
32
|
+
* @return {string} - Version for the NetCDF format
|
|
33
|
+
*/
|
|
34
|
+
get version() {
|
|
35
|
+
if (this.header.version === 1) {
|
|
36
|
+
return 'classic format';
|
|
37
|
+
}
|
|
38
|
+
return '64-bit offset format';
|
|
23
39
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
get version() {
|
|
30
|
-
if (this.header.version === 1) {
|
|
31
|
-
return 'classic format';
|
|
40
|
+
/**
|
|
41
|
+
* Get metadata for the record dimension
|
|
42
|
+
*/
|
|
43
|
+
get recordDimension() {
|
|
44
|
+
return this.header.recordDimension;
|
|
32
45
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return this.header.recordDimension;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
get dimensions() {
|
|
42
|
-
return this.header.dimensions;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
get attributes() {
|
|
46
|
-
return this.header.attributes;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
get variables() {
|
|
50
|
-
return this.header.variables;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
attributeExists(attributeName) {
|
|
54
|
-
const attribute = this.attributes.find(val => val.name === attributeName);
|
|
55
|
-
return attribute !== undefined;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
getAttribute(attributeName) {
|
|
59
|
-
const attribute = this.attributes.find(val => val.name === attributeName);
|
|
60
|
-
if (attribute) return attribute.value;
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
dataVariableExists(variableName) {
|
|
65
|
-
const variable = this.header.variables.find(function (val) {
|
|
66
|
-
return val.name === variableName;
|
|
67
|
-
});
|
|
68
|
-
return variable !== undefined;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
getDataVariableAsString(variableName) {
|
|
72
|
-
const variable = this.getDataVariable(variableName);
|
|
73
|
-
if (variable) return variable.join('');
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
getDataVariable(variableName) {
|
|
78
|
-
let variable;
|
|
79
|
-
|
|
80
|
-
if (typeof variableName === 'string') {
|
|
81
|
-
variable = this.header.variables.find(function (val) {
|
|
82
|
-
return val.name === variableName;
|
|
83
|
-
});
|
|
84
|
-
} else {
|
|
85
|
-
variable = variableName;
|
|
46
|
+
/**
|
|
47
|
+
* Get list of dimensions (each with `name` and `size`)
|
|
48
|
+
*/
|
|
49
|
+
get dimensions() {
|
|
50
|
+
return this.header.dimensions;
|
|
86
51
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Get list of global attributes with:
|
|
54
|
+
* * `name`: String with the name of the attribute
|
|
55
|
+
* * `type`: String with the type of the attribute
|
|
56
|
+
* * `value`: A number or string with the value of the attribute
|
|
57
|
+
*/
|
|
58
|
+
get attributes() {
|
|
59
|
+
return this.header.attributes;
|
|
90
60
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Get list of variables
|
|
63
|
+
*/
|
|
64
|
+
get variables() {
|
|
65
|
+
return this.header.variables;
|
|
96
66
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
for (const dimension of this.dimensions) {
|
|
106
|
-
result.push(" ".concat(dimension.name.padEnd(30), " = size: ").concat(dimension.size));
|
|
67
|
+
/**
|
|
68
|
+
* Check if an attribute exists
|
|
69
|
+
* @param attributeName - Name of the attribute to find
|
|
70
|
+
* @return
|
|
71
|
+
*/
|
|
72
|
+
attributeExists(attributeName) {
|
|
73
|
+
const attribute = this.attributes.find((val) => val.name === attributeName);
|
|
74
|
+
return attribute !== undefined;
|
|
107
75
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Returns the value of an attribute
|
|
78
|
+
* @param attributeName
|
|
79
|
+
* @return Value of the attributeName or null
|
|
80
|
+
*/
|
|
81
|
+
getAttribute(attributeName) {
|
|
82
|
+
const attribute = this.attributes.find((val) => val.name === attributeName);
|
|
83
|
+
if (attribute)
|
|
84
|
+
return attribute.value;
|
|
85
|
+
return null;
|
|
114
86
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Check if a dataVariable exists
|
|
89
|
+
* @param variableName - Name of the variable to find
|
|
90
|
+
* @return
|
|
91
|
+
*/
|
|
92
|
+
dataVariableExists(variableName) {
|
|
93
|
+
const variable = this.header.variables.find(function (val) {
|
|
94
|
+
return val.name === variableName;
|
|
95
|
+
});
|
|
96
|
+
return variable !== undefined;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Returns the value of a variable as a string
|
|
100
|
+
* @param variableName
|
|
101
|
+
* @return Value of the variable as a string or null
|
|
102
|
+
*/
|
|
103
|
+
getDataVariableAsString(variableName) {
|
|
104
|
+
const variable = this.getDataVariable(variableName);
|
|
105
|
+
if (variable)
|
|
106
|
+
return variable.join('');
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Retrieves the data for a given variable
|
|
111
|
+
* @param variableName - Name of the variable to search or variable object
|
|
112
|
+
* @return List with the variable values
|
|
113
|
+
*/
|
|
114
|
+
getDataVariable(variableName) {
|
|
115
|
+
let variable;
|
|
116
|
+
if (typeof variableName === 'string') {
|
|
117
|
+
// search the variable
|
|
118
|
+
variable = this.header.variables.find(function (val) {
|
|
119
|
+
return val.name === variableName;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
variable = variableName;
|
|
124
|
+
}
|
|
125
|
+
// throws if variable not found
|
|
126
|
+
if (variable === undefined) {
|
|
127
|
+
throw new Error(`NetCDF: variable not found: ${variableName}`);
|
|
128
|
+
}
|
|
129
|
+
// go to the offset position
|
|
130
|
+
this.buffer.seek(variable.offset);
|
|
131
|
+
if (variable.record) {
|
|
132
|
+
// record variable case
|
|
133
|
+
return (0, read_data_1.readRecord)(this.buffer, variable, this.header.recordDimension);
|
|
134
|
+
}
|
|
135
|
+
// non-record variable case
|
|
136
|
+
return (0, read_data_1.readNonRecord)(this.buffer, variable);
|
|
137
|
+
}
|
|
138
|
+
toString() {
|
|
139
|
+
const result = [];
|
|
140
|
+
result.push('DIMENSIONS');
|
|
141
|
+
for (const dimension of this.dimensions) {
|
|
142
|
+
result.push(` ${dimension.name.padEnd(30)} = size: ${dimension.size}`);
|
|
143
|
+
}
|
|
144
|
+
result.push('');
|
|
145
|
+
result.push('GLOBAL ATTRIBUTES');
|
|
146
|
+
for (const attribute of this.attributes) {
|
|
147
|
+
result.push(` ${attribute.name.padEnd(30)} = ${attribute.value}`);
|
|
148
|
+
}
|
|
149
|
+
const variables = JSON.parse(JSON.stringify(this.variables));
|
|
150
|
+
result.push('');
|
|
151
|
+
result.push('VARIABLES:');
|
|
152
|
+
for (const variable of variables) {
|
|
153
|
+
variable.value = this.getDataVariable(variable);
|
|
154
|
+
let stringify = JSON.stringify(variable.value);
|
|
155
|
+
if (stringify.length > 50)
|
|
156
|
+
stringify = stringify.substring(0, 50);
|
|
157
|
+
if (!isNaN(variable.value.length)) {
|
|
158
|
+
stringify += ` (length: ${variable.value.length})`;
|
|
159
|
+
}
|
|
160
|
+
result.push(` ${variable.name.padEnd(30)} = ${stringify}`);
|
|
161
|
+
}
|
|
162
|
+
return result.join('\n');
|
|
130
163
|
}
|
|
131
|
-
|
|
132
|
-
return result.join('\n');
|
|
133
|
-
}
|
|
134
|
-
|
|
135
164
|
}
|
|
136
|
-
|
|
165
|
+
exports.NetCDFReader = NetCDFReader;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Header describing a NetDCF file
|
|
3
|
+
* @param recordDimension: Number with the length of record dimension
|
|
4
|
+
* @param dimensions: List of dimensions
|
|
5
|
+
* @param attributes: List of global attributes
|
|
6
|
+
* @param variables: List of variables
|
|
7
|
+
*/
|
|
8
|
+
export type NetCDFHeader = {
|
|
9
|
+
version: number;
|
|
10
|
+
recordDimension: NetCDFRecordDimension;
|
|
11
|
+
dimensions: NetCDFDimension[];
|
|
12
|
+
attributes: NetCDFAttribute[];
|
|
13
|
+
variables: NetCDFVariable[];
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Metadata for the record dimension
|
|
17
|
+
* @param length Number of elements in the record dimension
|
|
18
|
+
* @param id Id in the list of dimensions for the record dimension
|
|
19
|
+
* @param name name of the record dimension
|
|
20
|
+
* @param recordStep the record variables step size
|
|
21
|
+
*/
|
|
22
|
+
export type NetCDFRecordDimension = {
|
|
23
|
+
length: number;
|
|
24
|
+
id: number;
|
|
25
|
+
name: string;
|
|
26
|
+
recordStep: number;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* `dimensions` is an array of dimension objects:
|
|
30
|
+
* @param name name of the dimension
|
|
31
|
+
* @param size size of the dimension
|
|
32
|
+
* @param recordId: id of the dimension that has unlimited size or undefined,
|
|
33
|
+
* @param recordName: name of the dimension that has unlimited size
|
|
34
|
+
*/
|
|
35
|
+
export type NetCDFDimension = {
|
|
36
|
+
name: string;
|
|
37
|
+
size: number;
|
|
38
|
+
recordId: number;
|
|
39
|
+
recordName: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Number of recordStep and list of variables with:
|
|
43
|
+
* @param name String with the name of the variable
|
|
44
|
+
* @param dimensions Array with the dimension IDs of the variable
|
|
45
|
+
* @param attributes Array with the attributes of the variable
|
|
46
|
+
* @param type String with the type of the variable
|
|
47
|
+
* @param size Number with the size of the variable
|
|
48
|
+
* @param offset Number with the offset where of the variable begins
|
|
49
|
+
* @param record True if is a record variable, false otherwise (unlimited size)
|
|
50
|
+
*/
|
|
51
|
+
export type NetCDFVariable = {
|
|
52
|
+
name: string;
|
|
53
|
+
dimensions: [];
|
|
54
|
+
attributes: [];
|
|
55
|
+
type: string;
|
|
56
|
+
size: number;
|
|
57
|
+
offset: number;
|
|
58
|
+
record: boolean;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* @param name name of the attribute
|
|
62
|
+
* @param type type of the attribute
|
|
63
|
+
* @param value number or string with the value of the attribute
|
|
64
|
+
*/
|
|
65
|
+
export type NetCDFAttribute = {
|
|
66
|
+
name: string;
|
|
67
|
+
type: string;
|
|
68
|
+
value: string;
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=netcdf-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"netcdf-types.d.ts","sourceRoot":"","sources":["../../src/netcdfjs/netcdf-types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,qBAAqB,CAAC;IACvC,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,SAAS,EAAE,cAAc,EAAE,CAAC;CAC7B,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,EAAE,CAAC;IACf,UAAU,EAAE,EAAE,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { IOBuffer } from '../iobuffer/iobuffer';
|
|
2
|
+
import type { NetCDFRecordDimension, NetCDFVariable } from './netcdf-types';
|
|
3
|
+
/**
|
|
4
|
+
* Read data for the given non-record variable
|
|
5
|
+
* @param buffer - Buffer for the file data
|
|
6
|
+
* @param variable - Variable metadata
|
|
7
|
+
* @return Data of the element
|
|
8
|
+
*/
|
|
9
|
+
export declare function readNonRecord(buffer: IOBuffer, variable: NetCDFVariable): (string | number | number[] | Uint8Array)[];
|
|
10
|
+
/**
|
|
11
|
+
* Read data for the given record variable
|
|
12
|
+
* @param buffer - Buffer for the file data
|
|
13
|
+
* @param variable - Variable metadata
|
|
14
|
+
* @param recordDimension - Record dimension metadata
|
|
15
|
+
* @return - Data of the element
|
|
16
|
+
*/
|
|
17
|
+
export declare function readRecord(buffer: IOBuffer, variable: NetCDFVariable, recordDimension: NetCDFRecordDimension): (string | number | number[] | Uint8Array)[];
|
|
18
|
+
//# sourceMappingURL=read-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-data.d.ts","sourceRoot":"","sources":["../../src/netcdfjs/read-data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AACnD,OAAO,KAAK,EAAC,qBAAqB,EAAE,cAAc,EAAC,MAAM,gBAAgB,CAAC;AAK1E;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,QAAQ,EAChB,QAAQ,EAAE,cAAc,GACvB,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,UAAU,CAAC,EAAE,CAc7C;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,QAAQ,EAChB,QAAQ,EAAE,cAAc,EACxB,eAAe,EAAE,qBAAqB,GACrC,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,UAAU,CAAC,EAAE,CAoB7C"}
|