GeoHexViz Utils Package

The utils package contains all of the utility functions used by GeoHexViz.

File Util Module

This module contains functions for the running of plot properties files. This module is used by the GeoHexSimple script (geohexviz/simple.py).

geohexviz.utils.file.run_file(filepath: str, strict: bool = False, debug: bool = False)[source]

Runs a file that represents plot properties.

Accepted: YAML, JSON

Parameters
  • filepath (str) – The filepath containing the plot properties

  • strict (bool) – Whether to handle strict events or not

  • debug (bool) – Whether to handle informational events or not

Returns

The status of the final plot

Return type

PlotStatus

geohexviz.utils.file.run_json(filepath: str, strict: bool = False, debug: bool = False)[source]

Runs a JSON representation of plot properties.

Parameters
  • filepath (str) – The path to the JSON file

  • strict (bool) – Whether to handle strict events or not

  • debug (bool) – Whether to handle informational events or not

Returns

The status of the final plot

Return type

PlotStatus

geohexviz.utils.file.run_yaml(filepath: str, strict: bool = False, debug: bool = False)[source]

Runs a YAML representation of plot properties.

Parameters
  • filepath (str) – The path to the YAML file

  • strict (bool) – Whether to handle strict events or not

  • debug (bool) – Whether to handle informational events or not

Returns

The status of the final plot

Return type

PlotStatus

Geo Util Module

This module contains all of the functions that GeoHexViz utilizes to do geospatial processing.

geohexviz.utils.geoutils.add_geometry(row) Polygon[source]

Returns a Polygon of the hex id in the same row.

This function returns a Polygon representing the boundaries defined by the hex cell in the given row.

Parameters
  • row – A row in the dataframe

  • hex_field_id

Returns

A polygon built from a hex id

Return type

Polygon

geohexviz.utils.geoutils.apply_bin_function(hex_gdf: DataFrame, binning_field: str, binning_fn: Callable, binning_args=None, result_name: Optional[str] = None, **binning_kw)[source]

Applies a function to a grouped dataframe (intended for hex use).

Parameters
  • hex_gdf (DataFrame) – The dataframe to perform the function on

  • binning_field (str) – The column within the dataframe to apply the function on

  • binning_fn (Callable) – The function to apply

  • binning_args (Iterable) – Arguments for the function

  • result_name (str) – The name of the column that contains the result

  • binning_kw (**kwargs) – Keyword arguments for the function

geohexviz.utils.geoutils.bin_by_hexid(hex_gdf: Union[DataFrame, GeoDataFrame], binning_field: Optional[str] = None, binning_fn: Optional[Callable] = None, binning_args=None, hex_field: Optional[str] = None, result_name: str = 'value_field', add_geoms: bool = False, loss_method: bool = True, **binning_kw)[source]

Bins a DataFrame by hex cell ids.

This function assumes the dataframe has a VALID hex and geometry columns. Using these columns the data is grouped into what hexagon on the grid they fall into.

Parameters
  • hex_gdf (GeoDataFrame) – A dataframe representing any kind of hex data

  • binning_field (str) – The column that the data will be grouped by

  • binning_fn (Callable) – The function to perform after grouping

  • binning_args (*args) – Arguments for the binning function

  • hex_field (str) – The location of the hex ids in the dataframe (None->index)

  • result_name (str) – The name of the column that contains the grouped result after having the function applied

  • add_geoms (bool) – Whether to add hex geometries after grouping or not

  • loss_method (bool) – Whether or not to use a method that is quicker but provides a loss of data (columns)

Returns

A frame containing the binned hex grid and its geometries

Return type

GeoDataFrame

geohexviz.utils.geoutils.check_crossing(lon1: float, lon2: float, validate: bool = True)[source]

Assuming a minimum travel distance between two provided longitude coordinates, checks if the 180th meridian (antimeridian) is crossed.

geohexviz.utils.geoutils.conform_geogeometry(gdf: GeoDataFrame, d3_geo: bool = True, fix_polys: bool = True) GeoDataFrame[source]

Fixes the winding order and antimeridian crossings for geometries in a GeoDataFrame.

Parameters
  • gdf (GeoDataFrame) – The geodataframe to conform

  • d3_geo (bool) – Whether to orient the polygons clockwise or counter-clockwise

  • fix_polys (bool) – Whether to fix antimeridian crossings or not

Returns

The conformed geodataframe

Return type

GeoDataFrame

geohexviz.utils.geoutils.conform_polygon(poly: Union[Polygon, MultiPolygon], rfc7946: bool = True, fix_poly: bool = True) Union[Polygon, MultiPolygon][source]

Conforms the given polygon to the given standard.

Parameters
  • poly (Polygon) – The polygon to conform

  • rfc7946 (bool) – The conform standard (True->Clockwise,False->Counterclockwise)

  • fix_poly (bool) – Whether or not to fix the polygons if they cross the anti-meridian (by shifting)

Returns

The conformed Polygon

Return type

Polygon

geohexviz.utils.geoutils.convert_crs(left: GeoDataFrame, right: GeoDataFrame, crs: Any = 'EPSG:4326')[source]

Converts two GeoDataFrames to the same crs.

Parameters
  • left (GeoDataFrame) – The left dataframe

  • right (GeoDataFrame) – The right dataframe

  • crs (Any) – The crs that the two dataframes will be converted to

geohexviz.utils.geoutils.convert_dataframe_geometry_to_geodataframe(df: DataFrame, geometry_field: str = 'geometry') GeoDataFrame[source]

Converts the given dataframe into a GeoDataFrame based on pre-existing geometry.

This function converts the given dataframe into a GeoDataFrame based on a pre-existing geometry column in the dataframe.

Parameters
  • df (DataFrame) – Any dataframe with a pre-existing geometry column

  • geometry_field (str) – The column that contains geometry

Returns

A geodataframe of the given dataframe

Return type

GeoDataFrame

geohexviz.utils.geoutils.find_geoms_within_collection(gc, collapse: bool = False) set[source]

Finds the geometry types within a collection of geometries.

Parameters
  • gc – The collection of geometries

  • collapse (bool) – Whether or not to collapse Multi geometries into their sub counterparts

Returns

The geometry types found

Return type

set

geohexviz.utils.geoutils.generate_grid_over(gdf: GeoDataFrame, hex_resolution: int) GeoDataFrame[source]

This function generates a hexagonal grid around a dataframe (a box).

Parameters
  • gdf (GeoDataFrame) – The dataframe to generate a hex-box around

  • hex_resolution (int) – The resolution to use for the grid

Returns

The resulting grid box

Return type

GeoDataFrame

geohexviz.utils.geoutils.get_present_geomtypes(gdf: GeoDataFrame, allow_collections: bool = True, collapse_geoms: bool = False) set[source]

Obtains a set of unique geometry types within a geodataframe.

Parameters
  • gdf (GeoDataFrame) – The geodataframe to find geometry types of

  • allow_collections (bool) – Whether or not to parse GeometryCollections for their types

  • collapse_geoms (bool) – Whether or not to collapse Multi geometries into their sub geometries

Returns

The unique set of geometries within the geodataframe

Return type

set

geohexviz.utils.geoutils.gpdclip(clip: GeoDataFrame, to: GeoDataFrame, enforce_crs: Any = 'EPSG:4326', keep_geom_type: bool = True)[source]

Clips a GeoDataFrame to another via GeoPandas clip function.

The operation first converts the two dataframes to the same crs.

Parameters
  • clip (GeoDataFrame) – The dataframe that is being clipped to the other dataframes boundary

  • to (GeoDataFrame) – The dataframe that is acting like the boundary for the clipping

  • enforce_crs (Any) – The crs to enforce before clipping

  • keep_geom_type (bool) – Passed into geopandas clip function

Returns

The clipped dataframe

Return type

GeoDataFrame

geohexviz.utils.geoutils.hexify_dataframe(gdf: GeoDataFrame, hex_resolution: int, add_geom: bool = False, keep_geom: bool = False, old_geom_name: Optional[str] = None, as_index: bool = True, raise_errors: bool = False) GeoDataFrame[source]

Makes a new GeoDataFrame, with the index set as the hex cell ids that each geometry in the geometry column corresponds to.

Parameters
  • gdf (GeoDataFrame) – The GeoDataFrame to place a hex cell id overlay on

  • hex_resolution (int) – The resolution of the hexes to be generated

  • add_geom (bool) – Whether to add the hex geometry to the dataframe or not

  • keep_geom (bool) – Whether to keep old geometry or not (add_geom=True)

  • old_geom_name (str) – The name of the column to store the old geometry in (add_geom=True, keep_geom=True)

  • as_index (bool) – Whether to make the hex column the index or not

  • raise_errors (bool) – Whether to raise errors related to empty geometry or not

Returns

A GeoDataFrame with a hex id index

Return type

GeoDataFrame

geohexviz.utils.geoutils.hexify_geometry(gdf: Union[DataFrame, GeoDataFrame], hex_col: Optional[str] = None, keep_geoms: bool = False, old_geom_name: Optional[str] = None) GeoDataFrame[source]

Adds the geometry of the hex ids in the given column or index.

Parameters
  • gdf (GeoDataFrame) – The GeoDataFrame containing the hex ids

  • hex_col (str) – The column containing hex ids (None->index)

  • keep_geoms (bool) – Whether or not to keep old geometry

  • old_geom_name (str) – The name for the column containing old geometry (keep_geoms=True)

Returns

A GeoDataFrame with hex ids and their geometries

Return type

GeoDataFrame

geohexviz.utils.geoutils.merge_datasets_simple(*args, merge_op: ~typing.Callable = <built-in function add>, common_columns: ~typing.Optional[~typing.List[str]] = None, keep_columns: ~typing.Optional[~typing.List[str]] = None, drop: bool = True, crs: ~typing.Optional[str] = None, result_name: ~typing.Optional[str] = None, errors: str = 'ignore') GeoDataFrame[source]

Merges the datasets with the given merge operation.

Parameters
  • args (*args: List[Union[GeoDataFrame, Tuple[str, GeoDataFrame]]]) – The datasets to merge

  • merge_op (Callable) – The merge operation to perform on the datasets

  • keep_columns (List[str]) – Additional columns to keep

  • common_columns (List[str]) – Columns that ALL dataframes share in common

  • drop (bool) – Whether to drop unnecessary columns or not

  • crs (Optional[str]) – The crs of the new dataframe

  • result_name (Optional[str]) – The name of the resulting column within the dataframe

  • errors (str) – The parameter determining errors to be thrown

Returns

A merged dataframe

Return type

GeoDataFrame

geohexviz.utils.geoutils.pointify_geodataframe(gdf: GeoDataFrame, keep_geoms: bool = True, raise_errors: bool = True) GeoDataFrame[source]

Makes a new GeoDataFrame, with the geometry all being of Point type, and the index representing the original row in the dataframe.

Parameters
  • gdf (GeoDataFrame) – The GeoDataFrame to convert the geometries of

  • keep_geoms (bool) – Whether to keep the original geometries in the dataframe or not

  • raise_errors (bool) – Errors are raised by pandas when the dataframe has no geometry, throw or not

Returns

A GeoDataFrame with a point-only geometry

Return type

GeoDataFrame

geohexviz.utils.geoutils.remove_other_geometries(gdf: GeoDataFrame, geom_type: str) GeoDataFrame[source]

Removes unwanted geometry from the GeoDataFrame.

Parameters
  • gdf (GeoDataFrame) – The GeoDataFrame to remove from

  • geom_type (str) – The geometry type that is to be kept

Returns

The GeoDataFrame without any other geometries

Return type

GeoDataFrame

geohexviz.utils.geoutils.simple_geojson(gdf: GeoDataFrame, value_field: Optional[str] = None, id_field: Optional[str] = None, file_output: Optional[str] = None) FeatureCollection[source]

Provides a GeoJSON representation of a GeoDataFrame.

Only works on GeoDataFrames with id, value, and geometry columns.

Parameters
  • gdf (GeoDataFrame) – The geodataframe to make a GeoJSON of

  • value_field (str) – The value column of the dataframe

  • id_field (Optional[str]) – An id field to use for the GeoJSON

  • file_output (Optional[str]) – Filepath for file output

Returns

A GeoJSON-like representation of the geodataframe

Return type

FeatureCollection

geohexviz.utils.geoutils.sjoinclip(clip: GeoDataFrame, to: GeoDataFrame, operation: str = 'intersects', enforce_crs: Any = 'EPSG:4326') GeoDataFrame[source]

Clips a GeoDataFrame to another via GeoPandas spatial join operations.

The operation first converts the two GeoDataFrames to the same crs.

Parameters
  • clip (GeoDataFrame) – The dataframe that is being clipped to the other dataframes boundary

  • to (GeoDataFrame) – The dataframe that is acting like the boundary for the clipping

  • operation (str) – The operation to be performed in the spatial join

  • enforce_crs (Any) – The crs to enforce before clipping

Returns

The clipped dataframe

Return type

GeoDataFrame

geohexviz.utils.geoutils.unify_geodataframe(gdf: GeoDataFrame) GeoDataFrame[source]

Unifies the geometries in a GeoDataFrame into a new GeoDataFrame.

Parameters

gdf (GeoDataFrame) – The input dataframe

Plot Util Module

This module contains all of the functions that GeoHexViz uses to modify the properties of its internal plot and layers.

geohexviz.utils.plot_util.format_html_exp10(exp: float, exp_type: str) str[source]

Formats a exponent to the power of 10 in html form.

geohexviz.utils.plot_util.format_latex_exp10(exp: float, exp_type: str) str[source]

Formats a exponent to the power of 10 in latex form.

geohexviz.utils.plot_util.format_raw_exp10(exp: float, exp_type: str) str[source]

Formats a exponent to the power of 10 in raw form.

geohexviz.utils.plot_util.get_shapes_from_world(name: Optional[str] = None) GeoDataFrame[source]

Retrieves a continent or country from the world, or the whole world.

This function uses GeoPandas naturalearth_lowres dataset. If the given name is None, the function will retrieve the shapes of thw entire world.

Parameters

name (str) – The name of the continent or country to get the shapes for

Returns

The dataframe containing the geometry of the country, continent, or world

Return type

GeoDataFrame

geohexviz.utils.plot_util.gpd_clip(clip: GeoDataFrame, to: List[GeoDataFrame], validate: bool = True)[source]

Plot wrapper for the geopandas clip operation.

Parameters
  • clip (GeoDataFrame) – The data to clip

  • to (List[GeoDataFrame]) – The list of data to act as the clip

  • validate (bool) – Whether to validate the result or not (throws)

Returns

The result of the clip

Return type

GeoDataFrame

geohexviz.utils.plot_util.logify_info(values: Union[Sequence[float], Set[float]], text_type: str = 'raw', exp_type: Optional[str] = None, fill_last: bool = True, include_min: bool = False, include_max: bool = False, minmax_rounding: int = 3, include_predecessors: bool = False, min_prefix: str = '', min_suffix: str = '', max_prefix: str = '', max_suffix: str = '') Dict[str, Any][source]

Retrieves a dictionary of information for a log scale.

entries: scale-min -> The minimum value on the scale scale-max -> The maximum value on the scale original-values -> The values given logged-values -> The values after having log10 performed on them scale-dict -> The scale values and their text

Parameters
  • values (Union[Sequence[float], Set[float]]) – The values to compute a log scale for

  • text_type (Optional[str]) – Determines how to format the tick text, (latex, html, raw)

  • exp_type (Optional[str]) – What type of exponent to select (None, E, ^, *, r)

  • fill_last (bool) – Whether to extend the last segment of the log scale to the next highest power or not

  • include_min (bool) – Whether to include a value-text pair for the minimum value

  • include_max (bool) – Whether to include a value-text pair for the maximum value

  • minmax_rounding (int) – The number of decimals to round the min and max values to

  • include_predecessors (bool) – Whether to include all previous exponents in the scale values or not

  • min_prefix (str) – Prefix for the minimum value-text pair

  • min_suffix (str) – Suffix for the minimum value-text pair

  • max_prefix (str) – Prefix for the maximum value-text pair

  • max_suffix (str) – Suffix for the maximum value-text pair

Returns

A dictionary of the above information

Return type

dict

geohexviz.utils.plot_util.logify_info_dep(values: Union[Sequence[float], Set[float]], text_type: str = 'raw', exp_type: Optional[str] = None, fill_first: bool = True, fill_last: bool = True, include_min: bool = False, include_max: bool = False, minmax_rounding: int = 6, min_prefix: str = '', min_suffix: str = '', max_prefix: str = '', max_suffix: str = '') Dict[str, Any][source]

Retrieves a dictionary of information for a log scale.

DEPRECATED

entries: scale-min -> The minimum value on the scale scale-max -> The maximum value on the scale original-values -> The values given logged-values -> The values after having log10 performed on them scale-vals -> The scale values scale-text -> The text for each scale values

Parameters
  • values (Union[Sequence[float], Set[float]]) – The values to compute a log scale for

  • text_type (Optional[str]) – Determines how to format the tick text, (latex, html, raw)

  • exp_type (Optional[str]) – What type of exponent to select (None, E, ^, *, r)

  • fill_first (bool) – Whether to extend the first segment of the log scale to the next lowest power or not

  • fill_last (bool) – Whether to extend the last segment of the log scale to the next highest power or not

  • include_min (bool) – Whether to include a value-text pair for the minimum value

  • include_max (bool) – Whether to include a value-text pair for the maximum value

  • minmax_rounding (int) – The number of decimals to round the min and max values to

  • min_prefix (str) – Prefix for the minimum value-text pair

  • min_suffix (str) – Suffix for the minimum value-text pair

  • max_prefix (str) – Prefix for the maximum value-text pair

  • max_suffix (str) – Suffix for the maximum value-text pair

Returns

A dictionary of the above information

Return type

dict

geohexviz.utils.plot_util.logify_scale(df: DataFrame, **kwargs) Dict[str, Any][source]

Converts a manager into log scale form.

Parameters
  • df (DataFrame) – The dataframe that contains the values for the scale

  • kwargs (**kwargs) – Keyword arguments to be passed into logify_info

geohexviz.utils.plot_util.logify_scale_dep(df: DataFrame, **kwargs) Dict[str, Any][source]

Converts a manager into log scale form.

DEPRECATED

Parameters
  • df (DataFrame) – The dataframe that contains the values for the scale

  • kwargs (**kwargs) – Keyword arguments to be passed into logify_info

geohexviz.utils.plot_util.opacify_colorscale(dataset: dict, alpha: Optional[float] = None)[source]

Plot wrapper for adjusting the opacity of a colorscale.

Parameters
  • dataset (dict) – The dataset whose colorscale to adjust

  • alpha (float) – The alpha to adjust by (if not, then the alpha within the dataset is used)

geohexviz.utils.plot_util.sjoin_clip(clip: GeoDataFrame, to: List[GeoDataFrame], operation: str = 'intersects', validate: bool = False) GeoDataFrame[source]

Plot wrapper for the spatial join clip operation.

Parameters
  • clip (GeoDataFrame) – The data to clip

  • to (List[GeoDataFrame]) – The list of data to act as the clip

  • operation (str) – The operation to be performed in the spatial join

  • validate (bool) – Whether to validate the result or not (throws)

Returns

The result of the clip

Return type

GeoDataFrame

General Util Module

This module contains other utility functions used by GeoHexViz.

geohexviz.utils.util.dict_deep_update(d: dict, u: dict) object[source]

Updates a dict without changing nested dicts that may be present.

Parameters
  • d (dict) – The dict to update

  • u (dict) – The updating dict

geohexviz.utils.util.fix_filepath(filepath: str, add_filename: str = '', add_ext: str = '') str[source]

Converts a directorypath, or filepath into a valid filepath.

Parameters
  • filepath (str) – The filepath to convert

  • add_filename (str) – The filename to add if there is none

  • add_ext (str) – The extension to add if there is a filename

Returns

The converted filepath

Return type

str

geohexviz.utils.util.get_best(*args, **kwargs) object[source]

Gets the best option from a list of labels.

see get_sorted_best()

Parameters
  • args (*args) – Arguments to be passed into the get_sorted_best() function

  • kwargs (**kwargs) – Keywords to be passed into the get_sorted_best() function

Returns

The best option in the list

Return type

object

geohexviz.utils.util.get_occurrences(lst: list, **kwargs) list[source]

Retrieves a list of tuples containing the list item and its frequency in the list.

Parameters
  • lst (list) – The list to count frequencies from

  • kwargs (**kwargs) – Keyword arguments for the sorted function

Returns

The list of item frequency pairs

Return type

list

geohexviz.utils.util.get_sorted_best(lst: list, allow_ties: bool = True, join_ties: bool = True, selector: Optional[Iterable] = None, reverse: bool = True) object[source]

Retrieves the best entry or entries from a list of labels based on occurrences.

Parameters
  • lst (list) – The list of labels to parse the best or worst option from

  • allow_ties (bool) – Whether to allow ties between labels or not

  • join_ties (bool) – Whether to join the labels of the tie if present or not

  • selector (Iterable) – If multiple items are tied, this determines the order of which they will be selected as the best

  • reverse (bool) – Whether to reverse the list or not (reversed=best, !reversed=worst)

Returns

The best or worst option from the list

Return type

object

geohexviz.utils.util.get_worst(*args, **kwargs) object[source]

Gets the worst option from a list of labels.

see get_sorted_best()

Parameters
  • args (*args) – Arguments to be passed into the get_sorted_best() function

  • kwargs (**kwargs) – Keywords to be passed into the get_sorted_best() function

Returns

The worst option in the list

Return type

object

Colour Scale Util Module

This module contains all of the functions that are dedicated to generating valid colour scales for Plotly.

geohexviz.utils.colorscales.discretize(colors: List[str], size_portion: float = 0, center_portion: float = 0, fix_bound: bool = True, fix_extension: bool = True) List[Tuple[float, str]][source]

Takes a single sequential colorscale and gets it’s discrete form.

Parameters
  • colors (List[str]) – The list of colors on the colors

  • size_portion (float) – The amount of space each discrete section will occupy on the colors (decimal-percentage)

  • center_portion (float) – The amount of space that the center will take up on the colors (decimal-percentage)

  • fix_bound (bool) – Determines if a color is fixed if it goes over the top of the colors

  • fix_extension (bool) – Determines if the last color should reach the end of the colors if no more colors available

Returns

The discrete colorscale

Return type

List[Tuple[float, str]]

geohexviz.utils.colorscales.discretize2(colors: List[str], size_portion: float = 0, center_portion: float = 0.0, size_low: float = 0.0, size_high: float = 1.0, fix_bound: bool = True, fix_extension: bool = True) _DScale[source]

Takes a single sequential colorscale and gets it’s discrete form.

Parameters
  • colors (List[str]) – The list of colors on the colors

  • size_portion (float) – The amount of space each discrete section will occupy on the colors (decimal-percentage)

  • fix_bound (bool) – Determines if a color is fixed if it goes over the top of the colors

  • fix_extension (bool) – Determines if the last color should reach the end of the colors if no more colors available

Returns

The discrete colorscale

Return type

List[Tuple[float, str]]

geohexviz.utils.colorscales.discretize_cscale(colorscale, scale_type: str, low: float, high: float, **kwargs)[source]

Transforms a normal colorscale into a discrete colorscale.

Parameters
  • colorscale (Any) – The colorscale to be converted

  • scale_type (str) – The type of colorscale (sequential, diverging)

  • low (float) – The minimum value on the colors

  • high (float) – The maximum value on the colors

  • kwargs (**kwargs) – Keyword arguments for the discrete functions

Returns

The discretized colorscale

Return type

Any

geohexviz.utils.colorscales.discretize_diverging(colors: List[str], low: float, high: float, discrete_size: float = 1.0, remove_middle: bool = True, high_shading: bool = True, center: Optional[float] = None, center_hue: Optional[int] = None, choose_left_hues: Union[List[int], int] = 1, choose_right_hues: Union[List[int], int] = 1, choose_left_luminance: float = 0.0, choose_right_luminance: float = 0.0, choose_luminance: float = 0.0) List[Tuple[float, str]][source]

Transforms a diverging scale into a discrete diverging scale.

It should be noted that luminance parameters only work if the scale is in RGB format. THIS FEATURE IS HIGHLY EXPERIMENTAL.

Parameters
  • colors (List[str]) – The list of colors on the scale

  • low (float) – The minimum value on the scale

  • high (float) – The maximum value on the scale

  • discrete_size (float) – The amount of space each discrete bin takes on the colorscale

  • remove_middle (bool) – Whether to remove the center of the diverging scale or not

  • high_shading (bool) – Whether to use hues closer to the ends of the scale or not

  • center (float) – The position of the center on the scale

  • center_hue (int) – Where the center hue is in the list of colors given

  • choose_left_hues (Union[List[int], int]) – The list of color positions to use on the left of the scale or an integer skip for color selection on the left

  • choose_right_hues (Union[List[int], int]) – The list of color positions to use on the right of the scale or an integer skip for color selection on the right

  • choose_left_luminance (float) – Choose colors for the left side under the maximum luminance

  • choose_right_luminance (float) – Choose colors for the right side under the maximum luminance

  • choose_luminance (float) – Choose colors for the both sides of the scale under the maximum luminance

Returns

The discretized diverging colorscale

Return type

Any

geohexviz.utils.colorscales.discretize_sequential(colors: List[str], low: float, high: float, discrete_size: float = 1.0, choose_hues: Union[List[int], int] = 1, choose_luminance: float = 0.0) List[Tuple[float, str]][source]

Makes a sequential colors discrete based on min, max on the colors.

choose_luminance does not work with colors that are not in rgb format.

Parameters
  • colors (List[str]) – The list of colors on the colors

  • low (float) – The minimum numerical value on the colors (not percentage)

  • high (float) – The maximum numerical value on the colors (not percentage)

  • discrete_size (float) – The numerical amount that each discrete bar will occupy (not percentage)

  • choose_hues (Union[List[int],int]) – Determines the step used in selecting colors from the colors, or the list of color positions that are used

  • choose_luminance (float) – The maximum luminance of the colors to be selected

Returns

The discrete sequential colors

Return type

List[Tuple[float, str]]

geohexviz.utils.colorscales.get_cscale_format(colorscale) str[source]

Retrieves the format of a colorscale.

Parameters

colorscale (Any) – The colorscale to get the format of

Returns

The format of the colorscale (string, iterable, nested iterable, unknown)

Return type

str

geohexviz.utils.colorscales.solid_scale(color: str, min_scale: float = 0.0, max_scale: float = 1.0) Tuple[source]

Retrieves a solid colorscale for a given color.

Parameters
  • color (ColorTuple) – The color to make a solid colors from

  • min_scale (number) – The minimum value on this colorscale

  • max_scale (number) – The maximum value on this colorscale

Returns

A solid colorscale

Return type

Tuple[Tuple[number, str]]