(* Weather data *) wStation = "KIAH"; (* George Bush Intercontinental Airport, Houston *) wCoordinates = {29.98444, -95.34139}; wLink = "https://www.wunderground.com/history/daily/us/tx/houston/KIAH/date/YEAR-MONTH-DAY"; (* wStation = "KCLL"; (* Easterwood Airport, College Station *) wCoordinates = {30.601389, -96.314445}; *) wTimezone = -6; wTranslations = { "hail" -> "\:0433\:0440\:0430\:0434", "rain" -> "\:0434\:043e\:0436\:0434\:044c", "snow" -> "\:0441\:043d\:0435\:0433", "fog" -> "\:0442\:0443\:043c\:0430\:043d", "thunderstorm" -> "\:0433\:0440\:043e\:0437\:0430", "Temperature" -> "\:0422\:0435\:043c\:043f\:0435\:0440\:0430\:0442\:0443\:0440\ \:0430", "lower than normal" -> "\:043d\:0438\:0436\:0435 \:043d\:043e\:0440\ \:043c\:044b", "higher than normal" -> "\:0432\:044b\:0448\:0435 \ \:043d\:043e\:0440\:043c\:044b", "min. over preceding two weeks is" -> "\:043c\:0438\:043d\:0438\:043c\ \:0430\:043b\:044c\:043d\:0430\:044f \:0437\:0430 \:043f\:0440\:0435\ \:0434\:044b\:0434\:0443\:0449\:0438\:0435 \:0434\:0432\:0435 \:043d\ \:0435\:0434\:0435\:043b\:0438", "Wind speed" -> "\:0421\:043a\:043e\:0440\:043e\:0441\:0442\:044c \:0432\:0435\ \:0442\:0440\:0430", "km/hour" -> "\:043a\:043c/\:0447", "Precipitation" -> "\:041e\:0441\:0430\:0434\:043a\:0438", "mm" -> "\:043c\:043c", "normal" -> "\:043d\:043e\:0440\:043c\:044b", "preceding two weeks" -> "\:0437\:0430 \:043f\:0440\:0435\:0434\:044b\ \:0434\:0443\:0449\:0438\:0435 \:0434\:0432\:0435 \:043d\:0435\:0434\ \:0435\:043b\:0438", "preceding two months" -> "\:0437\:0430 \:043f\ \:0440\:0435\:0434\:044b\:0434\:0443\:0449\:0438\:0435 \:0434\:0432\ \:0430 \:043c\:0435\:0441\:044f\:0446\:0430", "min." -> "\:043c\:0438\:043d.", "max." -> \ "\:043c\:0430\:043a\:0441.", "Weather" -> "\:041f\:043e\:0433\:043e\:0434\:0430" }; maintainWeather := ( Print["Running maintainWeather ..."]; ClearAll[wInstData, wAggData]; wdir = ToFileName[{dirwork, "data", "weather"}]; checkdir1[wdir]; wfile = ToFileName[wdir, ToLowerCase[wStation] <> ".m"]; If[FileName[wfile] === File, DeleteFile[wfile]]; wfilez = wfile <> ".zip"; If[FileType[wfilez] =!= File || ifRefreshWeather === True, Print["Loading weather data from the weather station ", wStation, " ..."]; wNearest = WeatherData[wCoordinates, "NearestStation"]; Print["The nearest weather station: ", wNearest]; If[wStation =!= wNearest, Print["Warning: maintainWeather: Weather station should be changed: ", wStation, " -> ", wNearest]]; wStations = WeatherData[{wCoordinates, 100}]; wMemberships = WeatherData[wStation, "Memberships"]; Print["WMO, NCDC, and CWOP reporting network membership: ", wMemberships]; wStationName = WeatherData[wStation, "StationName"]; Print["Station identifier: ", wStationName]; wStationDistance = WeatherData[wCoordinates, "StationDistance"]; Print["Distance to the point ", wCoordinates, ": ", wStationDistance]; wStationCoordinates = WeatherData[wStation, "Coordinates"]; Print["{latitude, longitude} coordinates in degrees: ", wStationCoordinates]; wStationDateRange = WeatherData[wStation, "DateRange"]; Print["Start and end dates for available station observation data: ", DateString /@ wStationDateRange]; wStationElevation = WeatherData[wStation, "Elevation"]; Print["Elevation in meters: ", wStationElevation]; (* For testing *) (*wStationDateRange = {{2017, 1, 1}, {2017, 2, 3}};*) (* Aggregate *) wIntervals = {"Day", "Week", "Month", "Year"}; wAggProperties = { "Conditions", (*"PrecipitationAmount",*) "PrecipitationTypes", (*"SnowAccumulation",*) (* *) "MaxTemperature", "MaxWindSpeed" , "MeanDewPoint", "MeanHumidity" , (*"MeanPressure", "MeanStationPressure",*) "MeanTemperature", "MeanVisibility", "MeanWindChill", "MeanWindSpeed", "MinTemperature" , "TotalPrecipitation", "WindGusts"}; Print["Aggregate properties: ", ToString[wAggProperties]]; Do[ range = Append[wStationDateRange, wInterval]; (* Old version: data = WeatherData[wCoordinates, wAggProperty, range, TimeZone -> wTimezone]; *) (* Necessary in Mathematica-11 *) data = WeatherData[wCoordinates, wAggProperty, range, "DateValueQuality", TimeZone -> wTimezone]; data = Select[data, #[[3]] &]; data = {#[[1]], #[[2]]} & /@ data; Print["Aggregate data: ", {wInterval, wAggProperty}, " -> ", Short[ToString[data], 9]]; wAggData[wAggProperty, wInterval] = data, {wInterval, wIntervals}, {wAggProperty, wAggProperties}]; (* Currently not used! (* Instant properties *) wInstProperties = { (*"CloudCoverFraction" , "CloudHeight", "CloudTypes",*) "DewPoint", "Humidity", (*"PrecipitationRate",*) "Pressure", (*"PressureTendency", "SnowAccumulationRate", "SnowDepth", "StationPressure",*) "Temperature", (*"Visibility",*) "WindChill" , "WindDirection", (*"WindGusts",*) "WindSpeed"}; Print["Instantaneous observation properties: ", ToString[wInstProperties]]; Do[ data = WeatherData[wStation, wInstProperty, wStationDateRange, TimeZone -> wTimezone]; Print["Instant data: ", wInstProperty, " -> ", Short[ToString[data], 9]]; wInstData[wInstProperty] = data, {wInstProperty, wInstProperties}]; *) Save[wfile, {wCoordinates, wStation, wTimezone, wNearest, wStations, wMemberships, wStationName, wStationDistance, wStationCoordinates, wStationDateRange, wStationElevation, wIntervals, wAggProperties, wAggData (* wInstProperties, wInstData, *)}]; If[FileName[wfilez] === File, DeleteFile[wfilez]]; CreateArchive[wfile, wfile <> ".zip"]; DeleteFile[wfile], ExtractArchive[wfilez, wdir]; Get[wfile]; DeleteFile[wfile]; ]; );