gfail.webpage

gfail.webpage.hazdev(maplayerlist, configs, shakemap, outfolder=None, alpha=0.7, shakethreshtype='pga', shakethresh=10.0, prefLS='Nowicki Jessee and others (2018)', prefLQ='Zhu and others (2017)', pop_file=None, defaultcolors=True, point=True, pager_alert='', eventsource='', eventsourcecode='', createpngs=True, gf_version=1, pdlcall=False)[source]

Create all files needed for product page creation Assumes gfail has been run already with -w flag

Parameters
  • maplayerlist (list) – List of model outputs from gfail.

  • configs (list) – List of dictionaries of config files corresponding to each model in maplayerlist and in the same order.

  • shakemap (str) – path to shakemap .xml file.

  • outfolder (str) – Location in which to save outputs. If None, will use current directory.

  • alpha (float) – Transparency to use for overlay pngs, value from 0 to 1.

  • shakethreshtype (str) – Type of ground motion to use for shakethresh, ‘pga’, ‘pgv’, or ‘mmi’.

  • shakethresh – Float or list of shaking thresholds in %g for pga, cm/s for pgv, float for mmi. Used for Hagg and Exposure computation.

  • prefLS (str) – shortref of “preferred” landslide model.

  • prefLQ (str) – shortref of “preferred” liquefaction model.

  • pop_file (str) – file path to population file used to compute population-based alert levels.

  • defaultcolors (bool) – If True, will use DFCOLORS for all layers instead of determining new ones. This will crash if any of the layers have a different number of bins than the number of DFCOLORS

  • point (bool) – if True, event is a point source and warning should be displayed

  • pager_alert (str) – PAGER alert level, e.g., ‘green’. ‘pending’, …

  • eventsource (str) – net id (e.g., ‘us’)

  • eventsourcecode (str) – event code (e.g. ‘123456pq’)

  • createpngs (bool) – if True, create pngs for web map

  • gf_version (int) – ground failure version

  • pdlcall (bool) – True if callgf was called by pdl automatically, false if called manually (or otherwise).

Returns

Files that need to be sent to comcat for hazdev to create the product
webpage including:
  • info.json

  • transparent png overlays of all models

gfail.webpage.create_png(event_dir, lsmodels=None, lqmodels=None, mercator=True, lsmask=0.002, lqmask=0.005, legends=False)[source]

Creates transparent PNG file for website.

Parameters
  • event_dir (srt) – Directory containing ground failure results.

  • lsmodels (list) – List of dictionaries of model summary info compiled by the hazdev function. If not specified, code will search for the hdf5 files for the preferred model and will create this dictionary and will apply default colorbars and bins.

  • lqmodels (list) – Same as above for liquefaction.

  • mercator (bool) – Project raster to web mercator

  • lsmask (float) – Mask all landslide cells with probabilities below this threshold

  • lqmask (float) – Mask all liquefaction cells with probabilities below this threshold

  • legends (bool) – if True, will produce png files of legends for each preferred model

Returns

.png map overlays and .json files specifying their mapped extents

gfail.webpage.create_info(event_dir, lsmodels, lqmodels, gf_version=1, eventsource='', eventsourcecode='', point=True, pdlcall=False)[source]

Create info.json for ground failure product.

Parameters
  • event_dir (srt) – Directory containing ground failure results.

  • lsmodels (list) – List of dictionaries of model summary info compiled by the hazdev function. If not specified, code will search for the hdf5 files for the preferred model and will create this dictionary and will apply default colorbars and bins.

  • lqmodels (list) – Same as above for liquefaction.

  • gf_version (int) – ground failure version

  • eventsource (str) – net id (e.g., ‘us’)

  • eventsourcecode (str) – event code (e.g. ‘123456pq’)

  • point (bool) – if True, event is a point source and warning should be displayed

  • pdlcall (bool) – True if callgf was called by pdl automatically

Returns

creates info.json for this event

gfail.webpage.fixfile(filename)[source]

Replace any Nan or Infinity values with null in info.json

Parameters

filename (str) – full path to info.json file

Returns: same file with invalid entries replaced with valid

gfail.webpage.make_legends(lqmin=0.005, lsmin=0.002, outfolder=None, orientation='horizontal', transparent=True)[source]

Make png file of legends to go with pngs using DFCOLORS and DFBINS

Parameters
  • lqmin (float) – minimum visible value of liquefaction probability

  • lsmin (float) – same as above for landslides

  • outfolder (str) – folder to place pngs of legends

  • orientation (str) – orientation of colorbar, ‘horizontal’ or ‘vertical’

  • transparent (bool) – if True, background will be transparent

Returns

(lsfilename, lqfilename), locations of files that were created.

Return type

tuple

gfail.webpage.create_kmz(maplayer, outfile, mask=None, levels=None, colorlist=None, qdict=None)[source]

Create kmz files of models

Parameters
  • maplayer (dict) –

    Dictionary of one model result formatted like:

    {
        'grid': mapio grid2D object,
        'label': 'label for colorbar and top line of subtitle',
        'type': 'output or input to model',
        'description': 'description for subtitle'
    }
    

  • outfile (str) – File extension

  • mask (float) – make all cells below this value transparent

  • levels (array) – list of bin edges for each color, must be same length

  • colorlist (array) – list of colors for each bin, should be length one less than levels

  • qdict (dict) – dictionary of quantile grids

Returns

kmz file

gfail.webpage.get_zoomextent(grid, propofmax=0.3)[source]

Get the extent that contains all values with probabilities exceeding a threshold in order to determine ideal zoom level for interactive map If nothing is above the threshold, uses the full extent

Parameters
  • grid – grid2d of model output

  • propofmax (float) – Proportion of maximum that should be fully included within the bounds.

Returns

a dictionary with keys ‘xmin’, ‘xmax’, ‘ymin’, and

’ymax’ that defines the zoomed boundaries in geographic coordinates.

Return type

  • boundaries

gfail.webpage.make_rgba(grid2D, levels, colorlist, mask=None, mercator=False)[source]

Make an rgba (red, green, blue, alpha) grid out of raw data values and provide extent and limits needed to save as an image file

Parameters
  • grid2D – Mapio Grid2D object of result to mape

  • levels (list) – list of bin edges for each color, must be same length

  • colorlist (list) – list of colors for each bin, should be length one less than levels

  • mask (float) – mask all values below this value

  • mercator (bool) – project to web mercator (needed for leaflet, not for kmz)

Returns

(rgba_img, extent, lmin, lmax, cmap), where:
  • rgba_img: rgba (red green blue alpha) image

  • extent: list of outside corners of image,

    [minlat, maxlat, minlon, maxlon]

  • lmin: lowest bin edge

  • lmax: highest bin edge

  • cmap: colormap corresponding to image

Return type

tuple

gfail.webpage.make_legend(levels, colorlist, filename=None, orientation='horizontal', title=None, transparent=False)[source]

Make legend file

Parameters
  • levels (list) – list of bin edges for each color, must be same length

  • colorlist (list) – list of colors for each bin, should be length one less than levels

  • filename (str) – File extension of legend file

  • orientation (str) – orientation of colorbar, ‘horizontal’ or ‘vertical’

  • title (str) – title of legend (usually units)

  • transparent (bool) – if True, background will be transparent

Returns

figure of legend

gfail.webpage.setupcolors(sync, plotorder, lims, colormaps, defaultcolormap=<matplotlib.colors.LinearSegmentedColormap object>, logscale=None, alpha=None)[source]

Get colors that will be used for all colorbars from reference grid

Parameters
  • sync (str) – If False, will exit program, else corresponds to the shortref of the model which should serve as the template for the colorbars used by all other models. All other models must have the exact same number of bins

  • plotorder (list) – List of keys of shortrefs of the grids that will be plotted.

  • lims

    Nx1 list of tuples or numpy arrays corresponding to plotorder defining the bin edges to use for each model. Example: .. code-block:: python

    [(0., 0.1, 0.2, 0.3), np.linspace(0., 1.5, 15)]

  • colormaps (list) – List of strings of matplotlib colormaps (e.g. cm.autumn_r) corresponding to plotorder

  • defaultcolormap (matplotlib colormap) – Colormap to use if colormaps is not defined. default cm.CMRmap_r

  • logscale – If not None, then a list of booleans corresponding to plotorder stating whether to use log scaling in determining colors

  • alpha – list of transparencies

Returns

(sync, colorlist, lim1) where:
  • sync (bool): whether or not colorbars are/can be synced

  • colorlist (list): list of rgba colors that will be applied to all

    models regardless of bin edge values

  • lim1 (array): bin edges of model to which others are synced

Return type

tuple