def readCylScript(fn,rotate=np.linspace(.75,1.5,50),interp=None): """ Load in data from 4D measurement of cylindrical mirror. File is assumed to have been saved with Ryan's scripting function. Scale to microns, remove misalignments, strip NaNs. If rotate is set to an array of angles, the rotation angle which minimizes the number of NaNs in the image after stripping perimeter nans is selected. Distortion is bump positive looking at concave surface. Imshow will present distortion in proper orientation as if viewing the concave surface. """ #Read in values from header f = open(fn+'.hdr','r') l = f.readlines() f.close() #Wavelength should never change wave = float(l[0].split()[0])*.001 #in microns #Ensure wedge factor is 0.5 wedge = float(l[1]) if wedge!=0.5: print 'Wedge factor is ' + str(wedge) pdb.set_trace() #Get pixel scale size dx = float(l[-1]) #Remove NaNs and rescale d = np.fromfile(fn+'.bin',dtype=np.float32) try: d = d.reshape((1002,981)) except: d = d.reshape((1003,982)) d[d>1e10] = np.nan d = man.stripnans(d) d = d *wave d = d - np.nanmean(d) #Remove cylindrical misalignment terms d = d - fit.fitCylMisalign(d)[0] #Rotate out CGH roll misalignment? if rotate is not None: b = [np.sum(np.isnan(\ man.stripnans(\ nd.rotate(d,a,order=1,cval=np.nan)))) for a in rotate] d = man.stripnans(\ nd.rotate(d,rotate[np.argmin(b)],order=1,cval=np.nan)) #Interpolate over NaNs if interp is not None: d = man.nearestNaN(d,method=interp) return d,dx
def measurePower(rays, Nx, Ny, method='linear'): """Measure the radius of curvature in X and Y axes of OPD Assumes you have steered the beam to get rid of any tilts Sign of power equals transform in z to go to focus""" #Get l,m l, dx, dy = interpolateVec(rays, 4, Nx, Ny, method=method) m = interpolateVec(rays, 5, Nx, Ny, method=method)[0] #Get slices xsl = man.stripnans(l[Ny / 2]) ysl = man.stripnans(m[:, Nx / 2]) #Estimate gradients xpow = 1 / np.gradient(xsl, dx)[Nx / 2] ypow = 1 / np.gradient(ysl, dy)[Ny / 2] return -xpow, -ypow
def primary2DPSF(img,dx,R0=220.,Z0=8400.,x0=np.linspace(-5.,5.,1001),\ wave=1.24e-6): """ Create height vector and radius img based on radial distortion input data. Then pass to a F2PY scattering function to compute PSF over observation points. """ #Remove NaNs if they exist img = man.stripnans(img) #Create height vector graze = woltparam(R0, Z0)[0] foc = primfocus(R0, Z0) z = np.arange(np.shape(img)[0]) * dx * np.cos(graze) + Z0 #Create radial position img rad = primrad(z, R0, Z0) rad2 = np.flipud(np.transpose(np.tile(rad, (np.shape(img)[1], 1)))) distortion = np.transpose(rad2 - img / 1e3) z = z[::-1] #Compute length for each slice length = np.array([(np.sum(~np.isnan(li))-1)*dx \ for li in distortion],order='F') DR = length * np.sin(graze) #Integrate each slice in Fortran psf = scatter.primarypsf(distortion, z - Z0, length, x0, wave, foc, R0, graze) return psf
def readCylWFS(fn, rotate=np.linspace(.75, 1.5, 50), interp=None): """ Load in data from WFS measurement of cylindrical mirror. Assumes that data was processed using processHAS, and loaded into a .fits file. Scale to microns, remove misalignments, strip NaNs. If rotate is set to an array of angles, the rotation angle which minimizes the number of NaNs in the image after stripping perimeter nans is selected. Distortion is bump positive looking at concave surface. Imshow will present distortion in proper orientation as if viewing the concave surface. """ #Remove NaNs and rescale d = pyfits.getdata(fn) d = man.stripnans(d) d = d - np.nanmean(d) #Remove cylindrical misalignment terms d = d - fit.fitCylMisalign(d)[0] # Negate to make bump positive. d = -d #Interpolate over NaNs if interp is not None: d = man.nearestNaN(d, method=interp) return d
def readFlat4D(fn,interp=None): """ Load in data from 4D measurement of flat mirror. Scale to microns, remove misalignments, strip NaNs. Distortion is bump positive looking at surface from 4D. Imshow will present distortion in proper orientation as if viewing the surface. """ #Get xpix value in mm l = getline(fn,9) dx = float(l.split()[1])*1000. #Remove NaNs and rescale d = np.genfromtxt(fn,skip_header=12,delimiter=',') d = man.stripnans(d) d = d *.6328 d = d - np.nanmean(d) d = np.fliplr(d) #Interpolate over NaNs if interp is not None: d = man.nearestNaN(d,method=interp) return d,dx
def readConicWFS(fn,interp=None): """ Load in data from WFS measurement of cylindrical mirror. Assumes that data was processed using processHAS, and loaded into a .fits file. Scale to microns, remove misalignments, strip NaNs. If rotate is set to an array of angles, the rotation angle which minimizes the number of NaNs in the image after stripping perimeter nans is selected. Distortion is bump positive looking at concave surface. Imshow will present distortion in proper orientation as if viewing the concave surface. Returns the data with best fit conic removed, as well as the coefficients in the conic fit. """ #Remove NaNs and rescale d = pyfits.getdata(fn) d = man.stripnans(d) d = d - np.nanmean(d) # Negate to make bump positive and rotate to be consistent with looking at the part beamside. #d = -d d = -np.fliplr(d) #np.rot90(d,k = 2) #Remove cylindrical misalignment terms conic_fit = fit.fitConic(d) d = d - conic_fit[0] #Interpolate over NaNs if interp is not None: d = man.nearestNaN(d,method=interp) return d,conic_fit[1]
def littrow(): """ Trace rectangular beam into OPG in Littrow. 400 nm groove period 8.4 m groove convergence """ #Set up beam rays = sources.rectArray(50., 50., 1e2) #Trace to Littrow and diffract tran.transform(rays, 0, 0, 0, 0, 52.28 * np.pi / 180, 0) surf.flat(rays) tran.transform(rays, 0, 8400., 0, 0, 0, 0) tran.radgrat(rays, 400. / 8400., 1, 632.8) #Steer out beam tilt tran.steerX(rays) tran.steerY(rays) #Bring rays to common plane surf.flat(rays) #Interpolate slopes to regular grid y, dx, dy = anal.interpolateVec(rays, 5, 200, 200) x, dx, dy = anal.interpolateVec(rays, 4, 200, 200) #Prepare arrays for integration #Reconstruct requires nans be replaced by 100 #Fortran functions require arrays to be packed in #fortran contiguous mode x = man.padRect(x) y = man.padRect(y) phase = np.zeros(np.shape(x), order='F') phase[np.isnan(x)] = 100. x[np.isnan(x)] = 100. y[np.isnan(y)] = 100. y = np.array(y, order='F') x = np.array(x, order='F') #Reconstruct and remove border phase = reconstruct.reconstruct(x, y, 1e-12, dx, phase) phase[phase == 100] = np.nan x[x == 100] = np.nan y[y == 100] = np.nan return man.stripnans(phase), man.stripnans(x), man.stripnans(y)
def readConic4D(fn,rotate=None,interp=None): """ Load in data from 4D measurement of cylindrical mirror. Scale to microns, remove misalignments, strip NaNs. If rotate is set to an array of angles, the rotation angle which minimizes the number of NaNs in the image after stripping perimeter nans is selected. Distortion is bump positive looking at concave surface. Imshow will present distortion in proper orientation as if viewing the concave surface. """ #Get xpix value in mm l = getline(fn,9) dx = float(l.split()[1])*1000. #Remove NaNs and rescale d = np.genfromtxt(fn,skip_header=12,delimiter=',') d = man.stripnans(d) d = d *.6328 d = d - np.nanmean(d) #d = np.rot90(d,k = 2) #Remove cylindrical misalignment terms conic_fit = fit.fitConic(d) d = d - conic_fit[0] #Rotate out CGH roll misalignment? if rotate is not None: b = [np.sum(np.isnan(\ man.stripnans(\ nd.rotate(d,a,order=1,cval=np.nan)))) for a in rotate] d = man.stripnans(\ nd.rotate(d,rotate[np.argmin(b)],order=1,cval=np.nan)) #Interpolate over NaNs if interp is not None: d = man.nearestNaN(d,method=interp) return d,dx,conic_fit[1]
def computeMeritFunctions(d,dx,x0=np.linspace(-2.,2.,1000),\ R0 = 220.,Z0 = 8400.,wave = 1.24e-6,\ renorm=True): """ RMS axial slope Axial sag d in microns """ #Remove NaNs d = man.stripnans(d) #Compute PSF primfoc = conic.primfocus(R0, Z0) dx2 = x0[1] - x0[0] resa = scat.primary2DPSF(d, dx[0], R0=R0, Z0=Z0, x0=x0, wave=wave) #Make sure over 95% of flux falls in detector integral = np.sum(resa) * dx2 if integral < .95: print 'Possible sampling problem' print str(np.sum(resa) * dx2) if integral > 1.5: print 'Possible aliasing problem' print str(np.sum(resa) * dx2) #Normalize the integral to account for some flux #scattered beyond the detector if renorm is True: resa = resa / integral cdf = np.cumsum(resa) * dx2 #Compute PSF merit functions # Computing the rms rigorously, but not usefully. #rmsPSF = np.sqrt(np.sum(resa*x0**2)*dx2-(np.sum(resa*x0)*dx2)**2) # Computing the rms by assuming a Gaussian profile. rmsPSF = x0[np.argmin(np.abs(cdf-.84))]-\ x0[np.argmin(np.abs(cdf-.16))] hpdPSF = x0[np.argmin(np.abs(cdf-.75))]-\ x0[np.argmin(np.abs(cdf-.25))] return rmsPSF/primfoc*180/np.pi*60**2*2,hpdPSF/primfoc*180/np.pi*60**2,\ [x0,resa]
def readFlatScript(fn,interp=None): """ Load in data from 4D measurement of flat mirror. File is assumed to have been saved with Ryan's scripting function. Scale to microns, remove misalignments, strip NaNs. Distortion is bump positive looking at surface from 4D. Imshow will present distortion in proper orientation as if viewing the surface. """ #Read in values from header f = open(fn+'.hdr','r') l = f.readlines() f.close() #Wavelength should never change wave = float(l[0].split()[0])*.001 #in microns #Ensure wedge factor is 0.5 wedge = float(l[1]) if wedge!=0.5: print 'Wedge factor is ' + str(wedge) pdb.set_trace() #Get pixel scale size dx = float(l[-1]) #Remove NaNs and rescale d = np.fromfile(fn+'.bin',dtype=np.float32) try: d = d.reshape((1002,981)) except: d = d.reshape((1003,982)) d[d>1e10] = np.nan d = man.stripnans(d) d = d *.6328 d = d - np.nanmean(d) d = np.fliplr(d) #Interpolate over NaNs if interp is not None: d = man.nearestNaN(d,method=interp) return d,dx
def readCylWFSRaw(fn): """ Load in data from WFS measurement of cylindrical mirror. Assumes that data was processed using processHAS, and loaded into a .fits file. Scale to microns, remove misalignments, strip NaNs. If rotate is set to an array of angles, the rotation angle which minimizes the number of NaNs in the image after stripping perimeter nans is selected. Distortion is bump positive looking at concave surface. Imshow will present distortion in proper orientation as if viewing the concave surface. """ #Remove NaNs and rescale d = pyfits.getdata(fn) d = man.stripnans(d) # Negate to make bump positive. d = -d return d
def realPSD(d0, win=np.hanning, dx=1., axis=None, nans=False, minpx=10): """(Ryan Allured) This function returns the PSD of a real function Gets rid of zero frequency and puts all power in positive frequencies Returns only positive frequencies """ from utilities.imaging.man import stripnans if nans is True: d = stripnans(d0) else: d = d0 if len(d) < minpx: return np.nan #Get Fourier components c = components(d, win=win) #Handle collapsing to 1D PSD if axis keyword is set if axis == 0: c = c[:, 0] elif axis == 1: c = c[0, :] #Reform into PSD if np.size(np.shape(c)) is 2: f = [np.fft.fftfreq(np.shape(c)[0],d=dx)[:np.shape(c)[0]/2],\ np.fft.fftfreq(np.shape(c)[1],d=dx)[:np.shape(c)[1]/2]] c = c[:np.shape(c)[0] / 2, :np.shape(c)[1] / 2] c[0, 0] = 0. #Handle normalization c = 2 * c c[0, :] = c[0, :] / np.sqrt(2.) c[:, 0] = c[:, 0] / np.sqrt(2.) elif np.size(np.shape(c)) is 1: f = np.fft.fftfreq(np.size(c), d=dx) f = f[:np.size(c) / 2] c = c[:np.size(c) / 2] c[0] = 0. c = c * np.sqrt(2.) return f[1:], np.abs(c[1:])**2
def readCyl4D_h5(h5_file): f = h5py.File(h5_file, 'r') meas = f['measurement0'] ################# # Getting the attributes of the data directly from the .h5 file wedge = meas['genraw'].attrs['wedge'] height_unit = meas['genraw'].attrs['height_units'] wave = meas['genraw'].attrs['wavelength'] xpix = meas['genraw'].attrs['xpix'] ################# # Processing the data as though it's a cylinder. # Apply the wedge factor. raw_data = array(meas['genraw']['data']) #*wedge # Removing the absurdly large value defaulted to for bad data and replacing it with a NaN. raw_data[raw_data > 1e10] = NaN # Then stripping that bad data flagged as nans from the perimeter. data = man.stripnans(raw_data) # Set the average surface to zero (i.e., remove piston) data -= nanmean(data) # Remove cylindrical misalignment. data = data - fit.fitCylMisalign(data)[0] # Apply unit transformation converting data to microns. if height_unit == 'wv': wavelength = float(wave[:-3]) data *= wavelength / 1000 if height_unit == 'nm': data /= 1000 # Apply unit transformation converting pixel size to mm. pix_unit = xpix[xpix.find(' ') + 1:] pix_num = float(xpix[:xpix.find(' ')]) if pix_unit == 'inch': pix_num *= 25.4 return data, pix_num
def readFlatWFS(fn,interp=None): """ Load in data from WFS measurement of flat mirror. Assumes that data was processed using processHAS, and loaded into a .fits file. Scale to microns, strip NaNs. If rotate is set to an array of angles, the rotation angle which minimizes the number of NaNs in the image after stripping perimeter nans is selected. Distortion is bump positive looking at concave surface. Imshow will present distortion in proper orientation as if viewing the concave surface. """ #Remove NaNs and rescale d = pyfits.getdata(fn) d = man.stripnans(d) d = -d #Interpolate over NaNs if interp is not None: d = man.nearestNaN(d,method=interp) return d
def plot_measured_correction(input_dist, theo_corr, meas_corr, dx, first_title='', second_title='', third_title='', sum_title='', cbar_label='', global_title='', save_file=None, est_perf=False, dist_merit=None, meas_corr_merit=None, vbounds=None): ''' ''' fig = plt.figure(figsize=(12, 10)) gs = gridspec.GridSpec(2, 2) ax1 = fig.add_subplot(gs[0]) ax2 = fig.add_subplot(gs[1]) ax3 = fig.add_subplot(gs[2]) ax4 = fig.add_subplot(gs[3]) #fig.subplots_adjust(top = 0.9,hspace = 0.1,wspace = 0.1) plot_dist = man.stripnans(input_dist - nanmean(input_dist)) plot_theo_corr = man.newGridSize( man.stripnans(theo_corr - nanmean(theo_corr)), shape(plot_dist)) plot_meas_corr = man.newGridSize( man.stripnans(meas_corr - nanmean(meas_corr)), shape(plot_dist)) extent = [ -shape(plot_theo_corr)[0] / 2 * dx, shape(plot_theo_corr)[0] / 2 * dx, -shape(plot_theo_corr)[0] / 2 * dx, shape(plot_theo_corr)[0] / 2 * dx ] if vbounds == None: vmin, vmax = nanmin([ plot_dist, plot_theo_corr, plot_meas_corr, plot_dist + plot_meas_corr ]), nanmax([ plot_dist, plot_theo_corr, plot_meas_corr, plot_dist + plot_meas_corr ]) else: [vmin, vmax] = vbounds im = ax1.imshow(plot_dist, extent=extent, vmin=vmin, vmax=vmax) ax1.set_xlabel('Azimuthal Dimension (mm)') ax1.set_ylabel('Axial Dimension (mm)') ax1.set_title(first_title) divider = make_axes_locatable(ax1) cax1 = divider.append_axes("right", size="5%", pad=0.10) cbar1 = plt.colorbar(im, cax=cax1) cbar1.set_label(cbar_label) ax2.imshow(plot_theo_corr, extent=extent, vmin=vmin, vmax=vmax) ax2.set_xlabel('Azimuthal Dimension (mm)') ax2.set_ylabel('Axial Dimension (mm)') ax2.set_title(second_title) divider = make_axes_locatable(ax2) cax2 = divider.append_axes("right", size="5%", pad=0.10) cbar2 = plt.colorbar(im, cax=cax2) cbar2.set_label(cbar_label) ax3.imshow(plot_meas_corr, extent=extent, vmin=vmin, vmax=vmax) ax3.set_xlabel('Azimuthal Dimension (mm)') ax3.set_ylabel('Axial Dimension (mm)') ax3.set_title(third_title) divider = make_axes_locatable(ax3) cax3 = divider.append_axes("right", size="5%", pad=0.10) cbar3 = plt.colorbar(im, cax=cax3) cbar3.set_label(cbar_label) ax4.imshow(plot_meas_corr + plot_dist, extent=extent, vmin=vmin, vmax=vmax) ax4.set_xlabel('Azimuthal Dimension (mm)') ax4.set_ylabel('Axial Dimension (mm)') ax4.set_title(sum_title) divider = make_axes_locatable(ax4) cax4 = divider.append_axes("right", size="5%", pad=0.10) cbar4 = plt.colorbar(im, cax=cax4) cbar4.set_label(cbar_label) fig.subplots_adjust(top=0.85, hspace=0.4, wspace=0.4) plt.suptitle(global_title, fontsize=20) if est_perf == True: print 'Computing performance for plotting... Be patient!' dist_merit = eva.computeMeritFunctions(plot_dist, [dx]) corr_merit = eva.computeMeritFunctions(plot_dist + plot_meas_corr, [dx]) ax1.text(0.05, 0.05, 'PSF RMS: ' + "{:4.1f}".format(dist_merit[0]) + ' asec.', ha='left', transform=ax1.transAxes) ax1.text(0.05, 0.10, 'PSF HPD: ' + "{:3.1f}".format(dist_merit[1]) + ' asec.', ha='left', transform=ax1.transAxes) ax4.text(0.05, 0.05, 'PSF RMS: ' + "{:4.1f}".format(meas_corr_merit[0]) + ' asec.', ha='left', transform=ax4.transAxes) ax4.text(0.05, 0.10, 'PSF HPD: ' + "{:3.1f}".format(meas_corr_merit[1]) + ' asec.', ha='left', transform=ax4.transAxes) if save_file != None: plt.savefig(save_file) return fig, (ax1, ax2, ax3, ax4)
def plot_computed_correction_inline(input_dist,fc,cor,dx,shade,first_title = '',second_title = '',sum_title = '', \ cbar_label = '',global_title = '',save_file = None,est_perf = False, \ dist_merit = None,corr_merit = None,vbounds = None): ''' ''' fig = plt.figure(figsize=(18, 5)) gs = gridspec.GridSpec(1, 3) ax1 = fig.add_subplot(gs[0]) ax2 = fig.add_subplot(gs[1]) ax3 = fig.add_subplot(gs[2]) #fig.subplots_adjust(top = 0.9,hspace = 1.0,wspace = 1.0) plot_corr = man.stripnans(comp_corr) corr_shade = ~isnan(comp_corr) plot_dist = stripWithShade(input_dist, corr_shade) extent = [ -shape(plot_corr)[0] / 2 * dx, shape(plot_corr)[0] / 2 * dx, -shape(plot_corr)[0] / 2 * dx, shape(plot_corr)[0] / 2 * dx ] if shape(plot_dist) != shape(plot_corr): print "Something's f****d here, mate" pdb.set_trace() if vbounds == None: vmin, vmax = nanmin([plot_dist, plot_corr, plot_dist + plot_corr]), nanmax( [plot_dist, plot_corr, plot_dist + plot_corr]) else: [vmin, vmax] = vbounds im = ax1.imshow(plot_dist, extent=extent, vmin=vmin, vmax=vmax) ax1.set_xlabel('Azimuthal Dimension (mm)') ax1.set_ylabel('Axial Dimension (mm)') ax1.set_title(first_title) divider = make_axes_locatable(ax1) cax1 = divider.append_axes("right", size="5%", pad=0.10) cbar1 = plt.colorbar(im, cax=cax1) cbar1.set_label(cbar_label) ax2.imshow(plot_corr, extent=extent, vmin=vmin, vmax=vmax) ax2.set_xlabel('Azimuthal Dimension (mm)') ax2.set_ylabel('Axial Dimension (mm)') ax2.set_title(second_title) divider = make_axes_locatable(ax2) cax2 = divider.append_axes("right", size="5%", pad=0.10) cbar2 = plt.colorbar(im, cax=cax2) cbar2.set_label(cbar_label) ax3.imshow(plot_dist + plot_corr, extent=extent, vmin=vmin, vmax=vmax) ax3.set_xlabel('Azimuthal Dimension (mm)') ax3.set_ylabel('Axial Dimension (mm)') ax3.set_title(sum_title) divider = make_axes_locatable(ax3) cax3 = divider.append_axes("right", size="5%", pad=0.10) cbar3 = plt.colorbar(im, cax=cax3) cbar3.set_label(cbar_label) fig.subplots_adjust(top=0.7, hspace=0.05, wspace=0.6) plt.suptitle(global_title, fontsize=20) if est_perf == True: print 'Computing performance for plotting... Be patient!' dist_merit = eva.computeMeritFunctions(plot_dist, [dx]) corr_merit = eva.computeMeritFunctions(plot_dist + plot_corr, [dx]) ax1.text(0.05, 0.05, 'PSF RMS: ' + "{:4.1f}".format(dist_merit[0]) + ' asec.', ha='left', transform=ax1.transAxes) ax1.text(0.05, 0.10, 'PSF HPD: ' + "{:3.1f}".format(dist_merit[1]) + ' asec.', ha='left', transform=ax1.transAxes) ax3.text(0.05, 0.05, 'PSF RMS: ' + "{:4.1f}".format(corr_merit[0]) + ' asec.', ha='left', transform=ax3.transAxes) ax3.text(0.05, 0.10, 'PSF HPD: ' + "{:3.1f}".format(corr_merit[1]) + ' asec.', ha='left', transform=ax3.transAxes) elif logical_and(dist_merit is not None, corr_merit is not None): ax1.text(0.05, 0.05, 'PSF RMS: ' + "{:4.1f}".format(dist_merit[0]) + ' asec.', ha='left', transform=ax1.transAxes) ax1.text(0.05, 0.10, 'PSF HPD: ' + "{:3.1f}".format(dist_merit[1]) + ' asec.', ha='left', transform=ax1.transAxes) ax3.text(0.05, 0.05, 'PSF RMS: ' + "{:4.1f}".format(corr_merit[0]) + ' asec.', ha='left', transform=ax3.transAxes) ax3.text(0.05, 0.10, 'PSF HPD: ' + "{:3.1f}".format(corr_merit[1]) + ' asec.', ha='left', transform=ax3.transAxes) if save_file != None: plt.savefig(save_file) return fig, (ax1, ax2, ax3)
def plot_correction_inline_vlad(input_dist,fc,cor,dx,first_title = '',second_title = '',third_title = '', cbar_label = '',global_title = '',save_file = None,dist_merit = None,vbounds = None,\ fc_merit = None,cor_merit = None, merit1_label = 'PSF E68', merit2_label = 'PSF HPD',merit1_unit = 'asec.',merit2_unit = 'asec.'): ''' ''' fig = plt.figure(figsize=(18, 5)) gs = gridspec.GridSpec(1, 3) ax1 = fig.add_subplot(gs[0]) ax2 = fig.add_subplot(gs[1]) ax3 = fig.add_subplot(gs[2]) plot_dist = man.stripnans(input_dist - nanmean(input_dist)) plot_fc = man.newGridSize(man.stripnans(fc - nanmean(fc)), shape(plot_dist)) plot_cor = man.newGridSize(man.stripnans(cor - nanmean(cor)), shape(plot_dist)) extent = [ -shape(plot_dist)[0] / 2 * dx, shape(plot_dist)[0] / 2 * dx, -shape(plot_dist)[0] / 2 * dx, shape(plot_dist)[0] / 2 * dx ] #if vbounds is None: # vmin,vmax = nanmin([plot_dist,plot_fc,plot_cor]),nanmax([plot_dist,plot_fc,plot_cor]) #else: # [vmin,vmax] = vbounds mirror_subplot_vlad(plot_dist, ax1, first_title, cbar_label, extent=extent, merit=dist_merit, merit1_label=merit1_label, merit2_label=merit2_label, merit1_unit=merit1_unit, merit2_unit=merit2_unit) mirror_subplot_vlad(plot_fc, ax2, second_title, cbar_label, extent=extent, merit=fc_merit, merit1_label=merit1_label, merit2_label=merit2_label, merit1_unit=merit1_unit, merit2_unit=merit2_unit) mirror_subplot_vlad(plot_cor, ax3, third_title, cbar_label, extent=extent, merit=cor_merit, merit1_label=merit1_label, merit2_label=merit2_label, merit1_unit=merit1_unit, merit2_unit=merit2_unit) fig.subplots_adjust(top=0.74, hspace=0.3, wspace=0.5) plt.suptitle(global_title, fontsize=20) if save_file != None: plt.savefig(save_file) plt.close() return plot_dist, plot_fc, plot_cor
def stripWithShade(dist, shade): output = copy(dist) output = man.newGridSize(dist, shape(shade)) output[shade == 0] = NaN return man.stripnans(output)
def plot_measured_correction_sixfig(input_dist, theo_corr, meas_corr0, meas_corr1, dx, first_title='', second_title='', third_title='', fourth_title='', fifth_title='', sixth_title='', cbar_label='', global_title='', save_file=None, dist_merit=None, meas_corr_merit0=None, meas_corr_merit1=None, vbounds=None): ''' ''' fig = plt.figure(figsize=(12, 16)) gs = gridspec.GridSpec(3, 2) ax1 = fig.add_subplot(gs[0]) ax2 = fig.add_subplot(gs[1]) ax3 = fig.add_subplot(gs[2]) ax4 = fig.add_subplot(gs[3]) ax5 = fig.add_subplot(gs[4]) ax6 = fig.add_subplot(gs[5]) plot_dist = man.stripnans(input_dist - nanmean(input_dist)) plot_theo_corr = man.newGridSize( man.stripnans(theo_corr - nanmean(theo_corr)), shape(plot_dist)) plot_meas_corr0 = man.newGridSize( man.stripnans(meas_corr0 - nanmean(meas_corr0)), shape(plot_dist)) plot_meas_corr1 = man.newGridSize( man.stripnans(meas_corr1 - nanmean(meas_corr1)), shape(plot_dist)) extent = [ -shape(plot_theo_corr)[0] / 2 * dx, shape(plot_theo_corr)[0] / 2 * dx, -shape(plot_theo_corr)[0] / 2 * dx, shape(plot_theo_corr)[0] / 2 * dx ] if vbounds == None: vmin = nanmin([ plot_dist, plot_theo_corr, plot_meas_corr0, plot_dist + plot_meas_corr0, plot_meas_corr1, plot_dist + plot_meas_corr1 ]), vmax = nanmax([ plot_dist, plot_theo_corr, plot_meas_corr, plot_dist + plot_meas_corr, plot_meas_corr1, plot_dist + plot_meas_corr1 ]) else: [vmin, vmax] = vbounds mirror_subplot(plot_dist, ax1, first_title, cbar_label, extent=extent, vmin=vmin, vmax=vmax, merit=dist_merit) mirror_subplot(plot_theo_corr, ax2, second_title, cbar_label, extent=extent, vmin=vmin, vmax=vmax, merit=None) mirror_subplot(plot_meas_corr0, ax3, third_title, cbar_label, extent=extent, vmin=vmin, vmax=vmax, merit=None) mirror_subplot(plot_meas_corr0 + plot_dist, ax4, fourth_title, cbar_label, extent=extent, vmin=vmin, vmax=vmax, merit=meas_corr_merit0) mirror_subplot(plot_meas_corr1, ax5, fifth_title, cbar_label, extent=extent, vmin=vmin, vmax=vmax, merit=None) mirror_subplot(plot_meas_corr1 + plot_dist, ax6, sixth_title, cbar_label, extent=extent, vmin=vmin, vmax=vmax, merit=meas_corr_merit1) fig.subplots_adjust(hspace=0.4, wspace=0.3) plt.suptitle(global_title, fontsize=20) if save_file != None: plt.savefig(save_file) plt.close() return fig, (ax1, ax2, ax3, ax4, ax5, ax6)