[ncl-talk] calcMonAnomTLL

Dennis Shea shea at ucar.edu
Mon May 31 20:27:19 MDT 2021


Well, you can not **directly** use  YYYYMM.
It is the user responsibility to examine the files being used. The 'time'
on the file is of the form:

%> *ncl_filedump*
<http://www.ncl.ucar.edu/Document/Tools/ncl_filedump.shtml> air.mon.mean.nc
| less
[snip]
      double time ( time )
         long_name :    Time
         delta_t :      0000-01-00 00:00:00
         avg_period :   0000-01-00 00:00:00
         axis : T
         standard_name :        time
         coordinate_defines :   start
         units :        hours since 1800-01-01 00:00:0.0     <===
         actual_range : ( 1297320, 1925544 )
[snip]

The 'time' on the file with units "hours since 1800-01-01 00:00:0.0  " must
be converted to YYYYMM. The function that can be used is *cd_calendar*
<http://www.ncl.ucar.edu/Document/Functions/Built-in/cd_calendar.shtml>
Study this function!

===
   a = *addfile*("air.mon.mean.nc","r")
   TIME   = a->time
   ymdhms = *cd_calendar*(TIME, 0)
   print(ymdhms)
   print("=========================")
   yyyymm = *cd_calendar*(TIME,-1)
   print(yyyymm)    ; 194801 to 201909
   print("=========================")

   ymStrt  = 196901                              ; (reference) climatology
period
   ymLast  = 200012

   ymStrt1 = 200001                            ; study period that I need
to calculate anomaly for
   ymLast1 = 200512

   iStrt   =* ind(*
<http://www.ncl.ucar.edu/Document/Functions/Built-in/ind.shtml>
yyyymm.eq.ymStrt)
   iLast   = ind(yyyymm.eq.ymLast)
   iStrt1  = ind(yyyymm.eq.ymStrt1)
   iLast1  = ind(yyyymm.eq.ymLast1)

   air     = a->air                            ; (time,lat,lon)
   refClm  = *clmMonTLL*( air(iStrt:iLast,:,:) )     ; reference (base)
climatology
   printVarSummary(refClm)                     ; (12,lat,lon)
   print("=========================")
   anom    = *calcMonAnomTLL*(air(iStrt1:iLast1,:,:), refClm)
   printVarSummary(anom)
   print("=========================")




On Mon, May 31, 2021 at 6:03 AM setare rahimi <rahimi.setare at gmail.com>
wrote:

> Dear Dave & Dennis,
> I profoundly appreciate the time you consider to respond to this issue.
> Following your advice, I calculated the anomaly of my study period
> (attached)
> . I just want to check with you to make sure that my calculation is
> correct.
>
> --------------------------------------------------------------------------------------------------------------------
>  ymStrt = 196901                              ; climatology period
>  ymLast = 200012
>
> ---------------------------------------------------------------------------------------------------------------------
>  ymStrt1 = 200001                            ; study period that I need to
> calculate anomaly for
>
>  air.mon.mean.nc
> <https://drive.google.com/file/d/1q6cOTIxpaphuvmC2snsizhUEq5MRL8lQ/view?usp=drive_web>
> ymLast1 = 200512
>
> ----------------------------------------------------------------------------------------------------------------------
> Many thanks in advance,
> Kind regards,
>
> On Sun, May 30, 2021 at 5:46 AM Dennis Shea <shea at ucar.edu> wrote:
>
>> Dave's analysis is correct.
>>
>> This was amongst the earliest functions added to NCL [?late 199[7/8/9] ?]
>>
>> It is the user's responsibility to examine the file(s). The example uses;
>>
>>   air  = *short2flt* <http://www.ncl.ucar.edu/Document/Functions/Contributed/short2flt.shtml>( fa->air)                           ; air temp
>>   nobs = *short2flt* <http://www.ncl.ucar.edu/Document/Functions/Contributed/short2flt.shtml>( fb->air)                           ; # obs for air
>>
>> because the data were of type *short *. They must be unpacked before
>> usage.
>> ---
>> The function requires the user to input a reference climatology as the
>> 2nd argument.
>>
>> function calcMonAnomTLL (
>> 		x     [*][*][*] : float or double,
>> 		xAve [12][*][*] : numeric  )
>>
>> Why?  Many papers/organizations used 1950-79 as a reference SST period.
>> Hence, we allowed the user to independently calculate the desired
>> reference climatology. [xAve]
>> This also allowed the reference period to be calculated from a different
>> SST.
>>
>> Also, I think the data started in 1800. The 'moStrt' and 'moLast' were
>> the index values for the start and end of the period to be used.
>>
>> Many other example use this function:
>>
>> eof_3.ncl
>> *http://www.ncl.ucar.edu/Applications/eof.shtml*
>> <http://www.ncl.ucar.edu/Applications/eof.shtml>
>> eof_3_640.ncl
>> eof_4_640.ncl
>> godas_3.ncl
>> *http://www.ncl.ucar.edu/Applications/godas.shtml*
>> <http://www.ncl.ucar.edu/Applications/godas.shtml>
>> index_amo_1.ncl
>> *http://www.ncl.ucar.edu/Applications/indices.shtml*
>> <http://www.ncl.ucar.edu/Applications/indices.shtml>
>> indices_nino_1.ncl          *
>> http://www.ncl.ucar.edu/Applications/indices.shtml*
>> <http://www.ncl.ucar.edu/Applications/indices.shtml>
>> indices_oni_1.ncl
>> indices_oni_2.nc
>>
>> Other examples:
>> bootstrap_correl_2.ncl
>> *http://www.ncl.ucar.edu/Applications/bootstrap.shtml*
>> <http://www.ncl.ucar.edu/Applications/bootstrap.shtml>
>> coads_3.ncl
>> *http://www.ncl.ucar.edu/Applications/coads.shtm*
>> <http://www.ncl.ucar.edu/Applications/coads.shtm>l
>> prn_osc_pat_1.ncl
>> *http://www.ncl.ucar.edu/Applications/prn_osc_pat.shtml*
>> <http://www.ncl.ucar.edu/Applications/prn_osc_pat.shtml>
>>
>> On Fri, May 28, 2021 at 11:53 AM Dave Allured - NOAA Affiliate via
>> ncl-talk <ncl-talk at mailman.ucar.edu> wrote:
>>
>>> There is a bit of missing information in the example.  I think the
>>> expectation is that you are supposed to get copies of the input files,
>>> examine their metadata, and figure out some of these things as an
>>> educational exercise.  But I agree that it is a bit mysterious.  This is
>>> what I deduce from reading the example and documentation, and being
>>> familiar with common structures in climate data.
>>>
>>> * Dimensions of the two main input file variables are (time, lat, lon).
>>> * The input files are a series of monthly grids in chronological order,
>>> 12 monthly grids for each year in the file.
>>> * The input months are stacked on a single time dimension, so that
>>> December of one year is immediately followed by January of the next year.
>>> * The first month in the input files is January 1800.
>>>
>>> The example computes monthly anomalies for a 30-year time range, and NOT
>>> starting at the beginning of the files.  Therefore, integer subscripts for
>>> the first and last time steps in the requested time range are needed.
>>> Subtract 1800 to get the year offset from the start of the file, to the
>>> start of the requested anomaly period.  Then multiply by 12 to convert from
>>> integer year offsets, to integer month offsets.
>>>
>>> As briefly noted in the comments, moStrt and moLast are the first and
>>> last integer subscripts to access all 12 months of the requested time
>>> range, 1950 through 1979.  In particular, that is January of the first
>>> year, through December of the last year.
>>>
>>>
>>> On Fri, May 28, 2021 at 11:16 AM setare rahimi via ncl-talk <
>>> ncl-talk at mailman.ucar.edu> wrote:
>>>
>>>> Dear all NCL users,
>>>>
>>>> I visited this link:
>>>> https://www.ncl.ucar.edu/Document/Functions/Contributed/calcMonAnomTLL.shtml
>>>>  , which is about monthly anomalies. But I could not understand the
>>>> way it calculates the anomalies.
>>>>
>>>> _____________________________________________________________________________________________
>>>>
>>>> Example 1
>>>>
>>>>   fa     = *addfile* <https://www.ncl.ucar.edu/Document/Functions/Built-in/addfile.shtml>("air.mean.nc","r")
>>>>   fb     = *addfile* <https://www.ncl.ucar.edu/Document/Functions/Built-in/addfile.shtml>("air.nobs.nc","r")
>>>>
>>>>   air  = *short2flt* <https://www.ncl.ucar.edu/Document/Functions/Contributed/short2flt.shtml>( fa->air)                           ; air temp
>>>>   nobs = *short2flt* <https://www.ncl.ucar.edu/Document/Functions/Contributed/short2flt.shtml>( fb->air)                           ; # obs for air
>>>> ; filter out geographic locations that have < nMin observations
>>>>   nMin   = 2                                           ; min # obs
>>>>   air    = *mask* <https://www.ncl.ucar.edu/Document/Functions/Built-in/mask.shtml>(air,nobs.ge.nMin,True)
>>>>
>>>> ;---Compute the climatology using a function in contributed.ncl
>>>>   yrStrt = 1950
>>>>   yrLast = 1979
>>>>   moStrt = (yrStrt-1800)*12              ; start subscript
>>>>   moLast = (yrLast-1800)*12 + 11         ; last  subscript
>>>>   clm = *clmMonTLL* <https://www.ncl.ucar.edu/Document/Functions/Contributed/clmMonTLL.shtml> (air(moStrt:moLast,:,:)) ; monthly climatology
>>>>
>>>> ;---Compute the anomalies from the climatology just computed
>>>>   xAnom = *calcMonAnomTLL* (air,clm)
>>>>
>>>> _________________________________________________________________
>>>>
>>>> May I ask you please explain subscript method? Why using 1800 and then multiply 12?
>>>>
>>>> what do moStrt and moLast show?
>>>>
>>>> I appriciate any advse
>>>>
>>>> All the best,
>>>>
>>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at mailman.ucar.edu
>>> List instructions, subscriber options, unsubscribe:
>>> https://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210531/752554a6/attachment.html>


More information about the ncl-talk mailing list