我有一份卫星图像文件。加载到dask数组中。我想获取感兴趣的纬度、经度的像素值(最近的)。
卫星图像是GEOS投影。我有2Dnumpy数组形式的经度和纬度信息。
我已经将它加载到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)我得到了一个2dnumpy数组,每个数组的经度和纬度都是坐标,但我不能使用它们进行切片或选择。
获取最近最长像素信息的最佳实践/方法是什么?我如何将数据投影到后面长坐标上,然后我可以使用这些坐标进行索引,从而得到像素值。
最后,我想得到感兴趣的long的像素值(最近的)。
提前感谢!
发布于 2021-03-02 21:04:52
您正在使用的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坐标。
发布于 2021-03-02 15:17:12
您可以通过以下命令找到该位置:
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发布于 2021-03-02 17:02:55
@serge ballesta -感谢您的指导
回答我自己的问题。
将纬度和经度(平台投影)投影到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')https://stackoverflow.com/questions/66433948
复制相似问题