[ncl-talk] calcMonAnomTLL

setare rahimi rahimi.setare at gmail.com
Mon May 31 06:02:48 MDT 2021


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/0fca72d2/attachment.html>
-------------- next part --------------
 begin  
;************************************************
; Read the file
;************************************************
  ymStrt = 196901                              ; climatology start year/month
  ymLast = 200012

  ymStrt1 = 200001                              ; climatology start year/month
  ymLast1 = 200512


  a      = addfile("air.mon.mean.nc","r")


  time   = a->time             
  yyyymm = cd_calendar(time, -1)
  ntStrt = ind(yyyymm.eq.ymStrt)                ; start time index
  ntLast = ind(yyyymm.eq.ymLast)                ; last  time index

  ntStrt1 = ind(yyyymm.eq.ymStrt1)                ; start time index
  ntLast1 = ind(yyyymm.eq.ymLast1)                ; last  time index
  

  tmp    = a->air(ntStrt:ntLast,:,:)            ; (time,lat,lon)
  tmp= tmp-273.15
  tmp1    = a->air(ntStrt1:ntLast1,:,:)            ; (time,lat,lon)
  tmp1= tmp1-273.15
        


  ntim = dimsizes(time)
 printMinMax(tmp,0)
  months = (/"January", "February", "March", "April" \
            ,"May", "June", "July", "August"         \
            ,"September", "October", "November"      \
            ,"December" /)
;************************************************
; Compute the climatology using a function in contributed.ncl
;************************************************
  tmpClm = clmMonTLL (tmp)                        ; monthly climatology
  
  tmpAnom = calcMonAnomTLL (tmp1,tmpClm)
   
;************************************************
; create colors
;*************************************************
  wks = gsn_open_wks("png","climo_ghcn")             ; send graphics to PNG file

;************************************************
; create panel plots
;*************************************************
  plot   = new (12, graphic)                    ; create graphical array

  res                      = True               ; plot options desired
  res at gsnDraw              = False
  res at gsnFrame             = False
  res at cnFillOn             = True               ; turn on color fill
  res at cnFillPalette        = "amwg256"          ; set color map
  res at cnInfoLabelOn        = False              ; turn off contour info label
  res at cnLinesOn            = False              ; turn off contour lines
  res at cnLineLabelsOn       = False              ; turn off line labels

  res at cnLevelSelectionMode = "ManualLevels"     ; set manual contour levels
  res at cnMinLevelValF       = -3             ; set min contour level
  res at cnMaxLevelValF       = 4         ; set max contour level
  res at cnLevelSpacingF      =  0.5             ; set contour spacing

  res at mpFillOn             = False              ; turn off gray continents
  res at mpCenterLonF         = 0                  ; Centers the plot at 0 
  res at lbLabelBarOn         = False              ; No single label bar
  
 
 res at mpMaxLatF            = 34        ; choose subregion
 res at mpMinLatF            = 28
 res at mpMaxLonF            = 54
 res at mpMinLonF            = 44
 res at mpDataBaseVersion    = "MediumRes"      ; better map outlines
 res at gsnRightString      = " mm"
  

  resP                     = True               ; panel options
  resP at gsnPanelMainString  = "Monthly mean of surface temperature : "+(ymStrt/100)+"-"+(ymLast/100)
  resP at gsnMaximize         = True               ; maximize image
  resP at gsnPanelLabelBar    = True               ; Add common label bar 
  
 
  do nmo=0,11                                   ; loop over the months
     res at gsnLeftString     = months(nmo)
     plot(nmo) = gsn_csm_contour_map(wks,tmpAnom(nmo,:,:), res)  ; create plot
  end do
  
  ;plot= gsn_csm_contour_map(wks,temp2(0,:,:), res)  ; create plot


  shapefile_name1 = "ProvinceKhuzestan.shp"
  shapefile_name2 = "IRN_adm0.shp"
  lnres = True
  lnres at gsLineThicknessF = 3
  lnres at gsLineColor = "Black"

  shape1 = gsn_add_shapefile_polylines(wks,plot,shapefile_name1,lnres)
  shape2 = gsn_add_shapefile_polylines(wks,plot,shapefile_name2,lnres) 
  gsn_panel(wks,plot,(/3,4/),resP)
end


More information about the ncl-talk mailing list