<jupyter_start><jupyter_text>LIT Dataset Python Library - Tutorial By <NAME>LIT is a voltage and current dataset for household utensils designed at UTFPR University, in the state of Paraná (Brazil). For more information, visit the official page (https://pessoal.dainf.ct.utfpr.edu.br/douglasrenaux/LIT_Dataset/) or the README of this repository. I have no connection with the research project team that designed this dataset, but I created this small library to facilitate the use of the Python dataset.This notebook will serve as a guide for using this library. Remember that the code in the *lit.py* file has docstrings in the non-internal functions, and you can consult them. First step - importIt is important that the *lit.py* file and the *LIT_Dataset* directory are at the same root as the file that will import this library. Otherwise, there will be problems with the library's internal paths.<jupyter_code>import matplotlib.pyplot as plt
import lit<jupyter_output><empty_output><jupyter_text>ShortnamesIn the LIT dataset, each load has a shortname such that '1A0', '2A0B0', etc. These shortnames are structured as follows:N + \[A-Z\]0 + \[A-Z\]0 + ...Where:* N is the quantity of appliances in the load* Each "\[A-Z\]0" expression is the shortname of one appliance in the load For example: "2A0B0" is a load that have two appliances that are identified as "A0" and "B0". For information such as type of appliance, brand and power of shortnames such as "A0" and "B0", see the website (https://pessoal.dainf.ct.utfpr.edu.br/douglasrenaux/LIT_Dataset/Subsets/Synthetic/index.html) or the *appliances.xlsx* spreadsheet. Listing shortnamesYou can use the **list_loads** function to get a list with all load shortnames with a specific quantity of appliances.You must specify the lit subset in the *subset* parameter and the number of appliances in the *n_appliances* parameter.<jupyter_code>#List load shortnames of SYNTHETIC subset with only one appliance
lit.list_loads(subset=lit.Subset.SYNTHETIC, n_appliances=1) 
#List load shortnames of SYNTHETIC subset with 2 appliances
lit.list_loads(subset=lit.Subset.SYNTHETIC, n_appliances=2)
#List load shortnames of SYNTHETIC subset with 3 appliances
lit.list_loads(subset=lit.Subset.SYNTHETIC, n_appliances=3)
#List load shortnames of SYNTHETIC subset with 8 appliances
lit.list_loads(subset=lit.Subset.SYNTHETIC, n_appliances=8)<jupyter_output><empty_output><jupyter_text>Waveform filesAfter the matlab preprocessing, you can get all the waveforms filenames of a load in the dataset. Just use the list_waveforms function specifying the subset and the load shortname.<jupyter_code>waveform_files, root = lit.list_waveforms(subset=lit.Subset.SYNTHETIC, shortname='1A0')

#Print content of waveform_files and root
print('waveform_files:', waveform_files, '\n')
print('root:', root)<jupyter_output>waveform_files: ['Waveform10000.mat', 'Waveform10001.mat', 'Waveform10002.mat', 'Waveform10003.mat', 'Waveform10004.mat', 'Waveform10005.mat', 'Waveform10006.mat', 'Waveform10007.mat', 'Waveform10008.mat', 'Waveform10009.mat', 'Waveform10010.mat', 'Waveform10011.mat', 'Waveform10012.mat', 'Waveform10013.mat', 'Waveform10014.mat', 'Waveform10015.mat'] 

root: LIT_Dataset/Matlab_Data/Synthetic/1/1A0<jupyter_text>Loading waveform fileYou can load data from a mat file of the dataset lit (obviously, only after pre-processing Matlab scripts). To do this, instantiate the *Waveform* class setting the *mat_path* parameter as the path to the mat file to be loaded.<jupyter_code>from os.path import join

waveform_filename = join(root, waveform_files[0])  #'LIT_Dataset/Matlab_Data/Synthetic/1/1A0/Waveform10000.mat'

waveform_obj = lit.Waveform(mat_path=waveform_filename)

print('shortname:', waveform_obj.load_short_name)
print('description:', waveform_obj.load_description)
print('frequency:', waveform_obj.frequency)
print('duration:', waveform_obj.duration)
print('sample rate:', waveform_obj.sample_rate)<jupyter_output>shortname: 1A0
description: Microwave, Consul 17 liters CMS18BBHNA,127V 1200W - standby 4.5W
frequency: 60
duration: 30
sample rate: 15384<jupyter_text>Getting the current signalThe *current* attibute of the Waveform object has the entire current signal.<jupyter_code>plt.plot(waveform_obj.current) #plot entire current
plt.show()<jupyter_output><empty_output><jupyter_text>Note that in this entire current signal, there is a period before the appliance is turned on and another after the appliance is turned off.To obtain the indices on this signal where each appliance is turned on, use the *get_turnon_indexes* method. This will return a list of tuples in the format (index, appliance_shortname).<jupyter_code>waveform_obj.get_turnon_indexes()<jupyter_output><empty_output><jupyter_text>To obtain the indices on this signal where each appliance is turned off, use the *get_turnoff_indexes* method. This will return a list of tuples in the same format.<jupyter_code>waveform_obj.get_turnoff_indexes()<jupyter_output><empty_output><jupyter_text>To obtain only the current of all appliances turned on, use the *get_turnedon_current* method.<jupyter_code>plt.plot( waveform_obj.get_turnedon_current() ) #plot the current between turning-on and turning-off
plt.show()
plt.plot( waveform_obj.get_turnedon_current()[0:1000] ) #plot the turnedon current between the samples 0 and 1000
plt.show()<jupyter_output><empty_output><jupyter_text>Getting voltage signalThe *voltage* attribute of the Waveform object has the voltage signal.<jupyter_code>plt.plot(waveform_obj.voltage) #plot entire voltage
plt.show()<jupyter_output><empty_output><jupyter_text>To get only the voltage signal with all appliances turned on, use the *get_turnedon_voltage* method.<jupyter_code>plt.plot(waveform_obj.get_turnedon_voltage()) #plot the voltage between turning-on and turning-off
plt.show()
plt.plot(waveform_obj.get_turnedon_voltage()[0:1000]) #plot the turnedon voltage between the samples 0 and 1000
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0859479305740988, 'fraction_numerical': 0.0267022696929239, 'mean_word_length': 6.614993646759848, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 40, 'https://': 2, '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': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '259792', 'license': 'MIT', 'n_tokens_mistral': 2023, 'n_tokens_neox': 1848, 'n_words': 625, 'path': 'tutorial.ipynb', 'repo_name': 'FilipeChagasDev/LIT-Dataset-Python-Library', 'size': '5999'}