Example #1
0
 def get_analysis_result(self, **kwargs):
     """
     Return a list of ADSs, that match the parameter values specified in kwargs.
     
     Examples
     --------
     >>> datastore.get_analysis_result(identifier=['PerNeuronValue','SingleValue'],sheet_name=sheet,value_name='orientation preference')
     
     This command should return or ADS whose identifier is *PerNeuronValue* or *SingleValue*, and are associated with sheet named *sheet* and as their value name have 'orientation preference'
     """
     return filter_query(self.analysis_results,**kwargs)
Example #2
0
 def get_analysis_result(self, **kwargs):
     """
     Return a list of ADSs, that match the parameter values specified in kwargs.
     
     Examples
     --------
     >>> datastore.get_analysis_result(identifier=['PerNeuronValue','SingleValue'],sheet_name=sheet,value_name='orientation preference')
     
     This command should return or ADS whose identifier is *PerNeuronValue* or *SingleValue*, and are associated with sheet named *sheet* and as their value name have 'orientation preference'
     """
     return filter_query(self.analysis_results, **kwargs)
Example #3
0
def param_filter_query(dsv, ads_unique=False, rec_unique=False, **kwargs):
    """
    It will return DSV with only recordings and ADSs with mozaik parameters 
    whose values match the parameter values combinations provided in `kwargs`. 
    
    To restrict mozaik parameters of the stimuli associated with the ADS or recordings 
    pre-pend 'st_' to the parameter name.
    
    For the recordings, parameter sheet refers to the sheet for which the recording was done. 
    
    
    Parameters
    ----------
    
    dsv : DataStoreView
        The input DSV.
    
    ads_unique : bool, optional
               If True the query will raise an exception if the query does not identify a unique ADS.

    rec_unique : bool, optional
               If True the query will raise an exception if the query does not identify a unique recording.
    
    \*\*kwargs : dict
               Remaining keyword arguments will be interepreted as the mozaik parameter names and their associated values that all ASDs
               or recordings have to match. The values of the parameters should be either directly the values to match or list of values in which
               case this list is interpreted as *one of* of the values that each returned recording or ASD has to match (thus effectively there
               is an *and* operation between the different parameters and *or* operation between the values specified for the given mozaik parameters). 
               
    Examples
    --------
    >>> datastore.param_filter_query(datastore,identifier=['PerNeuronValue','SingleValue'],sheet_name=sheet,value_name='orientation preference')
    
    This command should return DSV containing all recordings and ADSs whose identifier is *PerNeuronValue* or *SingleValue*, and are associated with sheet named *sheet_name* and as their value name have 'orientation preference'.
    Note that since recordings do not have these parameters, this query would return a DSV containing only ADSs.
    
    >>> datastore.param_filter_query(datastore,st_orientation=0.5)
    
    This command should return DSV containing all recordings and ADSs that are associated with stimuli whose mozaik parameter orientation has value 0.5.
    """

    new_dsv = dsv.fromDataStoreView()

    st_kwargs = dict([(k[3:], kwargs[k]) for k in kwargs.keys()
                      if k[0:3] == 'st_'])
    kwargs = dict([(k, kwargs[k]) for k in kwargs.keys() if k[0:3] != 'st_'])

    seg_st = [
        MozaikParametrized.idd(seg.annotations['stimulus'])
        for seg in dsv.block.segments
    ]
    ads_st = [
        MozaikParametrized.idd(ads.stimulus_id) for ads in dsv.analysis_results
        if ads.stimulus_id != None
    ]
    if 'sheet_name' in set(kwargs):
        if len(kwargs) == 1:
            # This means that there is only one 'non-stimulus' parameter sheet, and thus we need
            # to filter out all recordings that are associated with that sheet (otherwsie we do not pass any recordings)
            kw = kwargs['sheet_name'] if isinstance(
                kwargs['sheet_name'], list) else [kwargs['sheet_name']]
            seg_filtered = set([
                s for s in dsv.block.segments
                if s.annotations['sheet_name'] in kw
            ])
        else:
            seg_filtered = set([])
    else:
        seg_filtered = set(dsv.block.segments)

    ads_filtered = set(filter_query(dsv.analysis_results, **kwargs))

    if st_kwargs != {}:
        seg_filtered_st = set(
            filter_query(seg_st,
                         extra_data_list=dsv.block.segments,
                         **st_kwargs)[1])
        ads_filtered_st = set(
            filter_query(ads_st,
                         extra_data_list=[
                             ads for ads in dsv.analysis_results
                             if ads.stimulus_id != None
                         ],
                         **st_kwargs)[1])
    else:
        ads_filtered_st = set(dsv.analysis_results)
        seg_filtered_st = set(dsv.block.segments)

    seg = seg_filtered_st & seg_filtered
    ads = ads_filtered_st & ads_filtered

    new_dsv.sensory_stimulus = dsv.sensory_stimulus_copy()
    new_dsv.block.segments = list(seg)
    new_dsv.analysis_results = list(ads)

    if ads_unique and len(ads) != 1:
        raise ValueError(
            "Result was expected to have only single ADS, it contains %d" %
            len(ads))

    if rec_unique and len(seg) != 1:
        raise ValueError(
            "Result was expected to have only single Segment, it contains %d" %
            len(seg))

    return new_dsv
Example #4
0
def param_filter_query(dsv,ads_unique=False,rec_unique=False,**kwargs):
    """
    It will return DSV with only recordings and ADSs with mozaik parameters 
    whose values match the parameter values combinations provided in `kwargs`. 
    
    To restrict mozaik parameters of the stimuli associated with the ADS or recordings 
    pre-pend 'st_' to the parameter name.
    
    For the recordings, parameter sheet refers to the sheet for which the recording was done. 
    
    
    Parameters
    ----------
    
    dsv : DataStoreView
        The input DSV.
    
    ads_unique : bool, optional
               If True the query will raise an exception if the query does not identify a unique ADS.

    rec_unique : bool, optional
               If True the query will raise an exception if the query does not identify a unique recording.
    
    \*\*kwargs : dict
               Remaining keyword arguments will be interepreted as the mozaik parameter names and their associated values that all ASDs
               or recordings have to match. The values of the parameters should be either directly the values to match or list of values in which
               case this list is interpreted as *one of* of the values that each returned recording or ASD has to match (thus effectively there
               is an *and* operation between the different parameters and *or* operation between the values specified for the given mozaik parameters). 
               
    Examples
    --------
    >>> datastore.param_filter_query(datastore,identifier=['PerNeuronValue','SingleValue'],sheet_name=sheet,value_name='orientation preference')
    
    This command should return DSV containing all recordings and ADSs whose identifier is *PerNeuronValue* or *SingleValue*, and are associated with sheet named *sheet_name* and as their value name have 'orientation preference'.
    Note that since recordings do not have these parameters, this query would return a DSV containing only ADSs.
    
    >>> datastore.param_filter_query(datastore,st_orientation=0.5)
    
    This command should return DSV containing all recordings and ADSs that are associated with stimuli whose mozaik parameter orientation has value 0.5.
    """
    
    new_dsv = dsv.fromDataStoreView()
    
    st_kwargs = dict([(k[3:],kwargs[k]) for k in kwargs.keys() if k[0:3] == 'st_'])
    kwargs = dict([(k,kwargs[k]) for k in kwargs.keys() if k[0:3] != 'st_'])
    
    seg_st = [MozaikParametrized.idd(seg.annotations['stimulus']) for seg in dsv.block.segments]
    ads_st = [MozaikParametrized.idd(ads.stimulus_id) for ads in dsv.analysis_results if ads.stimulus_id != None]
    if 'sheet_name' in set(kwargs):
       if len(kwargs) == 1:
           # This means that there is only one 'non-stimulus' parameter sheet, and thus we need
           # to filter out all recordings that are associated with that sheet (otherwsie we do not pass any recordings)
           kw = kwargs['sheet_name'] if isinstance(kwargs['sheet_name'],list) else [kwargs['sheet_name']]
           seg_filtered = set([s for s in dsv.block.segments if s.annotations['sheet_name'] in kw])
       else:
           seg_filtered = set([]) 
    else:
           seg_filtered = set(dsv.block.segments)
    
    ads_filtered= set(filter_query(dsv.analysis_results,**kwargs))
    
    if st_kwargs != {}:
       seg_filtered_st= set(filter_query(seg_st,extra_data_list=dsv.block.segments,**st_kwargs)[1]) 
       ads_filtered_st= set(filter_query(ads_st,extra_data_list=[ads for ads in dsv.analysis_results if ads.stimulus_id != None],**st_kwargs)[1])
    else:
       ads_filtered_st = set(dsv.analysis_results)
       seg_filtered_st = set(dsv.block.segments)
    
    
    seg = seg_filtered_st & seg_filtered
    ads = ads_filtered_st & ads_filtered
    
    new_dsv.sensory_stimulus = dsv.sensory_stimulus_copy()
    new_dsv.block.segments = list(seg)
    new_dsv.analysis_results = list(ads)
    
    if ads_unique and len(ads) != 1:
       raise ValueError("Result was expected to have only single ADS, it contains %d" % len(ads)) 
        
    if rec_unique and len(seg) != 1:
       raise ValueError("Result was expected to have only single Segment, it contains %d" % len(seg)) 
    
    return new_dsv