NeurodataWithoutBorders / lindi

Linked Data Interface (LINDI) - cloud-friendly access to NWB data
BSD 3-Clause "New" or "Revised" License
1 stars 1 forks source link

Add metadata to dtype when kind is 'O' #47

Closed magland closed 2 months ago

magland commented 3 months ago

In order to get pynwb validation to pass I needed to make the tweak of this PR. It seems that h5py uses a vlen field in metadata for a numpy dtype, and pynwb inspects that. I don't understand exactly what this is about. But when I set it to bytes in this case, the validation passes.

Here's a test validation script where things are passing with this PR


import pynwb
from pynwb import CORE_NAMESPACE
from pynwb.validate import ValidatorMap
import h5py
import remfile
import lindi

def test_validate(io: pynwb.NWBHDF5IO):
    namespace = CORE_NAMESPACE
    validator = ValidatorMap(namespace=io.manager.namespace_catalog.get_namespace(name=namespace))
    builder = io.read_builder()
    validation_errors = validator.validate(builder=builder)
    if len(validation_errors) == 0:
        print('Validation passed!')
    else:
        print('Validation failed!')
        for ve in validation_errors:
            print(ve)

if __name__ == "__main__":
    # https://neurosift.app/?p=/nwb&dandisetId=000409&dandisetVersion=draft&url=https://api.dandiarchive.org/api/assets/c04f6b30-82bf-40e1-9210-34f0bcd8be24/download/

    print('')
    print('Validating with HDF5 URL...')
    h5_url = 'https://api.dandiarchive.org/api/assets/c04f6b30-82bf-40e1-9210-34f0bcd8be24/download/'
    remf = remfile.File(h5_url)
    h5f = h5py.File(remf, mode='r')
    with pynwb.NWBHDF5IO(file=h5f, mode='r', load_namespaces=True) as io:
        test_validate(io)

    print('')
    print('Validating with LINDI URL...')
    lindi_url = 'https://lindi.neurosift.org/dandi/dandisets/000409/assets/c04f6b30-82bf-40e1-9210-34f0bcd8be24/zarr.json'
    ff = lindi.LindiH5pyFile.from_reference_file_system(lindi_url)
    with pynwb.NWBHDF5IO(file=ff, mode='r', load_namespaces=True) as io:
        test_validate(io)
codecov-commenter commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 82.34%. Comparing base (3c4562f) to head (d269450).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #47 +/- ## ======================================= Coverage 82.33% 82.34% ======================================= Files 28 28 Lines 1970 1971 +1 ======================================= + Hits 1622 1623 +1 Misses 348 348 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.