[ncl-talk] wrf_cape_3d dimensionality error

Mary Haley haley at ucar.edu
Fri Sep 11 09:57:29 MDT 2015


I don't know if this got addressed, but it's a WRF question, so I'm
forwarding to the wrfhelp folks.

--Mary


On Fri, Aug 28, 2015 at 2:44 PM, Andrea Jenney <andrea at atmos.colostate.edu>
wrote:

> Hi all,
>
> I am having a problem with the wrf_cape_3d code. When I run it, I get the
> following error:
>
> "If p,q,t,z are 3-dimensional (time x lev x lat x lon), psfc,zsfc must be
> 2-dimensional (lat x lon)"
>
> However, my p,q,t,and z variables are all 3-D and my psfc, and zsfc, are
> 2-D (as required).
>
> I am running NCL Version 6.2.1
>
> Below is a copy of my code:
>
>
> ;-------------------------------------------------------------------------------
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>
> ;-------------------------------------------------------------------------------
> begin
>
> ;-------------------------------------------------------------------------------
> ; Read netCDF files and extract variables
>
>   h48_t_file =
> addfile("/Users/andrea/Documents/gigaLES/data/TWPICE_gigaLES_3D_TABS_0000086400.nc","r")
>   h48_q_file =
> addfile("/Users/andrea/Documents/gigaLES/data/TWPICE_gigaLES_3D_QV_0000086400.nc","r")
>
>   h48_t = rm_single_dims(h48_t_file->TABS)      ; Read in variables and
> remove
>   h48_q = rm_single_dims(h48_q_file->QV)        ; singleton time dimension
>
>   p = h48_t_file->pres
>   x = h48_t_file->x
>   y = h48_t_file->y
>   z = h48_t_file->z
>
> ;-------------------------------------------------------------------------------
> ; Moisture is in specific humidity. Need to convert to mixing ratio
> ;   r = q / (1 - q)
>
> ;-------------------------------------------------------------------------------
>   h48_r = h48_q                 ; Copy metadata
>
>   h48_q_mask = h48_q ; Copy metadata
>   h48_q_mask at _FillValue = 0.0   ; Set FillValue to 0 to minimize
> computational problems with CAPE function
>   h48_q_mask = mask(h48_q,h48_q.eq.1,False)     ; Mask values of 1 to
> avoid dividing by zero
>
>   h48_r = (/ h48_q / (1 - h48_q_mask) /)        ; Do math on values only
>
> ;-------------------------------------------------------------------------------
> ; NCL CAPE function requires two additional values, which we define here
> ; 1. Surface height
>      zsf = 0.0
> ; 2. Surface pressures
>      psf = 1013.25
>
> ;-------------------------------------------------------------------------------
> ; Scalar values need to be conformed to a grid in order to be used by the
> function
> ; First, the surface height and pressure become 2D
>
>   ny = dimsizes(h48_t(:,0,0))           ; Find size of each dimension
>   nx = dimsizes(h48_t(0,:,0))
>   nz = dimsizes(h48_t(0,0,:))
>
>   zsf_grid1 = conform_dims( (/ny,nx,1/) , zsf , 2 )
>   psf_grid1 = conform_dims( (/ny,nx,1/) , psf , 2 )
>
> ; Remove the singleton dimension
>
>   zsf_grid = rm_single_dims(zsf_grid1)
>   psf_grid = rm_single_dims(psf_grid1)
>
> ; Second, the pressure and height become 3D
>
>   p_3d = conform_dims( (/ny,nx,nz/) , p , 2 )
>   z_3d = conform_dims( (/ny,nx,nz/) , z , 2 )
>
>
>
> ;-------------------------------------------------------------------------------
> ; Calculate CAPE and CIN using NCL's wrf_cape_3d function
>
>   cape_cin48 = wrf_cape_3d(p_3d,h48_t,h48_r,z_3d,zsf_grid,psf_grid,False)
>
>
> This is where I run into errors. Doing a printVarSummary on all of the
> variables used in the wf_cape_3d function gives:
>
> Variable: zsf_grid
> Type: float
> Total Size: 16777216 bytes
>             4194304 values
> Number of Dimensions: 2
> Dimensions and sizes: [2048] x [2048]
> Coordinates:
>
> Variable: psf_grid
> Type: float
> Total Size: 16777216 bytes
>             4194304 values
> Number of Dimensions: 2
> Dimensions and sizes: [2048] x [2048]
> Coordinates:
>
> Variable: p_3d
> Type: double
> Total Size: 8556380160 bytes
>             1069547520 values
> Number of Dimensions: 3
> Dimensions and sizes: [2048] x [2048] x [255]
> Coordinates:
>
> Variable: z_3d
> Type: double
> Total Size: 8556380160 bytes
>             1069547520 values
> Number of Dimensions: 3
> Dimensions and sizes: [2048] x [2048] x [255]
> Coordinates:
>
> Variable: h48_t
> Type: float
> Total Size: 4278190080 bytes
>             1069547520 values
> Number of Dimensions: 3
> Dimensions and sizes: [y | 2048] x [x | 2048] x [z | 255]
> Coordinates:
>             y: [  50..204750]
>             x: [  50..204750]
>             z: [  25..26685.83203]
> Number Of Attributes: 1
>   time :   20
>
> Variable: h48_r
> Type: float
> Total Size: 4278190080 bytes
>             1069547520 values
> Number of Dimensions: 3
> Dimensions and sizes: [y | 2048] x [x | 2048] x [z | 255]
> Coordinates:
>             y: [  50..204750]
>             x: [  50..204750]
>             z: [  25..26685.83203]
> Number Of Attributes: 2
>   _FillValue :  0
>   time :   20
>
>
>
>
> Thank you!
>
> Andrea
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150911/8f1affcc/attachment.html 


More information about the ncl-talk mailing list