Crop radolan radar data using geographic coordinates in wradlib

huangapple go评论141阅读模式
英文:

Crop radolan radar data using geographic coordinates in wradlib

问题

我正在使用Python库wradlib来读取由德国气象局(DWD)的opendata服务提供的radolan雷达数据集。我想通过提供最大和最小经度和纬度坐标来裁剪数据,以便只保留所选区域,然后可以对其执行进一步的操作。

我的代码如下:

import wradlib as wrl

rv_file = "DE1200_RV2201271935_000"
ds = wrl.io.open_radolan_dataset(rv_file)
data = ds.RV

print(data)

输出显示该数组仅包含x和y坐标:

<xarray.DataArray 'RV' (y: 1200, x: 1100)>
[1320000 values with dtype=float32]
Coordinates:
  * y        (y) float64 -4.809e+03 -4.808e+03 ... -3.611e+03 -3.61e+03
  * x        (x) float64 -543.5 -542.5 -541.5 -540.5 ... 552.5 553.5 554.5 555.5
Attributes:
    valid_min:      0
    valid_max:      4095
    standard_name:  rainfall_rate
    long_name:      RV
    unit:           mm h-1

我知道我需要使用投影变换并将地理坐标系统添加到数组中。我尝试使用以下函数:

proj_stereo = wrl.georef.create_osr("dwd-radolan")
proj_wgs = osr.SpatialReference()
proj_wgs.ImportFromEPSG(4326)

radolan_grid_xy = wrl.georef.get_radolan_grid(1200, 1100)

但我不确定如何应用投影变换,然后裁剪数据。

英文:

I am using the python library wradlib to read radolan radar datasets provided by the opendata service of the Deutscher Wetterdienst (DWD). I want to crop the data by providing maximum and minimum longitude and latitude coordinates so that just a selected area remains which I can perform further operations on.

My code looks like this:

import wradlib as wrl

rv_file = &quot;DE1200_RV2201271935_000&quot;
ds = wrl.io.open_radolan_dataset(rv_file)
data = ds.RV

print(data)

The output shows that the array only has x and y coordinates:

&lt;xarray.DataArray &#39;RV&#39; (y: 1200, x: 1100)&gt;
[1320000 values with dtype=float32]
Coordinates:
  * y        (y) float64 -4.809e+03 -4.808e+03 ... -3.611e+03 -3.61e+03
  * x        (x) float64 -543.5 -542.5 -541.5 -540.5 ... 552.5 553.5 554.5 555.5
Attributes:
    valid_min:      0
    valid_max:      4095
    standard_name:  rainfall_rate
    long_name:      RV
    unit:           mm h-1

I know that I need to use a reprojection and add a geographic coordinate system to the array.
I tried using the following functions:

proj_stereo = wrl.georef.create_osr(&quot;dwd-radolan&quot;)
proj_wgs = osr.SpatialReference()
proj_wgs.ImportFromEPSG(4326)

radolan_grid_xy = wrl.georef.get_radolan_grid(1200, 1100)

But I am not sure how to apply the reprojection and then crop the data.

答案1

得分: 0

以下是代码部分的翻译:

# 创建“dwd-radolan”投影
proj_stereo = wrl.georef.create_osr("dwd-radolan")

# 创建WGS 84投影
proj_wgs = osr.SpatialReference()
proj_wgs.ImportFromEPSG(4326)

# 定义Radolan网格的尺寸
radolan_grid_x_rv, radolan_grid_y_rv = 1200, 1100

# 获取Radolan网格的坐标
radolan_grid_xy = wrl.georef.get_radolan_grid(radolan_grid_x_rv, radolan_grid_y_rv)

# 重新投影Radolan网格到WGS 84坐标系
radolan_grid_ll = wrl.georef.reproject(radolan_grid_xy, projection_source=proj_stereo, projection_target=proj_wgs)
# 将新的坐标分配给数据作为字典
lonlat_coords = dict(lon=(["y", "x"], radolan_grid_ll[:, :, 0]), lat=(["y", "x"], radolan_grid_ll[:, :, 1]))

new_data = data.assign_coords(lonlat_coords)

# 定义经纬度坐标范围
lon_min, lon_max = 8.2, 8.9
lat_min, lat_max = 53.2, 53.8

# 根据经纬度坐标裁剪数据
selected_area = new_data.where((new_data.lon > lon_min) & (new_data.lon < lon_max) & (new_data.lat > lat_min) & (new_data.lat < lat_max), drop=True)

print(selected_area)

希望这有所帮助。如果需要更多信息,请随时提问。

英文:

The projections for the radar data and the target reference system need to be defined.
Then the lon-lat-grid can be created by taking the radolan grid and the source and target projections.

proj_stereo = wrl.georef.create_osr(&quot;dwd-radolan&quot;)
proj_wgs = osr.SpatialReference()
proj_wgs.ImportFromEPSG(4326)

radolan_grid_x_rv, radolan_grid_y_rv = 1200, 1100

radolan_grid_xy = wrl.georef.get_radolan_grid(radolan_grid_x_rv, radolan_grid_y_rv)
radolan_grid_ll = wrl.georef.reproject(radolan_grid_xy, projection_source=proj_stereo, projection_target=proj_wgs)

The new coordinates can be assigned to the data as a dictionary.
The data can be cropped by filtering by lon and lat coordinates.

lonlat_coords = dict(lon=([&quot;y&quot;, &quot;x&quot;], radolan_grid_ll[:, :, 0]), lat=([&quot;y&quot;, &quot;x&quot;], radolan_grid_ll[:, :, 1]))

new_data = data.assign_coords(lonlat_coords)

lon_min, lon_max = 8.2, 8.9
lat_min, lat_max = 53.2, 53.8

selected_area = new_data.where((new_data.lon &gt; lon_min) &amp; (new_data.lon &lt; lon_max) &amp; (new_data.lat &gt; lat_min) &amp; (new_data.lat &lt; lat_max), drop=True)

print(selected_area)

huangapple
  • 本文由 发表于 2023年6月8日 07:57:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76427787.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定