社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

20个用于卫星观测数据可视化的Python库

GEE遥感训练营 • 6 天前 • 44 次点击  
随着空间技术的飞速发展,卫星观测数据已成为地理空间分析领域不可或缺的信息来源。 从高分辨率光学影像到全天候雷达数据,各类卫星传感器以前所未有的规模和频率持续记录着地球表面的变化。 这些海量数据蕴含着丰富的地理空间信息,为环境监测、城市规划、农业管理、灾害应急等诸多领域提供了强有力的数据支撑。然而,有效利用这些庞大而复杂的数据集,特别是将其转化为易于理解和分析的可视化形式,是地理空间专业人员面临的关键挑战。

Python 库在卫星数据可视化领域发挥着至关重要的作用,它们正是在这样的背景下应运而生,为地理空间数据的处理、分析和显示提供了强大的工具。这些库支持广泛的数据格式,实现交互式可视化,并与地理信息系统 (GIS) 和遥感工作流程良好集成,使其成为地理空间专业人员不可或缺的工具。

通过利用这些库,用户可以无缝处理大型卫星数据集,应用先进的图像处理技术,并生成富有洞察力的可视化表示。 无论是处理多光谱、高光谱还是雷达影像,这些工具都能实现高效的数据操作、增强和解译。 此外,它们还促进了与机器学习框架的无缝集成,从而为地球观测研究中的预测建模和模式识别提供了便利。

本文列出20个用于卫星数据可视化的必备Python库,并简要介绍其功能和应用。

1. Matplotlib

Matplotlib 是 Python 中最常用的绘图库,适用于卫星影像的静态可视化。它支持假彩色可视化和色彩映射。

import matplotlib.pyplot as plt
import rasterio
from rasterio.plot import show

with rasterio.open("satellite_image.tif") as src:
plt.figure(figsize=(10, 6))
show(src)

GitHub 链接: https://github.com/matplotlib/matplotlib

官方网站: https://matplotlib.org/

2. Seaborn

Seaborn 构建于 Matplotlib 之上,提供更美观的绘图效果。它擅长可视化统计分布、热图和相关矩阵。




    
import seaborn as sns
import numpy as np

# 模拟栅格数据作为热图
data = np.random.rand(10, 10)
sns.heatmap(data, cmap="coolwarm")

GitHub 链接: https://github.com/mwaskom/seaborn

官方网站: https://seaborn.pydata.org/

3. Plotly/Plotly Express

Plotly 及其高级 API 库 Plotly Express 拥有强大的地理空间数据可视化能力。 非常适合地形模型和多波段影像。该库拥有丰富的地图类型和易于使用的API。 Plotly Express 的推出,使得使用Plotly创建地理空间可视化变得更加容易。

例如,使用 Plotly Express 仅需一行代码即可完成动态 Choropleth 地图的创建。 与其他库相比,实现同样的效果可能需要编写大量的代码并尝试各种不同的解决方案。

1import plotly.express as px
2import xarray as xr
3
4dataset = xr.open_rasterio("satellite_image.tif")
5fig = px.imshow(dataset[0] , color_continuous_scale='viridis')
6fig.show()

结合 Dash (数据科学领域广泛使用且下载量最多的Web应用程序框架),Plotly提供了一整套用于部署 Web 应用程序的完整解决方案。 借助 Plotly Express 直观的 API 和 Dash Plotly,您可以将您的地理空间 Web 应用程序和可视化提升到一个新的水平。 

GitHub 链接: https://github.com/plotly/plotly.py

官方网站: https://plotly.com/python/

4. Folium

Folium 用于创建交互式 Web 地图,与 OpenStreetMap 和 Google Earth Engine (GEE) 配合良好。

import folium

m = folium.Map(location=[0, 0], zoom_start=2)
folium.Marker(location=[-1.28, 36.82], popup="内罗毕, 肯尼亚").add_to(m)

GitHub 链接: https://github.com/python-visualization/folium

官方网站: https://python-visualization.github.io/folium/

5. Geopandas

Geopandas 扩展了 Pandas,用于处理矢量数据(shapefile、GeoJSON),可用于将栅格数据与行政边界叠加显示。




    
import geopandas as gpd
import matplotlib.pyplot as plt

gdf = gpd.read_file("boundaries.geojson")
gdf.plot(figsize=(10, 6), color="blue", edgecolor="black")
plt.show()

GitHub 链接: https://github.com/geopandas/geopandas

官方网站: https://geopandas.org/en/stable/

6. Rasterio

Rasterio 是读取和写入栅格数据集(TIFF、NetCDF)的关键库,用于裁剪、重投影和掩膜栅格数据。

import rasterio
from rasterio.plot import show

with rasterio.open("satellite_image.tif") as src:
show(src)

GitHub 链接: https://github.com/rasterio/rasterio

官方网站: https://rasterio.readthedocs.io/en/stable/

7. Xarray

Xarray 最适合处理大型、多维栅格数据集,常用于海洋、大气和遥感数据(NetCDF、HDF5)。

import xarray as xr

dataset = xr.open_rasterio("satellite_image.tif")
dataset[0].plot()

GitHub 链接: https://github.com/pydata/xarray

官方网站: https://docs.xarray.dev/en/stable/

8. Cartopy

Cartopy 专门用于地图投影和地理空间可视化,支持shapefile、卫星影像叠加和网格变换。

import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt

fig, ax = plt.subplots(subplot_kw={'projection': ccrs.PlateCarree()})
ax.coastlines()

GitHub 链接: https://github.com/SciTools/cartopy

官方网站: https://scitools.org.uk/cartopy/docs/latest/

9. GDAL (地理空间数据抽象库)

GDAL是一个用于地理空间数据处理的基础库,支持处理栅格变换、格式转换和投影。

import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt

fig, ax = plt.subplots(subplot_kw={'projection': ccrs.PlateCarree()})
ax.coastlines()
ax.add_feature(cfeature.BORDERS, linestyle=':')
plt.show()

GitHub 链接: https://github.com/OSGeo/gdal

官方网站: https://gdal.org/

10. Leaflet (通过 ipyleaflet)

Leaflet类似于Folium,但在Jupyter notebook中更具可定制性,非常适合添加交互式标记、热图和叠加层。

from ipyleaflet import Map, Marker

m = Map(center=(0, 0), zoom=2)
marker = Marker(location=(-1.28, 36.82))
m.add_layer(marker)

GitHub 链接: https://github.com/jupyter-widgets/ipyleaflet

官方网站: https://ipyleaflet.readthedocs.io/en/latest/



11. Bokeh

Bokeh 是一个高性能交互式可视化库,适用于基于 Web 的卫星影像可视化。

from bokeh.plotting import figure, show
import numpy as np

img = np.random.rand(100, 100)
p = figure(width=500, height=500)
p.image(image=[img], x=0, y=0, dw=10, dh=10)
show(p)

GitHub链接: https://github.com/bokeh/bokeh

官方网站: https://bokeh.org/

12. OpenCV

OpenCV 主要用于图像处理,适用于卫星影像的边缘检测、分类和分割。

import cv2

img = cv2.imread("satellite_image.tif", cv2.IMREAD_GRAYSCALE)
edges = cv2.Canny(img, 100, 200)
cv2.imshow("Edges", edges)
cv2.waitKey(0)

GitHub链接: https://github.com/opencv/opencv

官方网站: https://opencv.org/

13. EarthPy

EarthPy 专为处理和可视化遥感数据而设计,适用于Landsat、Sentinel和MODIS数据处理和分析。

import earthpy.plot as ep
import rasterio

with rasterio.open("satellite_image.tif") as src:
ep.plot_rgb(src.read())

GitHub 链接: https://github.com/earthlab/earthpy

官方网站: https://earthpy.readthedocs.io/en/latest/

14. Pydeck

Pydeck 是一个用于大规模地理空间数据的 3D 可视化库,适用于可视化点云、高程模型和卫星影像。

import earthpy.plot as ep
import rasterio

with rasterio.open("satellite_image.tif") as src:
ep.plot_rgb(src.read())

请注意 Pydeck 实际上是 deck.gl 的 Python 封装,所以这里链接的是 deck.gl 的 GitHub 仓库和 Pydeck 的官方文档

GitHub 链接: https://github.com/visgl/deck.gl

官方网站: https://pydeck.gl/

15. Kepler.gl

Kepler.gl 是一个强大的基于Web的地图可视化库,能够处理海量的地理空间数据集进行可视化。

from keplergl import KeplerGl

map_1 = KeplerGl(height=500)
map_1

请注意 Kepler.gl 是一个 JavaScript 库, keplergl-jupyter 是其 Python 封装, 这里链接的是 kepler.gl 的 GitHub 仓库和官方网站

GitHub 链接: https://github.com/keplergl/kepler.gl

官方网站: https://kepler.gl/

16. PySAL (Python 空间分析库)

PySAL 是一个用于空间统计和计量经济学的库,适用于检测遥感数据中的空间模式。

import numpy as np
import libpysal as ps

data = np.random.rand(100)
weights = ps.weights.lat2W(10, 10)
print(weights.neighbors)

GitHub 链接: https://github.com/pysal/pysal

官方网站: https://pysal.org/

17. Rioxarray

Rioxarray扩展了Xarray库,用于地理空间栅格操作,支持坐标参考系统 (CRS) 变换,并适用于NetCDF、GeoTIFF和HDF5文件。

import rioxarray as rxr

raster = rxr.open_rasterio("satellite_image.tif")
raster.rio.reproject( "EPSG:4326").plot()

GitHub 链接: https://github.com/corteva/rioxarray

官方网站: https://corteva.github.io/rioxarray/stable/

18. Holoviews + Geoviews

Holoviews 和 Geoviews 简化了交互式地理空间可视化,与 Bokeh、Matplotlib 和 Plotly 协同工作。 这里同时提供了 Holoviews 和 Geoviews 的链接,因为它们通常一起使用

import geoviews as gv
from geoviews import opts
import cartopy.crs as ccrs

gv.extension('bokeh')
world = gv.feature.land.opts(projection=ccrs.PlateCarree())
world

Holoviews GitHub 链接: https://github.com/holoviz/holoviews

Holoviews 官方网站: https://holoviews.org/

Geoviews GitHub 链接: https://github.com/holoviz/geoviews

Geoviews 官方网站: https://geoviews.org/

19. SentinelHub-Py

SentinelHub-Py 可以直接访问 Sentinel-2、Sentinel-1 和 Landsat 影像,支持云层过滤、镶嵌和可视化,非常适合近实时遥感应用。




    
from sentinelhub import BBox, CRS

bbox = BBox(bbox=(-5.0, 40.0, 5.0, 50.0), crs=CRS.WGS84)
print(bbox)

GitHub 链接: https://github.com/sentinelhub/sentinelhub-py

官方网站: https://sentinelhub-py.readthedocs.io/en/latest/

20. Terracotta

Terracotta 是一个轻量级的栅格数据瓦片服务器,适用于将卫星影像作为 Web 地图服务,并与 SQLite 数据库配合进行元数据存储。

terracotta serve --port 5000

GitHub 链接: https://github.com/DHI-GRAS/terracotta

官方网站: https://terracotta.readthedocs.io/en/latest/

总结

这20个Python工具库涵盖了从简单的数据可视化到交互式在线地图,再到处理海量卫星数据的各种应用场景。 这些技术为地理空间分析工作奠定了坚实的基础,无论是处理原始卫星影像、进行复杂的空间分析,还是使用AI/ML进行预测性分析。

从管理多维栅格数据集 (Xarray, Rioxarray) 到生成适合出版的地图 (Cartopy, Folium),再到访问实时地球观测数据 (SentinelHub-Py, EarthPy),每个库都有其自身的特点。 借助Dask、Rasterio和GDAL等库,可以高效地处理大型数据集,尤其是在需要高性能计算的情况下。

通过组合使用这些工具,用户可以:

  • 预处理和清理卫星影像 (Rasterio, GDAL, Pyresample)

  • 执行统计和地统计分析 (PySAL, Geopandas)

  • 创建美观的交互式地图 (Folium, H3-Py, Holoviews, Geoviews)

  • 从遥感数据中提取有价值的洞察 (EOReader, Satpy, EarthPy)

  • 开发可扩展的云端应用 (Terracotta, Kepler.gl, Google Earth Engine API)

随着卫星影像变得越来越容易获取,以及人工智能驱动的地理空间分析不断发展,Python仍然是地理空间专业人员的首选语言。 

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/179206
 
44 次点击