Re: usage of absolute (abs) function

From: madhura ranade <madhuraran_at_nyahnyahspammersnyahnyah>
Date: Tue Mar 12 2013 - 23:36:43 MDT

Hello Adam,

Thanks a lot!

The stat_dispersion function solved my problem. The data didn't have any
problem, but while computing tvmax, I did not put a check on missing
values, so the missing value in tvmax was treated as a data point. Though I
fail to understand why 'abs' couldn't function, even though when missing
value is treated as a data value.

Also thank you for telling me about the 'where' function.

I realized, last time I mailed you on your personal email id, instead of
ncl-talk. My apologies.

Madhura

On 12 March 2013 21:07, Adam Phillips <asphilli@ucar.edu> wrote:

> Hi Madhura,
> I would suggest putting in multiple print statements to identify exactly
> what tvmax value is causing fabs problems. I would also take a closer look
> at your input data. What you have told me so far hints to me that something
> is amiss with your data.. (Although that is not necessarily the case.)
> Along with the multiple print statements to identify where things are
> failing, I would put the following in:
>
> opt = True
> opt@PrintStat = True
> statb = *stat_dispersion*(tvmax, opt )
>
>
>
> http://www.ncl.ucar.edu/Document/Functions/Contributed/stat_dispersion.shtml
>
> That should give you information about your tvmax array, including whether
> there are any nan or inf values present.
>
> I also believe you can accomplish what you want by using the where
> function. That way you get rid of all do loops:
> rcsig = where(fabs.ge.tcrit, rc, rcsig@_FillValue)
> Note that in this case rcsig needs to have the _FillValue attribute set.
>
> Finally, please reply to the ncl-talk email list only, as that way others
> can assist if I am not available. In case you need to reply to this email
> please respond to my original message to the entire ncl-talk email list.
> Best regards, Adam
>
>
> On 03/12/2013 01:36 AM, madhura ranade wrote:
>
> Hello Adam,
>
> Thank you for your reply.
>
> I had read about the fabs function being superceded by abs. So I used
> 'abs' initially, but I got the same error messages for both 'abs' as well
> as 'fabs'.
>
> As you mentioned, I tried printing the original as well as absolute value
> of my variable tvmax. I got the desired output, i.e. the abs function
> returned the absolute value. However, it fails to work within the loop....
> I don't understand why.
>
> I am using the NCL version 6.0
>
> This is my exact code.
>
> rc(:,:,:) = regCoef(pc1,tmax(:,:,:))
>
> tvmax = onedtond(rc@tval,dimsizes(rc))
>
> print(tvmax(0,10,11))
> print(abs(tvmax(0,10,11))
>
> tcrit = 1.9901
>
> do i = 0,nday-1
> do ilat = 0,nlat-1
> do ilon = 0,nlon-1
> if(.not.ismissing(tvmax(i,ilat,ilon)))then
> if((fabs(tvmax(i,ilat,ilon))).ge.tcrit)then
> rcsig(i,ilat,ilon) = rc(i,ilat,ilon)
> end if
> end if
> end do
> end do
> end do
>
>
> This is the output I got after executing the code.
>
> Variable: tvmax (subsection)
> Type: float
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> (0) -0.4313997
> (0) 0.4313997
>
>
> "Argument type mismatch on argument (0) of (abs) can not coerce"
>
>
> On 11 March 2013 22:46, Adam Phillips <asphilli@ucar.edu> wrote:
>
>> Hi Madhura,
>> A slight correction: I misread the documentation. abs supercedes fabs..
>> So you should be using abs, and not fabs.. My apologies for the confusion..
>> Adam
>>
>>
>> On 03/11/2013 11:13 AM, Adam Phillips wrote:
>>
>> Hi Madhura,
>> It sounds to me like fabs is not liking what you are passing it, which is
>> weird as fabs accepts all types of arrays. What happens if you were to take
>> the fabs call out of the if statement?
>> print(fabs(tvmax(i,ilat,ilon)))
>>
>> (Note: According to the documentation fabs should be used in place of abs
>> due to the fact that fabs accepts arrays of all types.)
>>
>> Finally, what version of NCL are you running? Please respond to ncl-talk
>> so others besides myself can assist.. Adam
>>
>> On 03/11/2013 01:01 AM, madhura ranade wrote:
>>
>> Hello all,
>> i am trying to test the significance of regression coefficient
>>
>> so this is what i did.
>>
>> if((fabs(tvmax(i,ilat,ilon))).ge.tcrit)then
>> rcsig(i,ilat,ilon) = rc(i,ilat,ilon)
>> end if
>>
>> initially i had used abs function instead of fabs. then i got an error
>>
>> "Argument type mismatch on argument (0) of (abs) can not coerce"
>>
>> Then i found from one of the ncl talks to use 'fabs' instead of 'abs'
>>
>> i did so, and yet i got the same error message.
>>
>> "Argument type mismatch on argument (0) of (fabs) can not coerce"
>>
>> I have defined both the variables, i.e. rc and rcsig as float.
>>
>> is there any way i check this?
>>
>> Thanks.
>>
>> Madhura
>> *
>> *
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>> --
>> ______________________________________________________________
>> Adam Phillips asphilli@ucar.edu
>> NCAR/Climate and Global Dynamics Division (303) 497-1726
>> P.O. Box 3000
>> Boulder, CO 80307-3000 http://www.cgd.ucar.edu/cas/asphilli
>>
>>
>> --
>> ______________________________________________________________
>> Adam Phillips asphilli@ucar.edu
>> NCAR/Climate and Global Dynamics Division (303) 497-1726
>> P.O. Box 3000
>> Boulder, CO 80307-3000 http://www.cgd.ucar.edu/cas/asphilli
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
> --
> ______________________________________________________________
> Adam Phillips asphilli@ucar.edu
> NCAR/Climate and Global Dynamics Division (303) 497-1726
> P.O. Box 3000
> Boulder, CO 80307-3000 http://www.cgd.ucar.edu/cas/asphilli
>
>

*
*

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Mar 12 21:36:54 2013

This archive was generated by hypermail 2.1.8 : Wed Mar 13 2013 - 14:19:38 MDT