Reference manual

GenMR.environment module

GenMR Virtual Environment Generator

This module defines the environmental layers and objects used in the GenMR digital template. Environmental layers are implemented as classes, and associated environmental objects are defined as classes or methods.

Planned Additions (v1.1.2)

  • Atmosphere

  • Power grid

  • Population

Author:

Arnaud Mignan, Mignan Risk Analytics GmbH

Version:

0.1

Date:

2025-10-27

License:

AGPL-3

class GenMR.environment.EnvLayer_natLand(soil, par)

Bases: object

Defines an environmental layer for the (natural) land classification: water, forest, grassland

class GenMR.environment.EnvLayer_soil(topo, par)

Bases: object

Defines an environmental layer for the soil

property FS_state
property FS_value

Return the factor of safety

property wetness
class GenMR.environment.EnvLayer_topo(src, par)

Bases: object

Defines an environmental layer for the topography on a coarser grid before interpolating back to default. The state variable is the altitude z(x,y). Derived variables include slope and aspect. Other characteristics include the coastline coordinates

Returns:

… default resolution [m]

algo_diamondsquare(i, roughness, sig, rng)

Generate a fractal topography following the Diamond-Square algorithm

i: iteration integer, determines size of final matrix roughness: 0 < < 1, equivalent to 1-H with H: Hurst exponent with Dfractal = 3-H m: initial square matrix of size 2^i+1 sig: standard deviation for random deviations

property aspect
property coastline_coord
model_cs_compoundbevel()
model_fr_diamondsquare()
model_rv_dampedsine()
model_th_ellipsoid()
model_vo_cone()
property river_coord

Call the function calc_coord_river_dampedsine()

Parameters:

Self

Returns:

property slope
class GenMR.environment.EnvLayer_urbLand(natLand, par)

Bases: object

Generate a city for land use state classification. Model that combines the SLEUTH city growth CA, the road network growth CA of ref, and the land use state transformation method of …

property bldg_roofpitch
property bldg_type
property bldg_value
calc_Pr_urbanise(slope, par)
get_S_urban(built, built_type)
get_d4mkd(ic, jc, i_test, j_test)
get_state_built(state0, neighbor_k, neighbor_d, m_kd)
property infiltration
property roadNet_coord
transform_landUse()
class GenMR.environment.EnvObj_roadNetwork(topo, land, par)

Bases: object

Generate a road network based on the CA described in …

class GenMR.environment.RasterGrid(par)

Bases: object

Define the coordinates (x,y) of the square-pixels of a 2D raster grid.

Notes

If x0, xbuffer, ybuffer and/or lat_deg are not provided by the user, they are fixed to xmin, 0, 0 and 45, respectively.

Parameters:
  • par (dict) – Input, dictionary with keys [‘w’, ‘xmin’, ‘x0’ (opt.), ‘xmax’, ‘ymin’, ‘ymax’, ‘xbuffer’ (opt.), ‘ybuffer’ (opt.)]

  • w (float) – Pixel width in km

  • xmin (float) – Minimum abcissa of buffer box

  • xmax (float) – Maximum abcissa of buffer box

  • ymin (float) – Minimum ordinate of buffer box

  • ymax (float) – Maximum ordinate of buffer box

  • xbuffer (float) – Buffer width in the x direction (default is 0.)

  • ybuffer (float) – Buffer width in the y direction (default is 0.)

  • lat_deg (float) – Latitude at center of the grid (default is 45.)

  • x0 (float) – Abscissa of reference N-S coastline (default is xmin)

  • x (ndarray(dtype=float, ndim=1)) – 1D array of unique abscissas

  • y (ndarray(dtype=float, ndim=1)) – 1D array of unique ordinates

  • xx (ndarray(dtype=float, ndim=2)) – 2D array of grid abscissas

  • yy (ndarray(dtype=float, ndim=2)) – 2D array of grid ordinates

  • nx (int) – Length of x

  • ny (int) – Length of y

Returns:

A new instance of class RasterGrid

Return type:

class instance

Example

Create a grid

>>> grid = RasterGrid({'w': 1, 'xmin': 0, 'xmax': 2, 'ymin': 0, 'ymax': 3})
>>> grid.x
array([0., 1., 2.])
>>> grid.y
array([0., 1., 2., 3.])
>>> grid.xx
array([[0., 0., 0., 0.],
   [1., 1., 1., 1.],
   [2., 2., 2., 2.]])
>>> grid.yy
array([[0., 1., 2., 3.],
   [0., 1., 2., 3.],
   [0., 1., 2., 3.]])
class GenMR.environment.Src(par, grid)

Bases: object

Define the characteristics of the peril sources.

Parameters:

par (dict) – A dictionary with nested keys [‘perils’, ‘EQ’[‘x’, ‘y’, ‘w_km’, ‘dip_deg’, ‘z_km’, ‘mec’, ‘bin_km’], ‘FF’[‘riv_A_km’, ‘riv_lbd’, ‘riv_ome’, ‘riv_y0’, ‘Q_m3/s’, ‘A_km2’], ‘VE’[‘x’, ‘y’]]

property EQ_char

Calls the function get_char_srcLine(self, par) if EQ source provided, otherwise returns error message.

Parameters:

self

Returns:

list of arrays (if EQ source defined)

[0] (ndarray(dtype=float, ndim=1)): 1D array of src_xi (for all points) [1] (ndarray(dtype=float, ndim=1)): 1D array of src_yi (for all points) [2] (ndarray(dtype=float, ndim=1)): 1D array of src_id (for all points) [3] (ndarray(dtype=float, ndim=1)): 1D array of src_L (for all faults) [4] (ndarray(dtype=float, ndim=1)): 1D array of seg_id (for all points) [5] (ndarray(dtype=float, ndim=1)): 1D array of seg_strike (for all fault segments) [6] (ndarray(dtype=float, ndim=1)): 1D array of seg_L (for all fault segments)

Return type:

list

get_char_srcLine(par)

Calculate the coordinates of fault sources based on their extrema and the provided resolution , as well as lenghts and strikes of faults and fault segments.

Parameters:

par (dict) – A dictionary with keys [‘x’, ‘y’, ‘w_km’, ‘dip_deg’, ‘z_km’, ‘mec’, ‘bin_km’]

Returns:

1D array of src_xi (for all points) ndarray(dtype=float, ndim=1): 1D array of src_yi (for all points) ndarray(dtype=float, ndim=1): 1D array of src_id (for all points) ndarray(dtype=float, ndim=1): 1D array of src_L (for all faults) ndarray(dtype=float, ndim=1): 1D array of seg_id (for all points) ndarray(dtype=float, ndim=1): 1D array of seg_strike (for all fault segments) ndarray(dtype=float, ndim=1): 1D array of seg_L (for all fault segments)

Return type:

ndarray(dtype=float, ndim=1)

GenMR.environment.calc_FS(slope, h, w, par)

Calculates the factor of safety using Eq. 3 of Pack et al. (1998).

Reference:

Pack RT, Tarboton DG, Goodwin CN (1998), The SINMAP Approach to Terrain Stability Mapping. Proceedings of the 8th Congress of the International Association of Engineering Geology, Vancouver, BC, Canada, 21 September 1998

GenMR.environment.calc_coord_river_dampedsine(grid, par, z='')

Calculate the (x,y,z) coordinates of the river(s) defined from a damped sine wave.

GenMR.environment.calc_topo_attributes(z, w)
GenMR.environment.downscale_RasterGrid(grid, factor, appl='pooling')

Reduce the resolution of a RasterGrid grid for specific applications. appl = topo for topography generation (with outer layer) for later upscaling

= pooling for max- or mean-pooling

Parameters:

xxx

Returns:

GenMR.environment.plot_EnvLayer_attr(envLayer, attr, hillshading_z='', file_ext='-')

Plot the attribute of an environmental layer.

Note

The attr argument should be the string version of the variable name, e.g., z becomes ‘z’, slope becomes ‘slope’.

Parameters:
  • envLayer (class) – An instance of environmental layer class

  • attr (str) – The identifier of the attribute

  • hillshading_z (ndarray(dtype=float, ndim=2), optional) – The elevation grid array

  • file_ext (str, optional) – String representing the figure format (‘jpg’, ‘pdf’, etc., ‘-’ by default)

Returns:

A plot

GenMR.environment.plot_EnvLayers(envLayers, file_ext='-')

Plot the listed environmental layers for a maximum of 3 attributes/properties per layer.

Parameters:
  • envLayers (list) – The list of class instances of environmental layers

  • save_as (str, optional) – String representing the figure format (‘jpg’ or ‘pdf’, ‘-’ by default)

Returns:

A plot

GenMR.environment.plot_src(src, file_ext='-')

Plot peril sources in the spatial grid.

Parameters:
  • grid (class) – An instance of class RasterGrid

  • par (dict) – A dictionary with nested keys [‘perils’, ‘EQ’[‘x’, ‘y’, ‘w_km’, ‘dip_deg’, ‘z_km’, ‘mec’, ‘bin_km’], ‘FF’[‘riv_A_km’, ‘riv_lbd’, ‘riv_ome’, ‘riv_y0’, ‘Q_m3/s’, ‘A_km2’], ‘VE’[‘x’, ‘y’]]

  • file_ext (str, optional) – String representing the figure format (‘jpg’, ‘pdf’, etc., ‘-’ by default)

Returns:

A plot (saved in file if file_ext not ‘-‘)

GenMR.utils module

GenMR Utility Functions

This module provides miscellaneous utility functions for input/output management, computing, and plotting within the GenMR_Basic package. These functions support core GenMR workflows by streamlining data handling, computation, and visualisation tasks.

Author:

Arnaud Mignan, Mignan Risk Analytics GmbH

Version:

0.1

Date:

2025-10-27

License:

AGPL-3

GenMR.utils.add0s_iter(i)
GenMR.utils.cmap_peril(peril)
GenMR.utils.col_peril(peril)
GenMR.utils.col_state_h(h, h0)
GenMR.utils.flatten_list(nestedlist)

Return a flatten list from a nested list.

GenMR.utils.get_data(filename)

Return path to package data file.

GenMR.utils.get_neighborhood_ind(i, j, grid_shape, r_v, method='Moore')

Get the indices of the neighboring cells, depending on method and radius of vision

GenMR.utils.get_net_coord(net)
GenMR.utils.incrementing(xmin, xmax, xbin, method)

Return evenly spaced values within a given interval in linear or log space, or repeat xmax xbin times if method = ‘rep’.

GenMR.utils.init_io()

Initialise required I/O directories for GenMR. Creates the following directories if they do not already exist:

  • io/

  • figs/

  • figs/CellAut_steps/

  • movs/

GenMR.utils.load_json2dict(filename)
GenMR.utils.load_pickle2class(filename)
GenMR.utils.marker_peril(peril)

Return marker for given point source peril.

class GenMR.utils.norm_z(vmin=None, vmax=None, sealevel=0, col_val=0.2, clip=False)

Bases: Normalize

GenMR.utils.partitioning(IDs, w, n)

Return a 1D array of length n of IDs based on their weights w

GenMR.utils.pooling(m, f, method='max')

Return a downscaled matrix by applying pooling (min, mean or max) on a matrix.

GenMR.utils.save_class2pickle(data, filename='envLayer_tmpsave')

Save a class instance in a pickle file.

Parameters:
  • data (class) – A class instance

  • filename (str, optional) – The name of the pickle file

Returns:

A pickle file

GenMR.utils.save_dict2json(data, filename='par_tmpsave')

Save a dictionary in a json file.

Parameters:
  • data (dict) – A dictionary

  • filename (str, optional) – The name of the json file

Returns:

A json file