Open j2l opened 1 year ago
Simple and complex packing types should also work: https://github.com/archmoj/grib2class/blob/c0ca0a2dff7e8a218bd255f8c0468f7dee3abb10/grib2class.js#L1286-L1289
Thank you very much @archmoj
So, if it's not the packingType, I might not use it correctly to read values:
<script>
import GRIB2CLASS from 'grib2class'
async function readfile(e) {
const file = await e.target.files[0];
let gribouille = new GRIB2CLASS({
numMembers: 1,
log: false,
});
await gribouille.parse(file);
console.log("gribouille: " + gribouille.getGrib2Section(0))
</script>
<input type="file" bind:files on:input={readfile}>
Any getGrib2Section returns 0 using example files as input (CMC_reg_TMP_TGL_2_ps10km_2019081112_P024.grib2 exactly).
Any idea?
As far as I know CMC grib2 files are encoded in jpeg-2000
not simple packing.
It should work if you provide the jpeg2000decoder
function as illustrated in this example: https://github.com/archmoj/opengrib2/blob/master/opengrib2.js
I expected some info about the file, just to make sure it can read something. My other trials didn't throw something different.
For example, a recent grib2 file from https://www.ncei.noaa.gov/data/global-forecast-system/access/grid-003-1.0-degree/analysis/202302/20230211/
is type grid_complex_spatial_differencing
and shows same result:
gribouille: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
What happens if you set log: true
in your app?
Could you possibly paste the log?
logger seems to be broken: Uncaught (in promise) TypeError: this is undefined < logger.js 38:12
What would happen if you require
the module instead of import
ing it?
Similar to https://github.com/archmoj/opengrib2/blob/master/opengrib2.js
Thank you @archmoj
Hmmm, getting "require is not defined" since it's Vite and Svelte (ESM). It's a well known wall because Svelte needs type=module
(see https://isotropic.co/how-to-fix-referenceerror-require-is-not-defined-in-javascript/).
Grib2class works without error as import though since you export it module.exports = function /* class */ GRIB2CLASS
I could try to redevelop it in Sveltekit to force server processing of require
but I'm pretty sure it won't solve it.
yeah, another wall with SvelteKit, since it cannot pass it to the client:
Error: Data returned from `load` while rendering / is not serializable: Cannot stringify a function (data.grib2class)
at Module.render_response (/node_modules/@sveltejs/kit/src/runtime/server/page/render.js:234:9)
at async Module.render_page (/node_modules/@sveltejs/kit/src/runtime/server/page/index.js:303:10)
at async resolve (/node_modules/@sveltejs/kit/src/runtime/server/respond.js:273:22)
at async Module.respond (/node_modules/@sveltejs/kit/src/runtime/server/respond.js:175:22)
at async file:///home/pm/Documents/github/sveltekit-grib/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:495:22
+page.server.js:
const grib2class = require("grib2class");
export const load = async ({locals}) => {
return {
grib2class: grib2class
};
};
It doesn't go further
Hello @archmoj, Thank you for making a JS library to parse grib2 files. Using linux tool grib_ls, it seems that your all grib example files are
grib_jpeg
packingType.Does grib2class also work for
grid_simple
packingType (wind on u and v axis, waves, ... on various dates and levels)?I can't make it work for now in svelte but it might be my fault :smile: