Re: wind_2.ncl script

From: Mittal, Moti <mmittal_at_nyahnyahspammersnyahnyah>
Date: Fri, 10 Apr 2009 17:36:30 -0400

Mary,

I am now not getting any errors after making changes in the script as you suggested.
In the plot I see the world map. I was expecting a region of India between 11 degree north to 14 degree north
and 78 degree east to 82 degree east.

Following is the modified script.

 1 ;*************************************************
  2 ; wind_2.ncl
  3 ;*************************************************
  4 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
  5 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
  6 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
  7 load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
  8 ;*************************************************
  9 begin
 10 ;*************************************************
 11 ; open file and read in data: data are on a gaussian grid
 12 ;*************************************************
 13 f = addfile ("wrfout_d01_2007-01-31_12.nc", "r")
 14 lat2d = f->XLAT(0,:,:)
 15 lon2d = f->XLONG(0,:,:)
 16 ; u = f->U ; (time,lat,lon)
 17 ; printVarSummary (u)
 18 ; v = f->V
 19 ; printVarSummary (v)
 20 u = wrf_user_getvar(f,"U10",0) ; 3D U at mass points
 21 v = wrf_user_getvar(f,"V10",0) ; 3D V at mass points
 22 ; printVarSummary (u)
 23 ; printVarSummary (v)
 24 ;*************************************************
 25 ; calculate vorticity: Wrap version maintains meta data
 26 ;*************************************************
 27 vrt = uv2vrG_Wrap(u,v)
 28
 29 ;*************************************************
 30 ; calculate rotational wind component
 31 ; --
 32 ; note: the calculation uses a procedure, so memory
 33 ; must be preallocated.
 34 ;*************************************************
 35 ur = new ( dimsizes(u), typeof(u) )
 36 vr = new ( dimsizes(v), typeof(v) )
 37 ; ur = new ( dimsizes(u), typeof(u), u@_FillValue )
 38 ; vr = new ( dimsizes(v), typeof(v), v@_FillValue )
 39 ur_at_lat2d = lat2d
 40 ur_at_lon2d = lon2d
 41 vr_at_lat2d = lat2d
 42 vr_at_lon2d = lon2d
 43
 44 vr2uvg(vrt, ur,vr)
 45 ur_at_long_name = "Zonal Rotational Wind"
 46 ur_at_units = u_at_units
 47 vr_at_long_name = "Meridional Rotational Wind"
 48 vr_at_units = v_at_units
 49 copy_VarCoords(u, ur )
 50 copy_VarCoords(u, vr )
 51 ;*************************************************
 52 ; plot results
 53 ;*************************************************
 54 wks = gsn_open_wks("x11","wind") ; open workstation
 55
 56 res = True
 57
 58 res_at_vcRefMagnitudeF = 5. ; make vectors larger
  59 res_at_vcRefLengthF = 0.050 ; reference vector
 60 res_at_vcGlyphStyle = "CurlyVector" ; turn on curly vectors
 61 res_at_vcMinDistanceF = 0.022 ; thin the vectors
 62 res_at_vcRefAnnoOrthogonalPosF = -1.0 ; move ref vector up
 63 res_at_gsnLeftString = "Rotational Wind"
 64 ; plot 1st time step
 65 ; plot= gsn_csm_vector_map_ce(wks,ur(0,:,:),vr(0,:,:),res)
 66
 67 plot= gsn_csm_vector_map_ce(wks,ur,vr,res)
 68
 69 end
 70

Thank you for your help and advice.

Moti
Professor, Department of Environment and Occupational Health
College of Public Health
University of South Florida
13201 Bruce B. Downs Blvd., MDC56
Tampa, Fl 33612-3805

Tel: (813) 974-9571
Fax: (813) 974-4986
Email: mmittal_at_health.usf.edu
________________________________________
From: Mary Haley [haley_at_ucar.edu]
Sent: Friday, April 10, 2009 4:53 PM
To: Mittal, Moti
Cc: ncl-talk_at_ucar.edu
Subject: Re: wind_2.ncl script

Sorry about that, I forgot this was WRF data.

You have 2D lat/lon variables, so you need to use the special "lat2d"
and "lon2d" attributes.

You code will need to have the following lines added:

  lat2d = f->XLAT ; I assume this is 2D? If not, subscript with
                        ; lat2d = f->XLAT(0,:,:)
  lon2d = f->XLONG ; Ditto for 2D or 3D

Then, after ur and vr are calculated, add the lines:

    ur_at_lat2d = lat2d
    ur_at_lon2d = lon2d
    vr_at_lat2d = lat2d
    vr_at_lon2d = lon2d

This will signal to the gsn_csm_xxxx script that you don't have 1D
coordinate arrays, but rather 2D lat/lon arrays, and it will use
these instead.

--Mary

On Fri, 10 Apr 2009, Mittal, Moti wrote:

> Mary,
>
> Your advice was helpful but now I am getting Latitude Longtitude problem.
> Output is:
>
> [mmittal_at_localhost ~/NCL]$ ncl wind_2.ncl
> Copyright (C) 1995-2009 - All Rights Reserved
> University Corporation for Atmospheric Research
> NCAR Command Language Version 5.1.0
> The use of this software is governed by a License Agreement.
> See http://www.ncl.ucar.edu/ for more details.
> (0) check_for_y_lat_coord: Warning: Data either does not contain a valid latitude coordinate array or doesn't contain one at all.
> (0) A valid latitude coordinate array should have a 'units' attribute equal to one of the following values:
> (0) 'degrees_north' 'degrees-north' 'degree_north' 'degrees north' 'degrees_N' 'Degrees_north' 'degree_N' 'degreeN' 'degreesN' 'deg north'
> (0) check_for_lon_coord: Warning: Data either does not contain a valid longitude coordinate array or doesn't contain one at all.
> (0) A valid longitude coordinate array should have a 'units' attribute equal to one of the following values:
> (0) 'degrees_east' 'degrees-east' 'degree_east' 'degrees east' 'degrees_E' 'Degrees_east' 'degree_E' 'degreeE' 'degreesE' 'deg east'
> [mmittal_at_localhost ~/NCL]$
>
> Where do I put the lat long attributes?
>
> Thank you for your help.
>
> moti
> Professor, Department of Environment and Occupational Health
> College of Public Health
> University of South Florida
> 13201 Bruce B. Downs Blvd., MDC56
> Tampa, Fl 33612-3805
>
> Tel: (813) 974-9571
> Fax: (813) 974-4986
> Email: mmittal_at_health.usf.edu
> ________________________________________
> From: Mary Haley [haley_at_ucar.edu]
> Sent: Friday, April 10, 2009 3:30 PM
> To: Mittal, Moti
> Cc: Dennis Shea; ncl-talk_at_ucar.edu
> Subject: Re: wind_2.ncl script
>
> On Fri, 10 Apr 2009, Mittal, Moti wrote:
>
>> Dennis,
>>
>> Thank you for your help. I could fix the earlier error by changing the script in the following way.
>> Now I am getting different error in FillValue as:
>>
>> [mmittal_at_localhost ~/NCL]$ ncl wind_2.ncl
>> Copyright (C) 1995-2009 - All Rights Reserved
>> University Corporation for Atmospheric Research
>> NCAR Command Language Version 5.1.0
>> The use of this software is governed by a License Agreement.
>> See http://www.ncl.ucar.edu/ for more details.
>>
>>
>> Variable: u
>> Type: float
>> Total Size: 9604 bytes
>> 2401 values
>> Number of Dimensions: 2
>> Dimensions and sizes: [south_north | 49] x [west_east | 49]
>> Coordinates:
>> Number Of Attributes: 6
>> coordinates : XLONG XLAT
>> stagger :
>> units : m s-1
>> description : U at 10 M
>> MemoryOrder : XY
>> FieldType : 104
>>
>>
>> Variable: v
>> Type: float
>> Total Size: 9604 bytes
>> 2401 values
>> Number of Dimensions: 2
>> Dimensions and sizes: [south_north | 49] x [west_east | 49]
>> Coordinates:
>> Number Of Attributes: 6
>> coordinates : XLONG XLAT
>> stagger :
>> units : m s-1

>> description : V at 10 M
>> MemoryOrder : XY
>> FieldType : 104
>> warning:Attempt to reference attribute (_FillValue) which is undefined
>> warning:Attempt to reference attribute (_FillValue) which is undefined
>> fatal:Number of subscripts do not match number of dimensions of variable,(3) Subscripts used, (2) Subscripts expected
>> fatal:Execute: Error occurred at or near line 57 in file wind_2.ncl
>
> Noti,
>
> Your u and v don't appear to have missing values (_FillVaue), so try:
>
> ur = new ( dimsizes(u), typeof(u) )
> vr = new ( dimsizes(v), typeof(v) )
>
> Also, the error for line 57 is telling you exactly what the problem
> is. It says you are trying to subscript a variable as if it
> has three dimensions, when it really only has two.
>
> Do this instead:
>
> plot= gsn_csm_vector_map_ce(wks,ur,vr,res)
>
> --Mary
>
>
>>
>>
>> wind_2.ncl script
>> 1 ;*************************************************
>> 2 ; wind_2.ncl
>> 3 ;*************************************************
>> 4 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>> 5 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>> 6 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>> 7 load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
>> 8 ;*************************************************
>> 9 begin
>> 10 ;*************************************************
>> 11 ; open file and read in data: data are on a gaussian grid
>> 12 ;*************************************************
>> 13 f = addfile ("wrfout_d01_2007-01-31_12.nc", "r")
>> 14 ; u = f->U ; (time,lat,lon)
>> 15 ; printVarSummary (u)
>> 16 ; v = f->V
>> 17 ; printVarSummary (v)
>> 18 u = wrf_user_getvar(f,"U10",0) ; 3D U at mass points
>> 19 v = wrf_user_getvar(f,"V10",0) ; 3D V at mass points
>> 20 printVarSummary (u)
>> 21 printVarSummary (v)
>> 22 ;*************************************************
>> 23 ; calculate vorticity: Wrap version maintains meta data
>> 24 ;*************************************************
>> 25 vrt = uv2vrG_Wrap(u,v)
>> 26
>> 27 ;*************************************************
>> 28 ; calculate rotational wind component
>> 29 ; --
>> 30 ; note: the calculation uses a procedure, so memory
>> 31 ; must be preallocated.
>> 32 ;*************************************************
>> 33 ur = new ( dimsizes(u), typeof(u), u@_FillValue )
>> 34 vr = new ( dimsizes(v), typeof(v), v@_FillValue )
>> 35
>> 36 vr2uvg(vrt, ur,vr)
>> 37 ur_at_long_name = "Zonal Rotational Wind"
>> 38 ur_at_units = u_at_units
>> 39 vr_at_long_name = "Meridional Rotational Wind"
>> 40 vr_at_units = v_at_units
>> 41 copy_VarCoords(u, ur )
>> 42 copy_VarCoords(u, vr )
>> 43 ;*************************************************
>> 44 ; plot results
>> 45 ;*************************************************
>> 46 wks = gsn_open_wks("x11","wind") ; open workstation
>> 47
>> 48 res = True
>> 49
>> 50 res_at_vcRefMagnitudeF = 5. ; make vectors larger
>> 51 res_at_vcRefLengthF = 0.050 ; reference vector
>> 52 res_at_vcGlyphStyle = "CurlyVector" ; turn on curly vectors
>> 53 res_at_vcMinDistanceF = 0.022 ; thin the vectors
>> 54 res_at_vcRefAnnoOrthogonalPosF = -1.0 ; move ref vector up
>> 55 res_at_gsnLeftString = "Rotational Wind"
>> 56 ; plot 1st time step
>> 57 plot= gsn_csm_vector_map_ce(wks,ur(0,:,:),vr(0,:,:),res)
>> 58
>> 59 end
>>
>>
>> Moti
>> Professor, Department of Environment and Occupational Health
>> College of Public Health
>> University of South Florida
>> 13201 Bruce B. Downs Blvd., MDC56
>> Tampa, Fl 33612-3805
>>
>> Tel: (813) 974-9571
>> Fax: (813) 974-4986
>> Email: mmittal_at_health.usf.edu
>> ________________________________________
>> From: Dennis Shea [shea_at_ucar.edu]
>> Sent: Friday, April 10, 2009 12:44 PM
>> To: Mittal, Moti
>> Cc: ncl-talk_at_ucar.edu
>> Subject: Re: wind_2.ncl script
>>
>> The WRF model has u and v on different grids.
>> The arrays are different sizes.
>>
>> http://www.ncl.ucar.edu/Document/Functions/wrf.shtml
>>
>> See the WRF WWW. It has a number of examples:
>>
>> http://www.mmm.ucar.edu/wrf/OnLineTutorial/Graphics/NCL/NCL_examples.htm
>>
>> The following places the winds on a common grid.
>>
>>
>>
>> u = wrf_user_getvar(a,"ua",it) ; 3D U at mass points
>> v = wrf_user_getvar(a,"va",it) ; 3D V at mass points
>>
>>
>> Generally, WRF related question should be sent to wrfhelp_at_ucar.edu
>>
>> Good luck
>>
>> Mittal, Moti wrote:
>>> Hi Dennis,
>>>
>>> I used printVarSummary for u and v and had the following output.
>>> It is showing [south_north | 49] x [west_east_stag | 50] for u
>>> and [south_north_stag | 50] x [west_east | 49] for v.
>>> My dimensions from wrfout header are as follows:
>>>
>>> 1 netcdf wrfout_d01_2007-01-31_12 {
>>> 2 dimensions:
>>> 3 Time = UNLIMITED ; // (6 currently)
>>> 4 DateStrLen = 19 ;
>>> 5 west_east = 49 ;
>>> 6 south_north = 49 ;
>>> 7 bottom_top = 27 ;
>>> 8 bottom_top_stag = 28 ;
>>> 9 soil_layers_stag = 4 ;
>>> 10 west_east_stag = 50 ;
>>> 11 south_north_stag = 50 ;
>>> 12 emissions_zdim = 1 ;
>>> 13 klevs_for_dust = 1 ;
>>> 14 dust_errosion_dimension = 3 ;
>>>
>>> What am I doing wrong? I am using polar stereographic projection.
>>> I am also attaching the script at the end of this message.
>>>
>>> Thank you for your help.
>>> Moti
>>>
>>> [mmittal_at_localhost ~/NCL]$ !ncl
>>> ncl wind_2.ncl
>>> Copyright (C) 1995-2009 - All Rights Reserved
>>> University Corporation for Atmospheric Research
>>> NCAR Command Language Version 5.1.0
>>> The use of this software is governed by a License Agreement.
>>> See http://www.ncl.ucar.edu/ for more details.
>>>
>>>
>>> Variable: u
>>> Type: float
>>> Total Size: 1587600 bytes
>>> 396900 values
>>> Number of Dimensions: 4
>>> Dimensions and sizes: [Time | 6] x [bottom_top | 27] x [south_north | 49] x [west_east_stag | 50]
>>> Coordinates:
>>> Number Of Attributes: 6
>>> FieldType : 104
>>> MemoryOrder : XYZ
>>> description : x-wind component
>>> units : m s-1
>>> stagger : X
>>> coordinates : XLONG_U XLAT_U
>>>
>>>
>>> Variable: v
>>> Type: float
>>> Total Size: 1587600 bytes
>>> 396900 values
>>> Number of Dimensions: 4
>>> Dimensions and sizes: [Time | 6] x [bottom_top | 27] x [south_north_stag | 50] x [west_east | 49]
>>> Coordinates:
>>> Number Of Attributes: 6
>>> FieldType : 104
>>> MemoryOrder : XYZ
>>> description : y-wind component
>>> units : m s-1
>>> stagger : Y
>>> coordinates : XLONG_V XLAT_V
>>> fatal:uv2vrF: The input arrays must have the same dimension sizes
>>> fatal:Execute: Error occurred at or near line 2277 in file $NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl
>>>
>>> fatal:Execute: Error occurred at or near line 20 in file wind_2.ncl
>>>
>>> wind_2.ncl: script
>>>
>>> 1 ;*************************************************
>>> 2 ; wind_2.ncl
>>> 3 ;*************************************************
>>> 4 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>>> 5 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>>> 6 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>>> 7 ;*************************************************
>>> 8 begin
>>> 9 ;*************************************************
>>> 10 ; open file and read in data: data are on a gaussian grid
>>> 11 ;*************************************************
>>> 12 f = addfile ("wrfout_d01_2007-01-31_12.nc", "r")
>>> 13 u = f->U ; (time,lat,lon)
>>> 14 printVarSummary (u)
>>> 15 v = f->V
>>> 16 printVarSummary (v)
>>> 17 ;*************************************************
>>> 18 ; calculate vorticity: Wrap version maintains meta data
>>> 19 ;*************************************************
>>> 20 vrt = uv2vrG_Wrap(u,v)
>>> 21
>>> 22 ;*************************************************
>>> 23 ; calculate rotational wind component
>>> 24 ; --
>>> 25 ; note: the calculation uses a procedure, so memory
>>> 26 ; must be preallocated.
>>> 27 ;*************************************************
>>> 28 ur = new ( dimsizes(u), typeof(u), u@_FillValue )
>>> 29 vr = new ( dimsizes(v), typeof(v), v@_FillValue )
>>> 30
>>> 31 vr2uvg(vrt, ur,vr)
>>> 32 ur_at_long_name = "Zonal Rotational Wind"
>>> 33 ur_at_units = u_at_units
>>> 34 vr_at_long_name = "Meridional Rotational Wind"
>>> 35 vr_at_units = v_at_units
>>> 36 copy_VarCoords(u, ur )
>>> 37 copy_VarCoords(u, vr )
>>> 38 ;*************************************************
>>> 39 ; plot results
>>> 40 ;*************************************************
>>> 41 wks = gsn_open_wks("ps","wind") ; open workstation
>>> 42
>>> 43 res = True
>>> 44
>>> 45 res_at_vcRefMagnitudeF = 5. ; make vectors larger
>>> 46 res_at_vcRefLengthF = 0.050 ; reference vector
>>> 47 res_at_vcGlyphStyle = "CurlyVector" ; turn on curly vectors
>>> 48 res_at_vcMinDistanceF = 0.022 ; thin the vectors
>>> 49 res_at_vcRefAnnoOrthogonalPosF = -1.0 ; move ref vector up
>>> 50 res_at_gsnLeftString = "Rotational Wind"
>>> 51 ; plot 1st time step
>>> 52 plot= gsn_csm_vector_map_ce(wks,ur(0,:,:),vr(0,:,:),res)
>>> 53
>>> 54 end
>>>
>>>
>>> Professor, Department of Environment and Occupational Health
>>> College of Public Health
>>> University of South Florida
>>> 13201 Bruce B. Downs Blvd., MDC56
>>> Tampa, Fl 33612-3805
>>>
>>> Tel: (813) 974-9571
>>> Fax: (813) 974-4986
>>> Email: mmittal_at_health.usf.edu
>>> ________________________________________
>>> From: Dennis Shea [shea_at_ucar.edu]
>>> Sent: Tuesday, April 07, 2009 5:59 PM
>>> To: Mittal, Moti
>>> Cc: ncl-talk_at_ucar.edu
>>> Subject: Re: wind_2.ncl script
>>>
>>> Something tells me that you are not running
>>> wind_2.ncl. It uses "uv2vrG_Wrap" and "vr2uvg"
>>>
>>> So, you have changed something.
>>>
>>> The eroor message say that you are using two
>>> different sized array as input.
>>>
>>> Please do a 'printVarSummary' on each variable.
>>>
>>> Good luck
>>>
>>>
>>>
>>>
>>>
>>> Mittal, Moti wrote:
>>>> I was trying to run the wind script. I am getting the following error.
>>>> I will appreciate the suggestion to circumvent.
>>>>
>>>> Thank you.
>>>> Moti
>>>>
>>>> Out put message:
>>>>
>>>> [mmittal_at_localhost ~/NCL]$ ncl wind_2.ncl
>>>> Copyright (C) 1995-2009 - All Rights Reserved
>>>> University Corporation for Atmospheric Research
>>>> NCAR Command Language Version 5.1.0
>>>> The use of this software is governed by a License Agreement.
>>>> See http://www.ncl.ucar.edu/ for more details.
>>>> fatal:uv2vrF: The input arrays must have the same dimension sizes
>>>> fatal:Execute: Error occurred at or near line 2277 in file $NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl
>>>>
>>>> fatal:Execute: Error occurred at or near line 18 in file wind_2.ncl
>>>>
>>>>
>>>> Professor, Department of Environment and Occupational Health
>>>> College of Public Health
>>>> University of South Florida
>>>> 13201 Bruce B. Downs Blvd., MDC56
>>>> Tampa, Fl 33612-3805
>>>>
>>>> Tel: (813) 974-9571
>>>> Fax: (813) 974-4986
>>>> Email: mmittal_at_health.usf.edu
>>>> _______________________________________________
>>>> ncl-talk mailing list
>>>> List instructions, subscriber options, unsubscribe:
>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Apr 10 2009 - 15:36:30 MDT

This archive was generated by hypermail 2.2.0 : Thu Apr 16 2009 - 10:05:49 MDT