def concx_to_vmrx(data, p_pascal, T_kelvin, conc_unit, mmol_var, mmol_air=None, to_unit=None): """ WORK IN PROGRESS. DO NOT USE! Convert mass concentration to volume mixing ratio (vmr) Parameters ---------- data : float or ndarray array containing vmr values p_pascal : float pressure in Pa of input data T_kelvin : float temperature in K of input data vmr_unit : str unit of input data mmol_var : float molar mass of variable represented by input data mmol_air : float, optional Molar mass of air. Uses average density of dry air if None. The default is None. to_unit : str, optional Unit to which output data is converted. If None, output unit is kg m-3. The default is None. Returns ------- float or ndarray input data converted to volume mixing ratio """ if mmol_air is None: from pyaerocom.molmasses import get_molmass mmol_air = get_molmass('air_dry') Rspecific = 287.058 # J kg-1 K-1 conversion_fac = 1 / cf_units.Unit('kg m-3').convert(1, conc_unit) # ============================================================================= # if conversion_fac != 1: # data *= conversion_fac #/ conversion_fac # ============================================================================= airdensity = p_pascal / (Rspecific * T_kelvin) # kg m-3 mulfac = mmol_var / mmol_air * airdensity # kg m-3 vmr = data / mulfac # unitless if to_unit is not None: conversion_fac *= cf_units.Unit('kg m-3').convert(1, to_unit) if not np.isclose(conversion_fac, 1, rtol=1e-7): vmr *= conversion_fac return vmr
def _vmr_to_conc_ghost_stats(data, mconcvar, vmrvar): mmol_air = get_molmass('air_dry') for stat in data: vmrdata = stat[vmrvar] meta = stat['meta'] p = meta['network_provided_volume_standard_pressure'] T = meta['network_provided_volume_standard_temperature'] mmol_var = get_molmass(vmrvar) unit_var = meta['var_info'][vmrvar]['units'] to_unit = const.VARS[mconcvar].units conc = vmrx_to_concx(vmrdata, p_pascal=p, T_kelvin=T, mmol_var=mmol_var, vmr_unit=unit_var, to_unit=to_unit) stat[mconcvar] = conc vi = {} vi.update(meta['var_info'][vmrvar]) vi['computed'] = True vi['units'] = to_unit meta['var_info'][mconcvar] = vi return data
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Thu Feb 4 14:51:48 2021 @author: jonasg """ from pyaerocom.mathutils import concx_to_vmrx from functools import partial from geonum.atmosphere import p0, T0_STD from pyaerocom.molmasses import get_molmass mmol_air = get_molmass('air_dry') mmol_o3 = get_molmass('o3')
def test_get_molmass(var_name, molmass): assert mm.get_molmass(var_name) == molmass