Author: tlinnet Date: Sat Jun 7 21:43:16 2014 New Revision: 23722 URL: http://svn.gna.org/viewcvs/relax?rev=23722&view=rev Log: Modified profiling script to have different number of NCYC points per frequency. This is to complicate the data, so any errournous reshaping of data is discovered. It is expected, that experiments can have different number of NCYC points per spectrometer frequency. Task #7807 (https://gna.org/task/index.php?7807): Speed-up of dispersion models for Clustered analysis. Modified: branches/disp_spin_speed/test_suite/shared_data/dispersion/profiling/profiling_cr72.py Modified: branches/disp_spin_speed/test_suite/shared_data/dispersion/profiling/profiling_cr72.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_spin_speed/test_suite/shared_data/dispersion/profiling/profiling_cr72.py?rev=23722&r1=23721&r2=23722&view=diff ============================================================================== --- branches/disp_spin_speed/test_suite/shared_data/dispersion/profiling/profiling_cr72.py (original) +++ branches/disp_spin_speed/test_suite/shared_data/dispersion/profiling/profiling_cr72.py Sat Jun 7 21:43:16 2014 @@ -24,7 +24,7 @@ # Python module imports. import cProfile from os import getcwd, path -from numpy import array, int32, float64, ones, pi, zeros +from numpy import array, arange, asarray, int32, float64, ones, pi, zeros import pstats import sys @@ -51,11 +51,11 @@ def main(): s_filename = 'single' # Profile for a single spin. - cProfile.run('single(iter=100)', s_filename) + cProfile.run('single(iter=1000)', s_filename) c_filename = 'cluster' # Profile for a cluster of 100 spins. - cProfile.run('cluster(iter=100)', c_filename) + cProfile.run('cluster(iter=1000)', c_filename) # Read all stats files into a single object s_stats = pstats.Stats(s_filename) @@ -79,7 +79,7 @@ Class Profile inherits the Dispersion container class object. """ - def __init__(self, num_spins=1, num_points=10, model=None): + def __init__(self, num_spins=1, model=None): """ Special method __init__() is called first (acts as Constructor). It brings in data from outside the class like the variable num_spins. @@ -93,19 +93,25 @@ # Define parameters self.model = model self.num_spins = num_spins - #self.fields = [800. * 1E6] - self.fields = [600. * 1E6, 800. * 1E6] - #self.fields = [600. * 1E6, 800. * 1E6, 900. * 1E6] + #self.fields = array([800. * 1E6]) + #self.fields = array([600. * 1E6, 800. * 1E6]) + self.fields = array([600. * 1E6, 800. * 1E6, 900. * 1E6]) self.exp_type = [EXP_TYPE_CPMG_SQ] self.offset = [0] # Required data structures. - self.num_points = num_points - self.ncyc_list = range(2, 2*self.num_points + 1, 2) - self.relax_time = 0.04 - self.points = array(self.ncyc_list) / self.relax_time - self.value = array(range(1,len(self.ncyc_list)+1), float64) * 1.00 - self.error = ones(len(self.ncyc_list), float64) * 0.01 + self.relax_times = self.fields / (100 * 100. *1E6 ) + self.ncycs = [] + for i in range(len(self.fields)): + inp = arange(2, 1000. * self.relax_times[i], 4) + self.ncycs.append(inp) + print("sfrq: ", self.fields[i], "number of cpmg frq", len(inp)) + self.ncycs = asarray(self.ncycs) + + self.points = self.ncycs / self.relax_times + + self.value = self.points * 1.1 + self.error = self.value * 0.1 # Make nested list arrays of data. And return them. values, errors, cpmg_frqs, missing, frqs, exp_types, relax_times, offsets = self.return_r2eff_arrays() @@ -184,22 +190,22 @@ for mi in range(len(self.fields)): frq = self.fields[mi] for oi in range(len(self.offset)): - for di in range(len(self.points)): + for di in range(len(self.points[mi])): # The Larmor frequency for this spin (and that of an attached proton for the MMQ models) and field strength (in MHz*2pi to speed up the ppm to rad/s conversion). frqs[ei][si][mi] = 2.0 * pi * frq / g1H * g15N * 1e-6 - cpmg_frqs[ei][mi][oi] = self.points + cpmg_frqs[ei][mi][oi] = self.points[mi] missing[ei][si][mi][oi].append(0) # Values - values[ei][si][mi][oi].append(self.value[di]) + values[ei][si][mi][oi].append(self.value[mi][di]) # The errors. - errors[ei][si][mi][oi].append(self.error[di]) + errors[ei][si][mi][oi].append(self.error[mi][di]) # The relaxation times. # Found. - relax_time = self.relax_time + relax_time = self.relax_times[mi] # Store the time. relax_times[ei][mi] = relax_time @@ -216,6 +222,7 @@ values[ei][si][mi][oi] = array(values[ei][si][mi][oi], float64) errors[ei][si][mi][oi] = array(errors[ei][si][mi][oi], float64) missing[ei][si][mi][oi] = array(missing[ei][si][mi][oi], int32) + # Return the structures. return values, errors, cpmg_frqs, missing, frqs, exp_types, relax_times, offsets @@ -332,13 +339,11 @@ return chi2 -def single(num_spins=1, num_points=20, model=MODEL_CR72_FULL, iter=None): +def single(num_spins=1, model=MODEL_CR72_FULL, iter=None): """Calculate for a single spin. @keyword num_spins: Number of spins in the cluster. @type num_spins: integer - @keyword num_points: The number of points the R2eff array should consists of. - @type num_points: integer @keyword model: The dispersion model to instantiate the Dispersion class with. @type model: string @keyword iter: The number of iterations to perform the function call. @@ -348,7 +353,7 @@ """ # Instantiate class - C1 = Profile(num_spins=num_spins, num_points=num_points, model=model) + C1 = Profile(num_spins=num_spins, model=model) # Assemble the parameter list. params = C1.assemble_param_vector(r2a=5.0, r2b=10.0, dw=3.0, pA=0.9, kex=1000.0, spins_params=['r2a', 'r2b', 'dw', 'pA', 'kex']) @@ -358,13 +363,11 @@ chi2 = C1.calc(params) -def cluster(num_spins=100, num_points=20, model=MODEL_CR72_FULL, iter=None): +def cluster(num_spins=100, model=MODEL_CR72_FULL, iter=None): """Calculate for a number of clustered spins. @keyword num_spins: Number of spins in the cluster. @type num_spins: integer - @keyword num_points: The number of points the R2eff array should consists of. - @type num_points: integer @keyword model: The dispersion model to instantiate the Dispersion class with. @type model: string @keyword iter: The number of iterations to perform the function call. @@ -374,7 +377,7 @@ """ # Instantiate class - C1 = Profile(num_spins=num_spins, num_points=num_points, model=model) + C1 = Profile(num_spins=num_spins, model=model) # Assemble the parameter list. params = C1.assemble_param_vector(r2a=5.0, r2b=10.0, dw=3.0, pA=0.9, kex=1000.0, spins_params=['r2a', 'r2b', 'dw', 'pA', 'kex']) @@ -389,15 +392,15 @@ main() def test_reshape(): - C1 = Profile(num_spins=4, num_points=20, model=MODEL_CR72_FULL) + C1 = Profile(num_spins=2, model=MODEL_CR72_FULL) end_index = C1.model.end_index - print("end_index:", end_index) + #print("end_index:", end_index) num_spins = C1.model.num_spins - print("num_spins:", num_spins) + #print("num_spins:", num_spins) num_frq = C1.model.num_frq - print("num_frq:", num_frq) + #print("num_frq:", num_frq) params = C1.assemble_param_vector(r2a=5.0, r2b=10.0, dw=3.0, pA=0.9, kex=1000.0, spins_params=['r2a', 'r2b', 'dw', 'pA', 'kex']) - print("params", params) + #print("params", params) R20 = params[:end_index[1]].reshape(num_spins*2, num_frq) R20A = R20[::2].flatten() @@ -416,24 +419,11 @@ r20_index = mi + si*num_frq r20a=R20A[r20_index] r20b=R20B[r20_index] - print "r20a", r20a, "r20b", r20b - - for mi in range(num_frq): - mi_s = mi*num_spins - mi_e = mi_s + num_spins - r20a=R20A[mi_s:mi_e] - r20b=R20B[mi_s:mi_e] - print "r20a", r20a, "r20b", r20b + print("r20a", r20a, "r20b", r20b) values = array(C1.model.values) values = array(values) - ex = values - # (1, 4, 3, 1, 20): ex, spin, frq, off, disp - #print type(ex), len(ex), ex.shape, ex - ex2 = ex.reshape(num_frq*20*num_spins) - #print type(ex2), len(ex2), ex2.shape, ex2 - #print "here" model = C1.calc(params) - print model - -#test_par() + print(model) + +#test_reshape()