[ncl-talk] question to the NCL latlon_to_SCRIP function

chenhuansheng at mail.iap.ac.cn chenhuansheng at mail.iap.ac.cn
Sun Oct 18 22:46:26 MDT 2015


Hi Dave,

Thanks for your explaination. Now I know the principle of the floating point computer arithmetic. 
Now I realize that the results were right and the rounding error were acceptable.

Thanks again.

Huansheng     




陈焕盛(LAPC/IAP)
大气边界层物理和大气化学国家重点实验室
中国科学院大气物理研究所

From: Dave Allured - NOAA Affiliate
Date: 2015-10-19 06:38
To: chenhuansheng at mail.iap.ac.cn
CC: Mary Haley; ncl-talk
Subject: Re: [ncl-talk] question to the NCL latlon_to_SCRIP function
Huansheng Chen,



The number 0.1 does not have an exact representation in regular floating point computer arithmetic.  The closest possible floating point numbers are approximately 0.10000000149 (single precision), or 0.10000000000000000555 (double precision).


Therefore, it is impossible to create numeric arrays with exactly 0.1 degree intervals.


The cases for 1.0, 0.5 and 0.25 degree intervals are different, because each of these numbers has an exact representation in floating point arithmetic.

Please read this section on Wikipedia.  The discussion uses 0.1 as an example, the same interval that you want:


https://en.wikipedia.org/wiki/Floating_point#Representable_numbers.2C_conversion_and_rounding


Also note that your original end points (89.95d, 179.95d) do not have exact floating point representations.



The best you can do is to make a set of approximate numbers that matches what you need in some way.  Can you restate your problem in terms of how you want to fit your interval and end points to a theoretical set of numbers?


--Dave




On Sun, Oct 18, 2015 at 3:50 AM, chenhuansheng at mail.iap.ac.cn <chenhuansheng at mail.iap.ac.cn> wrote:

Hi Mary,

I tried "Opt at URCorner  = (/  89.97d,  179.97d/)", this resulted in "grid_dims = 3600, 1800".
However, the lat-lon intervals are not exactly 0.1 degree. 
For example: "grid_center_lon = -179.95, -179.849994442901, -179.749988885802, "
It should be "grid_center_lon = -179.95, -179.85, -179.75, "

I also tried "Opt at URCorner  = (/  89.95001d,  179.95001d/)", the problem was similar.
"grid_center_lon = -179.95, -179.849999997221, -179.749999994443, "

The results I want are the 0.1x0.1 grids with exactly equal latitude and longtitude intervals (0.1 degree). How can I get it ?
For the 0.25x0.25 grids, the output results are right.

Best Wishes,
Huansheng




陈焕盛(LAPC/IAP)
大气边界层物理和大气化学国家重点实验室
中国科学院大气物理研究所

From: Mary Haley
Date: 2015-10-17 00:47
To: chenhuansheng at mail.iap.ac.cn
CC: ncl-talk
Subject: Re: [ncl-talk] question to the NCL latlon_to_SCRIP function
It looks like a simple rounding error.  


By providing strict corner lat/lon boundary values and a small resolution, you end up with values like 89.950001 and 179.950001. These are out of range of the URCorner boundary values that you provided, so you then end up with the last two values removed.  


You can try using slightly a higher values for URCorner:


Opt at URCorner       = (/  89.97d,  179.97d/)



I've created a ticket (NCL-2293) on this to see if this is something we can improve.


--Mary




On Fri, Oct 16, 2015 at 1:13 AM, chenhuansheng at mail.iap.ac.cn <chenhuansheng at mail.iap.ac.cn> wrote:

Dear all,

I used the latlon_to_SCRIP function to generate  lat-lon grid file with SCRIP format which will then be used as input files of the ESMF application "ESMF_RegridWeightGen".
When I applied latlon_to_SCRIP to 1x1, 0.5x0.5 and 0.25x0.25 grids, the output results were right. However, when I applied latlon_to_SCRIP to 0.1x0.1 grids, the output results 
are wrong. Do the latlon_to_SCRIP function support to generate a 0.1x0.1 grid file? Can you help me to solve this problem? 
Thank you very much.

The code used  to generate the 0.25x0.25 grids are as follows:
_______________
Opt                = True
Opt at LLCorner       = (/ -89.875d, -179.875d/)
Opt at URCorner       = (/  89.875d,  179.875d/)
Opt at ForceOverwrite = True
Opt at PrintTimings   = True
latlon_to_SCRIP(srcGridName,"0.25x0.25",Opt)
delete(Opt)
________________

The header of the output netcdf file is as follows: 
________________
dimensions:
        grid_size = 1036800 ;
        grid_corners = 4 ;
        grid_rank = 2 ;
variables:
        int grid_dims(grid_rank) ;
        double grid_center_lat(grid_size) ;
                grid_center_lat:units = "degrees" ;
        double grid_center_lon(grid_size) ;
                grid_center_lon:units = "degrees" ;
        int grid_imask(grid_size) ;
                grid_imask:units = "unitless" ;
        double grid_corner_lat(grid_size, grid_corners) ;
                grid_corner_lat:units = "degrees" ;
        double grid_corner_lon(grid_size, grid_corners) ;
                grid_corner_lon:units = "degrees" ;

// global attributes:
                :date_created = "Thu Oct 15 19:49:54 CST 2015" ;
                :Createdby = "ESMF_regridding.ncl" ;
                :Conventions = "SCRIP" ;
                :title = "0.25x0.25 grid" ;
data:

grid_dims = 1440, 720 ;
________________


The code used  to generate the 0.1x0.1 grids are as follows:
_______________
Opt                = True
Opt at LLCorner       = (/ -89.95d, -179.95d/)
Opt at URCorner       = (/  89.95d,  179.95d/)
Opt at ForceOverwrite = True
Opt at PrintTimings   = True
latlon_to_SCRIP(srcGridName,"0.1x0.1",Opt)
delete(Opt)
________________

The header of the output netcdf file is as follows: 
_____________
dimensions:
        grid_size = 6474601 ;
        grid_corners = 4 ;
        grid_rank = 2 ;
variables:
        int grid_dims(grid_rank) ;
        double grid_center_lat(grid_size) ;
                grid_center_lat:units = "degrees" ;
        double grid_center_lon(grid_size) ;
                grid_center_lon:units = "degrees" ;
        int grid_imask(grid_size) ;
                grid_imask:units = "unitless" ;
        double grid_corner_lat(grid_size, grid_corners) ;
                grid_corner_lat:units = "degrees" ;
        double grid_corner_lon(grid_size, grid_corners) ;
                grid_corner_lon:units = "degrees" ;

// global attributes:
                :date_created = "Thu Oct 15 20:27:42 CST 2015" ;
                :Createdby = "ESMF_regridding.ncl" ;
                :Conventions = "SCRIP" ;
                :title = "0.1deg grid" ;
data:

grid_dims = 3599, 1799 ;
_____________
Why the grid_dims are 3599x1799?  I think it should be 3600x1800.


Yours Sincerely,
Huansheng Chen




陈焕盛(LAPC/IAP)
大气边界层物理和大气化学国家重点实验室
中国科学院大气物理研究所
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151019/6b0fe82a/attachment.html 


More information about the ncl-talk mailing list