GeostatsPy Python Package: Open-source Spatial Data Analytics and Geostatistics

Oct 21, 2022 | Data Science

![Documentation Status](https://readthedocs.org/projects/geostatspy/badge?version=latest)

Cite As:

Pyrcz, M.J., Jo. H., Kupenko, A., Liu, W., Gigliotti, A.E., Salomaki, T., and Santos, J., 2021, GeostatsPy Python Package: Open-source Spatial Data Analytics and Geostatistics, DOI: doi:10.5281/zenodo.13835444. ![DOI](https://zenodo.org/badge/139197285.svg)

Introduction

The GeostatsPy package is your gateway to spatial data analytics and geostatistics within the Python environment. Think of it as a specialized toolbox designed for geoscientists that brings powerful GSLIB (Geostatistical Library) functionalities directly into your Python scripts. Imagine wielding the precision of a scalpel in a surgical operation; GeostatsPy equips you to conduct your geostatistical analyses with utmost finesse.

Getting Started with GeostatsPy

To embark on your geospatial analysis journey with GeostatsPy, you’ll need to set up your environment correctly.

Minimum Setup Requirements

  • Python 3.7.10 (due to the dependency on the Numba package for code acceleration).

Installation

GeostatsPy is conveniently available on the Python Package Index (PyPI). Use the following command to install it:

pip install geostatspy

Dependencies

Several foundational packages are necessary for GeostatsPy to function seamlessly. These include:

  • numpy – for ndarrays
  • pandas – for DataFrames
  • numba – for numerical speedup
  • scipy – for fast nearest neighbor search
  • matplotlib.pyplot – for plotting
  • tqdm – for progress bars
  • statsmodels – for weighted statistics

Understanding GeostatsPy

Think of GeostatsPy as a GPS system for navigating complex spatial data landscapes. Just as a GPS provides you with the most efficient route to your destination, GeostatsPy provides access to geostatistical functions that enable the smooth operation of data workflows. For instance, it encompasses two core components:

  • geostatspy.geostats – contains rewritten GSLIB functions in Python, exposing key methods for variogram calculation, stochastic simulation, and more.
  • geostatspy.GSLIB – includes visualizations and allows interaction with the GSLIB executables.

Example: Declustering with GeostatsPy

Below is a simple Python example that demonstrates the declustering technique utilized within GeostatsPy. It may look a bit lengthy at first, but it represents a practical application. Consider it akin to engineering a bridge—although the structure might appear complex, each component plays a vital role in ensuring stability.

import geostatspy.GSLIB as GSLIB
import geostatspy.geostats as geostats
import matplotlib.pyplot as plt
import scipy.stats

# Create a 2D simulation
nx = 100; ny = 100; cell_size = 10
xmin = 0.0; ymin = 0.0;
xmax = xmin + nx * cell_size; ymax = ymin + ny * cell_size
seed = 74073  
range_max = 1800; range_min = 500; azimuth = 65  
vario = GSLIB.make_variogram(0.0, nst=1, it1=1, cc1=1.0, azi1=65, hmaj1=1800, hmin1=500) 
mean = 10.0; stdev = 2.0  
vmin = 4; vmax = 16; cmap = plt.cm.plasma

# Calculate a stochastic realization
sim = GSLIB.sgsim_uncond(1, nx, ny, cell_size, seed, vario, simulation) 
sim = GSLIB.affine(sim, mean, stdev) 

# Sample and decluster the data
samples_cluster = samples.drop([80, 79, 78, 73]) 
samples_cluster = samples_cluster.reset_index(drop=True)  
wts, cell_sizes, averages = geostats.declus(samples_cluster, X, Y, Realization) 
samples_cluster[wts] = wts  # add the weights to the sample data
 
# Visualizing results
plt.subplot(321)
GSLIB.locmap_st(samples_cluster, X, Y, wts, xmin, xmax, ymin, ymax, 0.0, 2.0, 
                 'Declustering Weights', 'X (m)', 'Y (m)', 'Weights', cmap)
plt.show()

Troubleshooting

If you encounter any issues, here are a few suggestions:

  • Ensure all dependencies are properly installed.
  • Check your Python version; GeostatsPy requires a minimum of Python 3.7.10.
  • If you receive package import errors, use: python -m pip install [package-name] to install the missing package.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Recent Updates

The GeostatsPy package is continuously improving. Highlights of recent changes include:

  • New 3D methods for variogram calculations and kriging.
  • Improvements made in sequential Gaussian simulation for better variogram reproduction.

Conclusion

GeostatsPy empowers students and researchers alike to harness the power of geostatistics within Python’s versatile ecosystem. At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

More Resources

For additional information, check out the following:

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox