Changes

Jump to navigation Jump to search

Matplotlib DPL94 R1rho R2eff

2,892 bytes added, 20:59, 14 March 2014
import os
from math import cos, sin
from numpy import array, float64
### plotting facility.
from pipe_control.mol_res_spin import return_spin, spin_loop
# Import method to calculate the R1_rho offset data
from specific_analyses.relax_disp.disp_data import calc_rotating_frame_params, generate_r20_key, loop_exp_frq, loop_exp_frq_offset, loop_point, return_param_key_from_data, return_spin_lock_nu1from specific_analyses.relax_disp import optimisation
###############
res_state = os.path.join(res_folder, "DPL94", "results")
spin_inte = ":52@N"
 
# Interpolate graph settings
num_points=1000
num_points=100
extend=500.0
extend=500.0
 
################
spin_inte_rep = spin_inte.replace('#', '_').replace(':', '_').replace('@', '_')
# Calculate the offset data
theta_spin_dic, Domega_spin_dic, w_eff_spin_dic, dic_key_list = calc_rotating_frame_params(spin=cdp.myspin, spin_id=spin_inte, verbosity=10)
# Save the data in cdp to access it after execution of script.
cdp.myspin.theta_spin_dic = theta_spin_dic
cdp.myspin.dic_key_list = dic_key_list
# Create spin############################ First creacte back calculated R2eff data for interpolated plots.r2 keysr2keys ############################  # Return the original structure for frq, offsetspin_lock_nu1 = return_spin_lock_nu1(ref_flag=False)# Prepare list to hold new dataspin_lock_nu1_new = [] # Loop over the structures to generate datafor exp_type, frq ei in loop_exp_frqrange(len(spin_lock_nu1)): r2keys# Add a new dimension. spin_lock_nu1_new.append(generate_r20_key[])  # Then loop over the spectrometer frequencies. for mi in range(len(exp_type=exp_type, frq=frqspin_lock_nu1[ei]) ): # Save the keysAdd a new dimension.cdp spin_lock_nu1_new[ei].r2keys = r2keysappend([])
x_w_eff = # Finally the offsets. for oi in range(len(spin_lock_nu1[ei]x_theta = [mi])):x_disp_point = # Add a new dimension. spin_lock_nu1_new[ei]y = [mi]y_R1_rho = .append([])
cdp # No data.mydic = collections.OrderedDict if not len(spin_lock_nu1[ei][mi][oi]): continue
# Interpolate (adding the extended amount to the end). for dic_key di in cdp.myspin.dic_key_listrange(num_points): R1_rho_prime point = cdp.myspin.r2(di + 1) * (max(spin_lock_nu1[cdp.r2keysei][0mi][oi])+extend) / num_points R1 = cdp.myspin.ri_data spin_lock_nu1_new[ei]['R1'mi] R1_rho = cdp.myspin.r2eff[dic_keyoi].append(point)
# Store the R1_rho valueConvert to a numpy array. y_R1_rho.append spin_lock_nu1_new[ei][mi][oi] = array(R1_rhospin_lock_nu1_new[ei][mi][oi], float64)
exp_type# Then back calculate R2eff data for the interpolated points.cdp.myspin.back_calc = optimisation.back_calc_r2eff(spin=cdp.myspin, frq_1e6, offsetspin_id=spin_inte, point spin_lock_nu1= dic_key.split("_"spin_lock_nu1_new)
# Get disp_point, ##### Store the Spin-lock field strengthdata before plotting x_disp_point# Create a dictionary to hold datacdp.mydic = collections.append(floatOrderedDict(point))
# Get w_effLoop over the data structures w_eff for exp_type, frq, offset, ei, mi, oi in loop_exp_frq_offset(return_indices= cdp.myspin.w_eff_spin_dic[dic_key]True): x_w_eff.appendr20_key = generate_r20_key(w_effexp_type=exp_type, frq=frq)
# Get thetaThis is not used, but could be used to get Rex. theta R1_rho_prime = cdp.myspin.theta_spin_dic[dic_key] x_theta.append(theta) # Get Domega Domega = Domega_spin_dicr2[dic_keyr20_key]
# Calculate y valueGet R1 R1_rho_R2eff R1 = (R1_rho - cdp.myspin.ri_data['R1*cos(theta)*cos(theta)) / (sin(theta) * sin(theta))'] yR1_err = cdp.append(R1_rho_R2eff)myspin.ri_data_err['R1']
# Add to dic
if exp_type not in cdp.mydic:
cdp.mydic[exp_type] = collections.OrderedDict()
if frq_1e6 frq not in cdp.mydic[exp_type]: cdp.mydic[exp_type][frq_1e6frq] = collections.OrderedDict() if offset not in cdp.mydic[exp_type][frq_1e6frq]: cdp.mydic[exp_type][frq_1e6frq][offset] = collections.OrderedDict() # X val cdp.mydic[exp_type][frq_1e6frq][offset]['point'] = [] cdp.mydic[exp_type][frq_1e6frq][offset]['point_inter'] = [] cdp.mydic[exp_type][frq][offset]['theta'] = [] cdp.mydic[exp_type][frq_1e6frq][offset]['w_eff'] = [] # Y val cdp.mydic[exp_type][frq_1e6frq][offset]['R1_rho'] = [] cdp.mydic[exp_type][frq_1e6frq][offset]['R1_rho_err'] = [] cdp.mydic[exp_type][frq][offset]['R1_rho_bc'] = [] cdp.mydic[exp_type][frq][offset]['R1_rho_inter'] = [] # Y2 val cdp.mydic[exp_type][frq][offset]['R1_rho_R2eff'] = [] cdp.mydic[exp_type][frq][offset]['R1_rho_R2eff_err'] = []   # Loop over the orginal dispersion points. for point, di in loop_point(exp_type=exp_type, frq=frq, offset=offset, return_indices=True): param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point)  # X val cdp.mydic[exp_type][frq_1e6frq][offset]['point'].append(float(point)) theta = theta_spin_dic[param_key] cdp.mydic[exp_type][frq_1e6frq][offset]['theta'].append(float(theta)) cdp.mydic[exp_type][frq_1e6frq][offset]['w_eff'].append(floatw_eff_spin_dic[param_key])  # Y val R1_rho = cdp.myspin.r2eff[param_key] cdp.mydic[exp_type][frq][offset]['R1_rho'].append(w_effR1_rho) R1_rho_err = cdp.myspin.r2eff_err[param_key] cdp.mydic[exp_type][frq][offset]['R1_rho_err'].append(R1_rho_err) cdp.mydic[exp_type][frq_1e6frq][offset]['R1_rhoR1_rho_bc'].append(floatcdp.myspin.r2eff_bc[param_key])  # Y2 val # Calc R1_rho_R2eff R1_rho_R2eff = (R1_rho- R1*cos(theta)*cos(theta)) / (sin(theta) * sin(theta)) cdp.mydic[exp_type][frq_1e6frq][offset]['R1_rho_R2eff'].append(floatR1_rho_R2eff) R1_rho_R2eff_err = (R1_rho_err - R1_err*cos(theta)*cos(theta)) / (sin(theta) * sin(theta)) cdp.mydic[exp_type][frq][offset]['R1_rho_R2eff_err'].append(R1_rho_R2eff_err)  ## Loop over the new dispersion points. for di in range(len(cdp.myspin.back_calc[ei][0][mi][oi])): point = spin_lock_nu1_new[ei][mi][oi][di]  # X val cdp.mydic[exp_type][frq][offset]['point_inter'].append(R1_rho_R2effpoint # Y val R1_rho = cdp.myspin.back_calc[ei][0][mi][oi][di] cdp.mydic[exp_type][frq][offset]['R1_rho_inter'].append(R1_rho
# Print values in dic
for exptype, frq_dic in cdp.mydic.items():
for frq, offset_dic in frq_dic.items():
for offset, val_dics in offset_dic.items():
print exptype, frq, offset, val_dics['R1_rho'], val_dics['theta']
####### PLOT ###### Modify data
w_eff_div = 10**4
rem_points = 2
x_w_eff_mod = [x/w_eff_div for x in x_w_eff[:-rem_points]]
y_mod = y[:-rem_points]
## Define labels for plotting
plotlabel_R1_rho_R2eff = 'R1_rho_R2eff'
plotlabel_R1_rho = 'R1_rho'
 
ylabel_R1_rho = 'R1_rho [rad.s^-1]'
ylabel_R1_rho_R2eff = 'R1_rho_R2eff [rad.s^-1]'
 
xlabel_theta = 'Rotating frame tilt angle [rad]'
xlabel_w_eff = 'Effective field in rotating frame [%s rad.s^-1]'%(str(w_eff_div))
xlabel_theta = 'Rotating frame tilt angle [rad]'
xlabel_lock = 'Spin-lock field strength [Hz]'
ylabel_R1_rho_R2eff = 'R1_rho_R2eff [rad.s^-1]'
ylabel_R1_rho = 'R1_rho [rad.s^-1]'
# Plot R1_rho_R2eff values in dicfor exptype, frq_dic in cdp.mydic.items(): for frq, offset_dic in frq_dic.items(): for offset, val_dics in offset_dic.items(): # General plot label graphlabel = "%3.1f_%3.3f"%(frq/1E6, offset) graphlabel_bc = "%3.1f_%3.3f_bc"%(frq/1E6, offset) graphlabel_inter = "%3.1f_%3.3f_inter"%(frq/1E6, offset)  # Plot 1: R1_rho as function of w_efftheta. plt.figure(1) plt.errorbar(val_dics['theta'], val_dics['R1_rho'], yerr=val_dics['R1_rho_err'], fmt='o', label=graphlabel) #plt.plot(x_w_eff_modval_dics['theta'], y_modval_dics['R1_rho'], '-o', label=plotlabel_R1_rho_R2effgraphlabel # Plot 2: R1_rho_R2eff as function of w_eff plt.xlabelfigure(xlabel_w_eff2) x_w_eff_mod = [x/w_eff_div for x in val_dics['w_eff']] plt.ylabelerrorbar(ylabel_R1_rho_R2effx_w_eff_mod, val_dics['R1_rho_R2eff'], yerr=val_dics['R1_rho_R2eff_err'], fmt='o', label=graphlabel) #plt.legendplot(loc=x_w_eff_mod, val_dics['R1_rho_R2eff'], 'besto', label=graphlabel # Plot 3: R1_rho as function of as function of disp_point, the Spin-lock field strength plt.gridfigure(True3) line, = plt.ylimplot(val_dics[0'point_inter'],16val_dics['R1_rho_inter'], '-', label=graphlabel_inter) plt.titleerrorbar("%s \n %s as function of %s"%(spin_inteval_dics['point'], val_dics['R1_rho'], yerr=val_dics['R1_rho_err'], fmt='o', ylabel_R1_rho_R2efflabel=graphlabel, xlabel_w_effcolor=line.get_color()) plt.savefigplot("matplotlib_%s_%s_w_effval_dics['point'], val_dics['R1_rho_bc'], 'D', label=graphlabel_bc, color=line.png"%get_color(spin_inte_rep, plotlabel_R1_rho_R2eff) )
# Define settings for each graph# Plot R1_rho_R2eff 1: R1_rho as function of theta.plt.figure()plt.plot(x_theta, y, 'o', label=plotlabel_R1_rho_R2eff1)
plt.xlabel(xlabel_theta)
plt.ylabel(ylabel_R1_rho_R2effylabel_R1_rho)
plt.legend(loc='best')
plt.grid(True)
plt.ylim([0,16])
plt.title("%s \n %s as function of %s"%(spin_inte, ylabel_R1_rho_R2effylabel_R1_rho, xlabel_theta))#plt.savefig("matplotlib_%s_%s_thetas_theta_sep.png"%(spin_inte_rep, plotlabel_R1_rho_R2effplotlabel_R1_rho) )
## Plot 2: R1_rho_R2eff as function of disp_point, the Spin-lock field strengthw_effplt.figure()plt.plot(x_disp_point, y, 'o', label=plotlabel_R1_rho_R2eff2)plt.xlabel(xlabel_lockxlabel_w_eff)
plt.ylabel(ylabel_R1_rho_R2eff)
plt.legend(loc='best')
plt.grid(True)
plt.ylim([0,16])
plt.xlim([0,2])plt.title("%s \n %s as function of %s"%(spin_inte, ylabel_R1_rho_R2eff, xlabel_lockxlabel_w_eff))#plt.savefig("matplotlib_%s_%s_disps_w_eff.png"%(spin_inte_rep, plotlabel_R1_rho_R2eff) )
## Plot 3: R1_rho as function of theta.as function of disp_point, the Spin-lock field strengthplt.figure()plt.plot(x_theta, y_R1_rho, 'o', label=plotlabel_R1_rho3)plt.xlabel(xlabel_thetaxlabel_lock)
plt.ylabel(ylabel_R1_rho)
plt.legend(loc='best')
plt.grid(True)
plt.ylim([0,16])
plt.title("%s \n %s as function of %s"%(spin_inte, ylabel_R1_rho, xlabel_thetaxlabel_lock))plt.savefig("matplotlib_%s_%s_theta.png"%(spin_inte_rep, plotlabel_R1_rho) ) # Plot R1_rho as function of theta.plt.figure()for exptype, frq_dic in cdp.mydic.items(): for frq, offset_dic in frq_dic.items(): for offset, val_dics in offset_dic.items(): graphlabel = "%s_%s"%(frq, offset) plt.plot(val_dics['theta'], val_dics['R1_rho'], '-o', label=graphlabel)plt.ylabel(ylabel_R1_rho)plt.xlabel(xlabel_theta)plt.legend(loc='best')plt.grid(True)plt.ylim([0,16])plt.title("%s \n %s as function of %s"%(spin_inte, ylabel_R1_rho, xlabel_theta))plt.savefig("matplotlib_%s_%s_theta_seps_w_eff.png"%(spin_inte_rep, plotlabel_R1_rhoplotlabel_R1_rho_R2eff) )
plt.show()

Navigation menu