Re: trouble with calculating the cosine of 2 dimensional latitude

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Tue Apr 17 2012 - 08:53:25 MDT

As noted in the documentation
          http://www.ncl.ucar.edu/Document/Functions/Built-in/cos.shtml

Arguments
value - One or more values of any dimension, in radians.

======
Your must input radians *not* degrees.

rad = 4*atan(1.0)/180

Even with the correct units your coding also is an issue. The following

      u = f->U_GRD_GDS5_ISBL_10(i,:,:)/cos(rad*lat)*113000

is equivalent to

      u = (f->U_GRD_GDS5_ISBL_10(i,:,:)/cos(rad*lat))*113000

which is not correct.

Also, as noted below, better to use

    u = f->U_GRD_GDS5_ISBL_10(i,:,:)
    v = f->V_GRD_GDS5_ISBL_10(i,:,:)

    u = u/(cos(rad*lat)*113000)
    v = v/113000

This approach maintains meta data

On 4/17/12 7:58 AM, Mary Haley wrote:
> Alexander,
>
> When you do a calculation like this:
>
>> u = f->U_GRD_GDS5_ISBL_10(i,:,:)/cos(lat)*113000
>
> Any metadata that may have been part of f->U_GRD_GDS54_ISBL_10 will get stripped off (except the _FillValue attribute).
>
> This includes any lat/lon coordinate arrays that may have been attached to your data.
>
> To avoid losing metadata, you can do something like this:
>
> u = f->U_GRD_GDS5_ISBL_10(i,:,:) ; this retains metadata
> u = u/cos(lat)*113000
>
>
> --Mary
>
>
> On Apr 16, 2012, at 11:13 AM, Alexander Semenov wrote:
>
>> Dear NCL-users.
>>
>> I have a question about calculating the cosine of latitude.
>>
>> The trouble is that the latitude I'm using is two-dimensional.
>>
>> float g5_lat_0 ( g5_x_0, g5_y_1 ) - LATITUDE
>>
>> Do, when I calculate the cosine, the whole domain gets strange. NCL still plots it, but obviously something is going wrong. I attached 2 plots. The parameter I'm trying to calculate should look like the plot "when I don't devide U by cosine". Is there any way to fix that? Thanks
>>
>> That's the part of my code:
>>
>> i = 10 ;HEIGHT
>> lat = f->g5_lat_0
>> printVarSummary(lat)
>> lon = f->g5_lon_1
>> u = f->U_GRD_GDS5_ISBL_10(i,:,:)/cos(lat)*113000
>> v = f->V_GRD_GDS5_ISBL_10(i,:,:)/113000
>>
>>
>>
>> --
>> regards
>>
>> *******************************************************
>> Alexander Semenov
>>
>> PhD Student - Research Assistant
>> International Arctic Research Center
>> Department of atmospheric sciences
>> University of Alaska Fairbanks
>>
>> 930 Koyukuk dr, 408c3
>> Fairbanks, AK, USA, 99775
>> work phone +19074742672
>>
>> <when devide U by cosine.png><when I don't devide U by cosine.png>_______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Apr 17 08:53:37 2012

This archive was generated by hypermail 2.1.8 : Fri Apr 20 2012 - 16:21:18 MDT