Science projects with the Python MetPy library
Homework Helper

© Lead Image © Pavel Romanchenko, 123rf.com
MetPy can help you answer your kids' science questions.
Are you stumped by your kids' homework? Sometimes answering their science questions can be quite challenging. Luckily, some great resources and software packages can help parents out of a homework jam. A good example is the MetPy Python library [1], which has some awesome thermodynamic and weather functions.
In this article, I introduce the MetPy library and show how it can be used to solve questions like: Can you make snow when it's above freezing? How much thinner is the air with altitude? How do you calculate wind chill?
Getting Started
To install the MetPy Python library, enter:
pip install metpy
One of nice things about MetPy is that it manages scientific units, so a variable is defined with both its value and units. In the code
>>> from metpy.units import units >>> tempToday = [40] * units.degF >>> tempToday.to(units.degC) <Quantity([4.44444444], 'degree_Celsius')>
the units
module makes a simple temperature conversion. In this example, a temperature of 40°F is converted to 4.4°C with the to()
method.
You can also do some interesting mixing of units in math calculations. For example, you can add 6 feet and 4 meters:
>>> print( [6] * units.feet + [4] * units.m) [19.123359580052494] foot
MetPy has a very large selection of thermodynamic and weather functions, which I demonstrate in the next sections.
Can You Make Snow When It's Above Freezing?
Ski resorts can make snow by forcing water and pressurized air through a "snow gun" (Figure 1). Snowmaking [2] can be an expensive operation, but it allows ski resorts to extend their season.
When you get a weather forecast, the temperature is given as the ambient, or dry-bulb, temperature. The wet-bulb temperature takes the dry air temperature and relative humidity into account. The wet-bulb temperature is always less than the outside temperature, so snowmaking can take placer if the wet-bulb temperature is below -2.5°C or 27.5°F.
MetPy has a number of functions that can find the humidity and wet-bulb temperature (wet_bulb_temperature()
), which just needs the pressure, dry temperature, and dew point.
In Listing 1, the temperature is below freezing, but it's not possible to make snow, because the wet-bulb temperature is only -0.6°C (not the required -2.5°C).
Listing 1
Wet-Bulb Temp
Knowing that -2.5°C (27.5°F) is the wet-bulb temperature upper limit for snowmaking, the relative_humidity_wet_psychrometric
function can be used to create a curve of humidity and dry temperature points that shows where it is possible to make snow (Figure 2).
Listing 2 shows how to use the MetPy library to find when snow can be made. The code iterates between the temperatures of -10°C to 10°C (line 18), getting the relative humidity with the relative_humidity_wet_psychrometric
call (line 21). The relative humidity is multiplied by 100 to get a percentage and is made unitless by the to_tuple()[0]
method (line 23). The results are plotted by Matplotlib library functions (lines 29-34).
Listing 2
When to Make Snow
From the data, you can see that if the humidity is low, it is possible to make snow, even when the temperature is above freezing (+4°C is the typical cut-off temperature).
How Much Thinner is the Air with Altitude?
Everyone knows the air is thinner when you're in an airplane, but how much thinner is it in Denver or Mexico City compared with New York City?
Again, MetPy can help. The height_to_pressure_std
function calculates a pressure value by altitude. The to()
method converts the pressure to standard atmospheres (Listing 3).
Listing 3
Air Pressure by Altitude
The results show that the air pressure in Denver is 82 percent that of New York's, or 18 percent thinner, and Mexico City's atmosphere is 76 percent that of New York's, or 24 percent thinner.
Listing 4 uses the height_to_pressure_std
function to create a chart (Figure 3) of atmospheric pressure between sea level and the top of Mt. Everest (29,000ft). At the top of Mt. Everest, the air is 70 percent thinner than at sea level!
Listing 4
Air Thinning with Altitude
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Direct Download
Read full article as PDF:
Price $2.95
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Find SysAdmin Jobs
News
-
KDE Plasma 5.27 Beta is Ready for Testing
The latest beta iteration of the KDE Plasma desktop is now available and includes some important additions and fixes.
-
Netrunner OS 23 Is Now Available
The latest version of this Linux distribution is now based on Debian Bullseye and is ready for installation and finally hits the KDE 5.20 branch of the desktop.
-
New Linux Distribution Built for Gamers
With a Gnome desktop that offers different layouts and a custom kernel, PikaOS is a great option for gamers of all types.
-
System76 Beefs Up Popular Pangolin Laptop
The darling of open-source-powered laptops and desktops will soon drop a new AMD Ryzen 7-powered version of their popular Pangolin laptop.
-
Nobara Project Is a Modified Version of Fedora with User-Friendly Fixes
If you're looking for a version of Fedora that includes third-party and proprietary packages, look no further than the Nobara Project.
-
Gnome 44 Now Has a Release Date
Gnome 44 will be officially released on March 22, 2023.
-
Nitrux 2.6 Available with Kernel 6.1 and a Major Change
The developers of Nitrux have officially released version 2.6 of their Linux distribution with plenty of new features to excite users.
-
Vanilla OS Initial Release Is Now Available
A stock GNOME experience with on-demand immutability finally sees its first production release.
-
Critical Linux Vulnerability Found to Impact SMB Servers
A Linux vulnerability with a CVSS score of 10 has been found to affect SMB servers and can lead to remote code execution.
-
Linux Mint 21.1 Now Available with Plenty of Look and Feel Changes
Vera has arrived and although it is still using kernel 5.15, there are plenty of improvements sure to please everyone.