Example #1
0
def read_channel_labels_from_info(info: lsl.StreamInfo):
    info_xml = info.as_xml()
    rt = ET.fromstring(info_xml)
    channels_tree = (rt.find('desc').findall("channel")
                     or rt.find('desc').find("channels").findall("channel"))
    labels = [(ch.find('label')
               if ch.find('label') is not None else ch.find('name')).text
              for ch in channels_tree]
    # channels_tag = info.desc().child('channels')
    # if channels_tag.empty():
    #     return None
    # else:
    #     # TODO: this is hard to read.
    #     # Write a generator for children with a given name in helpers
    #     labels = list()
    #     types = list()
    #     single_channel_tag = channels_tag.child(name="channel")
    #     for channel_id in range(info.channel_count()):
    #         labels.append(single_channel_tag.child_value(name='label'))
    #         types.append(single_channel_tag.child_value(name='type'))
    #       single_channel_tag = single_channel_tag.next_sibling(
    #           name='channel')
    #     return labels, types
    types = []
    for l in labels:
        types.append('eeg')
    labels = [l[:-3] for l in labels]
    return labels, types
Example #2
0
def main():
    # create a new StreamInfo object which shall describe our stream
    info = StreamInfo("MetaTester", "EEG", 8, 100, "float32", "myuid56872")

    # now attach some meta-data (in accordance with XDF format,
    # see also https://github.com/sccn/xdf/wiki/Meta-Data)
    chns = info.desc().append_child("channels")
    for label in ["C3", "C4", "Cz", "FPz", "POz", "CPz", "O1", "O2"]:
        ch = chns.append_child("channel")
        ch.append_child_value("label", label)
        ch.append_child_value("unit", "microvolts")
        ch.append_child_value("type", "EEG")
    info.desc().append_child_value("manufacturer", "SCCN")
    cap = info.desc().append_child("cap")
    cap.append_child_value("name", "EasyCap")
    cap.append_child_value("size", "54")
    cap.append_child_value("labelscheme", "10-20")

    # create outlet for the stream
    outlet = StreamOutlet(info)

    # (...normally here one might start sending data into the outlet...)

    # === the following could run on another computer ===

    # first we resolve a stream whose name is MetaTester (note that there are
    # other ways to query a stream, too - for instance by content-type)
    results = resolve_stream("name", "MetaTester")

    # open an inlet so we can read the stream's data (and meta-data)
    inlet = StreamInlet(results[0])

    # get the full stream info (including custom meta-data) and dissect it
    info = inlet.info()
    print("The stream's XML meta-data is: ")
    print(info.as_xml())
    print("The manufacturer is: %s" % info.desc().child_value("manufacturer"))
    print("Cap circumference is: %s" %
          info.desc().child("cap").child_value("size"))
    print("The channel labels are as follows:")
    ch = info.desc().child("channels").child("channel")
    for k in range(info.channel_count()):
        print("  " + ch.child_value("label"))
        ch = ch.next_sibling()

    time.sleep(3)
Example #3
0
class Mock(threading.Thread):
    def __init__(
        self,
        name="Liesl-Mock-EEG",
        type="EEG",
        channel_count=8,
        nominal_srate=1000,
        channel_format="float32",
        source_id=None,
    ):

        threading.Thread.__init__(self)

        if source_id == None:
            source_id = str(hash(self))

        self.info = StreamInfo(name, type, channel_count, nominal_srate,
                               channel_format, source_id)
        self.channel_count = channel_count
        self.samplestep = 1 / nominal_srate
        self.is_running = False
        channels = self.info.desc().append_child("channels")
        types = (f"MockEEG" for x in range(1, channel_count + 1, 1))
        units = ("au" for x in range(1, channel_count + 1, 1))
        names = (f"C{x:03d}" for x in range(1, channel_count + 1, 1))
        for c, u, t in zip(names, units, types):
            channels.append_child("channel").append_child_value(
                "label",
                c).append_child_value("unit", u).append_child_value("type", t)

    def stop(self):
        self.is_running = False
        self.join()
        print("Shutting down")

    def await_running(self):
        try:
            self.start()
        except RuntimeError:
            pass
        while not self.is_running:
            pass

    def run(self):
        outlet = StreamOutlet(self.info)
        count = 0.0
        print("now sending data...")
        self.is_running = True
        while self.is_running:
            # make a new random 8-channel sample; this is converted into a
            # pylsl.vectorf (the data type that is expected by push_sample)
            # mysample = [rand() for c in range(self.channel_count)]
            mysample = []

            for c in range(self.channel_count):
                if c == 0:
                    mysample.append(rand())
                else:
                    smpl = sin((c**2) * 2 * pi * count * self.samplestep)
                    mysample.append(smpl)
            count += 1.0
            # now send it and wait for a bit
            outlet.push_sample(mysample)
            time.sleep(self.samplestep)

    def __str__(self):
        return self.info.as_xml()
Example #4
0
cap.append_child_value("labelscheme", "10-20")

# create outlet for the stream
outlet = StreamOutlet(info)

# (...normally here one might start sending data into the outlet...)

# === the following could run on another computer ===

# first we resolve a stream whose name is MetaTester (note that there are
# other ways to query a stream, too - for instance by content-type)
results = resolve_stream("name", "MetaTester")

# open an inlet so we can read the stream's data (and meta-data)
inlet = StreamInlet(results[0])

# get the full stream info (including custom meta-data) and dissect it
info = inlet.info()
print("The stream's XML meta-data is: ")
print(info.as_xml())
print("The manufacturer is: %s" % info.desc().child_value("manufacturer"))
print("Cap circumference is: %s" %
      info.desc().child("cap").child_value("size"))
print("The channel labels are as follows:")
ch = info.desc().child("channels").child("channel")
for k in range(info.channel_count()):
    print("  " + ch.child_value("label"))
    ch = ch.next_sibling()

time.sleep(3)
Example #5
0
 def log_info(self, metadata: pylsl.StreamInfo) -> None:
     """Log information about the current connections."""
     log.debug(metadata.as_xml())
     for marker_inlet in self._marker_inlets:
         log.debug("Streaming from marker inlet: %s",
                   inlet_name(marker_inlet))
cap.append_child_value("size", "54")
cap.append_child_value("labelscheme", "10-20")

# create outlet for the stream
outlet = StreamOutlet(info)

# (...normally here one might start sending data into the outlet...)

# === the following could run on another computer ===

# first we resolve a stream whose name is MetaTester (note that there are
# other ways to query a stream, too - for instance by content-type)
results = resolve_stream("name", "MetaTester")

# open an inlet so we can read the stream's data (and meta-data)
inlet = StreamInlet(results[0])

# get the full stream info (including custom meta-data) and dissect it
info = inlet.info()
print("The stream's XML meta-data is: ")
print(info.as_xml())
print("The manufacturer is: %s" % info.desc().child_value("manufacturer"))
print("Cap circumference is: %s" % info.desc().child("cap").child_value("size"))
print("The channel labels are as follows:")
ch = info.desc().child("channels").child("channel")
for k in range(info.channel_count()):
    print("  " + ch.child_value("label"))
    ch = ch.next_sibling()

time.sleep(3)