Open mdenker opened 9 years ago
The problem is : python does not take data in type dict with the same key but different values. Example:
targdict=[{'unit_id':0, 'unit_id':1, 'd':4},{'electrode_id':7}, {'a':1, 'b':2, 'c':3}]
# return: [{'d': 4, 'unit_id': 1}, {'electrode_id': 7}, {'a': 1, 'b': 2, 'c': 3}]
# unit_id = 0 and unit_id = 1 does NOT work.
For the above example, I suggest the following input:
targdict=[{'unit_id': 0, 'electrode_id': 7}, {'unit_id': 1, 'electrode_id': 7}]
# it means: (unit_id =0 AND electrode_id = 7) OR (unit_id = 1 AND electrode_id = 7)
targdict[0] # return {'electrode_id' = 7, 'unit_id' =0}
targdict[1] # return {'electrode_id' = 7, 'unit_id' =1}
In this case, it might be controversial with the above statement. But if we understand that targdict in this case is a list and for every element is an filter_combi_condition. It's easier to access to the filter_condition of every element with
targdict[0]['electrode_id'] # return 7
targdict[1]['unit_id'] # return 1
The filter function of neo can be reimplemented follow this way.
Currently, the filter function in neo accepts inputs of the form
targdict=[{cond1,cond2},{cond3,cond4},..]
where cond1 and cond2 are OR, whereas the individual dictionaries {cond1,cond2} and {cond3,cond4} are AND connected.
One drawback is that it is not possible to filter for multiple values. For example, filtering for units 0 and 1 on electrode 7 is not possible via the following statement, which returns only unit 1 (the last filtering condition specified):
Output:
To achive the desired behavior, you need to use complex list comprehensions: