Publish a Python module that calculates meteorological factors

Introduction

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.

Installation

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.

license

It is MIT licensed.

Main functions

  1. Functions that handle the wind --UV component of wind <=> Wind direction / speed conversion, 8/16 direction wind direction, cross wind, etc.
  2. A function that handles the amount of water in the atmosphere --Relative humidity <=> Dew point temperature conversion, saturated water vapor pressure, mixing ratio, etc.
  3. Function related to atmospheric stability --Potential temperature, equivalent potential temperature, SSI, K-Index, etc.
  4. Unit conversion -** m / s ** <=> ** knot ** conversion, ** meter ** <=> ** feet ** conversion, etc.

How to use

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.

Functions that handle the wind

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: **


A function that handles the amount of water in the atmosphere

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: $ {\ Large es = 6.1078 \ times 10 ^ {\ left (\ frac {7.5 T} {T + 237.3} \ right)}} $ WMO Approximation: $ {\ Large es = e ^ {\ left (19.482-\ frac {4303.4} {T + 243.5} \ right)}} $ Bolton's formula: $ {\ Large es = 6.112 \ times e ^ {\ left (\ frac {17.67 T} {T + 243.5} \ right)}} $

** 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: **


Function related to atmospheric instability

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.

{\Large T_{LCL} = \frac{1}{\frac{1}{Td-56}+\frac{ln(T\ /\ Td)}{800}}+56 }

** 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.

{\large \theta_{e} = T\left(\frac{1000}{P-e}\right)^\frac{R_{d}}{C_{pd}}\left(\frac{T}{T_{LCL}}\right)^{0.28w}exp\left(\left(\frac{3036.0}{T_{LCL}}-1.78\right)w(1+0.448w)\right) }

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: **


Unit conversion

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: **


About future version upgrades

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.

  1. LFC, CAPE, CIN, Lifted Index, etc.
  2. Advection, vorticity, wind vertical shear, stability, etc.
  3. Wet-bulb temperature, wet-bulb temperature, etc.
  4. Supercell index (SCP) and tornado index (STP) used in the United States, etc.

Recommended Posts

Publish a Python module that calculates meteorological factors
Create a Python module
A function that easily calculates a listwise removal tree (Python)
Use blender as a python module
The story of making a module that skips mail with python
[Python] A program that creates stairs with #
[Python] A program that calculates the number of chocolate segments that meet the conditions
[Python] A program that calculates the number of socks to be paired
Make a relation diagram of Python module
We have released a Python module that generates a regional mesh for Japan
The eval () function that calculates a string as an expression in python
[Python] Create a LineBot that runs regularly
A typed world that begins with Python
A program that plays rock-paper-scissors using Python
[Python] A program that rounds the score
I made a module PyNanaco that can charge nanaco credit with python
[Python] A program that calculates the difference between the total numbers on the diagonal line.
[Python] A program that calculates the number of updates of the highest and lowest records
Error when installing a module with Python pip
A memo that I wrote a quicksort in Python
[Python] A tool that allows intuitive relative import
[Python / Tkinter] A class that creates a scrollable Frame
A nice nimporter that connects nim and python
A program that removes duplicate statements in Python
How to add a Python module search path
"Python Kit" that calls a Python script from Swift
To add a module to python put in Julialang
Python: Create a class that supports unpacked assignment
[Python] A rough understanding of the logging module
A Vim plugin that automatically formats Python styles
I tried adding a Python3 module in C
Let's make a module for Python using SWIG
A story that was convenient when I tried using the python ip address module
Python module import
A module that makes it easier to write Perl-like filter programs in Python fileinput
Python collections module
[Python] A program that counts the number of valleys
Try to make a Python module in C language
A simple Python HTTP server that supports Range Requests
I made a VM that runs OpenCV for Python
I made a Python module to translate comment outs
Python that merges a lot of excel into one excel
From a book that programmers can learn ... (Python): Pointer
What's in that variable (when running a Python script)
Created a Python library DateTimeRange that handles time ranges
In Python, create a decorator that dynamically accepts arguments Create a decorator
[Python] How to write a docstring that conforms to PEP8
A server that echoes data POSTed with flask / python
[Python] A convenient library that converts kanji to hiragana
A memo that I touched the Datastore with python
[Python] A program that compares the positions of kangaroos.
Publish / upload a library created in Python to PyPI
A Python program that converts ical data into text
MALSS, a tool that supports machine learning in Python
A learning roadmap that allows you to develop and publish services from scratch with Python