@loaders.gl/netcdf 4.0.0-alpha.9 → 4.0.0-beta.2

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.
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports._typecheckNetCDFWorkerLoader = exports._typecheckNetCDFLoader = exports.NetCDFWorkerLoader = exports.NetCDFLoader = void 0;
7
+ exports.NetCDFWorkerLoader = exports.NetCDFLoader = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
9
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
@@ -14,7 +14,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
14
14
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
15
15
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
16
16
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
17
- var VERSION = typeof "4.0.0-alpha.9" !== 'undefined' ? "4.0.0-alpha.9" : 'latest';
17
+ var VERSION = typeof "4.0.0-beta.2" !== 'undefined' ? "4.0.0-beta.2" : 'latest';
18
18
  var NetCDFWorkerLoader = {
19
19
  name: 'NetCDF',
20
20
  id: 'mvt',
@@ -74,8 +74,4 @@ function parseNetCDF(arrayBuffer, options) {
74
74
  data: variables
75
75
  };
76
76
  }
77
- var _typecheckNetCDFWorkerLoader = NetCDFWorkerLoader;
78
- exports._typecheckNetCDFWorkerLoader = _typecheckNetCDFWorkerLoader;
79
- var _typecheckNetCDFLoader = NetCDFLoader;
80
- exports._typecheckNetCDFLoader = _typecheckNetCDFLoader;
81
77
  //# sourceMappingURL=netcdf-loader.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"netcdf-loader.js","names":["_netcdfReader","require","_createForOfIteratorHelper","o","allowArrayLike","it","Symbol","iterator","Array","isArray","_unsupportedIterableToArray","length","i","F","s","n","done","value","e","_e","f","TypeError","normalCompletion","didErr","err","call","step","next","_e2","return","minLen","_arrayLikeToArray","Object","prototype","toString","slice","constructor","name","from","test","arr","len","arr2","ownKeys","object","enumerableOnly","keys","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","arguments","source","forEach","key","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","VERSION","NetCDFWorkerLoader","id","module","version","extensions","mimeTypes","category","options","netcdf","loadVariables","exports","NetCDFLoader","parse","_parse","_asyncToGenerator2","_regenerator","mark","_callee","arrayBuffer","wrap","_callee$","_context","prev","abrupt","parseNetCDF","stop","_x","_x2","binary","_options$netcdf","reader","NetCDFReader","variables","loadData","_iterator","_step","variable","getDataVariable","loaderData","header","data","_typecheckNetCDFWorkerLoader","_typecheckNetCDFLoader"],"sources":["../../src/netcdf-loader.ts"],"sourcesContent":["import type {Loader, LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';\nimport type {NetCDFHeader} from './netcdfjs/netcdf-types';\nimport {NetCDFReader} from './netcdfjs/netcdf-reader';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type NetCDF = {\n loaderData: NetCDFHeader;\n data: {[variableName: string]: any[][]};\n};\n\nexport type NetCDFLoaderOptions = LoaderOptions & {\n netcdf?: {\n loadData?: boolean;\n };\n};\n\n/**\n * Worker loader for NETCDF\n */\nexport const NetCDFWorkerLoader = {\n name: 'NetCDF',\n id: 'mvt',\n module: 'mvt',\n version: VERSION,\n extensions: ['cdf', 'nc'],\n mimeTypes: [\n 'application/netcdf',\n 'application/x-netcdf'\n // 'application/octet-stream'\n ],\n category: 'image',\n options: {\n netcdf: {\n loadVariables: false\n }\n }\n};\n\n/**\n * Loader for the NetCDF format\n */\nexport const NetCDFLoader = {\n ...NetCDFWorkerLoader,\n parse: async (arrayBuffer, options) => parseNetCDF(arrayBuffer, options),\n binary: true\n};\n\nfunction parseNetCDF(arrayBuffer: ArrayBuffer, options?: NetCDFLoaderOptions): NetCDF {\n const reader = new NetCDFReader(arrayBuffer);\n const variables: {[variableName: string]: any[][]} = {};\n if (options?.netcdf?.loadData) {\n for (const variable of reader.variables) {\n variables[variable.name] = reader.getDataVariable(variable);\n }\n }\n return {\n loaderData: reader.header,\n data: variables\n };\n}\n\n// Type tests\nexport const _typecheckNetCDFWorkerLoader: Loader = NetCDFWorkerLoader;\nexport const _typecheckNetCDFLoader: LoaderWithParser = NetCDFLoader;\n"],"mappings":";;;;;;;;;;AAEA,IAAAA,aAAA,GAAAC,OAAA;AAAsD,SAAAC,2BAAAC,CAAA,EAAAC,cAAA,QAAAC,EAAA,UAAAC,MAAA,oBAAAH,CAAA,CAAAG,MAAA,CAAAC,QAAA,KAAAJ,CAAA,qBAAAE,EAAA,QAAAG,KAAA,CAAAC,OAAA,CAAAN,CAAA,MAAAE,EAAA,GAAAK,2BAAA,CAAAP,CAAA,MAAAC,cAAA,IAAAD,CAAA,WAAAA,CAAA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ClB,OAAA,CAAAC,YAAA,GAAAA,YAAA;AAEF,SAASa,WAAWA,CAACN,WAAwB,EAAEX,OAA6B,EAAU;EAAA,IAAAsB,eAAA;EACpF,IAAMC,MAAM,GAAG,IAAIC,0BAAY,CAACb,WAAW,CAAC;EAC5C,IAAMc,SAA4C,GAAG,CAAC,CAAC;EACvD,IAAIzB,OAAO,aAAPA,OAAO,gBAAAsB,eAAA,GAAPtB,OAAO,CAAEC,MAAM,cAAAqB,eAAA,eAAfA,eAAA,CAAiBI,QAAQ,EAAE;IAAA,IAAAC,SAAA,GAAAnG,0BAAA,CACN+F,MAAM,CAACE,SAAS;MAAAG,KAAA;IAAA;MAAvC,KAAAD,SAAA,CAAAvF,CAAA,MAAAwF,KAAA,GAAAD,SAAA,CAAAtF,CAAA,IAAAC,IAAA,GAAyC;QAAA,IAA9BuF,QAAQ,GAAAD,KAAA,CAAArF,KAAA;QACjBkF,SAAS,CAACI,QAAQ,CAAClE,IAAI,CAAC,GAAG4D,MAAM,CAACO,eAAe,CAACD,QAAQ,CAAC;MAC7D;IAAC,SAAA/E,GAAA;MAAA6E,SAAA,CAAAnF,CAAA,CAAAM,GAAA;IAAA;MAAA6E,SAAA,CAAAjF,CAAA;IAAA;EACH;EACA,OAAO;IACLqF,UAAU,EAAER,MAAM,CAACS,MAAM;IACzBC,IAAI,EAAER;EACR,CAAC;AACH;AAGO,IAAMS,4BAAoC,GAAGzC,kBAAkB;AAACU,OAAA,CAAA+B,4BAAA,GAAAA,4BAAA;AAChE,IAAMC,sBAAwC,GAAG/B,YAAY;AAACD,OAAA,CAAAgC,sBAAA,GAAAA,sBAAA"}
1
+ {"version":3,"file":"netcdf-loader.js","names":["_netcdfReader","require","_createForOfIteratorHelper","o","allowArrayLike","it","Symbol","iterator","Array","isArray","_unsupportedIterableToArray","length","i","F","s","n","done","value","e","_e","f","TypeError","normalCompletion","didErr","err","call","step","next","_e2","return","minLen","_arrayLikeToArray","Object","prototype","toString","slice","constructor","name","from","test","arr","len","arr2","ownKeys","object","enumerableOnly","keys","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","arguments","source","forEach","key","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","VERSION","NetCDFWorkerLoader","id","module","version","extensions","mimeTypes","category","options","netcdf","loadVariables","exports","NetCDFLoader","parse","_parse","_asyncToGenerator2","_regenerator","mark","_callee","arrayBuffer","wrap","_callee$","_context","prev","abrupt","parseNetCDF","stop","_x","_x2","binary","_options$netcdf","reader","NetCDFReader","variables","loadData","_iterator","_step","variable","getDataVariable","loaderData","header","data"],"sources":["../../src/netcdf-loader.ts"],"sourcesContent":["import type {Loader, LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';\nimport type {NetCDFHeader} from './netcdfjs/netcdf-types';\nimport {NetCDFReader} from './netcdfjs/netcdf-reader';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type NetCDF = {\n loaderData: NetCDFHeader;\n data: {[variableName: string]: any[][]};\n};\n\nexport type NetCDFLoaderOptions = LoaderOptions & {\n netcdf?: {\n loadData?: boolean;\n loadVariables?: boolean;\n };\n};\n\n/**\n * Worker loader for NETCDF\n */\nexport const NetCDFWorkerLoader: Loader<NetCDF, never, NetCDFLoaderOptions> = {\n name: 'NetCDF',\n id: 'mvt',\n module: 'mvt',\n version: VERSION,\n extensions: ['cdf', 'nc'],\n mimeTypes: [\n 'application/netcdf',\n 'application/x-netcdf'\n // 'application/octet-stream'\n ],\n category: 'image',\n options: {\n netcdf: {\n loadVariables: false\n }\n }\n};\n\n/**\n * Loader for the NetCDF format\n */\nexport const NetCDFLoader: LoaderWithParser<NetCDF, never, NetCDFLoaderOptions> = {\n ...NetCDFWorkerLoader,\n parse: async (arrayBuffer, options) => parseNetCDF(arrayBuffer, options),\n binary: true\n};\n\nfunction parseNetCDF(arrayBuffer: ArrayBuffer, options?: NetCDFLoaderOptions): NetCDF {\n const reader = new NetCDFReader(arrayBuffer);\n const variables: {[variableName: string]: any[][]} = {};\n if (options?.netcdf?.loadData) {\n for (const variable of reader.variables) {\n variables[variable.name] = reader.getDataVariable(variable);\n }\n }\n return {\n loaderData: reader.header,\n data: variables\n };\n}\n"],"mappings":";;;;;;;;;;AAEA,IAAAA,aAAA,GAAAC,OAAA;AAAsD,SAAAC,2BAAAC,CAAA,EAAAC,cAAA,QAAAC,EAAA,UAAAC,MAAA,oBAAAH,CAAA,CAAAG,MAAA,CAAAC,QAAA,KAAAJ,CAAA,qBAAAE,EAAA,QAAAG,KAAA,CAAAC,OAAA,CAAAN,CAAA,MAAAE,EAAA,GAAAK,2BAAA,CAAAP,CAAA,MAAAC,cAAA,IAAAD,CAAA,WAAAA,CAAA,CAAAQ,MAAA,qBAAAN,EAAA,EAAAF,CAAA,GAAAE,EAAA,MAAAO,CAAA,UAAAC,CAAA,YAAAA,EAAA,eAAAC,CAAA,EAAAD,CAAA,EAAAE,CAAA,WAAAA,EAAA,QAAAH,CAAA,IAAAT,CAAA,CAAAQ,MAAA,WAAAK,IAAA,mBAAAA,IAAA,SAAAC,KAAA,EAAAd,CAAA,CAAAS,CAAA,UAAAM,CAAA,WAAAA,EAAAC,EAAA,UAAAA,EAAA,KAAAC,CAAA,EAAAP,CAAA,gBAAAQ,SAAA,iJAAAC,gBAAA,SAAAC,MAAA,UAAAC,GAAA,WAAAV,CAAA,WAAAA,EAAA,IAAAT,EAAA,GAAAA,EAAA,CAAAoB,IAAA,CAAAtB,CAAA,MAAAY,CAAA,WAAAA,EAAA,QAAAW,IAAA,GAAArB,EAAA,CAAAsB,IAAA,IAAAL,gBAAA,GAAAI,IAAA,CAAAV,IAAA,SAAAU,IAAA,KAAAR,CAAA,WAAAA,EAAAU,GAAA,IAAAL,MAAA,SAAAC,GAAA,GAAAI,GAAA,KAAAR,CAAA,WAAAA,EAAA,e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AAA,CAAAnF,CAAA,CAAAM,GAAA;IAAA;MAAA6E,SAAA,CAAAjF,CAAA;IAAA;EACH;EACA,OAAO;IACLqF,UAAU,EAAER,MAAM,CAACS,MAAM;IACzBC,IAAI,EAAER;EACR,CAAC;AACH"}
@@ -1,5 +1,5 @@
1
1
  import { NetCDFReader } from './netcdfjs/netcdf-reader';
2
- const VERSION = typeof "4.0.0-alpha.9" !== 'undefined' ? "4.0.0-alpha.9" : 'latest';
2
+ const VERSION = typeof "4.0.0-beta.2" !== 'undefined' ? "4.0.0-beta.2" : 'latest';
3
3
  export const NetCDFWorkerLoader = {
4
4
  name: 'NetCDF',
5
5
  id: 'mvt',
@@ -33,6 +33,4 @@ function parseNetCDF(arrayBuffer, options) {
33
33
  data: variables
34
34
  };
35
35
  }
36
- export const _typecheckNetCDFWorkerLoader = NetCDFWorkerLoader;
37
- export const _typecheckNetCDFLoader = NetCDFLoader;
38
36
  //# sourceMappingURL=netcdf-loader.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"netcdf-loader.js","names":["NetCDFReader","VERSION","NetCDFWorkerLoader","name","id","module","version","extensions","mimeTypes","category","options","netcdf","loadVariables","NetCDFLoader","parse","arrayBuffer","parseNetCDF","binary","_options$netcdf","reader","variables","loadData","variable","getDataVariable","loaderData","header","data","_typecheckNetCDFWorkerLoader","_typecheckNetCDFLoader"],"sources":["../../src/netcdf-loader.ts"],"sourcesContent":["import type {Loader, LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';\nimport type {NetCDFHeader} from './netcdfjs/netcdf-types';\nimport {NetCDFReader} from './netcdfjs/netcdf-reader';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type NetCDF = {\n loaderData: NetCDFHeader;\n data: {[variableName: string]: any[][]};\n};\n\nexport type NetCDFLoaderOptions = LoaderOptions & {\n netcdf?: {\n loadData?: boolean;\n };\n};\n\n/**\n * Worker loader for NETCDF\n */\nexport const NetCDFWorkerLoader = {\n name: 'NetCDF',\n id: 'mvt',\n module: 'mvt',\n version: VERSION,\n extensions: ['cdf', 'nc'],\n mimeTypes: [\n 'application/netcdf',\n 'application/x-netcdf'\n // 'application/octet-stream'\n ],\n category: 'image',\n options: {\n netcdf: {\n loadVariables: false\n }\n }\n};\n\n/**\n * Loader for the NetCDF format\n */\nexport const NetCDFLoader = {\n ...NetCDFWorkerLoader,\n parse: async (arrayBuffer, options) => parseNetCDF(arrayBuffer, options),\n binary: true\n};\n\nfunction parseNetCDF(arrayBuffer: ArrayBuffer, options?: NetCDFLoaderOptions): NetCDF {\n const reader = new NetCDFReader(arrayBuffer);\n const variables: {[variableName: string]: any[][]} = {};\n if (options?.netcdf?.loadData) {\n for (const variable of reader.variables) {\n variables[variable.name] = reader.getDataVariable(variable);\n }\n }\n return {\n loaderData: reader.header,\n data: variables\n };\n}\n\n// Type tests\nexport const _typecheckNetCDFWorkerLoader: Loader = NetCDFWorkerLoader;\nexport const _typecheckNetCDFLoader: LoaderWithParser = NetCDFLoader;\n"],"mappings":"AAEA,SAAQA,YAAY,QAAO,0BAA0B;AAIrD,MAAMC,OAAO,GAAG,sBAAkB,KAAK,WAAW,qBAAiB,QAAQ;AAgB3E,OAAO,MAAMC,kBAAkB,GAAG;EAChCC,IAAI,EAAE,QAAQ;EACdC,EAAE,EAAE,KAAK;EACTC,MAAM,EAAE,KAAK;EACbC,OAAO,EAAEL,OAAO;EAChBM,UAAU,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC;EACzBC,SAAS,EAAE,CACT,oBAAoB,EACpB,sBAAsB,CAEvB;EACDC,QAAQ,EAAE,OAAO;EACjBC,OAAO,EAAE;IACPC,MAAM,EAAE;MACNC,aAAa,EAAE;IACjB;EACF;AACF,CAAC;AAKD,OAAO,MAAMC,YAAY,GAAG;EAC1B,GAAGX,kBAAkB;EACrBY,KAAK,EAAE,MAAAA,CAAOC,WAAW,EAAEL,OAAO,KAAKM,WAAW,CAACD,WAAW,EAAEL,OAAO,CAAC;EACxEO,MAAM,EAAE;AACV,CAAC;AAED,SAASD,WAAWA,CAACD,WAAwB,EAAEL,OAA6B,EAAU;EAAA,IAAAQ,eAAA;EACpF,MAAMC,MAAM,GAAG,IAAInB,YAAY,CAACe,WAAW,CAAC;EAC5C,MAAMK,SAA4C,GAAG,CAAC,CAAC;EACvD,IAAIV,OAAO,aAAPA,OAAO,gBAAAQ,eAAA,GAAPR,OAAO,CAAEC,MAAM,cAAAO,eAAA,eAAfA,eAAA,CAAiBG,QAAQ,EAAE;IAC7B,KAAK,MAAMC,QAAQ,IAAIH,MAAM,CAACC,SAAS,EAAE;MACvCA,SAAS,CAACE,QAAQ,CAACnB,IAAI,CAAC,GAAGgB,MAAM,CAACI,eAAe,CAACD,QAAQ,CAAC;IAC7D;EACF;EACA,OAAO;IACLE,UAAU,EAAEL,MAAM,CAACM,MAAM;IACzBC,IAAI,EAAEN;EACR,CAAC;AACH;AAGA,OAAO,MAAMO,4BAAoC,GAAGzB,kBAAkB;AACtE,OAAO,MAAM0B,sBAAwC,GAAGf,YAAY"}
1
+ {"version":3,"file":"netcdf-loader.js","names":["NetCDFReader","VERSION","NetCDFWorkerLoader","name","id","module","version","extensions","mimeTypes","category","options","netcdf","loadVariables","NetCDFLoader","parse","arrayBuffer","parseNetCDF","binary","_options$netcdf","reader","variables","loadData","variable","getDataVariable","loaderData","header","data"],"sources":["../../src/netcdf-loader.ts"],"sourcesContent":["import type {Loader, LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';\nimport type {NetCDFHeader} from './netcdfjs/netcdf-types';\nimport {NetCDFReader} from './netcdfjs/netcdf-reader';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type NetCDF = {\n loaderData: NetCDFHeader;\n data: {[variableName: string]: any[][]};\n};\n\nexport type NetCDFLoaderOptions = LoaderOptions & {\n netcdf?: {\n loadData?: boolean;\n loadVariables?: boolean;\n };\n};\n\n/**\n * Worker loader for NETCDF\n */\nexport const NetCDFWorkerLoader: Loader<NetCDF, never, NetCDFLoaderOptions> = {\n name: 'NetCDF',\n id: 'mvt',\n module: 'mvt',\n version: VERSION,\n extensions: ['cdf', 'nc'],\n mimeTypes: [\n 'application/netcdf',\n 'application/x-netcdf'\n // 'application/octet-stream'\n ],\n category: 'image',\n options: {\n netcdf: {\n loadVariables: false\n }\n }\n};\n\n/**\n * Loader for the NetCDF format\n */\nexport const NetCDFLoader: LoaderWithParser<NetCDF, never, NetCDFLoaderOptions> = {\n ...NetCDFWorkerLoader,\n parse: async (arrayBuffer, options) => parseNetCDF(arrayBuffer, options),\n binary: true\n};\n\nfunction parseNetCDF(arrayBuffer: ArrayBuffer, options?: NetCDFLoaderOptions): NetCDF {\n const reader = new NetCDFReader(arrayBuffer);\n const variables: {[variableName: string]: any[][]} = {};\n if (options?.netcdf?.loadData) {\n for (const variable of reader.variables) {\n variables[variable.name] = reader.getDataVariable(variable);\n }\n }\n return {\n loaderData: reader.header,\n data: variables\n };\n}\n"],"mappings":"AAEA,SAAQA,YAAY,QAAO,0BAA0B;AAIrD,MAAMC,OAAO,GAAG,qBAAkB,KAAK,WAAW,oBAAiB,QAAQ;AAiB3E,OAAO,MAAMC,kBAA8D,GAAG;EAC5EC,IAAI,EAAE,QAAQ;EACdC,EAAE,EAAE,KAAK;EACTC,MAAM,EAAE,KAAK;EACbC,OAAO,EAAEL,OAAO;EAChBM,UAAU,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC;EACzBC,SAAS,EAAE,CACT,oBAAoB,EACpB,sBAAsB,CAEvB;EACDC,QAAQ,EAAE,OAAO;EACjBC,OAAO,EAAE;IACPC,MAAM,EAAE;MACNC,aAAa,EAAE;IACjB;EACF;AACF,CAAC;AAKD,OAAO,MAAMC,YAAkE,GAAG;EAChF,GAAGX,kBAAkB;EACrBY,KAAK,EAAE,MAAAA,CAAOC,WAAW,EAAEL,OAAO,KAAKM,WAAW,CAACD,WAAW,EAAEL,OAAO,CAAC;EACxEO,MAAM,EAAE;AACV,CAAC;AAED,SAASD,WAAWA,CAACD,WAAwB,EAAEL,OAA6B,EAAU;EAAA,IAAAQ,eAAA;EACpF,MAAMC,MAAM,GAAG,IAAInB,YAAY,CAACe,WAAW,CAAC;EAC5C,MAAMK,SAA4C,GAAG,CAAC,CAAC;EACvD,IAAIV,OAAO,aAAPA,OAAO,gBAAAQ,eAAA,GAAPR,OAAO,CAAEC,MAAM,cAAAO,eAAA,eAAfA,eAAA,CAAiBG,QAAQ,EAAE;IAC7B,KAAK,MAAMC,QAAQ,IAAIH,MAAM,CAACC,SAAS,EAAE;MACvCA,SAAS,CAACE,QAAQ,CAACnB,IAAI,CAAC,GAAGgB,MAAM,CAACI,eAAe,CAACD,QAAQ,CAAC;IAC7D;EACF;EACA,OAAO;IACLE,UAAU,EAAEL,MAAM,CAACM,MAAM;IACzBC,IAAI,EAAEN;EACR,CAAC;AACH"}
@@ -9,44 +9,15 @@ export type NetCDF = {
9
9
  export type NetCDFLoaderOptions = LoaderOptions & {
10
10
  netcdf?: {
11
11
  loadData?: boolean;
12
+ loadVariables?: boolean;
12
13
  };
13
14
  };
14
15
  /**
15
16
  * Worker loader for NETCDF
16
17
  */
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
- };
18
+ export declare const NetCDFWorkerLoader: Loader<NetCDF, never, NetCDFLoaderOptions>;
31
19
  /**
32
20
  * Loader for the NetCDF format
33
21
  */
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;
22
+ export declare const NetCDFLoader: LoaderWithParser<NetCDF, never, NetCDFLoaderOptions>;
52
23
  //# sourceMappingURL=netcdf-loader.d.ts.map
@@ -1 +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"}
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;QACnB,aAAa,CAAC,EAAE,OAAO,CAAC;KACzB,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,mBAAmB,CAiBzE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,mBAAmB,CAI7E,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@loaders.gl/netcdf",
3
3
  "description": "Loader for NetCDF",
4
- "version": "4.0.0-alpha.9",
4
+ "version": "4.0.0-beta.2",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -30,7 +30,7 @@
30
30
  "build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/dist.min.js"
31
31
  },
32
32
  "dependencies": {
33
- "@loaders.gl/loader-utils": "4.0.0-alpha.9"
33
+ "@loaders.gl/loader-utils": "4.0.0-beta.2"
34
34
  },
35
- "gitHead": "03ff81ab468f20f3bddeec787aa88d477a7e1c72"
35
+ "gitHead": "79c2033f755e88e11bc30a04428e3666b177b8fc"
36
36
  }
@@ -14,13 +14,14 @@ export type NetCDF = {
14
14
  export type NetCDFLoaderOptions = LoaderOptions & {
15
15
  netcdf?: {
16
16
  loadData?: boolean;
17
+ loadVariables?: boolean;
17
18
  };
18
19
  };
19
20
 
20
21
  /**
21
22
  * Worker loader for NETCDF
22
23
  */
23
- export const NetCDFWorkerLoader = {
24
+ export const NetCDFWorkerLoader: Loader<NetCDF, never, NetCDFLoaderOptions> = {
24
25
  name: 'NetCDF',
25
26
  id: 'mvt',
26
27
  module: 'mvt',
@@ -42,7 +43,7 @@ export const NetCDFWorkerLoader = {
42
43
  /**
43
44
  * Loader for the NetCDF format
44
45
  */
45
- export const NetCDFLoader = {
46
+ export const NetCDFLoader: LoaderWithParser<NetCDF, never, NetCDFLoaderOptions> = {
46
47
  ...NetCDFWorkerLoader,
47
48
  parse: async (arrayBuffer, options) => parseNetCDF(arrayBuffer, options),
48
49
  binary: true
@@ -61,7 +62,3 @@ function parseNetCDF(arrayBuffer: ArrayBuffer, options?: NetCDFLoaderOptions): N
61
62
  data: variables
62
63
  };
63
64
  }
64
-
65
- // Type tests
66
- export const _typecheckNetCDFWorkerLoader: Loader = NetCDFWorkerLoader;
67
- export const _typecheckNetCDFLoader: LoaderWithParser = NetCDFLoader;
package/dist/index.js DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NetCDFLoader = exports.NetCDFReader = void 0;
4
- var netcdf_reader_1 = require("./netcdfjs/netcdf-reader");
5
- Object.defineProperty(exports, "NetCDFReader", { enumerable: true, get: function () { return netcdf_reader_1.NetCDFReader; } });
6
- var netcdf_loader_1 = require("./netcdf-loader");
7
- Object.defineProperty(exports, "NetCDFLoader", { enumerable: true, get: function () { return netcdf_loader_1.NetCDFLoader; } });
@@ -1,427 +0,0 @@
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;
@@ -1,52 +0,0 @@
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;
@@ -1,165 +0,0 @@
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;
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
- 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');
163
- }
164
- }
165
- exports.NetCDFReader = NetCDFReader;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readRecord = exports.readNonRecord = void 0;
4
- const read_type_1 = require("./read-type");
5
- // const STREAMING = 4294967295;
6
- /**
7
- * Read data for the given non-record variable
8
- * @param buffer - Buffer for the file data
9
- * @param variable - Variable metadata
10
- * @return Data of the element
11
- */
12
- function readNonRecord(buffer, variable) {
13
- // variable type
14
- const type = (0, read_type_1.str2num)(variable.type);
15
- // size of the data
16
- const size = variable.size / (0, read_type_1.num2bytes)(type);
17
- // iterates over the data
18
- const data = new Array(size);
19
- for (let i = 0; i < size; i++) {
20
- data[i] = (0, read_type_1.readType)(buffer, type, 1);
21
- }
22
- return data;
23
- }
24
- exports.readNonRecord = readNonRecord;
25
- /**
26
- * Read data for the given record variable
27
- * @param buffer - Buffer for the file data
28
- * @param variable - Variable metadata
29
- * @param recordDimension - Record dimension metadata
30
- * @return - Data of the element
31
- */
32
- function readRecord(buffer, variable, recordDimension) {
33
- // variable type
34
- const type = (0, read_type_1.str2num)(variable.type);
35
- const width = variable.size ? variable.size / (0, read_type_1.num2bytes)(type) : 1;
36
- // size of the data
37
- // TODO streaming data
38
- const size = recordDimension.length;
39
- // iterates over the data
40
- const data = new Array(size);
41
- const step = recordDimension.recordStep;
42
- for (let i = 0; i < size; i++) {
43
- const currentOffset = buffer.offset;
44
- data[i] = (0, read_type_1.readType)(buffer, type, width);
45
- buffer.seek(currentOffset + step);
46
- }
47
- return data;
48
- }
49
- exports.readRecord = readRecord;
@@ -1,230 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readName = exports.readNetCDFHeader = void 0;
4
- const read_type_1 = require("./read-type");
5
- // Grammar constants
6
- const ZERO = 0;
7
- const NC_DIMENSION = 10;
8
- const NC_VARIABLE = 11;
9
- const NC_ATTRIBUTE = 12;
10
- const NC_UNLIMITED = 0;
11
- /**
12
- * Read the header of the file
13
- * @param buffer - Buffer for the file data
14
- * @param version - Version of the file
15
- * @return - Header
16
- */
17
- function readNetCDFHeader(buffer, version) {
18
- // Length of record dimension
19
- // sum of the varSize's of all the record variables.
20
- const recordDimensionLength = buffer.readUint32();
21
- // List of dimensions
22
- const dimList = readDimensionsList(buffer);
23
- // List of global attributes
24
- const attributes = readAttributesList(buffer);
25
- // List of variables
26
- const variableList = readVariablesList(buffer, dimList.recordId, version);
27
- const header = {
28
- version,
29
- recordDimension: {
30
- length: recordDimensionLength,
31
- id: dimList.recordId,
32
- name: dimList.recordName,
33
- recordStep: variableList.recordStep
34
- },
35
- dimensions: dimList.dimensions,
36
- variables: variableList.variables,
37
- attributes
38
- };
39
- return header;
40
- }
41
- exports.readNetCDFHeader = readNetCDFHeader;
42
- /**
43
- * Read list of dimensions
44
- * @ignore
45
- * @param {IOBuffer} buffer - Buffer for the file data
46
- */
47
- function readDimensionsList(buffer) {
48
- const dimList = buffer.readUint32();
49
- if (dimList === ZERO) {
50
- if (buffer.readUint32() !== ZERO) {
51
- throw new Error('NetCDF: wrong empty tag for list of dimensions');
52
- }
53
- // TODO - is this empty dimension list supported / recoverable?
54
- return {
55
- recordId: 0,
56
- recordName: '',
57
- dimensions: []
58
- };
59
- }
60
- if (dimList !== NC_DIMENSION) {
61
- throw new Error('NetCDF: wrong tag for list of dimensions');
62
- }
63
- // Length of dimensions
64
- const dimensionSize = buffer.readUint32();
65
- const dimensions = new Array(dimensionSize);
66
- let recordId;
67
- let recordName;
68
- for (let dim = 0; dim < dimensionSize; dim++) {
69
- // Read name
70
- const name = readName(buffer);
71
- // Read dimension size
72
- const size = buffer.readUint32();
73
- if (size === NC_UNLIMITED) {
74
- // in netcdf 3 one field can be of size unlimmited
75
- recordId = dim;
76
- recordName = name;
77
- }
78
- dimensions[dim] = {
79
- name,
80
- size
81
- };
82
- }
83
- return {
84
- dimensions,
85
- recordId,
86
- recordName
87
- };
88
- }
89
- /**
90
- * List of attributes
91
- * @ignore
92
- * @param buffer - Buffer for the file data
93
- * @return List of attributes with:
94
- */
95
- function readAttributesList(buffer) {
96
- const gAttList = buffer.readUint32();
97
- if (gAttList === ZERO) {
98
- if (buffer.readUint32() !== ZERO) {
99
- throw new Error('NetCDF: wrong empty tag for list of attributes');
100
- }
101
- return [];
102
- }
103
- if (gAttList !== NC_ATTRIBUTE) {
104
- throw new Error('NetCDF: wrong tag for list of attributes');
105
- }
106
- // Length of attributes
107
- const attributeSize = buffer.readUint32();
108
- const attributes = new Array(attributeSize);
109
- for (let gAtt = 0; gAtt < attributeSize; gAtt++) {
110
- // Read name
111
- const name = readName(buffer);
112
- // Read type
113
- const type = buffer.readUint32();
114
- if (type < 1 || type > 6) {
115
- throw new Error(`NetCDF: non valid type ${type}`);
116
- }
117
- // Read attribute
118
- const size = buffer.readUint32();
119
- const value = (0, read_type_1.readType)(buffer, type, size);
120
- // Apply padding
121
- padding(buffer);
122
- attributes[gAtt] = {
123
- name,
124
- type: (0, read_type_1.num2str)(type),
125
- value
126
- };
127
- }
128
- return attributes;
129
- }
130
- /**
131
- * List of variables
132
- * @param buffer - Buffer for the file data
133
- * @param recordId - Id of the unlimited dimension (also called record dimension)
134
- * This value may be undefined if there is no unlimited dimension
135
- * @param {number} version - Version of the file
136
- */
137
- // eslint-disable-next-line max-statements, complexity
138
- function readVariablesList(buffer, recordId, version) {
139
- const varList = buffer.readUint32();
140
- let recordStep = 0;
141
- if (varList === ZERO) {
142
- if (buffer.readUint32() !== ZERO) {
143
- throw new Error('NetCDF: wrong empty tag for list of variables');
144
- }
145
- return {
146
- recordStep,
147
- variables: []
148
- };
149
- }
150
- if (varList !== NC_VARIABLE) {
151
- throw new Error('NetCDF: wrong tag for list of variables');
152
- }
153
- // Length of variables
154
- const variableSize = buffer.readUint32();
155
- const variables = new Array(variableSize);
156
- for (let v = 0; v < variableSize; v++) {
157
- // Read name
158
- const name = readName(buffer);
159
- // Read dimensionality of the variable
160
- const dimensionality = buffer.readUint32();
161
- // Index into the list of dimensions
162
- const dimensionsIds = new Array(dimensionality);
163
- for (let dim = 0; dim < dimensionality; dim++) {
164
- dimensionsIds[dim] = buffer.readUint32();
165
- }
166
- // Read variables size
167
- const attributes = readAttributesList(buffer);
168
- // Read type
169
- const type = buffer.readUint32();
170
- if (type < 1 && type > 6) {
171
- throw new Error(`NetCDF: non valid type ${type}`);
172
- }
173
- // Read variable size
174
- // The 32-bit varSize field is not large enough to contain the size of variables that require
175
- // more than 2^32 - 4 bytes, so 2^32 - 1 is used in the varSize field for such variables.
176
- const varSize = buffer.readUint32();
177
- // Read offset
178
- let offset = buffer.readUint32();
179
- if (version === 2) {
180
- if (offset > 0) {
181
- throw new Error('NetCDF: offsets larger than 4GB not supported');
182
- }
183
- offset = buffer.readUint32();
184
- }
185
- let record = false;
186
- // Count amount of record variables
187
- if (typeof recordId !== 'undefined' && dimensionsIds[0] === recordId) {
188
- recordStep += varSize;
189
- record = true;
190
- }
191
- variables[v] = {
192
- name,
193
- dimensions: dimensionsIds,
194
- attributes,
195
- type: (0, read_type_1.num2str)(type),
196
- size: varSize,
197
- offset,
198
- record
199
- };
200
- }
201
- return {
202
- variables,
203
- recordStep
204
- };
205
- }
206
- // HELPERS
207
- /**
208
- * Reads the name
209
- * @param buffer - Buffer for the file data
210
- * @return Name
211
- */
212
- function readName(buffer) {
213
- // Read name
214
- const nameLength = buffer.readUint32();
215
- const name = buffer.readChars(nameLength);
216
- // validate name
217
- // TODO
218
- // Apply padding
219
- padding(buffer);
220
- return name;
221
- }
222
- exports.readName = readName;
223
- /**
224
- * Moves 1, 2, or 3 bytes to next 4-byte boundary
225
- */
226
- function padding(buffer) {
227
- if (buffer.offset % 4 !== 0) {
228
- buffer.skip(4 - (buffer.offset % 4));
229
- }
230
- }
@@ -1,140 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.str2num = exports.num2bytes = exports.num2str = exports.readType = exports.TYPES = void 0;
4
- exports.TYPES = {
5
- BYTE: 1,
6
- CHAR: 2,
7
- SHORT: 3,
8
- INT: 4,
9
- FLOAT: 5,
10
- DOUBLE: 6
11
- };
12
- /**
13
- * Given a type and a size reads the next element
14
- * @param buffer - Buffer for the file data
15
- * @param type - Type of the data to read
16
- * @param size - Size of the element to read
17
- * @return
18
- */
19
- function readType(buffer, type, size) {
20
- switch (type) {
21
- case exports.TYPES.BYTE:
22
- return buffer.readBytes(size);
23
- case exports.TYPES.CHAR:
24
- return trimNull(buffer.readChars(size));
25
- case exports.TYPES.SHORT:
26
- return readNumber(size, buffer.readInt16.bind(buffer));
27
- case exports.TYPES.INT:
28
- return readNumber(size, buffer.readInt32.bind(buffer));
29
- case exports.TYPES.FLOAT:
30
- return readNumber(size, buffer.readFloat32.bind(buffer));
31
- case exports.TYPES.DOUBLE:
32
- return readNumber(size, buffer.readFloat64.bind(buffer));
33
- /* istanbul ignore next */
34
- default:
35
- throw new Error(`NetCDF: non valid type ${type}`);
36
- }
37
- }
38
- exports.readType = readType;
39
- /**
40
- * Parse a number into their respective type
41
- * @param type - integer that represents the type
42
- * @return parsed value of the type
43
- */
44
- function num2str(type) {
45
- switch (Number(type)) {
46
- case exports.TYPES.BYTE:
47
- return 'byte';
48
- case exports.TYPES.CHAR:
49
- return 'char';
50
- case exports.TYPES.SHORT:
51
- return 'short';
52
- case exports.TYPES.INT:
53
- return 'int';
54
- case exports.TYPES.FLOAT:
55
- return 'float';
56
- case exports.TYPES.DOUBLE:
57
- return 'double';
58
- /* istanbul ignore next */
59
- default:
60
- return 'undefined';
61
- }
62
- }
63
- exports.num2str = num2str;
64
- /**
65
- * Parse a number type identifier to his size in bytes
66
- * @param type - integer that represents the type
67
- * @return size of the type
68
- */
69
- function num2bytes(type) {
70
- switch (Number(type)) {
71
- case exports.TYPES.BYTE:
72
- return 1;
73
- case exports.TYPES.CHAR:
74
- return 1;
75
- case exports.TYPES.SHORT:
76
- return 2;
77
- case exports.TYPES.INT:
78
- return 4;
79
- case exports.TYPES.FLOAT:
80
- return 4;
81
- case exports.TYPES.DOUBLE:
82
- return 8;
83
- /* istanbul ignore next */
84
- default:
85
- return -1;
86
- }
87
- }
88
- exports.num2bytes = num2bytes;
89
- /**
90
- * Reverse search of num2str
91
- * @param type string that represents the type
92
- * @return parsed value of the type
93
- */
94
- function str2num(type) {
95
- switch (String(type)) {
96
- case 'byte':
97
- return exports.TYPES.BYTE;
98
- case 'char':
99
- return exports.TYPES.CHAR;
100
- case 'short':
101
- return exports.TYPES.SHORT;
102
- case 'int':
103
- return exports.TYPES.INT;
104
- case 'float':
105
- return exports.TYPES.FLOAT;
106
- case 'double':
107
- return exports.TYPES.DOUBLE;
108
- /* istanbul ignore next */
109
- default:
110
- return -1;
111
- }
112
- }
113
- exports.str2num = str2num;
114
- /**
115
- * Auxiliary function to read numeric data
116
- * @param size - Size of the element to read
117
- * @param bufferReader - Function to read next value
118
- * @return
119
- */
120
- function readNumber(size, bufferReader) {
121
- if (size !== 1) {
122
- const numbers = new Array(size);
123
- for (let i = 0; i < size; i++) {
124
- numbers[i] = bufferReader();
125
- }
126
- return numbers;
127
- }
128
- return bufferReader();
129
- }
130
- /**
131
- * Removes null terminate value
132
- * @param value - String to trim
133
- * @return - Trimmed string
134
- */
135
- function trimNull(value) {
136
- if (value.charCodeAt(value.length - 1) === 0) {
137
- return value.substring(0, value.length - 1);
138
- }
139
- return value;
140
- }