mailRe: r26975 - /trunk/pipe_control/spectrum.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by Edward d'Auvergne on December 06, 2014 - 16:01:
Hi Troels,

Just to catch possible problems with integer ratio in Python 2, I
would suggest passing pint and pint_err through the float() builtin
function.  It probably will not happen very often, but this could
cause a lot of bugs when peak heights and errors are low integer
values.

Regards,

Edward


On 6 December 2014 at 14:45,  <tlinnet@xxxxxxxxxxxxx> wrote:
Author: tlinnet
Date: Sat Dec  6 14:45:16 2014
New Revision: 26975

URL: http://svn.gna.org/viewcvs/relax?rev=26975&view=rev
Log:
Added the pipe_control.spectrum.signal_noise_ratio() backend function, for 
calculation of the signal to noise ratio per spin.

Modified:
    trunk/pipe_control/spectrum.py

Modified: trunk/pipe_control/spectrum.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/pipe_control/spectrum.py?rev=26975&r1=26974&r2=26975&view=diff
==============================================================================
--- trunk/pipe_control/spectrum.py      (original)
+++ trunk/pipe_control/spectrum.py      Sat Dec  6 14:45:16 2014
@@ -32,7 +32,7 @@

 # relax module imports.
 from lib.errors import RelaxError, RelaxImplementError, RelaxNoSpectraError
-from lib.io import write_data
+from lib.io import sort_filenames, write_data
 from lib.text.sectioning import section
 from lib.spectrum.peak_list import read_peak_list
 from lib.statistics import std
@@ -865,3 +865,73 @@

     # Return the list.
     return repl
+
+
+def signal_noise_ratio(verbose=True):
+    """Calculate the signal to noise ratio per spin.
+
+    @keyword verbose:       A flag which if True will print additional 
information out.
+    @type verbose:          bool
+    """
+
+    # Tests.
+    check_pipe()
+    check_mol_res_spin_data()
+
+    # Test if spectra have been loaded.
+    if not hasattr(cdp, 'spectrum_ids'):
+        raise RelaxError("No spectra have been loaded.")
+
+    # Possible print.
+    if verbose:
+        print("\nThe following signal to noise ratios has been 
calculated:\n")
+
+    # Set the spin specific signal to noise ratio.
+    for spin, spin_id in spin_loop(return_id=True):
+        # Skip deselected spins.
+        if not spin.select:
+            continue
+
+        # Skip spins missing intensity data.
+        if not hasattr(spin, 'peak_intensity'):
+            continue
+
+        # Test if error analysis has been performed.
+        if not hasattr(spin, 'peak_intensity_err'):
+            raise RelaxError("Intensity error analysis has not been 
performed.  Please see spectrum.error_analysis().")
+
+        # If necessary, create the dictionary.
+        if not hasattr(spin, 'sn_ratio'):
+            spin.sn_ratio = {}
+
+        # Loop over the ID.
+        ids = []
+        for id in spin.peak_intensity:
+            # Append the ID to the list.
+            ids.append(id)
+
+            # Calculate the sn_ratio.
+            pint = spin.peak_intensity[id]
+            pint_err = spin.peak_intensity_err[id]
+            sn_ratio = pint / pint_err
+
+            # Assign the sn_ratio.
+            spin.sn_ratio[id] = sn_ratio
+
+        # Sort the ids alphanumeric.
+        ids = sort_filenames(filenames=ids, rev=False)
+
+        # Collect the data under sorted ids.
+        data_i = []
+        for id in ids:
+            # Get the values.
+            pint = spin.peak_intensity[id]
+            pint_err = spin.peak_intensity_err[id]
+            sn_ratio = spin.sn_ratio[id]
+
+            # Store the data.
+            data_i.append([id, repr(pint), repr(pint_err), repr(sn_ratio)])
+
+        if verbose:
+            section(file=sys.stdout, text="Signal to noise ratio for spin 
ID '%s'"%spin_id, prespace=1)
+            write_data(out=sys.stdout, headings=["Spectrum ID", "Signal", 
"Noise", "S/N"], data=data_i)


_______________________________________________
relax (http://www.nmr-relax.com)

This is the relax-commits mailing list
relax-commits@xxxxxxx

To unsubscribe from this list, get a password
reminder, or change your subscription options,
visit the list information page at
https://mail.gna.org/listinfo/relax-commits



Related Messages


Powered by MHonArc, Updated Sat Dec 06 16:20:14 2014