%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function d = apparentAzEl(d, includeError) functions that retracts the pointing model and refraction corrections to go from encoder az/el to sky az/el. d - data structure creates new subfield: d.antenna0.servo.apparent, which is [Nby4], where each column corresponds to : [apparentAzimuth, apparentElevation, error in fit for Az, error in fit for El]; aza is the apparent azimuth ela is the apparent elevation erraz is the error between the antenna coordinate recorder in the data and what we get when we use the apparent position to start with for refraction and pointing calcualtions similarly for erralt CJC %%%%%%%%%%%%%%%%%%%%%%%%%%% ogk edit 1: Changed the condition in the while loop to Azimuth Error > threshold -> mod(Azimuth Error,360)>threshold %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% sjcm Aug 10, 2011: modified inputs so we don't report back the error in az/el automatically (which i don't think actually gets used anywhere); memory problem. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function d = apparentAzElSouth(d, includeError) 0002 0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0004 % 0005 % function d = apparentAzEl(d, includeError) 0006 % 0007 % functions that retracts the pointing model and refraction corrections to 0008 % go from encoder az/el to sky az/el. 0009 % 0010 % d - data structure 0011 % 0012 % creates new subfield: 0013 % d.antenna0.servo.apparent, which is [Nby4], where each column 0014 % corresponds to : 0015 % [apparentAzimuth, apparentElevation, error in fit for Az, error in fit 0016 % for El]; 0017 % 0018 % 0019 %aza is the apparent azimuth 0020 %ela is the apparent elevation 0021 %erraz is the error between the antenna coordinate recorder in the data and 0022 %what we get when we use the apparent position to start with for refraction 0023 %and pointing calcualtions 0024 %similarly for erralt 0025 % 0026 % CJC 0027 % 0028 %%%%%%%%%%%%%%%%%%%%%%%%%%%% 0029 % ogk edit 1: 0030 % Changed the condition in the while loop to 0031 % Azimuth Error > threshold -> mod(Azimuth Error,360)>threshold 0032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0033 % sjcm Aug 10, 2011: modified inputs so we don't report back the error in 0034 % az/el automatically (which i don't think actually gets used anywhere); 0035 % memory problem. 0036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0037 0038 if(nargin<2) 0039 includeError = 0; 0040 end 0041 0042 0043 %get the antenna coordinates that we start with 0044 azprime=d.antenna0.servo.az; 0045 elprime = d.antenna0.servo.el; 0046 maxitr=20; 0047 0048 %lets just see what sort of correction we get at this antenna angle (AZ')- 0049 %if we assume the difference between AZ (apparent) and AZ'(antenna) is 0050 %small then we can use this number as a start approximation- here we have 3 0051 %coordinates Az (apparent AZ) Az' (antenna Az) AZ'' (meaningless azimuth 0052 %position calculated by applying a pointing and refraction correction to ... 0053 % Az') and we 0054 %make the assumptio that Az-Az' is approximately Az'-Az'' 0055 [azdoubleprime,eldoubleprime]=calcAzEl2South(azprime,elprime,d); 0056 0057 %now we calculate what sort of offset we have, daz and del-note that this 0058 %offset is between AZ' and AZ''- ie daz=AZ'-AZ''- therefore to go back to 0059 %AZ we use the equation daz~=AZ-AZ' (using approximation) and therefore ... 0060 % AZ=AZ'+daz 0061 0062 daz=azprime-azdoubleprime; 0063 del=elprime-eldoubleprime; 0064 0065 %Now we assume that the difference between the apparent and antenna 0066 %coordinates is small i.e that the same sort of correction would have been 0067 %found if we'd done the calculation on the apparent coordinates- defining 0068 %apparent coordinates as AZ and antenna coordinates as AZ' we have 0069 %daz = AZ-AZ' (not the difference and similarity (!!!) with the calculation 0070 %above 0071 % AZ=AZ'+daz 0072 0073 azapp = azprime+daz; 0074 elapp = elprime+del; 0075 0076 %So these are our first guesses for the apparent azimuth and elevation 0077 %values- they should be ok but lets just check by going from these values 0078 %back to the antenna values and comparing 0079 0080 [azprime2,elprime2]=calcAzEl2South(azapp,elapp,d); 0081 0082 errazprime = (azprime-azprime2); 0083 errelprime = (elprime-elprime2); 0084 0085 maxazerr=max(abs(errazprime)); 0086 maxelerr=max(abs(errelprime)); 0087 vecazerr=[]; 0088 vecelerr=[]; 0089 a=isnan(daz); 0090 daz(a)=0; 0091 a=isnan(del); 0092 del(a)=0; 0093 %Now we iteratively adjust the Az (apparent coordinate) until it produces 0094 %the 'correct' AZ 0095 0096 alen=length(daz); 0097 i=0; 0098 %while(((maxazerr >0.0001) || (maxelerr>0.0001)) && (i<maxitr)) 0099 % i=i+1; 0100 %disp(['Iteration (max): ', num2str(i),'(',num2str(maxitr),')']); 0101 0102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0103 % ogk edit 1: change while loop conditional statement to 0104 % mod(maxazerr,360)<... 0105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0106 while(((mod(maxazerr,360) >0.0001) || (maxelerr>0.0001)) && (i<maxitr)) 0107 i=i+1; 0108 disp(['Iteration (max): ', num2str(i),'(',num2str(maxitr),')']); 0109 [azprime2,elprime2]=calcAzEl2South(azapp,elapp,d); 0110 errazprime = wrap180(azprime - azprime2); 0111 errelprime = wrap180(elprime - elprime2); 0112 a=isnan(errazprime); 0113 errazprime(a)=0; 0114 a=isnan(errelprime); 0115 errelprime(a)=0; 0116 0117 maxazerr=max(abs(errazprime)); 0118 maxelerr=max(abs(errelprime)); 0119 daz = daz + errazprime; 0120 del = del + errelprime; 0121 azapp= wrap360(azprime+daz); 0122 elapp = wrap360(elprime+del); 0123 vecazerr=[vecazerr maxazerr]; 0124 vecelerr=[vecelerr maxelerr]; 0125 %end 0126 end 0127 0128 if i>=maxitr 0129 %Error handling in case the removal of the pointing correction isn't 0130 % working 0131 error('Apparent Az/El not converging') 0132 end 0133 %might need some error checking here but otherwise 0134 0135 erraz=errazprime; 0136 errel=errelprime; 0137 aza=azapp; 0138 ela=elapp; 0139 0140 if(includeError) 0141 d.antenna0.servo.apparent = [aza ela erraz errel]; 0142 else 0143 d.antenna0.servo.apparent = [aza ela]; 0144 end 0145 0146 return;