in3Utils: Geo Transformation Utilities

geoTrans

The geoTrans.py module gathers useful functions to operate transformations on raster, lines, points…

Functions

Projection on Raster:

Points = projectOnRaster(dem, Points) takes a “dem” dictionary and “Points” dictionary (wich can be a single point or a line…) in input and returns the “Points” dictionary with an extra “z” argument representing the “z” coordinate of the (x,y) point on the dem.

Points = projectOnRasterVect(dem, Points, interp = 'bilinear') Does the same as the previous function but also operates on 2D arrays. All the calculation are vectorized to avoid loops. Two interpolation methods are available, ‘nearest’ or ‘bilinear’

Prepare Line:

AvaProfile, projSplitPoint = prepareLine(dem, AvaPath, distance=10, Point=None) takes a “dem” dictionary, a “AvaPath” dictionary (x, y coordinates), a re-sampling distance and a “Point” dictionary in input and returns the “AvaProfile” dictionary corresponding to the “AvaPath” dictionary. That is to say the “line” dictionary re-sampled according to distance with the corresponding “z” argument representing the “z” coordinate of the re-sampled (x,y) point on the dem and the curvilinear coordinate “s” along the line (the first point of the line has a s=0). It also returns the projection of the Point on the AvaProfile if this one was supplied in input.

Project on Profile:

projSplitPoint = findSplitPoint(AvaProfile, splitPoint) takes a “AvaProfile” dictionary and a “splitPoint” dictionary in input and returns the “projSplitPoint” dictionary which is the projection of “splitPoint” on the “AvaProfile”.

Check Profile:

projSplitPoint, AvaProfile = checkProfile(AvaProfile, projSplitPoint=None) takes a “AvaProfile” dictionary and a “projSplitPoint” dictionary in input and check if the Profile goes from top to bottom, reverts it if necessary and returns the correct “projSplitPoint” and “AvaProfile” dictionaries.

Prepare inputs for find angle in profile:

angle, tmp, deltaInd =prepareAngleProfile(beta, AvaProfile) takes a angle value in degres and an Avalanche profile in input, computes the angle of the profile and returns this angle, the list of indexes tmp where the angle is under the input angle value and deltaInd the number of consecutive indexes required.

Find angle in profile:

idsAnglePoint =findAngleProfile(tmp, deltaInd) takes the outputs of prepareAngleProfile as inputs and returns the index of the desired angle as output.

Bresenham Algorithm:

z = bresenfindCellsCrossedByLineBresenhamham(x0, y0, x1, y1, cs) takes a two (x,y) points and a cell size in input and returns the z = (x,y) list of the cells hit by the line between the two input points.

Path to domain:

rasterTransfo = path2domain(xyPath, rasterTransfo) takes the (x,y) coordinates of a polyline, a domain width and a cell size (in rasterTransfo) in input and returns the domain of width w along the polyline.

Polygon to mask:

mask = poly2mask_simple(ydep, xdep, ncols, nrows) takes the (x,y) coordinates of a polygon and a rater size in input and returns the raster mask corresponding to the polygon.

In polygon:

IN = inpolygon(X, Y, xv, yv) takes the (X, Y) coordinates of points and xv, yv foot print of a polygon on a raster in input and returns the raster mask corresponding to the polygon.

Generate Topography

Generate DEM files for idealised/generic topographies that can be used as required DEM input data for snow avalanche simulations.

The following topography types can be chosen:

  • flat plane (FP)

  • inclined plane of constant slope (IP)

  • parabola - using a parabola to describe the sloping plane that then transitions into a flat foreland (PF)

  • hockey stick - using an linearly sloping plane with smoothed transition to the flat foreland (HS)

  • bowl-shaped topography (BL)

  • helix-shaped topography (HX)

  • pyramid-shaped topography (PY)

On top of these topographies, channels can be introduced (then set channel=True), and these channels can also be set to become narrower along the channel and wider at the end of the channel (then set narrowing=True). There is the option to introduce these channels by either adding a ‘channel layer’ (max thickness=channel depth) on top of the topography (topoAdd=True) or by cutting them into the original topography (topoAdd=False). In case of the parabola topography also a Dam can be added by setting dam=True.

Input

  • in generateTopoCfg.ini all required input parameters are listed (does include default values for all parameters)

Output

  • 3D surface plot of generated topography as .png file and possibly shown to screen (see flags)

  • .asc file of DEM data

To run

  • copy generateTopoCfg.ini to local_generateTopoCfg.ini and set desired parameter values (if not, the default values are used)

  • in Avaframe/ run:

    python3 runGenerateTopo.py
    

Theory

Topographies are generated using inclined and flat planes, parabolas, spheres and circles. Channels are introduced as half-sphere shaped features with smooth transition from no channel to channel using cumulative distribution functions.

Configuration parameters

In the case of the pyramid-shaped topography, the domain extent is defined by the max elevation (z0 - elevation of the appex point) and the slope of the pyramid facets (meanAlpha)

Domain parameters:

dx

DEM spatial resolution [m]

xEnd

total horizontal extent of the domain [m]

yEnd

total horizontal extent of the domain [m]

Topography parameters:

flens

distance to point where slope transitions into flat plane [m]

meanAlpha

slope angle from max. elevation to start flat plane [°] - or slope of inclined plane [°]

C

total fall height [m]

rBowl

bowl radius [m]

rHelix

radius for helix [m]

z0

max elevation [m]

zElev

elevation of flat plane [m]

rCirc

radius of smoothing circle [m]

demType

topography types (FP, IP, PF, HS, BL, HX, PY - explanation given in the introductory description**

flatx

extent of flat foreland for pyramid in x

flaty

extent of flat foreland for pyramid in y

phi

rotation angle for pyramid

Flags for channels and plotting:

channel

True - introduce channel; False - no channel

narrowing

True - channel is wide at start and end and narrow in the middle part; False - channel is uniform

topoAdd

True - add channel layer; False: cut channel into original topography;

flagRot

True - rotate pyramid along z-axis

Channel parameters:

cRadius

standard channel radius

cInit

start and end half width of channel that is narrower in the middle part

cff

standard deviation sigma

cMustart

mean mu - represents upper part of the channel

cMuend

mean mu - represents lower part of the channel

Get Release Area

Generate a release area for a topography created with generateTopo , this function is available for the following topographies:

  • flat plane (FP)

  • inclined plane (IP)

  • parabola (PF)

  • hockey stick (HS)

The release areas are defined as rectangular features build by four corner points, which are based on the following conditions:

  • prescribed vertical stretch of 200 m (difference in altitude)

  • prescribed volume of the release area

  • lower margin is located where the slope angle falls below 30°

  • if slope does not fall below 30 °, upper margin is located xStart away from upper margin of the DEM

Input

  • in getReleaseAreaCfg.ini and generateTopoCfg.ini all required input parameters are listed (does include default values for all parameters)

Output

  • release area as shapefile, .nxyz and .txt file

  • if showplot flag is True, plot of release area on domain extent

To run

Following this steps, you can generate an avalanche test case including a DEM and a simple realease area.

  • copy generateTopoCfg and getReleaseAreaCfg to local_generateTopoCfg.ini and local_getReleaseAreaCfg.ini and set desired parameter values (if not, the default values are used)

  • in avaframe run:

    python3 runGenProjTopoRelease.py
    

Parameters:

hr

release area vertical stretch [m]

vol

volume of snow in release area [m3]

dh

release snow thickness [m]

xStart

upper margin of release area distance in x from origin [m]

lenP

number of release area polygon points

showPlot

True - show plot of release area

outputtxt

True - copy the output to txt file

xExtent

horizontal extent of release area for flat plane

alphaStop

slope angle that defines lower margin of release area

relNo

number of release area for name

relName

name of release area feature in shapefile

Initialize Project

This function creates the folder structure required to perform avalanche simulations:

NameOfAvalanche/
        Inputs/
                ENT/            - entrainment areas
                LINES/          - avalanche paths
                POINTS/         - split points
                REL/            - release area scenario
                RES/            - resistance areas
                SECREL/ - secondary release areas
                .asc            - DEM
        Outputs/
        Work/

Input

  • path to NameOfAvalanche

This path is specified in the configuration file avaframeCfg.ini with the parameter avalancheDir.

Output

  • NameOfAvalanche directory

To run

  • copy avaframeCfg.ini to local_avaframeCfg.ini and set your desired avalanche directory name

  • in avaframe run:

    python3 runInitializeProject.py

fileHandlerUtils

fileHandlerUtils.py gathers useful functions to create directories, read log files, extract information from logs, fetch and export data and fetch simulation infos into a dictionnary that can be used within other functions.

Functions

makeADir:

makeADir(dirName) takes a path to directory and if this directory does not yet exist, creates the directory dirName.

readLogFile:

logDict = readLogFile(logname, cfg='') takes a log file and returns a dictionary with information on the simulations that have been performed.

extractParameterInfo:

parameterDict =  extractParameterInfo(avaDir, simName) reads the log saved when performing a simulation with com1DFA and returns a dictionary with info on the release mass, the final time step and the current mass.

getDFAData:

getDFAData exports and renames the simulation results to the Aimec work directory following the required naming conventions.

getRefData:

getRefData(avaDir, outputDir, suffix, nameDir='') takes the data from the benchmark directory and exports it to the specified ouputDir and optionally renames the data.

exportcom1DFAOutput:

exportcom1DFAOutput(avaDir, cfg='') exports the simulation results of com1DFA to the Outputs directory and renames the peak files to include information on additional parameters such as Mu or release thickness.

makeSimDict:

data =  makeSimDict(inputDir, varPar='', avaDir='') takes all the peak files (avalanche simulation results saved as .asc file) and creates a dictionary that contains information for each simulation, such as path to file, file name, release area scenario, simulation type, model type, parameter variation, result type, simulation name, cell Size and name of avalanche. This dictionary can be used in other functions to load or filter simulation results.