Skip to content
Snippets Groups Projects
Commit 1df7e646 authored by giuliaghirardini's avatar giuliaghirardini Committed by Marco Luigi Gaibotti
Browse files

[weather-forecast-analysis][storical] Added functions for data elaboration and plots

parent b34d5f20
No related branches found
No related tags found
No related merge requests found
function comparisonPlot(time, model, fieldString, argString, modelString)
figure();
plot(time, model.year21.(fieldString), 'LineWidth', 1); hold on
plot(time, model.year22.(fieldString), 'LineWidth', 1); hold on
plot(time, model.year23.(fieldString), 'LineWidth', 1); hold on
legend('2021','2022','2023')
xlabel('days')
if strcmp(argString,"Wind direction")==1
ylabel([argString,', [°]'])
else
ylabel([argString,', [m/s]'])
end
xlim([time(1), time(end)])
grid('minor')
title([argString,' with ', modelString])
end
\ No newline at end of file
function [model, time] = dataElaboration(model, fieldString, meanString)
time = datenum(model.year21.time);
model.(meanString) = (model.year21.(fieldString) + model.year22.(fieldString) + ...
model.year23.(fieldString))/3;
x = [time; time; time];
y = [model.year21.(fieldString);
model.year22.(fieldString);
model.year23.(fieldString)];
[model.fitted_curve1.(fieldString), ~] = fit(x, y, 'sin8');
[model.fitted_curve2.(fieldString), ~] = fit(x, y, 'fourier8');
end
\ No newline at end of file
......@@ -50,72 +50,37 @@ ERA5.year23.direction = file2023.("wind_direction_10m_era5 (°)");
ERA5.year23.gust = file2023.("wind_gusts_10m_era5 (m/s)");
%% data elaboration
samples = length(ECMWF_IFS.year21.time);
time = datenum(ECMWF_IFS.year21.time);
modelString = 'ECMWF\_IFS';
ECMWF_IFS.meanSpeed = (ECMWF_IFS.year21.speed + ECMWF_IFS.year22.speed + ...
ECMWF_IFS.year23.speed)/3;
[ECMWF_IFS, time] = dataElaboration(ECMWF_IFS, 'speed', 'meanSpeed');
[ECMWF_IFS, ~] = dataElaboration(ECMWF_IFS, 'direction', 'meanDirection');
[ECMWF_IFS, ~] = dataElaboration(ECMWF_IFS, 'gust', 'meanGust');
x = [time; time; time];
y = [ECMWF_IFS.year21.speed; ECMWF_IFS.year22.speed; ECMWF_IFS.year23.speed];
[ECMWF_IFS.fitted_curve1.speed, ~] = fit(x, y, 'sin8');
[ECMWF_IFS.fitted_curve2.speed, ~] = fit(x, y, 'fourier8');
[ERA5, time] = dataElaboration(ERA5, 'speed', 'meanSpeed');
[ERA5, ~] = dataElaboration(ERA5, 'direction', 'meanDirection');
[ERA5, ~] = dataElaboration(ERA5, 'gust', 'meanGust');
%% PLOT
close all
% ECMWF IFS
storicalPlot(time, ECMWF_IFS, 'ECMWF\_IFS')
%%
figure();
plot(ECMWF_IFS.year21.time, ECMWF_IFS.year21.direction, 'LineWidth', 1); hold on
plot(ECMWF_IFS.year21.time, ECMWF_IFS.year22.direction, 'LineWidth', 1); hold on
plot(ECMWF_IFS.year21.time, ECMWF_IFS.year23.direction, 'LineWidth', 1); hold on
legend('2021','2022','2023')
xlabel('days')
ylabel('wind direction, °')
grid('minor')
title('Wind direction with ECMWF IFS')
figure();
plot(ECMWF_IFS.year21.time, ECMWF_IFS.year21.gust, 'LineWidth', 1); hold on
plot(ECMWF_IFS.year21.time, ECMWF_IFS.year22.gust, 'LineWidth', 1); hold on
plot(ECMWF_IFS.year21.time, ECMWF_IFS.year23.gust, 'LineWidth', 1); hold on
legend('2021','2022','2023')
xlabel('days')
ylabel('wind gust, m/s')
xlim([ECMWF_IFS.year21.time(1), ECMWF_IFS.year21.time(end)])
grid('minor')
title('Wind gust with ECMWF IFS')
storicalPlot(time, ECMWF_IFS, 'speed', 'meanSpeed', 'Wind speed', modelString)
storicalPlot(time, ECMWF_IFS, 'direction', 'meanDirection', 'Wind direction', modelString)
storicalPlot(time, ECMWF_IFS, 'gust', 'meanGust', 'Wind gust', modelString)
% ERA5
figure();
plot(ERA5.year21.time, ERA5.year21.speed, 'LineWidth', 1); hold on
plot(ERA5.year21.time, ERA5.year22.speed, 'LineWidth', 1); hold on
plot(ERA5.year21.time, ERA5.year23.speed, 'LineWidth', 1); hold on
legend('2021','2022','2023')
xlabel('days')
ylabel('wind speed, m/s')
grid('minor')
title('Wind speed with ERA5')
storicalPlot(time, ERA5, 'speed', 'meanSpeed', 'Wind speed', 'ERA5')
storicalPlot(time, ERA5, 'direction', 'meanDirection', 'Wind direction', 'ERA5')
storicalPlot(time, ERA5, 'gust', 'meanGust', 'Wind gust', 'ERA5')
figure();
plot(ERA5.year21.time, ERA5.year21.direction, 'LineWidth', 1); hold on
plot(ERA5.year21.time, ERA5.year22.direction, 'LineWidth', 1); hold on
plot(ERA5.year21.time, ERA5.year23.direction, 'LineWidth', 1); hold on
legend('2021','2022','2023')
xlabel('days')
ylabel('wind direction, °')
grid('minor')
title('Wind direction with ERA5')
figure();
plot(ERA5.year21.time, ERA5.year21.gust, 'LineWidth', 1); hold on
plot(ERA5.year21.time, ERA5.year22.gust, 'LineWidth', 1); hold on
plot(ERA5.year21.time, ERA5.year23.gust, 'LineWidth', 1); hold on
legend('2021','2022','2023')
xlabel('days')
ylabel('wind gust, m/s')
grid('minor')
title('Wind gust with ERA5')
\ No newline at end of file
%% Generical plots
% ECMWF IFS
dateTime = ECMWF_IFS.year21.time;
comparisonPlot(dateTime, ECMWF_IFS, 'speed', 'Wind speed', modelString)
comparisonPlot(dateTime, ECMWF_IFS, 'direction', 'Wind direction', modelString)
comparisonPlot(dateTime, ECMWF_IFS, 'gust', 'Wind gust', modelString)
% ERA5
comparisonPlot(dateTime, ERA5, 'speed', 'Wind speed', 'ERA5')
comparisonPlot(dateTime, ERA5, 'direction', 'Wind direction', 'ERA5')
comparisonPlot(dateTime, ERA5, 'gust', 'Wind gust', 'ERA5')
\ No newline at end of file
function storicalPlot(time, model, modelString)
function storicalPlot(time, model, fieldString, meanString, argString, modelString)
figure();
plot(time, model.year21.speed, '.', 'LineWidth', 1); hold on
plot(time, model.year22.speed, '.', 'LineWidth', 1); hold on
plot(time, model.year23.speed, '.', 'LineWidth', 1); hold on
plot(time, model.meanSpeed, '-k', 'LineWidth', 1.2);
plot(time, model.year21.(fieldString), '.', 'LineWidth', 1); hold on
plot(time, model.year22.(fieldString), '.', 'LineWidth', 1); hold on
plot(time, model.year23.(fieldString), '.', 'LineWidth', 1); hold on
plot(time, model.(meanString), '-k', 'LineWidth', 1.2);
fit1 = plot(model.fitted_curve1.speed, 'b'); hold on
set(fit1, 'Linewidth', 1.2)
fit2 = plot(model.fitted_curve2.speed, 'm');
set(fit2, 'Linewidth', 1.2)
legend('2021','2022','2023','mean', 'Sin', 'Fourier')
xlabel('days')
ylabel('wind speed, m/s')
if strcmp(argString,"Wind direction")==1
ylabel([argString,', [°]'])
else
ylabel([argString,', [m/s]'])
end
grid('minor')
xlim([time(1), time(end)])
title(['Wind speed with ', modelString])
title([argString,' with ', modelString])
% Set X-Ticks and Date Formatting
datetick('x', 'mmm dd', 'keepticks', 'keeplimits');
xtickangle(0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment