top of page
GeoWGS84AI_Logo_edited.jpg

EarthPy Python Package Tutorial for Beginners

Plotting shapefiles, evaluating raster pictures, and carrying out remote sensing operations are just a few of the complicated tasks that might arise when working with geographic data in Python. EarthPy, a potent open-source Python package, can help with it. EarthPy was created to streamline geospatial operations, making it simpler for both novices and experts to see, work with, and evaluate spatial data.


Everything you need to know to get started with EarthPy will be covered in this tutorial, including installation, key features, and basic examples.


EarthPy Python Package
EarthPy Python Package

What is EarthPy?


Popular geospatial and scientific computing libraries like Rasterio, Geopandas, Matplotlib, and Numpy are the foundation of the Python package EarthPy. Earth Lab at the University of Colorado Boulder created it to make Earth data scientific processes more efficient.


Important EarthPy Features:


  • Simple visualization of vector and raster data.

  • Raster data stacking, cropping, and clipping functions.

  • Tools for categorizing and mapping colors in images.

  • Integration with Geopandas for shapefiles and Matplotlib for plots.

  • Easy-to-use design for research and instruction.


Getting Started with EarthPy


  1. Import Required Libraries


import earthpy as et

import earthpy.spatial as es

import earthpy.plot as ep

import matplotlib.pyplot as plt


  1. Load Sample Data


EarthPy offers practice datasets as examples:


# Download example data

data = et.data.get_data("cold-springs-fire")

print(data)


Working with Raster Data


Stack and Plot Multiband Raster


import os

import rasterio as rio


# Define data path

data_path = os.path.join(et.io.HOME, "earth-analytics", "data")


# Stack Landsat data

stacked, meta = es.stack_raster_tifs(

[os.path.join(data_path, "landsat_band2.tif"),

os.path.join(data_path, "landsat_band3.tif"),

os.path.join(data_path, "landsat_band4.tif")]

)


# Plot stacked image

ep.plot_bands(stacked, cmap="terrain", cols=3, figsize=(10, 6))


Combining several raster bands into a stack and plotting them using user-friendly color maps is made easy using EarthPy.


Working with Vector Data


Shapefiles can be loaded and superimposed over raster plots with ease:


Import geopandas as gpd


# Load vector shapefile

fire_boundary = gpd.read_file(os.path.join(data_path, "fire_boundary.shp"))


# Plot with EarthPy

ep.plot_bands(stacked[0], cmap="gray")

fire_boundary.plot(ax=plt.gca(), edgecolor="red", linewidth=2)


This enables you to see administrative maps or raster data with boundaries.


Why Use EarthPy?


  • API for geospatial workflows that is easy to learn.

  • Wrapping repetitive raster/vector jobs saves time.

  • Compatible with widely used libraries such as Matplotlib, Rasterio, and Geopandas.

  • Perfect for data scientists, remote sensing analysts, and GIS students.


For those who are new to geospatial data science, the EarthPy Python package is an essential resource. It offers clear plotting functions for visualizing spatial data, streamlines raster and vector operations, and works well with the scientific Python ecosystem.


EarthPy is among the greatest resources to start with if you're new to geospatial analysis in Python.


For more information or any questions regarding the Python Package, please don't hesitate to contact us at


USA (HQ): (720) 702–4849


(A GeoWGS84 Corp Company)

 
 
 

Comments


bottom of page