tutorials - geomorphtools.org

Transcription

tutorials - geomorphtools.org
New Tools for Quantitative Geomorphology: Extraction and
Interpretation of Stream Profiles from Digital Topographic Data
Kelin Whipple
Cameron Wobus
Ben Crosby
Eric Kirby
Daniel Sheehan
GSA Annual Meeting
October 28, 2007
Boulder, CO
Sponsored by: NSF Geomorphology and Land Use Dynamics
CONTENTS
Chapter 1: DEM Preparation Guide
1
Chapter 2: Installing the Profiler Toolbar
7
Chapter 3: Extracting and Analyzing Profile Data
9
Chapter 4: Working with your Results
19
Chapter 5: Code Architecture and File Output
23
Ch. 1 – DEM Preparation Guide
Chapter 1 - DEM Preparation Guide
Obtaining Spatial Data:
1.
Go to a data distributor and find the data (the following for USGS quads)
A. http://seamless.usgs.gov
i. You must specify in the download tab on the far right that elevation or GIS data
set you want to download…otherwise you will just get 30m NED.
ii. If you select a large area or a high point-density data set, it will divide the datset
into specific chunks. These will have to be mosaiced later.
iii. Make sure that you select a region that has a northern boundary that is pretty
high…as during the projection, ArcMap tends to cut off northern parts of DEMs.
B. NOTE: projections always involve resampling and interpolation of data (so some level of
information degradation. Using Seamless source is convenient, but involves 2 projection
transformation: from original UTM to geographic in building the NED; back to UTM for
your use. Thus the purists approach is to obtain original USGS 10m DEM Quads (e.g.,
from http://www.mapmart.com ) and mosaic these in arcgis.
2.
Download the data
A. You will be prompted to download individual .zip files to your computer
B. These zip files will be named numerically so I suggest adding a descriptor to the
downloaded filename
C. If you select a large area, your DEM data will be divided into multiple .zip files no
greater than 100mb each.
3.
Decompress the data
A. If on a PC just use WinZip or the windows extractor.
B. Be sure to keep track or the names associated with the files as they can become confusing
during decompression.
Preparing your Elevation Data for Stream Profile Analysis:
4.
If multiple files, Mosaic your DEMs
A. This will merge back together your separate downloads into the large DEM you selected
at seamless.usgs.gov (or to merge individual DEM quads).
B. Open ArcMap and start ArcToolbox
C. Select: Toolbox / Data Management Tools / Raster / Mosaic to New Raster
i. Use the folder button to find your multiple unzipped grids
1. Add all the files so that they fill out the list below “Input Rasters”
ii. Specify the output DIRECTORY where the new raster will go
iii. Specify the name of the new raster that you are creating
iv. Leave All other fields as they are (do not project the data at this step)
5.
Project your Mosaiced DEM
A. The data from seamless comes in geographic coordinates (GCS, lat and long)…this must
be changed to a projected coordinate system with Equal Area square pixels (e.g. UTM or
Albers Equal Area)
B. Use: Data Management Tools / Projections and Transformations / Raster / Project Raster
i. Input raster is the mosaiced raster that you just completed
ii. Output raster is the name and location of your projected raster
iii. Output Coordinate System:
1. You can “Select” from a set of existing Geographic and Projected
Coordinate Systems
1
Ch. 1 – DEM Preparation Guide
2.
Or, you can “Import” an existing coordinate system from another GIS
file that you might already have that is in the projection that you want
the new data to conform to.
iv. For “Resampling,” be sure to select ‘bilinear’ for the projection calculation (this
prevents linear artifacts from being introduced into your data)
v. It is best to specify the output cell size to the native posting for the DEM
(otherwise you get something like 9.78m, and parts of the DEM may get cut-off
in some cases)
1. Depending on what you downloaded:
a. If using 1/3 arc second data, specify that the cells are 10m
b. If using 1 arc second data, specify that the cells are 30m
2. This will not affect the quality of the data…It WILL prevent the
northern areas from being clipped off during reprojections.
6.
Remove Ocean or negative values if you wish to mask them out of your DEM
A. Use: Spatial Analyst Tools / Math / Logical / Greater Than
i. Specify the input DEM
ii. Specify the value you want your DEM to be greater than (0m ?)
iii. Specify the name and location for the output raster – this grid will have a value
of “1” everywhere elevations are greater than you specified (0m) and “0”
elsewhere.
iv. Use: Spatial Analyst -> Raster Calculator to divide your original DEM by this
mask grid to create a DEM only composed of regions where elevations are
greater than what you specified (0m). Cell values will be “NoData” elsewhere.
B. If you have bathymetric data, you may want to take your data and add a large number to
all your elevations (like 10,000). This will allow all your elevations to be positive
without affecting the accuracy of the data. To do this use the raster calculator under
Spatial Analyst to add 10,000 to each cell in your DEM.
NB: Alternative to Steps 7 – 10.
Steps 7 – 10 below are time consuming. We have prepared a user-installable “Profiler Toolbox” that
can be added to ArcGIS (must be done in each new ArcMap project) and will automate these steps
while you are away from your computer.
Adding the Profiler Toolbox to ArcGIS
A. There are three files included, 2 Python scripts (*.py) and the toolbox. In ArcMap (or
any Arc app for that matter) open up ArcToolbox (little red box), then right-click within
this window, choose "add toolbox" and search for the add-in toolbox "Profiler Tools".
B. You now have a little red toolbox called "Profiler Tools". Expand it, and right click the
function "Profiler DEM Preparation" in the new toolbox "Profiler Tools" and click
Properties. Go to the "Source" tab and point it to the file "ProfilePrep9_1.py" or
"ProfilePrep9_2.py", depending on which version of Arc is being run (9.1 vs 9.2).
C. Once that is done, you can use the “Profiler DEM Preparation” function like any other
within ArcToolbox. Double click it and a dialog box opens where you can enter a DEM
and spit out the filled DEM, flow direction raster, acc raster, and ascii versions of the
original DEM and acc grid. This can take a while, depending on DEM size, computer
speed, and how rough the DEM is (how many pits need to be filled). When this process
is complete, you are now ready to skip to step 11 where you use the arcdemtxt2matlab.m
function to convert the ascii rasters to compact matlab binary files.
2
Ch. 1 – DEM Preparation Guide
7.
Fill pits in the DEM.
A. Filling ultimately allows flow to escape depressions, when you make the direction array.
B. Use: Spatial Analyst Tools / Hydrology / Fill
i. Specify the input DEM
ii. Specify the output filled DEM
C. Depending on the size and resolution of your DEM this may take a while…
D. Check that the cell size of the FillDEM is the same as the input DEM. Sometimes this
can be an issue. If so, in the Fill toolbox, click environments, raster, and set the cell size
for analysis to be the input DEM.
8.
Create the flowdirection array.
A. Use: Spatial Analyst Tools / Hydrology / Flow Direction
i. Specify the input filled DEM
ii. Specify the output direction raster
iii. Don’t bother with the other settings
9.
Create the flowaccumulation array.
A. Use: Spatial Analyst Tools / Hydrology / Flow Accumulation
i. Specify the input direction raster
ii. Specify the output flow accumulation
iii. Leave “weight raster” blank
iv. IMPORTANT: Set “Output Data Type” to INTEGER
B. Depending on the size and resolution of your DEM this also may take a while…
10. Export your Integer Accumulation and your original unfilled DEM to ASCII files
A. These .txt outputs will be used by MATLAB to extract channel profiles.
B. Use: Conversion Tools / From Raster / Raster to ASCII
i. Specify the location of the original, projected, unfilled DEM or accum grids.
ii. Specify the output names for the .txt files
1. NOTE! You must follow the following naming convention!
a. DEM file: file_namedem.txt
b. Accum file: file_nameacc.txt
2. e.g. if you are working on the snake river, you might create:
a. snakedem.txt and snakeacc.txt
b. do not worry that you do not see a projection file (*.prj) –
projection information is all in the headers of the ascii files
(*.txt) exported from ArcGis.
11. Use MATLAB to convert the exported .txt files into .mat data files.
A. Open MATLAB and change the working directory to be where you have the .txt files
stored. Place a copy of the code “arcdemtxt2matlab.m” in the same directory.
B. Convert .txt files to MATLAB .mat data files
i. Note: File naming convention must be followed. (See 10.b.ii above)
ii. In the Command Window, type:
1. arcdemtxt2matlab('matlab_directory',‘file_name’) [note: single quotes
are required for matlab to recognize characters];
a. ‘matlab_directory’ must be the full path name to the directory
where your *dem.txt and *acc.txt files are stored (e.g.,
‘C:\user_data\my_project\matlab’), and is where the matlab
binary files will be written. See Chapter 3, item 1 for a
recommended directory structure to organize your files.
b. This will start a program that changes your .txt files into the
more efficient .mat file format. The .mat files are saved in the
current directory as well as a projection-aware metadata file.
c. The filenames created by the code arcdemtxt2matlab.m will be
named ‘file_nameaccm.mat’ and ‘file_namedemm.mat’
3
Ch. 1 – DEM Preparation Guide
2.
3.
NOTE: arcdemtxt2matlab.m can be run in several different modes.
Open it up to read all the fun options. One useful one saves a bit on
memory use and is run with the matlab command: >>
arcdemtxt2matlab('matlab_directory', ‘file_name’,3);
After the code has run and you have verified that the .mat files that you
created are in good working order, you may want to delete or archive
the .txt files as they are no longer necessary.
If you are familiar with ArcGIS Model Builder, this can be another useful way to automate the steps
above, rather than using the user installable add-in toolbox provided. In model-space, the flow of
steps would look something like this.
Create
Namedem.prj
file (missing)
12. Clip a Watershed if needed.
Generally clipping watersheds is not needed for stream profile analysis. However, if your
*dem.txt and *acc.txt files are much greater than 100Mb (source grids bigger than about 5000 x
5000 pixels), you will run into memory limits of Matlab on a WinXP (32 bit) PC. One solution is
to run the 64bit version of Matlab on Linux, Win 64bit or Vista on a machine with > 4Gb Ram.
Alternatively, you can subdivide the dem into smaller parts for analysis in Matlab. An easy way is
to set your ArcMap display to show just the area you want to send to matlab and when running
Export in Step 10, under Environments > General Settings > Extent choose “Same as Display”.
You can keep the full dem in Arc, and just process one overlapping piece at a time in Matlab.
Another popular alternative is to clip out individual watersheds for analysis. Unfortunately
ArcMap is a bit cumbersome at defining watersheds for clipping. A convenient solution is offered
by an add-in toolbox written by Peter Isaacson called the “Hydrology Module” (see below for
installation steps).
4
Ch. 1 – DEM Preparation Guide
A. In the “Hydrology Module”, choose “Interactive Properties”. The flow direction grid and
flow accumulation grids were created above. Click “OK”.
B. Click the “Watershed” button on the hydrology module, and then click on the point
closest to the mouth of the river (choose by eye, easier if you are zoomed in, best if you
are looking at the flow accumulation grid, not the dem). Once done, you will see that
your watershed is masked out.
C. Convert the watershed raster to a polygon to use for mask. In the “Conversion Tools”
tool box, chose “From Raster” and “Raster to Polygon”. Input raster is the watershed
raster, output polygon is the name of your new polygon. MAKE SURE YOU UNCLICK
“Simply polygons”. If you don’t do this, parts of the outer edge of your watershed will
be cut-out.
D. You want to export data from your watershed only. In the “Spatial Analyst” Tool box,
“Extraction” box, double click on “Extract by Mask”. The “Input Raster” is your
UNFILLED DEM, the “Input raster or feature Mask data” is the watershed polygon that
you just created, and the “Ouput raster” is your soon-to-be-created DEM of this
watershed only. Note that if you use the raster watershed without making it into a
polygon, you will create a raster that only has values in the watershed, but it will have no
data values covering the rest of the area – these “nodata” points still count against total
memory. The point is to reduce the total number of points in the raster whether these are
“nodata” or not.
13. Loading the Hydrology Extension (from Peter Isaacson)
This is the link where you can download the hydrology extension.
http://arcobjectsonline.esri.com/ArcObjectsOnline/Samples/Spatial
%20Analyst/Hydrology%20Modeling/HydrologyModeling.htm
To install it, you need to have administrator permissions on the local machine (not Domain).
Follow the instructions from Chapter 2 on installing the Profiler Toolbar dll (process is the same).
Then in ArcMap, you should be able to add this extension (tools menu > customize > toolbars>
add from file > click the dll). Then you should be able to use it like any other toolbar. Installing it
once on your machine is sufficient, unless you re-install ArcGIS.
5
Ch. 2 – Installing the Toolbar
Chapter 2 - Installing the Profiler Toolbar (profiler.dll)
1.
Download and register the Profiler.dll file
A. Place the profiler.dll in your C:\Program Files\ArcGIS\bin folder, or an
alternate folder if you prefer (one option is to create the folder C:\Program
Files\ArcGIS_Stream_Profiler). REMEMBER WHERE YOU PUT IT. If
you install a new version you will need to overwrite this file. To avoid
problems you MUST always register the dll from the same directory.
B. Open 3 Windows Explorers. In the first window, change to the folder where
you stored the new DLL. In the second, change to the
C:\WINDOWS\system32 folder. In the third, change to the C:\Program
Files\ArcGIS\bin folder.
C. Now you need to drag the DLL and drop it onto the regsvr32.exe icon in the
Windows\System32 folder. Next, drag the DLL onto the regcat.exe icon in
Arcgis\bin folder. Click on the Arcmap checkbox then click Register.
2.
Install the profiler extension in ArcMap
A. Open ArcGIS. Click on Tools and Customize. You should see a form like this:
B. Click on Add from File (the middle button on the bottom of the form). This
allows you to add a dll that has been registered with Windows and with
ArcGIS. The dll has been written to interact directly with ArcGIS. Navigate to
the folder where you saved profiler.dll, highlight profiler.dll then click on
open
C. Once you do, you should see a form something like this:
7
Ch. 2 – Installing the Toolbar
D. These are the subroutines, forms, and toolbar that make up the new profiler
tool. Click on the Profiler Toolbar in the list of toolbars. You should see the
toolbar:
3.
The best practice for installing a new, improved version of the profiler toolbar when
released is to completely remove any memory of the old version before installing the new
one as listed above. The procedure is:
A. In ArcMap Tools->Customize-> uncheck the profiler toolbar
B. Close ArcMap
C. Double click on:
C:\Program Files\ArcGIS\Bin\categories.exe
i. Scroll down to ESRI Mx CommandBars, expand
a. search for Profiler1* and remove all objects related to profiler
toolbar - should just be the toolbar (should be at the end of the
list)
ii. Move to ESRI Mx Commands, expand
a. search for profiler1* and remove all objects related to profiler
toolbar - several functions (should be at the end of the list)
D. Normally not necessary, but if you are having issues with profiler toolbar
ghosts, check the following folders in the categories.exe file for items related
to "profiler", in addition to the mx commands and mx command bars folders:
i. arkansas objects
ii. automation objects
iii. esri gx commands
iv. esri sx command bars
v. esri sx commands
E. Reinstall the new Profiler.dll as described above
8
Ch. 3 – Extracting and analyzing Profile Data
Chapter 3 - Using the Profiler Toolbar and Matlab codes for extracting
and analyzing stream profile data
1.
Set up a convenient directory structure for your project.
Our stream profile analysis tools generate a lot of files (most of them quite small). Keeping
everything well organized from the start is HIGHLY recommended. The following directory
structure works well.
A. Store all the profiler matlab codes in one place, separate from any particular analysis
project. Set this as the Working Directory in Matlab, or add this directory to Matlab’s
PATH (C:\Program Files\ArcGIS_Stream_Profiler\Mfiles might be a good choice).
B. Place your *dem.txt and *acc.txt ascii files exported from ArcGIS into the directory you
want all matlab data files stored (model: C:\user_data\my_project\matlab); this will be
your “matlab_directory”.
C. Create a directory where you want all files created by the Profiler Toolbar stored (model:
C:\user_data\my_project\arcmap); this will be your “arcmap_directory”. This directory
will be empty to start with. You CAN use a single directory for both arcmap and matlab
files, however as numbers of files grows you will wish you kept them separate.
2.
Define the parameters for your DEM in ArcMap
A. Make sure that the unfilled DEM grid is loaded into and visible in ArcMap.
i. It is not really necessary to have any other layers loaded or visible
a. once you have run the code a few times and been successful at
extracting profiles, you may want to delete the intermediate files that
you created (fill, direction, accum, etc) to save disk space.
ii. It can be helpful to add other layers or manipulate the DEM and Accumulation
so that they best help you visualize the topography.
a. To see your stream network, it’s sometimes good to classify the
accumulation into two classes. I make all the low drainage area points
(0-1000 pixels) transparent and then make all the other large drainage
area pixels (>1000 pixels) some color (blue?).
b. To find your channel heads, it may be useful to create contour lines or a
shaded relief map for your DEM. Go to Spatial Analyst>Surface
Analysis>Contour (or Hillshade) and select a reasonable contour
interval (or illumination source) for your DEM.
B. Define Parameters in the info window in the profiler tool (shown on page 11). Click on
the red ‘i’. Set the working directory FIRST.
i. The “Working Folder” should be set to your “arcmap_directory”;
C:\user_data\my_project\arcmap or similar and is where the Profiler Toolbar
will look to both write and read. It MUST be the same directory specified as
“arcmap_directory” when you run the Matlab codes. You can type or
copy/paste the full pathname into the middle box (C:\ by default) instead of
browsing, which can be slow.
ii. Select your DEM from the dropdown list
iii. Choose a project name. This will save your settings in a file
“projectname_parameters.txt” so you retain a record and can easily reload these
settings with the “Import Saved Parameters” button at the top of the form.
iv. Theta Ref should be between 0.4 and 0.6, depending on your field site. 0.45 is a
good start (default)
v. The spike remover takes out any data spikes in your profile. Recommended for
DEMs that had lots of pits to fill (e.g., SRTM DEMs)
vi. The step remover removes artifacts from USGS 10m DEMs, and allows no
additional smoothing. This option is NOT implemented for Batch processing
(using profile51_batch.m and the “Auto KS Import” button on the Profiler
Toolbar)
9
Ch. 3 – Extracting and analyzing Profile Data
vii. Smoothing window is the length of a moving average window over which
Matlab will smooth raw profile data (in meters). Uncheck the Smooth Profile?
box to do no smoothing. For rougher and lower resolution data, longer
smoothing windows can be helpful. 250m is great for USGS DEMs, 1000m,
possibly more useful on very rough data (some SRTM 3 arc second data).
viii. Contour sampling interval is the vertical distance Matlab will use to calculate
raw slopes (NOTE: 12.192m is equivalent to the 40ft contour interval most
DEMs were created from). This form of smoothing is always done, to eliminate
smoothing, set = 1m. Coarse, rough data, requires larger contour intervals (20m
is recommended for SRTM 3 arc second data). Choice depends on the detail
you need to capture and the quality of your data – what is real and what is noise?
ix. Auto k_sn Window is the width of a moving window that Matlab uses to
calculate normalized steepness indices along the entire length of a profile. This
can provide a handy guide to profile analysis, can help determine if you have
chosen a reasonable Theta_ref for your area, and is very similar to how the
Batch processing mode (using profile51_batch.m and the “Auto KS Import”
button on the Profiler Toolbar) works to automate determination of normalized
steepness indices for an entire catchment.
x. Search distance is the distance Matlab will search downstream from your
selected channel head (in pixels) to make sure it’s actually in the channel. The
routine used to locate actual stream heads (and to eliminate the need to very
carefully pick points selected in step 2 below) is as follows: (1) from your
selected point the channel extractor runs downhill a number of pixels set by
“Search Distance”; (2) the channel extractor then turns around and follows the
channel all the way to the divide; (3) it then turns around again, moving
downstream and begins data extraction (distance, elevation, drainage area) when
it reaches the “Minimum Accumulation” (again in pixels) specified below. This
way by picking anywhere near the channel of interest you can always extract
exactly the same channel, and you can always start as near the divide as you like
without needing to zoom way in when choosing your channel head position.
xi. Minimum Accumulation helps Matlab define where the actual channel head is:
it is the number of pixels that contribute to the uppermost pixel in your channel
(see “j” above).
xii. Click the “Save parameters to file” tab at the bottom
xiii. Check that you created a new file called “run_parameters.txt” in the directory
that you specified. “run_parameters.txt” is the “active” file that both Matlab
codes and the Profiler Toolbar look to for information when running. This is
overwritten each time you click “Save parameters to file”. Your settings are
permanently saved in a copy called “projectname_parameters.txt”.
10
Ch. 3 – Extracting and analyzing Profile Data
11
Ch. 3 – Extracting and analyzing Profile Data
3.
Select the streams that you would like to extract in ArcMap.
A. The code will start the extraction at the headwaters of the stream you click in and
continue to extract channel data downstream until reaching the edge of the DEM.
i. Click on the toolbar button that says “(red-dot) to ML.” This will start up crosshairs that can be used to locate which stream you would like to extract. Crosshairs stay active until you select another ArcMap tool or another button on the
Profiler Toolbar.
a. Use the cross-hairs to click near a channel head on your DEM.
b. IF you clicked a point by accident at any point you must not “x” out of
the box: just use a dummy name and choose “submit name and close
file”. Picking a new location will over-write the bad one.
c. Give the stream a name (your choice, I recommend numerical)
d. Click “Submit Name” if you want to do a cluster of streams, or click
“Submit Name and close file” to just do a single stream. You can
always do more later.
e. If you hit “submit name” previously, you can repeat for each channel
you want to analyze as a cluster. When done, click on “Submit name
and close file”
ii. You can now see in the directory that you specified as the “arcmap_directory” in
the parameter window that there is a file called “location_ij.txt”. [To check that
everything is OK, you can open this file in a text editor and make sure the file
contains as many channels as you selected]. Data format is [row column easting
northing streamname].
4.
Extract long profile data in Matlab
A. Copy the following call line into the Matlab “Command Window.” It will be the
template that you will use when you are ready to run the profile extraction code.
i. profile51(‘file_name’, ‘arcmap_directory’, ‘matlab_directory’, ‘n’);
ii. Note that all fields in single-quotes must be written that way or the code will not
work (Matlab is looking for strings in each of these spots)
a. ‘file_name’ : The prefix in front of your *demm and *accm files
b. ‘arcmap_directory’ : Directory specified Profiler info-box in Arcmap
c. ‘matlab_directory’ : Directory where your *demm.mat, *accm.mat,
and *meta.mat files reside.
d. ‘n’ : This tells Matlab that you have not yet extracted the profile data
from each stream so it needs to create it. ‘y’ tells matlab to process
previously created ‘streamname’_chandata.mat files (either to re-do an
analysis or to run regressions on channels extracted in batch mode [see
7. Advanced options. Note that to change analysis options (smoothing,
etc) you need to edit “run_parameters.txt” either in a text editor or by
using the “i” define parameters dialog in ArcMap (see 2.2 above).
e. Best to include the semicolon at the end of matlab commands as this
suppresses matlab from writing the results to the screen (which usually
takes 100x longer than the calculation itself).
iii. Press Enter (Note: make sure you’ve got a “location_ij.txt” file before you type
enter or Matlab won’t know where to start!)
5.
Begin Profile analysis in MATLAB.
A. Once you hit Enter in Step 2, the MATLAB codes will create two plots (shown below)
and step you through a series of analyses.
12
Ch. 3 – Extracting and analyzing Profile Data
Matlab Profile Code’s “Figure 2”
Figure 2 Explained: In the top plot, the observed and predicted channel profiles for each analyzed reach
are shown. Raw elevations are in green, smoothed in pink. The dark blue lines are the profiles predicted by
the regressed channel concavity, θ. The cyan lines are for the specified reference concavity, θref. The plus
marks along the profile indicate the locations of user-specified knickpoint positions. In the lower plot the
same blue and cyan colors show the regressed and reference concavities, respectively. Red squares are logbin averages of the S-A data and open circles show the locations of the knickpoints as plotted on the long
profile. This is the plot that can be pulled up using hyperlink tool on single-channel shapefiles in arcmap.
13
Ch. 3 – Extracting and analyzing Profile Data
Matlab Profile Code’s “Figure 3”
Figure 3 Explained: The top plot is the profile data with elevation plotted against c, the integral
of drainage area to that point on the profile (see 2007 GSA Short Course lecture for notes on the
“Integral Method” used to determine the regression fits with specified reference concavity (plotted
in dark blue). Middle plot is local slope plotted against distance from mouth. Regression lines as
in Figure 2. On the upper two plots, open circles are user-selected knickpoint locations. The
lower plot shows the automated calculation of normalized channel steepness (ksn) over user
specified moving window width (auto ksn window). These can be a helpful guide to choosing
regression limits on the log gradient – distance plot above (option c).
14
Ch. 3 – Extracting and analyzing Profile Data
2. The codes will ask you for the following information:
>> From which plot would you like to pick regression
limits?
• Look at the long profile (Figure 2, plot 1), the slope-area plot (Figure 2,
plot 3), and the slope-distance plot (Figure 3, plot 1) and decide which
of these you want to use to choose the limits for your slope-area
regression. Choose a, b, or c.
• Once you make a selection, your mouse arrow will become a set of
crosshairs. Click on the upstream and then downstream limits of your
regression. Note that only the position of the vertical cross hair matters
so long as you are in the appropriate plot. Since the cross hairs extend
across the entire figure window, in some cases it is useful to look at
more than one plot with the same horizontal axis to help guide making
your selection.
>> Click the upper left corner to locate temporary
parameter text.
• Once the codes do the regressions, you need to choose a spot on your
figures to display the regression results. Find a spot with some white
space and click on it. (Figure 2, Plot 1 is often a good choice, above the
long profile).
• The results of the regression will be displayed. Note that ksn is the
normalized steepness value, which can be compared directly among
profiles with the same reference concavity.
>> Do you want to remember this fit (readable into
ArcMap)? (y/n)
• Decide whether to keep the fit. If you like it, SAVE it. This will be
importable into ArcMap as a shapefile.
>> Select another range to fit? (y/n)
• Decide if you want to select another range to fit. For example, if your
slope-area plot seems to have two distinct segments, you might want to
fit the upper and lower portions separately.
>> Mark points on long profile? (y/n)
• You can click on the long-profile to place markers at places where
there are interesting features along the profile (cirque floors, waterfalls,
top/bottom of a flat section, where the slope rapidly changes, etc)
• These points will be plotted on the GIS so that you can see where they
lie and what their characteristics are (elevation, area, etc)
>> From which plot would you like to mark points?
• You can mark points on the long profile (Figure 2, plot 1), the slopearea plot (Figure 2, plot 3), or the slope-distance plot (Figure 3, plot 1).
Choose a, b, or c.
>> Classify this point? (y/n)
• If you selected a point on your profile, you can then classify it using a
numeric code, such as: 1) Major Knickpoint; 2) Minor Knickpoint; 3)
Start of Steep Section; 4) End of Steep Section; or 5) Other. These data
will be imported into ArcMap along with your knickpoint shapefile.
>> Save slope-area fits, chandata, knickdata, and print
figures? (y/n)
• As a general rule, if prompted to save data (and you know the data are
good), always say “y” You can always delete it later!
>> Change the axis limits for fig 2, subplots 1 and 2?
(y/n)
• If you are going to want all of the longitudinal profiles in your
catchment to have the same scale, you can do that here. This can be
very useful for visual comparison of different streams, and for plotting
15
Ch. 3 – Extracting and analyzing Profile Data
tributaries relative to the mainstem. We often load the saved *.eps files
of the plots into different layers in Adobe Illustrator for convenient
viewing, which is best done when axes are all the same. Note that the
slope-area plots are always drawn with the same axes for this reason.
>> It is most convenient to return to ArcMap and import
data using the "add stream shapefile" and "create
knickpoint shapefile" buttons.
• While you can always finagle importing these files later, it’s a bit
inconvenient. Here’s how it works. When you select "add stream
shapefile" or "create knickpoint shapefile", the Profiler Toolbar
populates a list of streams to choose from by reading the “active”
location_ij.txt file in the “arcmap_directory”. If you did not import
your stream or cluster of streams BEFORE selecting any additional
channel heads in ArcMap, then this “active” location_ij.txt file will
have been overwritten. To facilitate importing a set you forgot to do,
you need to create a “location_ij.txt” where you edit the number of
lines and the “streamname”s in the last column to match the set you
wish to import. Note that the Profiler Toolbar only reads the last
column to populate the “available streams” box, so the other columns
can have random dummy values (just copy and paste the first row for
the number of streams then edit the streamname column as needed).
• An upgrade to this function is coming soon.
6.
Returning to ArcGIS.
A. Now back in Arc, you will need to download the data you just collected to visualize it in
ArcGIS and plot the data over the map. Use the profile toolbar to import your data:
B. Using the toolbar, click the third button from the left that looks like 3 curvy lines or
streams (next to “· to ML”). You will see the following screen:
16
Ch. 3 – Extracting and analyzing Profile Data
Select the stream(s) you want to import, add to the output list, and hit “Convert selected
streams to shapefiles”. Note that you can also create a single shapefile that will include
all the streams, rather than each one individually, by selecting “Append to new or
existing shapefile?”. Checking this box calls up additional windows on the dialog box
where you can either select an existing stream shapefile from the list, or type in the name
of a new one you wish to create.
C. After the stream data are imported, click the fourth button from the left that looks like
three strings of knickpoints. You will see a similar screen to the long profile import
screen, which will allow you to import your knickpoint data.
7.
Advanced options
A. Note that the profiler toolbar also has an “Auto KS Import” option. Combined with the
Matlab code “profile51_batch.m”, this tool allows you to create a shapefile that will
contain either a subset of streams you pick or ALL the streams in a catchment above a
specified minimum drainage area and that can be color-coded by steepness index. Both
cases are fully automated, so it’s a quick easy way to get a first cut analysis done. IT is
also completely objective, with no “art” to where to pick regression bounds. There are
two ways to use this option:
i. Use the batch profile option is to process EVERY stream in your catchment
above a specified minimum drainage area automatically.
a. The Matlab syntax is slightly different here, as you need to tell Matlab
what your critical drainage area is which triggers matlab to search for
channel heads automatically. At the Matlab command prompt, type the
following:
>> profile51_batch(‘fname’,’arcmap_directory’,
’matlab_directory’,’n’,<crit_area>)
Here <crit_area> is a number that tells Matlab what drainage area (in
square meters) defines the top of the automatically-selected channels.
A convenient format is to type 1e8, for example. Try a large critical
area first to limit the number of channels and how long the process
takes.
b. NOTE: the auto channel head selection routine will overwrite any
existing location_ij.txt files!
c. Once you have run this code, you can go back to ArcMap and click on
the “Auto KS Import” option (see below).
d. NOTE 2: The Auto KS Import option may take a REALLY long time
to run, particularly if you have selected a small ‘crit_area’ on a large
DEM. A progress bar will appear in lower right to (a) confirm that
ArcMap is at work and not dead and (b) let you track progress.
ii. Use batch profiler code to process a number of user-selected stream profiles
a. Select channel heads manually in ArcMap as before; this creates your
location_ij.txt file
b. At the Matlab command window, type the following:
>> profile51_batch(‘fname’,’arcmap_directory’,
’matlab_directory’,’n’)
c. The ‘n’ tells Matlab that you have not yet created a “chandata” file for
your stream profiles. Matlab will now extract the stream profiles
downstream of your selected channel heads, and it will calculate a
17
Ch. 3 – Extracting and analyzing Profile Data
d.
e.
f.
18
normalized steepness index for each point along the channel. It will
create a (large) file called ‘*ks_data.txt’
Go back to ArcMap and click the “Auto KS Import” button on the
profiler toolbar. This will bring up a screen like this:
Navigate to (or type of paste in) your “arcmap_directory” and select the
Batch KS file you just created, give your new shapefile a name, and
select “Create a shapefile for selected Auto KS data file”.
NOTE: This will take a little while, as ArcMap needs to process every
pixel along every stream you’ve created. Go get a cup of coffee if you
need to. A progress bar will appear in lower right to (a) confirm that
ArcMap is at work and not dead and (b) let you track progress.
Ch. 4 – Working with your results
Chapter 4 - Working with your results
1.
All of your long profile figures created in Matlab are saved. The current versions of the codes
save these files as both .eps and .jpg files. It is often very useful to overlay all of these in a single
document (i.e., in Adobe Illustrator) to look at the variations in stream geometry, systematic
differences in steepness, etc. In particular, using the .eps files, you can overlay all of your slopearea plots on one set of axes and pick out the regional upper and lower bounds on steepness
values, spatial variations in ksn, etc.
2.
The purpose of the jpeg version of these figures is to allow you to view them from ArcMap by
clicking on the associated stream (all segments of a given stream will call up the same figure of
course) – note that this works only if individual stream shapefiles have been merged into one
master shapefile. You do this by using the hyperlink tool in ArcMap (the lightning bolt on the
toolbar with the zoom buttons and info button). Just select the hyperlink tool and click on the
stream of interest (with the appropriate stream shapefile loaded and visible).
3.
In ArcMap, it is often useful to color-code your stream segments based on their normalized
steepness indices. Right click on your stream shapefile, select “Properties” and then select the
“Symbology” tab. You will see a screen like this:
19
Ch. 4 – Working with your results
You want to use Quantities > Graduated Colors and set Value field to ksn (of course you can also
color code by regression concavity values). Pick a color scheme that works well and spreads out
the steepness values appropriately. Click “Classify” in the mid-upper right to select among
options for setting the number of colors and the position of the color breaks. This will allow you to
look at patterns of steepness indices within your catchment to evaluate whether there might be
transients working their way through the system or breaks in steepness indices that might be
correlated with changes in tectonic uplift rates (see example below). Finding the perfect color
ramp can be an effort. Once you have one you like it is wise to save it as a Layer file that records
your settings. In the Layers side-bar in ArcMap (along the left margin by default), right click your
shapefile and select “Save as Layer File”. Once this is done, in the Symbology dialog box shown
above, you can use the “Import” button in the far upper right to import a color scheme previously
saved as a Layer File. This is highly recommended.
4.
For additional ArcMap user tips, see:
• http://web.mit.edu/gis/www/introarcgis/
• http://libinfo.uark.edu/GIS/tutorial.asp
• http://arrowsmith410-598.asu.edu/Lectures/Lecture9/DEM_data.html
20
Ch. 4 – Working with your results
Viewing Profile Composites for Comparison in Illustrator
It can be useful to load your saved matlab plots into different layers in Illustrator for direct comparison
and for plotting composites. For this to work you need to have set all plots to the same axis limits (see
item 15 above). Steps:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
Open the first *.ps file with Illustrator
Make a new layer and name the layer with a stream_name
Use PLACE command to insert the stream_name.ps file
Repeat 2-3 for ALL plots, including the one you opened in step 1.
save file occasionally
Remove the first, unnamed layer – this one will not be in exactly the same position as all the
others
save your file
For each layer you need to remove the background (opaque white) around the whole plot and
on each figure panel to be able to “see through” to layers below. Click on the plot to
highlight. Leave all selected and execute: Ungroup (ctrl-shift-g). Release Clipping Mask
(ctrl-alt-7). 2nd time Release Clipping Mask (ctrl-alt-7) (using the short cut key strokes is a
big time saver on this). Now every item in the layer can be edited individually.
click near the border to highlight surrounding frame (not visible) – delete
click in each figure panel to hightlight background frame (not visible) – delete
now you should see through to the layer below. Lock this layer. Turn off this layer to avoid
confusing clutter.
repeat for each layer, saving occasionally
leave all layers locked to avoid accidentally moving something. Turn on and off various
layers to confirm you can “see through” all of them and to create the composites you want to
see. You can print any composite sets and/or save as pdf files.
Your end result could look something like this:
21
Ch. 5 – Code Architecture and Output
Chapter 5 - Code Architecture and File Output
1. Code Architecture
Below is a list of the main Matlab codes (.m files) utilized in stream profile extraction and
analysis. This is meant to be an exhaustive list of all the .m files used, their purpose, which
subroutines are called by which files, and the syntax used for each code.
arcdemtxt2matlab.m: this code is used to pre-process DEM data to create Matlab binary files
from ArcGIS ASCII output. It also creates a “metadata” file for the DEM and accumulation
grids that are read into Matlab (can be a subset of the DEM, ACCUM grid loaded in ArcMap,
but must be in same projection and the DEM and ACCUM grids must have exactly the same
extent).
profile51.m: this code is the primary function that initializes and runs the profile extraction
routine.
function[]= profile51(‘fname’,’arcmap_directory’,’matlab_directory’,’exist_cd’)
For each river analyzed, profile.m creates a matrix called chandata that stores all of the
information for that channel (plus some supplementary files, see below). chandata is a
matrix comprising a series column vectors, with each row representing the data from an
individual pixel along the channel. The columns of the chandata array are as follows:
dfd – distance from divide [meters]
pelev – elevation [meters]
drainarea – upstream drainage area [meters2]
smooth_pelev – smoothed elevation [meters]
ptargi – x coordinate of point in the matrix [pixels: (0,0) is the upper left corner]
ptargj – y coordinate of point in the matrix [pixels: (0,0) is the upper left corner]
dfm – distance from mouth [meters]
auto_ks_vals – steepness index using automatic ks calculation routine
x_coord – Latitude in map coordinates [meters]
y_coord – Longitude in map coordinates [meters]
Note that at the end of each profile analysis routine, there is an option to save the
profile’s chandata. This is saved as a Matlab binary file filename_chandata.m. If you reprocess pre-existing chandata files (‘exist_cd’ = ‘y’), then there is an option to add a
suffix to all saved files (e.g. suffix ‘v2’ would give “mydata_chandata_v2.mat”)
profile51.m calls the following functions:
answer_yn: this is a simple function to return a binary flag in response to a yes/no question
(returns 1 if YES and 0 if NO)
movavg51.m: this code performs a moving average of the elevation array, within a window
of user-specified width
23
Ch. 5 – Code Architecture and Output
function[smooth_array] = movavg42(array,pixel_size,wind)
sa_analysis51.m: this code contains most of the analysis of slope/area data extracted from
the profile
function [ida,islope,lbarea,lbslope,chandata,ans2] =
sa_analysis51(chandata,movernset,name,arc_workdir,mat_workdir,rmspike,wind,no_s
tep,ks_window,cont_intv)
sa_analysis51.m in turn calls the following functions:
sa_regress.m: this function performs the primary regression(s) of slope-area data
IF you have opted to use “step remover” one of the following is called (this option
does not allow any additional smoothing of the data).
usgscontour.m: this code is specifically tailored to remove step-like changes in
elevation from USGS DEMs. The code extracts elevation data only from the
intersections of the stream channel and the contour lines
function [ind,cont_intv]=usgscontour(chandata)
usgscontour.m in turn calls the following functions:
closeto.m: this function finds the row that contains a value in a specified
column that is nearest to designated ‘value’
slopes.m: this function calculates channel slopes based on elevation and
distance from mouth. It returns slope and area, using a central differencing
based on a 3-pixel window.
closeto_allvalues.m: this function finds ALL rows that contain a value in a
specified column that is nearest to designated ‘value’
stepremover.m: this code is a generic version of usgscontour that allows extraction
of data from any stepped DEM
stepremover.m also calls closeto.m
profile51_batch.m: this function batch processes stream profiles, constructing chandata matrices
for a group of channels simultaneously. This code can be used to batch process channels from
user-selected channel heads, or it can be used to automatically find all the channels in a network.
function [chandata] = profile51_batch(fname,arcmap_directory, matlab_directory,
exist_cd,crit_area)
profile51_batch.m calls the same functions as profile51.m; it also calls:
auto_chn_finder.m: this function finds all of the channel heads in a network by
searching for a user-specified minimum drainage area.
24
Ch. 5 – Code Architecture and Output
function[atargi,atargj,atargx,atargy,label] = auto_chn_finder
(fname,arc_workdir,mat_workdir,accum,network,easting,northing,crit_pix)
auto_ks_calc.m: this function adds automatically calculated ksn values for each
stream segment, by forcing regressions through slope-area data over a user-specified
window length (ks_window)
function [chandata] = auto_ks_calc(chandata,movernset,cont_intv,
ks_window)
2. Files created during Profile extraction and analysis:
The profile extraction and analysis process generates a number of files along the way; all of these
will be stored in the Matlab and ArcMap directories that you specify at the command line when
you run profile51.m. Below is a list of the files created, and what they are.
A. Files Written to the ArcMap Directory (= Working Directory specified in ArcMap)
run_parameters.txt: This file stores the values you input in the ArcMap dialog box at
the very beginning of your profile analysis. The file is just a series of numbers, which are
(in order):
(1) cellsize; (2) reference concavity; (3) spike removal option [1/0]; (4) step
removal option [1/0]; (5) smoothing option [1/0]; (6) smoothing window size; (7)
contour interval; (8) window length for auto ksn calculation; (9) Distance to run
downstream to ensure you’re in the channel; (10) Minimum accumulation area to
determine upstream extent of a channel.
location_ij.txt: This file stores the coordinates of all the starting points you select in
ArcMap, in both matrix (i,j) and geographic (lat, long) form. It has the same number of
rows as there are channel heads selected.
In addition to these “generic” files, the codes will also create the following files for each
channel you analyze (where * denotes a given channel name, i.e. “stream1”).
1. Files Written by Matlab codes (for import into ArcMap):
*.jpg: a jpeg file of the Matlab generated Figure 2 with the long profile, drainage
area vs. distance, and slope-area plots (for use with ArcMap Hyperlink tool)
*_f3.jpg: a jpeg file of the Matlab generated Figure 3 with elevation vs. χ,
gradient vs. distance, and ksn vs distance.
*_stream.txt: a text file with all of the location information for the stream in
question (drainage area; i-j coordinates; lat-long coordinates for each point along
the stream)
25
Ch. 5 – Code Architecture and Output
*#.txt: # is stream segment number (number of segments you used in regression
analysis; this text file records the regression analysis bounds (Area_min and
Area_max) and results for each segment
*_knick.txt: a text file saving the chandata values from selected knick points
‘filename’_ksdata.txt: a text file saving results of a batch mode calculation of
ksn values for every pixel along every selected channel. Here ‘filename’ is the
name for the DEM used, not an individual assigned channel name.
2. Files Written by ArcMap (shapefiles produced by import function)
*_stream.dbf, *_stream.prj, *_stream.shp, *_stream.shx: This set of files
represents the shapefile created by ArcMap during import streams. These may be
supplemented by a new shapefile you specified to Append (or merge) stream
shapefiles together.
*_knick.dbf, *_knick.prj, *_knick.prj, *_knick.shp, *_knick.shx: This set of
files represents the shapefile created by ArcMap during import knickpoints.
These may be supplemented by a new shapefile you specified to Append (or
merge) knickpoint shapefiles together.
name.dbf, name.prj, name.shp, name.shx: This set of files represents the
shapefile created by ArcMap during “Import Auto Ksn”. Name is specified by
user during the import process.
B. Files Written to the Matlab Directory (all written by Matlab codes)
*.eps: a postscript file of the Matlab generated Figure 2 with the long profile,
drainage area vs. distance, and slope-area plots.
*_f3.eps: a postscript file of the Matlab generated Figure 3 with elevation vs. χ,
gradient vs. distance, and ks vs distance.
*.chandata.mat: a Matlab binary file saving the “chandata” matrix for your
stream
*.sa_data.mat: a Matlab binary file saving the slope-area data for the channel.
*_lb_sa_data.mat: a Matlab binary file saving the slope-area data in log-bins
*_SA_fits.mat: a Matlab binary file saving the regression parameters from the
slope-area fits
*_knick.mat: a Matlab binary file saving the chandata values from selected knick
locations
26