[ncl-talk] Spectral Analysis (Period in X-axis)

S. B. Ratna sbratna2012 at gmail.com
Tue Jun 20 12:40:07 MDT 2017


Hi Adam,
Thanks for your detail explanations and instructions.
I have followed your instruction and the example script.
I have used the script like below and it could plot the figure with
the X-axis as I wanted.
I hope, the result is correct.

   r at tmXBMode  = "Explicit"
   r at tmXBValues= tofloat ((/ 512, 256, 128, 64 , 32 , 16 , 8 , 4 /))
   r at tmXBLabels= tostring((/ 512, 256, 128, 64 , 32 , 16 , 8 , 4 /))
   r at xyXStyle = "Irregular"
   r at xyXIrregularPoints = (/4,8,16,32,64,128,256,512/)

   r at tiXAxisString = "Period (year)"           ; xaxis
   r at tiYAxisString = "Variance/freq"           ; yaxis
   plot = gsn_csm_xy(wks,p, splt,r)

Many thanks.
SBR







On Mon, Jun 19, 2017 at 5:48 PM, Adam Phillips <asphilli at ucar.edu> wrote:
> Hi SBR,
> First, welcome to NCL! As you are a new user we strongly recommend that you
> read through the NCL User Guide and the Mini-Language manual, both linked
> from here:
> http://www.ncl.ucar.edu/Document/Manuals/
>
> With regards to your question:
> "I want to keep the Y axis as it is but want to change the X axis to
> Period with scale 4 8 16 32 64 128 256 512."
>
> I think you need to set the following:
> r at xyXStyle = "Irregular"
> r at xyXIrregularPoints = (/.01,.1,.2,.25,.5/)
> Note that the setting of xyXIrregularPoints in purely subjective. The
> spacing between each value on the X-axis will be the same regardless of the
> size of the value, so set this however you want.
>
> If you want the labels of the X-axis to be 4 8 16 32 64 128 256 512, then
> you need to set the tmXBValues and tmXBLabels resources as I suggested in my
> initial reply. Note that to set these resources the formula to use is:
> 1/frequency = period, or 1/tmXBValues = tmXBLabels. As an example, for the
> returned spectra the smallest period will be 2 years, and the frequency is
> .5.  (1/.5 = 2)
>
> Here would be the settings for your first 4 labels; I leave the rest for you
> to calculate.
> r at tmXBValues = (/.03125,.0625,.125,.25/)
> r at tmXBLabels = (/"32","16","8","4"/)
>
> If you want the periods (frequency) to increase (decrease) along the x-axis
> as opposed to decreasing (increasing), you can set r at trXReverse = True
> http://www.ncl.ucar.edu/Document/Graphics/Resources/tr.shtml#trXReverse
>
> Finally, colleague sent in an example spectra script that sets various
> options and walks one through an alternative way to create a spectra plot
> with the period as the x-axis.  I have attached it here.
>
> Hope that helps. If you have any further questions please reply to the
> ncl-talk email list.
> Adam
>
> On Fri, Jun 16, 2017 at 7:51 PM, S. B. Ratna <sbratna2012 at gmail.com> wrote:
>>
>> Hi Adam,
>> Thanks for your reply. I am a new user of NCL and difficult to
>> understand many things now.
>> I am trying to modify the following code as per your instructions.
>> https://www.ncl.ucar.edu/Applications/Scripts/spec_4.ncl
>>
>> I want to keep the Y axis as it is but want to change the X axis to
>> Period with scale 4 8 16 32 64 128 256 512.
>> Could you please suggest how to change this part of the code.
>>
>> ;************************************************
>> ; plotting
>> ;************************************************
>>    wks  = gsn_open_wks("ps","spec")              ; Opens a ps file
>>
>>    r = True                                      ; plot mods desired
>>    r at tiMainString = "SOI"                        ; title
>>    r at tiXAxisString = "Frequency (cycles/month)"  ; xaxis
>>    r at tiYAxisString = "Variance"                  ; yaxis
>> ;***********************************************
>> ; Generate log plot showing "red noise" confidence bounds
>> ; (a) log scaling and (b) the Band Width
>> ;***********************************************
>>    r at trYLog              = True                 ; log scaling
>>    r at trYMinF             = 0.10                 ; manually set lower limit
>>    r at trYMaxF             = 30.0                 ;   "          upper
>>    r at gsnFrame            = False                ; do not advance frame
>>    plot  = gsn_csm_xy(wks,sdof at frq, splt,r)
>>
>>    xf   = (/0.40, 0.40+sdof at bw/)                ; Create band width line
>>    ys   = 0.75*max(sdof at spcx)                   ; 75% up Y axis
>>    yv   = (/ys,ys/)
>>    rpl  = True                                  ; resources for polyline
>>    rpl at gsLineThicknessF  = 2                    ; Define line thickness
>>    gsn_polyline(wks,plot,xf,yv,rpl)             ; Draw BandWidth
>>
>>    txres= True                                  ; label BW line
>>    txres at txFontHeightF = 0.015                  ; font height
>>    txres at txJust        = "CenterLeft"           ; Set lable location
>>    gsn_text(wks,plot,"BW",0.41+sdof at bw,ys,txres); Label
>>    frame (wks)
>> end
>>
>> Thanks.
>> SBR
>>
>> On Fri, Jun 16, 2017 at 10:57 PM, Adam Phillips <asphilli at ucar.edu> wrote:
>> > Hi SBR,
>> > To switch to period being on the bottom y-axis you can do something like
>> > this:
>> > pres at tmXBMode   = "Explicit"
>> > pres at tmXBValues = (/".02",".10",".20",".3333",".50"/)
>> > pres at tmXBLabels = (/"50","10","5","3","2"/)
>> > pres at tiXAxisString = "Period (years)"
>> >
>> > To alter the Y-axis type, you can set trYAxisType and trYCoordPoints as
>> > is
>> > done in XY example #30 here:
>> > http://www.ncl.ucar.edu/Applications/xy.shtml#ex30
>> >
>> > Hope that helps. If you have any further questions please respond to the
>> > ncl-talk email list.
>> > Adam
>> >
>> >
>> >
>> >
>> >
>> > On Fri, Jun 16, 2017 at 12:52 PM, S. B. Ratna <sbratna2012 at gmail.com>
>> > wrote:
>> >>
>> >> Hi All,
>> >> I would like to plot the spectral analysis for my annual mean data for
>> >> about 800 years. I would like to use 'spec_4.ncl' but I need "period
>> >> (year)" in the X-axis instead of "Frequency".
>> >> Also, the X-axis scale should be 4 8 16 32 64 128 256 512.
>> >> Could you please suggest how to draw such figure.
>> >> https://www.ncl.ucar.edu/Applications/Scripts/spec_4.ncl
>> >>
>> >> Thanks.
>> >> SBR
>> >> _______________________________________________
>> >> ncl-talk mailing list
>> >> ncl-talk at ucar.edu
>> >> List instructions, subscriber options, unsubscribe:
>> >> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>> >
>> >
>> >
>> >
>> > --
>> > Adam Phillips
>> > Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
>> > www.cgd.ucar.edu/staff/asphilli/   303-497-1726
>> >
>
>
>
>
> --
> Adam Phillips
> Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
> www.cgd.ucar.edu/staff/asphilli/   303-497-1726
>


More information about the ncl-talk mailing list