[ncl-talk] Fwd: Adding Up Files

Maria Gehne - NOAA Affiliate maria.gehne at noaa.gov
Wed Nov 25 17:11:47 MST 2015


Sure, just loose the [i] and it will work.

ref=  where(ref.lt.45, FillValue, ref)

Maria

On Wednesday, November 25, 2015, Tim Melino <melino33 at gmail.com> wrote:

> Is it possible to do something like this on each member of the array:
>
>  ref[i] = where(ref[i].lt.45,FillValue,ref[i])
>
> Then sum up the values?
>
> On Wed, Nov 25, 2015 at 4:17 PM, Tim Melino <melino33 at gmail.com
> <javascript:_e(%7B%7D,'cvml','melino33 at gmail.com');>> wrote:
>
>> Hi Maria,
>>
>> Each file is a single time I am trying to read in the first scan level so
>> I think the answer to your question is yes. Here is the variable summary
>> for the field I am reading:
>>
>> Variable: ref
>> Type: float
>> Total Size: 161604 bytes
>>             40401 values
>> Number of Dimensions: 2
>> Dimensions and sizes: [y0 | 201] x [x0 | 201]
>> Coordinates:
>>             y0: [-100..100]
>>             x0: [-100..100]
>> Number Of Attributes: 10
>>   grid_mapping : grid_mapping_0
>>   coordinates : lon0 lat0
>>   units : dBZ
>>   long_name : radar_reflectivity
>>   standard_name : REF
>>   valid_max : 47.81145
>>   valid_min : -25.57751
>>   time : 1427402261
>>   z0 : 1
>>   _FillValue : -9999
>>
>>
>> On Wed, Nov 25, 2015 at 1:50 PM, Maria Gehne - NOAA Affiliate <
>> maria.gehne at noaa.gov
>> <javascript:_e(%7B%7D,'cvml','maria.gehne at noaa.gov');>> wrote:
>>
>>> 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
>>> <javascript:_e(%7B%7D,'cvml','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 <javascript:_e(%7B%7D,'cvml','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/7655d9fb/attachment.html 


More information about the ncl-talk mailing list