Message Boards Message Boards

Issues with AstronomicalData and SunPosition

Posted 10 years ago
POSTED BY: Sjoerd de Vries
27 Replies
POSTED BY: Jeffrey Bryant
Posted 10 years ago

Thank you. And thanks for the link. Interestingly one of the datasources was the NASA one.

POSTED BY: John Drummond
Posted 10 years ago

Jeff, thanks for that. => Would you know what the accuracy of the SunPosition Calculations would or should be?

Here's the US Naval Laboratory for another comparison http://aa.usno.navy.mil/ they only have per minute on the site, but the numbers agree with the NASA 17:13 20.2 279.0 17:14 20.0 279.2 17:15 19.8 279.4 17:16 19.6 279.5

As Sjoerd kindly pointed out there's Mathematica did not take Atmospheric Refraction into consideration which will be something like 10 arc minutes at 5 degrees of altitude 1 at 45 and 35 at the horizon, or at 20 degrees of altitude something like 3 arc minutes (using Bennett's 1982 calculation) which is about 0.05 degrees. However this should increase the perceived altitude. So for the SunPosition Calculation this correction is big enough in magnitude, nor is it in the right direction to help with the reconciliation, as the SunPosition is supposed to exclude it.

=> Any thoughts how I reconcile these differences or am I missing something obvious?

=> Would you know what is supposed to be the most accurate estimate (I understand some approximation would be made for atmospheric refraction)?

POSTED BY: John Drummond

One reason for the minor difference between AstronomicalData and SunPosition is that the older AstronomicalData code base uses a simplistic conversion to Julian date for its internal computations. SunPosition/Alpha use a more modern/less naive conversion. The result being that you get a slightly different answer with the newer result less affected by errors in this particular component.

POSTED BY: Jeffrey Bryant
Posted 10 years ago

Are you sure the output is ok? I've refreshed with RebuildPacletData[]

If http : // ssd.jpl.nasa.gov/horizons.cgi?s_loc = 1 #top is the gold standard Then for the sample point I looked at {43.953074,4.472485} and at 2014-07-22 17:15:00 UTC AstronomicalData["Sun",.... does not agree with SunPosition[GeoPosition and both are different from the nasa calculation e.g. for the altitude for this point respectively I get 19.85892, 20.06311334010335, and 19.7609

Unless I've done some thing stupid I can't see that 0.3 degrees out is much of a success


copied from mathematica 10 notebook

In[26]:= {AstronomicalData["Sun",{"Azimuth",{2014,7,22,18,15,0},{43.953074,4.472485}},TimeZone->1], AstronomicalData["Sun",{"Altitude",{2014,7,22,18,15,0},{43.953074,4.472485}},TimeZone->1]} Out[26]= {279.28408[Degree],19.85892[Degree]} In[27]:= SunPosition[GeoPosition[{43.953074,4.472485}], DateObject[{2014,07,22,19,15, 0}, TimeZone -> IntegerPart[LocalTimeZone[Entity["City",{"Paris","IleDeFrance","France"}], DateObject[{2014,07,22,19,15, 0},TimeZone-> 0]]]] ]//FullForm Out[27]//FullForm= List[Quantity[279.096879879350734008354638938468698465083.6876323489782243,"AngularDegrees"],Quantity[20.063113340103351466195182502734913517392.5442756941572635,"AngularDegrees"]]

Result of values in the jpl.nasa site 279.3737 19.7609

POSTED BY: John Drummond

Two things: Firstly, I do not really consider NASA to be the gold standard; I used these words only in my reply to Nasser as he seemed to regard them as such.

Secondly, Mathematica delivers the actual sun position, not its apparent position. The latter would imply taking atmospheric refraction into account. At sunrise that amounts to about 0.5 degree, and is at a minimum when the sun is at zenith position. So, 0.3 deg off isn't really much of a problem, or so it seems.

POSTED BY: Sjoerd de Vries
Posted 10 years ago

I suppose I'm still not clear why the two different methods in Mathematica (AstronomicalData and SunPostion) don't agree. If I look at the Azimuth for which refraction presumably doesn't make much difference then I get

AstronomicalData 279.28408
SunPosition 279.09687
and NASA 279.3737

which there's roughly 0.1 degrees between AstronomicalData and NASA and 0.2 degrees between AstronomicalData and SunPosition

=> What would you consider to be the gold standard?

I'm interested as I was wondering how accurate one could plausibly make a sundial for for example the next 100 years and thought it would be fairly easy to set up on Mathematica, but am now not sure. the timezone correction is 4 minutes a degree, i.e. 0.1 degrees is 24 seconds 0.1 degrees is something like 3.5 mm at 2 metres

POSTED BY: John Drummond

Output seems to be OK now, great! Now, if the speed could be improved somewhat...

POSTED BY: Sjoerd de Vries

I spoke too soon. It hasn't pushed to the production server just yet. Should hopefully be on production tomorrow. Sorry if I caused additional confusion.

POSTED BY: Jeffrey Bryant

This issue should be resolved now that the most recent production push has happened. This was a time zone conversion problem. Results should now more closely match the results from AstronomicalData. This issue affected several functions mentioned in this thread and should all be addressed now. Thank you for letting us know!

POSTED BY: Jeffrey Bryant

I have found that, in addition to SunPosition returning the wrong result, DaylightQ and SiderealTime also produce the wrong result. SiderealTime code is almost certainly called by the SunPosition code, so this might be a good place to start looking.

POSTED BY: Andrew Mattingly

I'm investigating. I will let you know if I have found the problem.

POSTED BY: Jeffrey Bryant

Users here get the same results I do. I'm investigating for any issues I can think of that might cause such behavior.

POSTED BY: Jeffrey Bryant
POSTED BY: Sjoerd de Vries

I checked by setting my time zone to Champaign's

Block[{$TimeZone = -5}, 
  SunPosition[GeoPosition[{52.37`, 4.89`}], DateObject[{2013, 3, 1, #, 0, 0}, TimeZone -> 1]] & /@   Range[0, 23]
]

I now get your results.

So, you get the correct results because part of the calculation somehow assumes your time zone, which yields incorrect results for anyone not in your time zone. You are among the few who can't see the incorrect results ;-)

POSTED BY: Sjoerd de Vries

BTW I get the impression that daylight savings also causes problems. When I ask:

In[22]:= Sunrise[GeoPosition[{52.37`, 4.89`}],  DateObject[{2013, 3, 1}, TimeZone -> 1]]

I get

Out[22]= DateObject[{2013, 3, 1}, TimeObject[{8, 28}], TimeZone -> 2.]

whereas I feel it should be

DateObject[{2013, 3, 1}, TimeObject[{7, 28}], TimeZone -> 1.]

as the location is GMT + 1 and DST was not in effect on March,1 (it started March 31).

The documentation says: "Daylight Saving Time corrections must be included in the time zone", which means that fixed locations change from one time zone to another depending on DST.

POSTED BY: Sjoerd de Vries
POSTED BY: Jeffrey Bryant

Amsterdam is in TimeZone 1. The way Mathematica is set-up for daylight savings time entails it adds an hour if DST is in effect. On march 1, however, DST is not in effect and TZ 1 is correct for both me and Amsterdam. Anyway, setting TimeZone to two still has the sun rise in the middle of the night.

But I think that's beside the matter. With SunPosition you're asking for the position of the sun at a given day and time above a specific location. All these are the same in my call and in yours and should therefore return the same result. They don't.

In the meantime I've asked another user for his results and he comes up with exactly the same results I got.

POSTED BY: Sjoerd de Vries
POSTED BY: Jeffrey Bryant

No, I'm on a standard V10.0.0

I just executed the code again and still get the same result:

In[6]:= SunPosition[GeoPosition[{52.37`, 4.89`}], 
   DateObject[{2013, 3, 1, #, 0, 0}, TimeZone -> 1]] & /@ Range[0, 23]

Out[6]= {{Quantity[95.7, "AngularDegrees"], 
  Quantity[-5.1, "AngularDegrees"]}, {Quantity[107.6, 
   "AngularDegrees"], 
  Quantity[3.9, "AngularDegrees"]}, {Quantity[120.0, 
   "AngularDegrees"], 
  Quantity[12.3, "AngularDegrees"]}, {Quantity[133.5, 
   "AngularDegrees"], 
  Quantity[19.6, "AngularDegrees"]}, {Quantity[148.3, 
   "AngularDegrees"], 
  Quantity[25.4, "AngularDegrees"]}, {Quantity[164.5, 
   "AngularDegrees"], 
  Quantity[29.1, "AngularDegrees"]}, {Quantity[181.6, 
   "AngularDegrees"], 
  Quantity[30.2, "AngularDegrees"]}, {Quantity[198.6, 
   "AngularDegrees"], 
  Quantity[28.6, "AngularDegrees"]}, {Quantity[214.6, 
   "AngularDegrees"], 
  Quantity[24.5, "AngularDegrees"]}, {Quantity[229.2, 
   "AngularDegrees"], 
  Quantity[18.4, "AngularDegrees"]}, {Quantity[242.5, 
   "AngularDegrees"], 
  Quantity[10.9, "AngularDegrees"]}, {Quantity[254.8, 
   "AngularDegrees"], 
  Quantity[2.4, "AngularDegrees"]}, {Quantity[266.6, 
   "AngularDegrees"], 
  Quantity[-6.7, "AngularDegrees"]}, {Quantity[278.6, 
   "AngularDegrees"], 
  Quantity[-15.8, "AngularDegrees"]}, {Quantity[291.4, 
   "AngularDegrees"], 
  Quantity[-24.6, "AngularDegrees"]}, {Quantity[305.7, 
   "AngularDegrees"], 
  Quantity[-32.6, "AngularDegrees"]}, {Quantity[322.2, 
   "AngularDegrees"], 
  Quantity[-39.2, "AngularDegrees"]}, {Quantity[341.3, 
   "AngularDegrees"], 
  Quantity[-43.5, "AngularDegrees"]}, {Quantity[2.0, 
   "AngularDegrees"], 
  Quantity[-44.8, "AngularDegrees"]}, {Quantity[22.5, 
   "AngularDegrees"], 
  Quantity[-42.9, "AngularDegrees"]}, {Quantity[41.1, 
   "AngularDegrees"], 
  Quantity[-38.0, "AngularDegrees"]}, {Quantity[57.1, 
   "AngularDegrees"], 
  Quantity[-31.1, "AngularDegrees"]}, {Quantity[71.0, 
   "AngularDegrees"], 
  Quantity[-22.9, "AngularDegrees"]}, {Quantity[83.6, 
   "AngularDegrees"], Quantity[-13.9, "AngularDegrees"]}}

Did you see my analysis above? It showed that the actual W|A call also includes the caller's location. If that is somehow used in the calculation that would explain why we see different results. However, the results should not depend on that and it seems likely this is a bug.

POSTED BY: Sjoerd de Vries

The speed overhead is a known issue that we are actively planning to address in a future release.

POSTED BY: Jeffrey Bryant

Good to hear Jeff! Any suggestions as to how to get SunPosition return the same results as AstronomicalData?

POSTED BY: Sjoerd de Vries

Very good posts, Sjoerd. For my projects, I've started doing the calculations in other languages, using well-known datasets and algorithms, and then finally feeding the various chunks of calculated data to Mathematica for higher-level assembly and presentation. It's not the most desirable solution, but as Mathematica becomes a higher and higher level language, it's a pragmatic approach, at the moment. Of course, the temptation is to try and do it in just one environment - but then, which one?! :)

For one-off questions or exploring a new problem space, firing off a few dozen WolframAlpha queries is fine, but, like elsewhere in computing, relying on the cloud isn't always going to be the ideal solution. There are some obvious disadvantages, too: you don't know where it comes from or how it's been calculated, how reliable it is, or when or whether it's been updated or modified, missing and unexplained data points can't be tracked down and repaired, and so on. Unless the cloud service is quick and very reliable, and well documented, it's easy to end up with problems that aren't easily fixed.

POSTED BY: C ormullion

Thanks, Cormullion. If you have a use for my converted sun position code just let me know.

POSTED BY: Sjoerd de Vries

I can't answer the other issues since I do not use these functions. But on this point you raise

It needs an Internet connection

How would propose that Mathematica get the current ephemeris data for solar system planets and the sun without using an updated database somewhere on the internet?

I use JPL Horizon website myself for this information. You might want to see if there is a way to use this site via an API call to obtain this information. It is free.

POSTED BY: Nasser M. Abbasi

For the sun position and given the required accuracy of a minute or so you don't really need that as most algorithms are good for decades, if not centuries to come. See for instance this site.

POSTED BY: Sjoerd de Vries

I converted to Mathematica a VBS macro that you can find in this Excel sheet. It is written by Greg Pelletier and based on a NOAA Javascript program which was used to drive their sun calculation page. I performed a direct and ugly conversion without any optimization whatsoever. Testing it with the method above I found that it is about 30 times faster than V9 AstronomicalData and about 1100 times faster than V10's SunPosition.

Testing the output and taking the NASA website you refer to as the golden standard I get for the sun positions starting at 1 am (using AstronomicalData for V10):

Azimuth:

enter image description here

Elevation:

enter image description here

I declare winner the one with the smallest absolute deviation from the NASA data.

As to the need for ephemeris: The following plot compares the results for Pelletier's and V10's AstronomicalData in the year 3013, thousand years in the future (CircleDot is Mathematica):

enter image description here

POSTED BY: Sjoerd de Vries
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract