5
$\begingroup$

I am running a query to pull historical temperature readings from Los Angeles using the following query:

data=WeatherData[{"LosAngeles", "California", "UnitedStates"}, 
  "Temperature", {{2016, 07, 21, 9, 45, 0}, {2016, 07, 22, 12, 45, 
    0}}]["DatePath"]

The returned time stamps are marked as GMT-4. This is strange for two reasons. I would expect to get the times stamps reflecting local time at the location of the measurement which is GMT-8. Secondly, it doesn't even seem to reflect the time zone I am in (Philadelphia which is GMT-5). Is there a way to request local time (at location of measurement)? I have played around with the TimeZone option. While this changes the time stamps they are still always labelled GMT-4.

$\endgroup$
  • $\begingroup$ I don't know what other implications this will have, but you can change the default TimeZone value for DateObject and it will do what you are asking for I think: i.stack.imgur.com/RJiKO.png $\endgroup$ – Jason B. Jul 22 '16 at 15:13
  • $\begingroup$ Also, from what this page says, the current time zone offset for Philly is -4 hours, I guess that takes daylight savings time into consideration $\endgroup$ – Jason B. Jul 22 '16 at 15:15
3
$\begingroup$

WeatherData always assumes that the input times are in UTC, and the output times are in UTC as well. Any TimeZone option given to the DateObject in the call to WeatherData are overridden.

The TimeZone option can be used to set the offset from UTC for the input times, but doesn't really affect the output times. If you wanted to see the weather for L.A. between midnight and 18:00 on 21-July, consider the output:

(WeatherData["LosAngeles", 
     "Temperature", {DateObject[{2016, 07, 21, 0, 0, 0}], 
      DateObject[{2016, 07, 21, 18 , 00, 0}]}, TimeZone -> #] // 
    DateListPlot) & /@ {-8, 0, "America/Los_Angeles"}

Mathematica graphics

These are clearly wrong since we don't expect the lowest temperature at noon. However, the fist plot above does have the right data on the y axis, but the times are all wrong. Since the output of WeatherData is a TimeSeries we can use TimeSeriesShift

laWeather = TimeSeriesShift[
   WeatherData["LosAngeles", 
    "Temperature", {DateObject[{2016, 07, 21, 0, 0, 0}], 
     DateObject[{2016, 07, 21, 18, 00, 0}]}, TimeZone -> -8],
   Quantity[-8, "Hours"]
   ];
DateListPlot[laWeather]

Mathematica graphics

Okay, so it's plotting correctly, but if you called laWeather["DatePath"] the DateObject results would all still give your own time zone. This shouldn't be a problem, but if you really want them to show the proper time zone, then easiest workaround I could find is via

Block[{$TimeZone = -8},
 laWeather["DatePath"]
 ]

Mathematica graphics

However, note that when you give the results to DateListPlot, they will plot using your current time zone. So my recommendation would be to leave the results alone after applying TimeSeriesShift.

$\endgroup$
0
$\begingroup$

not sure why I cannot comment, so I'm going to write here. @JasonB, I made the following oversations:

  1. the method of setting timezone using SetOptions has no effect on the date-value paris returned. For my query the first timepoint is "Thu 21 Jul 2016 09:51:00" - 20C and the last is "Fri 22 Jul 2016 11:51:00" - 21C. It's the same no matter how I set

    SetOptions[DateObject, TimeZone -> -7];

The only thing that changes is that the date objects are labelled GMT-4 or GMT-7 etc.

  1. setting TimeZone as an option in the function merely shifts the date range,i.e. prepends timestamps and cuts off the same number at the end or it cuts in the beginning and appends the same number. however, the same time points are still associated with the same values. For example:

    data = WeatherData[{"LosAngeles", "California", "UnitedStates"}, "Temperature", {{2016, 07, 21, 9, 45, 0}, {2016, 07, 22, 12, 45, 0}}, TimeZone -> 3];

prepends time points "Thu 21 Jul 2016 06:51:00","Thu 21 Jul 2016 07:51:00" and "Thu 21 Jul 2016 08:51:00" and cuts from the end "Fri 22 Jul 2016 09:51:00","Fri 22 Jul 2016 10:51:00","Fri 22 Jul 2016 11:51:00" while the value associated with "Thu 21 Jul 2016 09:51:00" is still 20C (the same it was before setting the TimeZone option).

I think the time stamps which are returned always use my location, if I want LA time I would have to run the above query with TimeZone -> -3 and subtract 3 hours to all date objects but I am still not sure about it. What happens if there is a change due to daylight savings time etc.? What happens if somebody who is in a different time zone used the script?

$\endgroup$
  • 1
    $\begingroup$ The site software requires that you have 50 points of "reputation" before you can comment on posts that are not your own. (Reference: mathematica.stackexchange.com/help/privileges) This post is really not an answer and it should be deleted in time, but for now I shall make an exception as I understand the frustration of the software blocking you like this, and your comment is constructive. $\endgroup$ – Mr.Wizard Jul 22 '16 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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