NCL Home > Documentation > Functions > Meteorology

prcwater_dp

Computes total column precipitable water of the rightmost dimension.

Prototype

	function prcwater_dp (
		q  : numeric,  
		p  : numeric   
	)

	return_val  :  numeric

Arguments

q

An array of any dimensionality or a scalar value equal to the specific humidity in kg/kg. The rightmost dimension must be the level dimension.

p

An array of the same size as q or a one-dimensional array with only a level dimension equal to the pressure layer thickness in Pa.

Return value

An array of the same size as q minus the rightmost dimension. Units are kg/m2.

Description

Computes total column precipitable water of the rightmost dimension.

Background: This function was one of the original suite of meteorological functions. For historical reasons these original NCL functions operated upon the rightmost dimension for efficiency. Often, this required that the input variables be reordered via dimension reordering. This can be a nuisance and lead to cumbersome code. An adventage of prcwater_dp is that the dp can be one-dimensional [*].

Example 4 shows another approach to calculating total precipitable water.

See Also

dpres_plevel, dpres_hybrid_ccm, dpres_plevel_Wrap, dim_sum_n, dim_sum_n_Wrap, confirm_dims, confirm

Examples

Example 1

Let q and dp be one-dimensional. No dimension reordering is necessary. Units must be converted to those expected. The calculated 'pw' will be a scalar. Attributes are added for completeness.

  dp = (/ 10., 30. , 50., ..., 100., 50., 50, 50./)   ; hPa [mb]
  q  = (/ 20.8,19.4,16.5, ..., 1.7,1.0,0.5,0.1   /)   ; g/kg
 
  dp = dp*100.   ; convert hPa to pascals
  q  = q*0.001   ; convert g/kg to kg/kg
  
  pw = prcwater_dp (q,dp)          ; pw [kg/m2]
  pw@long_name = "total column precipitable water"
  pw@units     = "kg/m2"

Example 2

Let q be four-dimensional with named dimensions: q(time,lev,lat,lon). Reorder the array so that lev is the rightmost dimension. The units are g/kg. The must be converted to (kg/kg). Hence the conversion factor. dp is one-dimensional with units of pascals (Pa). pw will be three-dimensional with dimensions time,lat,lon. The same dp is used at all locations. Add meta data (attributes and coordinate information).

  cf = 0.001                ; convert g/kg to kg/kg
  pw = prcwater_dp (q(time|:,lat|:,lon|:,lev|:)*cf, dp)
  pw@long_name = "total column precipitable water"
  pw@units     = "kg/m2"
           
  copy_VarCoords(q(time,0,lat,lon), pw) ; add coordinate information
  printVarSummary(pw)     ; pw(time,lat,lon)

Example 3:

Let q(time,lev,lat,lon) with units (kg/kg). dp (Pa) is calculated from the hybrid coefficients using dpres_hybrid_ccm. Different layer thicknesses are used at each grid point. This example uses dimension reordering.

  q    = f->Q    ; specific humidity [kg/kg];  (time,lev,lat,lon)
                 ;                             (ntim,klev,nlat,mlon)
  hyai = f->hyai ; interface hybrid coefficients; klevi= klev+1
  hybi = f->hybi ;  
  ps   = f->PS   ; surface pressure [Pa]      ; (time,lat,lon)
  p0   = 100000. ; since ps is in Pa 
       
  dp   = dpres_hybrid_ccm(ps,p0,hyai,hybi)   ; dp(ntime,klevi-1,nlat,nlon)
  copy_VarCoords(q,dp)    ; dp(time,lev,lat,lon)

  pw = prcwater_dp(q(time|:,lat|:,lon|:,lev|:),dp(time|:,lat|:,lon|:,lev|:))    
  pw@long_name = "total column precipitable water"
  pw@units     = "kg/m2"
Example 4:

This illustrates another approach to calculating total precipitable water. It illustrates a step-by-step procedure with code documentation using attributes. Dimension reordering is not used.


  diri = "./"
  fili = "camaqua.cam2.h1.1985-09-01-00000.nc"
  pthi = diri+fili
  f    = addfile(pthi, "r")

  q    = f->Q    ; specific humidity [kg/kg]: (time,lev , lat, lon)
                 ;                            (ntim,klev,nlat,mlon) ; dimension sizes
                 ;                            ( 0    1     2    3 ) ; dimension numbers
  hyai = f->hyai ; interface hybrid coefficients (klevi = klev+1)
  hybi = f->hybi

  ps   = f->PS   ; surface pressure [Pa]: (time,lat,lon)
  p0   = 100000. ; since ps is in Pa 

  dp   = dpres_hybrid_ccm(ps,p0,hyai,hybi)    ; (ntim,klev,nlat,mlon): no meta data
                                               ; for clarity; add meta data; not necessary
  copy_VarCoords(q,dp)                        ; add coordinate info (time,lev,lat,lon)
  dp@long_name = "hybrid layer thickness"      ; add attributes
  dp@units     = ps@units   

  qdp  = q*dp                                  ; (ntim,klev,nlat,mlon): no meta data
  copy_VarCoords(q,qdp)                       ; for clarity; add meta data; not necessary
  qdp@long_name = "q*dp"
 ;qdp@units     = "(kg/kg) Pa"                 ; since Pa=[kg/(m-s2)] 
  qdp@units     = "kg/m-s2"                    ; (kg/kg)  [kg/(m-s2)]" => "kg/m-s2"

  g   = 9.80665                                ; [m/s2] gravity at 45 deg lat used by the WMO
  qdp = qdp/g                                  ; [kg/m-s2]/[m/s2] => kg/m2
  qdp@units = "mm"                             ; [kg/m2][1000 mm/m][(1/1000) m3/kg] ==> mm

  pw = dim_sum_n_Wrap(qdp, 1)                ; (time,lat,lon)                 
  pw@long_name = "total column precipitable water"
  pw@units     = "mm"

  printVarSummary(pw)       
  printMinMax(pw,0)
  print("---")

The output will be:
  
  Variable: pw
  Type: float
  Total Size: 983040 bytes
              245760 values
  Number of Dimensions: 3
  Dimensions and sizes:	[time | 30] x [lat | 64] x [lon | 128]
  Coordinates: 
              time: [   0..  29]
              lat: [-87.86379883923262..87.86379883923262]
              lon: [   0..357.1875]
  Number Of Attributes: 3
    long_name :total column precipitable water
    units : mm
    sum_op_ncl :	dim_sum_n over dimension(s): lev
  
  (0)	total column precipitable water: min=0.0811549   max=101.736