7
$\begingroup$

I am trying to plot SunPosition for an entire year. The examples I have seen plot a single day or one exact time across the entire year, not the full data set. (NOTE: the example code has a three day date range so as speed the trial calculations)

The data is generated with the code below:

loc = GeoPosition[{45, 0}]

tz = 0

sunriseToSunset[loc_, date_] := 
 SunPosition[loc, 
  DateRange[Sunrise[loc, date], Sunset[loc, date], {10, "Minute"}]]

dr = DateRange[DateObject[{2015, 1, 1}, TimeZone -> tz], 
   DateObject[{2015, 1, 3}, TimeZone -> tz]];

{dt, foo} = 
  AbsoluteTiming@
   TemporalData@
    ParallelMap[sunriseToSunset[loc, #] &, dr, Method -> Automatic];

The output foo is TemporalData with three paths. Each point in the list is {date, {azimuth, altitude}}

I would like to plot altitude vs azimuth for all three days (Paths) on the same chart at the same time.

Subsequently I would want to append the list with data calculated from the foo. For instance, attach Cos[altitude] to each point so the temporal data becomes {date, {azimuth, altitude, Cos[altitude]}}

$\endgroup$
2
  • $\begingroup$ Greetings! To make the most of Mma.SE please take the tour now. Help us to help you, write an excellent question. Edit if improvable, show due diligence, give brief context, include minimum working examples of code and data in formatted form. As you receive give back, vote and answer questions, keep the site useful, be kind, correct mistakes and share what you have learned. $\endgroup$
    – rhermans
    Oct 14, 2015 at 19:45
  • 1
    $\begingroup$ Have you considered the display problem? I can not see how you can make a single plot with 365 paths containing an average of 120 points each without producing a visual nightmare. Perhaps you might break it up into 12 monthly plots? $\endgroup$
    – m_goldberg
    Oct 15, 2015 at 2:19

1 Answer 1

5
$\begingroup$

The plots are easy. First, as an opaque "object", TemporalData has a "Properties" method, e.g.

foo["Properties"]
(* {"Components", "DateList", "DatePath", "DatePaths", "Dates", 
"FirstDates", "FirstTimes", "FirstValues", "LastDates", "LastTimes", 
"LastValues", "Part", "Path", "PathCount", "PathFunction", 
"PathFunctions", "PathLength", "PathLengths", "Paths", "PathTimes", 
"SliceData", "SliceDistribution", "TimeList", "Times", 
"ValueDimensions", "ValueList", "Values"} *)

At first look, "Values" would be the correct property to use, but it only returns data from one path, so "Paths" is the correct one with the ordinates extracted using Part which can be supplied to ListPlot, e.g.

ListPlot@foo["Paths"][[All, All, 2]]
$\endgroup$
2
  • $\begingroup$ Your code solution did not work for me. With modification from ListPlot@foo["Path"][[All, All, 2]] to ListPlot@foo["Paths"][[All, All, 2]] the plotting works as I wanted. Thank you. $\endgroup$
    – MBO
    Oct 28, 2015 at 19:14
  • $\begingroup$ @MBO so it was an obvious typo. They happen. $\endgroup$
    – rcollyer
    Oct 28, 2015 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.