<jupyter_start><jupyter_text>Homework 1Please use the function readcorr to read data from the files that start with BR00781 and calculate the average and the std for each time point. Remember that corr_fcts[0] represents the time, and corr_fcts[1] is the correlation function. You need to average over the 20 data sets for each time point. At the end you should have three 1-dimensional arrays: time, corravg, and corrstd. You then just need to uncomment the last cell and create a semilog plot with error bars.Below, I included some hint on how to solve the problem. For example, I show how to obtain a list of filenames that you can loop through to read all the data.Good luck<jupyter_code>import os
import numpy as np
import matplotlib.pyplot as plt
def readcorr(filename):
    with open(filename,'r') as f:
        for line in f:
            if line.startswith("[Corr"):
                break
        corr_fcts=[]
        for line in f:
            if line.startswith("[Raw"):
                break
            corr_fcts.append([float(a) for a in line.split()])
    corr_fcts = np.array(corr_fcts[:-1]).T
    return corr_fcts
# get current working directory
print(os.getcwd())
#defines the location of the data
datadir='data files/'
# get a list of files in this directory
filelist=os.listdir(datadir)
#print(filelist)
# create a list of files starting with "BR00781"
BR00781_list = [file for file in filelist if file.startswith("BR00781")]
BR00781_list
# My Code
corr_fcts = readcorr("data files/BR00781_01.sin")
time=corr_fcts[0]
timeshort=time[(time>1e-7) & (time<0.01)]
corr_fcts=[]
corravg=[]
corrstd=[]
#print("time",time)
#print("data",data)
for file in BR00781_list:
    corr_fcts_temp = readcorr("data files/"+file)
    corr_fcts_temp = corr_fcts_temp[1]
    corr_fcts_temp = corr_fcts_temp[(time>1e-7) & (time<0.01)]
    corr_fcts.append(corr_fcts_temp)
corr_fcts = np.array(corr_fcts).T
for timepoint in range(len(timeshort)):
    corravg.append(np.mean(corr_fcts[timepoint]))
    corrstd.append(np.std(corr_fcts[timepoint]))
%matplotlib inline
#plt.figure()
#plt.errorbar(time,corravg,yerr=corrstd,fmt="or")
#plt.xscale("log")
#plt.xlabel("delta t in sec")
#plt.ylabel("g(t)")
plt.figure()
plt.semilogx(timeshort,corravg)
plt.errorbar(timeshort,corravg,yerr=corrstd,fmt="or")
plt.xscale("log")
plt.xlabel("delta t in sec")
plt.ylabel("g(t)")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11395056556346879, 'fraction_numerical': 0.02346041055718475, 'mean_word_length': 4.527777777777778, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '321337', 'license': 'MIT', 'n_tokens_mistral': 921, 'n_tokens_neox': 859, 'n_words': 246, 'path': 'Programs/PyProg/HW1_HUA.ipynb', 'repo_name': 'xwghua/DRiP-public', 'size': '2387'}