[ncl-talk] computing the model SOI index

Sri nandini bax8609 at uni-hamburg.de
Thu Apr 15 01:50:40 MDT 2021


Thanx a lot Dave!

This works well indeed!!

Best

Sri

On 14.04.21 17:48, Dave Allured - NOAA Affiliate wrote:
> Okay, you want to stay with decimal coded, as in YYYYMM.  Your input 
> times are YYYYMMDD.fffff where the fraction is non-zero.  This is a 
> case of simple integer division and rounding down, except be careful 
> of precision with this many digits.  The original time values are type 
> double, so that should take care of the precision issue.
>
> Remove YYYY = cd_calendar(TIME,-2)/100.  Then do this. Note that 
> converting double to integer will truncate (set to zero) the 
> fractional part of the result.  Integer division will do the same thing.
>
>     YYYYMM = toint (TIME / 100)     ; divide in double precision, then 
> truncate
>     YYYY       = YYYYMM / 100        ; integer division and truncate
>
> To check the results, compare adjacent values.   For YYYYMM and 
> sequential months, the difference should always be the numbers 1 or 
> 89, e.g. 185101 - 185012.
>
>
> On Wed, Apr 14, 2021 at 1:31 AM Sri nandini <bax8609 at uni-hamburg.de 
> <mailto:bax8609 at uni-hamburg.de>> wrote:
>
>     Hello,
>
>     The output is taken from ECMWF output from the atmospheric
>     component of the MPI model.
>
>     They were orginally in grib format (hence the daily component),
>     and converted to .nc with cdo.
>
>     At the moment they are appearing as YYYYMMDD and i would like to
>     convert the time calendar to YYYYMM so instead of
>     18500131.99444444 i wish to convert to 185001.
>
>     Can someone help me with this?
>
>     Sri
>
>     On 13.04.21 18:18, Dave Allured - NOAA Affiliate wrote:
>>     Sri, there is something wrong with the time coordinates in
>>     fslp->time.  You show values of
>>     [18500131.99444444..20051231.99444444], but units of "hours since
>>     1850-01-31 23:15:00".  Time coordinates should either be offsets
>>     relative to the base time in the units string, or else they
>>     should be decimal coded numbers.  It looks like this file mixes
>>     the two approaches, resulting in your error.  Relative offsets is
>>     the conventional approach, but decimal coded may also be used
>>     with care.  Just don't mix the two.
>>
>>     Do you prefer to fix the input file, or try to use the decimal
>>     time values the way they are written now?  Please keep the
>>     conversation on the mailing list.
>>
>>
>>     On Tue, Apr 13, 2021 at 9:43 AM Sri nandini via ncl-talk
>>     <ncl-talk at mailman.ucar.edu <mailto:ncl-talk at mailman.ucar.edu>> wrote:
>>
>>         Hello dear ncl-users,
>>
>>         I am trying to compute the model SOI index to draw a
>>         timeseries plot. I
>>         have studies the examples on the ncl page for
>>         indices_soi_1.ncl and
>>         indices_soi_2.ncl , and made my script as per the methods
>>         here. But each
>>         time an error occurs when reading the time: fatal:An error
>>         occurred
>>         reading YYYY
>>
>>         Variable: TIME
>>         Type: double
>>         Total Size: 14976 bytes
>>                      1872 values
>>         Number of Dimensions: 1
>>         Dimensions and sizes:    [time | 1872]
>>         Coordinates:
>>                      time: [18500131.99444444..20051231.99444444]
>>         Number Of Attributes: 4
>>            standard_name :    time
>>            units :    hours since 1850-01-31 23:15:00
>>            calendar :    standard
>>            axis :    T
>>
>>         Variable: YYYY
>>         Type: integer
>>         Total Size: 7488 bytes
>>                      1872 values
>>         Number of Dimensions: 1
>>         Dimensions and sizes:    [1872]
>>
>>         Could someone reply to me offline, or help point me to a
>>         query or
>>         ncl-talk which already solved this or i can also transfer my
>>         datafile
>>         via ftp? Below is my script.
>>
>>         ; =============================================================
>>            latT    = -17.6         ; Tahiti
>>            lonT    = 210.75
>>            latD    = -12.5         ; Darwin
>>            lonD    = 130.83
>>
>>            PLOT    = True
>>            pltType = "png"         ; send graphics to PNG file
>>            pltDir  = "./"          ; dir to which plots are sent
>>
>>            pltName = "indices_soi"
>>            yrStrt  = 1950          ; manually specify for convenience
>>            yrLast  = 2010          ; 20th century ends 2010
>>
>>            clStrt  = 1950          ; reference climatology for SOI
>>            clLast  = 1979
>>         ; ======================End User
>>         Input=======================================
>>            nmos   = 12
>>            nyrs   = yrLast-yrStrt+1
>>
>>            fslp   = addfile("hist_1850-2005_ens_1-100.slp.nc
>>         <http://hist_1850-2005_ens_1-100.slp.nc>", "r")
>>            slp    = fslp->slp
>>            printVarSummary(slp)
>>            TIME   = fslp->time
>>            printVarSummary(TIME)
>>            ;YYYYMM = cd_calendar(TIME, -1) ;error here
>>
>>            YYYY   = cd_calendar(TIME,-2)/100
>>
>>            tStrt  = ind(YYYY .eq. (yrStrt*100 +  1))       ; indices
>>         20th century
>>            tLast  = ind(YYYY .eq. (yrLast*100 + 12))       ; relative
>>         to entire
>>         dataset
>>
>>            yyyymm = YYYY(tStrt:tLast)
>>            tStrtP = ind(yyyymm .eq. (yrStrtP*100+  1))       ;
>>         relative to
>>         yrStrt, yrLast
>>            tLastP = ind(yyyymm .eq. (yrLastP*100+ 12))
>>
>>            T      = short2flt(fslp->slp(1632:1871,:,{latT},{lonT}))
>>            D      = short2flt(fslp->slp(1632:1871,:,{latD},{lonD}))
>>            printVarSummary(T)
>>            printVarSummary(D)
>>            T&time = yyyymm ; convenience
>>            D&time = yyyymm
>>
>>            tClmStrt = ind(yyyymm.eq.(clStrt*100 +  1)) ; index for clStrt
>>            tClmLast = ind(yyyymm.eq.(clLast*100 + 12)) ; index for clStrt
>>            printVarSummary(tClmStrt)
>>            printVarSummary(tClmLast)
>>            TClm   = new ( nmos, typeof(T), T at _FillValue)     ;
>>         monthly climatologies
>>            DClm   = new ( nmos, typeof(D), D at _FillValue)
>>
>>            do nmo=0,nmos-1
>>             ;do n=0,99 ; reference clm for each
>>         month and each ensemble member?
>>               TClm(nmo) = avg(T(tClmStrt+nmo:tClmLast:nmos))
>>               DClm(nmo) = avg(D(tClmStrt+nmo:tClmLast:nmos))
>>            end do
>>           end do
>>            printVarSummary(TClm)
>>            printVarSummary(DClm)
>>            TAnom    = T
>>            DAnom    = D
>>            do nmo=0,nmos-1 ; anomalies
>>         reference clim
>>               TAnom(nmo::nmos) = T(nmo::nmos) - TClm(nmo)
>>               DAnom(nmo::nmos) = D(nmo::nmos) - DClm(nmo)
>>            end do
>>            printVarSummary(TAnom)
>>            printVarSummary(DAnom)
>>
>>            TAnomStd   = stddev(TAnom(tClmStrt:tClmLast))     ; stddev of
>>         anomalies over clStrt & clLast
>>            DAnomStd   = stddev(DAnom(tClmStrt:tClmLast))
>>            printVarSummary(TAnomStd)
>>         printVarSummary(DAnomStd) ; signal and noise
>>            soi_signal = (TAnom/TAnomStd) - (DAnom/DAnomStd)  ; (ntim)
>>            copy_VarCoords(TAnom, soi_signal)
>>            soi_signal at long_name = "SOI: 20th Century Reanalysis:
>>         "+yrStrt+"-"+yrLast
>>            printVarSummary(soi_signal)
>>
>>         ;=======================================
>>         ; lag-0 correlation
>>         ;=======================================
>>
>>            rslp  = escorc(soi_signal,slp(lat|:,lon|:,ens:|,time|:))
>>            copy_VarCoords(slp(0,:,:,:), rslp)
>>            rslp at long_name = "Correlation: SOI-SLP: "+yrStrt+"-"+yrLast
>>            printVarSummary(rslp)
>>
>>         Best
>>
>>         Sri
>>
>>         -- 
>>         Dr. Sri, Nandini-Weiss
>>         Research Associate
>>
>>         Universität Hamburg
>>         Center for Earth System Research and Sustainability (CEN)
>>         Cluster of Excellence 'Climate, Climatic Change, and Society'
>>         (CLICCS)
>>
>>         Bundesstrasse 53, 20146 Hamburg
>>
-- 
Dr. Sri, Nandini-Weiss
Research Associate

Universität Hamburg
Center for Earth System Research and Sustainability (CEN)
Cluster of Excellence 'Climate, Climatic Change, and Society' (CLICCS)

Bundesstrasse 53, 20146 Hamburg

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210415/e16e6de7/attachment.html>


More information about the ncl-talk mailing list