Request: Sun/moon position for a place everyday

27 views
Skip to first unread message

Arun Ganesh

unread,
Apr 21, 2012, 8:10:26 AM4/21/12
to ScraperWiki
Hi everyone, as part of the nasa space apps challenge (
http://spaceappschallenge.org/, I was looking at creating something
that would get common people to start looking at the stars here in
India. I was hunting for code that could calculate the sun's and moon
position for a place and time, but that seems to complex for the
limited time I have.

Is there any way to scrape the data from http://www.satellite-calculations.com/Satellite/suncalc.htm
? I basically want the sun and moon longitude values updated once a
day for India.

Any help or an easier way to go about it appreciated.
Thanks,
Arun

reclosedev

unread,
Apr 21, 2012, 9:53:59 AM4/21/12
to scrap...@googlegroups.com
Have you tried  PyEphem http://rhodesmill.org/pyephem/?

That site is based on Javascript and it's hard to scrape data from it.

суббота, 21 апреля 2012 г., 16:10:26 UTC+4 пользователь Arun Ganesh написал:

Thomas Levine

unread,
Apr 23, 2012, 3:52:50 PM4/23/12
to scrap...@googlegroups.com
It looks like those figures come from a model rather than empirical measurements.

Follow the Javascript functions.

update references AutoCalculateAngles, which references CalculateAngles, which references moon_angles.

function moon_angles(d,SiteLon,SiteLat){ var SunSouth,HourAngle,SIDEREALTIME,SatAz,SunSat,Tst,SatelliteAzimuth,pi,NewRA var w,a,e,M,L,N,oblecl,E,x,y,r,v,sunlon,z,xequat,yequat,zequat,RA,Decl,GMST0,UT,SIDTIME,HA var SunElevation,xhor,yhor,zhor,SunSatElevationDifference,SatElevation,GeometricElevation pi=Math.PI; var angles= new Array(); var sunangles=new Array(); var E0,E1,xeclip,yeclip,zeclip,Lm,Ls,Ms,Mm,D,F var P_lon1,P_lon2,P_lon3,P_lon4,P_lon5,P_lon6,P_lon7,P_lon8,P_lon9,P_lon10,P_lon11,P_lon12 var P_lat1,P_lat2,P_lat3,P_lat4,P_lat5,P_lat,P_lon,P_moondistance,Moon_RA,Moon_Decl var xh,yh,zh,MoonAzimuth,MoonElevation,Iterations,E_error,Ebeforeit,Eafterit,E_ErrorBefore //*********CALCULATE Moon DATA ********************* N=125.1228-0.0529538083*d; i=5.1454; w=318.0634 + 0.1643573223 * d ; //OK a=60.2666; //a=6.6107940559473451507806351067866; //a=0; //a=149476000; //km average distance e= 0.054900; M= 115.3654 + 13.0649929509 * d; w=Rev(w); M=Rev(M); N=Rev(N); // ok so far //alert('N='+N+'\n i='+i+'\n w='+w+'\n a='+a+'\n e='+e+'\n M='+M); E=M+ (180/pi)*e*Math.sin(Radians(M))*( 1+e * Math.cos(Radians(M)) ); E=Rev(E); // OK Ebeforeit=E; // now iterate until difference between E0 and E1 is less than 0.005_deg // use E0, calculate E1 Iterations=0; E_error=9; while ((E_error>0.0005) && (Iterations<20)) // ok - itererer korrekt { Iterations=Iterations+1; E0=E; E1= E0- (E0- (180/pi)*e*Math.sin(Radians(E0)) -M ) /( 1-e * Math.cos(Radians(E0))) ; //alert('1 E0='+E0+'\nNew E1='+E1+'\nE='+E+'\Diff='+Rev(E0-E1)); E=Rev(E1); //alert(Math.abs(E-E0)); Eafterit=E; if (E<E0) E_error=E0-E else E_error=E-E0; if (E<Ebeforeit) E_ErrorBefore=Ebeforeit-E else E_ErrorBefore=E-Ebeforeit; window.status="Iterations="+Iterations+" Moon eccentric anomaly error before iterations="+formatvalue(E_ErrorBefore,7)+"_deg after iterations="+E_error+"_deg"; if (Iterations>10) window.status="Number of Iterations more than 10="+Iterations+" Ebefore="+Ebeforeit+" Eafter="+Eafterit+" E_errorbefore="+formatvalue(E_ErrorBefore,7)+" E_errorafter"+E_error; } //alert(E); x= a*(Math.cos(Radians(E)) -e) ; y= a*Math.sin(Radians(Rev(E)))*Math.sqrt(1-e*e); r=Math.sqrt(x*x+y*y); v=Deg(Math.atan2(y,x)); //alert('E='+E); // ok så langt sunlon=Rev(v+w); // trolig ok x=r*Math.cos(Radians(sunlon)); y=r*Math.sin(Radians(sunlon)); z=0; xeclip=r*( Math.cos(Radians(N))*Math.cos(Radians(v+w)) - Math.sin(Radians(N)) * Math.sin(Radians(v+w))*Math.cos(Radians(i)) ); yeclip=r*( Math.sin(Radians(N))*Math.cos(Radians(v+w)) + Math.cos(Radians(N)) * Math.sin(Radians(v+w))*Math.cos(Radians(i)) ); zeclip=r*Math.sin(Radians(v+w))*Math.sin(Radians(i)); //alert('xeclip='+xeclip+'\nyeclip='+yeclip+'\nzeclip='+zeclip+'\Long='+Rev(v+w)); //ok so far moon_longitude=Rev(Deg(Math.atan2(yeclip,xeclip))); // OK moon_latitude=Deg(Math.atan2(zeclip,Math.sqrt(xeclip*xeclip +yeclip*yeclip ) )); // trolig OK // Now add Perbutations, we actually need Sun mean longitude and Suns mean anomaly //alert('moon_longitude='+moon_longitude+'\nmoon_latitude='+moon_latitude+'\nr='+r); sunangles=sun_angles(d,SiteLon,SiteLat); Ls=sunangles[11]; // Suns mean longitude er feil Ms=sunangles[6]; // Suns mean anomaly Mm=Rev(M); // Moons mean anomaly Lm=Rev(N+w+M) ; // moon mean longitude D=Rev(Lm-Ls); //Moons mean elongation F=Rev(Lm-N); //Moons argument of latitude //alert('Ms='+Ms+'\nMm='+Mm+'\nLs='+Ls+'\nLm='+Lm+'\nD='+D+'\nF='+F); // ok so far // Perbutations Moons Longitude P_lon1= -1.274 * Math.sin(Radians(Mm - 2*D)); // (Evection) P_lon2= +0.658 * Math.sin(Radians(2*D)); // (Variation) P_lon3= -0.186 * Math.sin(Radians(Ms) ) ; // (Yearly equation) P_lon4= -0.059 * Math.sin(Radians(2*Mm - 2*D)); P_lon5= -0.057 * Math.sin(Radians(Mm - 2*D + Ms)); P_lon6= +0.053 * Math.sin(Radians(Mm + 2*D)); P_lon7= +0.046 * Math.sin(Radians(2*D - Ms)); P_lon8= +0.041 * Math.sin(Radians(Mm - Ms)); P_lon9= -0.035 * Math.sin(Radians(D) ); // (Parallactic equation) P_lon10= -0.031 * Math.sin(Radians(Mm + Ms)); P_lon11= -0.015 * Math.sin(Radians(2*F - 2*D)); P_lon12= +0.011 * Math.sin(Radians(Mm - 4*D)); // Perbutations Moons Latitude P_lat1=-0.173 * Math.sin(Radians(F - 2*D)); P_lat2=-0.055 * Math.sin(Radians(Mm - F - 2*D)); P_lat3=-0.046 * Math.sin(Radians(Mm + F - 2*D)); P_lat4=+0.033 * Math.sin(Radians(F + 2*D)); P_lat5=+0.017 * Math.sin(Radians(2*Mm + F)); P_lon=P_lon1+P_lon2+P_lon3+P_lon4+P_lon5+P_lon6+P_lon7+P_lon8+P_lon9+P_lon10+P_lon11+P_lon12; P_lat=P_lat1+P_lat2+P_lat3+P_lat4+P_lat5; P_moondistance=-0.58 * Math.cos(Radians(Mm - 2*D)) -0.46 * Math.cos(Radians(2*D)); //alert('P_lon='+P_lon+'\nP_lat='+P_lat+'\nP_moondistance='+P_moondistance); moon_longitude=moon_longitude+P_lon; moon_latitude=moon_latitude+P_lat; r=r+P_moondistance; //alert('moon_longitude='+moon_longitude+'\nmoon_latitude='+moon_latitude+'\nmoondistance='+r); // OK so far // now calculate RA & Decl // get the Eliptic coordinates xh=r*Math.cos(Radians(moon_longitude))*Math.cos(Radians(moon_latitude)); yh=r*Math.sin(Radians(moon_longitude))*Math.cos(Radians(moon_latitude)); zh=r*Math.sin(Radians(moon_latitude)); // rotate to rectangular equatorial coordinates xequat=xh; yequat=yh*Math.cos(Radians(sunangles[9]))-zh*Math.sin(Radians(sunangles[9])); zequat=yh*Math.sin(Radians(sunangles[9]))+zh*Math.cos(Radians(sunangles[9])); Moon_RA=Rev(Deg(Math.atan2(yh,xh))); // OK Moon_Decl=Deg(Math.atan2(zh,Math.sqrt(xh*xh + yh*yh ) )); // trolig OK Moon_RA=Rev(Deg(Math.atan2(yequat,xequat))); // OK Moon_Decl=Deg(Math.atan2(zequat,Math.sqrt(xequat*xequat + yequat*yequat ) )); // trolig OK //alert('moon_RA='+Moon_RA+'\nMoon_Decl='+Moon_Decl+'\nmoondistance='+r+'\nObecl='+sunangles[9]); GMST0=(Ls+180); //*********CALCULATE TIME ********************* UT=d-Math.floor(d); //alert("UT="+UT); SIDEREALTIME=GMST0+UT*360+SiteLon; // ok HourAngle=SIDEREALTIME-Moon_RA; // trolig ok x=Math.cos(HourAngle*pi/180) * Math.cos(Moon_Decl*pi/180); y=Math.sin(HourAngle*pi/180) * Math.cos(Moon_Decl*pi/180); z=Math.sin(Moon_Decl*pi/180); xhor=x*Math.sin(SiteLat*pi/180) - z*Math.cos(SiteLat*pi/180); //alert('sitelat='+SiteLat+'\nsitelon='+SiteLon); yhor=y; zhor=x*Math.cos(SiteLat*pi/180) + z*Math.sin(SiteLat*pi/180); MoonElevation=Deg( Math.asin(zhor)); // ok regner ikke måne elevation helt riktig... MoonElevation=MoonElevation- Deg(Math.asin( 1/r * Math.cos(Radians(MoonElevation)) )); GeometricElevation=MoonElevation; MoonElevation=ElevationRefraction(MoonElevation); // atmospheric refraction MoonAzimuth=Deg(Math.atan2(yhor,xhor)); angles[0]=MoonElevation; if (SiteLat<0) angles[1]=MoonAzimuth+180 // added 180 deg else angles[1]=MoonAzimuth+180; //alert("Moon Raw Az="+MoonAzimuth); //alert('Moon Azimuth='+angles[1]+'\nMoon Elevation='+MoonElevation+' Geometric elevation='+GeometricElevation); angles[2]=Moon_Decl; angles[3]=moon_longitude; angles[4]=Moon_RA; angles[5]=Rev(GMST0); angles[6]=Rev(M); angles[7]=Rev(w); angles[8]=Rev(e); angles[9]=Rev(oblecl); angles[10]=GeometricElevation; angles[11]=moon_latitude; angles[12]=MoonElevation; angles[13]=r; return(angles); }

So it looks like this website has the code you want to calculate the positions of the sun and the moon.

Tom
Reply all
Reply to author
Forward
0 new messages