Two Nice Python Choices for Visualising Geospatial Variation
Heatmaps, also referred to as Density Maps, are information visualizations that show the spatial distribution of a variable throughout a geographic space. They are often nice instruments for visualising and figuring out traits, supporting decision-making, detecting outliers, and creating compelling visualisations for shows.
There are a number of mapping python libraries accessible, nonetheless, two extremely popular and simple to make use of libraries are Folium and Plotly Categorical.
Inside this text, we’ll see how we will use these two libraries to visualise acoustic compressional slowness information on the Norwegian Continental Shelf.
For this tutorial, we’ll begin with importing pandas, which might be used to load our information from a CSV file.
import pandas as pd
The dataset we’re utilizing for this tutorial is a mix of the next:
The Xeek Pressure 2020 Machine Studying lithology competitors dataset was used to derive a median acoustic compressional slowness (DTC) worth for the Shetland GroupData from the Norwegian Petroleum Directorate web site, which was used to offer the placement informationdf = pd.read_csv(‘xeek_force_2020_dtc_mapping.csv’)df
When the information has been loaded, we will name upon the dataframe with the next:
We will see that we have now 7 columns:
Effectively Title — Title of the WellDTC — Common acoustic compressional slowness for the Shetland GroupTemperature — Backside gap temperate for the wellWater Depth —Depth of seabed from sea levelCompletion 12 months — 12 months the effectively was completedLatitude — Latitude place of the effectively in decimal unitsLongitude — Longitude place of the effectively in decimal models
To start creating the heatmap with Plotly Categorical, we have to import the library into our pocket book like so:
import plotly_express as px
We then must create a brand new determine. That is executed by calling upon plotly categorical’s density_mapbox .
To create our map, we have to cross in a couple of parameters:
df — the title of the dataframe with the datalat — the title for the latitude columnlon — the title for the longitude columnz — the title of the column containing the information we wish to visualise on the heatmapcenter — the place the place the map might be centred upon. We will name upon the imply of the latitude and longitude columnszoom — the preliminary zoom degree of the map
The final two parameters mapbox_style and peak management the background mapping layer and the peak of the plot.
fig = px.density_mapbox(df, lat=’Latitude’, lon=’Longitude’,z=’DTC’, radius=20,heart=dict(lat=df.Latitude.imply(), lon=df.Longitude.imply()), zoom=4,mapbox_style=”open-street-map”, peak=900)fig.present()
Once we name upon fig.present() we get again the next map.
From this map, we will see that we have now greater values of DTC within the northern finish of the area, which may very well be attributable to a number of issues, together with decrease compaction or elevated shalieness.
The wonderful thing about the map generated by plotly categorical is that we will hover over the information and get the values for the plotted variable (DTC). That is executed routinely and doesn’t require further code to create a popup field.
To start utilizing Folium, we might want to import it; nonetheless, so as to generate heatmaps, we additionally must import the HeatMap plugin from folium.plugins.
import foliumfrom folium.plugins import HeatMap
As soon as Folium has been imported, we have to create a base map by calling upon folium.map() . Inside that class technique, we will cross in a number of arguments. For this instance, we’ll use the next:
location — The place the place the map might be centred uponzoom_start — The preliminary zoom degree of the mapcontrol_scale — Whether or not the dimensions controls are displayed on the map
If you wish to discover out extra in regards to the parameters for the map perform, then try the assistance documentation on the folium.map class.
m = folium.Map(location=[df_combined.Latitude.mean(), df_combined.Longitude.mean()], zoom_start=6, control_scale=True)
We subsequent must create the heatmap layer.
To do that, we first must convert the latitude, longitude and values to a listing, which might then be handed into the HeatMap name.
We will set a couple of parameters to stylise how the heatmap seems, such because the min and max opacity, the radius of the colouring from the information level, and extra.
map_values = df_combined[[‘Latitude’,’Longitude’,’DTC’]]
information = map_values.values.tolist()
hm = HeatMap(information,min_opacity=0.05, max_opacity=0.9, radius=25).add_to(m)
Once we name upon our map object, we will see the same sample to the one generated by plotly categorical.
Nonetheless, there are a few downsides to this map:
There isn’t a hover performance just like what we noticed above with Plotly Categorical. We might add markers, however it requires a number of strains of further code.
If you wish to see how to do that, try my article beneath.
The opposite difficulty is that there isn’t any color gradient bar to assist readers perceive the vary of colors. However this may be resolved by creating a color map dictionary, as mentioned within the following StackOverflow submit.
Heatmaps present a good way to visualise and determine traits throughout geographical areas and might simply be created utilizing two common Python libraries: Folium and Plotly Categorical. These two libraries are easy to make use of and can be utilized to map petrophysical and well-log properties throughout giant areas. From these maps, we will derive details about traits and variations throughout fields or areas.
Leave a Reply