Skip to content

Commit

Permalink
Main release v1.5
Browse files Browse the repository at this point in the history
Fixed a few bugs, total remodelling of the probability calculations and storage, new map display, improved preferences
  • Loading branch information
Seb authored and Seb committed Jul 26, 2018
1 parent 6654bf3 commit 85013e9
Show file tree
Hide file tree
Showing 21 changed files with 1,042 additions and 719 deletions.
Binary file added CODE/VAR/new_props.mat
Binary file not shown.
Binary file modified CODE/VAR/prefs.mat
Binary file not shown.
Binary file modified CODE/VAR/prefs_default.mat
Binary file not shown.
31 changes: 31 additions & 0 deletions CODE/archiveFiles.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
% Archive Tephra2 output files
function archiveFiles

% Check that you are located in the correct folder!
if ~exist(fullfile(pwd, 'tephraProb.m'), 'file')
errordlg(sprintf('You are located in the folder:\n%s\nIn Matlab, please navigate to the root of the TephraProb\nfolder, i.e. where tephraProb.m is located. and try again.', pwd), ' ')
return
end

% Load project file
project = load_run;
if project.run_pth == -1
return
end

% Request
s1 = {'Tephra2 output files', 'Tephra2 configuration files', 'Tephra2 grainsize files'};
s2 = {'OUT', 'CONF', 'GS'};

r1 = listdlg('PromptString','Choose a folder to compress:',...
'SelectionMode','multiple',...
'ListString',s1);
if isempty(r1); return; end

for iR = 1:length(r1)
fprintf('- Compressing folder %s\n', s2{r1(iR)})
target = fullfile(project.run_pth, s2{r1(iR)});
zip([project.run_pth, s2{r1(iR)}, '.zip'], target);
fprintf('- Removing folder %s\n', s2{r1(iR)})
rmdir(target, 's');
end
43 changes: 30 additions & 13 deletions CODE/conf_points.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
'Name', 'TephraProb: Points configuration',...
'NumberTitle', 'off');

% Menu
cdp.menu0 = uimenu(cdp.fig, 'Label', 'File');
cdp.load = uimenu(cdp.menu0, 'Label', 'Load points', 'Accelerator','O');
cdp.import = uimenu(cdp.menu0, 'Label', 'Import points in a text file', 'Accelerator', 'I', 'Separator', 'on');

cdp.main = uipanel(...
'units', 'normalized',...
'position', [.025 .025 .95 .95],...
Expand All @@ -74,21 +79,21 @@
'ForegroundColor', [.9 .5 .0],...
'String', 'Save');

cdp.load = uicontrol(...
'parent',cdp.main,...
'Style', 'pushbutton',...
'units', 'normalized',...
'position', [.665 .025 .15 .075],...
'BackgroundColor', [.3 .3 .3],...
'ForegroundColor', [.9 .5 .0],...
'String', 'Load',...
'Tooltip', 'Load points');
% cdp.load = uicontrol(...
% 'parent',cdp.main,...
% 'Style', 'pushbutton',...
% 'units', 'normalized',...
% 'position', [.665 .025 .15 .075],...
% 'BackgroundColor', [.3 .3 .3],...
% 'ForegroundColor', [.9 .5 .0],...
% 'String', 'Load',...
% 'Tooltip', 'Load points');

cdp.map = uicontrol(...
'parent',cdp.main,...
'Style', 'pushbutton',...
'units', 'normalized',...
'position', [.501 .025 .15 .075],...
'position', [.665 .025 .15 .075],...
'BackgroundColor', [.3 .3 .3],...
'ForegroundColor', [.9 .5 .0],...
'String', 'Plot map',...
Expand Down Expand Up @@ -198,6 +203,7 @@
set(cdp.table_add, 'callback', {@but_table_add, cdp})
set(cdp.save, 'Callback', {@but_save, cdp})
set(cdp.load, 'Callback', {@but_load, cdp})
set(cdp.import, 'Callback', {@import_csv, cdp})
set(cdp.map, 'Callback', {@but_map, cdp})

% Adapt display accross plateforms
Expand All @@ -224,13 +230,24 @@
if flname == 0
return
else
load(fullfile(dirname, flname), '-mat');
load(fullfile(dirname, flname), '-mat', 'grid');
end

set(cdp.points_table, 'Data', grid.points);
set(cdp.name, 'String', grid.grd_name);
set(cdp.vent, 'String', grid.vent_zone);

function cdp = import_csv(~, ~, cdp)
fprintf('Choose a 3-columns tab delimited text file file containing site name, latitude, longitude.\nNote that the file should have no header!\n')

[fl,pth] = uigetfile('*.txt');
if fl == 0; return; end

fid = fopen(fullfile(pth,fl));
data = textscan(fid, '%s %.03f %.03f');
fclose(fid);
set(cdp.points_table, 'Data', [data{1}, num2cell(data{2}), num2cell(data{3})]);

% Save button
function cdp = but_save(~, ~, cdp)

Expand Down Expand Up @@ -293,13 +310,13 @@
end

% Delete row
function cdp = but_table_del(hObject, eventdata, cdp)
function cdp = but_table_del(~, ~, cdp)
dta = get(cdp.points_table, 'Data');
dta(length(dta(:,1)),:) = [];
set(cdp.points_table, 'Data', dta);

% Add row
function cdp = but_table_add(hObject, eventdata, cdp)
function cdp = but_table_add(~, ~, cdp)
dta = get(cdp.points_table, 'Data');
dta = [dta; {'', [], []}];
set(cdp.points_table, 'Data', dta);
123 changes: 123 additions & 0 deletions CODE/exportASCII.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
% Exports the content of dataProb and dataT2 matrices to ascii files
function exportASCII

% Check that you are located in the correct folder!
if ~exist(fullfile(pwd, 'tephraProb.m'), 'file')
errordlg(sprintf('You are located in the folder:\n%s\nIn Matlab, please navigate to the root of the TephraProb\nfolder, i.e. where tephraProb.m is located. and try again.', pwd), ' ')
return
end

% Load preference file
load(['CODE', filesep, 'VAR', filesep, 'prefs'], 'prefs');

% Load project file
project = load_run;
if project.run_pth == -1
return
end

% Check that simulations were done on a matrix
if project.grd_type == 1
errordlg('ASCII outputs can only be produced if simulations were performed on a grid')
return
end

% Request
s1 = {'Summed Tephra2 outputs', 'Probability outputs', 'Probabilistic isomass'};
s2 = {'Columns', 'ASCII Grids', 'ArcMap ASCII Rasters'};

r1 = listdlg('PromptString','Choose a type of file to extract:',...
'SelectionMode','multiple',...
'ListString',s1);
if isempty(r1); return; end

r2 = listdlg('PromptString','Choose the format:',...
'SelectionMode','multiple',...
'ListString',s2);
if isempty(r2); return; end

% Folder names
f1 = {'SUM', 'PROB', 'IM'};
f2 = {'COL', 'GRID', 'RASTER'};


% Load grid
XX = load(['GRID', filesep, project.grd_pth, filesep, project.grd_pth, '_utmx.dat']);
YY = load(['GRID', filesep, project.grd_pth, filesep, project.grd_pth, '_utmy.dat']);
UTM = load(['GRID', filesep, project.grd_pth, filesep, project.grd_pth, '.utm']);
UTM = UTM(:,1:2);
UTM = sortrows(UTM, 1);

% Loop through type of files
for iT = 1:length(r1) % Type of file
fold1 = f1{r1(iT)};
mkdir(fullfile(project.run_pth, fold1)); % Create type directory

if r1(iT) > 1 % If any other type than sum, load prob data
fprintf('- Loading probability data...\n')
load(fullfile(project.run_pth, 'DATA', 'dataProb.mat'),'dataProb');
end

% Loop through seasons
for iS = 1:length(project.seasons)
mkdir(fullfile(project.run_pth, fold1, project.seasons{iS})); % Create season directory

if r1(iT) == 1 % If sum, load tephra2 data
fprintf('- Loading Tephra2 data for season %s...\n', project.seasons{iS})
load(fullfile(project.run_pth, 'DATA', ['dataT2_', project.seasons{iS}, '.mat']),'dataT2');
end

% Loop through formats
for iF = 1:length(r2) % Format of file
fold2 = f2{r2(iF)};
target = fullfile(project.run_pth, fold1, project.seasons{iS}, fold2);
mkdir(target) % Create format directory

fprintf('- Writing %s - %s - %s...\n', s1{r1(iT)}, s2{r2(iF)}, project.seasons{iS});

%%
% Sum
if r1(iT) == 1
for i = 1:size(dataT2,3)
tmp = dataT2(:,:,i);
fl = [num2str(i, '%04.0f'), '.txt'];
if r2(iF) == 1 % Columns
dlmwrite(fullfile(target, fl), [UTM, reshape(tmp, numel(XX),1)], 'delimiter', '\t');
elseif r2(iF) == 2 % Grid
dlmwrite(fullfile(target, fl), tmp, 'delimiter', '\t');
elseif r2(iF) == 3 % RASTER
writeDEM(fullfile(target, fl), XX, YY, tmp);
end
end

% Probability maps
elseif r1(iT) == 2
for i = 1:size(dataProb.prob.(project.seasons{iS}),3)
tmp = dataProb.prob.(project.seasons{iS})(:,:,i);
fl = ['prob_', project.seasons{iS}, '_', num2str(dataProb.massT(1)), '_kgm2.txt'];
if r2(iF) == 1 % Columns
dlmwrite(fullfile(target, fl), [UTM, reshape(tmp, numel(XX),1)], 'delimiter', '\t');
elseif r2(iF) == 2 % Grid
dlmwrite(fullfile(target, fl), tmp, 'delimiter', '\t');
elseif r2(iF) == 3 % RASTER
writeDEM(fullfile(target, fl), XX, YY, tmp);
end
end

% ISOMASS maps
elseif r1(iT) == 2
for i = 1:size(dataProb.IM.(project.seasons{iS}),3)
tmp = dataProb.IM.(project.seasons{iS})(:,:,i);
fl = ['prob_', project.seasons{iS}, '_', num2str(dataProb.probT(1)), '_kgm2.txt'];
if r2(iF) == 1 % Columns
dlmwrite(fullfile(target, fl), [UTM, reshape(tmp, numel(XX),1)], 'delimiter', '\t');
elseif r2(iF) == 2 % Grid
dlmwrite(fullfile(target, fl), tmp, 'delimiter', '\t');
elseif r2(iF) == 3 % RASTER
writeDEM(fullfile(target, fl), XX, YY, tmp);
end
end
end
end
end
end
Loading

0 comments on commit 85013e9

Please sign in to comment.