[ncl-talk] Array reordering in OISST

Dennis Shea shea at ucar.edu
Mon May 20 11:38:15 MDT 2019


I accidentally sent the previous email befor I finished:

[6]

   LATS = 30
   LATN = 90
   LONW = 110
   LONE  = 150

   sst = *short2flt*
<http://www.ncl.ucar.edu/Document/Functions/Contributed/short2flt.shtml>(
f->sst(:,*{*LATS:LATN*}*,*{*LONW:LONE*}*)
   *printVarSummary*(sst)

Look at the coordinate information.



On Mon, May 20, 2019 at 11:16 AM Dennis Shea <shea at ucar.edu> wrote:

> I *think* I understand what you want to do. You use:
>
> [A]  This following uses *standard subscripting (indexing):*
>
> print("sst(n,*90-30,130*)="+sst(n,*90-30,130)*+" "+lon(130)+"E
> "+lat(90-30)+"N")
> print("sstre(n,130,90+30-1)="+sstre(n,130,90+30-1)+" "+lon(130)+"E
> "+sstre&lat(90+30-1)+"N")
>
>
> [B] I think you intended to use *coordinate subscripting
> <https://www.ncl.ucar.edu/Document/Language/subscript_coord.shtml> *which
> uses the following syntax:
> *{...}*
> A 'best practices' programming style is to use variables rather than
> hard-wiring numbers. Generally, this makes ithe intended use more clear.
>
>    LATS = 30
>    LATN = 90
>    LON = 130
>
>     SST = sst(n,*{*LATS:LATN*}*,*{*LON*}*)
>     printVarSummary(SST)
>
> or, say
>    LATS = 30
>    LATN = 90
>    LONW = 110
>    LONE  = 150
>
>     SST = sst(n,*{*LATS:LATN*}*,*{*LON*W:LONE}*)
>     printVarSummary(SST)
>
> =================================
> [1] Your file variable is:
> *     short *sst(time, lat, lon)
>
>      The coordinates are:
>
>        Coordinates:
>             time: [66443..80078]
>             *lat: [89.5..-89.5]               ; <=== North-to-South
> ordering*
>             lon: [0.5..359.5]
>
> [2] NCL has the *short2flt *
> <https://www.ncl.ucar.edu/Document/Functions/Contributed/short2flt.shtml>function
> that unpacks an maintains meta data.
>
>     sst =* short2flt*( f->sst )
> *; import and unpack the variable maintaining meta data*
> *    printVarSummary
> <https://www.ncl.ucar.edu/Document/Functions/Built-in/printVarSummary.shtml>(sst)*
>     *printMinMax*
> <https://www.ncl.ucar.edu/Document/Functions/Contributed/printMinMax.shtml>
> (sst,0)
>
> [3]  It is not necessary to explicitly read the following coordinate
> variables from the file. NCL imports the variable as a *data structure*
> ['object'] that contains the array values and meta data including
> coordinate information associated with the variable.
>
> time = sst*&*time
> lat    = sst*&*lat
> lon   = sst*&*lon
>
> [4] There are different methods for accessing subsets of a variable:
> classic indexing and coordinate variable indexing. See above.
>
> [5] Generally, *NCL graphics* *are aware of coordinate order.* Hence, no
> reordering is necessary.
>
> ---
> [6]
>
>
>
>
> On Sun, May 19, 2019 at 9:46 PM Atsuyoshi MANDA <am at bio.mie-u.ac.jp>
> wrote:
>
>> Hi,
>>
>> I am trying to reorder the array dimensions in the monthly mean OISST
>> version 2 dataset, which was downloaded from
>> ftp://ftp.cdc.noaa.gov/Datasets/noaa.oisst.v2/sst.mnmean.nc.
>>
>> However, reordering using the named subscripting in my script does not
>> work.
>>
>> Please see the attached files:
>> OIV2LR.sst.1982JUL.png (original data)
>> OIV2LR.sstre.1982JUL.png (reordered data)
>>
>> Any suggestions would be greatly appreciated.
>>
>> Here is my script:
>> ;=========================
>> indir="./"
>> infle="sst.mnmean.nc"
>> in=indir+"/"+infle
>>
>> script_name  = get_script_name()
>> outdir="BIN_"+systemfunc("basename "+script_name+" .ncl")
>>
>> dset="OIV2LR"
>> MM=7
>>
>> month_abbr = (/"","JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP", \
>>                     "OCT","NOV","DEC"/)
>> MMM=month_abbr(MM)
>>
>> system("mkdir -vp "+outdir)
>>
>>
>> f=addfile(in, "r")
>>
>> ;printVarSummary(f)
>> ;print(f)
>>
>> lon=f->lon
>> lat=f->lat
>> sst=f->sst
>> time=f->time
>>
>> utc_date = cd_calendar(time, 0)
>>
>> year   = tointeger(utc_date(:,0))    ; Convert to integer for
>> month  = tointeger(utc_date(:,1))    ; use sprinti
>> day    = tointeger(utc_date(:,2))
>> hour   = tointeger(utc_date(:,3))
>> minute = tointeger(utc_date(:,4))
>> second = utc_date(:,5)
>> date_str = sprinti("%0.2iZ ", hour) + sprinti("%0.2i ", day) + \
>>            month_abbr(month) + " "  + sprinti("%0.4i", year)
>>
>> yyyys=1982
>> yyyye=2017
>>
>> sst_scaled=sst*sst at scale_factor + sst at add_offset
>> copy_VarAtts(sst,sst_scaled)
>> copy_VarCoords(sst,sst_scaled)
>> printVarSummary(sst_scaled)
>>
>> sstre=sst_scaled(time|:,lon|:,lat|:)
>> copy_VarAtts(sst_scaled,sst)
>> copy_VarCoords(sst_scaled,sstre)
>> printVarSummary(sstre)
>>
>>
>>
>> dim=dimsizes(year)
>> nt=dim(0)
>>
>> do n=7,7 ;0,nt-1
>>
>> if(year(n) .ge. yyyys .and. year(n) .le. yyyye .and. month(n) .eq. MM)then
>> print(n+" "+date_str(n))
>>
>>
>> figdir="FIG_"+systemfunc("basename "+script_name+" .ncl")+"_"+dset
>> system("mkdir -vp "+figdir)
>> type="png"
>>
>>
>>
>> figfle=dset+"."+"sstre."+year(n)+MMM+""
>> fig=figdir+"/"+figfle
>>
>> print("figfle="+figfle+"."+type)
>>
>> wks = gsn_open_wks(type, fig)
>>
>> res=True
>>   res at cnFillOn              = True               ; turn on color fill
>>   res at cnLinesOn             = False              ; turn off contour lines
>> plot1=gsn_csm_contour_map(wks,sstre(n,:,:),res)
>>
>>
>>
>> figfle=dset+"."+"sst."+year(n)+MMM+""
>> fig=figdir+"/"+figfle
>>
>> print("figfle="+figfle+"."+type)
>>
>> wks = gsn_open_wks(type, fig)
>>
>> res=True
>>   res at cnFillOn              = True               ; turn on color fill
>>   res at cnLinesOn             = False              ; turn off contour lines
>> plot1=gsn_csm_contour_map(wks,sst(n,:,:),res)
>>
>>
>> print("sst(n,90-30,130)="+sst(n,90-30,130)+" "+lon(130)+"E
>> "+lat(90-30)+"N")
>> print("sstre(n,130,90+30-1)="+sstre(n,130,90+30-1)+" "+lon(130)+"E
>> "+sstre&lat(90+30-1)+"N")
>>
>> end if
>>
>> end do
>> ;=========================
>>
>> Thank you,
>> Atsuyoshi
>>
>> -
>> Atsuyoshi Manda, Ph.D
>> Associate Professor,
>> Mie University
>> 1577 Kurimamachiya-cho Tsu city, Mie 514-8507 JAPAN
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190520/a3c3bbaa/attachment.html>


More information about the ncl-talk mailing list