Group Abstract Group Abstract

Message Boards Message Boards

Issues with AstronomicalData and SunPosition

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

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

POSTED BY: John Drummond
Posted 11 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 11 years ago
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 11 years ago
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
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

I have now asked two users that are in my time zone, they get the same result as me. Another user is on GMT and his results differ from both yours and mine.

It really seems the calculation take your own locale into account, which it shouldn't.

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
POSTED BY: Sjoerd de Vries

I saw your analysis. The API call includes a fair amount of information that may or may not be needed for a specific input. I see nothing obviously wrong with the API arguments being sent assuming for you:

$TimeZone -> 2
$GeoLocation -> GeoPosition[{52.09, 5.12}]

You only gave a single API call, but did not specify which value of date was used as input for that call.

Your input date specifies that you are trying to feed in a different timezone (1) from where you are (2). TimeZone conversions need this information to be correct or you could get confusing results.

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
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