Skip to content

Commit ba55dfb

Browse files
committed
fix break import modules, remove unused import modules, fix docstring length
1 parent 30d0909 commit ba55dfb

File tree

2 files changed

+26
-30
lines changed

2 files changed

+26
-30
lines changed

Diff for: diffpy/srmise/multimodelselection.py

+26-29
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
import numpy as np
1919
from matplotlib import transforms
2020

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
2423

2524
logger = logging.getLogger("diffpy.srmise")
2625

@@ -114,7 +113,7 @@ def makeaics(self, dgs, dr, filename=None):
114113
if filename is not None:
115114
try:
116115
import cPickle as pickle
117-
except:
116+
except ImportError:
118117
import pickle
119118
out_s = open(filename, "wb")
120119
pickle.dump(aics_out, out_s)
@@ -126,7 +125,7 @@ def loadaics(self, filename):
126125
"""Load file containing results of the testall method."""
127126
try:
128127
import cPickle as pickle
129-
except:
128+
except ImportError:
130129
import pickle
131130
in_s = open(filename, "rb")
132131
aics_in = pickle.load(in_s)
@@ -321,7 +320,7 @@ def classify(self, r, tolerance=0.05):
321320
exemplar_baseline = self.results[classes[c][0]][2]
322321

323322
# Check baseline type and number of parameters
324-
if type(baseline) != type(exemplar_baseline):
323+
if type(baseline) is not type(exemplar_baseline):
325324
continue
326325
if baseline.npars() != exemplar_baseline.npars():
327326
continue
@@ -331,7 +330,7 @@ def classify(self, r, tolerance=0.05):
331330
if len(peaks) != len(exemplar_peaks):
332331
continue
333332
for p, ep in zip(peaks, exemplar_peaks):
334-
if type(p) != type(ep):
333+
if type(p) is not type(ep):
335334
badpeak = True
336335
break
337336
if p.npars() != ep.npars():
@@ -341,7 +340,6 @@ def classify(self, r, tolerance=0.05):
341340
continue
342341

343342
# check peak values
344-
current_psqval = []
345343
for p, ep in zip(psqval, epsqval[c]):
346344
basediff = np.abs(np.sum(p - ep))
347345
# if basediff > tolerance*np.sum(ep):
@@ -383,7 +381,6 @@ def classify(self, r, tolerance=0.05):
383381

384382
def makesortedclasses(self):
385383
self.sortedclasses = {}
386-
em = self.ppe.error_method
387384

388385
for dg in self.dgs:
389386
bestinclass = []
@@ -468,13 +465,15 @@ def plot3dclassprobs(self, **kwds):
468465
dGs - Sequence of dG values to plot. Default is all values.
469466
highlight - Sequence of dG values to highlight on plot. Default is [].
470467
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.]
472470
class_size - Report the size of each class as a "number" or "fraction". Default is "number".
473471
norm - A colors normalization for displaying number/fraction of models in class. Default is "auto".
474472
If equal to "full" determined by the total number of models.
475473
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.
478477
highlight_cmap - A colormap or registered colormap name for coloring highlights. Default is cm.gray.
479478
title - True, False, or a string. Defaults to True, which displays some basic information about the graph.
480479
p_alpha - Probability graph alpha. (Colorbar remains opaque). Default is 0.7.
@@ -495,12 +494,11 @@ def plot3dclassprobs(self, **kwds):
495494

496495
from matplotlib import cm, colorbar, colors
497496
from matplotlib.collections import PolyCollection
498-
from mpl_toolkits.mplot3d import Axes3D
499497

500498
fig = kwds.pop("figure", plt.gcf())
501499
ax = fig.add_subplot(kwds.pop("subplot", 111), projection="3d")
502500

503-
cbkwds = kwds.copy()
501+
kwds.copy()
504502

505503
# Resolve keywords (title resolved later)
506504
dGs = kwds.pop("dGs", self.dgs)
@@ -530,41 +528,41 @@ def plot3dclassprobs(self, **kwds):
530528

531529
# Define face colors
532530
fc = np.array([len(self.classes[z]) for z in zlabels])
533-
if class_size is "fraction":
531+
if class_size == "fraction":
534532
fc = fc / float(len(self.results))
535533

536534
# 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":
539537
indexedcolors = cmap(np.linspace(0.0, 1.0, np.max(fc)))
540538
cmap = colors.ListedColormap(indexedcolors)
541-
elif norm is "full":
539+
elif norm == "full":
542540
indexedcolors = cmap(np.linspace(0.0, 1.0, len(self.results)))
543541
cmap = colors.ListedColormap(indexedcolors)
544542
# A user-specified norm cannot be used to index a colormap.
545543

546544
# 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":
549547
mic = np.min(fc)
550548
mac = np.max(fc)
551549
nc = mac - mic + 1
552550
norm = colors.BoundaryNorm(np.linspace(mic, mac + 1, nc + 1), nc)
553-
if class_size is "fraction":
551+
if class_size == "fraction":
554552
norm = colors.Normalize()
555553
norm.autoscale(fc)
556-
elif norm is "full":
554+
elif norm == "full":
557555
mcolor = len(self.results)
558-
if class_size is "number":
556+
if class_size == "number":
559557
norm = colors.BoundaryNorm(np.linspace(0, mcolor + 1, mcolor + 2), mcolor + 1)
560-
if class_size is "fraction":
558+
if class_size == "fraction":
561559
norm = colors.Normalize(0.0, 1.0)
562560

563561
zs = np.arange(len(zlabels))
564562

565563
poly = PolyCollection(verts, facecolors=cmap(norm(fc)), closed=False)
566564
poly.set_alpha(p_alpha)
567-
cax = ax.add_collection3d(poly, zs=zs, zdir="y")
565+
ax.add_collection3d(poly, zs=zs, zdir="y")
568566

569567
# Highlight values of interest
570568
color_idx = np.linspace(0, 1, len(highlight))
@@ -602,12 +600,11 @@ def plot3dclassprobs(self, **kwds):
602600
)
603601

604602
if title is not False:
605-
figtitle = fig.suptitle(title)
603+
fig.suptitle(title)
606604

607605
# Add colorbar
608606
if "cbpos" in kwds:
609607
cbpos = kwds.pop("cbpos")
610-
aspect = cbpos[3] / cbpos[2]
611608
plt.tight_layout() # do it before cbaxis, so colorbar is ignored.
612609
transAtoF = ax.transAxes + fig.transFigure.inverted()
613610
rect = transforms.Bbox.from_bounds(*cbpos).transformed(transAtoF).bounds
@@ -626,9 +623,9 @@ def plot3dclassprobs(self, **kwds):
626623

627624
cb = colorbar.ColorbarBase(cbaxis, cmap=cmap, norm=norm, **kwds)
628625

629-
if class_size is "number":
626+
if class_size == "number":
630627
cb.set_label("Models in class")
631-
elif class_size is "fraction":
628+
elif class_size == "fraction":
632629
cb.set_label("Fraction of models in class")
633630

634631
return {"fig": fig, "axis": ax, "cb": cb, "cbaxis": cbaxis}

Diff for: diffpy/srmise/pdfdataset.py

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"""
2121

2222

23-
import copy
2423
import os.path
2524
import re
2625
import time

0 commit comments

Comments
 (0)