[ncl-talk] Fwd: Adding Up Files
Maria Gehne - NOAA Affiliate
maria.gehne at noaa.gov
Wed Nov 25 11:50:33 MST 2015
Hi Tim,
what are the dimensions of REF in each file? Are you really trying to read
only the first level/time (or whatever the first two dimensions are)?
I would get rid of the loop entirely. Join the files instead of
concatenating, that gives you an extra dimension. And then you can just sum
over the first dimension. So:
ref = a[:]->REF(0,0,:,:) ; now ref is 75 x nlat x nlon
ref_tot = dim_sum_n_Wrap(ref,0) ; sums over the first dimension and keeps
meta-data
Hop this helps,
Maria
On Wed, Nov 25, 2015 at 3:51 AM, Tim Melino <melino33 at gmail.com> wrote:
> Hi,
>
> I am trying to add up reflectivity values from a bunch of netcdf radar
> data but I can't quite get it to work. I have 75 files to loop over and I
> am trying to add to the total each iteration. I have attached the code
> below. If anyone has any ideas how to put this together correctly that
> would be great!
>
> ;========================
> ; get list of all files and open as "one big file"
> ;========================
> fils = systemfunc ("ls ./grids/ncf*.nc") ; file paths
> a = addfiles (fils, "r")
> ListSetType (a, "cat") ; concatenate (=default)
>
> type = "png"
> wks = gsn_open_wks(type, "radar")
>
> ; Set some Basic Plot options
> res = True
> res at gsnDraw = False ; do not draw the plot
> res at gsnFrame = False ; do not advance the frame
> pltres = True
> pltres at NoTitles = True
> pltres at CommonTitle = True
> pltres at PlotTitle = "Radar Reflectivity DbZ"
> pltres at PanelPlot = True
> pltres at FramePlot = False
>
> ; Set the Colormap
> gsn_define_colormap(wks,"WhBlGrYeRe")
> FillValue = 0
> lat = a[0]->lat0(:,:)
> lon = a[0]->lon0(:,:)
>
> total = 75
> i = 0
> do while(i.le.total)
> ;print (i)
> if ( i .gt. 0 ) then
> ref_save = a[i]->REF(0,0,:,:)
> ref_save = where(ref_save.lt.45,FillValue,ref_save)
> ref_tot = ref_tot + ref_save
> ;print (ref_save)
> else
> ref_tot = a[i]->REF(0,0,:,:)
> ref_tot = where(ref_tot.lt.45,FillValue,ref_tot)
> end if
>
> i=i+1
> end do
>
>
>
>
> Thanks in advance!
> -Tim
>
>
>
>
> _______________________________________________
> 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/20151125/bf205249/attachment.html
More information about the ncl-talk
mailing list