[ncl-talk] Coefficient_of Divergence

Kunal Bali kunal.bali9 at gmail.com
Wed Nov 8 23:05:45 MST 2017


when I try the attached script (plot1.ncl) for large time steps say 442 then
it shows an error



*fatal:divide: Division by 0, Can't continuefatal:Div: operator failed,
can't continuefatal:["Execute.c":8640]:Execute: Error occurred at or near
line 120 in file plot.ncl*

*120 line is *
CoD1 = ((DATA_SINGLE_3D - data_subset)/(DATA_SINGLE_3D + data_subset))^2

So I separated this line to
   x1 = (DATA_SINGLE_3D - data_subset)
   x2 = (DATA_SINGLE_3D + data_subset)

and then tried


*CoD   = 1. / where(x2.ne.0, x1/x2, x2 at _FillValue)   ; it can be divisible
by 0    CoD1 = (CoD)^2*
   printVarSummary(CoD1)
   printMinMax(CoD1, 0)


But, still showing the same error



*fatal:divide: Division by 0, Can't continuefatal:Div: operator failed,
can't continuefatal:["Execute.c":8640]:Execute: Error occurred at or near
line 120 in file plot.ncl*


regards
Kunal Bali






On Wed, Nov 8, 2017 at 10:56 AM, Kunal Bali <kunal.bali9 at gmail.com> wrote:

> I followed your instruction, But now CoD1 and CoD2 values are showing the
> same values, which is incorrect? and because of this values of the square
> root of CoD2 is not correct.
>
>
> ;-----calculation of coefficient of divergence
>    CoD1 = ((DATA_SINGLE_3D - data_subset)/(DATA_SINGLE_3D+ data_subset))^2
>    printVarSummary(CoD1)
>    printMinMax(CoD1, 0)
>
>    CoD1 at _FillValue = -28672
>    CoD2 = dim_avg_n_Wrap(CoD1, 0)    ; (nlat,mlon)
>    printVarSummary(CoD2)
>    printMinMax(CoD2,0)
>
>    CoD3 = sqrt(CoD2)
>    printVarSummary(CoD3)
>    printMinMax(CoD3, 0)
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *Variable: CoD1Type: floatTotal Size: 7824960 bytes            1956240
> valuesNumber of Dimensions: 3Dimensions and sizes:    [3] x [660] x
> [988]Coordinates: Number Of Attributes: 1  _FillValue :    -28672(0)
> min=0   max=0.961394Variable: CoD2Type: floatTotal Size: 2608320
> bytes            652080 valuesNumber of Dimensions: 2Dimensions and
> sizes:    [660] x [988]Coordinates: Number Of Attributes: 2  _FillValue
> :    -28672  average_op_ncl :    dim_avg_n function was applied(0)
> min=0   max=0.961394Variable: CoD3Type: floatTotal Size: 2608320
> bytes            652080 valuesNumber of Dimensions: 2Dimensions and
> sizes:    [660] x [988]Coordinates: Number Of Attributes: 1  _FillValue
> :    -28672(0)    min=0   max=0.980507*
>
>
>
> regsrds
> Kunal Bali
>
>
>
>
>
>
> On Wed, Nov 8, 2017 at 3:55 AM, Dennis Shea <shea at ucar.edu> wrote:
>
>>
>> *Variable: CoD1*
>> *Dimensions and sizes: [3] x [660] x [988]*
>> *(0) min=0   max=0.961394*
>>
>>
>> step 2:
>>
>>    CoD2 = sum(CoD1)/3           <===  No!
>>    printVarSummary(CoD2)
>>    printMinMax(CoD2, 0)
>>
>> https://www.ncl.ucar.edu/Document/Functions/Contributed/dim_
>> avg_n_Wrap.shtml
>>
>>    CoD2 = dim_avg_n_Wrap(CoD1, 0)    ; (nlat,mlon)
>>    printVarSummary(CoD2)
>>    printMinMax(CoD2,0)
>>
>> ===
>> If you still have large numbers, the find one grid point where a large
>> number occurs, then print the values.
>>
>>    print(CoD1(:,nn,mm))   ; print series where large numbers occur
>> (indices:  nn,mm)
>>
>> See documentation for
>>    https://www.ncl.ucar.edu/Document/Functions/Built-in/ind.shtml
>>    https://www.ncl.ucar.edu/Document/Functions/Built-in/ind_resolve.shtml
>> See Examples 2 & 3
>>
>>
>>
>>
>>
>>
>> On Tue, Nov 7, 2017 at 1:32 PM, Kunal Bali <kunal.bali9 at gmail.com> wrote:
>>
>>> Thanks for suggesting this.
>>>
>>> Actually, I am trying to calculate the COD at each grid cell.
>>>
>>> So as you suggested
>>>
>>>
>>> *DATA_SINGLE_3D = conform(data_subset, data_single, 0)    ; it worked*
>>>
>>>
>>>
>>> *Variable: DATA_SINGLE_3DType: floatTotal Size: 7824960 bytes
>>> 1956240 valuesNumber of Dimensions: 3Dimensions and sizes: [3] x [660] x
>>> [988]Coordinates: Number Of Attributes: 1  _FillValue : -28672*
>>> step 1:
>>> CoD1 = ((DATA_SINGLE_3D - data_subset)/(DATA_SINGLE_3D+ data_subset))^2
>>>    printVarSummary(CoD1)
>>>    printMinMax(CoD1, 0)
>>>
>>> *Variable: CoD1*
>>> *Type: float*
>>> *Total Size: 7824960 bytes*
>>> *            1956240 values*
>>> *Number of Dimensions: 3*
>>> *Dimensions and sizes: [3] x [660] x [988]*
>>> *Coordinates: *
>>> *Number Of Attributes: 1*
>>> *  _FillValue : -28672*
>>> *(0) min=0   max=0.961394*
>>>
>>>
>>> step 2:
>>>
>>>    CoD2 = sum(CoD1)/3
>>>    printVarSummary(CoD2)
>>>    printMinMax(CoD2, 0)
>>>
>>> *Variable: CoD2*
>>> *Type: float*
>>> *Total Size: 4 bytes*
>>> *            1 values*
>>> *Number of Dimensions: 1*
>>> *Dimensions and sizes: [1]*
>>> *Coordinates: *
>>> *(0) min=20691.8   max=20691.8   --------> values are very
>>> high? and also it's not giving at each grid cell, because of that I can't
>>> calculate the sqrt in the next step*
>>>
>>>
>>> step 3:
>>>
>>>   CoD3 = sqrt(CoD2)
>>>  printVarSummary(CoD3)
>>>  printMinMax(CoD2, 0)
>>>
>>>
>>> The final values are coming very high. It should be less than 0.3 at
>>> each grid cell.
>>>
>>> regards
>>> Kunal Bali
>>>
>>>
>>>
>>>
>>>
>>> On Wed, Nov 8, 2017 at 1:18 AM, Dennis Shea <shea at ucar.edu> wrote:
>>>
>>>> If you have a one-dimensional array (1D; eg: a 'time series') and a
>>>> three-dimensional array (3D; eg: time series at multiple grid points), you
>>>> *must* make the arrays 'conformant' for an array calculation
>>>>
>>>> You have:
>>>>    CoD1 = ((data_single(:) - data_subset(:,:,:))/(data_single(:) +
>>>> data_subset(:,:,:)))^2
>>>>
>>>> You did not include a 'printVarSummary' of these variables. Assuming
>>>> data_single(ntim) and data_subset(ntim,nlat,mlon) then you must replicate
>>>> (aka, propogate) the 1D array to the 3D array size. In NCL, this is called
>>>> 'array conformance' . Please see and carefully read:
>>>>
>>>> https://www.ncl.ucar.edu/Document/Functions/Built-in/conform.shtml
>>>> https://www.ncl.ucar.edu/Document/Functions/Built-in/conform_dims.shtml
>>>>
>>>> ---
>>>>   DATA_SINGLE_3D = conform(data_subset, data_single, 0)    ;
>>>> (ntim,nlat,mlon)
>>>>   printVarSummary(DATA_SINGLE_3D)   ; Look at data
>>>>
>>>> Do *not* use (:,:,:) in a computation... this is inefficient.
>>>>
>>>>   CoD1 = ((DATA_SINGLE_3D - data_subset)/(DATA_SINGLE_3D+
>>>> data_subset))^2
>>>>   printVarSummary(CoD1)
>>>>   printMinMax(CoD1, 0)
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Tue, Nov 7, 2017 at 11:15 AM, Kunal Bali <kunal.bali9 at gmail.com>
>>>> wrote:
>>>>
>>>>> Dear NCL user
>>>>>
>>>>> Suppose, I have 2 datasets
>>>>> e.g.
>>>>>
>>>>> data1 = of single point lat & lon (e.g 28N, 72E) with time steps 365
>>>>> (having filling values)
>>>>> data2 = of grid box (24-32N, 68-76E) with time steps 365  (having
>>>>> filling values)
>>>>>
>>>>> Now I want to calculate the CoD from one single point to 400km grid
>>>>> box area and then lot the spatial map of the calculated product.
>>>>>
>>>>> Formula for CoD is GIVEN BELOW
>>>>>>>>>>
>>>>> So I calculated in NCL as
>>>>>
>>>>> CoD1 = ((data1 - data2)/(data1 + data2))^2
>>>>> CoD_final = (sqrt(sum(CoD1)))/3
>>>>>
>>>>> please let me know is it the right way to do?
>>>>>
>>>>> I tried to plot the final product CoD_final with the attached script,
>>>>> but error comes as
>>>>>
>>>>> fatal:Minus: Number of dimensions do not match, can't continue
>>>>> fatal:["Execute.c":8578]:Execute: Error occurred at or near line 116
>>>>> in file plot.ncl
>>>>>
>>>>>
>>>>>
>>>>> regards
>>>>> Kunal Bali
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> ncl-talk mailing list
>>>>> ncl-talk at ucar.edu
>>>>> List instructions, subscriber options, unsubscribe:
>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>
>>>>>
>>>>
>>>
>>> _______________________________________________
>>> 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/20171109/7272a3e0/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: COD.png
Type: image/png
Size: 34015 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171109/7272a3e0/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: plot1.ncl
Type: application/octet-stream
Size: 4382 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171109/7272a3e0/attachment.obj>


More information about the ncl-talk mailing list