爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 384|回复: 0

[求助] 计算ERA5小时数据的风速百分位

[复制链接]

新浪微博达人勋

发表于 2024-2-19 14:06:30 | 显示全部楼层 |阅读模式
5金钱
  1. import os
  2. import numpy as np
  3. import xarray as xr

  4. data_folder1 = 'K:\\reanalysis\ERA5\\100m_speed\\100m u\\1979-2022'
  5. data_folder2 = 'K:\\reanalysis\ERA5\\100m_speed\\100m v\\1979-2022'

  6. file_names_u = os.listdir(data_folder1)
  7. file_names_v = os.listdir(data_folder2)

  8. def read_wind(file_path_u, file_path_v, lat_value, lon_value):
  9.     with xr.open_dataset(file_path_u) as ds:
  10.         u_wind = ds['u100'].sel(latitude=lat_value, longitude=lon_value).values
  11.     with xr.open_dataset(file_path_v) as ds:
  12.         v_wind = ds['v100'].sel(latitude=lat_value, longitude=lon_value).values
  13.     return u_wind, v_wind

  14. lat_value = 0
  15. lon_value = 90
  16. all_u_winds = []
  17. all_v_winds = []

  18. for file_name_u, file_name_v in zip(file_names_u, file_names_v):
  19.     file_path_u = os.path.join(data_folder1, file_name_u)
  20.     file_path_v = os.path.join(data_folder2, file_name_v)
  21.     u_wind, v_wind = read_wind(file_path_u, file_path_v, lat_value, lon_value)
  22.     all_u_winds.extend(u_wind)
  23.     all_v_winds.extend(v_wind)

  24. all_u_winds = np.array(all_u_winds)
  25. all_v_winds = np.array(all_v_winds)

  26. # 计算风速
  27. all_windspeeds = np.sqrt(np.square(all_u_winds) + np.square(all_v_winds))

  28. percentile_50 = np.percentile(all_windspeeds, 50)
  29. print(f"The 50% percentile of the wind speed values is: {percentile_50}")
复制代码
我想计算ERA5小时数据每个经纬度网格点44年的百分位,我的一个u的nc文件的大小是1.4G,总共u,v共1056个文件,所以没办法直接计算。我现在的想法是把每个经纬度网格点的的百分位算出来,循环。但是我目前写的代码计算一个经纬度网格点的百分位就非常慢,有大佬能帮我看一下问题吗

密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表