RE : Re: RE : Re: [ncl-talk] Creation of Netcdf file

From: louis Vonder <appopson_at_nyahnyahspammersnyahnyah>
Date: Thu, 21 Feb 2008 18:42:39 +0100 (CET)

Hi Mary,
After removing the option "res_at_tfDoNDCOverlay = True" every going right.
Thanks

Mary Haley <haley_at_ucar.edu> a écrit : Louis,

In your script below, you have the following line:

  res_at_tfDoNDCOverlay = True

When you set this to True (it is False by default), you are telling
NCL that the data is not to be transformed before it is overlaid on
the map. In order to use this, then, you are telling NCL that the data
has already been transformed, and hence it doesn't use the lat/lon
information attached to the file. You can only set this resource to
True if you know the exact map projection parameters that the data
were measure on. When no transformation needs to take place, then,
the lat/lon information is not used. This is why when you change
the lat values, you don't see any change in your plot.

Try commenting this line out and see what happens.

As a side, you can remove some of the lines inside your do loop,
and hopefully make it run faster.

For example, the following lines:

        name = stringtocharacter(fili(n))
        name1 = name(0:20)
        name2 = chartostring(name1)

can be rewritten as:

        name = stringtocharacter(fili(n))
        name2 = chartostring(name(0:20))

Same for:

        xhour1 = chartostring(name(14:15))
        xhour2 = stringtofloat(xhour1)
        xhour3 = xhour2/2.
        xhour4 = floor(xhour3)
        xhour5 = xhour3 - xhour4

can be rewritten as:

        xhour3 = stringtofloat(chartostring(name(14:15)))/2.
        xhour4 = floor(xhour3)
        xhour5 = xhour3 - xhour4

Of course, the way you are doing it is much cleaner. It's just that
when you start creating variables inside a do loop, it can cause
things to slow down signifcantly.

--Mary

On Thu, 21 Feb 2008, louis Vonder wrote:

> Thanks Mary,
>
K> Here attached the script I am using for my plot.
> When my ini_lat begin with 15 and decrease, like this
>
> ini_lat = 1.
> xlatxlat = ini_lat + (ispan(nlat-1, 0, 1) * 0.25)
>
> I get the the same plot.
>
>
>
> ;****************************************************
> ; native_2.ncl
> ;*****************************************************
> load
> "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load
> "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> ;*****************************************************
> begin
>
> fili = systemfunc("ls FLXCut_025_FC_*_235K.nc")
> nfil = dimsizes( fili )
>
> do n=0, nfil - 1
> name = stringtocharacter(fili(n))
> name1 = name(0:20)
> name2 = chartostring(name1)
>
> xhour1 = chartostring(name(14:15))
> xhour2 = stringtofloat(xhour1)
> xhour3 = xhour2/2.
> xhour4 = floor(xhour3)
> xhour5 = xhour3 - xhour4
>
>
> if (xhour5.eq.0.5) then
> if (xhour4.le.9.) then
> xhour = "0"+xhour4+"30"
> else
> xhour = xhour4+"30"
> end if
> else
> if (xhour4.le.9.) then
> xhour = "0"+xhour4+"00"
> else
> if (xhour4.eq.24) then
> xhour = "0000"
> else
> xhour = xhour4+"00"
> end if
> end if
> end if
>
> xhour0 = xhour+" LST"
>
>
> ; xhour2 = chartostring(name(19:20))
> ; xhour = xhour1+"00"+"-"+xhour2+"00 LST"
>
>
> f1 = addfile(fili(n), "r")
>
> fsd=f1->FC
>
> ;print(fsd)
>
> fsd1 = fsd
>
> fsd_at_long_name = "Fractional coverage"
> lat = fsd&lat
> lon = fsd&lon
> nlat = dimsizes(lat)
> nlon = dimsizes(lon)
> ;**************************************
> ; Create plot
> ;***************************************
> wks = gsn_open_wks("eps", name2)
> gsn_define_colormap(wks,"BlGrYeOrReVi200") ;
> choose color map
> ;i = NhlNewColor(wks,0.7,0.7,0.7) ;
> add gray to colormap
> ;setvalues wks
> ;"wkColorMap" : "gsltod"
> ;"wkForegroundColor" : (/0.,0.,0./)
> ;"wkBackgroundColor" : (/1.,1.,1./)
> ;end setvalues
>
> res = True ;
> plot mods desired
>
>
>
> res_at_cnFillOn = True ;
> turn on color
> res_at_cnLinesOn = False ;
> no contour lines
>
> res_at_cnLevelSelectionMode = "ManualLevels" ;
> set manual contour levels
> res_at_cnMinLevelValF = 5 ;
> set min contour level
> res_at_cnMaxLevelValF = 55 ;
> set max contour level
> res_at_cnLevelSpacingF = 5 ;
> contour spacing
>
>
> res_at_gsnSpreadColors = True ;
> use full color map
> res_at_gsnSpreadColorEnd = -3 ;
> don't use added gray
> res_at_lbOrientation ="vertical" ;
> vertical label bar
>
> res_at_mpDataBaseVersion = "Ncarg4_1" ;
> use finer database
> res_at_pmTickMarkDisplayMode = "Always" ;
> turn on tickmarks
> res_at_mpGeophysicalLineThicknessF = 2.5 ;
> thickness of outlines
> res_at_mpNationalLineThicknessF = 2.5
> res_at_mpOutlineBoundarySets = "National" ; turn
> on country boundaries
> res_at_gsnAddCyclic = False ;
> regional data, don't add pt
>
> res_at_mpProjection = "mercator" ;
> projection
> res_at_mpLimitMode = "Corners" ;
> method to zoom
> res_at_mpLeftCornerLatF = min(lat)
> res_at_mpLeftCornerLonF = min(lon)
> res_at_mpRightCornerLatF = max(lat)
> res_at_mpRightCornerLonF = max(lon)
> res_at_tfDoNDCOverlay = True ;
> do not transform data
>
> res_at_tiMainString = xhour0
> res_at_tiXAxisString = " "
> res_at_tiYAxisString = " "
> res_at_tiMainFontHeightF = 0.03
> ; change font heights
> res_at_tiXAxisFontHeightF = 0.03
> res_at_tiYAxisFontHeightF = 0.03
>
> res_at_vpXF = 0.095
> res_at_vpYF = 0.85
> res_at_vpHeightF = 0.7 ; Make this second map
> smaller.
> res_at_vpWidthF = 0.7
>
>
> ;plot = gsn_csm_contour_map (wks, fsd1, res) ;
> create plot
>
> plot = gsn_csm_contour_map (wks, fsd1, res) ;
> create plot
>
> end do
>
>
> end
>
>
> Thanks a lot.
>
>
>
>
> --- Mary Haley a écrit :
>
>>
>> On Wed, 20 Feb 2008, louis Vonder wrote:
>>
>>> Dear Ncl users,
>>> I am using a modified version of Ncl script to
>> create
>>> Netcdf file. My version is attached here.
>>>
>>> After modifications of the following lines, I get
>> the
>>> same plot. There is no change in the plot when my
>>> first latitude (ini_lat) begin with 1 or with 15.
>>>
>>> What is the Problem here?
>>>
>>> nlat = 58
>>> xlat = new((/nlat/), "float")
>>> ini_lat = 1.
>>> do ii = 0, nlat - 1
>>> xlat(ii) = ini_lat
>>> ini_lat = ini_lat + 0.25
>>> end do
>>
>> Hi Louis,
>>
>> First, you can write the code above without a do
>> loop, which
>> is always something to strive for since do loops can
>> be slow.
>> The seven lines above can be replaced with:
>>
>> ini_lat = 1.
>> xlat = ini_lat + (ispan(0,nlat-1,1) * 0.25)
>>
>> Second, you didn't include the code for your plot,
>> so I'm not sure
>> what might be causing your plots to not change when
>> you change
>> ini_lat. Can you email me with your graphics code
>> snippet? (BTW, it
>> looks to me like you've set up "dummy_data"
>> correctly.)
>>
>> Thanks,
>>
>> --Mary
>>
>>
>>>
>>>
>>>
>>> My NCL script
>>>
>>> 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
>>>
>>> nlat = 58
>>> xlat = new((/nlat/), "float")
>>> ini_lat = 1.
>>> do ii = 0, nlat - 1
>>> xlat(ii) = ini_lat
>>> ini_lat = ini_lat + 0.25
>>> end do
>>>
>>> ;lat = xlat(::-1)
>>> lat = xlat
>>>
>>>
>>> nlon = 66
>>> xlon = new((/nlon/), "float")
>>> ini_lon = 1.5
>>> do ii = 0, nlon - 1
>>> xlon(ii) = ini_lon
>>> ini_lon = ini_lon + 0.25
>>> end do
>>>
>>> lon = xlon
>>>
>>>
>>>
>>> lat_at_units = "degrees_north"
>>> lat_at_long_name = "latitude"
>>> lon_at_units = "degrees_east"
>>> lon_at_long_name = "longitude"
>>>
>>>
>>> fili = systemfunc("ls FFL_3h_*_235K.txt")
>>> nfil = dimsizes( fili )
>>>
>>> do n=0, nfil - 1
>>> name = stringtocharacter(fili(n))
>>> name1 = name(0:16)
>>> name2 = chartostring(name1)
>>>
>>> dummy_data = asciiread(fili(n),
>> (/nlat,nlon/),
>>> "float")
>>>
>>> ; Set up coordinate arrays so we can overlay on
>> map.
>>> dummy_data!0 = "lat"
>>> dummy_data!1 = "lon"
>>> dummy_data&lat = lat
>>> dummy_data&lon = lon
>>> dummy_data_at_units = "%"
>>> dummy_data@_FillValue = -9999.
>>> dummy_data_at_missing_value = dummy_data@_FillValue
>>> dummy_data_at_long_name = "Fractional coverage"
>>>
>>> diro = "./" ; Output
>>> directory
>>> filo = name2+".nc" ; Output
>> file
>>> system("/bin/rm -f " + diro + filo) ; remove
>> if
>>> exists
>>> fout = addfile (diro + filo, "c") ; open output
>>> file
>>>
>>>
>>>
>>>
>>
> ;===================================================================
>>> ; explicitly declare file definition mode.
>> Improve
>>> efficiency.
>>>
>>>
>>
> ;===================================================================
>>> setfileoption(fout,"DefineMode",True)
>>>
>>>
>>>
>>
> ;===================================================================
>>> ; create global attributes of the file
>>>
>>>
>>
> ;===================================================================
>>> fAtt = True ;
>> assign
>>> file attributes
>>> fAtt_at_title = "NCL Efficient Approach to
>>> netCDF Creation"
>>> fAtt_at_source_file = name
>>> fAtt_at_Conventions = "None"
>>> fAtt_at_creation_date = systemfunc ("date")
>>> fileattdef( fout, fAtt ) ; copy file
>>> attributes
>>>
>>>
>>
> ;===================================================================
>>> ; predefine the coordinate variables and their
>>> dimensionality
>>> ; note: to get an UNLIMITED record dimension,
>> we
>>> set the dimensionality
>>> ; to -1 and set the unlimited array to True.
>>>
>>>
>>
> ;===================================================================
>>> dimNames = (/ "lat", "lon" /)
>>> dimSizes = (/ nlat, nlon /)
>>> dimUnlim = (/ False, False /)
>>> filedimdef(fout, dimNames, dimSizes, dimUnlim)
>>>
>>>
>>>
>>> filevardef(fout, "lat" ,typeof(lat),"lat")
>>>
>>> filevardef(fout, "lon" ,typeof(lon),"lon")
>>>
>>> filevardef(fout, "FC", typeof(dummy_data),
>>> (/"lat" ,"lon"/))
>>>
>>>
>>> filevarattdef(fout,"lat",lat)
>>> ; copy lat attributes
>>> filevarattdef(fout,"lon",lon)
>>> ; copy lon attributes
>>> filevarattdef(fout,"FC", dummy_data)
>>> ; copy TOPOG attributes
>>>
>>> setfileoption(fout,"DefineMode",False)
>>>
>>>
>>> fout->lat = (/lat/)
>>> fout->lon = (/lon/)
>>> fout->FC = (/dummy_data/)
>>>
>>>
>>
> === message truncated ===
>
>
>
> _____________________________________________________________________________
> Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail http://mail.yahoo.fr
>

       
---------------------------------
 Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Feb 21 2008 - 10:42:39 MST

This archive was generated by hypermail 2.2.0 : Tue Feb 26 2008 - 16:44:49 MST