Python错误与xarray open_rasterio函数

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

Python error with xarray open_rasterio function

问题

# Step 3: 使用 rioxarray 读取 GeoTIFF 文件
data = xr.open_rasterio(tif)

# 从数据中提取纬度和经度值
latitude = data.y.values
longitude = data.x.values

# 将风数据从U/V分量转换为大小和方向
u_wind = data.values[0]
v_wind = data.values[1]
wind_magnitude = np.sqrt(u_wind*2 + v_wind*2)
wind_direction = np.degrees(np.arctan2(u_wind, v_wind))

# 创建纬度和经度的网格
lon_grid, lat_grid = np.meshgrid(longitude, latitude)
英文:

I am trying to read a file this netcdf file and convert it into tif file and read it using xarray

import xarray as xr
import geemap
import numpy as np
from mayavi import mlab

# Step 1: Download the NetCDF file
url = 'https://github.com/giswqs/leafmap/raw/master/examples/data/wind_global.nc'
filename = 'wind_global.nc'
data = geemap.read_netcdf(filename)

# Step 2: Convert the NetCDF file to a GeoTIFF
tif = 'wind_global.tif'
geemap.netcdf_to_tif(filename, tif, variables=['u_wind', 'v_wind'], shift_lon=True)
print(data)
# Step 3: Read the GeoTIFF file using rioxarray
data = xr.open_rasterio(tif)

# Extract latitude and longitude values from the data
latitude = data.y.values
longitude = data.x.values

# Convert wind data from U/V components to magnitude and direction
u_wind = data.values[0]
v_wind = data.values[1]
wind_magnitude = np.sqrt(u_wind*2 + v_wind*2)
wind_direction = np.degrees(np.arctan2(u_wind, v_wind))

# Create a meshgrid of latitude and longitude
lon_grid, lat_grid = np.meshgrid(longitude, latitude)

which throws me the error
module 'xarray' has no attribute 'open_rasterio'

答案1

得分: 1

xarray.open_rasterio自版本0.20.0起已被弃用(发布说明),并在2023.04.0版本中已删除(发布说明)。

推荐的替代方法是rioxarray.open_rasterio“入门指南”)。

英文:

xarray.open_rasterio was deprecated from version 0.20.0 onwards (release notes), and has been removed as of build 2023.04.0 (release notes).

The recommended replacement is rioxarray.open_rasterio ("Getting Started" guide).

huangapple
  • 本文由 发表于 2023年7月17日 20:17:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76704386.html
匿名

发表评论

匿名网友

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

确定