Author: bugman Date: Fri May 3 11:53:46 2013 New Revision: 19628 URL: http://svn.gna.org/viewcvs/relax?rev=19628&view=rev Log: Alphabetical ordering of the functions of the specific_analyses.relax_disp.disp_data module. Modified: branches/relax_disp/specific_analyses/relax_disp/disp_data.py Modified: branches/relax_disp/specific_analyses/relax_disp/disp_data.py URL: http://svn.gna.org/viewcvs/relax/branches/relax_disp/specific_analyses/relax_disp/disp_data.py?rev=19628&r1=19627&r2=19628&view=diff ============================================================================== --- branches/relax_disp/specific_analyses/relax_disp/disp_data.py (original) +++ branches/relax_disp/specific_analyses/relax_disp/disp_data.py Fri May 3 11:53:46 2013 @@ -67,6 +67,83 @@ print("Setting the '%s' spectrum CPMG frequency %s Hz." % (spectrum_id, cdp.cpmg_frqs[spectrum_id])) +def exp_curve_index_from_key(key): + """Convert the exponential curve key into the corresponding index. + + @param key: The exponential curve key - either the CPMG frequency or R1rho spin-lock field strength. + @type key: float + @return: The corresponding index. + @rtype: int + """ + + # CPMG data. + if cdp.exp_type == 'cpmg': + return cdp.cpmg_frqs_list.index(key) + + # R1rho data. + else: + return cdp.spin_lock_nu1_list.index(key) + + +def exp_curve_key_from_index(index): + """Convert the exponential curve key into the corresponding index. + + @param index: The exponential curve index. + @type index: int + @return: The exponential curve key - either the CPMG frequency or R1rho spin-lock field strength. + @rtype: float + """ + + # CPMG data. + if cdp.exp_type == 'cpmg': + return cdp.cpmg_frqs_list[index] + + # R1rho data. + else: + return cdp.spin_lock_nu1_list[index] + + +def intensity_key(exp_key=None, relax_time=None): + """Return the intensity key corresponding to the given exponential curve key and relaxation time. + + @keyword exp_key: The CPMG frequency or R1rho spin-lock field strength used as a key to identify each exponential curve. + @type exp_key: float + @keyword relax_time: The time, in seconds, of the relaxation period. + @type relax_time: float + """ + + # Find all keys corresponding to the given relaxation time. + time_keys = [] + for key in cdp.relax_times: + if cdp.relax_times[key] == relax_time: + time_keys.append(key) + + # Find all keys corresponding to the given exponential key. + exp_keys = [] + if cdp.exp_type == 'cpmg': + data = cdp.cpmg_frqs + else: + data = cdp.spin_lock_nu1 + for key in data: + if data[key] == exp_key: + exp_keys.append(key) + + # The common key. + common_key = [] + for key in time_keys: + if key in exp_keys: + common_key.append(key) + + # Sanity checks. + if len(common_key) == 0: + raise RelaxError("No intensity key could be found for the CPMG frequency or R1rho spin-lock field strength of %s and relaxation time period of %s seconds." % (exp_key, relax_time)) + if len(common_key) != 1: + raise RelaxError("More than one intensity key %s found for the CPMG frequency or R1rho spin-lock field strength of %s and relaxation time period of %s seconds." % (common_key, exp_key, relax_time)) + + # Return the unique key. + return common_key[0] + + def loop_dispersion_point(): """Generator method for looping over all dispersion points (either spin-lock field or nu_CPMG points). @@ -86,42 +163,6 @@ # Yield each unique field strength or frequency. for field in fields: yield field - - -def exp_curve_index_from_key(key): - """Convert the exponential curve key into the corresponding index. - - @param key: The exponential curve key - either the CPMG frequency or R1rho spin-lock field strength. - @type key: float - @return: The corresponding index. - @rtype: int - """ - - # CPMG data. - if cdp.exp_type == 'cpmg': - return cdp.cpmg_frqs_list.index(key) - - # R1rho data. - else: - return cdp.spin_lock_nu1_list.index(key) - - -def exp_curve_key_from_index(index): - """Convert the exponential curve key into the corresponding index. - - @param index: The exponential curve index. - @type index: int - @return: The exponential curve key - either the CPMG frequency or R1rho spin-lock field strength. - @rtype: float - """ - - # CPMG data. - if cdp.exp_type == 'cpmg': - return cdp.cpmg_frqs_list[index] - - # R1rho data. - else: - return cdp.spin_lock_nu1_list[index] def loop_exp_curve(): @@ -143,81 +184,6 @@ yield i, key -def intensity_key(exp_key=None, relax_time=None): - """Return the intensity key corresponding to the given exponential curve key and relaxation time. - - @keyword exp_key: The CPMG frequency or R1rho spin-lock field strength used as a key to identify each exponential curve. - @type exp_key: float - @keyword relax_time: The time, in seconds, of the relaxation period. - @type relax_time: float - """ - - # Find all keys corresponding to the given relaxation time. - time_keys = [] - for key in cdp.relax_times: - if cdp.relax_times[key] == relax_time: - time_keys.append(key) - - # Find all keys corresponding to the given exponential key. - exp_keys = [] - if cdp.exp_type == 'cpmg': - data = cdp.cpmg_frqs - else: - data = cdp.spin_lock_nu1 - for key in data: - if data[key] == exp_key: - exp_keys.append(key) - - # The common key. - common_key = [] - for key in time_keys: - if key in exp_keys: - common_key.append(key) - - # Sanity checks. - if len(common_key) == 0: - raise RelaxError("No intensity key could be found for the CPMG frequency or R1rho spin-lock field strength of %s and relaxation time period of %s seconds." % (exp_key, relax_time)) - if len(common_key) != 1: - raise RelaxError("More than one intensity key %s found for the CPMG frequency or R1rho spin-lock field strength of %s and relaxation time period of %s seconds." % (common_key, exp_key, relax_time)) - - # Return the unique key. - return common_key[0] - - -def relax_time(time=0.0, spectrum_id=None): - """Set the relaxation time period associated with a given spectrum. - - @keyword time: The time, in seconds, of the relaxation period. - @type time: float - @keyword spectrum_id: The spectrum identification string. - @type spectrum_id: str - """ - - # Test if the spectrum id exists. - if spectrum_id not in cdp.spectrum_ids: - raise RelaxNoSpectraError(spectrum_id) - - # Initialise the global relaxation time data structures if needed. - if not hasattr(cdp, 'relax_times'): - cdp.relax_times = {} - if not hasattr(cdp, 'relax_time_list'): - cdp.relax_time_list = [] - - # Add the time, converting to a float if needed. - cdp.relax_times[spectrum_id] = float(time) - - # The unique time points. - if cdp.relax_times[spectrum_id] not in cdp.relax_time_list: - cdp.relax_time_list.append(cdp.relax_times[spectrum_id]) - cdp.relax_time_list.sort() - - # Update the exponential time point count. - cdp.num_time_pts = len(cdp.relax_time_list) - - # Printout. - print("Setting the '%s' spectrum relaxation time period to %s s." % (spectrum_id, cdp.relax_times[spectrum_id])) - - def loop_spectrometer(): """Generator method for looping over all spectrometer field data. @@ -238,6 +204,40 @@ yield field +def relax_time(time=0.0, spectrum_id=None): + """Set the relaxation time period associated with a given spectrum. + + @keyword time: The time, in seconds, of the relaxation period. + @type time: float + @keyword spectrum_id: The spectrum identification string. + @type spectrum_id: str + """ + + # Test if the spectrum id exists. + if spectrum_id not in cdp.spectrum_ids: + raise RelaxNoSpectraError(spectrum_id) + + # Initialise the global relaxation time data structures if needed. + if not hasattr(cdp, 'relax_times'): + cdp.relax_times = {} + if not hasattr(cdp, 'relax_time_list'): + cdp.relax_time_list = [] + + # Add the time, converting to a float if needed. + cdp.relax_times[spectrum_id] = float(time) + + # The unique time points. + if cdp.relax_times[spectrum_id] not in cdp.relax_time_list: + cdp.relax_time_list.append(cdp.relax_times[spectrum_id]) + cdp.relax_time_list.sort() + + # Update the exponential time point count. + cdp.num_time_pts = len(cdp.relax_time_list) + + # Printout. + print("Setting the '%s' spectrum relaxation time period to %s s." % (spectrum_id, cdp.relax_times[spectrum_id])) + + def spin_lock_field(spectrum_id=None, field=None): """Set the spin-lock field strength (nu1) for the given spectrum.