- 积分
- 31
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2022-4-16
- 最后登录
- 1970-1-1
|
5金钱
- import os
- import numpy as np
- import xarray as xr
- data_folder1 = 'K:\\reanalysis\ERA5\\100m_speed\\100m u\\1979-2022'
- data_folder2 = 'K:\\reanalysis\ERA5\\100m_speed\\100m v\\1979-2022'
- file_names_u = os.listdir(data_folder1)
- file_names_v = os.listdir(data_folder2)
- def read_wind(file_path_u, file_path_v, lat_value, lon_value):
- with xr.open_dataset(file_path_u) as ds:
- u_wind = ds['u100'].sel(latitude=lat_value, longitude=lon_value).values
- with xr.open_dataset(file_path_v) as ds:
- v_wind = ds['v100'].sel(latitude=lat_value, longitude=lon_value).values
- return u_wind, v_wind
- lat_value = 0
- lon_value = 90
- all_u_winds = []
- all_v_winds = []
- for file_name_u, file_name_v in zip(file_names_u, file_names_v):
- file_path_u = os.path.join(data_folder1, file_name_u)
- file_path_v = os.path.join(data_folder2, file_name_v)
- u_wind, v_wind = read_wind(file_path_u, file_path_v, lat_value, lon_value)
- all_u_winds.extend(u_wind)
- all_v_winds.extend(v_wind)
- all_u_winds = np.array(all_u_winds)
- all_v_winds = np.array(all_v_winds)
- # 计算风速
- all_windspeeds = np.sqrt(np.square(all_u_winds) + np.square(all_v_winds))
- percentile_50 = np.percentile(all_windspeeds, 50)
- print(f"The 50% percentile of the wind speed values is: {percentile_50}")
复制代码 我想计算ERA5小时数据每个经纬度网格点44年的百分位,我的一个u的nc文件的大小是1.4G,总共u,v共1056个文件,所以没办法直接计算。我现在的想法是把每个经纬度网格点的的百分位算出来,循环。但是我目前写的代码计算一个经纬度网格点的百分位就非常慢,有大佬能帮我看一下问题吗 |
|