LSDTopoTools
 All Classes Files Functions Variables Friends Pages
Public Member Functions | Protected Attributes | List of all members
LSDRasterSpectral Class Reference

This object performs spectral analysis. More...

#include <LSDRasterSpectral.hpp>

Inheritance diagram for LSDRasterSpectral:
LSDRaster LSDRasterModel LSDModelDriver

Public Member Functions

 LSDRasterSpectral (string filename, string extension)
 Create an LSDRasterSpectral from a file. Uses a filename and file extension. More...
 
 LSDRasterSpectral (int nrows, int ncols, float xmin, float ymin, float cellsize, float ndv, Array2D< float > data)
 Create an LSDRasterSpectral from memory. More...
 
 LSDRasterSpectral (LSDRaster &An_LSDRaster)
 Create an LSDRasterSpectral from an LSDRaster object. More...
 
 LSDRasterSpectral (int raster_order, float cellsize, float ndv)
 Create an LSDRasterSpectral object that has dimensions 2^raster_order. More...
 
LSDRasterSpectraloperator= (const LSDRasterSpectral &LSDR)
 Assignment operator.
 
vector< float > get_row_direction_frequencies_unshifted ()
 This returns the frequency values of an UNSHIFTED DFT along the rows. More...
 
vector< float > get_col_direction_frequencies_unshifted ()
 This returns the frequency values of an UNSHIFTED DFT along the columns. More...
 
Array2D< float > get_frequency_scaling_array (float beta)
 This calucaltes a scaling array for scaling an unshifted DFT by the factor 1/f^beta. More...
 
void generate_fractal_surface_spectral_method (float beta)
 This creates a fractal surface using the spectral method. More...
 
void generate_fractal_surface_spectral_method (float beta, float desired_relief)
 This creates a fractal surface using the spectral method. More...
 
void find_rollover_frequency (float &rollover_frequency, float &rollover_beta, float &sub_rollover_beta, float log_bin_width)
 FINDS ROLLOVER FREQUENCY. More...
 
void calculate_background_spectrum (float rollover_frequency, float beta, float log_bin_width, int N_iterations, int window_option=0)
 CALCULATE BACKGROUND SPECTRUM. More...
 
void dfftw2D_fwd (Array2D< float > &InputArray, Array2D< float > &OutputArrayReal, Array2D< float > &OutputArrayImaginary, int transform_direction)
 Computes the forward fast fourier transform of a 2D discrete dataset. More...
 
void dfftw2D_inv (Array2D< float > &InputArrayReal, Array2D< float > &InputArrayImaginary, Array2D< float > &OutputArray, int transform_direction)
 Computes the inverse fast fourier transform of a 2D discrete dataset. More...
 
void dfftw2D_inv_complex (Array2D< complex< float > > &InputArrayComplex, Array2D< float > &OutputArray, int transform_direction)
 Computes the inverse fast fourier transform of a 2D discrete dataset. More...
 
void detrend2D (Array2D< float > &zeta, Array2D< float > &zeta_detrend, Array2D< float > &trend_plane)
 Detrend Data. More...
 
void window_data_Hann2D (Array2D< float > &zeta_detrend, Array2D< float > &zeta_Hann2D, Array2D< float > &Hann2D)
 Hann Window Module. More...
 
void window_data_Hamming2D (Array2D< float > &zeta_detrend, Array2D< float > &zeta_Hamming2D, Array2D< float > &Hamming2D)
 Hamming Window Module. More...
 
void window_data (Array2D< float > &input, Array2D< float > &output, Array2D< float > &window, int window_option=0)
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=REDUNDANT=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- More...
 
void shift_spectrum (Array2D< float > &spectrum_real, Array2D< float > &spectrum_imaginary, Array2D< float > &spectrum_real_shift, Array2D< float > &spectrum_imaginary_shift)
 SHIFT ORIGIN OF SPECTRUM IN FOURIER DOMAIN. More...
 
void shift_spectrum (Array2D< float > &spectrum_real, Array2D< float > &spectrum_imaginary)
 SHIFT ORIGIN OF SPECTRUM IN FOURIER DOMAIN. More...
 
void shift_spectrum_inv (Array2D< float > &FilteredSpectrumReal, Array2D< float > &FilteredSpectrumImaginary, Array2D< float > &FilteredSpectrumReal_deshift, Array2D< float > &FilteredSpectrumImaginary_deshift)
 DE-SHIFT ORIGIN OF SPECTRUM. More...
 
void shift_spectrum_inv (Array2D< float > &spectrum_real, Array2D< float > &spectrum_imaginary)
 DE-SHIFT ORIGIN OF SPECTRUM. More...
 
void calculate_2D_PSD (Array2D< float > &spectrum_real_shift, Array2D< float > &spectrum_imaginary_shift)
 CALCULATE THE DFT PERIODOGRAM. More...
 
void scale_spectrum (Array2D< float > SpectrumReal, Array2D< float > SpectrumIm, float beta)
 SCALE SPECTRUM. More...
 
void calculate_radial_PSD ()
 GET RADIAL POWER SPECTRUM. More...
 
void fftw2D_spectral_analysis (char *file_id, float LogBinWidth)
 COMPUTE DISCRETE FAST FOURIER TRANSFORM OF A REAL, 2-DIMENSIONAL DATASET. More...
 
void full_spectral_analysis (float log_bin_width, int N_iterations, int window_option=0)
 FULL SPECTRAL ANALYSIS. More...
 
void bandpass_filter (Array2D< float > &RawSpectrumReal, Array2D< float > &RawSpectrumImaginary, Array2D< float > &FilteredSpectrumReal, Array2D< float > &FilteredSpectrumImaginary, float f1, float f2)
 BANDPASS FILTER. More...
 
void lowpass_filter (Array2D< float > &RawSpectrumReal, Array2D< float > &RawSpectrumImaginary, Array2D< float > &FilteredSpectrumReal, Array2D< float > &FilteredSpectrumImaginary, float f1, float f2)
 LOWPASS FILTER. More...
 
void lowpass_filter_remainder (Array2D< float > &RawSpectrumReal, Array2D< float > &RawSpectrumImaginary, Array2D< float > &FilteredSpectrumReal, Array2D< float > &FilteredSpectrumImaginary, float f1, float f2)
 LOWPASS FILTER REMAINDER. More...
 
void highpass_filter (Array2D< float > &RawSpectrumReal, Array2D< float > &RawSpectrumImaginary, Array2D< float > &FilteredSpectrumReal, Array2D< float > &FilteredSpectrumImaginary, float f1, float f2)
 HIGHPASS FILTER. More...
 
void highpass_filter_remainder (Array2D< float > &RawSpectrumReal, Array2D< float > &RawSpectrumImaginary, Array2D< float > &FilteredSpectrumReal, Array2D< float > &FilteredSpectrumImaginary, float f1, float f2)
 HIGHPASS FILTER REMAINDER. More...
 
void wiener_filter (Array2D< float > &RawSpectrumReal, Array2D< float > &RawSpectrumImaginary, Array2D< float > &FilteredSpectrumReal, Array2D< float > &FilteredSpectrumImaginary)
 WIENER FILTER. More...
 
LSDRaster fftw2D_filter (int FilterType, float FLow, float FHigh)
 FAST FOURIER TRANSFORM FILTER FOR A REAL, 2-DIMENSIONAL DATASET. More...
 
LSDRaster fftw2D_wiener ()
 WIENER FILTER FOR A REAL, 2-DIMENSIONAL DATASET. More...
 
void print_radial_spectrum (string file_id)
 
void print_binned_spectrum (string output_id, float log_bin_width)
 
LSDIndexRaster IsolateChannelsWienerQQ (float area_threshold, float window_radius, string q_q_filename)
 method to locate channel pixels adapted from Pelletier (2013). More...
 
LSDIndexRaster IsolateChannelsWienerQQAdaptive (float area_threshold, float window_radius, string q_q_filename)
 
- Public Member Functions inherited from LSDRaster
 LSDRaster ()
 The create function. This is default and throws an error.
 
 LSDRaster (string filename, string extension)
 Create an LSDRaster from a file. Uses a filename and file extension. More...
 
 LSDRaster (int nrows, int ncols, float xmin, float ymin, float cellsize, float ndv, Array2D< float > data)
 Create an LSDRaster from memory. More...
 
 LSDRaster (int nrows, int ncols, double xmin, double ymin, double cellsize, double ndv, Array2D< double > data)
 Create an LSDRaster from memory, with the elvation data stored as double precision floats. More...
 
 LSDRaster (int nrows, int ncols, float xmin, float ymin, float cellsize, float ndv, Array2D< float > data, map< string, string > temp_GRS)
 Create an LSDRaster from memory, includes georeferencing. More...
 
int get_NRows () const
 
int get_NCols () const
 
float get_XMinimum () const
 
float get_YMinimum () const
 
float get_DataResolution () const
 
int get_NoDataValue () const
 
Array2D< float > get_RasterData () const
 
Array2D< double > get_RasterData_dbl () const
 Get the raw raster data, double format. More...
 
Array2D< int > get_RasterData_int () const
 Get the raw raster data, integer format. More...
 
map< string, string > get_GeoReferencingStrings () const
 
float get_data_element (int row, int column)
 Get the raster data at a specified location. More...
 
void set_data_element (int row, int column, float value)
 Sets the raster data at a specified location. More...
 
LSDRasteroperator= (const LSDRaster &LSDR)
 Assignment operator.
 
void read_raster (string filename, string extension)
 Read a raster into memory from a file. More...
 
TNT::Array2D< double > get_ascii_raster (string FILENAME)
 Reads a raster from an ascii file for use in LSDCatchmentModel. More...
 
void read_ascii_raster (string FILENAME)
 
void read_ascii_raster_integers (string FILENAME)
 Reads a raster of integers and populates LSDRaster integer array member data. More...
 
void write_raster (string filename, string extension)
 Read a raster from memory to a file. More...
 
void write_double_raster (string filename, string extension)
 This calls raster write functions, writing from Arrays of type <double> to raster format. More...
 
void write_double_asc_raster (string string_filename)
 Writes out a double array to an ascii.
 
void write_double_flt_raster (string filename, string string_filename)
 Writes out a double array to a binary flt file.
 
void write_double_bil_raster (string filename, string string_filename)
 Writes out a double array to a ENVI bil file (untested!) More...
 
bool does_raster_have_same_dimensions (LSDRaster &Compare_raster)
 Checks to see if two rasters have the same dimensions Does NOT check georeferencing. More...
 
bool does_raster_have_same_dimensions (LSDIndexRaster &Compare_raster)
 Checks to see if two rasters have the same dimensions Does NOT check georeferencing. More...
 
bool does_raster_have_same_dimensions_and_georeferencing (LSDRaster &Compare_raster)
 Checks to see if two rasters have the same georeferencing. More...
 
bool does_raster_have_same_dimensions_and_georeferencing (LSDIndexRaster &Compare_raster)
 Checks to see if two rasters have the same georeferencing. More...
 
map< string, string > Update_GeoReferencingStrings (float NewXmin, float NewYmax)
 Method which takes a new xmin and ymax value and modifys the GeoReferencingStrings map_info line to contain these new values. More...
 
void Update_GeoReferencingStrings ()
 Method which updates the map info element of the georeferencing strings based on information within the datamembers of the raster. More...
 
void impose_georeferencing_UTM (int zone, string NorS)
 This method imposes georefereing strings assuming the coordinate system is UTM. More...
 
int Find_UTM_central_meridian (int UTM_zone)
 This method looks up the central meridian given a UTM zone. More...
 
void get_UTM_information (int &UTM_zone, bool &is_North)
 this function gets the UTM_zone and a boolean that is true if the map is in the northern hemisphere More...
 
void get_x_and_y_locations (int row, int col, double &x_loc, double &y_loc)
 this gets the x and y location of a node at row and column More...
 
void get_x_and_y_locations (int row, int col, float &x_loc, float &y_loc)
 this gets the x and y location of a node at row and column More...
 
void get_lat_and_long_locations (int row, int col, double &lat, double &longitude, LSDCoordinateConverterLLandUTM Converter)
 a function to get the lat and long of a node in the raster Assumes WGS84 ellipsiod More...
 
void get_easting_and_northing_vectors (vector< float > &Eastings, vector< float > &Northings)
 This returns vectors of all the easting and northing points in the raster Used for interpolations. More...
 
vector< float > interpolate_points_bilinear (vector< float > UTMEvec, vector< float > UTMNvec)
 This interpolates a vector of points onto the raster. Uses bilinear interpolation. More...
 
LSDRaster fill_with_interpolated_data (vector< int > rows_of_nodes, vector< int > cols_of_nodes, vector< float > interpolated_data)
 This fills a raster with precalculated interpolated data. More...
 
float get_value_of_point (float UTME, float UTMN)
 This gets the value at a point in UTM coordinates. More...
 
bool check_if_point_is_in_raster (float X_coordinate, float Y_coordinate)
 this check to see if a point is within the raster More...
 
void get_row_and_col_of_a_point (float X_coordinate, float Y_coordinate, int &row, int &col)
 Gets the row and column of a point in the raster. More...
 
vector< float > get_XY_MinMax ()
 This function returns a vector with the X adn Y minimum and max values. More...
 
vector< float > get_RasterData_vector ()
 This function returns the raster data as a vector. More...
 
vector< float > get_RasterData_vector_No_NDVs ()
 This function returns the raster data as a vector, ignoring NDVs. More...
 
void write_RasterData_to_text_file (string filename)
 This function returns the raster data as text file. More...
 
void rewrite_with_random_values (float range)
 rewrite all the data array values with random numbers (with a uniform distribution). More...
 
LSDRaster create_raster_nodata ()
 Create a raster in of the same number of rows and cols with nodata. More...
 
LSDRaster RasterTrimmer ()
 Calculate the minimum bounding rectangle for an LSDRaster Object and crop out all the surrounding NoDataValues to reduce the size and load times of output rasters. More...
 
LSDRaster RasterTrimmerPadded (int padded_pixels)
 Calculate the minimum bounding rectangle for an LSDRaster Object and crop out all the surrounding NoDataValues to reduce the size and load times of output rasters. Similar to RasterTrimmer but has a pixel buffer. Useful for CRN data since sometimes the channel in the DEM does not correspond exactly with the data point. More...
 
LSDRaster RasterTrimmerSpiral ()
 Takes a raster and trims nodata from around the edges to result in a rectangular LSDRaster. More...
 
LSDRaster clip_to_smaller_raster (LSDRaster &smaller_raster)
 This returns a clipped raster that has the same dimensions as the smaller raster. More...
 
LSDRaster clip_to_smaller_raster (LSDIndexRaster &smaller_raster)
 This returns a clipped raster that has the same dimensions as the smaller raster. More...
 
LSDRaster LSDRasterTemplate (Array2D< float > InputData)
 Make LSDRaster object using a 'template' raster and an Array2D of data. More...
 
void strip_raster_padding ()
 Strips the edge rows/columns of a LSDRaster on each side of the array. More...
 
LSDRaster BufferRasterData (float window_radius)
 Buffers a raster using a circular kernel of a user-defined radius (m) More...
 
LSDRaster calculate_relief (float kernelWidth, int kernelType)
 Calculates a relief raster. More...
 
float mean_elevation (void)
 Calculates mean elevation of a raster. More...
 
float max_elevation (void)
 Calculates max elevation of a raster. More...
 
float mean_relief (float kernelsize)
 Calculates mean relief of a raster, it defaults to a circular kernal. More...
 
float difference_rasters (LSDRaster &compare_raster)
 Calculates the mean difference between two rasters. More...
 
void raster_multiplier (float multiplier)
 This multiplies the raster data by a multiplier Note that values are replaced. More...
 
LSDRaster MapAlgebra_multiply (LSDRaster &M_raster)
 This multiplies two rasters, elementwise Simple elementwise multiplictation. More...
 
LSDRaster MapAlgebra_divide (LSDRaster &M_raster)
 This divides two rasters, elementwise Simple elementwise division. More...
 
LSDRaster MapAlgebra_add (LSDRaster &M_raster)
 This add two rasters, elementwise Simple elementwise addition. More...
 
LSDRaster MapAlgebra_subtract (LSDRaster &M_raster)
 This subtracts two rasters, elementwise Simple elementwise subtraction. More...
 
float WrapSample (int row, int col)
 This returns a value from the array data element but wraps around the array dimensions so that row > NRows (for example) returns a value. More...
 
void SetWrapSample (int row, int col, float value)
 This sets a value in the data array withthe added feature that it wraps beyond NRows and NCols. More...
 
void DSSetFeatureCorners (int featuresize, float scale)
 This sets the corners of features as the first step in the diamond square algorithm. More...
 
void DSSampleSquare (int row, int col, int size, float value)
 This is the square sampling step of the diamond square algorithm: it takes the average of the four corners and adds a random number to set the centrepoint of a square. More...
 
void DSSampleDiamond (int row, int col, int size, float value)
 This is the diamond sampling step of the diamond square algorithm: it takes the average of the four corners and adds a random number to set the centrepoint of a diamond. More...
 
void DiamondSquare_SampleStep (int stepsize, float scale)
 This is the sampling function for the diamond square algorithm: it runs both a diamond and a square sampling for each step. More...
 
LSDRaster DiamondSquare (int feature_order, float scale)
 This is the driving function for the diamond square algorithm. More...
 
LSDRaster hillshade ()
 This function generates a hillshade raster. More...
 
LSDRaster hillshade (float altitude, float azimuth, float z_factor)
 
Array2D< float > Shadow (int theta, int phi)
 This function generates a hillshade derivative raster using the algorithm outlined in Codilean (2006). More...
 
LSDRaster CastShadows (int Azimuth, int ZenithAngle)
 Function to determine areas of a DEM that are in shadow from a given radiation source defined by an Azimuth and Zenith following Codilean (2006). More...
 
Array2D< float > Shadows (int Azimuth, int ZenithAngle)
 Function to determine areas of a DEM that are in shadow from a given radiation source defined by an Azimuth and Zenith following Codilean (2006). More...
 
LSDRaster TopographicShielding (int theta_step, int phi_step)
 This function generates a topographic shielding raster using the algorithm outlined in Codilean (2006). More...
 
LSDRaster TopographicShielding ()
 
vector< LSDRastercalculate_polyfit_surface_metrics (float window_radius, vector< int > raster_selection)
 Surface polynomial fitting and extraction of topographic metrics. More...
 
vector< LSDRastercalculate_polyfit_roughness_metrics (float window_radius1, float window_radius2, vector< int > raster_selection)
 Surface polynomial fitting and extraction of roughness metrics. More...
 
void calculate_polyfit_coefficient_matrices (float window_radius, Array2D< float > &a, Array2D< float > &b, Array2D< float > &c, Array2D< float > &d, Array2D< float > &e, Array2D< float > &f)
 This function calculates 6 coefficient matrices that allow the user to then calcualte slope, curvature, aspect, a classification for finding saddles and peaks and other metrics. More...
 
LSDRaster calculate_polyfit_elevation (Array2D< float > &f)
 This function calculates the elevation based on a polynomial fit. More...
 
LSDRaster calculate_polyfit_slope (Array2D< float > &d, Array2D< float > &e)
 This function calculates the slope based on a polynomial fit. More...
 
LSDRaster calculate_polyfit_aspect (Array2D< float > &d, Array2D< float > &e)
 This function calculates the aspect based on a polynomial fit. More...
 
LSDRaster calculate_polyfit_curvature (Array2D< float > &a, Array2D< float > &b)
 This function calculates the curvature based on a polynomial fit. More...
 
LSDRaster calculate_polyfit_planform_curvature (Array2D< float > &a, Array2D< float > &b, Array2D< float > &c, Array2D< float > &d, Array2D< float > &e)
 This function calculates the planform curvature based on a polynomial fit. More...
 
LSDRaster calculate_polyfit_profile_curvature (Array2D< float > &a, Array2D< float > &b, Array2D< float > &c, Array2D< float > &d, Array2D< float > &e)
 This function calculates the profile curvature based on a polynomial fit. More...
 
LSDRaster calculate_polyfit_tangential_curvature (Array2D< float > &a, Array2D< float > &b, Array2D< float > &c, Array2D< float > &d, Array2D< float > &e)
 This function calculates the tangential curvature based on a polynomial fit. More...
 
LSDIndexRaster calculate_polyfit_classification (Array2D< float > &a, Array2D< float > &b, Array2D< float > &c, Array2D< float > &d, Array2D< float > &e)
 This function identifies approximate position of stationary points within discrete surface using a threshold slope. More...
 
LSDRaster get_hilltop_curvature (LSDRaster &curvature, LSDRaster &Hilltops)
 Gets the hilltop curvature raster. More...
 
LSDRaster remove_positive_hilltop_curvature (LSDRaster &hilltop_curvature)
 Removes positive hilltop curvature values. More...
 
void remove_positive_values ()
 Removes positive values from a raster. More...
 
float get_percentage_bedrock_ridgetops (LSDRaster &roughness, LSDRaster &hilltop_curvature, float threshold)
 Gets the percentage of bedrock ridges. More...
 
LSDRaster calculate_slope_angles ()
 Calculates slope angle in radians. Needs the slope raster. More...
 
LSDRaster calculate_water_supply_rate_for_saturation (float soil_thick, float K, LSDRaster &ContributingArea, LSDRaster &SlopeAngle)
 Calculates the water supply rate required for saturation of the hillslope soil. More...
 
LSDRaster calculate_factor_of_safety_at_saturation (float C_r, float rho_s, float soil_thick, float tan_phi, LSDRaster &SlopeAngle)
 This calculates the factor of safety if the soil is completely saturated. More...
 
void calculate_polyfit_directional_cosines (Array2D< float > &d, Array2D< float > &e, Array2D< float > &l, Array2D< float > &m, Array2D< float > &n)
 Algorithm that assesses surface roughness based on a polynomial fit. More...
 
void calculate_orientation_matrix_eigenvalues (float window_radius, Array2D< float > &l, Array2D< float > &m, Array2D< float > &n, Array2D< float > &s1, Array2D< float > &s2, Array2D< float > &s3)
 Find eigenvalues for orientation matrix. More...
 
void calculate_plane_coefficient_matrices (float window_radius, Array2D< float > &a_plane, Array2D< float > &b_plane, Array2D< float > &c_plane)
 This function is a wrapper to get the three roughness eigenvalues s1, s2 and s3. More...
 
LSDRaster calculate_REI (Array2D< float > &a_plane, Array2D< float > &b_plane, float CriticalSlope)
 Create the REI raster. More...
 
LSDRaster calculate_REI (float window_radius, float CriticalSlope)
 Create the REI raster (imporoved wrapper) Rock exposure index defined as areas with local slope exceeding some critical slope as defined by DiBiase et al. (2012) More...
 
void calculate_and_print_polyfit_rasters (float window_radius, string file_prefix, vector< int > file_list)
 this function takes the polyfit functions and requires a window radius and a vector telling the function which rasters to print to file. More...
 
void calculate_and_print_polyfit_and_roughness_rasters (float window_radius, float roughness_radius, string file_prefix, vector< int > file_list)
 This function takes the combines the polyfit functions and the roughness function in one package. More...
 
void calculate_roughness_rasters (float window_radius, float roughness_radius, string file_prefix, vector< int > file_code)
 This function takes the combines the roughness functions in one package. More...
 
void remove_seas ()
 This function changes any elevation <= 0 to NoDataValue. More...
 
void mask_to_nodata_below_threshold (float threshold)
 This function changes any elevation <= threshold to NoDataValue. More...
 
LSDRaster mask_to_nodata_using_threshold (float threshold, bool belowthresholdisnodata)
 This function changes any data point either above or below threshold to NoDataValue. More...
 
LSDRaster mask_to_nodata_using_threshold_using_other_raster (float threshold, bool belowthresholdisnodata, LSDRaster &MaskingRaster)
 This function changes any data point either above or below threshold to NoDataValue The threshold is determined by a second raster. More...
 
LSDIndexRaster mask_to_indexraster_using_threshold (float threshold, bool belowthresholdisnodata)
 This function creats an LSDIndexRaster mask (with true == 1 and otherwise nodata) from an LSDRaster. Can mask either above or below a threshold. More...
 
LSDRaster mask_to_nodata_with_mask_raster (LSDIndexRaster &Mask_raster, int mask_value)
 This function masks a raster to nodata based on a mask value and a mask raster. More...
 
LSDRaster fill ()
 This function fills pits/sinks in a DEM by incrementing elevations for cells with no downslope neighbour. The process is repeated adnausium until no cells require incrementing. More...
 
void fill_iterator (Array2D< float > &fill_data, int i, int j)
 This is a recursive algorithm that is called by the fill function. More...
 
LSDRaster fill (float &MinSlope)
 This function fills pits/sinks in a DEM by checking for pits from lowest to highest elevation, starting at the DEM boundary (raster edge or adjacent to NDVs). More...
 
LSDRaster MDFlow (vector< string > BoundaryConditions)
 Generate a flow area raster using a multi direction algorithm. More...
 
LSDRaster FreemanMDFlow ()
 Generate a flow area raster using a multi direction algorithm. More...
 
LSDRaster FreemanMDFlow_SingleSource (int i_source, int j_source)
 Route flow from one source pixel using FreemanMDFlow. Adapted from SWDG's code above. More...
 
LSDRaster FMDChannelsFromChannelHeads (vector< int > &channel_heads_rows, vector< int > &channel_heads_cols, float R_threshold)
 Extracts a multi-pixel channel network, as opposed to a single thread channel, using method outlined in Pelletier, 2013, WRR; A robust, two-parameter method for the extraction of drainage networks from high-resolution digital elevation models (DEMs): Evaluation using synthetic and real-world DEMs. More...
 
LSDRaster QuinnMDFlow ()
 Generate a flow area raster using a multi direction algorithm. More...
 
LSDRaster M2DFlow ()
 Generate a flow area raster using a multi 2-direction algorithm. More...
 
LSDRaster RidgeSample (Array2D< float > &Ridges)
 Module to sample LSDRaster values running along a ridgetop network. More...
 
LSDRaster RidgeSmoother (int WindowRadius)
 Pass a smoothing window over a ridge LSDRaster object to calculate an average value running along the ridgetop. More...
 
LSDRaster RidgeBuffer (int BufferRadius)
 Pass a buffer over a ridge LSDRaster object to increase sampling area. More...
 
LSDRaster BasinAverager (LSDIndexRaster &Basins)
 Module assigns an average LSDRaster value to each basin. More...
 
float SingleBasinAverager (LSDIndexRaster &Basin)
 Module calculates an average value to each for a given raster from within a basin. More...
 
LSDRaster BasinArea (LSDIndexRaster Basins)
 Write the area(in spatial units) of each basin to the basin's pixels. More...
 
void GetBasinVector (LSDIndexRaster Basins, int BasinOfInterest)
 Convert a basin, given by a basin ID, into a chain of xy coordinates for fast plotting of vector basin outlines. More...
 
vector< LSDRasterBasinPuncher (vector< int > basin_ids, LSDIndexRaster BasinArray)
 Punch basins out of an LSDRaster to create DEMs of a single catchment. More...
 
LSDRaster CookieCutRaster (LSDRaster Cutter)
 Cookie cut a raster using a smaller raster. More...
 
void CollectBasinMetrics (LSDIndexRaster &Basins, LSDRaster &Slope, LSDRaster &Elevation, LSDRaster &Aspect, LSDRaster &Area, LSDRaster &DrainageDensity, LSDRaster &Cht, LSDRaster &HillslopeLength, LSDRaster &MeanSlope, LSDRaster &Relief, LSDRaster &MeanAspect, LSDRaster &LH_drainage_density, Array2D< float > LH_Data, float CriticalSlope, string RasterFilename)
 Collect all basin average metrics into a single file. More...
 
void raster_statistics_by_index (LSDIndexRaster &IndexRaster, vector< float > &mean_vector, vector< float > &sd_vector, vector< float > &serr_vector, vector< int > &Npts_vector)
 Takes a raster and a corresponding index raster, and calculates the mean, sd and standard error by index. Returns four vectors: mean, st.dev., st.err and Number of points for each category. More...
 
pair< float, float > Boomerang (LSDRaster &Slope, LSDRaster &D_inf, string RasterFilename, float log_bin_width=0.1, int SplineResolution=200, float bin_threshold=0.05)
 Generate data in two text files to create a boomerang plot as in Roering et al [2007]. More...
 
LSDRaster DrainageDensity (LSDIndexRaster &StreamNetwork, LSDIndexRaster &Basins, Array2D< int > FlowDir)
 Calculate drainage density of a set of input basins. More...
 
float get_drainage_density_of_raster (LSDIndexRaster &StreamNetwork, Array2D< int > FlowDir)
 Calculate drainage density of a DEM. More...
 
LSDRaster HillslopeLengthFromDrainageDensity (LSDIndexRaster &StreamNetwork, LSDIndexRaster &Basins, Array2D< int > FlowDir)
 Simple method to calculate drainage density for each basin and then convert these values into a hillslope length raster. More...
 
void GetVectors (LSDRaster Magnitude, LSDRaster Direction, string output_file, int step)
 Method to export thinned vector field data to a text file. More...
 
LSDRaster NonLocalMeansFilter (int WindowRadius=2, int SimilarityRadius=2, int DegreeFiltering=2, float Sigma=1.25)
 Perform Non-local means filtering on a DEM following Baude et al [2005]. More...
 
void PadRasterSymmetric (Array2D< float > &PaddedRasterData, int &SimilarityRadius)
 Creates a buffer around an array (of size SimilarityRadius) and gives the new border mirror symmetric values of the original array reflected across the boundary. More...
 
void MakeGaussianKernel (Array2D< float > &Kernel, float sigma, int SimilarityRadius)
 Generate gaussian weighted kernel. More...
 
LSDRaster GaussianFilter (float sigma, int kr=0)
 Filters the raster using a square 2D Gaussian filter. The filter is applied using a moving kernel of gaussian weights with a radius of 3*sigma. More...
 
LSDRaster PeronaMalikFilter (int timesteps, float percentile_for_lambda, float dt)
 Filters the raster using a Perona-Malik non-linear diffusion filter. More...
 
Array2D< float > D_inf_FlowDir ()
 D-infinity flow direction algorithm after Tarboton (1997). More...
 
LSDRaster D_inf_FlowArea (Array2D< float > FlowDir_array)
 Main function for generating a D-infinity flow area raster after Tarboton (1997). More...
 
void D_infAccum (int i, int j, Array2D< float > CountGrid, Array2D< float > Flowarea_Raster, Array2D< float > FlowDir_array)
 Recursive function to calculate accumulating area for a given pixel. More...
 
LSDRaster D_inf ()
 Wrapper Function to create a D-infinity flow area raster with one function call. More...
 
LSDRaster D_inf_units ()
 Wrapper Function to create a D-infinity flow area raster, in spatial units, with one function call. More...
 
LSDRaster D_inf_ConvertFlowToArea ()
 Wrapper Function to convert a D-infinity flow raster into spatial units. More...
 
LSDRaster write_dinf_flowdir_to_LSDRaster (Array2D< float > dinflow)
 Function to write the D-infinity flow directions to an LSDRaster. More...
 
LSDIndexRaster D_inf_watershed (LSDRaster D_inf_FlowDir, int PourRow, int PourCol)
 Function to generate upslope contributing area extent from the D-infinity flow directions to an LSDRaster. More...
 
LSDRaster calculate_topographic_index (LSDRaster &AccumulationArea, LSDRaster &Slope)
 Function to calculate the topographic index, a moisture distribution indicator. More...
 
LSDIndexRaster PointShapefileToRaster (string FileName)
 Method to turn a point shapefile into an LSDIndexRaster. More...
 
LSDIndexRaster PolylineShapefileToRaster (string FileName)
 Method to turn a polyline shapefile into an LSDIndexRaster. More...
 
LSDRaster Resample (float OutputResolution)
 Method to resample an LSDRaster to a lower resolution. More...
 
Array2D< int > create_mask (float window_radius, int neighbourhood_switch)
 creates a circular mask for neighbourhood statistics More...
 
LSDRaster neighbourhood_statistics_spatial_average (float window_radius, int neighbourhood_switch)
 gets mean value for specified circular neighbourhood More...
 
vector< LSDRasterneighbourhood_statistics_spatial_average_and_SD (float window_radius, int neighbourhood_switch)
 gets mean & standard deviation value specified circular neighbourhood More...
 
LSDRaster neighbourhood_statistics_local_relief (float window_radius, int neighbourhood_switch)
 gets relief within value specified circular neighbourhood More...
 
LSDRaster neighbourhood_statistics_fraction_condition (float window_radius, int neighbourhood_switch, int condition_switch, float test_value)
 tests neighbourhood for the fraction of values for which the specified condition is met. More...
 
LSDRaster border_with_nodata (int border_width, int irregular_switch=0)
 Function to change border pixels to nodata. More...
 
LSDIndexRaster find_cells_bordered_by_nodata ()
 This function creates a mask that has the value of 1 for cells that are either on the edge or bordered by nodata (from their 9 neighbors) More...
 
void check_isolated_nodata ()
 This looks for isolated instances of no data. More...
 
void rudimentary_nodata_fill ()
 a very rudimentay filling routine that just fills nodata nodes with the average elevation of its neighbors More...
 
LSDRaster alternating_direction_nodata_fill (int window_width)
 A routine that fills nodata holes. It cannot recognise nodata around the edges so the spiral trimmer should be used first The routine sweeps the raster looking for nodata and filling this nodata with an average value from surrounding nodes. The sweeping changes directions, four sweep directions in all (+ rows, - rows, + cols, -cols) and it alternates between these directions until the raster is filled. More...
 
LSDIndexRaster create_binary_isdata_raster ()
 This returns an index raster with 1 for data and 0 for nodata. More...
 
LSDRaster alternating_direction_nodata_fill_with_trimmer (int window_width)
 A routine that fills nodata holes. It first prepares the data with the sprial trimmer so nodata around the edges is removed. The routine sweeps the raster looking for nodata and filling this nodata with an average value from surrounding nodes. The sweeping changes directions, four sweep directions in all (+ rows, - rows, + cols, -cols) and it alternates between these directions until the raster is filled. The routine is particularly useful for data with holes that is to be prepared for spectral analysis. More...
 
LSDRaster nodata_fill_irregular_raster (int window_radius)
 Function to fill in no data holes in an irregular raster. Pixel must have all neighbours not equal to no data value within the specified window radius. Data is filled based on mean of pixels within the window radius.
 
LSDRaster alternating_direction_nodata_fill_irregular_raster (int window_width)
 A routine that fills nodata holes. Modified by FJC to only fill holes surrounded in all directions by pixels with valid elevation values. More...
 
LSDIndexRaster Create_Mask (string Condition, float TestValue)
 Function to create a masked LSDIndexRaster raster based on a conditional statement. More...
 
LSDRaster ExtractByMask (LSDIndexRaster Mask)
 Function to extract an LSDRaster based on a LSDIndexRaster mask. More...
 
void MaskRaster (LSDIndexRaster Mask)
 Function to update an LSDRaster based on a LSDIndexRaster mask. More...
 
LSDIndexRaster IsolateChannelsLashermesCurvature (float sigma, string q_q_filename)
 method to locate channel pixels outlined by Lashermes. More...
 
LSDIndexRaster IsolateChannelsLashermesAspect (float sigma, string q_q_filename)
 
LSDIndexRaster IsolateChannelsLashermesFull (float sigma, string q_q_filename_prefix)
 
LSDIndexRaster IsolateChannelsLashermesCurvatureArea (float sigma, float area_threshold, string q_q_filename)
 
LSDIndexRaster IsolateChannelsGeonet (float timesteps, float area_threshold, float window_radius, string q_q_filename)
 method to locate channel pixels outlined by Passalacqua et al. (2010). More...
 
LSDIndexRaster IsolateChannelsQuantileQuantile (string q_q_filename)
 uses quantile-quantile analysis to pick departure from gaussian behaviour, then uses this as a threshold to create a binary dataset. More...
 
LSDIndexRaster IsolateChannelsQuantileQuantileAdaptive (int half_width)
 
Array2D< float > CalculateAdaptiveCurvatureThresholdSD (int half_width)
 Function to calculate the curvature threshold used for DrEICH channel extraction which varies across the landscape. More...
 
LSDIndexRaster CreateHilltopPatches (int minimum_patch_size)
 Method to convert an LSDRaster hilltop file into a series of contigiuous hilltop patches. More...
 
LSDIndexRaster CreateHilltopPatchesNEW (int minimum_patch_size)
 
void FlattenToFile (string FileName)
 Simple method to flatten an LSDRaster to a text file, with a sigle value on each line. More...
 
void FlattenToCSV (string FileName)
 Method to flatten an LSDRaster and place the non NDV values in a csv file. More...
 
void FlattenToWGS84CSV (string FileName)
 Method to flatten an LSDRaster and place the non NDV values in a csv file. More...
 
LSDRaster RemoveBelow (float Value)
 Simple method to remove any values below a user supplied value from an LSDRaster. More...
 
LSDRaster RemoveAbove (float Value)
 Simple method to remove any values above a user supplied value from an LSDRaster. More...
 
LSDRaster apply_mask (LSDIndexRaster &mask)
 apply a mask to a raster dataset, converts pixels to nodata where mas=k=1 More...
 
LSDIndexRaster ConvertToBinary (int Value, int ndv)
 Method to convert all values in an LSDRaster to a single value. More...
 
LSDRaster MergeRasters (LSDRaster &RasterToAdd)
 Method to merge data from two LSDRasters WITH SAME EXTENT together. /// The data from the raster specified as an argument will be added (will overwrite the original raster if there is a conflict). More...
 
void OverwriteRaster (LSDRaster &RasterToAdd)
 Method to merge data from two LSDRasters WITH SAME EXTENT together. /// The data from the raster specified as an argument will be added (will overwrite the original raster if there is a conflict). Overloaded function to rewrite original raster rather than creating a new one. More...
 
LSDIndexRaster get_potential_floodplain_patches (LSDRaster &Relief, LSDRaster &Slope, float relief_threshold, float slope_threshold)
 Function to get potential floodplain patches using a slope and relief threshold. More...
 
float get_threshold_for_floodplain (float bin_width, float peak_threshold, int peak_distance)
 Function to get threshold from a raster using a histogram of Probability-Density values. The function identifies the peaks in the PDF, and sets the threshold to the peak with the lowest value. This can be used to set the floodplain threshold. More...
 
float get_threshold_for_floodplain_QQ (string q_q_filename, float threshold_condition, int lower_percentile, int upper_percentile)
 Function to get threshold from a raster using qq plots. More...
 
string ChannelLengthByOrder (LSDIndexRaster &StreamNetwork, Array2D< int > FlowDir)
 Get the lengths in spatial units of each part of the channel network, divided by strahler order. More...
 
LSDRaster PoupulateRasterGaussian (float minimum, float mean)
 Populate a raster with random noise drawn from a gaussian distribution of given mean and minimum values. More...
 
LSDRaster PoupulateRasterSingleValue (float value)
 Populate a raster with a single value. More...
 
void HilltopsToCSV (LSDRaster &CHT, LSDRaster &CHT_gradient, LSDRaster &gradient, int UTMZone, bool isNorth, int eId, string filename)
 Write CHT and hilltop gradient data to a *.csv file, coded by UTM coordinates as well as lat/long. More...
 
vector< vector< float > > Sample_Along_Ridge (LSDRaster &Raster1, LSDRaster &Raster2, LSDRaster &Raster3, int a, int b, int threshold)
 Sample the values of 3 input rasters that intersect with the point a,b within the area defined by threshold. More...
 
LSDRaster convert_from_feet_to_metres ()
 function to convert feet to metres using US international feet, where 1 foot = 0.3048006096012192 metres. More...
 
LSDRaster convert_from_centimetres_to_metres ()
 function to convert elevations from centimetres to metres More...
 

Protected Attributes

int Lx
 
int Ly
 
float dfx
 
float dfy
 
float NyquistFreq
 
float WSS
 
Array2D< float > P_DFT
 
vector< float > RadialFrequency
 
vector< float > RadialPSD
 
vector< float > BackgroundPSD
 
vector< float > NormalisedPSD
 
vector< float > CI95
 
vector< float > normCI95
 
vector< float > normCI99
 
vector< float > R_sq
 
vector< float > beta
 
- Protected Attributes inherited from LSDRaster
int NRows
 Number of rows.
 
int NCols
 Number of columns.
 
float XMinimum
 Minimum X coordinate.
 
float YMinimum
 Minimum Y coordinate.
 
float DataResolution
 Data resolution.
 
int NoDataValue
 No data value.
 
map< string, string > GeoReferencingStrings
 A map of strings for holding georeferencing information.
 
Array2D< float > RasterData
 Raster data.
 
Array2D< double > RasterData_dbl
 These are used primarily by LSDCatchmentModel.
 
Array2D< int > RasterData_int
 

Detailed Description

This object performs spectral analysis.

Constructor & Destructor Documentation

LSDRasterSpectral::LSDRasterSpectral ( string  filename,
string  extension 
)
inline

Create an LSDRasterSpectral from a file. Uses a filename and file extension.

Returns
LSDRasterSpectral
Parameters
filenameA String, the file to be loaded.
extensionA String, the file extension to be loaded.
Author
SMM
Date
18/12/2012
LSDRasterSpectral::LSDRasterSpectral ( int  nrows,
int  ncols,
float  xmin,
float  ymin,
float  cellsize,
float  ndv,
Array2D< float >  data 
)
inline

Create an LSDRasterSpectral from memory.

Returns
LSDRasterSpectral
Parameters
nrowsAn integer of the number of rows.
ncolsAn integer of the number of columns.
xminA float of the minimum X coordinate.
yminA float of the minimum Y coordinate.
cellsizeA float of the cellsize.
ndvAn integer of the no data value.
dataAn Array2D of floats in the shape nrows*ncols, containing the data to be written.
Author
SMM
Date
18/12/2012
LSDRasterSpectral::LSDRasterSpectral ( LSDRaster An_LSDRaster)
inline

Create an LSDRasterSpectral from an LSDRaster object.

Parameters
An_LSDRasterLSDRaster object.
Returns
LSDRasterSpectral.
Author
SMM
Date
18/12/2012
LSDRasterSpectral::LSDRasterSpectral ( int  raster_order,
float  cellsize,
float  ndv 
)
inline

Create an LSDRasterSpectral object that has dimensions 2^raster_order.

Parameters
rasterorder, that is the order of the raster dimension where the dimension is 2^raster_order.
Thesize of the cells
nodata value
Author
SMM
Date
18/02/2014

Member Function Documentation

void LSDRasterSpectral::bandpass_filter ( Array2D< float > &  RawSpectrumReal,
Array2D< float > &  RawSpectrumImaginary,
Array2D< float > &  FilteredSpectrumReal,
Array2D< float > &  FilteredSpectrumImaginary,
float  f1,
float  f2 
)

BANDPASS FILTER.

Filter array to band between frequency bands f1 and f2. The bandpass filter is a gaussian filter centred at (f1+f2)/2 and with a SD of |f2-f1|/6.

Parameters
RawSpectrumReal
RawSpectrumImaginary
FilteredSpectrumReal
f1
f2
Author
David Milodowski
Date
18/12/2012
void LSDRasterSpectral::calculate_2D_PSD ( Array2D< float > &  spectrum_real_shift,
Array2D< float > &  spectrum_imaginary_shift 
)

CALCULATE THE DFT PERIODOGRAM.

Multiply fourier analysis output by complex conjugate and normalises.

Parameters
spectrum_real_shift
spectrum_imaginary_shift
Author
David Milodowski
Date
18/12/2012
void LSDRasterSpectral::calculate_background_spectrum ( float  rollover_frequency,
float  beta,
float  log_bin_width,
int  N_iterations,
int  window_option = 0 
)

CALCULATE BACKGROUND SPECTRUM.

This function calculates the background spectrum, following Perron et al., 2008; Spectral Signatures of characteristic spatial scales and nonfractal structure in landscapes; Journal of Geophysical Research. The background spectrum is produced by creating a number of fractal rasters with the same spectral power as the original dataset and averaging their spectra.

Parameters
rollover_frequency
betafractal scaling
log_bin_widthof the logarithmically spaced bins. For topography, suggest this is 0.1 to start.
N_iterationsThe number of reference fractal rasters that are produced to create the background spectrum
window_option0 = unity window (default); 1 = Hann window (recommended); 2 = Hamming window
Author
David Milodowski
Date
30/10/2014
void LSDRasterSpectral::calculate_radial_PSD ( )

GET RADIAL POWER SPECTRUM.

Collapse 2D PSD into a radial PSD.

Author
David Milodowski
Date
18/12/2012
void LSDRasterSpectral::detrend2D ( Array2D< float > &  zeta,
Array2D< float > &  zeta_detrend,
Array2D< float > &  trend_plane 
)

Detrend Data.

Fit plane by least squares regression and use coefficients to determine local slope ax + by + c = z.

Parameters
zetaInput elevation data.
zeta_detrendOutput detrended elevation data.
trend_planeOutput array of trend plane.
Author
David Milodowski
Date
18/12/2012
void LSDRasterSpectral::dfftw2D_fwd ( Array2D< float > &  InputArray,
Array2D< float > &  OutputArrayReal,
Array2D< float > &  OutputArrayImaginary,
int  transform_direction 
)

Computes the forward fast fourier transform of a 2D discrete dataset.

Parameters
InputArray= zeta_padded (padded DEM).
transform_direction= -1.
OutputArrayReal= Real 2D spectrum.
OutputArrayImaginary= Imaginary 2D spectrum.
Author
David Milodowski
Date
18/12/2012
void LSDRasterSpectral::dfftw2D_inv ( Array2D< float > &  InputArrayReal,
Array2D< float > &  InputArrayImaginary,
Array2D< float > &  OutputArray,
int  transform_direction 
)

Computes the inverse fast fourier transform of a 2D discrete dataset.

Parameters
InputArrayReal= Real component of 2D spectrum.
InputArrayImaginary= Imaginary component of 2D spectrum.
OutputArray= reconstructed DEM.
transform_direction= 1.
Author
David Milodowski
Date
18/12/2012
void LSDRasterSpectral::dfftw2D_inv_complex ( Array2D< complex< float > > &  InputArrayComplex,
Array2D< float > &  OutputArray,
int  transform_direction 
)

Computes the inverse fast fourier transform of a 2D discrete dataset.

Parameters
InputArrayComplex= Complex array of a 2D spectrum (real and imaginary parts)
OutputArray= reconstructed DEM.
transform_direction= 1.
Author
DAV
Date
22/10/2014

Note using a float-version: "fftwf_complex" rather than "fftw_complex", which is type double.

LSDRaster LSDRasterSpectral::fftw2D_filter ( int  FilterType,
float  FLow,
float  FHigh 
)

FAST FOURIER TRANSFORM FILTER FOR A REAL, 2-DIMENSIONAL DATASET.

Note that FLow <= FHigh

There are three types of filters depending on the intentions of the user

BANDPASS FILTER (FilterType = 1)
Filter array to band between frequency bands f1 and f2. The bandpass filter is a gaussian filter centred at (f1+f2)/2 and with a SD of |f2-f1|/6.

LOWPASS FILTER (FilterType = 2)
Filter array to retain frequencies below f1. The filter edge is a radial gaussian function with a SD of |f2-f1|/3. f1 is the frequency below which the filter starts to taper; f2 is the frequency at which the filter tapers to zero. If f1 = f2, the edge is effectively a step function.

HIGHPASS FILTER (FilterType = 3)
Filter array to retain frequencies above f2. The filter edge is a radial gaussian function with a SD of |f2-f1|/3. f2 is the frequency below which the filter starts to taper; f1 is the frequency at which the filter tapers to zero. If f1 = f2, the edge is effectively a step function.

HIGHPASS FILTER REMAINDER(FilterType = 4)
Filter returns the counterpart signal to that filtered using the highpass filter (FilterType 1)

LOWPASS FILTER REMAINDER(FilterType = 5)
Filter returns the counterpart signal to that filtered using the lowpass filter (FilterType 2)

A second type of bandpass filter is possible by combining the highpass and lowpass filters (using FilterTypes 4 & 5 successively).

Parameters
FilterType
FLow
FHigh
Author
David Milodowski
Date
18/12/2012
void LSDRasterSpectral::fftw2D_spectral_analysis ( char *  file_id,
float  LogBinWidth 
)

COMPUTE DISCRETE FAST FOURIER TRANSFORM OF A REAL, 2-DIMENSIONAL DATASET.

Computes the 2D and radial power spectra of a 2D array.

Parameters
file_idFile identifier to prefix output files
LogBinWidthWidth of the logarithmically spaced bins. For topography, suggest this is 0.1 to start.
Author
David Milodowski
Date
18/12/2012
LSDRaster LSDRasterSpectral::fftw2D_wiener ( )

WIENER FILTER FOR A REAL, 2-DIMENSIONAL DATASET.

The Wiener filter is a spectral filter that removes noise from an image or DEM. Essentially, it works on the principle that the observed spectrum contains the superposition of the real signal and an additional noise signal, which we want to remove. If we know, or can make a reasonable guess at the noise, N(f), and signal, S(f), parts of the spectrum then we can remove the noise using the filter:

phi(f) = |S(f)|^2/(|S(f)|^2 + |N(f)|^2)

For topography; at long wavelengths the topographic signal obeys an approximate power law relationship between amplitude and frequency, decreasing as the frequency increases (and wavelength decreases). Noise typically dominates the high frequency part of the spectrum. Thus at high frequencies the spectrum is dominated by noise, and the filter weight goes to zero. In contrast, at low frequencies, the signal dominates and the filter weight goes to 1.

The optimal wiener filter is described in more detail in Numerical Recipes, 13.3, p149.

The exact structure of the noise is worth thinking about. White noise, which is random, has equal power across all wavelengths. In the instance of topography, noise can be created by a whole range of sources, from rock exposure, to pit and mound topography, to unfiltered vegetation etc. It is likely that these sources will not produce purely white noise, but rather will show an element of structure. This program makes two assumptions about the noise: i) it dominates the signal at high frequencies (close to the Nquist frequency) and ii) we can reasonably model this using a linear fit in log-log space - i.e. it obeys some form of power law function between frequency and amplitude. Note that if the noise in the signal is really white noise, then the power law function for the noise would simply have an exponent of zero. I prefer this formulation because it permits the characterisation of the noise model without assuming that the noise has a particular structure (white noise, pink noise etc.)

Author
David Milodowski
Date
18/12/2012
void LSDRasterSpectral::find_rollover_frequency ( float &  rollover_frequency,
float &  rollover_beta,
float &  sub_rollover_beta,
float  log_bin_width 
)

FINDS ROLLOVER FREQUENCY.

This function finds the rollover frequency in the power spectrum of a landscape, following Perron et al., 2008; Spectral Signatures of characteristic spatial scales and nonfractal structure in landscapes; Journal of Geophysical Research.

Parameters
rollover_frequency
rollover_betafractal scaling of spectrum at frequencies above the rollover frequency
sub_rollover_betafractal scaling of spectrum at frequencies below the rollover frequency
LogBinWidthWidth of the logarithmically spaced bins. For topography, suggest this is 0.1 to start.
Author
David Milodowski
Date
30/10/2014
void LSDRasterSpectral::full_spectral_analysis ( float  log_bin_width,
int  N_iterations,
int  window_option = 0 
)

FULL SPECTRAL ANALYSIS.

This function is a wrapper function for the forward Fast Fourier Transform and subsequent analysis. It is designed to replicate the analysis of emergent lengthscales from Perron et al., 2008; Spectral Signatures of characteristic spatial scales and nonfractal structure in landscapes; Journal of Geophysical Research. The analysis runs the forward transform on the real dataset, converting the output producing a radial periodogram. A background spectrum is then produced by creating a number of fractal rasters with the same spectral power and averaging their spectra. This is then used to produce a normalised spectrum. The program outputs are two .txt files containing the power spectrum and log-binned spectrum, that can then be plotted (a python plotting script is available).

Parameters
LogBinWidthWidth of the logarithmically spaced bins. For topography, suggest this is 0.1 to start.
N_iterationsThe number of reference fractal rasters that are produced to create the background spectrum
window_option0 = unity window (default); 1 = Hann window (recommended); 2 = Hamming window
Author
David Milodowski
Date
30/10/2014
void LSDRasterSpectral::generate_fractal_surface_spectral_method ( float  beta)

This creates a fractal surface using the spectral method.

The method works as follows:
1) Generate a random surface.
2) Perform DFT on this random surface.
3) Scale the tranform (both real and imaginary parts) by 1/f^beta.
4) Perform the inverse DFT.
This results in a pseudo fractal surface that can be used in comparison with real topography.

Parameters
betavalue which is the scaling exponent
Author
SMM
Date
20/02/2014
void LSDRasterSpectral::generate_fractal_surface_spectral_method ( float  beta,
float  desired_relief 
)

This creates a fractal surface using the spectral method.

The method works as follows:
1) Generate a random surface.
2) Perform DFT on this random surface.
3) Scale the tranform (both real and imaginary parts) by 1/f^beta.
4) Perform the inverse DFT.
This results in a pseudo fractal surface that can be used in comparison with real topography.

Parameters
betavalue which is the scaling exponent
reliefThe maximum relief of the resulting surface
Author
SMM
Date
10/08/2017
vector< float > LSDRasterSpectral::get_col_direction_frequencies_unshifted ( )

This returns the frequency values of an UNSHIFTED DFT along the columns.

Returns
A float vector containing the frequency
Author
SMM
Date
19/02/2014
Array2D< float > LSDRasterSpectral::get_frequency_scaling_array ( float  beta)

This calucaltes a scaling array for scaling an unshifted DFT by the factor 1/f^beta.

Parameters
betathe fractal exponent
Returns
a float array with the scaling factor 1/f^beta
Author
SMM
Date
19/02/2014
vector< float > LSDRasterSpectral::get_row_direction_frequencies_unshifted ( )

This returns the frequency values of an UNSHIFTED DFT along the rows.

Returns
A float vector containing the frequency
Author
SMM
Date
19/02/2014
void LSDRasterSpectral::highpass_filter ( Array2D< float > &  RawSpectrumReal,
Array2D< float > &  RawSpectrumImaginary,
Array2D< float > &  FilteredSpectrumReal,
Array2D< float > &  FilteredSpectrumImaginary,
float  f1,
float  f2 
)

HIGHPASS FILTER.

Filter array to retain frequencies above f2. The filter edge is a radial gaussian function with a SD of |f2-f1|/3.

Parameters
RawSpectrumReal
RawSpectrumImaginary
FilteredSpectrumReal
FilteredSpectrumImaginary
f1
f2
Author
David Milodowski
Date
18/12/2012
void LSDRasterSpectral::highpass_filter_remainder ( Array2D< float > &  RawSpectrumReal,
Array2D< float > &  RawSpectrumImaginary,
Array2D< float > &  FilteredSpectrumReal,
Array2D< float > &  FilteredSpectrumImaginary,
float  f1,
float  f2 
)

HIGHPASS FILTER REMAINDER.

Filter array to retaining frequencies below f2 (the remainder from the highpass filter). The filter edge is a radial gaussian function with a SD of |f2-f1|/3.

Parameters
RawSpectrumReal
RawSpectrumImaginary
FilteredSpectrumReal
FilteredSpectrumImaginary
f1
f2
Author
David Milodowski
Date
29/09/2014
LSDIndexRaster LSDRasterSpectral::IsolateChannelsWienerQQ ( float  area_threshold,
float  window_radius,
string  q_q_filename 
)

method to locate channel pixels adapted from Pelletier (2013).

Isolate channelised portions of the landscape using an adapted method to that proposed by Pelletier, J. D. (2013), A robust, two-parameter method for the extraction of drainage networks from high-resolution digital elevation models (DEMs): Evaluation using synthetic and real-world DEMs, Water Resour. Res., 49, doi:10.1029/2012WR012452.

This function (i) filters the DEM using a Wiener filter; (ii) calculates the curvature; (iii) uses quantile quantile analysis to define a curvature threshold for channel initiation.

Parameters
acatchment area threshold for pruning
awindow radius for surface fitting from which curvature calculation is performed
Returns
LSDIndexRaster A binary raster where the pixel value is 1 where the input raster exceeded the defined threshold
Author
DTM
Date
10/07/2015
void LSDRasterSpectral::lowpass_filter ( Array2D< float > &  RawSpectrumReal,
Array2D< float > &  RawSpectrumImaginary,
Array2D< float > &  FilteredSpectrumReal,
Array2D< float > &  FilteredSpectrumImaginary,
float  f1,
float  f2 
)

LOWPASS FILTER.

Filter array to retain frequencies below f1. The filter edge is a radial gaussian function with a SD of |f2-f1|/3.

Parameters
RawSpectrumReal
RawSpectrumImaginary
FilteredSpectrumReal
FilteredSpectrumImaginary
f1
f2
Author
David Milodowski
Date
18/12/2012
void LSDRasterSpectral::lowpass_filter_remainder ( Array2D< float > &  RawSpectrumReal,
Array2D< float > &  RawSpectrumImaginary,
Array2D< float > &  FilteredSpectrumReal,
Array2D< float > &  FilteredSpectrumImaginary,
float  f1,
float  f2 
)

LOWPASS FILTER REMAINDER.

Filter array to retain frequencies above f1 (the remainder from the highpass filter). The filter edge is a radial gaussian function with a SD of |f2-f1|/3.

Parameters
RawSpectrumReal
RawSpectrumImaginary
FilteredSpectrumReal
FilteredSpectrumImaginary
f1
f2
Author
David Milodowski
Date
29/09/2014
void LSDRasterSpectral::scale_spectrum ( Array2D< float >  SpectrumReal,
Array2D< float >  SpectrumIm,
float  beta 
)

SCALE SPECTRUM.

Scales the spectrum by 1/f^beta, where beta is the fractal scaling.

Parameters
spectrum_real
spectrum_imaginary
beta
Author
David Milodowski
Date
30/10/2014
void LSDRasterSpectral::shift_spectrum ( Array2D< float > &  spectrum_real,
Array2D< float > &  spectrum_imaginary,
Array2D< float > &  spectrum_real_shift,
Array2D< float > &  spectrum_imaginary_shift 
)

SHIFT ORIGIN OF SPECTRUM IN FOURIER DOMAIN.

The output of the DFT algorithm must be rearranged to place the zero wavenumber element near the center of the array.

Parameters
spectrum_real
spectrum_imaginary
spectrum_real_shift
spectrum_imaginary_shift
Author
David Milodowski
Date
18/12/2012
void LSDRasterSpectral::shift_spectrum ( Array2D< float > &  spectrum_real,
Array2D< float > &  spectrum_imaginary 
)

SHIFT ORIGIN OF SPECTRUM IN FOURIER DOMAIN.

The output of the DFT algorithm must be rearranged to place the zero wavenumber element near the center of the array. This version overwrites the original shifted spectrum

Parameters
spectrum_real
spectrum_imaginary
Author
David Milodowski
Date
30/10/2014
void LSDRasterSpectral::shift_spectrum_inv ( Array2D< float > &  FilteredSpectrumReal,
Array2D< float > &  FilteredSpectrumImaginary,
Array2D< float > &  FilteredSpectrumReal_deshift,
Array2D< float > &  FilteredSpectrumImaginary_deshift 
)

DE-SHIFT ORIGIN OF SPECTRUM.

Inverse process of shift_spectrum() to return filtered spectrum to original format required for the inverse fourier transform algorithm.

Parameters
FilteredSpectrumReal.
FilteredSpectrumImaginary.
FilteredSpectrumReal_deshift.
FilteredSpectrumImaginary_deshift
Author
David Milodowski
Date
18/12/2012
void LSDRasterSpectral::shift_spectrum_inv ( Array2D< float > &  spectrum_real,
Array2D< float > &  spectrum_imaginary 
)

DE-SHIFT ORIGIN OF SPECTRUM.

Inverse process of shift_spectrum() to return filtered spectrum to original format required for the inverse fourier transform algorithm. This version overwrites the original shifted spectrum

Parameters
SpectrumReal.
SpectrumImaginary.
Author
David Milodowski
Date
30/10/2014
void LSDRasterSpectral::wiener_filter ( Array2D< float > &  RawSpectrumReal,
Array2D< float > &  RawSpectrumImaginary,
Array2D< float > &  FilteredSpectrumReal,
Array2D< float > &  FilteredSpectrumImaginary 
)

WIENER FILTER.

The Wiener filter is a spectral filter that removes noise from an image or DEM. Weights in filter given by amplitudes of noise and signal:

phi(f) = |S(f)|^2/(|S(f)|^2 + |N(f)|^2)

Parameters
RawSpectrumReal
RawSpectrumImaginary
FilteredSpectrumReal
FilteredSpectrumImaginary
WSSSummed square of the weighting coefficients.
Author
David Milodowski
Date
18/12/2012
void LSDRasterSpectral::window_data ( Array2D< float > &  input,
Array2D< float > &  output,
Array2D< float > &  window,
int  window_option = 0 
)

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=REDUNDANT=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

WINDOW MODULE.

This module applies a window to an input raster in order to limit spectral leakage in the Fourier transformation. A number of windows are available and more can be added as required. This function can replace the previous windowing functions. Currently there are three windows coded up:

  • a unity (box) window, which is the default - window_option = 0
  • a 2D elliptical Hann window - window_option = 1
  • a 2D elliptical Hamming window - window_option = 2.
    Parameters
    inputThe input raster, usually a detrended raster
    outputThe output windowed raster.
    windowA raster containing the window weights.
    window_optionAn integer to select the desired window function (see details)
    Author
    David Milodowski
    Date
    30/10/2014
void LSDRasterSpectral::window_data_Hamming2D ( Array2D< float > &  zeta_detrend,
Array2D< float > &  zeta_Hamming2D,
Array2D< float > &  Hamming2D 
)

Hamming Window Module.

Use 2D elliptical Hamming (raised cosine) window on data matrix, to reduce spectral leakage and retain good frequency resolution.

Parameters
zeta_detrendDetrended elevation data
zeta_Hamming2DOutput windowed data.
Hamming2DOutput Hann window.
Author
David Milodowski
Date
30/10/2014
void LSDRasterSpectral::window_data_Hann2D ( Array2D< float > &  zeta_detrend,
Array2D< float > &  zeta_Hann2D,
Array2D< float > &  Hann2D 
)

Hann Window Module.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=REDUNDANT=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Use 2D elliptical Hann (raised cosine) window on data matrix, to reduce spectral leakage and retain good frequency resolution.

Parameters
zeta_detrendDetrended elevation data
zeta_Hann2DOutput windowed data.
Hann2DOutput Hann window.
Author
David Milodowski
Date
18/12/2012

The documentation for this class was generated from the following files: