Open yarikoptic opened 1 year ago
Just out of curiosity, are y'all intending to use webnwb
in Node.js in the long run? Generally, I've created the library for the browser—though it should be possible to fully support node with a bit of finessing.
Generally, if you'd like to use webnwb
using Node.js, you'd install the library using Node Package Manager (NPM), import that in a .js file (e.g. a file called main.js with const nwb = require('webnwb')
or import nwb from 'webnwb')
and insert the code you'd like to execute, then run node main.js
in the console.
Internally in the webnwb
and hdf5-io
repos, I'm using Jest for testing. For this, I'm writing a test file and running npm run test
, which executes the Jest CLI based on the script property of the package.json file.
To help you both get started, I created a simple test repo using the browser and Node.js. It seems like there are some leftover bugs for streaming NWB files in Node.js and loading local files. The installation and execution steps are contained in that repo's README.md file. Generally, just run npm i
then npm start
for Node.js, and use Visual Studio Code's Live Server extension for the HTML file.
You should be able to check that required properties such as identifier
or nwb_version
are present.
Are you expecting to load NWB files that aren't able to be read by webnwb
?
Just out of curiosity, are y'all intending to use
webnwb
in Node.js in the long run?
ATM I have no immediate "use" cases for webnwb
so the answer would be No I guess ;) in the effort of this particular (dandisets-healthstatus) effort we are trying to make sure that all .nwb files uploaded to the archive could be at least opened with most common libraries for .nwb (pynwb, matnwb, and now webnwb ;) ). Depending on how people would like to use - in browsers pure JS or via node, we might want to adjust/extend our tests battery.
To help you both get started, I created a simple test repo using the browser and Node.js. It seems like there are some leftover bugs for streaming NWB files in Node.js and loading local files.
THANK YOU!
as I care only about opening/loading ATM, I took only opening part and with help of chatgpt I added loading filename from cmdline
Are you expecting to load NWB files that aren't able to be read by
webnwb
?
sorry , I am not following... FWIW: I am expecting webnwb
to be able to load and read any legit .nwb file. I expect that only legit .nwb files would be uploaded to dandiarchive.
Thank you for explaining the goals of the repo. Now your questions make much more sense.
Can you explain to me how MatNWB and PyNWB are currently being checked? That way, I can propose an analogous solution to what you already have for those.
There will be very few inconsistencies between the browser and Node—aside from the latter being more difficult to set up read/stream and write operations, while also being better to access local files without user input. As such, I'd expect we could get by with finalized tests for Node.
Can you explain to me how MatNWB and PyNWB are currently being checked? That way, I can propose an analogous solution to what you already have for those.
ATM we are trying to stay as basic (as minimal/simplest invocation) as possible to test the most basic functionality - being able to open an .nwb file without blowing up, but even that still shows to be challenging ;-)
with pynwb.NWBHDF5IO(sys.argv[1], "r", load_namespaces=True) as reader:
nwbfile = reader.read()
assert repr(nwbfile)
assert str(nwbfile)
generateCore()
nwb = nwbRead(f, 'savedir', '../out')
but we might need to change, following the discussion in https://github.com/NeurodataWithoutBorders/matnwb/issues/493 and https://github.com/NeurodataWithoutBorders/matnwb/issues/491 .
Unfortunately our full sweep process is still too slow due to need to be at large serial so we can't quickly change, but soon will do after current sweep through all dandisets is done and we get our https://github.com/dandi/dandisets-healthstatus#readme updated.
Got it. The conversion of the PyNWB test for WebNWB would look like the following:
import './polyfill.js' // This is required since the bundle assumes there is a global Blob object
import nwb from 'webnwb'
import process from 'process'
const args = process.argv.slice(2)
const filename = args[0]
const io = new nwb.NWBHDF5IO()
const file = await io.load(filename)
if (!file) throw new Error(`File ${filename} could not be loaded`)
// // Works in current version (see note in text below)
// const identifier = async file.identifier
// if (!identifier) throw new Error(`File ${filename} could not be loaded`)
However, I've noticed that this currently would not be thrown for files that currently error, as they'll return an empty NWBFile object (which passes this check), which is why I suggested checking properties like identifier
that are required but not set by the API if missing.
I will fix this in the next release of WebNWB so that files that cannot be loaded / streamed return an undefined
value and, therefore, trigger the above check.
https://github.com/brainsatplay/webnwb#loading-a-local-file gives an example
Since I know no JS, @garrettmflynn, would you be so kind to guide me and @jwodder on
node
in some other project for that)load
is lazy and does not really read much of metadata or data until asked, is there any other "generic" (applicable to any .nwb file) action to perform to quickly check thatwebnwb
is capable of reading the .nwb at hand.