Re: How to boost performances of NCL scripts?

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Wed Mar 31 2010 - 14:09:52 MDT

Caroline,

Since you have 2D lat/lon variables, I don't think it's necessary for
you to create the plot once, get the NDC coordinates, change the map
projection, and then create the plot again.

You should be able to go straight to the Mercator projection as long
as you have lat2d/lon2d attached to your tt array:

tt@lat2d = lat2d
tt@lon2d = lon2d

Make sure you do *not* set tfDoNDCOverlay. It will default to False,
which is what you want. Otherwise, your lat2d/lon2d will be ignored.

Also, I noticed you are reordering the lat2d/lon2d on the file. Are
they coming in as lat x lon or lon x lat? If it is lat x lon, then
you shouldn't reorder them.

--Mary

On Mar 31, 2010, at 7:45 AM, Caroline Serraud wrote:

> Hello to everyone,
>
> I would like to boost performances of my ncl scripts to make them
> faster and less cpu-consuming.
> My script is reading a netcdf file in a native lambert projection
> grid and plot temperature contour on a mercator projection. I think
> regridding with ndctodata may be one of the reason my script is
> slow. I saw that for better performances it could be recommanded to
> use C functions and procedures, but I don't know which part of my
> script could be put into C routines or if it would help in such case.
>
> Does someone have an idea on optimizing such a script?
> Any remark would be very helpful!
> Kind regards,
> Caroline
>
> --
> Caroline Serraud - Ingénieur Etudes & Développements
> ------------------------------------------------------
> METEO CONSULT / La Chaine Météo - Groupe Figaro
> Département Informatique
> Domaine de Marsinval F-78540 Vernouillet, FRANCE
> Tél : 01 39 28 1990 - Fax : 01 39 71 85 31
> e-mail : cs@meteoconsult.fr
> ------------------------------------------------------
> Toute la météo sur le Web : http://www.meteoconsult.fr
> Toute la météo par téléphone : 3201
> ;*************************************************
> ; barb_3.ncl
> ;
> ; Concepts illustrated:
> ; - Drawing colored wind barbs vectors over a cylindrical
> equidistant map
> ; - Changing the length of the wind barbs
> ; - Changing the size of the wind barbs
> ; - Decreasing the number of vectors drawn
> ; - Adding a color to an existing color map
> ; - Using the full color map for colored wind barbs
> ; - Changing the length of a wind barb tick
> ; - Changing the distance between wind barb ticks
> ; - Turning off the vector reference annotation label
> ; - Drawing a map using the medium resolution map outlines
> ; - Thinning vectors using a minimum distance resource
> ;
> ;************************************************
> 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/csm/shea_util.ncl"
> ;************************************************
> begin
> if (.not.isvar("v_file")) then
> print("Le nom du fichier source n'est pas defini")
> exit()
> end if
> ;************************************************
> ; read in netCDF file
> ;************************************************
> a = addfile(v_file,"r")
> setfileoption(a,"SuppressClose",False)
> ;************************************************
> ; read in zonal [u] and meridional [v] winds
> ;************************************************
> t = a->TMP_GDS3_HTGL_10(:,:)
> tt = t/10.
>
> LAT2D= a->g3_lat_0
> LON2D= a->g3_lon_1
> lon2d=LON2D(g3_y_1|:,g3_x_0|:)
> lat2d=LAT2D(g3_y_1|:,g3_x_0|:)
>
> dimll = dimsizes(lat2d)
> nlon = dimll(0)
> nlat = dimll(1)
>
>
> i_lat_min = v_lat_min + 0
> i_lat_max = v_lat_max + 0
> i_lon_min = v_lon_min + 0
> i_lon_max = v_lon_max + 0
>
> ;************************************************
> ; create plot
> ;************************************************
> wks_type = "ps"
> wks =gsn_open_wks(wks_type,"tempe")
>
> gsn_define_colormap(wks,"BlWhRe") ; choose color map
>
> res = True ; plot
> mods desired
>
> res@gsnMaximize = True
> res@gsnPaperOrientation = "landscape"
> res@gsnBoxMargin = 0.0
>
> res@lbLabelBarOn = False
>
> res@tmXBOn = False ; don't draw axis nor axis labels
> res@tmXTOn = False
> res@tmYLOn = False
> res@tmYROn = False
>
> res@cnLevelSelectionMode = "ManualLevels"
> res@cnMinLevelValF = -15.
> res@cnMaxLevelValF = 35.
> res@cnLevelSpacingF = 1.
> res@cnFillOn = True ; turn on color for
> contours
> res@cnLinesOn = False ; turn off contour
> lines
> res@cnLineLabelsOn = False ; turn off contour
> line labels
> res@cnFillColors = (/
> 2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50
> ,
> 52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,9
> 8,100,102/)
> res@cnInfoLabelOn = False
>
> res@gsnAddCyclic = False ; regional data
>
>
> ; zoom in on map
>
>
> res@mpDataBaseVersion = "RANGS_GSHHS" ; high
> resolution coastline
> res@mpDataResolution = "FinestResolution"
> res@mpFillOn = False
> res@mpOutlineOn = False
> res@mpPerimOn = False
> ; res@mpShapeMode = "FixedAspectNoFitBB"
>
> res@mpProjection = "LambertConformal"
> res@mpLimitMode = "Corners" ; choose range of map
> res@mpLeftCornerLatF = lat2d@corners(0)
> res@mpLeftCornerLonF = lon2d@corners(0)
> res@mpRightCornerLatF = lat2d@corners(2)
> res@mpRightCornerLonF = lon2d@corners(2)
> res@mpLambertParallel1F = lat2d@Latin1 ; ncl adds from grib file
> res@mpLambertParallel2F = lat2d@Latin2 ; ncl adds from grib file
> res@mpLambertMeridianF = lat2d@Lov ; ncl adds from grib file
>
> res@tfDoNDCOverlay = True
> res@gsnDraw = False
> res@gsnFrame = False
>
> plot=gsn_csm_contour_map(wks,tt,res)
>
> getvalues plot
> "vpXF" : x
> "vpYF" : y
> "vpWidthF" : w
> "vpHeightF" : h
> end getvalues
> ; print("x: " + x + " y: " + y + " w: " + w + " h: " + h)
>
> ndcx = fspan(x, x + w,nlon)
> ndcy = fspan(y-h,y,nlat)
>
> eps = 5e-7
> ndcx(0) = ndcx(0) + eps
> ndcx(nlon-1) = ndcx(nlon -1) - eps
> ndcy(0) = ndcy(0) + eps
> ndcy(nlat-1) = ndcy(nlat -1) - eps
>
> ; print( "calculating lat/lon fields")
> tndcy = new(nlon, float)
> outlat = new((/nlat,nlon/), float)
> outlon = new((/nlat,nlon/), float)
>
> do i = 0, nlat-1
> tndcy = ndcy(i)
> ndctodata(plot,ndcx,tndcy,outlon(i,:),outlat(i,:))
> end do
>
>
> res@gsnAddCyclic = False
> res@sfXArray = outlon
> res@sfYArray = outlat
> res@tfDoNDCOverlay = False
>
>
> res@mpProjection = "mercator"
> res@mpLimitMode = "Corners"
> res@mpLeftCornerLatF = i_lat_min
> res@mpLeftCornerLonF = i_lon_min
> res@mpRightCornerLatF = i_lat_max
> res@mpRightCornerLonF = i_lon_max
>
>
> plot=gsn_csm_contour_map(wks,tt,res)
> draw(plot)
> frame(wks)
>
>
> end
>
>
> _______________________________________________
> 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 Wed Mar 31 14:11:05 2010

This archive was generated by hypermail 2.1.8 : Thu Apr 01 2010 - 11:31:45 MDT