@loaders.gl/scientific 0.0.0-stage → 5.0.0-alpha.13

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.
Files changed (175) hide show
  1. package/README.md +21 -2
  2. package/dist/index.cjs +4313 -0
  3. package/dist/index.cjs.map +6 -0
  4. package/dist/index.d.ts +11 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +8 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/netcdf/bundled.cjs +1394 -0
  9. package/dist/netcdf/bundled.d.ts +2 -0
  10. package/dist/netcdf/bundled.d.ts.map +1 -0
  11. package/dist/netcdf/bundled.js +5 -0
  12. package/dist/netcdf/bundled.js.map +1 -0
  13. package/dist/netcdf/index.cjs +1394 -0
  14. package/dist/netcdf/index.cjs.map +6 -0
  15. package/dist/netcdf/index.d.ts +7 -0
  16. package/dist/netcdf/index.d.ts.map +1 -0
  17. package/dist/netcdf/index.js +8 -0
  18. package/dist/netcdf/index.js.map +1 -0
  19. package/dist/netcdf/iobuffer/iobuffer.d.ts +253 -0
  20. package/dist/netcdf/iobuffer/iobuffer.d.ts.map +1 -0
  21. package/dist/netcdf/iobuffer/iobuffer.js +450 -0
  22. package/dist/netcdf/iobuffer/iobuffer.js.map +1 -0
  23. package/dist/netcdf/netcdf-format.cjs +39 -0
  24. package/dist/netcdf/netcdf-format.d.ts +11 -0
  25. package/dist/netcdf/netcdf-format.d.ts.map +1 -0
  26. package/dist/netcdf/netcdf-format.js +14 -0
  27. package/dist/netcdf/netcdf-format.js.map +1 -0
  28. package/dist/netcdf/netcdf-loader-with-parser.cjs +995 -0
  29. package/dist/netcdf/netcdf-loader-with-parser.d.ts +60 -0
  30. package/dist/netcdf/netcdf-loader-with-parser.d.ts.map +1 -0
  31. package/dist/netcdf/netcdf-loader-with-parser.js +35 -0
  32. package/dist/netcdf/netcdf-loader-with-parser.js.map +1 -0
  33. package/dist/netcdf/netcdf-loader.cjs +84 -0
  34. package/dist/netcdf/netcdf-loader.d.ts +81 -0
  35. package/dist/netcdf/netcdf-loader.d.ts.map +1 -0
  36. package/dist/netcdf/netcdf-loader.js +41 -0
  37. package/dist/netcdf/netcdf-loader.js.map +1 -0
  38. package/dist/netcdf/netcdf-source-loader-types.cjs +78 -0
  39. package/dist/netcdf/netcdf-source-loader-types.d.ts +28 -0
  40. package/dist/netcdf/netcdf-source-loader-types.d.ts.map +1 -0
  41. package/dist/netcdf/netcdf-source-loader-types.js +32 -0
  42. package/dist/netcdf/netcdf-source-loader-types.js.map +1 -0
  43. package/dist/netcdf/netcdf-source-loader.cjs +1319 -0
  44. package/dist/netcdf/netcdf-source-loader.d.ts +59 -0
  45. package/dist/netcdf/netcdf-source-loader.d.ts.map +1 -0
  46. package/dist/netcdf/netcdf-source-loader.js +421 -0
  47. package/dist/netcdf/netcdf-source-loader.js.map +1 -0
  48. package/dist/netcdf/netcdfjs/netcdf-reader.d.ts +68 -0
  49. package/dist/netcdf/netcdfjs/netcdf-reader.d.ts.map +1 -0
  50. package/dist/netcdf/netcdfjs/netcdf-reader.js +172 -0
  51. package/dist/netcdf/netcdfjs/netcdf-reader.js.map +1 -0
  52. package/dist/netcdf/netcdfjs/netcdf-types.d.ts +70 -0
  53. package/dist/netcdf/netcdfjs/netcdf-types.d.ts.map +1 -0
  54. package/dist/netcdf/netcdfjs/netcdf-types.js +3 -0
  55. package/dist/netcdf/netcdfjs/netcdf-types.js.map +1 -0
  56. package/dist/netcdf/netcdfjs/read-data.d.ts +19 -0
  57. package/dist/netcdf/netcdfjs/read-data.d.ts.map +1 -0
  58. package/dist/netcdf/netcdfjs/read-data.js +51 -0
  59. package/dist/netcdf/netcdfjs/read-data.js.map +1 -0
  60. package/dist/netcdf/netcdfjs/read-header.d.ts +16 -0
  61. package/dist/netcdf/netcdfjs/read-header.d.ts.map +1 -0
  62. package/dist/netcdf/netcdfjs/read-header.js +227 -0
  63. package/dist/netcdf/netcdfjs/read-header.js.map +1 -0
  64. package/dist/netcdf/netcdfjs/read-type.d.ts +36 -0
  65. package/dist/netcdf/netcdfjs/read-type.d.ts.map +1 -0
  66. package/dist/netcdf/netcdfjs/read-type.js +135 -0
  67. package/dist/netcdf/netcdfjs/read-type.js.map +1 -0
  68. package/dist/netcdf/unbundled.cjs +1394 -0
  69. package/dist/netcdf/unbundled.d.ts +2 -0
  70. package/dist/netcdf/unbundled.d.ts.map +1 -0
  71. package/dist/netcdf/unbundled.js +5 -0
  72. package/dist/netcdf/unbundled.js.map +1 -0
  73. package/dist/netcdf.dev.js +3153 -0
  74. package/dist/netcdf.min.js +12 -0
  75. package/dist/zarr/bundled.d.ts +2 -0
  76. package/dist/zarr/bundled.d.ts.map +1 -0
  77. package/dist/zarr/bundled.js +5 -0
  78. package/dist/zarr/bundled.js.map +1 -0
  79. package/dist/zarr/geo-zarr-source-loader.d.ts +121 -0
  80. package/dist/zarr/geo-zarr-source-loader.d.ts.map +1 -0
  81. package/dist/zarr/geo-zarr-source-loader.js +692 -0
  82. package/dist/zarr/geo-zarr-source-loader.js.map +1 -0
  83. package/dist/zarr/index.cjs +14747 -0
  84. package/dist/zarr/index.cjs.map +6 -0
  85. package/dist/zarr/index.d.ts +11 -0
  86. package/dist/zarr/index.d.ts.map +1 -0
  87. package/dist/zarr/index.js +10 -0
  88. package/dist/zarr/index.js.map +1 -0
  89. package/dist/zarr/lib/consolidated-zarr.d.ts +31 -0
  90. package/dist/zarr/lib/consolidated-zarr.d.ts.map +1 -0
  91. package/dist/zarr/lib/consolidated-zarr.js +113 -0
  92. package/dist/zarr/lib/consolidated-zarr.js.map +1 -0
  93. package/dist/zarr/lib/load-zarr.d.ts +11 -0
  94. package/dist/zarr/lib/load-zarr.d.ts.map +1 -0
  95. package/dist/zarr/lib/load-zarr.js +22 -0
  96. package/dist/zarr/lib/load-zarr.js.map +1 -0
  97. package/dist/zarr/lib/spatial-multiscales.d.ts +14 -0
  98. package/dist/zarr/lib/spatial-multiscales.d.ts.map +1 -0
  99. package/dist/zarr/lib/spatial-multiscales.js +34 -0
  100. package/dist/zarr/lib/spatial-multiscales.js.map +1 -0
  101. package/dist/zarr/lib/utils.d.ts +28 -0
  102. package/dist/zarr/lib/utils.d.ts.map +1 -0
  103. package/dist/zarr/lib/utils.js +137 -0
  104. package/dist/zarr/lib/utils.js.map +1 -0
  105. package/dist/zarr/lib/zarr-data-cache.d.ts +13 -0
  106. package/dist/zarr/lib/zarr-data-cache.d.ts.map +1 -0
  107. package/dist/zarr/lib/zarr-data-cache.js +70 -0
  108. package/dist/zarr/lib/zarr-data-cache.js.map +1 -0
  109. package/dist/zarr/lib/zarr-pixel-source.d.ts +41 -0
  110. package/dist/zarr/lib/zarr-pixel-source.d.ts.map +1 -0
  111. package/dist/zarr/lib/zarr-pixel-source.js +97 -0
  112. package/dist/zarr/lib/zarr-pixel-source.js.map +1 -0
  113. package/dist/zarr/lib/zarrita-pixel-source.d.ts +40 -0
  114. package/dist/zarr/lib/zarrita-pixel-source.d.ts.map +1 -0
  115. package/dist/zarr/lib/zarrita-pixel-source.js +96 -0
  116. package/dist/zarr/lib/zarrita-pixel-source.js.map +1 -0
  117. package/dist/zarr/ome-zarr-source-loader.d.ts +195 -0
  118. package/dist/zarr/ome-zarr-source-loader.d.ts.map +1 -0
  119. package/dist/zarr/ome-zarr-source-loader.js +523 -0
  120. package/dist/zarr/ome-zarr-source-loader.js.map +1 -0
  121. package/dist/zarr/spatial-data-source.d.ts +95 -0
  122. package/dist/zarr/spatial-data-source.d.ts.map +1 -0
  123. package/dist/zarr/spatial-data-source.js +242 -0
  124. package/dist/zarr/spatial-data-source.js.map +1 -0
  125. package/dist/zarr/types.d.ts +105 -0
  126. package/dist/zarr/types.d.ts.map +1 -0
  127. package/dist/zarr/types.js +5 -0
  128. package/dist/zarr/types.js.map +1 -0
  129. package/dist/zarr/unbundled.d.ts +2 -0
  130. package/dist/zarr/unbundled.d.ts.map +1 -0
  131. package/dist/zarr/unbundled.js +5 -0
  132. package/dist/zarr/unbundled.js.map +1 -0
  133. package/dist/zarr/zarr-array-source.d.ts +102 -0
  134. package/dist/zarr/zarr-array-source.d.ts.map +1 -0
  135. package/dist/zarr/zarr-array-source.js +132 -0
  136. package/dist/zarr/zarr-array-source.js.map +1 -0
  137. package/dist/zarr/zarr-loader-types.d.ts +236 -0
  138. package/dist/zarr/zarr-loader-types.d.ts.map +1 -0
  139. package/dist/zarr/zarr-loader-types.js +128 -0
  140. package/dist/zarr/zarr-loader-types.js.map +1 -0
  141. package/dist/zarr.dev.js +16574 -0
  142. package/dist/zarr.min.js +79 -0
  143. package/package.json +62 -4
  144. package/src/index.ts +52 -0
  145. package/src/netcdf/bundled.ts +5 -0
  146. package/src/netcdf/index.ts +14 -0
  147. package/src/netcdf/iobuffer/iobuffer.ts +510 -0
  148. package/src/netcdf/netcdf-format.ts +16 -0
  149. package/src/netcdf/netcdf-loader-with-parser.ts +54 -0
  150. package/src/netcdf/netcdf-loader.ts +62 -0
  151. package/src/netcdf/netcdf-source-loader-types.ts +45 -0
  152. package/src/netcdf/netcdf-source-loader.ts +526 -0
  153. package/src/netcdf/netcdfjs/LICENSE +24 -0
  154. package/src/netcdf/netcdfjs/netcdf-reader.ts +196 -0
  155. package/src/netcdf/netcdfjs/netcdf-types.ts +75 -0
  156. package/src/netcdf/netcdfjs/read-data.ts +71 -0
  157. package/src/netcdf/netcdfjs/read-header.ts +277 -0
  158. package/src/netcdf/netcdfjs/read-type.ts +147 -0
  159. package/src/netcdf/unbundled.ts +5 -0
  160. package/src/zarr/bundled.ts +5 -0
  161. package/src/zarr/geo-zarr-source-loader.ts +998 -0
  162. package/src/zarr/index.ts +60 -0
  163. package/src/zarr/lib/consolidated-zarr.ts +190 -0
  164. package/src/zarr/lib/load-zarr.ts +31 -0
  165. package/src/zarr/lib/spatial-multiscales.ts +47 -0
  166. package/src/zarr/lib/utils.ts +162 -0
  167. package/src/zarr/lib/zarr-data-cache.ts +91 -0
  168. package/src/zarr/lib/zarr-pixel-source.ts +134 -0
  169. package/src/zarr/lib/zarrita-pixel-source.ts +141 -0
  170. package/src/zarr/ome-zarr-source-loader.ts +837 -0
  171. package/src/zarr/spatial-data-source.ts +370 -0
  172. package/src/zarr/types.ts +129 -0
  173. package/src/zarr/unbundled.ts +5 -0
  174. package/src/zarr/zarr-array-source.ts +225 -0
  175. package/src/zarr/zarr-loader-types.ts +166 -0
@@ -0,0 +1,172 @@
1
+ // SPDX-License-Identifier: MIT
2
+ import { IOBuffer } from "../iobuffer/iobuffer.js";
3
+ import { readNetCDFHeader } from "./read-header.js";
4
+ import { readRecord, readNonRecord } from "./read-data.js";
5
+ /**
6
+ * Reads a NetCDF v3.x file
7
+ * https://www.unidata.ucar.edu/software/netcdf/docs/file_format_specifications.html
8
+ * @param {ArrayBuffer} data - ArrayBuffer or any Typed Array (including Node.js' Buffer from v4) with the data
9
+ * @constructor
10
+ */
11
+ export class NetCDFReader {
12
+ header;
13
+ buffer;
14
+ constructor(data) {
15
+ const buffer = new 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 = readNetCDFHeader(buffer, version);
29
+ this.buffer = buffer;
30
+ }
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';
39
+ }
40
+ /**
41
+ * Get metadata for the record dimension
42
+ */
43
+ get recordDimension() {
44
+ return this.header.recordDimension;
45
+ }
46
+ /**
47
+ * Get list of dimensions (each with `name` and `size`)
48
+ */
49
+ get dimensions() {
50
+ return this.header.dimensions;
51
+ }
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;
60
+ }
61
+ /**
62
+ * Get list of variables
63
+ */
64
+ get variables() {
65
+ return this.header.variables;
66
+ }
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;
75
+ }
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;
86
+ }
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
+ let errorOutput;
128
+ if (typeof variableName === 'string') {
129
+ errorOutput = variableName;
130
+ }
131
+ else if (typeof variableName === 'object') {
132
+ errorOutput = JSON.stringify(variableName);
133
+ }
134
+ throw new Error(`NetCDF: variable not found: ${errorOutput}`);
135
+ }
136
+ // go to the offset position
137
+ this.buffer.seek(variable.offset);
138
+ if (variable.record) {
139
+ // record variable case
140
+ return readRecord(this.buffer, variable, this.header.recordDimension, this.header.dimensions);
141
+ }
142
+ // non-record variable case
143
+ return readNonRecord(this.buffer, variable);
144
+ }
145
+ toString() {
146
+ const result = [];
147
+ result.push('DIMENSIONS');
148
+ for (const dimension of this.dimensions) {
149
+ result.push(` ${dimension.name.padEnd(30)} = size: ${dimension.size}`);
150
+ }
151
+ result.push('');
152
+ result.push('GLOBAL ATTRIBUTES');
153
+ for (const attribute of this.attributes) {
154
+ result.push(` ${attribute.name.padEnd(30)} = ${attribute.value}`);
155
+ }
156
+ const variables = JSON.parse(JSON.stringify(this.variables));
157
+ result.push('');
158
+ result.push('VARIABLES:');
159
+ for (const variable of variables) {
160
+ variable.value = this.getDataVariable(variable);
161
+ let stringify = JSON.stringify(variable.value);
162
+ if (stringify.length > 50)
163
+ stringify = stringify.substring(0, 50);
164
+ if (!Number.isNaN(variable.value.length)) {
165
+ stringify += ` (length: ${variable.value.length})`;
166
+ }
167
+ result.push(` ${variable.name.padEnd(30)} = ${stringify}`);
168
+ }
169
+ return result.join('\n');
170
+ }
171
+ }
172
+ //# sourceMappingURL=netcdf-reader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"netcdf-reader.js","sourceRoot":"","sources":["../../../src/netcdf/netcdfjs/netcdf-reader.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B,OAAO,EAAC,QAAQ,EAAC,gCAA6B;AAQ9C,OAAO,EAAC,gBAAgB,EAAC,yBAAsB;AAC/C,OAAO,EAAC,UAAU,EAAE,aAAa,EAAC,uBAAoB;AAEtD;;;;;GAKG;AACH,MAAM,OAAO,YAAY;IAChB,MAAM,CAAe;IACrB,MAAM,CAAW;IAExB,YAAY,IAAI;QACd,MAAM,MAAM,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC;QAClC,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C,KAAK,EAAE,CAAC,CAAC;QACrE,CAAC;QAED,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;QAC7D,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAChB,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC1B,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;YAChD,IAAI,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAC/C,IAAI,SAAS,CAAC,MAAM,GAAG,EAAE;gBAAE,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAClE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;gBACzC,SAAS,IAAI,aAAa,QAAQ,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;YACrD,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,KAAK,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,SAAS,EAAE,CAAC,CAAC;QAC9D,CAAC;QACD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;CACF"}
@@ -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: number[];
54
+ attributes: NetCDFAttribute[];
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/netcdf/netcdfjs/netcdf-types.ts"],"names":[],"mappings":"AAEA;;;;;;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,MAAM,EAAE,CAAC;IACrB,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,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"}
@@ -0,0 +1,3 @@
1
+ // SPDX-License-Identifier: MIT
2
+ export {};
3
+ //# sourceMappingURL=netcdf-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"netcdf-types.js","sourceRoot":"","sources":["../../../src/netcdf/netcdfjs/netcdf-types.ts"],"names":[],"mappings":"AAAA,+BAA+B"}
@@ -0,0 +1,19 @@
1
+ import type { IOBuffer } from "../iobuffer/iobuffer.js";
2
+ import type { NetCDFDimension, NetCDFRecordDimension, NetCDFVariable } from "./netcdf-types.js";
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
+ * @param dimensions - Declared file dimensions used to exclude record padding
16
+ * @return - Data of the element
17
+ */
18
+ export declare function readRecord(buffer: IOBuffer, variable: NetCDFVariable, recordDimension: NetCDFRecordDimension, dimensions: NetCDFDimension[]): (string | number | number[] | Uint8Array)[];
19
+ //# sourceMappingURL=read-data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-data.d.ts","sourceRoot":"","sources":["../../../src/netcdf/netcdfjs/read-data.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,QAAQ,EAAC,gCAA6B;AACnD,OAAO,KAAK,EAAC,eAAe,EAAE,qBAAqB,EAAE,cAAc,EAAC,0BAAuB;AAK3F;;;;;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;;;;;;;GAOG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,QAAQ,EAChB,QAAQ,EAAE,cAAc,EACxB,eAAe,EAAE,qBAAqB,EACtC,UAAU,EAAE,eAAe,EAAE,GAC5B,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,UAAU,CAAC,EAAE,CAwB7C"}
@@ -0,0 +1,51 @@
1
+ // SPDX-License-Identifier: MIT
2
+ import { readType, str2num, num2bytes } from "./read-type.js";
3
+ // const STREAMING = 4294967295;
4
+ /**
5
+ * Read data for the given non-record variable
6
+ * @param buffer - Buffer for the file data
7
+ * @param variable - Variable metadata
8
+ * @return Data of the element
9
+ */
10
+ export function readNonRecord(buffer, variable) {
11
+ // variable type
12
+ const type = str2num(variable.type);
13
+ // size of the data
14
+ const size = variable.size / num2bytes(type);
15
+ // iterates over the data
16
+ const data = new Array(size);
17
+ for (let i = 0; i < size; i++) {
18
+ data[i] = readType(buffer, type, 1);
19
+ }
20
+ return data;
21
+ }
22
+ /**
23
+ * Read data for the given record variable
24
+ * @param buffer - Buffer for the file data
25
+ * @param variable - Variable metadata
26
+ * @param recordDimension - Record dimension metadata
27
+ * @param dimensions - Declared file dimensions used to exclude record padding
28
+ * @return - Data of the element
29
+ */
30
+ export function readRecord(buffer, variable, recordDimension, dimensions) {
31
+ // variable type
32
+ const type = str2num(variable.type);
33
+ // NetCDF stores each record variable on a four-byte boundary. `variable.size` includes that
34
+ // padding, so derive the logical element count from the declared non-record dimensions.
35
+ const width = variable.dimensions
36
+ .filter(dimensionId => dimensionId !== recordDimension.id)
37
+ .reduce((elementCount, dimensionId) => elementCount * dimensions[dimensionId].size, 1);
38
+ // size of the data
39
+ // TODO streaming data
40
+ const size = recordDimension.length;
41
+ // iterates over the data
42
+ const data = new Array(size);
43
+ const step = recordDimension.recordStep;
44
+ for (let i = 0; i < size; i++) {
45
+ const currentOffset = buffer.offset;
46
+ data[i] = readType(buffer, type, width);
47
+ buffer.seek(currentOffset + step);
48
+ }
49
+ return data;
50
+ }
51
+ //# sourceMappingURL=read-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-data.js","sourceRoot":"","sources":["../../../src/netcdf/netcdfjs/read-data.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAI/B,OAAO,EAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAC,uBAAoB;AAEzD,gCAAgC;AAEhC;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAC3B,MAAgB,EAChB,QAAwB;IAExB,gBAAgB;IAChB,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAEpC,mBAAmB;IACnB,MAAM,IAAI,GAAG,QAAQ,CAAC,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CAAC,CAAC;QACxC,MAAM,CAAC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { IOBuffer } from "../iobuffer/iobuffer.js";
2
+ import type { NetCDFHeader } from "./netcdf-types.js";
3
+ /**
4
+ * Read the header of the file
5
+ * @param buffer - Buffer for the file data
6
+ * @param version - Version of the file
7
+ * @return - Header
8
+ */
9
+ export declare function readNetCDFHeader(buffer: IOBuffer, version: number): NetCDFHeader;
10
+ /**
11
+ * Reads the name
12
+ * @param buffer - Buffer for the file data
13
+ * @return Name
14
+ */
15
+ export declare function readName(buffer: IOBuffer): string;
16
+ //# sourceMappingURL=read-header.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-header.d.ts","sourceRoot":"","sources":["../../../src/netcdf/netcdfjs/read-header.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,QAAQ,EAAC,gCAA6B;AACnD,OAAO,KAAK,EAAC,YAAY,EAAmD,0BAAuB;AAWnG;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,YAAY,CA4BhF;AA2MD;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,MAAM,CAWjD"}
@@ -0,0 +1,227 @@
1
+ // SPDX-License-Identifier: MIT
2
+ import { readType, num2str } from "./read-type.js";
3
+ // Grammar constants
4
+ const ZERO = 0;
5
+ const NC_DIMENSION = 10;
6
+ const NC_VARIABLE = 11;
7
+ const NC_ATTRIBUTE = 12;
8
+ const NC_UNLIMITED = 0;
9
+ /**
10
+ * Read the header of the file
11
+ * @param buffer - Buffer for the file data
12
+ * @param version - Version of the file
13
+ * @return - Header
14
+ */
15
+ export function readNetCDFHeader(buffer, version) {
16
+ // Length of record dimension
17
+ // sum of the varSize's of all the record variables.
18
+ const recordDimensionLength = buffer.readUint32();
19
+ // List of dimensions
20
+ const dimList = readDimensionsList(buffer);
21
+ // List of global attributes
22
+ const attributes = readAttributesList(buffer);
23
+ // List of variables
24
+ const variableList = readVariablesList(buffer, dimList.recordId, version);
25
+ const header = {
26
+ version,
27
+ recordDimension: {
28
+ length: recordDimensionLength,
29
+ id: dimList.recordId, // id of the unlimited dimension
30
+ name: dimList.recordName, // name of the unlimited dimension
31
+ recordStep: variableList.recordStep
32
+ },
33
+ dimensions: dimList.dimensions,
34
+ variables: variableList.variables,
35
+ attributes
36
+ };
37
+ return header;
38
+ }
39
+ /**
40
+ * Read list of dimensions
41
+ * @ignore
42
+ * @param {IOBuffer} buffer - Buffer for the file data
43
+ */
44
+ function readDimensionsList(buffer) {
45
+ const dimList = buffer.readUint32();
46
+ if (dimList === ZERO) {
47
+ if (buffer.readUint32() !== ZERO) {
48
+ throw new Error('NetCDF: wrong empty tag for list of dimensions');
49
+ }
50
+ // TODO - is this empty dimension list supported / recoverable?
51
+ return {
52
+ recordId: 0,
53
+ recordName: '',
54
+ dimensions: []
55
+ };
56
+ }
57
+ if (dimList !== NC_DIMENSION) {
58
+ throw new Error('NetCDF: wrong tag for list of dimensions');
59
+ }
60
+ // Length of dimensions
61
+ const dimensionSize = buffer.readUint32();
62
+ const dimensions = new Array(dimensionSize);
63
+ let recordId;
64
+ let recordName;
65
+ for (let dim = 0; dim < dimensionSize; dim++) {
66
+ // Read name
67
+ const name = readName(buffer);
68
+ // Read dimension size
69
+ const size = buffer.readUint32();
70
+ if (size === NC_UNLIMITED) {
71
+ // in netcdf 3 one field can be of size unlimmited
72
+ recordId = dim;
73
+ recordName = name;
74
+ }
75
+ dimensions[dim] = {
76
+ name,
77
+ size
78
+ };
79
+ }
80
+ return {
81
+ dimensions,
82
+ recordId,
83
+ recordName
84
+ };
85
+ }
86
+ /**
87
+ * List of attributes
88
+ * @ignore
89
+ * @param buffer - Buffer for the file data
90
+ * @return List of attributes with:
91
+ */
92
+ function readAttributesList(buffer) {
93
+ const gAttList = buffer.readUint32();
94
+ if (gAttList === ZERO) {
95
+ if (buffer.readUint32() !== ZERO) {
96
+ throw new Error('NetCDF: wrong empty tag for list of attributes');
97
+ }
98
+ return [];
99
+ }
100
+ if (gAttList !== NC_ATTRIBUTE) {
101
+ throw new Error('NetCDF: wrong tag for list of attributes');
102
+ }
103
+ // Length of attributes
104
+ const attributeSize = buffer.readUint32();
105
+ const attributes = new Array(attributeSize);
106
+ for (let gAtt = 0; gAtt < attributeSize; gAtt++) {
107
+ // Read name
108
+ const name = readName(buffer);
109
+ // Read type
110
+ const type = buffer.readUint32();
111
+ if (type < 1 || type > 6) {
112
+ throw new Error(`NetCDF: non valid type ${type}`);
113
+ }
114
+ // Read attribute
115
+ const size = buffer.readUint32();
116
+ const value = readType(buffer, type, size);
117
+ // Apply padding
118
+ padding(buffer);
119
+ attributes[gAtt] = {
120
+ name,
121
+ type: num2str(type),
122
+ value
123
+ };
124
+ }
125
+ return attributes;
126
+ }
127
+ /**
128
+ * List of variables
129
+ * @param buffer - Buffer for the file data
130
+ * @param recordId - Id of the unlimited dimension (also called record dimension)
131
+ * This value may be undefined if there is no unlimited dimension
132
+ * @param {number} version - Version of the file
133
+ */
134
+ // eslint-disable-next-line max-statements, complexity
135
+ function readVariablesList(buffer, recordId, version) {
136
+ const varList = buffer.readUint32();
137
+ let recordStep = 0;
138
+ if (varList === ZERO) {
139
+ if (buffer.readUint32() !== ZERO) {
140
+ throw new Error('NetCDF: wrong empty tag for list of variables');
141
+ }
142
+ return {
143
+ recordStep,
144
+ variables: []
145
+ };
146
+ }
147
+ if (varList !== NC_VARIABLE) {
148
+ throw new Error('NetCDF: wrong tag for list of variables');
149
+ }
150
+ // Length of variables
151
+ const variableSize = buffer.readUint32();
152
+ const variables = new Array(variableSize);
153
+ for (let v = 0; v < variableSize; v++) {
154
+ // Read name
155
+ const name = readName(buffer);
156
+ // Read dimensionality of the variable
157
+ const dimensionality = buffer.readUint32();
158
+ // Index into the list of dimensions
159
+ const dimensionsIds = new Array(dimensionality);
160
+ for (let dim = 0; dim < dimensionality; dim++) {
161
+ dimensionsIds[dim] = buffer.readUint32();
162
+ }
163
+ // Read variables size
164
+ const attributes = readAttributesList(buffer);
165
+ // Read type
166
+ const type = buffer.readUint32();
167
+ if (type < 1 && type > 6) {
168
+ throw new Error(`NetCDF: non valid type ${type}`);
169
+ }
170
+ // Read variable size
171
+ // The 32-bit varSize field is not large enough to contain the size of variables that require
172
+ // more than 2^32 - 4 bytes, so 2^32 - 1 is used in the varSize field for such variables.
173
+ const varSize = buffer.readUint32();
174
+ // Read offset
175
+ let offset = buffer.readUint32();
176
+ if (version === 2) {
177
+ if (offset > 0) {
178
+ throw new Error('NetCDF: offsets larger than 4GB not supported');
179
+ }
180
+ offset = buffer.readUint32();
181
+ }
182
+ let record = false;
183
+ // Count amount of record variables
184
+ if (typeof recordId !== 'undefined' && dimensionsIds[0] === recordId) {
185
+ recordStep += varSize;
186
+ record = true;
187
+ }
188
+ variables[v] = {
189
+ name,
190
+ dimensions: dimensionsIds,
191
+ attributes,
192
+ type: num2str(type),
193
+ size: varSize,
194
+ offset,
195
+ record
196
+ };
197
+ }
198
+ return {
199
+ variables,
200
+ recordStep
201
+ };
202
+ }
203
+ // HELPERS
204
+ /**
205
+ * Reads the name
206
+ * @param buffer - Buffer for the file data
207
+ * @return Name
208
+ */
209
+ export function readName(buffer) {
210
+ // Read name
211
+ const nameLength = buffer.readUint32();
212
+ const name = buffer.readChars(nameLength);
213
+ // validate name
214
+ // TODO
215
+ // Apply padding
216
+ padding(buffer);
217
+ return name;
218
+ }
219
+ /**
220
+ * Moves 1, 2, or 3 bytes to next 4-byte boundary
221
+ */
222
+ function padding(buffer) {
223
+ if (buffer.offset % 4 !== 0) {
224
+ buffer.skip(4 - (buffer.offset % 4));
225
+ }
226
+ }
227
+ //# sourceMappingURL=read-header.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-header.js","sourceRoot":"","sources":["../../../src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C;QAC5B,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { IOBuffer } from "../iobuffer/iobuffer.js";
2
+ export declare const TYPES: {
3
+ BYTE: number;
4
+ CHAR: number;
5
+ SHORT: number;
6
+ INT: number;
7
+ FLOAT: number;
8
+ DOUBLE: number;
9
+ };
10
+ /**
11
+ * Given a type and a size reads the next element
12
+ * @param buffer - Buffer for the file data
13
+ * @param type - Type of the data to read
14
+ * @param size - Size of the element to read
15
+ * @return
16
+ */
17
+ export declare function readType(buffer: IOBuffer, type: number, size: number): string | number | number[] | Uint8Array;
18
+ /**
19
+ * Parse a number into their respective type
20
+ * @param type - integer that represents the type
21
+ * @return parsed value of the type
22
+ */
23
+ export declare function num2str(type: number): string;
24
+ /**
25
+ * Parse a number type identifier to his size in bytes
26
+ * @param type - integer that represents the type
27
+ * @return size of the type
28
+ */
29
+ export declare function num2bytes(type: number): number;
30
+ /**
31
+ * Reverse search of num2str
32
+ * @param type string that represents the type
33
+ * @return parsed value of the type
34
+ */
35
+ export declare function str2num(type: string): number;
36
+ //# sourceMappingURL=read-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-type.d.ts","sourceRoot":"","sources":["../../../src/netcdf/netcdfjs/read-type.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,QAAQ,EAAC,gCAA6B;AAE9C,eAAO,MAAM,KAAK;;;;;;;CAOjB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACtB,MAAM,EAAE,QAAQ,EAChB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,UAAU,CAkBzC;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAkB5C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAkB9C;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAkB5C"}