Wolfram Language

Time Series Processing

Visualize Seasonal Patterns

Compare seasonal precipitation in a Midwest and a Southwest location.

WeatherData provides aggregated precipitation in cm.

In[1]:=
Click for copyable input
start = {1999, 1, 1}; end = {2015, 12, 31};
In[2]:=
Click for copyable input
getData[place_] := WeatherData[place, "TotalPrecipitation", {start, end, "Month"}]

Create a TimeSeries of precipitation for Champaign, IL, and Phoenix, AZ. Specify MissingDataMethod to use interpolation to fill in missing data.

In[3]:=
Click for copyable input
makeTS[place_] := TimeSeries[getData[place], MissingDataMethod -> "Interpolation"]
In[4]:=
Click for copyable input
tsIL = makeTS[ Entity["City", {"Champaign", "Illinois", "UnitedStates"}]]
Out[4]=
In[5]:=
Click for copyable input
tsAZ = makeTS[Entity["City", {"Phoenix", "Arizona", "UnitedStates"}]]
Out[5]=

Create WeightedData with amounts of precipitation as weights and plot DateHistogram averaging the data over the total number of years.

In[6]:=
Click for copyable input
dataIL = WeightedData[tsIL["Dates"], tsIL["Values"]]; dataAZ = WeightedData[tsAZ["Dates"], tsAZ["Values"]];
In[7]:=
Click for copyable input
totalyears = (end[[1]] - start[[1]] + 1);
In[8]:=
Click for copyable input
avg := Function[{x, y}, y/totalyears]
In[9]:=
Click for copyable input
makeHistogram[data_, lab_] := DateHistogram[data, "Month", avg, DateReduction -> "Year", PlotRange -> {All, {-1, 9}}, AxesLabel -> "cm", PlotLabel -> lab]
In[10]:=
Click for copyable input
{makeHistogram[dataIL, "IL"], makeHistogram[dataAZ, "AZ"]}
Out[10]=

Related Examples

de es fr ja ko pt-br ru zh