[ncl-talk] Error subscript when using indices output from dim_pqsort to reorder another array

YAN HUIPING yanhp2009 at gmail.com
Fri May 29 13:48:36 MDT 2020


Hi Rashed,

I am very appreciated for your reply. 
Yes, I am try to reorder the 4-D array and the 2-D array is a simple example to show the problem. 
What I am done here is sorting the data in vertical, i.e. from the bottom surface to the top. Since the pressure in vertical is decreasing while the temperature may be not,  I could not simply use the dim_pqsort_n to reorder the temperature (Y) as the pressure array (X).  That’s why I have to use the indices from the pressure (X here) to reorder the temperature (Y). 

Actually, I have used several loops to do such reordering and solved my own problems. But I think this function may need some improvements.


Thanks,
Huiping


> On May 29, 2020, at 5:42 PM, Rashed Mahmood <rashidcomsis at gmail.com> wrote:
> 
> Hi Huiping,
> I think in this case the following should work, note that your ip variable has dimensions [2,3] as you can see from the print statements:
> 
> y(0,:)=y(0,ip(0,:))
> y(1,:)=y(1,ip(1,:))
> 
> However, I guess this is not what you are trying to do for your original array of (time,nlat,nlon,nlev)?
> If, for example "data" is a variable name with sizes (ntime,nlat,nlon,nlev) and you want to sort out according to time dimension, you can do something as:
> data_new = dim_pqsort_n(data,-2,0)  ; read documentation about the option -2
> NOTE that this will sort out your "data" variable in decreasing order.
> See the documentation for different of sorting in descending/ascending order.
> https://www.ncl.ucar.edu/Document/Functions/Built-in/dim_pqsort_n.shtml <https://www.ncl.ucar.edu/Document/Functions/Built-in/dim_pqsort_n.shtml>
> 
> hope that helps,
> Cheers,
> Rashed
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> On Thu, May 28, 2020 at 3:49 PM YAN HUIPING via ncl-talk <ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu>> wrote:
> Thank you Laura, I tried, but it does not help.
> and just now I created a simple script like the example of the function dim_pqsort ,and  it came out the same errors. 
> 
> “ fatal:Illegal subscript. Subscripts must be scalar or one dimensional vectors
> 
> fatal:["Execute.c":8637]:Execute: Error occurred at or near line 12 in file test.ncl"
> 
> =========================================
> 
> begin
>   
> x=(/(/2,1,3/),(/4,6,5/)/)
> printVarSummary(x)
> print(x)
> ip=dim_pqsort(x,-2)
> print(x)
> 
> printVarSummary(ip)
> 
> y=(/(/2,1,3/),(/4,6,5/)/)
> y=y(ip,:)
> 
> print(y)
> end
> 
> 
> 
>> On May 29, 2020, at 6:35 AM, Laura Fowler <laura at ucar.edu <mailto:laura at ucar.edu>> wrote:
>> 
>> Hi Huiping:
>> may be you need to add delete(TTnew) before the line:
>> 
>> delete(TTnew)
>> TTnew=y(ip,:,:,:);
>> printMinMax(TTnew,0)
>> 
>> since TTnew is originally a 4-dimensional array.
>> Laura
>> 
>> 
>> 
>> 
>> On Thu, May 28, 2020 at 4:23 PM YAN HUIPING via ncl-talk <ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu>> wrote:
>> Hi,
>> I post the message
>> 
>> 
>> the ncl script:
>> 
>> ==========================================
>> x=PPnew
>> print(num(ismissing(x)))
>> y=TTnew
>> ip=dim_pqsort_n(x,-2,3)
>> printVarSummary(x)
>> printVarSummary(ip)
>> printMinMax(ip,0)
>> print(dimsizes(ip))
>> 
>> TTnew=y(ip,:,:,:);
>> printMinMax(TTnew,0)
>> =========================================
>> 
>> (0)	missing number 0
>> 
>> Variable: x
>> Type: float
>> Total Size: 31948800 bytes
>>             7987200 values
>> Number of Dimensions: 4
>> Dimensions and sizes:	[time | 12] x [lat | 160] x [lon | 320] x [LEV | 13]
>> Coordinates: 
>>             time: [20160116.875..20161216.875]
>>             lat: [89.14151942646112..-89.14151942646112]
>>             lon: [   0..358.875]
>>             LEV: [107500..5000]
>> Number Of Attributes: 7
>>   _FillValue :	1e+20
>>   institution :	MPIMET
>>   cell_methods :	time: mean
>>   table :	128
>>   code :	130
>>   units :	K
>>   long_name :	pressure
>> 
>> Variable: ip
>> Type: integer
>> Total Size: 31948800 bytes
>>             7987200 values
>> Number of Dimensions: 4
>> Dimensions and sizes:	[12] x [160] x [320] x [13]
>> Coordinates: 
>> (0)	min=0   max=12
>> (0)	12
>> (1)	160
>> (2)	320
>> (3)	13
>> fatal:Illegal subscript. Subscripts must be scalar or one dimensional vectors
>> 
>> ====================
>> 
>> Y has the same dimensions as X ([time | 12] x [lat | 160] x [lon | 320] x [LEV | 13]). And there is no missing value in X, but Y has some.
>> 
>> 
>> Thus, I think there are some bugs here. Could you please help me look into it?
>> 
>> Thanks,
>> Huiping
>> 
>> 
>>> On May 29, 2020, at 1:21 AM, Dennis Shea <shea at ucar.edu <mailto:shea at ucar.edu>> wrote:
>>> 
>>> Whenever you encounter an error, you should add print statements to help you debug the issue.
>>> 
>>>   printVarSummary(x)                         ; overview of source variable
>>>   print("-----")                                       ; visual break
>>> 
>>>   ip = dim_pqsort(x,-2)                          ;; descending order
>>>   printVarSummary(ip)
>>>   prinyMinMax(ip, 0)
>>>   print("-----") 
>>> 
>>>   dim_ip = dimsizes(ip)
>>>   print(dim_ip)
>>>   print("-----")    
>>> 
>>>    y=y(ip,:,:,:)
>>> =============================
>>> Are there grid locations that contain all missing values? 
>>> 
>>> 
>>> 
>>> On Tue, May 26, 2020 at 6:36 PM YAN HUIPING via ncl-talk <ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu>> wrote:
>>> Hi,
>>> I am using the function dim_pqsort to reorder an array with dimensions of (time,nlat, nlon, nlev) following the instructions https://www.ncl.ucar.edu/Document/Functions/Built-in/dim_pqsort.shtml <https://www.ncl.ucar.edu/Document/Functions/Built-in/dim_pqsort.shtml>
>>> 
>>> ip=dim_pqsort(x,-2);; descending order
>>> y=y(ip,:,:,:)
>>> 
>>> However, there are error messages: “fatal:Illegal subscript. Subscripts must be scalar or one dimensional vectors”.
>>> Ps: the version of NCL I used is 6.5.0
>>> 
>>> Could please help me on this problem?
>>> 
>>> Thanks,
>>> Huiping
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu>
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk <http://mailman.ucar.edu/mailman/listinfo/ncl-talk>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu>
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk <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 <mailto:laura at ucar.edu>
>> phone: 303-497-1628
>> 
>> !-------------------------------------------------------------------------------------------------------------
> 
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu>
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk <http://mailman.ucar.edu/mailman/listinfo/ncl-talk>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20200530/d12e34a1/attachment.html>


More information about the ncl-talk mailing list