<jupyter_start><jupyter_text>LZW decompression algorihm<jupyter_code>import pandas as pd
from collections import namedtuple
import warnings
warnings.filterwarnings('ignore')<jupyter_output><empty_output><jupyter_text>SOURCEShttps://stackoverflow.com/questions/20036161/can-we-draw-digital-waveform-graph-with-pyplot-in-python-or-matlab  Data<jupyter_code>data = pd.read_csv('waveform.csv')
data.shape
a = data[data.columns[3]]
for i in a:
    try:
        t = int(str(i),2)
        print(t)
    except:
        print('error',i)
tha to gamiso giati?<jupyter_output><empty_output><jupyter_text>Column to decompress<jupyter_code>int('00000000000000000000000000000000',2)
vals = data[data.columns[3]].apply(int,args=(2,)).values
vals
keep = vals[vals<5000]
keep<jupyter_output><empty_output><jupyter_text>f = open('./output.lzw','r')lines = f.readlines()f.close() keep = []for line in lines:    keep.append(int(line.strip().split('=')[-1].split(' ')[0]))len(keep) keep lines[0] lines[0].split(' ')[-1] [int(l) for l in lines[0].split(' ')] keep = []for l in lines[0].split(' '):    if l=='':        print(l)        continue    try:        keep.append(int(l))        except:        print('error: ', l)<jupyter_code>col = 'TRIGGER'

# compressed = data[col].values

dictionaryArray = [namedtuple("MyStruct", "prefix character") for i in range(2023)]
def decode(code):
    if code>999:
        character = dictionaryArray[code].character
        temp = decode(dictionaryArray[code].prefix)
    else:
        character = code
        temp = code
    output.append(character)
    return temp
compressed = keep
dictionarySize=2023
previousCode = compressed[0]
output = []
output.append(previousCode)
index = len(compressed)-1
nextCode = 1000
for i in range(index):
    print('iteration: ', i)
    curentCode = compressed[i+1]
    print('current code: ',curentCode)
    print('previous code: ',previousCode)
    if curentCode >= nextCode:
        print('[-] first')
        firstChar = decode(previousCode)  
        print('first char: ', firstChar)
        output.append(firstChar)   
    
    else:
        print('[-] second')
        firstChar = decode(curentCode)
        print('first char: ', firstChar)
        
    if nextCode < dictionarySize:
        print('[-] third')
        dictionaryArray[nextCode].prefix = previousCode
        dictionaryArray[nextCode].character = firstChar    
        nextCode +=1
    print('next code', nextCode)
    print(' ')    
    previousCode = curentCode
len(output)/float(len(keep))
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['figure.figsize'] = 15, 5
def my_lines(ax, pos, *args, **kwargs):
    if ax == 'x':
        for p in pos:
            plt.axvline(p, *args, **kwargs)
    else:
        for p in pos:
#             print(p)
            plt.axhline(p, *args, **kwargs)

bits = output[1:]
data = np.repeat(bits, 2)
clock = 1 - np.arange(len(data)) % 2
manchester = 1 - np.logical_xor(clock, data)
t = 0.5 * np.arange(len(data))

plt.hold(True)

my_lines('x', range(len(bits)+1), color='.5', linewidth=2)

my_lines('y', [0.5, 2, 4], color='.5', linewidth=2)

plt.step(t, clock + 4, 'r', linewidth = 2, where='post')
plt.step(t, data + 2, 'r', linewidth = 2, where='post')
plt.step(t, manchester, 'r', linewidth = 2, where='post')
plt.ylim([-1,6])

for tbit, bit in enumerate(bits):
    plt.text(tbit + 0.5, 1.5, str(bit))

plt.gca().axis('off')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16177751960499565, 'fraction_numerical': 0.030496659889631135, 'mean_word_length': 3.629032258064516, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '549677', 'license': 'Apache-2.0', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1193, 'n_words': 255, 'path': 'decompression.ipynb', 'repo_name': 'gpamfilis/CoDe', 'size': '3443'}