Skip to main content

Geographical visualization

Project description

drawing

buy me caffeine

Geographical Visualization

Geomapviz is a package to visualize data on maps at different levels of granularity, aggregating at the specified geographical level, dissolving the polygons if needed. The maps can be static (using matplotlib) or interactive (using geoviews and holoviews).

It returns a single map or a panel of maps, useful to compare how different models are capturing the geographical patterns.

The average values are either returned raw or (auto) binned. You can change the face-colour (background) if you prefer light over a black background (I don't know if anyone would).

Installation

$ pip install geomapviz -U

Applications

Generate dummy data

Introducing correlation to the geo identifier of regions

import geomapviz as gm
import cmasher as cmr

# the greatest country in the world,
# first military and economic power in the Universe
shp_file = gm.load_be_shp()
geom_df = shp_file.copy()

# create correlation with the geo entities
feat_1 = np.repeat(np.log10(geom_df.INS.astype(int).values), 10)
feat_1 = (feat_1 - feat_1.min()) / (feat_1.max() - feat_1.min())
# dummy data
X = (np.repeat(geom_df.long.values, 10) - (geom_df.long.mean())) / geom_df.long.std()
Y = (np.repeat(geom_df.lat.values, 10) - (geom_df.lat.mean())) / geom_df.lat.std()

# dummy data
bel_df = pd.DataFrame({
    'geoid': np.repeat(geom_df.INS.values, 10),
    'truth': (1 - Y + X + Y**3) * np.exp(-(X**2 + Y**2)),
    'feat_2':  (1 - Y**3 + X**3 + Y**5) * np.exp(-(X**2 + Y**2)) + np.random.beta(.5, .5, size=len(feat_1)),
    'feat_3': (1 + Y*X+ Y**3) * np.exp(-(X**2 + Y**2)) + np.random.beta(.5, .5, size=len(feat_1)),
    'feat_4': feat_1 + np.random.beta(5, 2, size=len(feat_1))
}
)

bel_df = bel_df.merge(geom_df[['INS', 'borough', 'district']], left_on='geoid', right_on='INS')

Simple choropleth

f = gm.plot_on_map(df=bel_df, target='truth', geoid='INS', shp_file=shp_file,
                   figsize=(20, 6), cmap=cmr.iceburn, normalize=True, facecolor="black")

Simple choropleth and incertitude on the average

f = gm.plot_on_map(df=bel_df, target='truth', dissolve_on=None, distrib='gaussian',
                   plot_uncertainty=True, plot_weight=False,
                   autobin=False, n_bins=7, geoid='INS', weight=None, shp_file=shp_file,
                   figsize=(20, 6), cmap=cmr.iceburn, normalize=True, facecolor="black")

Simple choropleth with auto-binning

You can also choose the number of decimal in the legend.

f = gm.plot_on_map(df=bel_df, target='truth', plot_uncertainty=True,
                   autobin=True, n_bins=7, geoid='INS', weight=None, shp_file=shp_file,
                   figsize=(20, 6), cmap=cmr.iceburn, normalize=True, facecolor="black", nbr_of_dec=3)

Panel of choropleths with auto-binning and dissolve polygons

cols_pred = ['feat_2', 'feat_3', 'feat_4']
f = gm.facet_map(df=bel_df, target='truth', cols_to_plot=cols_pred, dissolve_on='borough',
                      autobin=True, n_bins=5, geoid='INS', shp_file=shp_file
                      figsize=(12, 12), ncols=2, normalize=False)

Interactive map

Using geoviews behind the scene, geomapviz generates an interactive map. You can have non-binned or auto-binned average values, etc.

f = gm.facet_map_interactive(df=bel_df, target='truth', cols_to_plot=None, predicted=None, dissolve_on=None,
                             autobin=True, n_bins=7, geoid='INS', weight=None, shp_file=shp_file, alpha=.8,
                             figsize=(400, 400), ncols=2, cmap=cmr.iceburn, normalize=False) #, tiles_src='Wikipedia')
f

Interactive panel

By passing column names , you will have an interactive panel chart with linked maps. You can change the source of the tiles if you want to, using the tiles_src argument.

cols_pred = ['feat_2', 'feat_3', 'feat_4']
f = gm.facet_map_interactive(df=bel_df, target='truth', cols_to_plot=cols_pred, predicted=None, dissolve_on=None,
                             autobin=True, n_bins=7, geoid='INS', weight=None, shp_file=shp_file,
                             figsize=(400, 400), ncols=2, cmap=None, normalize=False) #, tiles_src='Wikipedia')
f

Changes

0.4

  • Make Belgian shp available using load_be_shp
  • More decimal
  • User defined alpha for the interactive maps

0.3

  • Bound functions to the upper level

0.2

  • First version

0.1

  • First version

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

geomapviz-0.4.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

geomapviz-0.4-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

File details

Details for the file geomapviz-0.4.tar.gz.

File metadata

  • Download URL: geomapviz-0.4.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0.post20201207 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.7.9

File hashes

Hashes for geomapviz-0.4.tar.gz
Algorithm Hash digest
SHA256 4c06b81302d7b7cb89d511a3ad6e0f0088d21c47a292d13d16cf91979a8f1036
MD5 cd53466bb26248d632efff311e0a5a7e
BLAKE2b-256 862096236b23fb7dbdf223629365eab3c53662a3c218ec7eaa4774f78c72603a

See more details on using hashes here.

File details

Details for the file geomapviz-0.4-py3-none-any.whl.

File metadata

  • Download URL: geomapviz-0.4-py3-none-any.whl
  • Upload date:
  • Size: 21.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0.post20201207 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.7.9

File hashes

Hashes for geomapviz-0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3a110c5b63e17f010c9566fa70702c9e738e0539ba4e358a13150713aafd7266
MD5 e9ede8b8d8f83f624d1fe2f16044088b
BLAKE2b-256 2d995022d88a64da769e2d424ccecc91a9bc203e30959d3b592ea3ad9c0f78dc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page