def plot_bandstructure(fname, rotate=True, cmap='jet', logscale=False, ax=None, E2=False): """ make a nice pcolormesh plot of the bandstructure usage: plot_bandstructure( fname ) where fname is a txt file exported manually using a lumerical script. See 'load_bandstructure' for proper formatting of this txt file. """ d1, d2, fields = load_bandstructure(fname) D1 = kc.centers_to_corners(d1) D2 = kc.centers_to_corners(d2) if ax == None: ax = plt.gca() if logscale: fields = np.log(fields) if rotate == True: """ Note: the /1e12 converts Hz to THz """ plot = ax.pcolormesh(D1, D2 / 1e12, np.transpose(fields), cmap=cmap) ax.axis([D1.min(), D1.max(), D2.min() / 1e12, D2.max() / 1e12]) else: plot = ax.pcolormesh(D2, D1, fields, cmap=cmap) ax.axis([D2.min(), D2.max(), D1.min(), D1.max()]) #show() return plot, D1, D2, fields
def plot_bandstructure( fname, rotate=True, cmap='jet', logscale=False, ax=None, E2=False ): """ make a nice pcolormesh plot of the bandstructure usage: plot_bandstructure( fname ) where fname is a txt file exported manually using a lumerical script. See 'load_bandstructure' for proper formatting of this txt file. """ d1, d2, fields = load_bandstructure( fname ) D1 = kc.centers_to_corners( d1 ) D2 = kc.centers_to_corners( d2 ) if ax==None: ax=plt.gca() if logscale: fields = np.log(fields) if rotate==True: """ Note: the /1e12 converts Hz to THz """ plot = ax.pcolormesh( D1, D2/1e12, np.transpose( fields ), cmap=cmap ) ax.axis([ D1.min(), D1.max(), D2.min()/1e12, D2.max()/1e12 ]) else: plot = ax.pcolormesh( D2, D1, fields, cmap=cmap ) ax.axis([ D2.min(), D2.max(), D1.min(), D1.max() ]) #show() return plot, D1, D2, fields
def plotcolormap(self): files = glob.glob( self.DataPath + "\\" + self.FnameBase + '_*.SPE' ) # get a list of all non-glued txt files # assume filename is of the format: timeseriesvacuum_2640.SPE # where 2640 is the time in seconds since the start of the series of scans try: files.sort( key=lambda x: int(os.path.split(x)[1].split('.SPE')[0].split('_')[1]) ) # sort by acquisition start time except ValueError: # there was a file in there with the same filename base but that wasn't part of the series # (e.g. "timeseriesvacuum_after blocking laser 10mn.SPE") for fname in files: if not os.path.split(fname)[1].split('.SPE')[0].split('_')[1].isdigit(): files.remove( fname ) files.sort( key=lambda x: int(os.path.split(x)[1].split('.SPE')[0].split('_')[1]) ) # sort by acquisition start time if len(files) == 0: print "no SPE files found." return False if files == self.SPEFiles: # print "same list as last time." pass else: # presumably we could save some effort and not load the whole list every time, # but this program is meant to be used while taking spectra every 30sec or so, # which would give us plenty of time to refresh the plot each time. # but the plotting itself is probably the most expensive part, so this is moot... self.SPEFiles = files self.spectra = [] self.time = [] for fname in files: self.time.append( float( os.path.split(fname)[1].split('.SPE')[0].split('_')[-1] ) ) s = spe.Spectrum( fname ) s.remove_linear_background( npoints=10 ) s.normalize() self.spectra.append( s.lum ) self.wavelen = s.wavelen wavelen_image = kc.centers_to_corners( self.wavelen ) time_image = kc.centers_to_corners( self.time )/60.0 spectra_image = pylab.array( self.spectra ) self.axes.pcolormesh( time_image, wavelen_image, spectra_image.transpose(), cmap='copper' ) self.axes.set_ylim( wavelen_image[0], wavelen_image[-1] ) self.axes.set_xlim( time_image[0], time_image[-1] ) self.axes.set_ylabel( 'Wavelength (nm)' ) self.axes.set_xlabel( 'Time (min)' ) self.axes.set_title( self.FnameBase ) return True
def plot2Dmonitor( fname, rotate=False, offset=[0,0], cmap='Purples', ax=None, E2=False ): """ make a nice pcolormesh plot that has same units in both axes usage: plot2Dmonitor( fname ) where fname is a txt file exported manually from CAD. """ d1, d2, fields = load2D( fname ) if E2: fields = np.sqrt(fields) # you exported E-squared (E intensity) but you want abs(E). D1 = kc.centers_to_corners( d1 ) D2 = kc.centers_to_corners( d2 ) if ax==None: ax=plt.gca() if rotate==True: plot = ax.pcolormesh( D1+offset[0], D2+offset[1], transpose( fields ), cmap=cmap ) ax.axis([ D1.min()+offset[0], D1.max()+offset[0], D2.min()+offset[1], D2.max()+offset[1] ]) else: plot = ax.pcolormesh( D2+offset[0], D1+offset[1], fields, cmap=cmap ) ax.axis([ D2.min()+offset[0], D2.max()+offset[0], D1.min()+offset[1], D1.max()+offset[1] ]) ax.set_aspect('equal') #show() return plot, D1, D2, fields
def plot2Dmonitor(fname, **kwargs): """ make a nice pcolormesh plot that has same units in both axes usage: plot2Dmonitor( fname ) where fname is a txt file exported manually from CAD. Various keyword arguments are supported (in addition to any : rotate: True/False for whether colormap should be rotated 90deg offset: [x,y] tuple specifying lateral shift of origin for plotting ax: axes instance for plotting. If not specified, gca() is used. take_sqrt: True/False. If True, take np.sqrt() before plotting (formerly E2) logscale: True/False. If True, take np.log10() before plotting flipvert: True/False. If True, multiply the locations of the vertical axis by -1 to flip it. """ d1, d2, fields = load2D(fname) D1 = kc.centers_to_corners(d1) D2 = kc.centers_to_corners(d2) if 'E2' in kwargs.keys(): raise ValueError, "E2 is deprecated and was replaced with take_sqrt (which acts equivalently)." if 'rotate' in kwargs.keys(): rotate = kwargs['rotate'] del kwargs['rotate'] else: rotate = False if 'offset' in kwargs.keys(): offset = kwargs['offset'] del kwargs['offset'] else: offset = [0, 0] if 'ax' in kwargs.keys(): ax = kwargs['ax'] del kwargs['ax'] else: ax = plt.gca() if 'flipvert' in kwargs.keys(): flipvert = kwargs['flipvert'] del kwargs['flipvert'] else: flipvert = False if 'take_sqrt' in kwargs.keys(): if kwargs['take_sqrt']: fields = np.sqrt( fields ) # you exported E-squared (E intensity) but you want abs(E). del kwargs['take_sqrt'] if 'logscale' in kwargs.keys(): if kwargs['logscale']: fields = np.log10(fields) del kwargs['logscale'] if rotate == True: if flipvert: D2 *= -1 plot = ax.pcolormesh(D1 + offset[0], D2 + offset[1], np.transpose(fields), **kwargs) ax.axis([ D1.min() + offset[0], D1.max() + offset[0], D2.min() + offset[1], D2.max() + offset[1] ]) else: if flipvert: D1 *= -1 plot = ax.pcolormesh(D2 + offset[0], D1 + offset[1], fields, **kwargs) ax.axis([ D2.min() + offset[0], D2.max() + offset[0], D1.min() + offset[1], D1.max() + offset[1] ]) ax.set_aspect('equal') #show() return plot, D1, D2, fields
def colormap(self): """ plot a colormap of the full raster scan """ x = kc.centers_to_corners(self.xpoints) y = kc.centers_to_corners(self.ypoints)
def plot2Dmonitor( fname, **kwargs ): """ make a nice pcolormesh plot that has same units in both axes usage: plot2Dmonitor( fname ) where fname is a txt file exported manually from CAD. Various keyword arguments are supported (in addition to any : rotate: True/False for whether colormap should be rotated 90deg offset: [x,y] tuple specifying lateral shift of origin for plotting ax: axes instance for plotting. If not specified, gca() is used. take_sqrt: True/False. If True, take np.sqrt() before plotting (formerly E2) logscale: True/False. If True, take np.log10() before plotting flipvert: True/False. If True, multiply the locations of the vertical axis by -1 to flip it. """ d1, d2, fields = load2D( fname ) D1 = kc.centers_to_corners( d1 ) D2 = kc.centers_to_corners( d2 ) if 'E2' in kwargs.keys(): raise ValueError, "E2 is deprecated and was replaced with take_sqrt (which acts equivalently)." if 'rotate' in kwargs.keys(): rotate = kwargs['rotate'] del kwargs['rotate'] else: rotate = False if 'offset' in kwargs.keys(): offset = kwargs['offset'] del kwargs['offset'] else: offset = [0,0] if 'ax' in kwargs.keys(): ax = kwargs['ax'] del kwargs['ax'] else: ax=plt.gca() if 'flipvert' in kwargs.keys(): flipvert = kwargs['flipvert'] del kwargs['flipvert'] else: flipvert=False if 'take_sqrt' in kwargs.keys(): if kwargs['take_sqrt']: fields = np.sqrt(fields) # you exported E-squared (E intensity) but you want abs(E). del kwargs['take_sqrt'] if 'logscale' in kwargs.keys(): if kwargs['logscale']: fields = np.log10(fields) del kwargs['logscale'] if rotate==True: if flipvert: D2 *= -1 plot = ax.pcolormesh( D1+offset[0], D2+offset[1], np.transpose( fields ), **kwargs ) ax.axis([ D1.min()+offset[0], D1.max()+offset[0], D2.min()+offset[1], D2.max()+offset[1] ]) else: if flipvert: D1 *= -1 plot = ax.pcolormesh( D2+offset[0], D1+offset[1], fields, **kwargs ) ax.axis([ D2.min()+offset[0], D2.max()+offset[0], D1.min()+offset[1], D1.max()+offset[1] ]) ax.set_aspect('equal') #show() return plot, D1, D2, fields
def colormap( self ): """ plot a colormap of the full raster scan """ x = kc.centers_to_corners( self.xpoints ) y = kc.centers_to_corners( self.ypoints )