<jupyter_start><jupyter_text>mtlab tutorial  import repo "mtlab"then copy the `mtlab.py` to main dir<jupyter_code>!git clone "https://github.com/ttt50966/mtlab"
!cp ./mtlab/mtlab.py ./<jupyter_output><empty_output><jupyter_text>import module "mtlab"<jupyter_code>import mtlab<jupyter_output><empty_output><jupyter_text>help function<jupyter_code>help(mtlab)<jupyter_output>Help on module mtlab:

NAME
    mtlab

FUNCTIONS
    diff_fit_data(params, x)
    
    diff_fitting(params, x, y)
        import lmfit
        params = lmfit.Parameters() # Add new fitting objects
        params.add('A',value=-0.08)
        params.add('B',value=0.1)
        params.add('T', value=5)
        params.add('H', value=800)
    
    diff_residual(params, x, y)
    
    fitting_init()
    
    moving_average(interval, windowsize)
        This is a smooth function
        interval is the original data
        windowsize can set 3~10
    
    plot(line, dpiValue, title, xlabel, ylabel, saveFig)
        This is a template for plotting
        line would be [{
            "x" : [],
            "y": [],
            "label" : ""
        }]
        
        dpiValue is integer like 300
        title, xlabel and ylabel are string
        saveFig is a boolean

FILE
    /content/mtlab.py<jupyter_text>mtlab.plot<jupyter_code>import pandas as pd
df1 = pd.read_csv("/content/mtlab/test_data/plot_test.csv")
df1
line = []
for i in range(1,3):
  line.append({
      "x":df1["x"+str(i)].values,
      "y":df1["y"+str(i)].values,
      "label": "line "+str(i)
      })
mtlab.plot(line,150,"Plot","x","y",False)<jupyter_output><empty_output><jupyter_text>Fitting<jupyter_code>mtlab.fitting_init()
df2 = pd.read_csv("/content/mtlab/test_data/fitting.csv")
df2.head()
data = [{
    "x":df2.x.values,
    "y":df2.y.values,
    "label":"original"
}]    
mtlab.plot(data,150,"Fitting","x","y",False)
import lmfit
params = lmfit.Parameters() # Add new fitting objects
params.add('A',value=-0.08)
params.add('B',value=0.1)
params.add('T', value=5)
params.add('H', value=800)
out = mtlab.diff_fitting(params,data[0]["x"],data[0]["y"])
out.params
data.append({"x":data[0]["x"],"y":mtlab.diff_fit_data(out.params,data[0]["x"]),"label":"fitting"})
mtlab.plot(data,150,"Fitting","x","y",False)
data_smooth = [data[0]]
for i in range(2,6):
  sm = mtlab.moving_average(data[0]["y"],i)
  d = {"x":data[0]["x"],"y":sm,"label":"window size "+str(i)}
  data_smooth.append(d)
mtlab.plot(data_smooth,150,"Smooth","x","y",False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17501988862370724, 'fraction_numerical': 0.02386634844868735, 'mean_word_length': 3.8365384615384617, 'pattern_counts': {'":': 13, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 1, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '622657', 'license': 'MIT', 'n_tokens_mistral': 1007, 'n_tokens_neox': 956, 'n_words': 159, 'path': 'test_data/examples.ipynb', 'repo_name': 'ttt50966/mtlab', 'size': '2514'}