Comprehensive Python library for meteorological data analysis and weather visualization.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
MetPy provides a comprehensive library of over 60 physical constants essential for meteorological calculations. All constants include proper units through Pint integration, ensuring dimensional analysis and preventing unit errors in calculations.
Fundamental properties of Earth used in atmospheric and geophysical calculations.
# Earth geometric properties
earth_avg_radius = 6371008.7714 * units.m
earth_gravity = 9.80665 * units('m/s^2')
earth_avg_angular_vel = 7292115e-11 * units('rad/s')
# Earth orbital properties
earth_sfc_avg_dist_sun = 149597870700.0 * units.m
earth_ellipsoid_flattening = 1/298.257223563
earth_eccentricity = 0.081819221456
# Solar geometry
earth_max_declination_angle = 23.45 * units.degreesProperties of the atmosphere essential for meteorological calculations.
# Dry air properties
dry_air_molecular_weight = 28.9647 * units('g/mol')
dry_air_gas_constant = 287.0 * units('J/(kg*K)')
dry_air_spec_heat_press = 1004.0 * units('J/(kg*K)') # Cp
dry_air_spec_heat_vol = 717.0 * units('J/(kg*K)') # Cv
dry_air_density_stp = 1.275 * units('kg/m^3')
# Atmospheric pressure
atmos_pressure_sea_level = 101325.0 * units.PaWater vapor and phase change properties for humidity and cloud physics calculations.
# Water vapor properties
water_molecular_weight = 18.0153 * units('g/mol')
water_gas_constant = 461.5 * units('J/(kg*K)')
# Latent heats
water_heat_vaporization = 2.501e6 * units('J/kg')
water_heat_fusion = 3.337e5 * units('J/kg')
water_heat_sublimation = 2.834e6 * units('J/kg')
# Specific heats
water_specific_heat = 4186.0 * units('J/(kg*K)')
ice_specific_heat = 2106.0 * units('J/(kg*K)')
# Densities
density_water = 1000.0 * units('kg/m^3')
density_ice = 917.0 * units('kg/m^3')
# Triple point properties
water_triple_point_temperature = 273.16 * units.K
water_triple_point_pressure = 611.657 * units.PaFundamental constants from physics used in atmospheric radiation and thermodynamics.
# Fundamental constants
boltzmann = 1.380649e-23 * units('J/K')
planck = 6.62607015e-34 * units('J*s')
avogadro = 6.02214076e23 * units('1/mol')
universal_gas_constant = 8.314462618 * units('J/(mol*K)')
# Electromagnetic constants
speed_of_light = 299792458.0 * units('m/s')
stefan_boltzmann = 5.670374419e-8 * units('W/(m^2*K^4)')
# Other constants
gravitational_constant = 6.67430e-11 * units('m^3/(kg*s^2)')Commonly used ratios and derived quantities for atmospheric calculations.
# Molecular weight ratios
epsilon = water_molecular_weight / dry_air_molecular_weight # ≈ 0.622
poisson_exponent = dry_air_gas_constant / dry_air_spec_heat_press # ≈ 0.286
# Heat capacity ratio
gamma = dry_air_spec_heat_press / dry_air_spec_heat_vol # ≈ 1.4
# Other derived quantities
dry_adiabatic_lapse_rate = earth_gravity / dry_air_spec_heat_press # ≈ 9.8 K/kmimport metpy.constants as constants
from metpy.units import units
# Use constants in calculations
pressure = 1000 * units.hPa
temperature = 20 * units.celsius
# Calculate air density using ideal gas law
density = pressure / (constants.dry_air_gas_constant * temperature.to('kelvin'))
print(f"Air density: {density}")
# Calculate scale height
scale_height = (constants.dry_air_gas_constant * temperature.to('kelvin')) / constants.earth_gravity
print(f"Scale height: {scale_height}")# Calculate potential temperature manually using constants
theta = temperature * (1000 * units.hPa / pressure) ** constants.poisson_exponent
print(f"Potential temperature: {theta}")
# Calculate saturation vapor pressure using Clausius-Clapeyron
e_sat = 611 * units.Pa * np.exp(
(constants.water_heat_vaporization * (temperature.to('kelvin') - 273.15 * units.K)) /
(constants.water_gas_constant * temperature.to('kelvin') * 273.15 * units.K)
)
print(f"Saturation vapor pressure: {e_sat}")# Convert between different temperature scales
temp_celsius = 25 * units.celsius
temp_kelvin = temp_celsius.to('kelvin')
temp_fahrenheit = temp_celsius.to('fahrenheit')
# Energy conversions
kinetic_energy = 0.5 * 1000 * units.kg * (10 * units('m/s'))**2
kinetic_energy_cal = kinetic_energy.to('calorie')
# Pressure conversions using standard atmosphere
pressure_mb = 850 * units.mbar
pressure_pa = pressure_mb.to('pascal')
pressure_inhg = pressure_mb.to('inch_Hg')# Import all constants
import metpy.constants as constants
# Access individual constants
g = constants.earth_gravity
R_d = constants.dry_air_gas_constant
L_v = constants.water_heat_vaporization
# Use in meteorological calculations
# Hydrostatic equation: dp/dz = -ρg
# Ideal gas law: p = ρRT
# Clausius-Clapeyron: de_s/dT = L_v*e_s/(R_v*T^2)# Import specific constants directly
from metpy.constants import earth_gravity, dry_air_gas_constant
from metpy.constants import water_heat_vaporization as L_v
# Access through metpy.constants namespace
import metpy
g = metpy.constants.earth_gravity# All constants are Pint Quantity objects with appropriate units
from pint import Quantity
# Example constant types
earth_gravity: Quantity # Length/Time^2 units
dry_air_gas_constant: Quantity # Energy/(Mass*Temperature) units
water_heat_vaporization: Quantity # Energy/Mass units
atmos_pressure_sea_level: Quantity # Pressure units