def litho_colormap(min,max,boundary=1600.0,width=20): if boundary<min or boundary>max: bndry=max-50 b=(bndry-min)/(max-min) else: b=(boundary-min)/(max-min) cdict = {'red': (( 0.0, 0.0 , 0.0), ( (width-1)*b/width, 0.0 , 0.0), ( b, 0.8 , 1.0), (((width-1)*b+1)/width, 1.0 , 1.0), ( 1.0, 0.4 , 1.0)), 'green': (( 0.0, 0.0 , 0.0), ( (width-1)*b/width, 0.0 , 0.0), ( b, 0.9 , 0.9), (((width-1)*b+1)/width, 0.0 , 0.0), ( 1.0, 0.0 , 0.0)), 'blue': (( 0.0, 0.0 , 0.4), ( (width-1)*b/width, 1.0 , 1.0), ( b, 1.0 , 0.8), (((width-1)*b+1)/width, 0.0 , 0.0), ( 1.0, 0.0 , 0.0))} cm=LinearSegmentedColormap('lithosphere_%d'%boundary, cdict) plt.register_cmap(cmap=cm) return cm
def create_colormaps(): from matplotlib.colors import ListedColormap cmaps = {} for (name, data) in (('magma', _magma_data), ('inferno', _inferno_data), ('plasma', _plasma_data), ('viridis', _viridis_data)): cmaps[name] = ListedColormap(data, name=name) register_cmap(cmap=cmaps[name])
def alpha_colormap(name, red, green, blue, alpha_min=0.0, alpha_max=1.0): cdict = { 'red': ((0.0, red, red), (1.0, red, red)), 'green': ((0.0, green, green), (1.0, green, green)), 'blue': ((0.0, blue, blue), (1.0, blue, blue)), 'alpha': ((0.0, alpha_min, alpha_min), (1.0, alpha_max, alpha_max)) } cm = LinearSegmentedColormap(name, cdict) register_cmap(cmap=cm) return cm
def alpha_colormap(name,red,green,blue,alpha_min=0.0,alpha_max=1.0): cdict = {'red': ((0.0,red,red), (1.0,red,red)), 'green': ((0.0,green,green), (1.0,green,green)), 'blue': ((0.0,blue,blue), (1.0,blue,blue)), 'alpha': ((0.0,alpha_min,alpha_min), (1.0,alpha_max,alpha_max))} cm=LinearSegmentedColormap(name, cdict) register_cmap(cmap=cm) return cm
def litho_colormap(min, max, boundary=1600.0, width=20): if boundary < min or boundary > max: bndry = max - 50 b = (bndry - min) / (max - min) else: b = (boundary - min) / (max - min) cdict = { 'red': ((0.0, 0.0, 0.0), ((width - 1) * b / width, 0.0, 0.0), (b, 0.8, 1.0), (((width - 1) * b + 1) / width, 1.0, 1.0), (1.0, 0.4, 1.0)), 'green': ((0.0, 0.0, 0.0), ((width - 1) * b / width, 0.0, 0.0), (b, 0.9, 0.9), (((width - 1) * b + 1) / width, 0.0, 0.0), (1.0, 0.0, 0.0)), 'blue': ((0.0, 0.0, 0.4), ((width - 1) * b / width, 1.0, 1.0), (b, 1.0, 0.8), (((width - 1) * b + 1) / width, 0.0, 0.0), (1.0, 0.0, 0.0)) } cm = LinearSegmentedColormap('Lithosphere%d' % boundary, cdict) register_cmap(cmap=cm) return cm
def plot(lats, lons, values, args): """ Creates the plot Arguments: lats (np.array): 2D array with latitudes lons (np.array): 2D array with longitudes values (np.array): 2D array with number of hours """ font = {'family': 'normal', 'weight': 'bold', 'size': args.fontsize} font = { 'sans-serif': 'Arial', 'family': 'san-serif', 'size': args.fontsize } matplotlib.rc('font', **font) mpl.clf() dlat = 0 dlon = 0 cmap = mpl.cm.RdBu if args.cmap is not None: cmap = args.cmap if args.maptype is not None: llcrnrlat = max(-90, np.min(lats) - dlat / 10) urcrnrlat = min(90, np.max(lats) + dlat / 10) llcrnrlon = np.min(lons) - dlon / 10 urcrnrlon = np.max(lons) + dlon / 10 llcrnrlat = 56 urcrnrlat = 72 llcrnrlon = 0 urcrnrlon = 30 res = verif.util.get_map_resolution([llcrnrlat, urcrnrlat], [llcrnrlon, urcrnrlon]) if args.xlim is not None: llcrnrlon = args.xlim[0] urcrnrlon = args.xlim[1] if args.ylim is not None: llcrnrlat = args.ylim[0] urcrnrlat = args.ylim[1] map = mpl_toolkits.basemap.Basemap(llcrnrlon=llcrnrlon, llcrnrlat=llcrnrlat, urcrnrlon=urcrnrlon, urcrnrlat=urcrnrlat, projection='tmerc', lat_0=60, lon_0=10, resolution=res) map.drawcoastlines(linewidth=0.25) map.drawcountries(linewidth=0.25) map.drawmapboundary() [x, y] = map(lons, lats) if args.edges is None: mpl.contourf(x, y, values, cmap=cmap, extend="both") else: # mpl.contour(x, y, values, [0,1000,2000,3000,4000,5000,6000,7000,8000], colors="k", linewidths=0.3) mpl.contourf(x, y, values, args.edges, cmap=cmap, extend="both") else: if args.edges is None: # mpl.contourf(values, cmap=cmap, extend="both") mpl.imshow(values, cmap=cmap) else: print args.edges a = 0.25 b = 0.50 cdict = { 'red': [(0.0, 0.68, 0.9), (a, 0.99, 0.19), (b, 0.855, 0.776), (1, 0.2, 1)], 'green': [(0, 0.68, 0.33), (a, 0.82, 0.639), (b, 0.854, 0.86), (1, 0.51, 1)], 'blue': [(0, 0.68, 0.05), (a, 0.635, 0.329), (b, 0.922, 0.94), (1, 0.74, 1)] } epic = matplotlib.colors.LinearSegmentedColormap('epic', cdict) mpl.register_cmap(cmap=epic) mpl.contourf(values, args.edges, cmap=cmap, extend="max") if args.legfs is not None and args.legfs > 0: cb = mpl.colorbar(extend="both") # , ax=ax) cb.ax.set_position([0.05, 0.4, 0.1, 0.5]) cb.set_ticks(np.linspace(0, 4000, 5)) # 16 cb.set_label(u"Snøproduksjonspotensial (timer/år)", labelpad=-120, fontsize=26) mpl.gca().set_position([0, 0, 1, 1]) if args.figsize is not None: mpl.gcf().set_size_inches((args.figsize), forward=True) if args.ofile is None: mpl.show() else: mpl.savefig(args.ofile, dpi=args.dpi)
(0.35, 0.35, 0.35), (0.45, 0.9, 0.9), (0.5, 0.6, 0.6), (0.75, 1.0, 1.0), (1.0, 1.0, 1.0)), 'blue': ((0.0, 0.0, 0.0), (0.4, 0.0, 0.0), (0.5, 0.6, 0.6), (0.65, 1.0, 1.0), (1.0, 1.0, 1.0)) } # A little sum'n sum'n for my hood minot. I'm on a roll now. cdict4 = { 'red': ((0.0, 0.0, 0.0), (0.7, 0.0, 0.0), (1.0, 1.0, 1.0)), 'green': ((0.0, 0.0, 0.0), (0.5, 1.0, 0.2), (0.7, 1.0, 1.0), (1.0, 1.0, 1.0)), 'blue': ((0.0, 0.0, 0.1), (0.5, 1.0, 0.0), (0.7, 0.0, 0.0), (1.0, 1.0, 1.0)) } # Create the colormap using the dictionary above, and register it so it can be referenced later. plt.register_cmap(cmap=clr.LinearSegmentedColormap('Map', cdict1)) plt.register_cmap(cmap=clr.LinearSegmentedColormap('LandSea', cdict2)) plt.register_cmap(cmap=clr.LinearSegmentedColormap( 'Martia', cdict3)) # Not bad for earth's oceans. #-- Honorable Mentions (native to matplotlib) # gray # copper # seismic #-- Slightly less honorable mentions # gist_earth # cubehelix # nipy_spectral ################################################################################
def func(sss): from matplotlib import pylab from numpy import * from matplotlib.colors import LinearSegmentedColormap cdict = { 'red': ((0.0, 0.0, 0.0), (0.25, 0.0, 0.0), (0.5, 0.8, 1.0), (0.75, 1.0, 1.0), (1.0, 0.4, 1.0)), 'green': ((0.0, 0.0, 0.0), (0.25, 0.0, 0.0), (0.5, 0.9, 0.9), (0.75, 0.0, 0.0), (1.0, 0.0, 0.0)), 'blue': ((0.0, 0.0, 0.4), (0.25, 1.0, 1.0), (0.5, 1.0, 0.8), (0.75, 0.0, 0.0), (1.0, 0.0, 0.0)) } blue_red = LinearSegmentedColormap('BlueRed', cdict) pylab.register_cmap(cmap=blue_red) pylab.rcParams['image.cmap'] = 'BlueRed' with open('velocity_9sensors_analysis_1.csv', 'r') as file1: lines = file1.readlines() z1 = [] m1 = [] norm = [] for i in range(0, 120): linearray = lines[i].split(',') for j in range(19): for k in range(5): p = float(linearray[j]) z1.append(p) for k in range(5): p = float(linearray[19].rstrip('\n')) z1.append(p) z1 = array(z1).reshape(120, 100) m1 = z1.T with open('velocity_' + sss + 'sensors_analysis_1.csv', 'r') as file2: lines = file2.readlines() z2 = [] m2 = [] for i in range(0, 120): linearray = lines[i].split(',') for j in range(19): for k in range(5): p = float(linearray[j]) z2.append(p) for k in range(5): p = float(linearray[19].rstrip('\n')) z2.append(p) z2 = array(z2).reshape(120, 100) m2 = z2.T ## print z ## pylab.xticks(arange(20),'0','5','10','15','20') ## pylab.yticks(arange(120),'8.30','9.00','9.30','10.00','10.00') fig = pylab.figure() ax = fig.add_subplot(111) ax.set_ylabel('Cell Number') ax.set_xlabel('Time') ## pylab.xmajorLocator=fig.MultipleLocator(10) ## pylab.ylim(0,100) ax.set_title('2004.Nov.3(Wed.), 8:30-10:30') diff = (m2 - m1) max = diff.max() min = diff.min() for i in diff: for j in i: if (j > 0): print j j = j / max print j else: j = -j / min norm.append(j) norm = array(norm).reshape(100, 120) imag = pylab.imshow(norm) cb = pylab.colorbar(imag, shrink=0.87, ticks=[-3, -2, -1, 0, 1, 2, 3, 4]) cb.set_ticklabels([str(round(min, 2)), '0', str(round(max, 2))], update_ticks=True) #pylab.show() pylab.savefig('9-' + sss + '.png', dpi=150) print 'over'
'red': ((0.0, 0.0, 0.0), (1.0, 1.0, 1.0)), 'green': ((0.0, 0.0, 0.0), (1.0, 0.0, 0.0)), 'blue': ((0.0, 0.0, 0.0), (1.0, 0.0, 0.0)) } cdict2 = { 'red': ((0.0, 0.0, 0.0), (1.0, 0.0, 0.0)), 'green': ((0.0, 0.0, 0.0), (1.0, 0.0, 0.0)), 'blue': ((0.0, 0.0, 0.0), (1.0, 1.0, 1.0)) } cdict3 = { 'red': ((0.0, 0.0, 0.0), (1.0, 0.0, 0.0)), 'green': ((0.0, 0.0, 0.0), (1.0, 1.0, 1.0)), 'blue': ((0.0, 0.0, 0.0), (1.0, 0.0, 0.0)) } red1 = LinearSegmentedColormap('Red1', cdict1) plt.register_cmap(cmap=red1) blue1 = LinearSegmentedColormap('Blue1', cdict2) plt.register_cmap(cmap=blue1) green1 = LinearSegmentedColormap('Green1', cdict3) plt.register_cmap(cmap=green1) def main(): # Initialize PVCAM and find the first available camera. pvc.init_pvcam() cam = [cam for cam in Camera.detect_camera()][0] cam.open() cam.gain = 1 cam.exp_mode = "Timed" cam.binning = 2 #Binning to set camera to collect at
'''Quick plotting tools go here''' import proper import numpy as np # import vip # import pyfits as pyfits import matplotlib.pylab as plt import Utils.colormaps as cmaps plt.register_cmap(name='viridis', cmap=cmaps.viridis) plt.register_cmap(name='plasma', cmap=cmaps.plasma) plt.register_cmap(name='inferno', cmap=cmaps.plasma) plt.register_cmap(name='magma', cmap=cmaps.plasma) from matplotlib.colors import LogNorm, SymLogNorm import matplotlib.ticker as ticker from params import tp, sp, iop from Utils.misc import dprint # MEDIUM_SIZE = 17 # plt.rc('font', size=MEDIUM_SIZE) # controls default text sizes # from matplotlib import rcParams # rcParams['font.family'] = 'STIXGeneral' # 'Times New Roman' # rcParams['mathtext.fontset'] = 'custom' # rcParams['mathtext.fontset'] = 'stix' # rcParams['mathtext.rm'] = 'Bitstream Vera Sans' # rcParams['mathtext.bf'] = 'Bitstream Vera Sans:bold' def fmt(x, pos): a, b = '{:.0e}'.format(x).split('e') b = int(b) return r'${} e^{{{}}}$'.format(a, b)
(0.88, 0.944, 0.944), (0.98, 0.500, 0.500), (1., 1., 1.)), 'green': ((0., 0., 0.), (0.10, 0.000, 0.000), (0.25, 0.389, 0.389), (0.32, 0.833, 0.833), (0.40, 1.000, 1.000), (0.52, 1.000, 1.000), (0.64, 0.803, 0.803), (0.76, 0.389, 0.389), (0.88, 0.000, 0.000), (1., 0., 0.)), 'blue': ((0., 0.00, 0.00), (0.001, 0., 0.), (0.07, 0.500, 0.500), (0.12, 0.900, 0.900), (0.23, 1.000, 1.000), (0.28, 1.000, 1.000), (0.40, 0.722, 0.722), (0.52, 0.2778, 0.2778), (0.64, 0.000, 0.000), (1., 0., 0.)) } import matplotlib.pylab as plt _jet_black_cm = matplotlib.colors.LinearSegmentedColormap( 'jet_black', _jet_black_cdict, 1e5) plt.register_cmap(cmap=_jet_black_cm) # matplotlib.rcParams['axes.linewidth'] = 1.5 # matplotlib.rcParams['xtick.labelsize'] = 14 # matplotlib.rcParams['ytick.labelsize'] = 14 # matplotlib.rcParams['axes.labelsize'] = 20 # Custom mpl styling import config # import matplotlib, json # mpljson = json.load(open("%s/styles/bmh_matplotlibrc.json" % config.DATA_DIR)) # # mpljson = json.load(open("%s/styles/538.json" % config.DATA_DIR)) # matplotlib.rcParams.update(mpljson) # print "PLOT FBARYON FIT CURVES FOR AMR AND CUDATON RUNS AT FIXED POINTS IN THEIR REIONIZATION HISTORY, NOT REDSHIFT" # print "RUN RAMSES-RT SIM WITH EXACT SAME PHYSICS_PARAMS AS ATON RUNS (EXCEPT SF CRITERIA)"
liter.append(loss_fn(paramsf,xzp.T, l_c) + (0.6/N)) loss_arrs_N.append(liter) loss_fin.append(loss_fn(paramsf,xzp.T, l_c)) # Plotting the spectrograms and final loss for the different N's costs_fin = loss_fin import matplotlib.pyplot as pyp import matplotlib from matplotlib.pylab import register_cmap cdict = { 'red': ((0.0, 1.0, 1.0), (1.0, 0.0, 0.0)), 'green': ((0.0, 1.0, 1.0), (1.0, .15, .15)), 'blue': ((0.0, 1.0, 1.0), (1.0, 0.4, 0.4)), 'alpha': ((0.0, 0.0, 0.0), (1.0, 1.0, 1.0))} register_cmap(name='InvBlueA', data=cdict) matplotlib.rcParams.update({'font.size': 16}) def plot_various_window_size(sigi): pyp.figure(figsize=(22, 4)) szs = N_sweep for i in range(len(szs)): sz, hp = szs[i], szs[i] a = diff_stft(sigi,s = szs[i]*1.0/6,hf = 1) pyp.gcf().add_subplot(1, len(szs), i + 1), pyp.gca().pcolorfast(a,cmap = "InvBlueA") pyp.gca().set_title(f'FFT size: {sz}, \n Loss: {costs_fin[i]:.5f}') pyp.xlabel('Time Frame') pyp.ylabel('Frequency Bin') pyp.gcf().tight_layout() plot_various_window_size(signal[:5*one_period.shape[0]])
#plt.show(block=False) if len(idw_flds_list) != len(rm_flds_list): raise Exception('Number of idw and random mixing files is not equal.') old_info_list = [] # for RM idw_old_info_list = [] # for IDW avg_rm_old_info_list = [] # for Avg RM tot_rows, tot_cols = 25, 16 row_span, col_span = 7, 8 #blues = LinearSegmentedColormap.from_list(name='blues', N=15, colors=['white','#00CED1','#800080']) blues = LinearSegmentedColormap.from_list( name='blues', N=15, colors=['white', '#00CED1', '#140066']) plt.register_cmap(cmap=blues) cmap = plt.get_cmap(blues) cmap.set_over('#5a0080') #cmap = plt.get_cmap('Paired') cmap.set_over('0.25') cmap.set_under('0.75') c_bar_ticks = [0.001, 5, 10, 15, 20, 30, 50, 70, 100] # adjust the color intervals by increasing the number of items # per list c_bar_ints = list(np.arange(0, 21, 0.5)) + \ list(np.arange(20, 61, 0.75)) + \ list(np.arange(61, 100, 1))
'''Takes a exposure with and without the coronagraph and creates contrast curve''' import sys, os sys.path.append('/Data/PythonProjects/MEDIS/MEDIS') sys.path.append('/Data/PythonProjects/MEDIS/MEDIS/Telescope') import glob import proper import numpy as np np.set_printoptions(threshold=np.inf) import matplotlib.pylab as plt import Utils.colormaps as cmaps plt.register_cmap(name='viridis', cmap=cmaps.viridis) plt.register_cmap(name='plasma', cmap=cmaps.plasma) from params import ap, cp, tp, mp import Detector.analysis as ana import Detector.MKIDs as MKIDs import Telescope.run_system as run_system # tp.nwsamp = 1 tp.occulter_type = None # None# # tp.use_prim_ab = True if tp.detector == 'MKIDs': MKIDs.initialize() #code to run CAOS if tp.use_atmos and glob.glob(cp.atmosdir + '*.fits') == []: import Atmosphere.caos as caos #import here since pidly can stay open sometimes and that's annoying