def imshow(self, err=False, cbar=False, ax=None, show=True, border=False, zorder=0, cmap=cm.binary, alpha=True, cdf=True, savefig=None, acf=False, ss=False, extent=None, log=False, xlim=None, ylim=None): """ Basic plotting of the dynamic spectrum """ if acf: if self.acf is None: self.acf2d() data = self.acf elif ss: if self.ss is None: self.secondary_spectrum(log=log) data = self.ss elif err: data = self.errdata else: data = self.getData() if extent is None: if acf: T = self.acfT F = self.acfF elif ss: T = self.ssconjT F = self.ssconjF else: if self.Tcenter is None: T = self.T else: T = self.Tcenter if self.Fcenter is None: F = self.F else: F = self.Fcenter if log and not ss: data = np.log10(data) if alpha and not (acf or ss): #or just ignore? cmap.set_bad(alpha=0.0) for i in range(len(data)): for j in range(len(data[0])): if data[i, j] <= 0.0: # or self.errdata[i][j]>3*sigma: data[i, j] = np.nan if cdf: xcdf, ycdf = u.ecdf(data.flatten()) low, high = u.likelihood_evaluator(xcdf, ycdf, cdf=True, values=[0.01, 0.99]) for i in range(len(data)): for j in range(len(data[0])): if data[i, j] <= low: data[i, j] = low elif data[i, j] >= high: data[i, j] = high if extent is None: minT = T[0] maxT = T[-1] minF = F[0] maxF = F[-1] extent = [minT, maxT, minF, maxF] #return np.shape(data) #raise SystemExit # print inds # raise SystemExit # spec[inds] = np.nan if ax is None: fig = plt.figure() ax = fig.add_subplot(111) cax = u.imshow(data, ax=ax, extent=extent, cmap=cmap, zorder=zorder) if xlim is not None: plt.xlim(xlim) if ylim is not None: plt.ylim(ylim) #border here? if border: # and self.extras['name']!='EFF I': plt.plot([T[0], T[-1]], [F[0], F[0]], '0.50', zorder=zorder + 0.1) plt.plot([T[0], T[-1]], [F[-1], F[-1]], '0.50', zorder=zorder + 0.1) plt.plot([T[0], T[0]], [F[0], F[-1]], '0.50', zorder=zorder + 0.1) plt.plot([T[-1], T[-1]], [F[0], F[-1]], '0.50', zorder=zorder + 0.1) if acf: plt.xlabel('Time Lag (%s)' % self.Tunit) plt.ylabel('Frequency Lag (%s)' % self.Funit) elif ss: plt.xlabel('Conjugate Time (1/%s)' % self.Tunit) plt.ylabel('Conjugate Frequency (1/%s)' % self.Funit) else: plt.xlabel('Time (%s)' % self.Tunit) plt.ylabel('Frequency (%s)' % self.Funit) if cbar: plt.colorbar(cax) #im.set_clim(0.0001,None) if savefig is not None: plt.savefig(savefig) if show: plt.show() return ax
def imshow(self, err=False, cbar=False, ax=None, show=True, border=False, ZORDER=0, cmap=cm.binary, alpha=True, cdf=True): """ Basic plotting of the dynamic spectrum """ if err: spec = self.errdata else: spec = self.data T = self.T if self.T is None: if self.Tcenter is None: T = np.arange(len(spec)) else: T = self.Tcenter F = self.F if self.F is None: if self.Fcenter is None: F = np.arange(len(spec[0])) else: F = self.Fcenter #cmap = cm.binary#jet if alpha: cmap.set_bad(alpha=0.0) if alpha: #do this? for i in range(len(spec)): for j in range(len(spec[0])): if spec[i, j] <= 0.0: # or self.errdata[i][j]>3*sigma: spec[i, j] = np.nan minT = T[0] maxT = T[-1] minF = F[0] maxF = F[-1] if cdf: xcdf, ycdf = u.ecdf(spec.flatten()) low, high = u.likelihood_evaluator(xcdf, ycdf, cdf=True, values=[0.01, 0.99]) for i in range(len(spec)): for j in range(len(spec[0])): if spec[i, j] <= low: spec[i, j] = low elif spec[i, j] >= high: spec[i, j] = high # print inds # raise SystemExit # spec[inds] = np.nan cax = u.imshow(spec, ax=ax, extent=[minT, maxT, minF, maxF], cmap=cmap, zorder=ZORDER) #border here? if border: # and self.extras['name']!='EFF I': plt.plot([T[0], T[-1]], [F[0], F[0]], '0.50', zorder=ZORDER + 0.1) plt.plot([T[0], T[-1]], [F[-1], F[-1]], '0.50', zorder=ZORDER + 0.1) plt.plot([T[0], T[0]], [F[0], F[-1]], '0.50', zorder=ZORDER + 0.1) plt.plot([T[-1], T[-1]], [F[0], F[-1]], '0.50', zorder=ZORDER + 0.1) if cbar: plt.colorbar(cax) #im.set_clim(0.0001,None) if show: plt.show() return ax