Exemplo n.º 1
0
def nest_get_spikes_by_spikedetector(spikedetector_id, from_time=None, to_time=None, node_ids=None, skip=None, top=None):  # noqa: E501
    """Retrieves the spikes for the given time range (optional) and node IDs (optional) from one spike detector. If no time range or node list is specified, it will return the spikes for whole time or all nodes respectively.

     # noqa: E501

    :param spikedetector_id: The ID of the spike detector to query.
    :type spikedetector_id: int
    :param from_time: The start time in milliseconds (including) to be queried.
    :type from_time: float
    :param to_time: The end time in milliseconds (excluding) to be queried.
    :type to_time: float
    :param node_ids: A list of node IDs queried for spike data.
    :type node_ids: List[int]
    :param skip: The offset into the result.
    :type skip: int
    :param top: The maximum number of entries to be returned.
    :type top: int

    :rtype: Spikes
    """
    spikes = Spikes([], [])
    for node in simulation_nodes.nest_simulation_nodes:
        
        if node_ids is not None:
            node_id_param = ",".join(map(str, node_ids))
        else:
            node_id_param = None

        response = requests.get(
            node+"/spikes", params={"fromTime": from_time, "toTime": to_time, "nodeIds": node_id_param, "spikedetectorId": spikedetector_id}).json()
        for x in range(len(response["simulationTimes"])):
            if node_ids is not None:
                if response["nodeIds"][x] in node_ids:
                    spikes.simulation_times.append(response["simulationTimes"][x])
                    spikes.node_ids.append(response["nodeIds"][x])
            else:
                spikes.simulation_times.append(response["simulationTimes"][x])
                spikes.node_ids.append(response["nodeIds"][x])

    # sort
    sorted_ids = [x for _, x in sorted(
        zip(spikes.simulation_times, spikes.node_ids))]
    spikes.node_ids = sorted_ids
    spikes.simulation_times.sort()

    # offset and limit
    if (skip is None):
        skip = 0
    if (top is None or (top + skip) > len(spikes.node_ids)):
        top = len(spikes.node_ids) - skip
    spikes.node_ids = spikes.node_ids[skip:skip+top]
    spikes.simulation_times = spikes.simulation_times[skip:skip+top]

    return spikes
Exemplo n.º 2
0
def nest_get_spikes_by_node_collection(node_collection_id, from_time=None, to_time=None, skip=None, top=None):  # noqa: E501
    """Retrieves the spikes for the given simulation steps (optional) and node collection. This request merges the spikes recorded by all spike detectors and removes duplicates.

     # noqa: E501

    :param node_collection_id: The identifier of the node collection.
    :type node_collection_id: int
    :param from_time: The start time (including) to be queried.
    :type from_time: float
    :param to_time: The end time (excluding) to be queried.
    :type to_time: float
    :param skip: The offset into the result.
    :type skip: int
    :param top: The maximum numbers of entries to be returned.
    :type top: int

    :rtype: Spikes
    """
    spikes = Spikes([], [])
    for node in simulation_nodes.nest_simulation_nodes:
        response = requests.get(
            node+"/spikes", params={"fromTime": from_time, "toTime": to_time, "nodeCollectionId": node_collection_id}).json()
        for x in range(len(response["simulationTimes"])):
            spikes.simulation_times.append(response["simulationTimes"][x])
            spikes.node_ids.append(response["nodeIds"][x])

    # sort
    sorted_ids = [x for _, x in sorted(
        zip(spikes.simulation_times, spikes.node_ids))]
    spikes.node_ids = sorted_ids
    spikes.simulation_times.sort()

    # offset and limit
    if (skip is None):
        skip = 0
    if (top is None or (top + skip) > len(spikes.node_ids)):
        top = len(spikes.node_ids) - skip
    spikes.node_ids = spikes.node_ids[skip:skip+top]
    spikes.simulation_times = spikes.simulation_times[skip:skip+top]

    return spikes
Exemplo n.º 3
0
def nest_get_spikes(_from=None, to=None, gids=None, offset=None, limit=None):  # noqa: E501
    """Retrieves the spikes for the given simulation steps (optional) and GIDS (optional).

     # noqa: E501

    :param _from: The start time (including) to be queried.
    :type _from: float
    :param to: The end time (excluding) to be queried.
    :type to: float
    :param gids: A list of GIDs queried for spike data.
    :type gids: List[int]
    :param offset: The offset into the result.
    :type offset: int
    :param limit: The maximum of entries to be result.
    :type limit: int

    :rtype: Spikes
    """
    spikes = Spikes([], [])
    for node in nodes.nest_simulation_nodes:
        response = requests.get(
            node+'/spikes', params={"from": _from, "to": to, "gids": gids}).json()
        for x in range(len(response['simulation_times'])):
            spikes.simulation_times.append(response['simulation_times'][x])
            spikes.gids.append(response['gids'][x])

    # sort
    sorted_ids = [x for _, x in sorted(
        zip(spikes.simulation_times, spikes.gids))]
    spikes.gids = sorted_ids
    spikes.simulation_times.sort()

    # offset and limit
    if (offset is None):
        offset = 0
    if (limit is None or (limit + offset) > len(spikes.gids)):
        limit = len(spikes.gids) - offset
    spikes.gids = spikes.gids[offset:offset+limit]
    spikes.simulation_times = spikes.simulation_times[offset:offset+limit]

    return spikes
Exemplo n.º 4
0
def nest_get_spikes_by_spikerecorder(spikerecorder_id,
                                     from_time=None,
                                     to_time=None,
                                     node_ids=None,
                                     skip=None,
                                     top=None):  # noqa: E501
    """Retrieves the spikes for the given time range (optional) and node IDs (optional) from one spike detector. If no time range or node list is specified, it will return the spikes for whole time or all nodes respectively.

     # noqa: E501

    :param spikedetector_id: The ID of the spike detector to query.
    :type spikedetector_id: int
    :param from_time: The start time in milliseconds (including) to be queried.
    :type from_time: float
    :param to_time: The end time in milliseconds (excluding) to be queried.
    :type to_time: float
    :param node_ids: A list of node IDs queried for spike data.
    :type node_ids: List[int]
    :param skip: The offset into the result.
    :type skip: int
    :param top: The maximum number of entries to be returned.
    :type top: int

    :rtype: Spikes
    """
    spikes = Spikes([], [])
    simulation_times = []
    node_id_list = []
    lastFrame = False

    for node in simulation_nodes.nest_simulation_nodes:

        if node_ids is not None:
            node_id_param = ",".join(map(str, node_ids))
        else:
            node_id_param = None

        response = requests.get(node + "/spikes",
                                params={
                                    "fromTime": from_time,
                                    "toTime": to_time,
                                    "nodeIds": node_id_param,
                                    "spikedetectorId": spikerecorder_id
                                })

        response = orjson.loads(response.content)
        lastFrame = response["lastFrame"]
        simulation_times = simulation_times + response["simulationTimes"]
        node_id_list = node_id_list + response["nodeIds"]

    #sort
    sorted_lists = sort_together([simulation_times, node_id_list])
    if sorted_lists != []:
        spikes.simulation_times = sorted_lists[0]
        spikes.node_ids = sorted_lists[1]

    # offset and limit
    if (skip is None):
        skip = 0
    if (top is None or (top + skip) > len(spikes.node_ids)):
        top = len(spikes.node_ids) - skip
    spikes.node_ids = spikes.node_ids[skip:skip + top]
    spikes.simulation_times = spikes.simulation_times[skip:skip + top]

    json_string = orjson.dumps({
        "nodeIds": spikes.node_ids,
        "simulationTimes": spikes.simulation_times,
        "lastFrame": lastFrame
    })
    return ConnexionResponse(status_code=200,
                             content_type='application/json',
                             mimetype='text/plain',
                             body=json_string)
Exemplo n.º 5
0
def nest_get_spikes_by_node_collection(node_collection_id,
                                       from_time=None,
                                       to_time=None,
                                       skip=None,
                                       top=None):  # noqa: E501
    """Retrieves the spikes for the given simulation steps (optional) and node collection. This request merges the spikes recorded by all spike detectors and removes duplicates.

     # noqa: E501

    :param node_collection_id: The identifier of the node collection.
    :type node_collection_id: int
    :param from_time: The start time (including) to be queried.
    :type from_time: float
    :param to_time: The end time (excluding) to be queried.
    :type to_time: float
    :param skip: The offset into the result.
    :type skip: int
    :param top: The maximum numbers of entries to be returned.
    :type top: int

    :rtype: Spikes
    """
    spikes = Spikes([], [])
    simulation_times = []
    node_id_list = []
    lastFrame = False
    for node in simulation_nodes.nest_simulation_nodes:
        response = requests.get(node + "/spikes",
                                params={
                                    "fromTime": from_time,
                                    "toTime": to_time,
                                    "nodeCollectionId": node_collection_id
                                })
        response = orjson.loads(response.content)
        lastFrame = response["lastFrame"]
        simulation_times = simulation_times + response["simulationTimes"]
        node_id_list = node_id_list + response["nodeIds"]

    # sort
    sorted_lists = sort_together([simulation_times, node_id_list])
    if sorted_lists != []:
        spikes.simulation_times = sorted_lists[0]
        spikes.node_ids = sorted_lists[1]

    # offset and limit
    if (skip is None):
        skip = 0
    if (top is None or (top + skip) > len(spikes.node_ids)):
        top = len(spikes.node_ids) - skip
    spikes.node_ids = spikes.node_ids[skip:skip + top]
    spikes.simulation_times = spikes.simulation_times[skip:skip + top]

    json_string = orjson.dumps({
        "nodeIds": spikes.node_ids,
        "simulationTimes": spikes.simulation_times,
        "lastFrame": lastFrame
    })
    return ConnexionResponse(status_code=200,
                             content_type='application/json',
                             mimetype='text/plain',
                             body=json_string)