Author: bugman Date: Wed Jul 20 11:20:07 2011 New Revision: 13768 URL: http://svn.gna.org/viewcvs/relax?rev=13768&view=rev Log: Created the replicated_flags() method for returning a dictionary of replicated spectra flags. Modified: branches/gui_testing/generic_fns/spectrum.py Modified: branches/gui_testing/generic_fns/spectrum.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/generic_fns/spectrum.py?rev=13768&r1=13767&r2=13768&view=diff ============================================================================== --- branches/gui_testing/generic_fns/spectrum.py (original) +++ branches/gui_testing/generic_fns/spectrum.py Wed Jul 20 11:20:07 2011 @@ -292,19 +292,16 @@ @type verbosity: int """ - # replicated spectra. - repl = {} - for i in xrange(len(cdp.replicates)): - for j in xrange(len(cdp.replicates[i])): - repl[cdp.replicates[i][j]] = True + # Replicated spectra. + repl = replicated_flags() # Are all spectra replicated? - if len(repl.keys()) == len(cdp.spectrum_ids): + if False in repl.values(): + all_repl = False + print("All spectra replicated: No.") + else: all_repl = True print("All spectra replicated: Yes.") - else: - all_repl = False - print("All spectra replicated: No.") # Test if the standard deviation has already been calculated. if hasattr(cdp, 'sigma_I'): @@ -317,7 +314,7 @@ # Loop over the spectra. for id in cdp.spectrum_ids: # Skip non-replicated spectra. - if not repl.has_key(id): + if not repl[id]: continue # Skip replicated spectra which already have been used. @@ -1106,3 +1103,24 @@ # Set the replicates. cdp.replicates.append(spectrum_ids) + + +def replicated_flags(): + """Create and return a dictionary of flags of whether the spectrum is replicated or not. + + @return: The dictionary of flags of whether the spectrum is replicated or not. + @rtype: dict of bool + """ + + # Initialise all IDs to false. + repl = {} + for id in cdp.spectrum_ids: + repl[id] = False + + # Loop over the replicates. + for i in range(len(cdp.replicates)): + for j in range(len(cdp.replicates[i])): + repl[cdp.replicates[i][j]] = True + + # Return the dictionary. + return repl