pennmem/ptsa

Loss of numpy append_field functionality

LoganJF opened this issue · 7 comments

When events are loaded the old way using the matlab path, the events have functionality with the numpy function append_field. However, the new events loaded using json do not have this functionality and I'm not sure why.
screen shot 2018-01-11 at 5 37 25 pm

I'm currently using this as a work around
screen shot 2018-01-11 at 5 47 22 pm

@LoganJF can you upload these notebooks as a gist so that I can play around with this?

Yes. Thanks!

The problem is that the stim_params field in the JSON events is itself a Python dict. This was a poor design choice when the JSON events were defined that we are now unfortunately stuck with. If you create a subset of events which omits stim_params, you can append fields without issues.

Example:

ra = np.rec.array(json_events)
names = [name for name in ra.dtype.names if name not in ['stim_params']]
ra2 = ra[names]
append_fields(base=ra2, names='new_field', data=data_values, dtypes=ra2.mstime.dtype)

The best thing to do for now is document this behavior.

Closing in favor of #128.