<jupyter_start><jupyter_text>NI SystemLink Python API     TDMReader Service Example***The TDMReader Service API provides functions to access TDMS data (Groups, Channels, Metadata) in TDMS files hosted by **SystemLink**. The TDMReader Service API uses the file id as a key to locate which file to read. The file id can be retrieved using the File Service API.*** Prerequisites- Before you run this example, you need to create the test file (sine_wave_sdk_example.tdms)    - To do that, run the FileServiceExample notebook located in the same folder as this file. SummaryThis example exercises the File Service API to get the file id of the test file created by the FileServiceExample notebook. The file id is then consumed by the TDMReader Service API to read the noisy Sine Waves stored on the file. Finally, the waveforms are plotted.- Get the file id of 'sine_wave_sdk_example.tdms' calling the **query_files** File Service API call- Get all the channels from group 'signals' on the test file, by calling the **query_data** TDMReader API call- Plot all the channels- Plot a waveform with the mean values, visualizing the max/min***<jupyter_code>import matplotlib.pyplot as plt
import numpy as np

from systemlink.clients.nifile.api.files_api import FilesApi
from systemlink.clients.nifile.models.query_available_files_request import QueryAvailableFilesRequest
from systemlink.clients.nifile.models.property_query import PropertyQuery

from systemlink.clients.nitdmreader.api.metadata_api import MetadataApi
from systemlink.clients.nitdmreader.api.data_api import DataApi
from systemlink.clients.nitdmreader.models.one_channel_specifier import OneChannelSpecifier
from systemlink.clients.nitdmreader.models.data_window import DataWindow
from systemlink.clients.nitdmreader.models.channel_specifications_xy_channels import ChannelSpecificationsXyChannels
from systemlink.clients.nitdmreader.models.channel_specifications import ChannelSpecifications
from systemlink.clients.nitdmreader.models.query_data_specifier import QueryDataSpecifier

file_name = 'sine_wave_sdk_example.tdms'
group_name = 'signals'

files_api = FilesApi()
metadata_api = MetadataApi()
data_api = DataApi()

# Use the File Service API to get the fileid of sine_wave_sdk_example.tdms
property_query = PropertyQuery(key="Name", operation="EQUAL", value=file_name)
query = QueryAvailableFilesRequest(properties_query=[property_query])
res = await files_api.query_available_files(query=query)

num_files = len(res.available_files)

if num_files == 0:
    raise RuntimeError('You need to run the example notebook FileServiceExample.ipynb to upload the test file needed by this example')
elif num_files > 1:
    raise RuntimeError('You have more than one file in SystemLink named {}, aborting'.format(file_name))
else:
    # Get all the Sine Wave signals inside sine_wave_sdk_example.tdms
    file_id = res.available_files[0].id
    channels = await metadata_api.get_channels(file_id=file_id, group_name=group_name, skip=0, take=-1, return_count=True)

    sine_waves = []
    for channel_name in channels.names:
        channel_specifier = OneChannelSpecifier(file_id=file_id, group_name=group_name, channel_name=channel_name)
        data_window = DataWindow(xmin=0, xmax=1000, xlog=False, ymin=0, ymax=1000, ylog=False, decimatex=0, decimatey=0, show_points=False, show_lines=False)
        xy_channels = ChannelSpecificationsXyChannels(x_channel=None, y_channels=[channel_specifier], data_window=data_window)
        channel_spec = ChannelSpecifications(xy_channels=[xy_channels])
        query_data_specifier = QueryDataSpecifier(channel_specifications=channel_spec)
        sine_wave = await data_api.query_data(query_data_specifier)
        sine_waves.append(np.array(sine_wave.data[0].y[0].numeric_data))<jupyter_output><empty_output><jupyter_text>Sine Wave VisualizationPlot the 10 Sine Waves at the same time. The resulting graph shows how the Sine Waves in the tdms file are very noisy.<jupyter_code># Plot all the noisy sine waves

#plt.style.use('fivethirtyeight')

fig = plt.figure(figsize=(20, 10))
x = np.linspace(1, 1000, 1000)
for i in range(10):
    plt.plot(x, sine_waves[i])
plt.show()<jupyter_output><empty_output><jupyter_text>Mean Sine Wave with VarianceNext, we calculate the sine wave's mean and plot it. We calculate the max and min values for every point and we plot those too, filling the area between the mean and the min/max. The resulting graph give a richer visualization of the variance between sine wave signals.<jupyter_code># Plot the sine wave's mean, with the min/max values

mean_sine_wave = np.mean(sine_waves, axis=0)
max_sine_wav = np.max(sine_waves, axis=0)
min_sine_wav = np.min(sine_waves, axis=0)

fig = plt.figure(figsize=(20, 10))
plt.plot(x, mean_sine_wave)
plt.fill_between(x, min_sine_wav, max_sine_wav, color='red', alpha=0.2)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0757265656979124, 'fraction_numerical': 0.009209987720016374, 'mean_word_length': 6.001432664756447, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '292442', 'license': 'MIT', 'n_tokens_mistral': 1538, 'n_tokens_neox': 1480, 'n_words': 464, 'path': 'jupyter/TDMReaderServiceExample.ipynb', 'repo_name': 'haworthia/systemlink-server-examples', 'size': '4886'}