Skip to content

Instantly share code, notes, and snippets.

@neuromusic
Created November 19, 2017 21:42
Show Gist options
  • Select an option

  • Save neuromusic/1feaa2ba8b4327f95229e76fb98767fa to your computer and use it in GitHub Desktop.

Select an option

Save neuromusic/1feaa2ba8b4327f95229e76fb98767fa to your computer and use it in GitHub Desktop.
pynwb timeseries to xarray dataarray
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