[ncl-talk] Help Required in plotting average 2m temperature for 24 hours for 30 days in NCL

Mary Haley haley at ucar.edu
Mon Oct 16 11:54:23 MDT 2017


Muhammad,

When asking new questions on ncl-talk, please start a new thread and do not
address NCL developers directly. This is a community-based forum where
everybody tries to answer questions. If you address one person, then you
make it their problem.

To calculate wind speed, see this function:

http://www.ncl.ucar.edu/Document/Functions/Contributed/wind_speed.shtml

To overlay wind speed, you can use the same method that you are using for
LH, except I imagine you want to plot wind speed as line contours rather
than filled contours, if you are overlaying it on the LH plot.

You can see some examples of overlaying multiple WRF plots at:

http://www.ncl.ucar.edu/Applications/overlay.shtml#wrfnogsn5

I suggest that you do NOT use addfiles_GetVar
​. This function has been deprecated. You should be able to use
wrf_user_getvar to retrieve u and v on mass points, and then use wind_speed
to calculate the wind speed.  ​

--Mary


On Mon, Oct 16, 2017 at 7:53 AM, Muhammad Omer Mughal <
m.mughal1 at postgrad.curtin.edu.au> wrote:

> Hi Mary
>
>
> How can we overlay the average of wind speed vectors in the following 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"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
> load "/data/muhdomer/NSCC/scratch/WRF_myfunc.ncl"
>
> begin
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ;   input from WRF
>
>     ; The WRF ARW input file.
>
>   wrf_file1 = systemfunc("ls /data/muhdomer/Build_WRF/
> Martilli/glade/u/home/martilli/wrf_3.8/wrfout_d05_2016-04-01_00:00:00")
>   wrf_file2 = systemfunc("ls  /data/muhdomer/Build_WRF/
> Martilli/glade/u/home/martilli/wrf_3.8/WRF_Forest/
> run/wrfout_d05_2016-04-01_00:00:00")
> ; This needs to have a ".nc" appended, so just do it.
>   a = addfiles(wrf_file1+".nc","r")
>   b = addfiles(wrf_file2+".nc","r")
>
>  ListSetType(b,"cat")
>   LH1 = addfiles_GetVar(a,wrf_file1,"T2")
>   LH2 = addfiles_GetVar(b,wrf_file2,"T2")
>   ;LH1 = wrf_user_getvar(a,"rh2",-1)
>   ;LH2 = wrf_user_getvar(b,"rh2",-1)
>   ;printVarSummary(LH1)
>   ;printVarSummary(LH2)
>
>   LH = LH1 - LH2
>   ;LH=LH-273.16
>   ; What times and how many time steps are in the data set?
> ;  times  = wrf_user_list_times(a)  ; get times in the file
>   times = a[:]->Times
>   ntimes = dimsizes(times)         ; number of times in the file
>   ntimes_plot = ntimes(0)
>
>
>   lh3d = new((/29,129,210/), float)
>   lh2d = new((/129,210/), float)
>     c = 0
>
>  do i=time_serie, ntimes_plot-2,24
>        lh2d(:,:) = LH(i,:,:)
>        lh3d(c,:,:) = lh2d(:,:)
>        c = c + 1
>
>       end do
>     lh_avg = dim_avg_n(lh3d,0)
> ; We generate plots, but what kind do we prefer?
>   type = "png"
>
>   wks = gsn_open_wks(type,"LH_d05_diff_3_1_"+hour)
>   ; gsn_define_colormap(wks,"spread_15lev")
> ; Set some basic resources
>   res = True
>
>   ;res at ContourParameters = (/ 273., 310., 5./)
>       res at cnFillOn = True
>       res at cnLevelSelectionMode = "ExplicitLevels"
>      ; res at cnLevels=(/-0.4,-0.2,0,0.4,0.8,1.0,1.4,1.8,2.0,2.4/)
>       res at cnLevels=(/-0.2,0,0.4,0.6,0.8,1.0,1.2,1.4,1.6,1.8,2.0,2.2,2.4/)
>   ;res at cnLevelSelectionMode = "ExplicitLevels"
>   ;res at cnLevels = (/-50,-45,-40,-35,-30,-25,-20,-15,-10,-5,0/)
>   ;res at cnFillColors = (/12,11,10,9,8,7,6,5,4,3,2,2/)
>   ;res at MainTitle                   = "REAL-TIME WRF"
>   ;res at cnLevels = (/0,5,10,15,20,25,30,35,40,45,50/)
>   ;res at cnLevels = (/0,10,20,30,40,50,60,70,80,90,100/)
>   ;res at cnFillColors = (/2,2,3,4,5,6,7,8,9,10,11,12,13/)
>  ;res at mpOutlineOn = False
>   res at InitTime = False
>   res at Footer = False
>   res at gsnMaximize = True
>   res at gsnPaperOrientation = "landscape"
>   pltres = True
>   pltres at NoTitles = True
>   pltres at gsnMaximize = True
>   pltres at FramePlot = False
>   pltres at PanelPlot = True
>   mpres = True
>   ;mpres at mpFillOn = False
>   ;mpres at mpGeophysicalLineColor = "black"
>   ;mpres at mpGeophysicalLineThicknessF       = 0.0   ; for type = "png"
>  ; mpres at mpDataBaseVersion="Ncarg4_1"
>  ; mpres at mpDataSetName="Earth..4"
>  ; mpres at mpDataResolution="Finest"
>  ; mpres at mpOutlineOn=False
>
> lh_avg at description = "UHI"
>   ;lh_avg at description = "Sensible Heat Flux"
>
>
>   lh_avg at units = "C"
>   ; Plotting options for LH
>       opts = res
>       opts at cnFillOn = True
>       ;opts at ContourParameters = (/ -50., 0., 5. /)
>       ;opts at gsnSpreadColorEnd = -3  ; End third from the last color in
> color map
>       contour_lh = wrf_contour(a[0],wks,lh_avg,opts)
>       delete(opts)
>    ; MAKE PLOTS
>
>  plot = wrf_map_overlays(a[0],wks,contour_lh,pltres,mpres)
>     shape_files = (/"/data/muhdomer/NSCC/scratch/Shapefiles/SGP_adm0.
> shp","/data/muhdomer/NSCC/scratch/Shapefiles/MYS_adm0.
> shp","/data/muhdomer/NSCC/scratch/Shapefiles/IDN_adm0.shp"/)
>
>      plot = add_coastline_sgmyid(shape_files,wks,plot,"black")
>
>      draw(plot)
>      frame(wks)
>
>
>
>
>
>
>
> Muhammad Omer Mughal
> MSc BSc Mechanical Engineering
> PhD  Research Scholar
> Remote Sensing and Satellite Research Group
> Department of Imaging and Applied Physics
> Curtin University
>
> Curtin University
> Tel | +61 8 9266 7962
> Fax | +61 8 9266 2377
> Mobile | 0470 237 525
>
> Email | m.mughal1 at postgrad.curtin.edu.au <m.lynch at curtin.edu.au>
> Web | http://curtin.edu.au
>
> Curtin University is a trademark of Curtin University of Technology.
> CRICOS Provider Code 00301J (WA), 02637B (NSW)
>
>
> ------------------------------
> *From:* Mary Haley <haley at ucar.edu>
> *Sent:* Saturday, 14 October 2017 4:16:59 AM
> *To:* Muhammad Omer Mughal
> *Cc:* ncl-talk at ucar.edu
> *Subject:* Re: [ncl-talk] Help Required in plotting average 2m
> temperature for 24 hours for 30 days in NCL
>
> Muhammad,
>
> I think this script is slightly more complicated than it needs to be.
>
> It looks like your tc2 array is dimensioned ((/30,129,210/), and you want
> to skip indexes 0-11 of the leftmost dimension so that you are only
> averaging across indexes 12-29
> ​? If so, then:
>
> tc2_avg = dim_avg_n(tc2(12:,:,:),0)​
>
> This will give you back a 129 x 210 array, where each element is an
> average of the last 18 timesteps.
>
> --Mary
>
>
> On Wed, Oct 11, 2017 at 2:53 AM, Muhammad Omer Mughal <
> m.mughal1 at postgrad.curtin.edu.au> wrote:
>
>> Hi Mary
>>
>>
>> Kindly see the script below which I use with the bash script to determine
>> the average of 2M TEMPERATURE contained in the whole of WRF out directory.
>> I intend to skip the first 12 hours (spin up time) and I also tend to plot
>> the final average in one plot. Kindly let me know if you can help me out
>>
>>
>> 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"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
>> load "/data/muhdomer/NSCC/scratch/WRF_myfunc.ncl"
>> begin
>>
>>  DATADir = "./"
>>
>>   FILES   = systemfunc (" ls -1 " + DATADir + "wrfout_d05* ")
>>
>>   a       = addfiles(FILES+".nc","r")
>>
>>
>>   tc2 = wrf_user_getvar(a,"T2",-1)
>>   tc2 = tc2-273.16
>>   times = a[:]->Times
>>   ntimes = dimsizes(times)         ; number of times in the file
>>   ntimes_plot = ntimes(0)        ; abandon the first 12 hours
>>
>>
>>   lh3d = new((/30,129,210/), float)
>>   lh2d = new((/129,210/), float)
>>     c = 0
>>     do i=time_serie, ntimes_plot-2,24
>>        lh2d(:,:) = tc2(i,:,:)
>>        lh3d(c,:,:) = lh2d(:,:)
>>        c = c + 1
>>     end do
>>     lh_avg = dim_avg_n(lh3d,0)
>>   type = "x11"
>> wks= gsn_open_wks(type,"temp_"+hour)
>>     gsn_define_colormap(wks,"spread_15lev")
>>
>>   res = True
>>   res at cnLevelSelectionMode = "ExplicitLevels"
>>   res at cnLevels=(/24,25,26,27,28,29,30,31,32,33,34,35,36/)
>>   res at InitTime = False
>>   res at Footer = False
>>   res at gsnMaximize = True
>>   res at gsnPaperOrientation = "landscape"
>>   pltres = True
>>   pltres at NoTitles = True
>>   pltres at gsnMaximize = True
>>   pltres at FramePlot = False
>>   pltres at PanelPlot = True
>>   mpres = True
>>   mpres at mpFillOn = False
>>   mpres at mpGeophysicalLineColor = "black"
>>   mpres at mpGeophysicalLineThicknessF       = 0.0   ; for type = "png"
>>   mpres at mpDataBaseVersion="Ncarg4_1"
>>   mpres at mpDataSetName="Earth..4"
>>   mpres at mpDataResolution="Finest"
>>   mpres at mpOutlineOn=False
>>
>>   lh_avg at description = "temperature averaged"
>>
>>   lh_avg at units = "degree C"
>>        opts = res
>>       opts at cnFillOn = True
>>      contour_lh = wrf_contour(a[0],wks,lh_avg,opts)
>>       delete(opts)
>>       plot = wrf_map_overlays(a[0],wks,contour_lh,pltres,mpres)
>>
>>    shape_files = (/"/data/muhdomer/NSCC/scratch
>> /Shapefiles/MYS_adm0.shp","/data/muhdomer/NSCC/scratch/
>> Shapefiles/IDN_adm0.shp","/data/muhdomer/NSCC/scratch/
>> Shapefiles/MP14_REGION_NO_SEA_PL.shp"/)
>>
>>      plot = add_coastline_sgmyid(shape_files,wks,plot,"black")
>>
>>      draw(plot)
>>      frame(wks)
>> end
>>
>> Regards
>>
>>
>> Muhammad Omer
>>
>> Muhammad Omer Mughal
>> MSc BSc Mechanical Engineering
>> PhD  Research Scholar
>> Remote Sensing and Satellite Research Group
>> Department of Imaging and Applied Physics
>> Curtin University
>>
>> Curtin University
>> Tel | +61 8 9266 7962
>> Fax | +61 8 9266 2377
>> Mobile | 0470 237 525
>>
>> Email | m.mughal1 at postgrad.curtin.edu.au <m.lynch at curtin.edu.au>
>> Web | http://curtin.edu.au
>>
>> Curtin University is a trademark of Curtin University of Technology.
>> CRICOS Provider Code 00301J (WA), 02637B (NSW)
>>
>>
>>
>> _______________________________________________
>> 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/20171016/00765878/attachment.html>


More information about the ncl-talk mailing list