NCL Home> Documentation> Functions> Meteorology

mixhum_convert

Convert mixing ratio to specific humidity or vice-versa.

Available in version 6.5.0 and later.

Prototype

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" ; This library is automatically loaded
 ; from NCL V6.2.0 onward.
 ; No need for user to explicitly load.
	function mixhum_convert (
		wq : numeric, ; float, double, integer only
		wqType [1] : string, 
		iounit [2] : integer 
	)
	return_val [dimsizes(wq)] : float or double

Arguments

wq

A scalar or array containing mixing ratio or specific humidity (units: kg/kg, g/kg).

wqType

  • wqType="w" or "W" means that wq is mixing ratio and a conversion to specific humidity is desired.
  • wqType="q" or "Q" means that wq is specific humidity and a conversion to mixing ratio is desired.

iounit

An integer array of length 2 which specifies the units of the input wq and returned variable

  • iounit(0)=0 input wq are kg/kg
  • iounit(0)=1 input wq are g/kg

  • iounit(1)=0 returned units are kg/kg
  • iounit(1)=1 returned units are g/kg

Return value

A variable of the same size and shape as wq.

Description

The mixing ratio and specific humidity are commonly denoted as w and q, respectively. As noted in the Glossary of Meteorology, these quantities are nearly identical. Hence, w and q are often used interchangeably. Still, for certain applications, it may be appropriate to make the conversion. Specifically:

  q = w/(1+w) [switch=True] <===> w = q/(1-q) [switch=False]

See Also

mixhum_ptd, mixhum_ptrh, relhum

Examples

Example 1: Convert mixing ratio to specific humidity and vice-versa.

 W = 15.2 ; g/kg iounit(0)=1
 q = mixhum_convert(W, "w", (/1,1/) ; q = 14.97; return g/kg, iounit(1)=1
 printVarSummary(q)
 w = mixhum_convert(q, "q", (/1,1/) ; w = 15.2 ; return g/kg, iounit(1)=1 
 printVarSummary(w)

Example 2: Read specific humidity (Q; kg/kg). Convert to mixing ratio and vice-versa.

 a = addfile("cam35.h0.0008-07.nc","r") 
 Q = a->Q ; kg/kg iounit(0)=0
 w = mixhum_convert(Q, "q", (/0,0/); return kg/kg, iounit(1)=0 
 printVarSummary(w) ; w(time,lat,lon)
 q = mixhum_convert(w, "w" , (/0,1/); return kg/kg, iounit(1)=1 
 printVarSummary(q) ; q(time,lat,lon)
The edited output:
 Variable: Q
 Type: float
 Total Size: 1437696 bytes
 359424 values
 Number of Dimensions: 4
 Dimensions and sizes:	[time | 1] x [lev | 26] x [lat | 96] x [lon | 144]
 Coordinates: 
 time: [3132..3132]
 lev: [3.54463800000001..992.5560999999998]
 lat: [ -90..89.99999999999999]
 lon: [ 0..357.5]
 Number Of Attributes: 3
 units :	kg/kg
 long_name :	Specific humidity
 cell_method :	time: mean
 (0)	Specific humidity (kg/kg) : min=4.95837e-07 max=0.0220418
 
 Variable: w
 Type: float
 Total Size: 1437696 bytes
 359424 values
 Number of Dimensions: 4
 Dimensions and sizes:	[time | 1] x [lev | 26] x [lat | 96] x [lon | 144]
 Coordinates: 
 time: [3132..3132]
 lev: [3.54463800000001..992.5560999999998]
 lat: [ -90..89.99999999999999]
 lon: [ 0..357.5]
 Number Of Attributes: 4
 long_name :	mixing ratio
 equation :	w=q/(1-q)
 units :	kg/kg
 NCL :	mixhum_convert
 (0)	mixing ratio (kg/kg) : min=4.95838e-07 max=0.0225386
 
 
 Variable: q 
 Type: float
 Total Size: 1437696 bytes
 359424 values
 Number of Dimensions: 4
 Dimensions and sizes:	[time | 1] x [lev | 26] x [lat | 96] x [lon | 144]
 Coordinates: 
 time: [3132..3132]
 lev: [3.54463800000001..992.5560999999998]
 lat: [ -90..89.99999999999999]
 lon: [ 0..357.5]
 Number Of Attributes: 4
 long_name :	specific humidity
 equation :	q=w/(1+w)
 units :	 g/kg
 NCL :	mixhum_convert
 (0)	specific humidity (kg/kg) : min=4.95837e-04 max=2.20418


AltStyle によって変換されたページ (->オリジナル) /