Message Boards Message Boards

How to get max/min daily temperatures statistics from AirTemperatureData?

Posted 2 years ago

For example, when I use:

AirTemperatureData["WRSP", {DateObject[{2017, 5, 1}], DateObject[{2017, 5, 10}]}] 

I get a TimeSeries object with 33 data points for this 5 day period I can plot this with DataListPlot[%] But I would like to get the daily max and min temperature for each day. How can I do this? How can I extract daily max/min values from the TimeSeries?

Try

data = AirTemperatureData[
  "WRSP", {DateObject[{2017, 5, 1}], DateObject[{2017, 5, 10}]}];

Then

GroupBy[Normal[
  GroupBy[Normal[data], DateObject[First[#], "Day"] & -> Last]], 
 DateObject[First[#], "Day"] &, Apply[MinMax, Last /@ #] &]

<|DateObject[{2017, 5, 1}, "Day", 
   "Gregorian", -6.] -> {Quantity[79.9, "DegreesFahrenheit"], 
   Quantity[93.7, "DegreesFahrenheit"]}, 
 DateObject[{2017, 5, 2}, "Day", 
   "Gregorian", -6.] -> {Quantity[81., "DegreesFahrenheit"], 
   Quantity[92.1, "DegreesFahrenheit"]}, 
 DateObject[{2017, 5, 3}, "Day", 
   "Gregorian", -6.] -> {Quantity[80.8, "DegreesFahrenheit"], 
   Quantity[88., "DegreesFahrenheit"]}, 
 DateObject[{2017, 5, 4}, "Day", 
   "Gregorian", -6.] -> {Quantity[80.1, "DegreesFahrenheit"], 
   Quantity[92.1, "DegreesFahrenheit"]}, 
 DateObject[{2017, 5, 5}, "Day", 
   "Gregorian", -6.] -> {Quantity[79.7, "DegreesFahrenheit"], 
   Quantity[92.5, "DegreesFahrenheit"]}, 
 DateObject[{2017, 5, 6}, "Day", 
   "Gregorian", -6.] -> {Quantity[78.1, "DegreesFahrenheit"], 
   Quantity[87.4, "DegreesFahrenheit"]}, 
 DateObject[{2017, 5, 7}, "Day", 
   "Gregorian", -6.] -> {Quantity[80.2, "DegreesFahrenheit"], 
   Quantity[85.3, "DegreesFahrenheit"]}, 
 DateObject[{2017, 5, 8}, "Day", 
   "Gregorian", -6.] -> {Quantity[77.7, "DegreesFahrenheit"], 
   Quantity[83.1, "DegreesFahrenheit"]}, 
 DateObject[{2017, 5, 9}, "Day", 
   "Gregorian", -6.] -> {Quantity[81.5, "DegreesFahrenheit"], 
   Quantity[90.7, "DegreesFahrenheit"]}, 
 DateObject[{2017, 5, 10}, "Day", 
   "Gregorian", -6.] -> {Quantity[80.4, "DegreesFahrenheit"], 
   Quantity[80.4, "DegreesFahrenheit"]}|>

I believe this strictly answers extract the min/max values for each day. It does not extract the min/max values and their time of day for each day. If you wish to get time of day you can split the series into TimeSeriesWindow ... extract the min/max along with time of day.

POSTED BY: Hans Michel
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