<jupyter_start><jupyter_text>```asammdf``` Quick Start & Reference.A one page introduction to ```asammdf``` for Measurement Data Format (MDF) data analysis.For engineers wanting to drink from a fire hose or already experienced with Python data analysis.Replaces some or all of the functionality of these tools with a fullly opensource, free, analysis stack:- [AVL CONCERTO 5™](https://www.avl.com/web/guest/-/avl-concerto-5-)- [MathWorks® Vehicle Network Toolbox™](https://www.mathworks.com/products/vehicle-network.html)- [ETAS Measure Data Analyzer (MDA V8)](https://www.etas.com/en/company/realtimes_2019_2020-quick-and-intuitive-analysis-of-measurement-data.php)- [National Instruments DIAdem](https://www.ni.com/en-us/shop/data-acquisition-and-control/application-software-for-data-acquisition-and-control-category/what-is-diadem.html)- [Vector CANape & vSignalyzer](https://www.vector.com/int/en/products/application-areas/ecu-calibration/analyzing-evaluating-measurement-data/)<jupyter_code>%matplotlib inline
import asammdf
import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl<jupyter_output><empty_output><jupyter_text>Create MDF File- Create a [0, 10)s time vector with 100Hz sampling rate (10 ms raster)- Create a simple MDF file with two channels:    - "EngineSpeedCmd" 0.5 Hz sinewave with amplitude=10, & dc offset=600.    - "EngineSpeed" 0.5 Hz sinewave with amplitude=5, phi=pi/8, & dc offset=600.  Generate Engine Speed signals<jupyter_code># Time Vector
t0=0  # [s]
tf=10 # [s]
f_sample = 100 # [Hz]
dT = 1/f_sample # [s]
timestamps = np.arange(t0, tf, dT)
# Engine Speed
A = 10
f_signal = 0.5
dc_offset = 600
engine_speed_cmd = A*np.sin(2*np.pi*f_signal*timestamps)+dc_offset
engine_speed = A*0.5*np.sin(2*np.pi*f_signal*(timestamps-0.25))+dc_offset<jupyter_output><empty_output><jupyter_text>Plot engine speed signal.Direct plotting with [matplotlib](https://matplotlib.org/) & [seaborn](https://seaborn.pydata.org/).<jupyter_code>sns.set(
    rc={
        "figure.figsize": (11.69, 8.27), # A4 paper size.
        "figure.facecolor": "w",
        "figure.edgecolor": "k",
        "axes.labelsize": 18,
        "axes.titlesize": 18,
        "legend.fontsize": 18,
    }
)
plt.plot(timestamps, engine_speed_cmd, timestamps, engine_speed)
plt.xlabel("Time [s]")
plt.ylabel("Engine Speed [rpm]")
plt.title("Engine Speed vs Time")
plt.legend(
    {"Engine Speed Cmd", "Engine Speed"},
    loc='upper right'
);
plt.savefig(
    "EngineSpeedPlot.png",
    transparent=False,
    bbox_inches='tight'
);<jupyter_output><empty_output><jupyter_text>Generate ```asammdf```.```Signal``` & save ```MDF``` file.Convert the ```numpy``` arrays into ```asammdf.Signal```s & save.  ```Signal``` Object<jupyter_code>asammdf.Signal?
engine_speed_cmd_sig = asammdf.Signal(
    samples=engine_speed_cmd,
    timestamps=timestamps,
    unit='rpm',
    name='EngineSpeedCmd',
    conversion=None,
    comment='Swept sine plant identification, X(t)',
    raw=True,
    master_metadata=None,
    display_name='Engine Speed Command',
    attachment=(),
    source=None,
    bit_count=None,
    stream_sync=False,
    invalidation_bits=None,
    encoding=None,
)
engine_speed_sig = asammdf.Signal(
    samples=engine_speed,
    timestamps=timestamps,
    unit='rpm',
    name='EngineSpeed',
    conversion=None,
    comment='Swept sine plant identification, Y(t)',
    raw=True,
    master_metadata=None,
    display_name='Engine Speed',
    attachment=(),
    source=None,
    bit_count=None,
    stream_sync=False,
    invalidation_bits=None,
    encoding=None,
)
signals = [
    engine_speed_cmd_sig,
    engine_speed_sig,
]<jupyter_output><empty_output><jupyter_text>```MDF``` Object<jupyter_code>asammdf.MDF?<jupyter_output><empty_output><jupyter_text>Write the file directly in and out of a context manager.<jupyter_code>with asammdf.MDF(version="4.10") as mdf:
    mdf.append(signals, "Created by Python") 
    # save new file
    mdf.save("quickstart_example.mf4", overwrite=True)
mdf = asammdf.MDF(version="4.10")
mdf.append(signals, "Created by Python") 
    # save new file
mdf.save("quickstart_example.mf4", overwrite=True)
mdf.close()<jupyter_output><empty_output><jupyter_text>```fsspec``` example.> Filesystem Spec is a project to unify various projects and classes to work with remote filesystems and file-system-like abstractions using a standard pythonic interface.> - https://filesystem-spec.readthedocs.io/en/latest/This allows reading & writing directly from S3, Azure Datalakes, Google Storage, and others.<jupyter_code>import fsspec
with fsspec.open("quickstart_example_fs.mf4", "wb") as fid:
    with asammdf.MDF(version="4.10") as mdf:
        mdf.append(signals, "Created by Python") 
        # save new file
        mdf.save(fid, overwrite=True)<jupyter_output><empty_output><jupyter_text>Read & Analyze MDF<jupyter_code>%matplotlib inline
import asammdf
import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl<jupyter_output><empty_output><jupyter_text>Open a file with and without ```fsspec```.<jupyter_code>with fsspec.open("quickstart_example_fs.mf4", "rb") as fid:
    mdf = asammdf.MDF(fid)
mdf = asammdf.MDF("quickstart_example.mf4")<jupyter_output><empty_output><jupyter_text>List the channels in the database.<jupyter_code>mdf.channels_db
mdf.get_channel_unit("EngineSpeedCmd")
mdf.get_channel_comment("EngineSpeedCmd")
sns.set(
    rc={
        "figure.figsize": (11.69, 8.27), # A4 paper size.
        "figure.facecolor": "w",
        "figure.edgecolor": "k",
        "axes.labelsize": 18,
        "axes.titlesize": 18,
        "legend.fontsize": 18,
    }
)
for channel in mdf.iter_channels():
    channel.plot()<jupyter_output>WARNING:root:Signal plotting requires pyqtgraph or matplotlib<jupyter_text>Export to [```pandas```.```DataFrame```](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html):<jupyter_code>df = mdf.to_dataframe()
df.describe()
df<jupyter_output><empty_output><jupyter_text>Reset IndexConvert the 'timestamps' index back into a column for direct plotting from ```pandas```.<jupyter_code># Convert the 
df.reset_index(inplace=True)
df.plot(x="timestamps", y={"EngineSpeed", "EngineSpeedCmd"})
plt.ylabel("Engine Speed [rpm]")
plt.xlabel("Timestamps [s]");<jupyter_output><empty_output><jupyter_text>Export```asammdf``` natively supports:- csv- hdf5- mat- parquet<jupyter_code>mdf.export?
mdf.export(fmt="csv")
!ls *.csv
pd.read_csv("quickstart_example.ChannelGroup_0.csv")
mdf.export(fmt="hdf5")
!ls *.hdf
mdf.export(fmt="mat")
!ls *.mat<jupyter_output>quickstart_example.mat
{'fraction_non_alphanumeric': 0.13888057467824005, 'fraction_numerical': 0.015264890751272074, 'mean_word_length': 5.1822386679000925, 'pattern_counts': {'":': 12, '<': 51, '<?xml version=': 0, '>': 53, 'https://': 9, 'lorem ipsum': 0, 'www.': 5, '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': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '30305', 'license': 'MIT', 'n_tokens_mistral': 2509, 'n_tokens_neox': 2365, 'n_words': 483, 'path': '01_QuickStart.ipynb', 'repo_name': 'SimulinkDevOps/Jupyter_MDF_Analysis', 'size': '6682'}