diff --git a/src/new/mirror_maps/FT_prepare_phase_map_for_finesse.m b/src/new/mirror_maps/FT_prepare_phase_map_for_finesse.m index 02272bc866d2fe1d515673b7bb3e1155305652f4..65b041d055245cdee416ac0ae9652e72a377a083 100644 --- a/src/new/mirror_maps/FT_prepare_phase_map_for_finesse.m +++ b/src/new/mirror_maps/FT_prepare_phase_map_for_finesse.m @@ -1,57 +1,54 @@ %-------------------------------------------------------------------------- -% function [map_out,zc] = FT_prepare_phase_map_for_finesse(map,curvature) +% function [map_out] = FT_prepare_phase_map_for_finesse(map,curvature,w) % -% A Matlab function which prepares a (phase) mirror map for use in Finesse, -% using Zernike polynomials to remove effects such as offset, tilt and -% residual curvature. The function then saves the resulting map in the -% file format for use in Finesse, as well as creating and saving a map -% representing the aperture created by the mirror. +% A Matlab function which prepares a (phase) mirror map for use in Finesse. +% Any curvature, tilt or offset of the surface is removed as these +% properties are specified with the finesse .kat file. The function saves +% the resulting map in the file format for use in Finesse, as well as +% creating and saving a map representing the aperture created by the map. +% A file containing information on the properties removed from the maps is +% also produced. +% +% This function allows the user to specify if a gaussian weighting should +% be used when removing these properties. If a guassian weight is +% specified the function uses fitting functions using fminsearch to fit and +% remove the curvature and tilt of the surface, weighting the fitting to +% get the best fit for a particular gaussian radius. If a gaussian +% weighting is not required the function uses an inner product with +% specific Zernike polynomials (Z20, Z1+/-1, Z00). % % map: Input map to be prepared and converted for Finesse % offset: [x0 y0] offset to the map optical centre ([0,0] for map % centre) [mm] -% curvature: Variable which determines what curvature to remove from the -% map. -% 'constant': remove constant curvature (Z20 term) -% 'all': remove constant and astigmatic curvature -% (Z20 and Z22 terms) -% 'astigmatism': remove just Z22 term -% 'none': no curvature removal +% w: Beam-size for gaussian weighting for curvature etc. +% removal [m]. For no gaussian weighting use w = 0; % % map_out: Returned map, after preparation for Finesse -% zc: Zernike content. Summary of the zernike polynomials in the -% original map. % % Part of the Simtools package, http://www.gwoptics.org/simtools % Charlotte Bond 04.05.2012 %-------------------------------------------------------------------------- % -function [map_out,zc] = FT_prepare_phase_map_for_finesse(map,offset,curvature) - - % TO DO: 04.05.2012 - % Add in gaussian weighting function +function [map_out] = FT_prepare_phase_map_for_finesse(map,offset,w) baseid = 'prepare_phase_map_for_finesse'; - - % Error messages - if (~strcmp(curvature,'none') && ~strcmp(curvature,'astigmatism') && ... - ~strcmp(curvature,'constant') && ~strcmp(curvature,'all')) - msg = 'Invalid value: curvature must be "constant", "astigmatism", "all" or "none"' - msgid = [baseid,':checkarguments'] - error(msgid,result); - end % Output filenames basename = map.name; + % Finesse map file f_mapname = sprintf('%s',basename,'_for_finesse.txt'); + % Finesse aperture file a_mapname = sprintf('%s',basename,'_aperture.txt'); - zc_name = sprintf('%s',basename,'_zernike_content'); + % File storing results of preparation, fittings etc. results_name = sprintf('%s',basename,'_conversion_info.txt'); + % set display style for fitting routines to 'final' + display_style=0; + % Factor to scale map.data to nm (usually 1) nm_scaling = map.scaling*1e9; - + % Output map and temporary map map_out = map; @@ -61,36 +58,63 @@ function [map_out,zc] = FT_prepare_phase_map_for_finesse(map,offset,curvature) % Remove invalid outside elements map_out = FT_remove_elements_outside_map(map_out); - - [y,x]=size(map.data); - - disp(' --- removing Zernike terms Z00, Z11 and Z20 ...') - % Removing offset - [map_out,zc] = FT_remove_zernike_offset_from_map(map_out); - A(1) = nm_scaling*zc.amp(1,1); - disp(sprintf(' --- removing offset of A00 = %g [nm] ...',A(1))) - - % Removing tilt -> -1 (odd polynomial), +1 (even polynomial) - [map_out,zc] = FT_remove_zernike_tilt_from_map(map_out); - A(2) = nm_scaling*zc.amp(2,1); - A(3) = nm_scaling*zc.amp(2,2); - disp(sprintf(' --- removing tilt of A11 = %g [nm] ...',sqrt(A(2)^2+A(3)^2))) + + % Map radius + R = map_out.xstep*FT_find_map_radius(map_out); - A(4:6) = 0; - if ~(strcmp(curvature,'none')) - % Remove curvature - [map_out,zc] = FT_remove_zernike_curvatures_from_map(map_out,curvature); - if strcmp(curvature,'all') || strcmp(curvature,'constant') - A(5) = nm_scaling*zc.amp(3,2); - disp(sprintf(' --- removing curvature of A20 = %g [nm] ...',A(5))) - end - if strcmp(curvature,'all') || strcmp(curvature,'astigmatism') - A(4) = nm_scaling*zc.amp(3,1); - A(6) = nm_scaling*zc.amp(3,3); - disp(sprintf(' --- removing astigmatism of A22 = %g [nm] ...',sqrt(A(4)^2+A(6)^2))) + disp('--- removing curvature ...') + % Remove curvature using Zernike polynomials. If gaussian weighting is + % required a fitting function is used and this curvature (Rc_temp) is + % used as the initial guess of the curvature + [map2,A2,Rc_temp] = FT_remove_zernike_curvatures_from_map(map_out,'constant'); + if w~=0 + % If weighting required use fitting function + [map_out,Rc,A0_1] = FT_remove_curvature_from_mirror_map(map_out,Rc_temp(1),w,display_style); + % Equivalent Zernike amplitude + A2 = FT_Rc_to_Znm(Rc,R); + % Offset from fitting function. -A2 is removed as this offset is + % automatically part of the curvature polynomial (i.e. Z20 = + % A20*(r^2 - 1). + A0_1 = A0_1+A2; + else + map_out = map2; + Rc = Rc_temp(1); + end + disp(sprintf(' --- removing curvature of A20 = %g [nm] ...',A2)) + disp(sprintf(' (Rc = %g [m] ...',Rc)) + + disp('--- removing offset ...') + % Remove average offset over beam-size/mirror + if w~=0 + % If weighting function is used remove the average offset over the + % beam radius + if w<R + [map_out,A0] = FT_remove_offset_from_mirror_map(map_out,w); + else + [map_out,A0] = FT_remove_offset_from_mirror_map(map_out,R); end + % Put into nm + A0 = A0*nm_scaling+A0_1; + else + [map_out,A0] = FT_remove_zernike_offset_from_map(map_out); end + disp(sprintf(' --- removing offset of A00 = %g [nm] ...',A0)) + + disp('--- removing piston ...') + % Remove piston + if w~=0 + % Use fitting function if gaussian weighting is required + [map_out,xbeta,ybeta,A0_2] = FT_remove_piston_from_mirror_map(map_out,w,display_style); + % Equivalent zernike amplitude + A1 = R*tan([ybeta xbeta])*1e9; + A0 = A0 + A0_2; + else + [map_out,A1,xbeta,ybeta] = FT_remove_zernike_tilt_from_map(map_out); + end + disp(sprintf(' --- removing tilt of A11 = %g [nm] ...',sqrt(A1(1)^2+A1(2)^2))) + disp(sprintf(' (xbeta = %g [rad], ybeta = %g [rad])',xbeta,ybeta)) + % Offset map if offset(1)~=0 || offset(2)~=0 % Add offset to mirror centre map_out.x0 = map_out.x0+offset(1)*1e-3/map_out.xstep; @@ -106,8 +130,8 @@ function [map_out,zc] = FT_prepare_phase_map_for_finesse(map,offset,curvature) disp(sprintf(' --- saving file "%s" ...',a_mapname)) FT_write_surface_map(a_mapname,a_map) - % Write results to STDOUT - write_results(1,map_out,A,offset); + % Write results to terminal + write_results(1,map_out,A0,A1,A2,Rc,xbeta,ybeta,offset); % ... and to file disp(sprintf(' --- writing results to file "%s" ...',results_name)); @@ -117,7 +141,7 @@ function [map_out,zc] = FT_prepare_phase_map_for_finesse(map,offset,curvature) msgid=[baseid,':fileopen']; error(msgid,result); end - write_results(FID,map_out,A,offset); + write_results(FID,map_out,A0,A1,A2,Rc,xbeta,ybeta,offset); fclose(FID); % and maybe plot the result @@ -126,14 +150,11 @@ function [map_out,zc] = FT_prepare_phase_map_for_finesse(map,offset,curvature) end -function []=write_results(FID,map,A,offset); +function []=write_results(FID,map,A0,A1,A2,Rc,xbeta,ybeta,offset); - % Calculate map radius [m] and equivalent optical features (angles for - % tilt, Rcs for curvature etc.) + % Calculate map radius [m] R = map.xstep*(FT_find_map_radius(map,'max')); - OF1 = FT_zernike_optical_features(A(3),R,1,1); - OF2 = FT_zernike_optical_features(A(2),R,1,-1); - + % use FID=1 for stdout % Output conversion data fprintf(FID,'\n---------------------------------------------------------\n'); @@ -141,23 +162,11 @@ function []=write_results(FID,map,A,offset); fprintf(FID,'Date: %s\n', datestr(now,'dd. mmmm yyyy (HH:MM:SS)')); fprintf(FID,'---------------------------------------------------------\n'); fprintf(FID,'Diameter: %3.3f cm\n',2*R*1e2); - fprintf(FID,'Offset (Z00): %3.1f nm\n',A(1)); - fprintf(FID,'Tilt (Z11): %3.1f nm\n',sqrt(A(2)^2+A(3)^2)); - fprintf(FID,'(xbeta = %2.2g urad, ybeta = %2.2g urad)\n',OF1.value*1e6,OF2.value*1e6); - if A(5)>0 - OF3 = FT_zernike_optical_features(A(5),R,2,0); - fprintf(FID,'Curvature (Z20): %3.1f nm\n',A(5)); - fprintf(FID,' (Rc = %3.1f m)\n',OF3.value); - end - if A(4)>0 || A(6)>0 - Amps = [A(4) A(5) A(6)]; - n = [2 2 2]; - m = [-2 0 2]; - OP4 = FT_zernike_optical_features(Amps,R,n,m); - fprintf(FID,'Astigmatism (Z22): %3.1f nm\n',sqrt(A(4)^2+A(6)^2)); - fprintf(FID,'Curvature (Z20): %3.1f nm\n',A(5)); - fprintf(FID,'(Rcx = %4.1f m, Rcy = %4.1f m)\n',OP4.value(1),OP4.value(2)); - end + fprintf(FID,'Offset (Z00): %3.1f nm\n',A0); + fprintf(FID,'Tilt (Z11): %3.1f nm\n',sqrt(A1(1)^2+A1(2)^2)); + fprintf(FID,'(xbeta = %2.2g urad, ybeta = %2.2g urad)\n',xbeta*1e6,ybeta*1e6); + fprintf(FID,'Curvature (Z20): %3.1f nm\n',A2); + fprintf(FID,'(Rc = %3.1f m)\n',Rc(1)); if offset(1)~=0 || offset(2)~=0 fprintf(FID,'x0 offset: %3.2f mm\n',offset(1)); fprintf(FID,'y0 offset: %3.2f mm\n',offset(2)); diff --git a/src/new/mirror_maps/FT_remove_zernike_curvatures_from_map.m b/src/new/mirror_maps/FT_remove_zernike_curvatures_from_map.m index 3ba960d26443b1b2e8f781e212adcc6d37ca211a..a979743ecd0a4087fb47c5d9e7f319e9665be87b 100644 --- a/src/new/mirror_maps/FT_remove_zernike_curvatures_from_map.m +++ b/src/new/mirror_maps/FT_remove_zernike_curvatures_from_map.m @@ -13,7 +13,7 @@ % 'astigmatism': Just remove astigmatism % % map_out: Returned map with curvatures removed -% A: Amplitudes of removed polynomials. +% A: Amplitudes of removed polynomials [nm] % If removing 'all', A = [A2-2 A20 A2+2], if 'constant', % A = A20, if 'astigmatism' A = [A2-2 A2+2]. % Rc: Equivalent curvature removed. Rc = [Rcx Rcy] (really @@ -65,6 +65,9 @@ function [map_out,A,Rc]=FT_remove_zernike_curvatures_from_map(map,curvature) end + % Put into nm + A = A*map.scaling*1e9; + % Calculate equivalent radius of curvature R = map.xstep*FT_find_map_radius(map); if length(mc)==1 @@ -76,6 +79,7 @@ function [map_out,A,Rc]=FT_remove_zernike_curvatures_from_map(map,curvature) A22 = sqrt(A(1)^2+A(3)^2); Rc = FT_Znm_to_Rc([A(2) A22],R); end + end diff --git a/src/new/mirror_maps/FT_remove_zernike_offset_from_map.m b/src/new/mirror_maps/FT_remove_zernike_offset_from_map.m index 7a62a6609400e19a1b8da9abc8a69d1884761b50..4dfed053e2b6eae1066a6082f2a13f28493eb86d 100644 --- a/src/new/mirror_maps/FT_remove_zernike_offset_from_map.m +++ b/src/new/mirror_maps/FT_remove_zernike_offset_from_map.m @@ -8,7 +8,7 @@ % map: Input map % % map_out: Output map with offset removed -% A: Amplitude of remove Zernike polynomial +% A: Amplitude of remove Zernike polynomial [nm] % % Charlotte Bond 30.01.2013 %-------------------------------------------------------------------------- @@ -24,6 +24,8 @@ function [map_out,A] = FT_remove_zernike_offset_from_map(map) % Remove offset from map A = FT_get_zernike_coefficient(zc,0,0); map_out = FT_remove_zernike_polynomial_from_map(map_out,0,0,A); - + + % In nm + A = A*1e9*map.scaling; end diff --git a/src/new/mirror_maps/FT_remove_zernike_tilt_from_map.m b/src/new/mirror_maps/FT_remove_zernike_tilt_from_map.m index da0c320f84abc9d3fa82feb99199ff3f35c6ad6b..eb34b4c1db09c45264f6b1b0b2f4099ce5770670 100644 --- a/src/new/mirror_maps/FT_remove_zernike_tilt_from_map.m +++ b/src/new/mirror_maps/FT_remove_zernike_tilt_from_map.m @@ -1,22 +1,24 @@ %-------------------------------------------------------------------------- -% function [map_out,zc] = FT_remove_zernike_tilt_from_map(map) +% function [map_out,A,xbeta,ybeta] = FT_remove_zernike_tilt_from_map(map) % % A function for Matlab which takes a map in the usual structure (see -% FT_new_surface_map.m) and removes tilt from the surface by calculating -% the overlap between the Zernike tilt terms and the map surface. +% FT_new_surface_map.m) and removes any tilt from the surface by +% calculating the overlap between the Zernike tilt terms and the map +% surface. % % map: Input map % % map_out: Output map with tilt removed -% A: Structure containing zernike coefficients from overlap with -% map. -% xbeta: +% A: Amplitude of the Zernike tilt terms removed [nm] +% A(1) = amplitude of Z1-1 (odd polynomial, tilt in y-direction) +% A(2) = amplitude of Z1+1 (even polynomial, tilt in x-direction) +% xbeta/ybeta: Equivalent tilt in radians removed from the surface % % Charlotte Bond 30.01.2013 %-------------------------------------------------------------------------- % -function [map_out,A,ybeta,xbeta] = FT_remove_zernike_tilt_from_map(map) +function [map_out,A,xbeta,ybeta] = FT_remove_zernike_tilt_from_map(map) % Zernike map convolution up to order 1 (don't save the data) zc = FT_zernike_map_convolution(map,1,0); @@ -34,6 +36,7 @@ function [map_out,A,ybeta,xbeta] = FT_remove_zernike_tilt_from_map(map) map_out = FT_remove_zernike_polynomial_from_map(map_out,1,1,A(2)); xbeta = atan(A(2)*map.scaling/R); - + % In nm + A = 1e9*map.scaling*A; end