2222import re
2323import sys
2424
25- import matplotlib .pyplot as plt
2625import numpy as np
27- import scipy as sp
28- from scipy .optimize import leastsq
2926
27+ from diffpy .srmise import srmiselog
3028from diffpy .srmise .baselines import Baseline
3129from diffpy .srmise .modelparts import ModelParts
3230from diffpy .srmise .peaks import Peak , Peaks
3937
4038logger = logging .getLogger ("diffpy.srmise" )
4139
42- from diffpy .srmise import srmiselog
43-
4440
4541class ModelCovariance (object ):
4642 """Helper class preserves uncertainty info (full covariance matrix) for a fit model.
@@ -201,8 +197,8 @@ def transform(self, in_format, out_format, **kwds):
201197 subg = np .identity (p .npars (True ))
202198 except Exception as e :
203199 logger .warning (
204- "Transformation gradient failed for part %i: %s. Failed with message %s. Ignoring transformation. "
205- % (i , str (p ), str (e ))
200+ "Transformation gradient failed for part %i: %s. "
201+ "Failed with message %s. Ignoring transformation." % (i , str (p ), str (e ))
206202 )
207203 subg = np .identity (p .npars (True ))
208204
@@ -211,8 +207,8 @@ def transform(self, in_format, out_format, **kwds):
211207 p .pars = p .owner ().transform_parameters (p .pars , in_format , out_format )
212208 except Exception as e :
213209 logger .warning (
214- "Parameter transformation failed for part %i: %s. Failed with message %s. Ignoring transformation. "
215- % (i , str (p ), str (e ))
210+ "Parameter transformation failed for part %i: %s. "
211+ "Failed with message %s. Ignoring transformation." % (i , str (p ), str (e ))
216212 )
217213 subg = np .identity (p .npars (True ))
218214
@@ -600,21 +596,21 @@ def factory(mcstr, **kwds):
600596 baselinefunctions = header [res .end () :].strip ()
601597 header = header [: res .start ()]
602598
603- ### Instantiating baseline functions
599+ # Instantiating baseline functions
604600 if readblf :
605601 blfbaselist = []
606602 res = re .split (r"(?m)^#+ BaselineFunction \d+\s*(?:#.*\s+)*" , baselinefunctions )
607603 for s in res [1 :]:
608604 blfbaselist .append (BaseFunction .factory (s , blfbaselist ))
609605
610- ### Instantiating peak functions
606+ # Instantiating peak functions
611607 if readpf :
612608 pfbaselist = []
613609 res = re .split (r"(?m)^#+ PeakFunction \d+\s*(?:#.*\s+)*" , peakfunctions )
614610 for s in res [1 :]:
615611 pfbaselist .append (BaseFunction .factory (s , pfbaselist ))
616612
617- ### Instantiating header data
613+ # Instantiating header data
618614 # peak_funcs
619615 res = re .search (r"^peak_funcs=(.*)$" , header , re .M )
620616 peak_funcs = eval (res .groups ()[0 ].strip ())
@@ -631,19 +627,19 @@ def factory(mcstr, **kwds):
631627 res = re .search (r"^slice=(.*)$" , header , re .M )
632628 cluster_slice = eval (res .groups ()[0 ].strip ())
633629
634- ### Instantiating BaselineObject
630+ # Instantiating BaselineObject
635631 if re .match (r"^None$" , baselineobject ):
636632 baseline = None
637633 else :
638634 baseline = Baseline .factory (baselineobject , blfbaselist )
639635
640- ### Instantiating model
636+ # Instantiating model
641637 model = Peaks ()
642638 res = re .split (r"(?m)^#+ ModelPeak\s*(?:#.*\s+)*" , model_peaks )
643639 for s in res [1 :]:
644640 model .append (Peak .factory (s , pfbaselist ))
645641
646- ### Instantiating start data
642+ # Instantiating start data
647643 # read actual data - r, y, dy
648644 arrays = []
649645 if hasr :
@@ -664,9 +660,10 @@ def factory(mcstr, **kwds):
664660 # raise SrMiseDataFormatError if something goes wrong
665661 try :
666662 for line in start_data .split ("\n " ):
667- l = line .split ()
668- if len (arrays ) != len (l ):
663+ lines = line .split ()
664+ if len (arrays ) != len (lines ):
669665 emsg = "Number of value fields does not match that given by '%s'" % start_data_info
666+ raise IndexError (emsg )
670667 for a , v in zip (arrays , line .split ()):
671668 a .append (float (v ))
672669 except (ValueError , IndexError ) as err :
@@ -847,7 +844,7 @@ def deletepeak(self, idx):
847844
848845 def estimatepeak (self ):
849846 """Attempt to add single peak to empty cluster. Return True if successful."""
850- ### STUB!!! ###
847+ # STUB!!! ###
851848 # Currently only a single peak function is supported. Dynamic
852849 # selection from multiple types may require additional support
853850 # within peak functions themselves. The simplest method would
@@ -901,7 +898,7 @@ def fit(
901898 if estimate :
902899 try :
903900 self .estimatepeak ()
904- except SrMiseEstimationError as e :
901+ except SrMiseEstimationError :
905902 logger .info ("Fit: No model to fit, estimation not possible." )
906903 return
907904 else :
@@ -1278,7 +1275,7 @@ def prune(self):
12781275 msg = ["====Pruning fits:====" , "Original model:" , "%s" , "w/ quality: %s" ]
12791276 logger .info ("\n " .join (msg ), best_model , best_qual .stat )
12801277
1281- #### Main prune loop ####
1278+ # Main prune loop ####
12821279 while check_models .count (None ) < len (check_models ):
12831280
12841281 # Cache value of individual peaks for best current model.
0 commit comments