<jupyter_start><jupyter_text>Import k-space data<jupyter_code>numexpr=400
noise=0.001
csv_path=f"./data/train_data{numexpr}_noise{noise}_d6.csv"
complete_df = pd.read_csv(csv_path,index_col=0)
complete_df.head()<jupyter_output><empty_output><jupyter_text>Calculate average signal intensity for each k-space point<jupyter_code>avg_df=pd.DataFrame(complete_df.mean(axis=0)).transpose()
avg_df=avg_df.drop(columns=['mean','sd'])
avg_df=avg_df.transpose().reset_index().rename(columns={'index':'k-space',0:'signal'})
avg_df['k-space']=avg_df['k-space'].str.slice(7,-2)
avg_df['k-space'] = avg_df['k-space'].replace('',0)
avg_df['k-space']= avg_df['k-space'].astype(int).apply(lambda x: -int(x) if int(x)>0 else 0)
avg_df<jupyter_output><empty_output><jupyter_text>Extract a single row(single simulated experiment)<jupyter_code>row_nm=90
single_row=complete_df.iloc[[row_nm]]
# Save mean D and SD as seperate parameters and drop them from df
distr=single_row[['mean','sd']]
single_row=single_row.drop(columns=['mean','sd'])

# Transpose df so that k-space points are a new row and signal is a row as well
single_df=pd.DataFrame()
single_df=single_row.transpose().reset_index().rename(columns={'index':'k-space',row_nm:'signal'})

#Slice k-space row to remove letters and save only k-space points from negative to zero
single_df['k-space']=single_df['k-space'].str.slice(7,-2)
single_df['k-space'] = single_df['k-space'].replace('',0)
single_df['k-space']= single_df['k-space'].astype(int).apply(lambda x: -int(x) if int(x)>0 else 0)
single_df
distr["mean"].iloc[0]<jupyter_output><empty_output><jupyter_text>Plot real space and k-space data<jupyter_code>#Calculate rolling average of the single experiment data in case this is needed
single_df['rolling_avg'] = single_df['signal'].rolling(window=2).mean().shift(-1)
single_df['rolling_avg']<jupyter_output><empty_output><jupyter_text>Plot single experiment k-space signal and average signal of multiple experiments<jupyter_code>#Define plot parameters

sns.set_style("ticks", {"xtick.major.size": 200, "ytick.major.size": 1})

fig, ax = plt.subplots(figsize=(12,8))



#Change tick mark labels font size
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)

#Create actual seborn graph
graph=sns.lineplot(data=single_df, x="k-space", y='signal',color='grey')#, fit_reg=False
#graph_avg=sns.lineplot(data=avg_df, x="k-space", y='signal',color='black', linestyle='--')#, fit_reg=False

#Change axis labels
plt.xlabel("k-space (invese space a.u.)",fontsize=14, labelpad=10)
plt.ylabel("Signal intensity (a.u.)",fontsize=14, labelpad=10)
title="K-space signal for spheres with mean="+str(distr["mean"].iloc[0])+" and sd="+str(distr["sd"].iloc[0])
plt.title(title, size=20, pad=20)

# control x and y limits
plt.xlim(-128,1)
ax.set( yscale="log")

#set tickmarks direction
plt.tick_params(direction="in")

#specify secondary axis similar to primary repeat all that we did above
#Xaxis first
secax = ax.secondary_xaxis('top')
secax.set_xlim([-128, 1])
secax.tick_params(axis="both",direction="in",which="both", pad=10, colors='black')
secax.set_xticklabels([]);

#Yaxis second
secax2 = ax.secondary_yaxis('right')
secax2.tick_params(axis="both",direction="in",which="both", pad=10, colors='black')
secax2.set_yticklabels([]);

plt.savefig("figures/K-space signal for spheres with mean="+str(int(distr["mean"].iloc[0])), bbox_inches='tight')<jupyter_output><empty_output><jupyter_text>Plot real space signal for same sample as k-space signal<jupyter_code>real_df=real_space_profile(diam=distr["mean"].iloc[0],sd=distr["sd"].iloc[0],sphere_num=150)
sns.set_style("ticks", {"xtick.major.size": 200, "ytick.major.size": 1})

fig, ax = plt.subplots(figsize=(12,8))



#Change tick mark labels font size
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)

#Create actual seborn graph
graph=sns.lineplot(data=real_df, x="space", y='signal',color='grey')#, fit_reg=False


#Change axis labels
plt.xlabel("Real Space (a.u.)",fontsize=14, labelpad=10)
plt.ylabel("Signal intensity (a.u.)",fontsize=14, labelpad=10)
title="1D real space profile for spheres with mean="+str(distr["mean"].iloc[0])+" and sd="+str(distr["sd"].iloc[0])
plt.title(title, size=20, pad=20)

# control x and y limits
plt.xlim(0,128)

#set tickmarks direction
plt.tick_params(direction="in")

#specify secondary axis similar to primary repeat all that we did above
#Xaxis first
secax = ax.secondary_xaxis('top')
secax.set_xlim([0, 128])
secax.tick_params(axis="both",direction="in",which="both", pad=10, colors='black')
secax.set_xticklabels([]);

#Yaxis second
secax2 = ax.secondary_yaxis('right')
secax2.tick_params(axis="both",direction="in",which="both", pad=10, colors='black')
secax2.set_yticklabels([]);

plt.savefig("figures/1D real space profile for spheres with mean="+str(int(distr["mean"].iloc[0])), bbox_inches='tight')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17607084019769356, 'fraction_numerical': 0.02368204283360791, 'mean_word_length': 8.523529411764706, 'pattern_counts': {'":': 4, '<': 25, '<?xml version=': 0, '>': 27, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '426410', 'license': 'MIT', 'n_tokens_mistral': 1889, 'n_tokens_neox': 1799, 'n_words': 336, 'path': 'Signal_Analysis.ipynb', 'repo_name': 'kziovas/UniOfPiraeusMScThesisProject', 'size': '4856'}