[Thread Prev][Thread Next][Index]

Re: [ferret_users] regridding etopo5



Hello All,

Here is an idea that might work for extracting the median of water depths (ie excluding land) for a series of grid boxes without the need for an external function. It is based on SORTI and SAMPLEI. I'll illustrate the idea for one grid box 170W-166W, 53-56N.

! Define the data file and how to select "water" points
use etopo05 ; set mem/size=500
let sea=if(rose[d=1] lt 0)then rose[d=1]
! count the number of etopo05 water points that fall in the new grid box
let nsea=sea[x=@ngd,y=@ngd]

! ... and define a file to accept the median values
sp touch median.file

!Step 0. define the corners of the grid box desired ... for example
let my_xlo=190 ; let my_xhi=194 ; let my_ylo=53 ; let my_yhi=56

!--------------------------------------------------
!Step 1. For a particular grid box write out the water depths with a flag 999 for land
region/x=`my_xlo`:`my_xhi`/y=`my_ylo`:`my_yhi`
list/nohead/clob/file=temp.file/form=(f10.2) missing(sea,999)
let ngood=`nsea` ; let midpoint=int(ngood/2)+1
can region/all

!Step 2. Read back the water depths and sort in increasing order
file/form=free/var=depth temp.file ; set var/bad=999 depth
let index=sorti(depth) ; let sorted=samplei(depth,index)

!Step 3. Pick off the mid point
let median=sorted[i=`midpoint`]

!Step 4. List the result (to a file) then go back to Step 0 for the next grid cell
list/app/nohead/form=(f10.2)/file=median.file median
can data 2 ! eliminate the temporary file
!----------------------------------------------------

The results check out: there are 1769 "water" points among the 1813 etopo05 cells within the box.
The mid point is #885 and the 885th of the sorted depths (i.e the median) is -951m.

To create a whole grid of boxes a pair of nested loops can define the my_xlo,my_xhi, my_ylo and
my_yhi values in turn. In the inner loop a .jnl file containing steps 1-4 above is called to incrementally write the median values. After this is done the ASCII file of medians is read into the new grid and the result output to a netCDF file.

Hope this helps,
Mick
------------------------
David Wang wrote:
Hi Ansley,

Thanks. That is supposed to work also. But I think that taking medians is ideal for those adjacent to coastlines when a coarser grid box needs to be determined as a wet box or a dry box.

David

Ansley Manke wrote:

Hi David,
You could also do another regridding operation from etopo5, using linear or averaging to regrid to your coarser grid.

Ansley


David Wang wrote:

Hey Ansley,

Thanks very much for your response. I don't think I have time working on an external function right now. maybe some time in the future, then I will contact you.
This was to generate the bathymetry file for an ocean model. But since currently I actually don't need a very accurate representation of the sea floor and the coastlines, I may still use my present crude one derived from Levitus.

Cheers,
-d.

On 5/30/06, *Ansley Manke* <Ansley.B.Manke@noaa.gov <mailto:Ansley.B.Manke@noaa.gov>> wrote:

Hi David,
I think this would require an external function. You'd pass in
the data
on the finer grid as one argument, and a second argument would be
some
dummy variable on the desired output grid. Then the function
would need
to determine which grid points from the fine grid lie within the grid
boxes of the output data, and compute the median value, assigning
it to
the "result" of the function, on the coarser grid.

There would be some things to decide. Would you weight input data
according to what portion of the input grid cell lies within the
output
grid cell? That is, if you had the fine grid and the output grid
lining
up like this, with data at the o's and grid cell edges at the |'s,

|---o---|---o---|---o---|---o---|---o---|
|----------O----------|----------O----------|----------O----------|

then, would data at the first o in the fine data, which lies right on
the edge of an output grid cell, be weighted the same as the next
two
data points which lie entirely within the output grid cell? or
would its
contribution to the value of the median be smaller? (and similar
considerations due to working in 2 dimensions.)

Another consideration would be whether to apply the cosine latitude
correction when working on a latitude-longitude grid.

If you (or anyone!) would like to work on this, I can give you more
ideas and help you get started.

Ansley

David Wang wrote:

> Hello Ferreters,
>
> I'm thinking of regridding etopo5 bathymetry data onto a much
coarser
> grid (say 0.5x0.5) in such a way that the regridded value at
each new
> grid point is chosen to be the median of all etopo5 grid points
within
> each new grid box. Are there any tricks for doing this in FERRET?
>
> Thanks,
> - d.









[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement