From DataJoint Python and DataJoint MATLAB, I have inserted the same values into a longblob attribute. From DataJoint Python it was inserted as a dictionary and from DataJoint MATLAB it was inserted as a struct. The entry that was inserted with DataJoint MATLAB is a recarray when fetched in Python, which is expected. However, this recarray is difficult to parse since there are nested values.
Inserted with DataJoint Python, fetched with DataJoint Python:
{'cat_gt': {'use_cat_gt': 1,
'cat_gt_params': {'apfilter': ['biquad', 2, 300, 0],
'gfix': [0.4, 0.1, 0.02],
'extras': ['prb_fld', 't_miss_ok', 'ap', 'gblcar', 'out_prb_fld']}},
'process_cluster': 'tiger',
'clustering_method': 'Kilosort2'}
Inserted with DataJoint MATLAB, fetched with DataJoint Python:
rec.array([[(rec.array([[(array([[1.]]), rec.array([[(MatCell([['biquad'],
[2.0],
[300.0],
[0.0]], dtype=object), array([[0.4 ],
[0.1 ],
[0.02]]), MatCell([['prb_fld'],
['t_miss_ok'],
['ap'],
['gblcar'],
['out_prb_fld']], dtype='<U11')) ]],
dtype=[('apfilter', 'O'), ('gfix', 'O'), ('extras', 'O')]))]],
dtype=[('use_cat_gt', 'O'), ('cat_gt_params', 'O')]), array(['tiger'], dtype='<U5'), array(['Kilosort2'], dtype='<U9'))]],
dtype=[('cat_gt', 'O'), ('process_cluster', 'O'), ('clustering_method', 'O')])
Using query.fetch(as_dict=True)
did not seem to solve the issue:
[{'preprocess_paramset': rec.array([[(rec.array([[(array([[1.]]), rec.array([[(MatCell([['biquad'],
[2.0],
[300.0],
[0.0]], dtype=object), array([[0.4 ], ...
I could create a recursive function for converting a recarray to a dictionary, but wondering if there is a native method in DataJoint for fetching and converting this entry to a dictionary?
Thanks!
This is expected behavior. MATLAB structs are not equivalent to lists of dictionaries in python. They are more like
numpy.recarray
. Thefetch
flagas_dict
applies to the structure of the fetch result, not the blob internals.One could write a function to convert nested recarrays to dictionaries. It's hard to make it work universally because MATLAB struct arrays and cell arrays are not mapped easily to native Python types.