简体   繁体   English

使用纬度经度坐标从卫星图像中获取最近的像素值

[英]Get nearest pixel value from satellite image using latitude longitude coordinates

I have a satellite image file.我有一个卫星图像文件。 Loaded into dask array.加载到 dask 数组中。 I want to get pixel value (nearest) of a latitude, longitude of interest.我想获得感兴趣的纬度、经度的像素值(最近的)。

Satellite image is in GEOS projection.卫星图像在 GEOS 投影中。 I have longitude and latitude information as 2D numpy arrays.我的经度和纬度信息为 2D numpy arrays。

Satellite Image file卫星图像文件

I have loaded it into a dask data array我已将其加载到 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']

This is what the dask array looks like:这是 dask 数组的样子: 在此处输入图像描述 在此处输入图像描述

I read lon lats from the area attribute with the help of satpy:我在 satpy 的帮助下从 area 属性中读取了 lon lats:

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

(1179, 808)
(1179, 808)

I get a 2d numpy array each, for longitude and latitude that are coordinates but I can not use them for slicing or selecting.我得到一个 2d numpy 数组,每个数组用于坐标的经度和纬度,但我不能将它们用于切片或选择。

What is the best practice/method to get nearest lat long, pixel information?获取最近的经纬度像素信息的最佳实践/方法是什么? How do I project the data onto lat long coordinates that I can then use for indexing to arrive at the pixel value.如何将数据投影到经纬度坐标上,然后我可以将其用于索引以得出像素值。

At the end, I want to get pixel value (nearest) of lat long of interest.最后,我想获得感兴趣的 lat long 的像素值(最近的)。

Thanks in advance!!!提前致谢!!!

The AreaDefinition object you are using ( .attrs['area'] ) has a few methods for getting different coordinate information.您正在使用的AreaDefinition object ( .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]

Note that row and column are flipped.请注意,行和列是翻转的。 The get_xy_from_lonlat method should work for arrays or scalars. get_xy_from_lonlat方法应该适用于 arrays 或标量。

There are other methods for getting X/Y coordinates of each pixel if that is what you're interesting in.如果您对此感兴趣,还有其他方法可以获取每个像素的 X/Y 坐标。

You can find the location with following:您可以通过以下方式找到该位置:

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

@serge ballesta - thanks for the direction @serge ballesta - 感谢您的指导

Answering my own question.回答我自己的问题。

Project the latitude and longitude (platecaree projection) onto the GEOS projection CRS.将纬度和经度(platecaree 投影)投影到 GEOS 投影 CRS 上。 Find x and y.找到 x 和 y。 Use this x and y and nearest select method of xarray to get pixel value from dask array.使用 xarray 的这个 x 和 y 以及最近的 select 方法从 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')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 了解 GeoTIFF 图像中特定像素值的地理坐标(经度和纬度) - Know the geographic coordinates (longitude and latitude) of a particular pixel value in a GeoTIFF image 从纬度/经度坐标计算像素值(使用matplotlib底图) - Calculate pixel values from latitude/longitude coordinates (using matplotlib Basemap) 如何使用 python 获取 eumetsat 图像像素的纬度和经度? - How to get latitude and longitude for a pixel of a eumetsat image using python? 查找 GeoTiff 图像中每个像素的纬度/经度坐标 - Find Latitude/Longitude Coordinates of Every Pixel in a GeoTiff Image 从坐标中提取纬度和经度 - Extract latitude and longitude from coordinates 如何从经纬度坐标列表中获取城市、state 和国家? - How to get city, state, and country from a list of latitude and longitude coordinates? 如何使用 plotly python 从 pandas 数据帧中标记点(使用纬度和经度)与卫星视图 - how to mark points(using latitude and longitude) from pandas data frame using plotly python with satellite view Python 可以从卫星图像中导出纬度/经度吗? - Can Python export latitude/longitude from Satellite images? 使用 python 将纬度和经度坐标自动填充到 excel - autopopulate latitude and longitude coordinates into excel using python 使用pyproj将坐标转换为经度和纬度 - Converting coordinates to longitude and latitude using pyproj
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM