[Thread Prev][Thread Next][Index]

Re: 3D to 2D



Hi,
I don't think your question reached the Users' List,
but here's a simple answer. The function RESHAPE(A,B) wraps argument A onto the grid of argument B. We can define the output grid with an abstract X axis of length NX*NY, and the same time axis as the input grid, create a dummy variable on the output grid, then use RESHAPE
to define the output 2D variable

Here is a simple example:


! Define a small 3-D variable

yes? def axis/x=1:5:1 xax
yes? def axis/y=1:3:1 yax
yes? def axis/t=1:4:1 tax
yes? let var3d = x[gx=xax] + 10*y[gy=yax] + 100*t[gt=tax]
yes? list/l=1/j=1 var3d
VARIABLE : X[GX=XAX] + 10*Y[GY=YAX] + 100*T[GT=TAX]
SUBSET : 5 points (X)
Y : 1
T : 1
1 1
1 / 1: 111.0
2 / 2: 112.0
3 / 3: 113.0
4 / 4: 114.0
5 / 5: 115.0
yes? list/l=4/j=2 var3d
VARIABLE : X[GX=XAX] + 10*Y[GY=YAX] + 100*T[GT=TAX]
SUBSET : 5 points (X)
Y : 2
T : 4
2 2
1 / 1: 421.0
2 / 2: 422.0
3 / 3: 423.0
4 / 4: 424.0
5 / 5: 425.0

! Define a 2-D grid and a variable on it.

yes? def axis/x=1:`5*3`:1 space_ax
!-> def axis/x=1:15:1 space_ax
yes? let var2d = 0*x[gx=space_ax] + 0*t[gt=tax]

! Use the RESHAPE function to create the output 2-D variable.
! Check the values.

yes? let outvar = reshape(var3d,var2d)
yes? list/l=1 outvar
VARIABLE : RESHAPE(VAR3D,VAR2D)
SUBSET : 15 points (X)
T : 1
1 / 1: 111.0
2 / 2: 112.0
3 / 3: 113.0
4 / 4: 114.0
5 / 5: 115.0
6 / 6: 121.0
7 / 7: 122.0
8 / 8: 123.0
9 / 9: 124.0
10 / 10: 125.0
11 / 11: 131.0
12 / 12: 132.0
13 / 13: 133.0
14 / 14: 134.0
15 / 15: 135.0
yes? list/l=4 outvar
VARIABLE : RESHAPE(VAR3D,VAR2D)
SUBSET : 15 points (X)
T : 4
1 / 1: 411.0
2 / 2: 412.0
3 / 3: 413.0
4 / 4: 414.0
5 / 5: 415.0
6 / 6: 421.0
7 / 7: 422.0
8 / 8: 423.0
9 / 9: 424.0
10 / 10: 425.0
11 / 11: 431.0
12 / 12: 432.0
13 / 13: 433.0
14 / 14: 434.0
15 / 15: 435.0




R Prabowo wrote:

Hi there,

I have a 3D data (long, lat, time) size of (65, 33, 73). I want make this 3D data become a 2D data (long-lat, time or 65x33, 73). I have been trying to do it by using nested repeat command as script bellows. But up 1995 iteration, there is error saying that:

**ERROR: a program limit has been reached: too many user-defined variables
cancel or redefine some variables
DEFINE VARIABLE 5dcr2D1995=5dcr[i=45,j=31]
Command file, command group, or REPEAT execution aborted

The script I used is:

can data/all
can var/all
SET MEMORY/SIZE=15
use/regulart data.nc
show data/full
DEFINE AXIS/T=3-JAN:29-DEC/npoints=73 tpentad LET zero=T[gt=tpentad@mod] * 0 REPEAT/l=1:73 ( \
REPEAT/j=1:33 ( \
REPEAT/i=1:65 ( \
let ij = `i`+(`j`-1)*65; \
let 5dcr2D`ij`=5dcr[i=`i`,j=`j`]); \
let 5dcr2D= 5dcr2D`ij`+zero[l=`l`]; \
save/append/file= data2D.nc 5dcr2D))

Is there any one has any elegant way to do this work? Thank you very much.






[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement