Skip to content

Commit

Permalink
Update July-7 2017
Browse files Browse the repository at this point in the history
  • Loading branch information
BodoBookhagen committed Jul 7, 2017
1 parent 0914664 commit 5f8f1c0
Show file tree
Hide file tree
Showing 13 changed files with 1,627 additions and 1,205 deletions.
Binary file removed KZ-Picker/Matlab/DEM_MAT_parameters.mat
Binary file not shown.
22 changes: 15 additions & 7 deletions KZ-Picker/Matlab/E_KZ_knickzone_selection.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
%% Select Knickzones Using the Chi and Elevation Information from each Basin

mkdir maps_and_chi_plots;
mkdir csv_KZ_databases;

fprintf(1,'step 4 of 4: Selecting Knickzones' )
try
number_of_basins = length(basin_index);
catch ME
number_of_basins = 1;
end

for i = 1:number_of_basins
% record the maximum elevation of the entire streamobj (needed for
Expand Down Expand Up @@ -283,7 +291,7 @@
%% New function interpolates chi-elev data
% interpolates the points in the chiplot because the chi
% values do not increase with constant intervals between
% successive values. You shouldn’t use a Savitzky Golay
% successive values. You shouldnt use a Savitzky Golay
% filter on data that has a different stepsize between data
% values, so the data must be interpolated over a constant
% measurement interval
Expand Down Expand Up @@ -859,14 +867,14 @@
% specify filename for knickzone lips
kp_lips_fn = strcat('kp_lips_basin', str_basin_id,'.csv');
%give filename
cd([oldfolder,'\csv_KZ_databases\'])
cd([oldfolder,'/csv_KZ_databases/'])
fid = fopen(kp_lips_fn, 'w');
fprintf(fid, txt);
fclose(fid);

% write .csv file containing knickzone lip information for
% current parameters (need one row offset for the header)
dlmwrite([oldfolder,'\csv_KZ_databases\',kp_lips_fn],Knickpoint_Database_Lips_CB,'-append','delimiter',',', 'precision', '%.5f','roffset',1);
dlmwrite([oldfolder,'/csv_KZ_databases/',kp_lips_fn],Knickpoint_Database_Lips_CB,'-append','delimiter',',', 'precision', '%.5f','roffset',1);

% specify filename for knickzone bases
kp_bases_fn = strcat('kp_bases_basin', str_basin_id,'.csv');
Expand All @@ -878,7 +886,7 @@

% write .csv file containing knickzone lip information for
% current parameters
dlmwrite([oldfolder,'\csv_KZ_databases\',kp_bases_fn],Knickpoint_Database_Bases_CB,'-append','delimiter',',', 'precision', '%.5f','roffset',1);
dlmwrite([oldfolder,'/csv_KZ_databases/',kp_bases_fn],Knickpoint_Database_Bases_CB,'-append','delimiter',',', 'precision', '%.5f','roffset',1);

cd(oldfolder); % return to working directory
end
Expand Down Expand Up @@ -911,14 +919,14 @@
% specify filename for knickzone lips
kp_lips_fn = strcat('kz_lips_all','.csv');
%give filename
cd([oldfolder,'\csv_KZ_databases\'])
cd([oldfolder,'/csv_KZ_databases/'])
fid = fopen(kp_lips_fn, 'w');
fprintf(fid, txt);
fclose(fid);

% write .csv file containing knickzone lip information for
% current parameters (need one row offset for the header)
dlmwrite([oldfolder,'\csv_KZ_databases\',kp_lips_fn],Knickpoint_Database_Lips,'-append','delimiter',',', 'precision', '%.5f','roffset',1);
dlmwrite([oldfolder,'/csv_KZ_databases/',kp_lips_fn],Knickpoint_Database_Lips,'-append','delimiter',',', 'precision', '%.5f','roffset',1);

% specify filename for knickzone bases
kp_bases_fn = strcat('kp_bases_all','.csv');
Expand All @@ -930,7 +938,7 @@

% write .csv file containing knickzone lip information for
% current parameters
dlmwrite([oldfolder,'\csv_KZ_databases\',kp_bases_fn],Knickpoint_Database_Bases,'-append','delimiter',',', 'precision', '%.5f','roffset',1);
dlmwrite([oldfolder,'/csv_KZ_databases/',kp_bases_fn],Knickpoint_Database_Bases,'-append','delimiter',',', 'precision', '%.5f','roffset',1);

cd(oldfolder);

13 changes: 8 additions & 5 deletions KZ-Picker/Matlab/E_calib_KZ_calibration_I.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,19 @@
mkdir calib_database_outputs;

num = 1; %counter
number_of_iterations = length(min_kp_size2_calib)*length(min_kp_size1_calib)*length(lumping_search_distance_calib)*length(SG_smoothing_calib);
fprintf('At iteration # of %d: ', number_of_iterations);

for b = 1:length(min_kp_size2_calib) % minimum knickpoint size2
for a = 1:length(min_kp_size1_calib) % minimum knickpoint size1
for c = 1:length(lumping_search_distance_calib) % lumping window
for l = 1:length(SG_smoothing_calib) % smoothing window
fprintf('%d, ', num);
if mod(num,25) == 0
fprintf('\nAt iteration # of %d: ', number_of_iterations);
end

iteration_number = num % tells you progress (this takes a while)
iteration_number = num; % tells you progress (this takes a while)

%% Name Parameters

Expand Down Expand Up @@ -362,9 +368,6 @@
beta_all_tribs_all_basins{1} = beta_all_tribs; % for each basin
end


fprintf('\n');

% All the knickpoints are saved in the above cell arrays
% Organize all knickpoints into a lists (unpack the cell arrays and
% organize these attributes into columns in a matrix so they
Expand Down Expand Up @@ -506,7 +509,7 @@
kp_plot_size KZ_calib_northing_column_num KZ_calib_easting_column_num...
KZ_calib_relief_column_num do_you_have_calibration_KZ_bases smoothing_option...
theta_bf_option theta_ref num theta_bf ks_chiplot ksn_SA_store Min_DA_threshold...
Knickpoint_Database_Lips_all_params Knickpoint_Database_Bases_all_params...
Knickpoint_Database_Lips_all_params Knickpoint_Database_Bases_all_params orgfolder number_of_iterations oldfolder...

end
end
Expand Down
2 changes: 1 addition & 1 deletion KZ-Picker/Matlab/F_calib_KZ_calibration_comparison_II.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
format long g

% set current directory as 'oldfolder'
oldfolder = pwd;
oldfolder = orgfolder;

% load attribute table for the calibration knickzone bases and lips. ROW 1
% is assumed to be the header! so starts reading at ROW 2!!!!!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
format long g

% set current directory as 'oldfolder'
oldfolder = orgfolder;

% load attribute table for the calibration knickzone lips. ROW 1
% is assumed to be the header! so starts reading at ROW 2!!!!!!
Expand Down
26 changes: 12 additions & 14 deletions KZ-Picker/Matlab/MASTER_RUN_KZ.m
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
%getting latest topotoolbox from: https://github.com/wschwanghart/topotoolbox
%git clone https://github.com/wschwanghart/topotoolbox
%!adjust the following to match your location!
addpath('/home/bodo/Dropbox/Matlab-work/topotoolbox','genpath')
addpath(genpath('/home/bodo/Dropbox/Matlab-work/topotoolbox'))

%getting latest KZ-Picker code from https://github.com/UP-RS-ESP/DEM-KZP/tree/master/KZ-Picker/Matlab
%git clone https://github.com/UP-RS-ESP/DEM-KZP/tree/master/KZ-Picker/Matlab
Expand All @@ -167,45 +167,43 @@
%change to directory with data and start processing
cd /home/bodo/Dropbox/Matlab-work/KZP-examples/SCI-1m-smugglers
%extract archive
!7z e smugglers_1m.7z
%!7z x smugglers_1m.7z
orgfolder = pwd;

A_KZ_topometrics_1load_v1

%% (2) Calculate flow direction and flow accumulation and choose basins to analyze
%
% (REQUIRES USER INPUT)
B_KZ_topometrics_2preprocessing_v1

%% (3) Mask DEM according to drainage basins selected for processing

% (REQUIRES USER INPUT)
%
C_KZ_drainage_basin_plot_and_select

%% (4) Use selections from data cursor to mask draiange basins of interest
% Calculate Ksn and Chi coordinate for stream-cell in each drainage basin
% Export slope-area figures
D_KZ_masking_DBs

%% (5-Calibration) If calibration option is selected (NOTE: THIS STEP IS SLOW!)
%% (5-Calibration) If calibration option is selected (NOTE: THIS STEP IS SLOW AND USUALLY ONLY NEEDS TO BE RUN ONCE!)
oldfolder = orgfolder;

oldfolder = pwd;
if Calibration_option == 1
% run calibration scripts and do not run the processing scripts
E_calib_KZ_calibration_I

if do_you_have_calibration_KZ_bases == 1

if do_you_have_calibration_KZ_bases == 1
F_calib_KZ_calibration_comparison_II

else

else
F_calib_KZ_calibration_comparison_II_only_calib_lips

end

end
end

%% if calibration is not selected (default) run processing scripts with
% default/inputted smoothing parameters
%NOTE: The example calibrates the data and DOES NOT run the knickzone
%detection. Set Calibration_option = 0 to run the knickzone detection
if Calibration_option == 0
% (5) Select Knickzones in each drainage basin
% Select knickzones from Chi/elev data of each stream and tributary
Expand Down
Binary file removed KZ-Picker/Matlab/code_workflow.pdf
Binary file not shown.
Binary file removed KZ-Picker/Matlab/code_workflow.pptx
Binary file not shown.
10 changes: 7 additions & 3 deletions KZ-Picker/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Neely, A., Bookhagen B., Burbank, D.W. (2017): An automated knickzone selection
http://onlinelibrary.wiley.com/doi/10.1002/2017JF004250/full

Code developed by Al Neely ([email protected]) and Bodo Bookhagen ([email protected])
Latest update: 7-July-2017
Latest update: 7-July-2017 (BB)

The code was tested on a Ubuntu 16.04 LTS and Windows 7 operating system with Matalb R2015a and Matlab R2016b

Expand All @@ -23,9 +23,13 @@ Before running the code, you will need to install the additional items:

1. Edit the 'PARAMETERS_INPUTS_KZ_picker' to set input and output filenames. Then use MASTER_RUN_KZ.m to process the DEM. There are additional information in the beginning of the MASTER_RUN_KZ.m file.

There is a set of files generated that can be loaded in ArcMap/QGIS or a similar GIS.


## Examples
There exists an example dataset at containing a 1-m DEM of a part of Santa Cruz Island, southern California: smugglers_1m_dem.
This example file is available at https://www.dropbox.com/s/kpujj3mfezzd34b/smugglers_1m.7z?dl=0 or https://boxup.uni-potsdam.de/index.php/f/38152339
There exists an example dataset at containing a 1-m DEM of a part of Santa Cruz Island, southern California: _smugglers_1m_dem.7z_.
This example GeoTIF file is available at https://www.dropbox.com/s/kpujj3mfezzd34b/smugglers_1m.7z?dl=0 or https://boxup.uni-potsdam.de/index.php/f/38152339


## Additional information
BEFORE using your DEM with this script, make sure that you use a projected coordinate system. We strongly suggest to use an UTM or other
Expand Down
Loading

0 comments on commit 5f8f1c0

Please sign in to comment.