【问题标题】:Get nearest pixel value from satellite image using latitude longitude coordinates使用纬度经度坐标从卫星图像中获取最近的像素值
【发布时间】:2021-05-31 16:12:23
【问题描述】:

我有一个卫星图像文件。加载到 dask 数组中。我想获取感兴趣的纬度、经度的像素值(最近的)。

卫星图像在 GEOS 投影中。我将经度和纬度信息作为 2D numpy 数组。

Satellite Image file

我已将它加载到一个 dask 数据数组中

from satpy import Scene
import matplotlib as plt
import os

cwd = os.getcwd()

fn = os.path.join(cwd, 'EUMETSAT_data/1Jan21/MSG1-SEVI-MSG15-0100-NA-20210101185741.815000000Z-20210101185757-1479430.nat')

files = [fn]

scn = Scene(filenames=files, reader='seviri_l1b_native')
scn.load(["VIS006"])
da = scn['VIS006']

这是 dask 数组的样子:

我在 satpy 的帮助下从 area 属性中读取了 lon lats:

lon, lat = scn['VIS006'].attrs['area'].get_lonlats()
print(lon.shape)
print(lat.shape)

(1179, 808)
(1179, 808)

我得到一个 2d numpy 数组,用于坐标的经度和纬度,但我不能将它们用于切片或选择。

获取最近的经纬度像素信息的最佳做法/方法是什么? 如何将数据投影到经纬度坐标上,然后我可以使用该坐标进行索引以得出像素值。

最后,我想获得感兴趣的 lat long 的像素值(最近的)。

提前致谢!!!

【问题讨论】:

  • 您有卫星图像使用的 GEOS 投影的 proj 参数。我会做相反的事情:将您的纬度点转换为该地理投影。从那里简单的四舍五入将为您提供最近的像素。

标签: python gis netcdf python-xarray satellite-image


【解决方案1】:

您正在使用的AreaDefinition 对象 (.attrs['area']) 有几种方法可以获取不同的坐标信息。

area = scn['VIS006'].attrs['area']
col_idx, row_idx = area.get_xy_from_lonlat(lons, lats)

scn['VIS006'].values[row_idx, col_idx]

请注意,行和列是翻转的。 get_xy_from_lonlat 方法应该适用于数组或标量。

如果您对此感兴趣,还有其他方法可以获取每个像素的 X/Y 坐标。

【讨论】:

    【解决方案2】:

    @serge ballesta - 感谢您的指导

    回答我自己的问题。

    将纬度和经度(platecaree 投影)投影到 GEOS 投影 CRS 上。找到 x 和 y。使用 xarray 的这个 x 和 y 以及最近的选择方法从 dask 数组中获取像素值。

    import cartopy.crs as ccrs
    
    data_crs = ccrs.Geostationary(central_longitude=41.5, satellite_height=35785831, false_easting=0, false_northing=0, globe=None, sweep_axis='y')
    
    lon = 77.541677 # longitude of interest
    lat = 8.079148 # latitude of interst
    
    # lon lat system in 
    x, y = data_crs.transform_point(lon, lat, src_crs=ccrs.PlateCarree())
    
    dn = ds.sel(x=x,y=y, method='nearest')
    

    【讨论】:

      【解决方案3】:

      您可以通过以下方式找到该位置:

      import numpy as np
      px,py = (23.0,55.0) # some location to take out values:
      
      dist = np.sqrt(np.cos(lat*np.pi/180.0)*(lon-px)**2+(lat-py)**2); # this is the distance matrix from point (px,py)
      kkout = np.squeeze(np.where(np.abs(dist)==np.nanmin(dist))); # find location where distance is minimum
      print(kkout) # you will see the row and column, where to take out data
      

      【讨论】:

      • 嗯...Proj4 在处理坐标系方面做得很好,并且关心地球不是一个真正的球体。为什么jou建议手工计算?
      • 因为它是简单的数学运算,而且 lon/lat 数组已经存在。总是可以采用更精确/更复杂的方法,但我认为问题是关于切片和使用现有数组。
      • 我能理解你的意思,你正在回答 OP 提出的确切问题(我没有 DV...)。然而,我认为这不是处理实际问题的最佳方式,这也是我在这里和问题上发表评论的原因。
      • 谢谢你们的cmets。感谢 Serge 的投入。那么最好的方法是将我感兴趣的经纬度投影到 GEOS 投影坐标参考系统上?我现在正在寻找方法。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-23
      • 2014-03-25
      • 2012-05-13
      • 1970-01-01
      • 1970-01-01
      • 2013-09-21
      • 2020-08-27
      相关资源
      最近更新 更多