ssciwr / mease-elabftw

A Python library for interacting with eLabFTW experiments
MIT License
1 stars 0 forks source link

add `get_nwb_conversion_tools_metadata()` function #30

Closed lkeegan closed 2 years ago

lkeegan commented 2 years ago

There are two possible (very similar) formats for nwb metadata depending on use case:

Failed validating 'type' in schema['properties']['Subject']['properties']['weight']: {'default': '0.02 g', 'description': 'The weight of the subject, including units. Using ' 'kilograms is recommended. e.g., "0.02 kg". If a float ' 'is provided, then the weight will be stored as ' '"[value] kg".', 'type': 'number'}


  - we have a [schema](https://github.com/ssciwr/mease-elabftw/blob/main/mease_elabftw/tests/metadata_ecephys.schema.json) in tests which looks consistent with above schemas but not with sample error message

Would be good to have `get_nwb_metadata` work for the first use case, and add `get_nwb_conversion_tools_metadata()` for the second use case. Internally it should call `get_nwb_metadata`, then make the necessary changes:
- [x] datetime objects -> strings
- [x] mouse weight -> float (in kilograms)
  - maybe it would make sense to just rescale whatever the value is to a sane mouse weight?
    - i.e. if above 1 then assume unit is grams & divide by 1000
    - I'll ask about this
- [x] ...?
GwydionJon commented 2 years ago

I might have found a way to convert the pynwb file back into a dict:

nwbfile_dict = nwb_metadata.get("NWBFile")
subject_dict = nwb_metadata.get("Subject")
{key: pynwb_file.fields[key] for key in nwbfile_dict}
{key: pynwb_file_1.subject.fields[key] for key in subject_dict}