Created
November 19, 2017 21:42
-
-
Save neuromusic/1feaa2ba8b4327f95229e76fb98767fa to your computer and use it in GitHub Desktop.
pynwb timeseries to xarray dataarray
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def timeseries_to_xarray(time_series): | |
| attrs = ts.fields.copy() | |
| data = attrs.pop('data').value | |
| timestamps = attrs.pop('timestamps').value | |
| for k,v in attrs.iteritems(): | |
| # replace any links with their name | |
| try: | |
| attrs[k] = v.name | |
| except AttributeError: | |
| pass | |
| xarr = xr.DataArray( | |
| data = data, | |
| name=time_series.name, | |
| dims = ('unknown','time'), | |
| coords = {'time':timestamps}, | |
| attrs = attrs, | |
| ) | |
| return xarr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment