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
% Pathing of files might differ in
% other machine.
function [FinalResultofWholeData, Plotting_OF_cores] = ClusterProject(Data,Max_core, Cores_working, minYYYY, maxYYYY, minXXXX, maxXXXX, minHHHH, maxHHHH, Savingg, Plottingg)
try
% Variables
DataInToFunct = []; % X x Y x vector of ozone, name of variable will be chaged to more meaningful name.
FinalResultofWholeData = zeros(size(700, 400, 25)); % change location afterwards
%%
y= []; % time - bar chart
X= []; % cores - bar chart
while Cores_working <= Max_core
if isempty(gcp('nocreate')) % it checks if we already have a parallel pool or not?
parpool(Cores_working);
end
tic %start timing for current node
for timEE = minHHHH:maxHHHH
% For creating appropriate data set.
DataInToFunct = [];
for IXX = minXXXX:maxXXXX % 2nd col
for IYY = minYYYY:maxYYYY % 1st col
NewOz = Data(:, IYY, IXX, timEE);
NewOzOnetoSeven = NewOz.';
DataInToFunct = [DataInToFunct;[IYY, IXX, NewOzOnetoSeven]];
end
end
%%
% Main part of the code. Creating appropirate temporary data and assigining
% to DDC function to get right value for each location.
heightY = maxYYYY-minYYYY;
FinalArrayOfData = zeros(size(DataInToFunct,1), 1); % 1x 700 x 400 x 25
variableLoopIndex = (heightY+3):size(DataInToFunct) - (heightY+2);
parfor IXX = variableLoopIndex
if (mod(IXX,heightY+1) == 0 ) || ((mod(IXX,heightY+1)-1) == 0) % for looping through specific locations
continue
end
tempData = [];
%Centre Value
NewOzC = DataInToFunct(IXX, 3:end)';
CentreLocation = repmat(DataInToFunct(IXX,(1:2)), 7, 1);
tempData = [CentreLocation, NewOzC];
% for neighbour locatoins.
% Location above
NewOzUp = DataInToFunct(IXX-1, 3:end)';
LocUp = repmat(DataInToFunct(IXX-1,(1:2)), 7, 1);
tempData = [tempData; [LocUp, NewOzUp] ]; %problematic
%
% Location Below
NewOzBel = DataInToFunct(IXX+1, 3:end)';
LocBel = repmat(DataInToFunct(IXX+1,(1:2)), 7, 1);
tempData = [tempData; [LocBel, NewOzBel] ];%problematic
%%
% Location Left
NewOzLeft = DataInToFunct(IXX-(heightY+1), 3:end)';
LocLeft = repmat(DataInToFunct(IXX-(heightY+1),(1:2)), 7, 1);
tempData = [tempData; [LocLeft, NewOzLeft] ];
%
% Location Right
NewOzRight = DataInToFunct(IXX+(heightY+1), 3:end)';
LocRight = repmat(DataInToFunct(IXX+(heightY+1),(1:2)), 7, 1);
tempData = [tempData; [LocRight, NewOzRight] ];
%%
%DDC function call, should be here.
[Clusters, Results] = DDC_ver01_1_CAMS(tempData, 1.5, 0, 0); % getting results and cluster from DDC functoin
MostFrequentCl = mode(Results(:, [4])); % [4] for 4th column and : for all values. this is for getting mode value. most repetetive.
%for getting centre value.
CentreofMfrequentCl = Clusters.Centre(MostFrequentCl,3);
% Assigning Accurate value to the 'FinalArrayOfData' array.
% FinalArrayOfData(DataInToFunct([IXX],[1]),DataInToFunct([IXX],[2]), 1) = CentreofMfrequentCl;
FinalArrayOfData(IXX,:) = CentreofMfrequentCl; % the result is long nx1 array that consist of only O3 value calculated.
end
%%
finalAnswer = [DataInToFunct(:,1:2),FinalArrayOfData]; %nx3 array. X Y O3 values.
for IXX = 1:size(finalAnswer)
FinalResultofWholeData(finalAnswer([IXX],[1]),finalAnswer([IXX],[2]), timEE) = finalAnswer(IXX, 3);
end
end
t2 = toc % showing the time spent for current node.
% ending the process pool %
poolobj = gcp('nocreate');
delete(poolobj);
y = [y;[t2]]; % time
X = [X;[Cores_working]]; % cores
% add t2 to table
currentCore = Cores_working
Cores_working = Cores_working + 1;
end
%%
%Saving File
if Savingg == true
if ~exist('results', 'dir')
mkdir('results')
end
for eachHour = minHHHH:maxHHHH
File = FinalResultofWholeData(:,:,eachHour);
ch = int2str(eachHour);
writematrix(File, strcat('results/',ch,'Hour.csv'))
end
end
% for ploting
if Plottingg == true
Plotting_OF_cores = bar(X,y,0.618);
else
Plotting_OF_cores = false;
end
catch
% if code in try section fails, please check based on input.
% ClusterProject(Data,Max_core, Cores_working, minYYYY, maxYYYY, minXXXX, maxXXXX, minHHHH, maxHHHH, Savingg, Plottingg
if ~isa(Max_core, 'Numeric') || ~isa(Cores_working, 'Numeric') || ~isa(minYYYY, 'Numeric') || ~isa(maxYYYY, 'Numeric') || ~isa(minXXXX, 'Numeric') || ~isa(maxXXXX, 'Numeric') || ~isa(minHHHH, 'Numeric') || ~isa(maxHHHH, 'Numeric') || ~isa(Savingg, 'Numeric') || ~isa(Plottingg, 'Numeric')
error('ABC:InputMustBeNumeric', ...
'Input must be numeric. Please input appropriate data type.')
end
p = gcp('nocreate'); % If no pool, do not create new one.
if p.NumWorkers < Max_core
error('Not enough workers/cores.')
end
% so here there is gonna be some errors. try to catch them based
% on cases.
end
delete(gcp('nocreate'))
end