pynwb.io.utils module

pynwb.io.utils.get_nwb_version(builder: Builder, include_prerelease=False) Tuple[int, ...][source]

Get the version of the NWB file from the root of the given builder, as a tuple.

If the “nwb_version” attribute on the root builder equals “2.5.1”, then (2, 5, 1) is returned. If the “nwb_version” attribute on the root builder equals “2.5.1-alpha” and include_prerelease=False, then (2, 5, 1) is returned. If the “nwb_version” attribute on the root builder equals “2.5.1-alpha” and include_prerelease=True, then (2, 5, 1, “alpha”) is returned.

If the “nwb_version” attribute == “2.0b” (the only deviation from semantic versioning in the 2.x series), then if include_prerelease=True, (2, 0, 0, “b”) is returned; else, (2, 0, 0) is returned.

Parameters:
  • builder (Builder) – Any builder within an NWB file.

  • include_prerelease (bool) – Whether to include prerelease information in the returned tuple.

Returns:

The version of the NWB file, as a tuple.

Return type:

tuple

Raises:

ValueError – if the ‘nwb_version’ attribute is missing from the root of the NWB file.

pynwb.io.utils.parse_date(datestr, field_name)[source]

Parse an ISO 8601 date string read from a file into a datetime.

datestr may be str or UTF-8 bytes. Scalar datasets are decoded on read, while elements of an array-valued dataset (file_create_date) carry whichever the file stores: a variable-length str dataset is decoded, a variable-length bytes one is not.

dateutil handles the common formats. datetime.fromisoformat covers UTC offsets that carry a seconds component (e.g. -05:50:36), which some writers emit. A value that neither accepts raises a ValueError naming the field and the offending string.