def __call__(self, labels=(2, 3), filename='trajectory_plots.pdf', exclude_labels=(0, )): cmap = unsupervised_cmap(self._nclusters) try: pdf = PdfPages(join(self._odir, filename)) for title_, tracks in self._data.iteritems(): title = '%s (%s)' % (self._position, title_.lower()) # checking for binary matrix if np.unique(tracks).size == 2: is_binary = True labels_ = (1, ) else: is_binary = False labels_ = labels # trajectory plots fig = plots.trajectories(tracks, labels_, title=title, cmap=cmap) pdf.savefig(fig) delchars = NameValidator.defaultdeletechars.copy() delchars.remove('-') validator = NameValidator(case_sensitive='lower', deletechars=delchars) fname = validator.validate(title)[0] + '.csv' np.savetxt(join(self._odir, fname), tracks, fmt='%d', delimiter=',') # boxplots if not is_binary: ylabel = "dwell time (%s)" % self.timeunit xlabel = "class labels" dwell_times = self.dwell_times(tracks) fig1 = plots.dwell_boxplot(dwell_times, title, ylabel=ylabel, xlabel=xlabel, exclude_labels=exclude_labels, cmap=cmap) fig2 = plots.barplot(dwell_times, title, xlabel=xlabel, ylabel=ylabel, exclude_labels=exclude_labels, cmap=cmap) pdf.savefig(fig1) pdf.savefig(fig2) finally: pdf.close()
def __init__(self, nclusters, *args, **kw): super(ClassDefinitionUnsup, self).__init__(*args, **kw) self.nclusters = nclusters self.colormap = unsupervised_cmap(self.nclusters) # dummy attribute to recyle export function in timeholder self.classifier = GaussianMixtureModel() for i in xrange(self.nclusters): name = "cluster-%d" % i self.class_labels[name] = i self.class_names[i] = name self.hexcolors[name] = rgb2hex(self.colormap(i))
def __call__(self, labels=(2,3), filename='trajectory_plots.pdf', exclude_labels=(0, )): cmap = unsupervised_cmap(self._nclusters) try: pdf = PdfPages(join(self._odir, filename)) for title_, tracks in self._data.iteritems(): title = '%s (%s)' %(self._position, title_.lower()) # checking for binary matrix if np.unique(tracks).size == 2: is_binary = True labels_ = (1, ) else: is_binary = False labels_ = labels # trajectory plots fig = plots.trajectories(tracks, labels_, title=title, cmap=cmap) pdf.savefig(fig) delchars = NameValidator.defaultdeletechars.copy() delchars.remove('-') validator = NameValidator(case_sensitive='lower', deletechars=delchars) fname = validator.validate(title)[0]+'.csv' np.savetxt(join(self._odir, fname), tracks, fmt='%d', delimiter=',') # boxplots if not is_binary: ylabel = "dwell time (%s)" %self.timeunit xlabel = "class labels" dwell_times = self.dwell_times(tracks) fig1 = plots.dwell_boxplot(dwell_times, title, ylabel=ylabel, xlabel=xlabel, exclude_labels=exclude_labels, cmap=cmap) fig2 = plots.barplot(dwell_times, title, xlabel=xlabel, ylabel=ylabel, exclude_labels=exclude_labels, cmap=cmap) pdf.savefig(fig1) pdf.savefig(fig2) finally: pdf.close()