-
Notifications
You must be signed in to change notification settings - Fork 0
/
P8L_Base.m
69 lines (57 loc) · 2.39 KB
/
P8L_Base.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
% Programming 8 Lesson 1
% <Name>
% <date>
% Weather Plotter
% Plots the average temperature and wind chill factor
% from Mt. Washington for a given date and # of days
close; clc; clear;
% Introduction telling the user what the script does and what to do
disp("---- Weather Plotter ----" );
disp("Plots the average temperature" );
disp("and wind chill factor from " );
disp("Mt. Washington based on your" );
disp("Inputs: Date and # of days" );
%% Ask user for Time Period
% User inputs for the date and number of days of data
D = input('Enter a date: ','s');
N = input('Enter number of days: ');
%% Load Temperature and Wind Velocity data
% Connect with GHCN and download raw data
% Prepare and format all information as required to use
% the GHCN (Global Historical Climatology Network)
% https://www1.ncdc.noaa.gov/pub/data/ghcn/daily/readme.txt
dataset = 'daily-summaries';
station = 'USW00014755'; % Mt. Washington station ID
% For more information on this weather station:
% https://www.ncdc.noaa.gov/cdo-web/datasets/GHCND/stations/GHCND:USW00014755/detail
startDate = char(datetime(D,'InputFormat','yyyy-MM-dd','Format','y-MM-dd'));
endDate = char(datetime(D,'InputFormat','yyyy-MM-dd','Format','y-MM-dd')+(N-1));
dataTypes = 'TMAX,TMIN,AWND';
format = 'csv';
base = 'https://www.ncei.noaa.gov/access/services/data/v1?dataset=';
call = strcat(base,dataset,'&dataTypes=',dataTypes,...
'&stations=',station,'&startDate=',startDate,...
'&endDate=',endDate,'&format=',format);
% Make a request of the GHCN and store the returned data
Data = webread(call);
% Break out the data needed:
% Dates(DT), wind speeds(WD), low temperatures(LT), and high temperatures(HT)
DT = Data.('DATE');
% Wind provided in 10ths of meters per second
WD = (Data.('AWND')*.1)*(1000/(60*60)); % Converted to kph
% Temperature provided 10ths of degrees C
LT = (Data.('TMIN')*.1); % Converted to deg C
HT = (Data.('TMAX')*.1); % Converted to deg C
%% Calculate daily Avg. Temp and Wind Chill Factor
% Calculate Daily Avg. Temp
AT = (HT + LT)/2;
% Calculate Wind Chill Factor
WCF=35.74 + 0.6215.*AT - 35.75.*WD.^0.16 + 0.4275.*AT.*WD.^0.16;
%% Plot Temperatures and wind chill factor
% Plot Avg Temp and WCF vs dates
plot(DT,AT,'b-.o',DT,WCF,'r--d')
% Update figure with title and labels
legend('Average Temperatures','Wind Chill Factors');
xlabel('Day');
ylabel('Temperature(°F)');
title('Temperatures and Wind Chill Factors Mt. Washington');