### Install Python Comtrade Source: https://github.com/dparrini/python-comtrade/blob/master/README.md Install the module using pip. Alternatively, copy the comtrade.py file directly. ```bash pip install comtrade ``` -------------------------------- ### Load and Plot CFG/DAT Files Source: https://github.com/dparrini/python-comtrade/blob/master/README.md Load COMTRADE data from separate CFG and DAT files and plot analog channels using matplotlib. Ensure matplotlib is installed for plotting. ```python import matplotlib.pyplot as plt import comtrade rec = comtrade.load("sample_files/sample_ascii.cfg", "sample_files/sample_ascii.dat") print("Trigger time = {}s".format(rec.trigger_time)) plt.figure() plt.plot(rec.time, rec.analog[0]) plt.plot(rec.time, rec.analog[1]) plt.legend([rec.analog_channel_ids[0], rec.analog_channel_ids[1]]) plt.show() ``` -------------------------------- ### Load COMTRADE Data as Pandas DataFrame Source: https://github.com/dparrini/python-comtrade/blob/master/README.md Load COMTRADE data directly into a pandas DataFrame using load_as_dataframe or convert an existing Comtrade object to a DataFrame using to_dataframe(). Requires pandas to be installed. ```python import comtrade df = comtrade.load_as_dataframe("sample_files/sample_ascii.cfg") print(df.head()) # Or, alternatively rec = comtrade.load("sample_files/sample_ascii.cfg") df = rec.to_dataframe() print(df.head()) ``` -------------------------------- ### Run Unit Tests for COMTRADE Module Source: https://github.com/dparrini/python-comtrade/blob/master/README.md Execute the module's unit tests using Python's unittest framework. This command should be run from a clone of the GitHub repository. ```shell python3 -m unittest ./tests/tests.py ``` -------------------------------- ### Load and Plot CFF Files Source: https://github.com/dparrini/python-comtrade/blob/master/README.md Load COMTRADE data from a single CFF file (2013 revision) and plot analog channels using matplotlib. This method is specific to the 2013 revision. ```python import matplotlib.pyplot as plt import comtrade rec = comtrade.load("sample_files/sample_ascii.cff") print("Trigger time = {}s".format(rec.trigger_time)) plt.figure() plt.plot(rec.time, rec.analog[0]) plt.plot(rec.time, rec.analog[1]) plt.legend([rec.analog_channel_ids[0], rec.analog_channel_ids[1]]) plt.show() ``` -------------------------------- ### Initialize Comtrade with Numpy Arrays Source: https://github.com/dparrini/python-comtrade/blob/master/README.md Enforce the use of numpy.array for data structures in the Comtrade object constructor. This can improve performance for data computations after loading. ```python obj = Comtrade(use_numpy_arrays=True) ``` -------------------------------- ### Load COMTRADE File with Specific Encoding Source: https://github.com/dparrini/python-comtrade/blob/master/README.md Load a COMTRADE file specifying a custom encoding. This is useful when dealing with files that do not use the default UTF-8 encoding. ```python import comtrade comtrade.load("sample_files/sample_ascii.cff", encoding="iso-8859-1") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.