簡體   English   中英

如何抵消cartopy海岸線以適應實際數據?

[英]How to offset the cartopy coastline to fit the actual data?

我正在嘗試使用帶有 cartopy 的 imshow() 來 plot 來自 HDF5 文件的簡單衛星圖像。 但是我的 map 並沒有與正確的區域完全重疊。 以下是示例代碼 -

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

import numpy as np

# First get data from HDF5 file with h5py:
fn = '/home/swadhin/project/insat/3DIMG_15JUN2022_0930_L1C_ASIA_MER.h5' #filename (the ".h5" file)
with h5py.File(fn) as data:      
    # retrieve image data:
    image = 'IMG_TIR1'
    img_arr = data[image][0,:,:] 
    # get _FillValue for data masking
    img_arr_fill = data[image].attrs['_FillValue'][0] 


# retrieve extent of plot from file attributes:
    left_lon = data.attrs['left_longitude'][0]
    right_lon = data.attrs['right_longitude'][0]
    lower_lat = data.attrs['lower_latitude'][0]
    upper_lat = data.attrs['upper_latitude'][0]  
    sat_long = data.attrs['Nominal_Central_Point_Coordinates(degrees)_Latitude_Longitude'][1]
img_extent_deg = (left_lon, right_lon, lower_lat, upper_lat)
print(img_extent_deg)
img_arr_m = np.ma.masked_equal(img_arr, img_arr_fill, copy=True)   
map_proj = ccrs.Mercator(central_longitude=sat_long)
ax = plt.axes(extent = img_extent_deg,projection=map_proj)
ax.coastlines(color='white')
ax.add_feature(cfeature.BORDERS, edgecolor='white', linewidth=0.5)
ax.add_feature(cfeature.STATES,edgecolor = 'red',linewidth = 0.5)
ax.gridlines(color='black', alpha=0.5, linestyle='--', linewidth=0.75, draw_labels=True)
map_extend_mer = ax.get_extent(crs=map_proj)
plt.imshow(img_arr_m, extent=map_extend_mer, cmap = 'gray')
plt.colorbar()

然而,plot 生成的范圍略低於 10S,因此無法正確顯示功能。 例如,應該在古吉拉特地區上空的雲現在在巴基斯坦邊境。 在此處輸入圖像描述

更新 1:在 map 投影中添加緯度范圍后,問題得到解決。


map_proj = ccrs.Mercator(central_longitude=sat_long, min_latitude= lower_lat,max_latitude=upper_lat)

在 map 投影中添加緯度范圍后,問題得到解決。

map_proj = ccrs.Mercator(central_longitude=sat_long, min_latitude= lower_lat,max_latitude=upper_lat)

每當我指定central_longitude時,都會出現意外行為。

我無法告訴你原因,因為我沒有詳細調查過。

但只需初始化沒有central_longitude的投影,只需調用ccrs.Mercator() 然后,您可以使用ax.set_extent(area_extent, crs)將視圖區域限制為您的 roi。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM