I have created a Python module ** `` `wxparams``` ** that collects functions that calculate meteorological elements, such as functions that calculate the dew point temperature from temperature and relative humidity, so I will publish it. (Abbreviation for ** Weather Parameters **)
Before I started Python, I often wrote scripts to process weather data in Perl, and I also put together the functions that I often use in the weather field in the Perl module. I spent more time at home because of the corona virus (laughs), so I decided to rewrite it to Python on this machine.
The source code is GitHub, and the explanation of how to use it is summarized in this article because I will publish it if I make it anyway.
You can install pip from my GitHub.
pip install git+https://github.com/Yoshiki443/weather_parameters
If you are uncomfortable with pip installation, you can download and use only `` `wxparams / wxparams.py``` on GitHub.
It is MIT licensed.
I will introduce a code example first.
import numpy as np
import wxparams as wx
temp = np.array([[0., 5.],[10., 20.]]) #temperature[C]
rh = np.array([[90., 50.], [70., 99.5]]) #Humidity[%]
td = wx.RH_to_Td(temp, rh) #Dew point temperature[C]
print(td)
#output
# [[-1.44330606 -4.56523582]
# [ 4.78251527 19.91913689]]
Import first. The abbreviation "wx" in the code example is often used as an abbreviation for weather. After importing, call the function. The above example shows the case of calculating the dew point temperature from air temperature and relative humidity.
The data entered here is basically assumed to be ** numpy.ndarray **. Or it works with ** pandas.Series **. If you enter each weather element one by one, some functions will work and some will not.
As input data, for example, input a whole meteorological element with a pressure surface with GPV (that is, a two-dimensional array) to calculate another meteorological element, or enter a column of meteorological elements with structured data such as csv It is supposed to be used for calculating the weather elements of.
Some processes assume numpy.ndarray, so ** numpy.ndarray ** is recommended as the author.
Below is a description of each function.
UV_to_SpdDir(U, V) The wind direction and speed are calculated from the UV component of the wind. The UV component represents U = east-west wind and V = north-south wind, and the wind data of the numerical weather prediction GPV such as the Japan Meteorological Agency MSM is usually the UV component. Generally, the west wind has a positive value for the east-west wind, and the south wind has a positive value for the north-south wind. The unit of wind speed can be any unit of speed such as * m / s, knot *. The wind direction is 360 degrees, not 0 degrees due north. If the wind speed is 0, the wind direction will also be 0 degrees.
** Parameters: **
** Returns: **
SpdDir_to_UV(Wspd, Wdir) The opposite of UV_to_SpdDir, the UV component of the wind is calculated from the wind direction and speed. The unit of wind speed can be any unit of speed such as * m / s, knot *.
** Parameters: **
** Returns: **
Deg_to_Dir8(Wdir, dir_zero=None, numeric=False) Converts the wind direction from 360 degrees to 8 directions. The return value is the alphabet "** N / NE / E / SE / S / SW / W / NW " that represents the eight directions of " North / Northeast / East / Southeast / South / Southwest / West / Northwest ". Will be converted to. If the wind direction is 0, it will be converted to the character string specified by the argument dir_zero. The default is None, but in the case of aviation weather, for example, you can use it to convert to " VRB **", which indicates a state where the wind direction is uncertain.
If the argument numeric is set to True, the output will be the numerical value "8, 1, 2, 3, 4, 5, 6, 7". At this time, true north is 8 instead of 0. If the wind direction is 0, the output will be 0.
** Parameters: **
** Returns: **
Deg_to_Dir16(val, dir_zero=None, numeric=False) Converts the wind direction from 360 degrees to 16 headings, like Deg_to_Dir8. That is, the return value is an alphabet representing 16 directions of "** north, north-northeast, northeast, east-northeast, east, southeast, southeast, south-southeast, south, south-southwest, southwest, west-southwest, west, west-northwest, northwest, north-northwest ". It is converted to " N / NNE / NE / ENE / E / ESE / SE / SSE / S / SSW / SW / WSW / W / WNW / NW / NNW **".
If the argument numeric is set to True, the numerical values "16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15" are output. The treatment of wind direction 0 is the same as Deg_to_Dir8.
** Parameters: **
** Returns: **
Cross_Wind(Wspd, Wdir, RWY) The cross wind component (Cross Wind) of the wind is calculated from the wind speed, wind direction, and direction of the runway at the airport. The unit of wind speed can be any unit of speed such as * m / s, knot *. The unit of wind direction is * degree *. The runway is given in 360 degrees instead of the 2-digit RWY number. For example, for RWY22, enter 220 degrees.
** Parameters: **
** Returns: **
Tail_Wind(Wspd, Wdir, RWY) The tail wind component (Tail Wind) of the wind is calculated from the wind speed, wind direction, and direction of the runway at the airport. Others are the same as Cross_Wind.
** Parameters: **
** Returns: **
Head_Wind(Wspd, Wdir, RWY) The head wind component of the wind is calculated from the wind speed, wind direction, and direction of the airport runway. Matches the opposite value of Tail_Wind. Other than that, it is the same as Cross_Wind.
** Parameters: **
** Returns: **
RH_to_Td(T, RH, formula="Bolton") Calculate the dew point temperature [C] from the air temperature [C] and relative humidity [%]. Relative humidity cannot be calculated if it is 0%, so 0.1% is converted to the minimum value. The saturated water vapor pressure [hPa] is calculated in the calculation process, and there are three types of calculation formulas. By default, Bolton's formula is used, but Tetens' formula and WMO approximation formula can be specified as options. See T_to_WVP for details.
** Parameters: **
** Returns: **
Td_to_RH(T, Td, formula="Bolton") The opposite of RH_to_Td, the relative humidity [%] is calculated from the air temperature [C] and the dew point temperature [C]. Others are the same as RH_to_Td.
** Parameters: **
** Returns: **
T_to_WVP(T, formula="Bolton") Calculate the saturated water vapor pressure [hPa] from the air temperature [C]. If you enter the dew point temperature [C] instead of the air temperature, the water vapor pressure [hPa] will be calculated. There are three types of calculation formulas. The default uses Bolton's formula. This is because it is implemented by the formula adopted by the Japan Meteorological Agency when calculating the equivalent potential temperature. See also Theta_e. However, as far as I've confirmed, it doesn't matter which formula you use in practice, so you can use any formula you like. Personally, I am familiar with the Tetens formula.
Tetens expression:
** Parameters: **
** Returns: **
WVP_to_T(es, formula="Bolton") The inverse function of T_to_WVP calculates the temperature [C] from the saturated water vapor pressure [hPa]. If you enter the water vapor pressure [hPa], the dew point temperature [C] will be calculated.
** Parameters: **
** Returns: **
T_Td(T, Td) Dew point depression [C] is calculated from air temperature [C] and dew point temperature [C]. It's a function that simply performs subtraction.
** Parameters: **
** Returns: **
Mixing_Ratio(Td, P, formula="Bolton") The mixture ratio [g / g] is calculated from the dew point temperature [C] and the atmospheric pressure [hPa]. Since the saturated water vapor pressure is calculated during the calculation process, the formula can be specified with the formula option. See T_to_WVP for option types.
** Parameters: **
** Returns: **
Theta(T, P) Calculate the potential temperature [K] from the temperature [C] and the atmospheric pressure [hPa].
** Parameters: **
** Returns: **
Tlcl(T, Td) From the air temperature [K] and the dew point temperature [K], calculate the temperature [K] of the lifted condensation level. Please note that the unit of air temperature and dew point temperature is entered in [K]. It is used in the calculation process of equivalent potential temperature. See also Theta_e for the formula.
** Parameters: **
** Returns: **
Theta_e(T, Td, P, formula="Bolton") Equivalent potential temperature [K] is calculated from air temperature [C], dew point temperature [C], and atmospheric pressure [hPa]. It seems that there are multiple formulas for calculating the equivalent potential temperature, but here calculation method adopted by the Japan Meteorological Agency It conforms to. For details, please refer to the last page of the linked PDF.
In the above PDF, the value of $ R_ {d} \ / \ C_ {pd} $ is ** 0.2854 **, but I think it is usually ** 0.2857 **. I don't know why ** 0.2854 **, a typographical error, or a reason. The implementation adopted ** 0.2857 **.
Since the saturated water vapor pressure is calculated during the calculation process, the formula can be specified with the formula option. The default is "Bolton" following the equivalent potential temperature calculation formula of the Japan Meteorological Agency. See T_to_WVP for option types.
** Parameters: **
** Returns: **
SSI(P0, P1, T0, T1, Td0, formula="Bolton") Calculate SSI, which is a representative of atmospheric instability index. The inputs are the altitude pressure [hPa], temperature [C], and dew point temperature [C] of the air to be lifted, and the altitude pressure [hPa], temperature [C] of the lifted air. Normally, SSI is calculated at 850-500hPa, but it can be calculated at any barometric pressure level. Since the saturated water vapor pressure is calculated during the calculation process, the formula can be specified with the formula option. See T_to_WVP for option types.
** Parameters: **
** Returns: **
K_Index(T850, Td850, T700, Td700, T500) Calculates K-Index, one of the atmospheric instability indexes. The inputs are 850 hPa temperature [C] and dew point temperature [C], 700 hPa temperature [C] and dew point temperature [C], and 500 hPa temperature [C].
** Parameters: **
** Returns: **
MPS_to_KT(x) It is a unit conversion of speed such as wind speed. Convert m / s to knot.
** Parameters: **
** Returns: **
KT_to_MPS(x) It is a unit conversion of speed such as wind speed. Convert knot to m / s.
** Parameters: **
** Returns: **
M_to_FT(x) It is a unit conversion of length such as altitude. Convert meter to feet.
** Parameters: **
** Returns: **
FT_to_M(x) It is a unit conversion of length such as altitude. Convert feet to meter.
** Parameters: **
** Returns: **
degF_to_degC(x) It is a unit conversion of temperature. Converts Fahrenheit [F] to Celsius [C].
** Parameters: **
** Returns: **
degC_to_degF(x) It is a unit conversion of temperature. Converts Celsius [C] to Fahrenheit [F].
** Parameters: **
** Returns: **
As I mentioned at the beginning, I rewrote what I originally made as a Perl module to Python, so I completed it once.
In the future, we will also incorporate the following meteorological factors. I don't know if there is demand (laughs), but I would like to make it with the attention of weather experts.
Recommended Posts