# [ferret_users] Re: Remapping curvilinear coordinates to rectilinear coordinates

This issue is similar to use meshgrid function from matlab:

```[X,Y] = meshgrid(1:3,10:14)X =     1     2     3     1     2     3     1     2     3     1     2     3
1     2     3Y =    10    10    10    11    11    11    12    12    12    13    13    13    14    14    14```

but I have to get those data only in one matrix what  confusing me a bit.

2010/10/8 Szymon Roziewski
Now I'm thinking how to make appropriate grid for that:

My data are on grid;

(bottom left) -5.67E, -2S (bottom right) 5.25W, -2S
(top left) -5.67E, 10N (top right) 5.25W, 10N

Maybe there is special function wchich dealing with it in ferret?

2010/10/8 Szymon Roziewski
Ok,
I found it,
the problem was about statement:

let grid_out = y[gy=yax] + x[gx=xax]
which I didn't get well.

Cheers

2010/10/8 Szymon Roziewski

I also attach my script which does compute coefficient matrix.

DEFINE AXIS/x=1:448:1/unit=degree xaxis
DEFINE AXIS/y=1:615:1/unit=degree yaxis
DEFINE GRID/x=xaxis/y=yaxis gridlonlat
!read curvilinear coordinates onto grid 448x615
FILE/VARIABLES=clon_in/COLUMNS=448/GRID=gridlonlat "/home/szymon/WAM/CHECK/umlonicm448x615.dat"
FILE/VARIABLES=clat_in/COLUMNS=448/GRID=gridlonlat "/home/szymon/WAM/CHECK/umlaticm448x615.dat"
!create grid which we desire
define axis/x=-5.666666667:5.25:0.083333333/modulo/units=degrees xax
def axis/y=-2.0:10.0:0.083333333/units=degrees yax
let grid_out = y[gy=yax] + x[gx=xax]
!do transformation matrix
let map = CURV_TO_RECT_MAP(clon_in[d=1], clat_in[d=2], grid_out, 4)
!save data
save/clobber/file=curv_map_UM_TO_ICM.nc map

and another script which uses it:

DEFINE AXIS/x=1:448:1/unit=degree xaxis
DEFINE AXIS/y=1:615:1/unit=degree yaxis
DEFINE GRID/x=xaxis/y=yaxis gridlonlat
!load data for transformation  - wind fields u,v
file/var=wlon/grid=gridlonlat/format=stream/type=r4/swap "/home/szymon/WAM/CHECK/03225_2010092100+48000000c3hs000000000000000"
file/var=wlat/grid=gridlonlat/format=stream/type=r4/swap "/home/szymon/WAM/CHECK/03226_2010092100+48000000c3hs000000000000000"
!using transform matrix
use "/home/szymon/ferret/vectors/curv_map_UM_TO_ICM.nc"
! do transformation
let wlon_icm = curv_to_rect(wlon[d=1], map[d=3])
let wlat_icm = curv_to_rect(wlat[d=2], map[d=3])
!save transformation data which You can see for example in the picture wind_2010092103_ICM_remapped_132x145_and_interpolated.gif or UM_Significant_Wave_Height_21_September_2010_020000_TMP.gif (vectors only)
save/format=(448F8.2)/file=winduumicm+48.txt/clobber wlon_icm
save/format=(448F8.2)/file=windvumicm+48.txt/clobber wlat_icm

Best regards,
Simon

2010/10/8 Szymon Roziewski

Hello there,
I have problem with appropriate remapping from curvilinear coordinates to rectilinear coordinates.
The area which is covered with curvilinear coordinates is bigger than I need in rectilinear coordinates (it's a subset of curvilinear grid).
I would like to raise such a question if ferret can do this transformation automaticly i.e. I needn't to care about the curvilinear grid is about bigger area than rectilinear.
Or I need to tell ferret that fact by some computations and findings.
I attach files:
- wind_2010092103_ICM_aspect.gif - this is wind on curvilinear grid it is a bigger area
- wind_2010092103_ICM_remaped_132x145_and_interpolated.gif - this is wind on rectilinear grid it's a smaller area.

As You can see ferret did transformation but in a way I didn't intend. The Baltic Sea area is a little bit translated to the north and the northern part of sea was cut. The picture should wrap all area of Baltic Sea.
In the picture UM_Significant_Wave_Height_21_September_2010_020000_TMP.gif I marked the area which matches interpolated wind field on Baltic Sea and You can see that it disagrees to significant wave height which occupies properly area. It means that interpolation from curvilinear grid 448x615 to the rectilinear grid 132x145 was done improperly.
I hope I was understood.

Kind regards,
Szymon Roziewski

--
Z wyrazami szacunku,
Szymon Roziewski

--
Z wyrazami szacunku,
Szymon Roziewski

--
Z wyrazami szacunku,
Szymon Roziewski

--
Z wyrazami szacunku,
Szymon Roziewski