18
18
import numpy as np
19
19
from matplotlib import transforms
20
20
21
- import diffpy .srmise .srmiselog
22
- from diffpy .srmise import ModelCluster , PeakStability
23
- from diffpy .srmise .modelevaluators .base import ModelEvaluator
21
+ from diffpy .srmise .modelcluster import ModelCluster
22
+ from diffpy .srmise .peakstability import PeakStability
24
23
25
24
logger = logging .getLogger ("diffpy.srmise" )
26
25
@@ -114,7 +113,7 @@ def makeaics(self, dgs, dr, filename=None):
114
113
if filename is not None :
115
114
try :
116
115
import cPickle as pickle
117
- except :
116
+ except ImportError :
118
117
import pickle
119
118
out_s = open (filename , "wb" )
120
119
pickle .dump (aics_out , out_s )
@@ -126,7 +125,7 @@ def loadaics(self, filename):
126
125
"""Load file containing results of the testall method."""
127
126
try :
128
127
import cPickle as pickle
129
- except :
128
+ except ImportError :
130
129
import pickle
131
130
in_s = open (filename , "rb" )
132
131
aics_in = pickle .load (in_s )
@@ -321,7 +320,7 @@ def classify(self, r, tolerance=0.05):
321
320
exemplar_baseline = self .results [classes [c ][0 ]][2 ]
322
321
323
322
# Check baseline type and number of parameters
324
- if type (baseline ) != type (exemplar_baseline ):
323
+ if type (baseline ) is not type (exemplar_baseline ):
325
324
continue
326
325
if baseline .npars () != exemplar_baseline .npars ():
327
326
continue
@@ -331,7 +330,7 @@ def classify(self, r, tolerance=0.05):
331
330
if len (peaks ) != len (exemplar_peaks ):
332
331
continue
333
332
for p , ep in zip (peaks , exemplar_peaks ):
334
- if type (p ) != type (ep ):
333
+ if type (p ) is not type (ep ):
335
334
badpeak = True
336
335
break
337
336
if p .npars () != ep .npars ():
@@ -341,7 +340,6 @@ def classify(self, r, tolerance=0.05):
341
340
continue
342
341
343
342
# check peak values
344
- current_psqval = []
345
343
for p , ep in zip (psqval , epsqval [c ]):
346
344
basediff = np .abs (np .sum (p - ep ))
347
345
# if basediff > tolerance*np.sum(ep):
@@ -383,7 +381,6 @@ def classify(self, r, tolerance=0.05):
383
381
384
382
def makesortedclasses (self ):
385
383
self .sortedclasses = {}
386
- em = self .ppe .error_method
387
384
388
385
for dg in self .dgs :
389
386
bestinclass = []
@@ -468,13 +465,15 @@ def plot3dclassprobs(self, **kwds):
468
465
dGs - Sequence of dG values to plot. Default is all values.
469
466
highlight - Sequence of dG values to highlight on plot. Default is [].
470
467
classes - Sequence of indices of classes to plot. Default is all classes.
471
- probfilter - [float1, float2]. Only show classes with maximum probability in given range. Default is [0., 1.]
468
+ probfilter - [float1, float2]. Only show classes with maximum probability in given range.
469
+ Default is [0., 1.]
472
470
class_size - Report the size of each class as a "number" or "fraction". Default is "number".
473
471
norm - A colors normalization for displaying number/fraction of models in class. Default is "auto".
474
472
If equal to "full" determined by the total number of models.
475
473
If equal to "auto" determined by the number of models in displayed classes.
476
- cmap - A colormap or registered colormap name. Default is cm.jet. If class_size is "number" and norm is either "auto"
477
- or "full" the map is converted to an indexed colormap.
474
+ cmap - A colormap or registered colormap name. Default is cm.jet.
475
+ If class_size is "number" and norm is either "auto"
476
+ or "full" the map is converted to an indexed colormap.
478
477
highlight_cmap - A colormap or registered colormap name for coloring highlights. Default is cm.gray.
479
478
title - True, False, or a string. Defaults to True, which displays some basic information about the graph.
480
479
p_alpha - Probability graph alpha. (Colorbar remains opaque). Default is 0.7.
@@ -495,12 +494,11 @@ def plot3dclassprobs(self, **kwds):
495
494
496
495
from matplotlib import cm , colorbar , colors
497
496
from matplotlib .collections import PolyCollection
498
- from mpl_toolkits .mplot3d import Axes3D
499
497
500
498
fig = kwds .pop ("figure" , plt .gcf ())
501
499
ax = fig .add_subplot (kwds .pop ("subplot" , 111 ), projection = "3d" )
502
500
503
- cbkwds = kwds .copy ()
501
+ kwds .copy ()
504
502
505
503
# Resolve keywords (title resolved later)
506
504
dGs = kwds .pop ("dGs" , self .dgs )
@@ -530,41 +528,41 @@ def plot3dclassprobs(self, **kwds):
530
528
531
529
# Define face colors
532
530
fc = np .array ([len (self .classes [z ]) for z in zlabels ])
533
- if class_size is "fraction" :
531
+ if class_size == "fraction" :
534
532
fc = fc / float (len (self .results ))
535
533
536
534
# Index the colormap if necessary
537
- if class_size is "number" :
538
- if norm is "auto" :
535
+ if class_size == "number" :
536
+ if norm == "auto" :
539
537
indexedcolors = cmap (np .linspace (0.0 , 1.0 , np .max (fc )))
540
538
cmap = colors .ListedColormap (indexedcolors )
541
- elif norm is "full" :
539
+ elif norm == "full" :
542
540
indexedcolors = cmap (np .linspace (0.0 , 1.0 , len (self .results )))
543
541
cmap = colors .ListedColormap (indexedcolors )
544
542
# A user-specified norm cannot be used to index a colormap.
545
543
546
544
# Create proper norms for "auto" and "full" types.
547
- if norm is "auto" :
548
- if class_size is "number" :
545
+ if norm == "auto" :
546
+ if class_size == "number" :
549
547
mic = np .min (fc )
550
548
mac = np .max (fc )
551
549
nc = mac - mic + 1
552
550
norm = colors .BoundaryNorm (np .linspace (mic , mac + 1 , nc + 1 ), nc )
553
- if class_size is "fraction" :
551
+ if class_size == "fraction" :
554
552
norm = colors .Normalize ()
555
553
norm .autoscale (fc )
556
- elif norm is "full" :
554
+ elif norm == "full" :
557
555
mcolor = len (self .results )
558
- if class_size is "number" :
556
+ if class_size == "number" :
559
557
norm = colors .BoundaryNorm (np .linspace (0 , mcolor + 1 , mcolor + 2 ), mcolor + 1 )
560
- if class_size is "fraction" :
558
+ if class_size == "fraction" :
561
559
norm = colors .Normalize (0.0 , 1.0 )
562
560
563
561
zs = np .arange (len (zlabels ))
564
562
565
563
poly = PolyCollection (verts , facecolors = cmap (norm (fc )), closed = False )
566
564
poly .set_alpha (p_alpha )
567
- cax = ax .add_collection3d (poly , zs = zs , zdir = "y" )
565
+ ax .add_collection3d (poly , zs = zs , zdir = "y" )
568
566
569
567
# Highlight values of interest
570
568
color_idx = np .linspace (0 , 1 , len (highlight ))
@@ -602,12 +600,11 @@ def plot3dclassprobs(self, **kwds):
602
600
)
603
601
604
602
if title is not False :
605
- figtitle = fig .suptitle (title )
603
+ fig .suptitle (title )
606
604
607
605
# Add colorbar
608
606
if "cbpos" in kwds :
609
607
cbpos = kwds .pop ("cbpos" )
610
- aspect = cbpos [3 ] / cbpos [2 ]
611
608
plt .tight_layout () # do it before cbaxis, so colorbar is ignored.
612
609
transAtoF = ax .transAxes + fig .transFigure .inverted ()
613
610
rect = transforms .Bbox .from_bounds (* cbpos ).transformed (transAtoF ).bounds
@@ -626,9 +623,9 @@ def plot3dclassprobs(self, **kwds):
626
623
627
624
cb = colorbar .ColorbarBase (cbaxis , cmap = cmap , norm = norm , ** kwds )
628
625
629
- if class_size is "number" :
626
+ if class_size == "number" :
630
627
cb .set_label ("Models in class" )
631
- elif class_size is "fraction" :
628
+ elif class_size == "fraction" :
632
629
cb .set_label ("Fraction of models in class" )
633
630
634
631
return {"fig" : fig , "axis" : ax , "cb" : cb , "cbaxis" : cbaxis }
0 commit comments