pyincore_viz

geoutil

class geoutil.GeoUtil

Utility methods for Geospatial Visualization

static calc_center_from_bbox(bbox)

Calculate center point location from given bounding box.

Parameters:

bbox (list) – Geodata bounding box with [min_lat, min_lon, max_lat, max_lon].

Returns:

A latitude of center location in the bounding box. float: A longitude of center location in the bounding box.

Return type:

float

static convert_bound_to_ipylft_format(bbox)

Convert conventional geodata’s bounding box to ipyleaflet bounding box format.

Parameters:

bbox (list) – Geodata bounding box with [min_lat, min_lon, max_lat, max_lon].

Returns:

A bounding box coordinates, [[south, east], [north, west]].

Return type:

list

static create_choro_data_from_pd(pd, key)

Create choropleth’s choro-data from dataframe.

Parameters:
  • pd (object) – an Input dataframe.

  • key (str) – a string for dictionary key

Returns:

A dictionary of dataframe

Return type:

obj

static create_data_img_url_from_geotiff_for_ipyleaflet(input_path)

Creates boundary list from raster dataset file.

Parameters:

input_path (str) – An input raster dataset (GeoTiff) file path.

Returns:

Data for the png data converted from GeoTiff.

Return type:

str

static create_geodata_from_geodataframe(gdf, name)

Create map window using dataset list. Should be okay whether it is shapefile or geotiff.

Parameters:
  • gdf (obj) – A geopandas geodataframe.

  • name (str) – A name of the gdf.

Returns:

An ipyleaflet GeoData.

Return type:

obj

static get_gdf_map(datasets: list)

Get ipyleaflet map with list of datasets with geopandas.

Parameters:

datasets (list) – a list of pyincore Dataset objects.

Returns:

An ipyleaflet Map.

Return type:

obj

static get_gdf_wms_map(datasets, wms_datasets, wms_url=pyincore_viz.globals.INCORE_GEOSERVER_WMS_URL)

Get a map with WMS layers from list of datasets for geopandas and list of datasets for WMS.

Parameters:
  • datasets (list) – A list of pyincore dataset objects.

  • wms_datasets (list) – A list of pyincore dataset objects for wms layers.

  • wms_url (str) – URL of WMS server.

Returns:

An ipyleaflet Map.

Return type:

obj

static get_ipyleaflet_heatmap(locations=None, radius=10, blur=10, max=1, name='')

Creates ipyleaflet map object and fit the map using the bounding box information.

Parameters:
  • locations (list) – A list of center locations with values.

  • radius (float) – A radius of each “point” of the heatmap.

  • blur (float) – Amount of blur.

  • max (float) – A maximum point intensity.

  • name (str) – A name that represents the layer.

Returns:

An ipyleaflet map.

Return type:

obj

static get_ipyleaflet_map(bbox=None)

Creates ipyleaflet map object and fit the map using the bounding box information.

Parameters:

bbox (list) – Geodata bounding box.

Returns:

An ipyleaflet map.

Return type:

obj

static get_ipyleaflet_map_with_center_location(cen_lon, cen_lat, zoom_level)

Creates ipyleaflet map object and fit the map using the center point location and zoom level.

Parameters:
  • cen_lon (float) – Longitude of map’s center location.

  • cen_lat (float) – Latitude of map’s center location.

  • zoom_level (int) – An initial zoom level of the map.

Returns:

An ipyleaflet map.

Return type:

obj

static get_network_graph(filename, is_directed=False)

Get network graph from filename.

Parameters:
  • filename (str) – A name of a geo dataset resource recognized by Fiona package.

  • is_directed (bool) – Graph type. True for directed Graph, False default for Graph.

Returns:

Graph. dict: Node coordinates.

Return type:

obj

static get_raster_boundary(input_path)

Creates boundary list from raster dataset file.

Parameters:

input_path (str) – An input raster dataset (GeoTiff) file path.

Returns:

A list of boundary values.

Return type:

list

static get_wms_map(datasets: list, wms_url=pyincore_viz.globals.INCORE_GEOSERVER_WMS_URL, layer_check=False)

Get a map with WMS layers from list of datasets.

Parameters:
  • datasets (list) – list of pyincore Dataset objects.

  • wms_url (str) – URL of WMS server.

  • layer_check (bool) – boolean for checking the layer availability in wms server.

Returns:

An ipyleaflet Map.

Return type:

obj

static join_datasets(geodataset, dataset)

Join Geospatial Dataset and non-geospatial Dataset.

Parameters:
  • geodataset (obj) – pyincore dataset with geospatial data.

  • dataset (obj) – pyincore dataset without geospatial data.

Returns:

Geopandas DataFrame object.

Return type:

GeoDataFrame

static join_table_dataset_with_source_dataset(dataset, client)

Creates geopandas dataframe by joining table dataset and its source dataset.

Parameters:
  • dataset (obj) – pyincore dataset.

  • client (obj) – pyincore service client.

Returns:

Geopandas geodataframe object.

Return type:

obj

static map_raster_overlay_from_file(input_path)

Creates map window with geo-referenced raster file from local or url visualized.

Parameters:

input_path (str) – An input raster dataset (GeoTiff) file path.

Returns:

ipyleaflet Map object.

Return type:

obj

static merge_bbox(bbox1, bbox2)

Merge bbox to create bigger bbox to contain both bbox.

Parameters:
  • bbox1 (list) – [min_lat, min_lon, max_lat, max_lon].

  • bbox2 (list) – [min_lat, min_lon, max_lat, max_lon].

Returns:

merged bbox [min_lat, min_lon, max_lat, max_lon].

Return type:

list

static merge_table_dataset_with_field(dataset_list: list, column=<class 'str'>, in_source_dataset_id=None)

Creates pandas dataframe with all dataset in the list joined with guid and column.

Parameters:
  • dataset_list (list) – list of table dataset.

  • column (str) – column name to be plot.

  • in_source_dataset_id (str) – source dataset id, default is None.

Returns:

Pandas dataframe with all dataset joined together with guid. list: A list of dataset id. list: A list of dataset title. str: A common source dataset id from datasets.

Return type:

obj

static overlay_gdf_with_raster_hazard(gdf, column, raster, category=False, basemap=True, source={'attribution': '(C) OpenStreetMap contributors', 'html_attribution': '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors', 'max_zoom': 19, 'name': 'OpenStreetMap.Mapnik', 'url': 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'})

Overlay Geopandas DataFrame with raster dataset such as earthquake or flood.

Parameters:
  • gdf (obj) – Geopandas DataFrame object.

  • column (obj) – A column name of gdf to be plot.

  • raster (str) – A raster hazard dataset id to overlay, such as tif or png dataset

  • category (bool) – Turn on/off category option.

  • basemap (bool) – Turn on/off base map (e.g. openstreetmap).

  • source (obj) – source of the Map to be used. examples, ctx.providers.OpenStreetMap.Mapnik (default), ctx.providers.Stamen.Terrain, ctx.providers.CartoDB.Positron etc.

static plot_choropleth_multiple_dataset(dataset_list, field_list, zoom_level=10)

Make choropleth map using multiple dataset.

Parameters:
  • dataset_list (list) – A list of dataset to be mapped

  • field_list (list) – A list of fields in the dataset. The order of the list should be matched with the order of dataset list

  • zoom_level (int) – Zoom level

Returns:

An ipyleaflet map.

Return type:

obj

static plot_choropleth_multiple_fields_from_single_dataset(dataset, field_list)

Make choropleth map using multiple fields from single dataset.

Parameters:
  • dataset (list) – A dataset to be mapped

  • field_list (list) – A list of fields in the dataset

Returns:

An ipyleaflet map.

Return type:

obj

static plot_earthquake(earthquake_id, client, demand=None)

Plot earthquake raster data.

Parameters:
  • earthquake_id (str) – ID of tornado hazard.

  • client (obj) – pyincore service Client Object.

  • demand (str) – A demand type, only applicable to dataset based earthquakes that can have one raster for each demand. e.g. PGA, PGV, 0.2 sec SA.

static plot_gdf_map(gdf, column, category=False, basemap=True, source={'attribution': '(C) OpenStreetMap contributors', 'html_attribution': '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors', 'max_zoom': 19, 'name': 'OpenStreetMap.Mapnik', 'url': 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'})

Plot Geopandas DataFrame.

Parameters:
  • gdf (obj) – Geopandas DataFrame object.

  • column (str) – A column name to be plot.

  • category (bool) – Turn on/off category option.

  • basemap (bool) – Turn on/off base map (e.g. openstreetmap).

  • source (obj) – source of the Map to be used. examples, ctx.providers.OpenStreetMap.Mapnik (default), ctx.providers.Stamen.Terrain, ctx.providers.CartoDB.Positron etc.

static plot_graph_network(graph, coords)

Plot graph.

Parameters:
  • graph (obj) – A nx graph to be drawn.

  • coords (dict) – Position coordinates.

static plot_heatmap(dataset, fld_name, radius=10, blur=10, max=1, multiplier=1, name='')

Creates ipyleaflet map object and fit the map using the bounding box information.

Parameters:
  • dataset (obj) – A dataset to be mapped.

  • fld_name (str) – A column name to be plot in heat map.

  • radius (float) – Radius of each “point” of the heatmap.

  • blur (float) – Amount of blur.

  • max (float) – Maximum point intensity.

  • multiplier (float) – A multiplication factor for making fld value to more clearly in the map.

  • name (str) – name that represents the layer.

Returns:

An ipyleaflet map.

Return type:

obj

static plot_heatmap_from_gdf(gdf, fld_name, radius=10, blur=10, max=1, multiplier=1, name='')

Creates ipyleaflet map object and fit the map using the bounding box information.

Parameters:
  • gdf (GeoDataFrame) – GeoPandas geodataframe.

  • fld_name (str) – column name to be plot in heat map.

  • radius (float) – Radius of each “point” of the heatmap.

  • blur (float) – Amount of blur.

  • max (float) – Maximum point intensity.

  • multiplier (float) – A multiplication factor for making fld value to more clearly in the map.

  • name (str) – A name that represents the layer.

Returns:

An ipyleaflet map.

Return type:

obj

static plot_join_map(geodataset, dataset, column, category=False, basemap=True, source={'attribution': '(C) OpenStreetMap contributors', 'html_attribution': '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors', 'max_zoom': 19, 'name': 'OpenStreetMap.Mapnik', 'url': 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'})

Plot a map from geospatial dataset and non-geospatial dataset.

Parameters:
  • geodataset (obj) – pyincore Dataset object with geospatial data.

  • dataset (obj) – pyincore Dataset object without geospatial data.

  • column (str) – Column name to be plotted.

  • category (bool) – turn on/off category option.

  • basemap (bool) – turn on/off base map (e.g. openstreetmap).

  • source (obj) – source of the Map to be used. examples, ctx.providers.OpenStreetMap.Mapnik (default), ctx.providers.Stamen.Terrain, ctx.providers.CartoDB.Positron etc.

static plot_local_earthquake(eq_dataset)

Plot local earthquake data on the map

static plot_local_flood(flood_dataset)

Plot local tsunami data on the map

Parameters:

tsu_dataset (obj) – pyincore TsunamiDataset object

Returns:

none

static plot_local_hazard(dataset)

Plot hazard dataset on the map

Parameters:

dataset (obj) – pyincore HazardDataset object

Returns:

none

static plot_local_hurricane(hur_dataset)

Plot local hurricane data on the map

Parameters:

hur_dataset (obj) – pyincore HurricaneDataset object

Returns:

none

static plot_local_tornado(tornado, id_field)

Plot local tornado data on the map

Parameters:
  • tornado (obj) – pyincore TornadoDataset object

  • id_field (str) – id field name

static plot_local_tsunami(tsu_dataset)

Plot local tsunami data on the map

Parameters:

tsu_dataset (obj) – pyincore TsunamiDataset object

Returns:

none

static plot_map(dataset, column, category=False, basemap=True, source={'attribution': '(C) OpenStreetMap contributors', 'html_attribution': '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors', 'max_zoom': 19, 'name': 'OpenStreetMap.Mapnik', 'url': 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'})

Plot a map of geospatial dataset.

Parameters:
  • dataset (obj) – pyincore Dataset object with geospatial data.

  • column (str) – column name to be plot.

  • category (bool) – turn on/off category option.

  • basemap (bool) – turn on/off base map (e.g. openstreetmap).

  • source (obj) – source of the Map to be used. examples, ctx.providers.OpenStreetMap.Mapnik (default), ctx.providers.Stamen.Terrain, ctx.providers.OpenTopoMap.attribution, ctx.providers.CartoDB.Positron etc.

static plot_maps_dataset_list(dataset_list, client, column='guid', category=False, basemap=True)

Create map window using dataset list. Should be okay whether it is shapefile or geotiff.

Parameters:
  • dataset_list (list) – A list of dataset to be mapped.

  • column (str) – A column name to be plot.

  • client (obj) – pyincore service Client.

  • category (bool) – turn on/off category option.

  • basemap (bool) – turn on/off base map (e.g. openstreetmap).

Returns:

An ipyleaflet Map.

Return type:

obj

static plot_multiple_vector_dataset(dataset_list)

Plot multiple vector datasets on the same map.

Parameters:

dataset_list (list) – A list of datasets

Returns:

An ipyleaflet map.

Return type:

obj

static plot_network_dataset(network_dataset: NetworkDataset)

Creates map window with Network Dataset visualized.

Parameters:

network_dataset (obj) – pyincore Network Dataset.

Returns:

An ipyleaflet Map object, GeoUtil.map (ipyleaflet.Map).

Return type:

obj

static plot_raster_dataset(dataset_id, client)

Plot raster data.

Parameters:
  • dataset_id (str) – ID of tornado hazard.

  • client (obj) – pyincore service Client Object.

static plot_raster_file_with_legend(file_path, title=None)

Plot raster file using matplotlib.

Parameters:
  • file_path (str) – A file path for the raster data.

  • title (str) – A title for the plot.

plot_raster_from_path()

Creates map window with geo-referenced raster file from local or url visualized.

Parameters:

input_path (str) – An input raster dataset (GeoTiff) file path.

Returns:

An ipyleaflet Map, GeoUtil.map (ipyleaflet.Map).

Return type:

obj

Deprecated since version 1.2.0: use map_raster_overlay_from_file instead

static plot_table_dataset(dataset, client, column=<class 'str'>, category=False, basemap=True, source={'attribution': '(C) OpenStreetMap contributors', 'html_attribution': '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors', 'max_zoom': 19, 'name': 'OpenStreetMap.Mapnik', 'url': 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'})

Creates map window with table dataset.

Parameters:
  • dataset (obj) – pyincore dataset.

  • client (obj) – pyincore service.

  • column (str) – column name to be plot.

  • category (bool) – turn on/off category option.

  • basemap (bool) – turn on/off base map (e.g. openstreetmap).

  • source (obj) – source of the Map to be used. examples, ctx.providers.OpenStreetMap.Mapnik (default), ctx.providers.Stamen.Terrain, ctx.providers.CartoDB.Positron etc.

static plot_table_dataset_list_from_single_source(client, dataset_list, column, in_source_dataset_id=None)

Creates map window with a list of table dataset and source dataset.

Parameters:
  • client (obj) – pyincore service Client Object.

  • dataset_list (list) – list of table dataset.

  • column (str) – column name to be plot.

  • in_source_dataset_id (str) – source dataset id, the default is None.

Returns:

An ipyleaflet Map, GeoUtil.map (ipyleaflet.Map).

Return type:

obj

static plot_tornado(tornado_id, client, category=False, basemap=True, source={'attribution': '(C) OpenStreetMap contributors', 'html_attribution': '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors', 'max_zoom': 19, 'name': 'OpenStreetMap.Mapnik', 'url': 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'})

Plot a tornado path.

Parameters:
  • tornado_id (str) – ID of tornado hazard.

  • client (obj) – pyincore service Client Object.

  • category (bool) – turn on/off category option.

  • basemap (bool) – turn on/off base map (e.g. openstreetmap).

  • source (obj) – source of the Map to be used. examples, ctx.providers.OpenStreetMap.Mapnik (default), ctx.providers.Stamen.Terrain, ctx.providers.CartoDB.Positron etc.

static random_color(feature)

Creates random color for ipyleaflet map feature

Parameters:

feature (obj) – geodataframe feature

Returns:

dictionary for color

Return type:

obj

plotutil

class plotutil.PlotUtil

Plotting utility.

static dmg_state2value(damage_result, dmg_ratio_tbl)

Damage state to value.

Parameters:
  • damage_result (str) – A damage result value.

  • dmg_ratio_tbl (dict) – A damage ratio table.

Returns:

static get_fragility_plot(fragility_set, title=None, dimension=2, limit_state='LS_0', custom_curve_parameters={}, **kwargs)

Get fragility plot.

Parameters:
  • fragility_set (obj) – A JSON like description of fragility assigned to the infrastructure inventory.

  • title (str) – A title of the plot.

  • dimension (int) – 2d versus 3d.

  • limit_state (str) – A limit state name, such as LS_0, or insignific, etc.

  • custom_curve_parameters (dict) – Custom fragility curve parameters. If you wish to overwrite default curve parameters (expression field).

  • **kwargs – Keyword arguments.

Returns:

Plot and its style functions.

Return type:

obj

static get_fragility_plot_2d(fragility_set, title=None, custom_curve_parameters={}, **kwargs)

Get 2d refactored fragility plot.

Parameters:
  • fragility_set (obj) – A JSON like description of fragility assigned to the infrastructure inventory.

  • title (str) – A title of the plot.

  • custom_curve_parameters (dict) – Custom fragility curve parameters. If you wish to overwrite default curve parameters (expression field).

  • **kwargs – Keyword arguments.

Returns:

Matplotlib pyplot object.

Return type:

obj

static get_fragility_plot_3d(fragility_set, title=None, limit_state='LS_0', custom_curve_parameters={}, **kwargs)

Get 3d refactored fragility plot.

Parameters:
  • fragility_set (obj) – A JSON like description of fragility assigned to the infrastructure inventory.

  • title (str) – A title of the plot.

  • limit_state (str) – A limit state name, such as LS_0, or insignific, etc.

  • custom_curve_parameters (dict) – Custom fragility curve parameters. If you wish to overwrite default curve parameters (expression field).

  • **kwargs – Keyword arguments.

Returns:

Matplotlib pyplot object.

Return type:

obj

get_standard_x_y(alpha: float, beta: float)

Get arrays of x and y values for standard fragility or period standard fragility.

Parameters:
  • disttype (str) – A distribution type (log normal and normal).

  • alpha (float) – A distribution parameter (mostly mean).

  • beta (float) – A distribution parameter (mostly standard deviation).

Returns:

X sampling values. ndarray: Y cumulative density values.

Return type:

ndarray

Deprecated since version 1.8.0: It is not being used anymore. Check get_x_y or get_x_y_z

static get_x_y(curve, demand_type_name, curve_parameters, custom_curve_parameters, start=0.001, end=10, sample_size: int = 200)

Get arrays of x and y values for plotting refactored fragility curves.

Parameters:
  • curve (obj) – An individual fragility curve object.

  • demand_type_name (str) – Demand type name

  • curve_parameters (list) – Default fragility curve parameters.

  • start (float) – A start value.

  • end (float) – An end value.

  • sample_size (int) – Number of points.

  • **custom_curve_parameters – Keyword arguments.

Returns:

X sampling values. ndarray: Y cumulative density values.

Return type:

ndarray

static get_x_y_z(curve, demand_type_names, curve_parameters, custom_curve_parameters, start=1, end=50, sample_interval: int = 0.5)

Get arrays of x, y and z values for plotting refactored fragility plots.

Parameters:
  • curve (obj) – An individual fragility curve object.

  • demand_type_names (dict) – Valid demand type names.

  • curve_parameters (list) – Default fragility curve parameters.

  • **custom_curve_parameters – Keyword arguments.

  • start (float) – A start value.

  • end (float) – An end value.

  • sample_interval (float) – Sample interval.

Returns:

X sampling values. ndarray: Y sampling values. ndarray: Z cumulative density values.

Return type:

ndarray

static histogram_from_csv_with_column(plot_title, x_title, y_title, column, in_csv, num_bins, figure_size)

Get histogram from csv with column.

Parameters:
  • plot_title (str) – A title of the plot.

  • x_title (str) – A title of the X axis.

  • y_title (str) – A title of the Y axis.

  • column (str) – A name of the column.

  • in_csv (obj) – A csv file with the column to be plotted.

  • num_bins (int) – Number of histogram bins.

  • figure_size (list) – Figure size, x and y.

Returns:

Figure with damage histograms.

Return type:

obj

static inventory_to_geodataframe(inventory_dataset)

Convert inventory_dataset to GeoDataFrame.

Parameters:

inventory_dataset (obj) – An inventory dataset.

Returns:

Inventory.

Return type:

GeoDataFrame

Deprecated since version 1.9.0: It is not being used anymore. Check pyincore’s Dataset.get_dataframe_from_shapefile

static mean_damage_histogram(mean_damage_dataset, histogram_bins=20, figure_size=(10, 5), axes_font_size=12, title_font_size=12)

Figure with mean damage histogram.

Parameters:
  • mean_damage_dataset (obj) – Mean damage dataset.

  • histogram_bins (int) – Number of bins.

  • figure_size (list) – Figure size, x and y.

  • axes_font_size (int) – Axle font size.

  • title_font_size (int) – Title font size.

Returns:

Figure with damage histograms.

Return type:

obj

static merge_inventory_w_dmg(inventory_df, damage_result)

Merge inventory with damages.

Parameters:
  • inventory_df (df) – A Panda’s Data frame inventory.

  • damage_result (df) – A Panda’s Data frame damage results.

Returns:

Inventory.

Return type:

DataFrame

static remove_null_inventories(inventory_df, key='guid')

Remove null inventory.

Parameters:
  • inventory_df (df) – An inventory DataFrame.

  • key (str) – A key such as “guid”.

Returns:

Inventory.

Return type:

DataFrame

tabledatasetlistmap

class tabledatasetlistmap.TableDatasetListMap

Mapping class for visualizing list of Table Dataset

create_basemap_ipylft(geo_dataframe, title_list)

Creates map window with given inventory with multiple table dataset file using folder location.

Parameters:
  • geo_dataframe (obj) – Geopandas DataFrame.

  • title_list (list) – A list of the file names in the folder.

Returns:

ipyleaflet map.

Return type:

obj

create_choropleth_layer(key)

add choropleth layer to map.

Parameters:

key (str) – A selected value from tablemap’s layer selection drop down menu.

Returns:

create_map_widgets(title_list, map, inventory_df)

Create and add map widgets into map.

Parameters:

title_list (list) – A list of the file names in the folder.

Returns:

on_button_clicked(b)

A button click action for map.

Parameters:

b (action) – A button click action for tablemap.

Returns:

analysisviz

class analysisviz.AnalysisViz

Methods for visualizing analysis.

static visualize(dataset, **kwargs)

Base visualize method that dynamically imports the necessary modules.

Parameters:

dataset (obj) – pyincore dataset without geospatial data.

Returns:

None