How to use the nptdms.TdmsFile function in npTDMS

To help you get started, we’ve selected a few npTDMS examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dnvgl / qats / qats / readers / tdms.py View on Github external
"""
    if not os.path.isfile(path):
        raise FileNotFoundError("file not found: %s" % path)

    if isinstance(names, str):
        names = [names]
    elif type(names) in (list, tuple):
        pass
    elif names is None:
        # if names not specified, get all names
        names = read_names(path)
    else:
        raise TypeError("`names` must be str/list/tuple, got: %s" % type(names))

    arrays = []
    with TdmsFile.open(path) as f:
        # memory efficient but maybe slower

        for name in names:
            # assuming an object hierarchy with depth 2 'group-channel'
            assert len(name.split('\\')) == 2, f"Unable to parse group name and channel name from {name}."
            group_name, channel_name = name.split('\\')

            group = f[group_name]
            channel = group[channel_name]
            data = channel[:]
            time = None

            try:
                # try to fetch time track defined by wf_start_time and wf_start_offset attributes
                time = channel.time_track()
            except KeyError:
github sandialabs / slycat / web-server / plugins / slycat-dac / dac-tdms-file-parser.py View on Github external
parse_error_log = update_parse_log(database, model, parse_error_log, "Progress",
                                       "Uploaded " + str(num_files) + " file(s).")

    # push progress for wizard polling to database
    slycat.web.server.put_model_parameter(database, model, "dac-polling-progress", ["Extracting ...", 10.0])

    # treat each uploaded file as bitstream
    file_object = []
    tdms_ref = []

    for i in range(0,num_files):

        try:

            file_object.append(io.BytesIO(files[i]))
            tdms_ref.append(nptdms.TdmsFile(file_object[i]))

        except Exception as e:

            # couldn't open tdms file, report to user
            slycat.web.server.put_model_parameter(database, model, "dac-polling-progress",
                                                  ["Error", "couldn't read .tdms file."])

            # record no data message in front of parser log
            parse_error_log = update_parse_log(database, model, parse_error_log, "No Data",
                                               "Error -- couldn't read .tmds file.")

            # print error to cherrypy.log.error
            cherrypy.log.error(traceback.format_exc())

    stop_event = threading.Event()
    thread = threading.Thread(target=parse_tdms_thread, args=(database, model, tdms_ref,
github adamreeve / npTDMS / nptdms / tdmsinfo.py View on Github external
def tdmsinfo(file, show_properties=False):
    tdms_file = TdmsFile.read_metadata(file)

    level = 0
    display('/', level)
    if show_properties:
        display_properties(tdms_file, level + 1)
    for group in tdms_file.groups():
        level = 1
        display("%s" % group.path, level)
        if show_properties:
            display_properties(group, level + 1)
        for channel in group.channels():
            level = 2
            display("%s" % channel.path, level)
            if show_properties:
                level = 3
                if channel.data_type is not None:
github dnvgl / qats / qats / readers / tdms.py View on Github external
Path (relative or absolute) to tdms-file

    Returns
    -------
    list
        List of time series names (datasets)

    References
    ----------
    1. http://www.ni.com/product-documentation/3727/en/

    """
    if not os.path.isfile(path):
        raise FileNotFoundError("file not found: %s" % path)

    f = TdmsFile(path)
    names = [f"{g.name}\\{c.name}" for g in f.groups() for c in f[g.name].channels() if c.name.lower() != 'time']

    return names