[ncl-talk] Array subsetting

Dennis Shea shea at ucar.edu
Thu Oct 24 16:30:50 MDT 2019


k2    = f2[:]->k22_deepc(itime_b:itime_e,:) ; [Time | 14] x [nCells |
5898242]
k2!0 = "nCells"
k2 at _FillValue = 0

nifa  = f3[:]->nifa(itime_b:itime_e,:,:)          ;  [Time | 14] x [nCells
| 5898242] x [nVertLevels | 55]
nifa at _FillValue = *default_fillvalue*(typeof(nifa))

dim_k2         = *dimsizes*(k2)    ; (/14,5898242/)
k2_1d           = *ndtooned*(k2)
k2_1d_good = *ind*(.not*.ismissing*(k2_1d))
printVarSummary(k2_1d_good)
print("-----")

k2_good   = *ind_resolve*(*ind*
<http://www.ncl.ucar.edu/Document/Functions/Built-in/ind.shtml>
(.not.ismissing(k2_1d)),dim_k2)
printVarSummary(k2_good)

---
So ....could the indices change for each time step? If,

ntim = dim_k2(0)

If so, you will have to use a do-loop for each time

  do nt=0,ntim-1
       ... use indices for current time
  end do


On Thu, Oct 24, 2019 at 2:24 PM Laura Fowler <laura at ucar.edu> wrote:

> Dennis:
> After following your suggestions, I got the following error messages:
>
> fatal:Illegal subscript. Subscripts must be scalar or one dimensional
> vectors
>
> fatal:["Execute.c":8637]:Execute: Error occurred at or near line 74 in
> file plot.xmb.ncl
>
> The portion of the sourcecode that causes me issues is:
>
> k2 = f2[:]->k22_deepc(itime_b:itime_e,:)
>
> k2!0 = "nCells"
>
> k2 at _FillValue = 0
>
>
> ;--- nifa:
>
> nifa = f3[:]->nifa(itime_b:itime_e,:,:)
>
> nifa at _FillValue = default_fillvalue(typeof(nifa))
>
> printVarSummary(k2)
>
> printVarSummary(nifa)
>
> nifa_k2 = where(.not.ismissing(k2),nifa(:,:,k2),nifa at _FillValue)
>
> printVarSummary(nifa_k2)
>
>
>
> with the following outputs:
>
> Variable: k2
>
> Type: integer
>
> Total Size: 330301552 bytes
>
>             82575388 values
>
> Number of Dimensions: 2
>
> Dimensions and sizes: [Time | 14] x [nCells | 5898242]
>
> Coordinates:
>
> Number Of Attributes: 3
>
>   _FillValue : 0
>
>   units : unitless
>
>   long_name : k22 level for deep convection in the Grell-Freitas
> convection scheme
>
>
>
> Variable: nifa
>
> Type: float
>
> Total Size: 18166585360 bytes
>
>             4541646340 values
>
> Number of Dimensions: 3
>
> Dimensions and sizes: [Time | 14] x [nCells | 5898242] x [nVertLevels |
> 55]
>
> Coordinates:
>
> Number Of Attributes: 3
>
>   _FillValue : 9.96921e+36
>
>   long_name : Ice-friendly aerosol number concentration
>
>   units : nb kg^{-1}
>
> fatal:Illegal subscript. Subscripts must be scalar or one dimensional
> vectors
>
>
> fatal:["Execute.c":8637]:Execute: Error occurred at or near line 74 in
> file plot.xmb.ncl
>
> Thanks,
> Laura
>
>
>
>
> On Thu, Oct 24, 2019 at 11:55 AM Dennis Shea <shea at ucar.edu> wrote:
>
>> You can not directly check for _FillValue. Specifically:  k2.ne.k2 at _FillValue
>> will not do the correct test.
>> You must use a function. eg: in fortran:*   ieee_is_nan(*x)
>>
>> In NCL: *ismissing
>> <http://www.ncl.ucar.edu/Document/Functions/Built-in/ismissing.shtml> *...
>> please read the documentation
>>
>>
>> Try replacing:
>>       ifa = where(k2.ne.k2 at _FillValue,diag(:,k2),diag at _FillValue)
>> with
>>       ifa = where(*.not.ismissing*(k2), diag(:,k2), diag at _FillValue)
>>
>> On Thu, Oct 24, 2019 at 10:37 AM Laura Fowler via ncl-talk <
>> ncl-talk at ucar.edu> wrote:
>>
>>> Hello:
>>>
>>> I have the following arrays:
>>>
>>> Variable: diag
>>>
>>> Type: float
>>>
>>> Total Size: 1297613240 bytes
>>>
>>>             324403310 values
>>>
>>> Number of Dimensions: 2
>>>
>>> Dimensions and sizes: [nCells | 5898242] x [nVertLevels | 55]
>>>
>>> Coordinates:
>>>
>>> Number Of Attributes: 3
>>>
>>>   _FillValue : 9.96921e+36
>>>
>>>   long_name : Ice-friendly aerosol number concentration
>>>
>>>   units : nb kg^{-1}
>>>
>>>
>>>
>>> Variable: k2
>>>
>>> Type: integer
>>>
>>> Total Size: 23592968 bytes
>>>
>>>             5898242 values
>>>
>>> Number of Dimensions: 1
>>>
>>> Dimensions and sizes: [nCells | 5898242]
>>>
>>> Coordinates:
>>>
>>> Number Of Attributes: 1
>>>
>>>   _FillValue : 0
>>>
>>>
>>> where nCells is the horizontal dimension and nVertLevels is the number
>>> of vertical levels. you can think of k2 as the index for the base of a
>>> convective cloud with a missing value set to zero. I would like to build an
>>> array nifa which contains the value of diag at k2, such that:
>>>
>>>
>>> nifa(iCell) = diag(:,k2(iCell)) for iCell varying between 0 and nCells-1.
>>>
>>>
>>>
>>> I tried to use the function "where" but this did not work. I get the
>>> following:
>>>
>>> nifa = where(k2.ne.k2 at _FillValue,diag(:,k2),diag at _FillValue)
>>>
>>>
>>> fatal:NclMalloc Failed:[errno=12]
>>>
>>> Segmentation fault (core dumped)
>>>
>>>
>>>
>>> I am not sure why this is not working. I also tried the ismissing
>>> function but this did not work either. Any suggestions?
>>>
>>>
>>> Thanks,
>>>
>>> Laura
>>>
>>>
>>>
>>> --
>>>
>>> !-------------------------------------------------------------------------------------------------------------
>>> Laura D. Fowler
>>>
>>> Mesoscale and Microscale Meteorology Division (MMM)
>>> National Center for Atmospheric Research
>>> P.O. Box 3000, Boulder CO 80307-3000
>>>
>>> e-mail: laura at ucar.edu
>>> phone: 303-497-1628
>>>
>>>
>>> !-------------------------------------------------------------------------------------------------------------
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at ucar.edu
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
> --
>
> !-------------------------------------------------------------------------------------------------------------
> Laura D. Fowler
>
> Mesoscale and Microscale Meteorology Division (MMM)
> National Center for Atmospheric Research
> P.O. Box 3000, Boulder CO 80307-3000
>
> e-mail: laura at ucar.edu
> phone: 303-497-1628
>
>
> !-------------------------------------------------------------------------------------------------------------
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20191024/bd89ab98/attachment.html>


More information about the ncl-talk mailing list