用降水、比湿和温度计算相对湿度(nc版、python)

11 篇文章 5 订阅
4 篇文章 0 订阅

用降水、比湿和温度计算相对湿度(nc版、python)

有时收集到的气象数据为比湿,但模型中需要的输入为相对湿度,我们可以利用降水、比湿和温度进行换算。
转换公式:https://earthscience.stackexchange.com/questions/2360/how-do-i-convert-specific-humidity-to-relative-humidity
在这里插入图片描述
比湿转换为相对湿度

def shum_switch_rhum(temp,shum,pres):
    '''
    利用比湿(specific humidity)计算相对湿度
    :param temp: 气温,K
    :param shum: 比湿
    :param pres: 气压,Pa
    :return: rhum,%
    '''
    rhum = 0.236 * pres * shum * np.exp((17.67 * (temp - 273.16))/(temp - 29.65)) ** (-1)
    print(rhum)
    return rhum

如果你的数据是nc的,那么你可以尝试用下面的函数进行批量计算

import xarray as xr
import os
import datetime
import numpy as np
import pandas as pd
def Search_File(dirname,suffix):
    '''
    This function can search all files with the specified suffix in this dir.
    :param dirname: string, the path need to be searched
    :param suffix: string, the specified suffix need to be seached
    :return:
    filter_list: list, the path list need to be searched.
    '''
    filter = [suffix]  # 设置过滤后的文件类型 当然可以设置多个类型
    filter_list = []
    for maindir, subdir, file_name_list in os.walk(dirname):
        #print(maindir) #当前主目录
        for filename in file_name_list:
            apath = os.path.join(maindir, filename)#合并成一个完整路径
            portion = os.path.splitext(apath)
            ext = portion[1]  # 获取文件后缀 [0]获取的是除了文件名以外的内容

            if ext in filter:
                newname = portion[0] + suffix

                filter_list.append((newname,portion[0].split("\\")[-1]))
    # print(filter_list)
    return filter_list
    
def batch_shum_to_rhum(pres_path,shum_path,temp_path,output_path,start_year,end_year):
    '''
    可以利用降水、比湿和温度计算相对湿度,注意数据单位
    :param pres_path:
    :param shum_path:
    :param temp_path:
    :param output_path:
    :return:
    '''
    # 批量比湿和相对湿度换算
    # 导入数据,压力、比湿以及温度,注意单位
    pres_path_list = Search_File(pres_path,".nc")
    pres_list = [read_nc_data(path[0]) for path in pres_path_list]
    pres = xr.combine_nested(pres_list,concat_dim="time")
    temp_path_list = Search_File(temp_path,".nc")
    temp_list = [read_nc_data(path[0]) for path in temp_path_list]
    temp = xr.combine_nested(temp_list,concat_dim="time")
    shum_path_list = Search_File(shum_path, ".nc")
    shum_list = [read_nc_data(path[0]) for path in shum_path_list]
    shum = xr.combine_nested(shum_list, concat_dim="time")

    acc = xr.merge([shum,temp,pres])
    rhum_data = shum_switch_rhum(acc["temp"].values,acc["shum"].values,acc["pres"].values)
    rhum = xr.Dataset({"rhum": (["time", "lat", "lon"], rhum_data)}, coords=acc.coords,
               attrs={"long_name": "relative humidity", "units": "%"})

    years = list(range(start_year, end_year + 1))
    for year in years:
    	# 输入年月数据比较方便!!!
        out = rhum.sel(time=rhum["time.year"] == year)
        out.to_netcdf("{}/rhum_{}.nc".format(output_path,year))
        print(out)
  • 5
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
计算整层水汽通量,可以使用以下公式: 单层水汽通量 = q * v / g 其中,q是比湿(单位为kg/kg),v是风速(单位为m/s),g是重力加速度(单位为10**-2·hPa·m**2/kg)\[2\]。 在Python中,可以使用metpy库来进行计算。具体的计算步骤如下: 1. 首先,根据相对湿度温度计算露点温度,使用mpcalc.dewpoint_from_relative_humidity函数\[3\]。 2. 然后,根据露点温度气压计算比湿,使用mpcalc.specific_humidity_from_dewpoint函数\[3\]。 3. 接下来,根据比湿、风速和重力加速度计算单层水汽通量\[3\]。 4. 最后,可以根据需要进行进一步的处理或绘图。 请注意,以上步骤仅为计算整层水汽通量的基本方法,具体的实现可能会根据实际情况有所不同。 #### 引用[.reference_title] - *1* *2* [整层水汽通量和整层水汽通量散度计算python绘图](https://blog.csdn.net/wdbhysszjswn/article/details/129044910)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [基于python 利用ERA5 资料绘制水汽剖面图](https://blog.csdn.net/happycatherin/article/details/130059882)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值