Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
global currentHour;
global exiting;
global colour;
global play;
global dataSource;
global maxTime;
maxTime = 25;
setExit(false); %Set the initial value of the global variables
setHour(1);
setExit(false);
setPlay(true);
%Create a New window to select the colour scheme from and put some radio
%buttons on it
fig2 = uifigure("Position", [400 400 280 200]);
text1 = uilabel(fig2, "Position", [20 140 120 30], "Text", "Select Colour Scheme");
bg = uibuttongroup(fig2,'Position',[20 60 120 85]);
rb1 = uiradiobutton(bg, 'Position', [10 60 120 15], 'Text', 'Default');
rb2 = uiradiobutton(bg, 'Position', [10 40 120 15], 'Text', 'Green');
rb3 = uiradiobutton(bg, 'Position', [10 20 120 15], 'Text', 'Blue');
text2 = uilabel(fig2, "Position", [150 140 120 30], "Text", "Select Data Source");
bg = uibuttongroup(fig2,'Position',[150 60 120 85]);
rb4 = uiradiobutton(bg, 'Position', [10 60 120 15], 'Text', 'CBE');
rb5 = uiradiobutton(bg, 'Position', [10 40 120 15], 'Text', 'Simple Ensemble');
rb6 = uiradiobutton(bg, 'Position', [10 20 120 15], 'Text', 'Compared');
%Create a button
nextBtn = uibutton(fig2,"push",...
"Text", "Next",...
"Position",[120 20 50 20],...
"ButtonPushedFcn", @(btn,event) next(rb2, rb3, rb4, rb5, fig2)); %When the button
% call the next() function
function setUp()
%Selects the data source the user selected and extract the data
if getDataSource()==1
z = extractDataCBE("C:\Users\user\Documents\Me\Uni\Big Data\Code\Original\O3Surface.nc");
text = "Cluter Based Ensemble Data showing levels of O^3 in the atmosphere above Europe in a 25 hour period.";
elseif getDataSource()==2
z = extractDataSimple("C:\Users\user\Documents\Me\Uni\Big Data\Code\Original\O3Surface.nc");
text = "Simple Ensemble Data showing levels of O^3 in the atmosphere above Europe in a 25 hour period.";
else
z = extractDataCompare("C:\Users\user\Documents\Me\Uni\Big Data\Code\Original\O3Surface.nc");
text = "Heatmap showing the difference between the CBE and Simple Ensemble.";
end
fig = uifigure("Position",[400 350 600 600]); %Create a new window
title = uilabel(fig,...
"Position", [10 550 595 30],...
"Text", text);
sld = uislider(fig,... %Create a slider
"Position",[170 75 300 3],... %Set the position and size
"Limits", [1 getMaxTime()],... %Sets the limits to 25
"ValueChangedFcn" ,@(sld,event) updateGauge(sld)); %Call the updateGauge function
%when the sider is changed by the user
btn = uibutton(fig,"push",... %Create a pause button
"Text", "Pause",...
"Position",[100 70 50 20],...
"ButtonPushedFcn", @(btn,event) playOrPause(btn,fig,sld, z));
%Call the playOrPause() function when the button when pressed
closeBtn = uibutton(fig,"push",... %Create a close Button that calls the
"Text", "Exit",... %Exit function when pressed
"Position",[100 40 50 20],...
"ButtonPushedFcn", @(btn,event) exit());
loop(fig,sld, z)
end
function loop(fig,sld, z)
global currentHour
while getPlay() %Loops until the pause button is pushed
if getExit() %If the global var exit is true, exit set but exit button
close(fig) %Close the window
return; %Stop the program
end
displayHour(currentHour, fig, z); %Plots the data on the map for the current hour
sld.Value = currentHour; %Change the position of the slider to the current hour
if getHour() == getMaxTime()
currentHour = 1;
else
currentHour = currentHour+1;
end
pause(1.5);
end
end
function displayHour(currentHour, fig, z)
global colour;
[x] = 30.15:0.1:69.85; % create x value
[y] = -24.85:0.1:44.85; %Create y Value
[x, y] = meshgrid(x, y); %Create a grid with the lat and long
h = worldmap( 'Europe'); %Create a map of Europe
land = shaperead('landareas', 'UseGeoCoords', true);%Show the land
geoshow(gca, land, 'FaceColor', [0.5 0.7 0.5]);
surfm(x, y, z(:,:,currentHour),'FaceAlpha', 0.5);%Plot the data on the map
hCopy = copyobj(h, fig); %Copy the map to the uifigure
close(); %Close the maps original figure
%Selects the colour from the options saved to colour
if colour(1)
colormap(hCopy, summer)
elseif colour(2)
colormap(hCopy, winter)
end
end
%Extract the CBE data
function r = extractDataCBE(path)
r = ncread(path, "ensemble_ozone");
end
function r = extractDataSimple(path)
%extract the data from the 7 models
chimere = ncread(path, "chimere_ozone");
emepe = ncread(path, "emep_ozone");
eurad = ncread(path, "eurad_ozone");
lotoseuros = ncread(path, "lotoseuros_ozone");
match = ncread(path, "match_ozone");
mocage = ncread(path, "mocage_ozone");
silam = ncread(path, "silam_ozone");
r = zeros(size(chimere));
loopsize2 = size(r, 2);
loopsize1 = size(r, 1);
%Parallel process the average of the models
tic
parfor idx3 = 1 : size(r, 3)
for idx2 = 1 : loopsize2
for idx1 = 1 : loopsize1
r(idx1, idx2, idx3) = (chimere(idx1, idx2, idx3) + emepe(idx1, idx2, idx3) + eurad(idx1, idx2, idx3)...
+ lotoseuros(idx1, idx2, idx3) + match(idx1, idx2, idx3) + mocage(idx1, idx2, idx3) + silam(idx1, idx2, idx3))/7;
end
end
end
toc
end
function r = extractDataCompare(path)
%Extracts data to a 3dArray
CBE = extractDataCBE(path);
simple = extractDataSimple(path);
compared = zeros(size(CBE));
loop1size = size(compared,1);
maxTime = getMaxTime();
%Parallel process the comparison
tic
for idx3 = 1 : maxTime
parfor idx2 = 1 : size(compared, 2)
for idx1 = 1 : loop1size
compared(idx1, idx2, idx3) = CBE(idx1, idx2, idx3) - simple(idx1, idx2, idx3);
end
end
end
toc
r = compared;
end
%Functions to comunicate with global variables
function r = getHour
global currentHour;
r = currentHour;
end
function setHour(val)
global currentHour;
currentHour = val;
end
function r = getColour
global colour;
r = colour;
end
function setColour(val)
global colour;
colour = val;
end
function r = getExit
global exiting;
r = exiting;
end
function setExit(val)
global exiting;
exiting = val;
end
function r = getPlay
global play;
r = play;
end
function setPlay(val)
global play;
play = val;
end
function r = getDataSource
global DataSource;
r = DataSource;
end
function setDataSource(val)
global DataSource;
DataSource = val;
end
function r = getMaxTime
global maxTime;
r = maxTime;
end
function setMaxTime(val)
global maxTime;
maxTime = val;
end
%Function called when the pause button is pressed
function playOrPause(b,fig,sld,z)
if b.Text == "Pause" %If the text is Pause
b.Text = "Play";
setPlay(false); %Set global var play to false stopping while loop in loop()
else
b.Text = "Pause";
setPlay(true); %Set global var play to true
loop(fig,sld, z) %Call the loop function
end
end
%Called when gauge is updated
function updateGauge(sld)
setHour(round(sld.Value)); %Set the current hour to the positon of the slider rounded.
end
%Called by the next button to go to the main screen
function next(rb2, rb3, rb4, rb5, fig)
global colour;
colour = [rb2.Value rb3.Value]; %Stored the radio button value in global var colour
if rb4.Value == 1
setDataSource(1)
elseif rb5.Value == 1
setDataSource(2)
else
setDataSource(3)
end
close(fig); %Close the current figure
setUp()
end
%Called by the exit button on the main page
function exit(btn)
setExit(true)
end