[Thread Prev][Thread Next][Index]
Re: reshape and get x axis data onto z axis
Hi Ansley
Thanks very much for greatly clarifying the RESHAPE function.
Unfortunately the suggestion using ncdump and ncgen didn't work because
the data is still in
the wrong order.
However, in that spirit, but using the LIST command to output to ASCII
and the FILE command, together with
obvious choices of the /ORDER qualifier allowed me to force it onto the
desired grid.
Thanks,
Rob
At 11:41 AM 12/3/2002 -0800, you wrote:
Hi Rob,
The RESHAPE function keeps the data in its internal order,
just wrapping it onto the newly specified grid. The last step
you describe would require the function to shuffle the ordering
of the data which it doesn't do. Try this example to see what
is happening. I like to use STAT to see the size and shape
of the variables, but the LIST commands really show what's
going on.
yes? def axis/x=1:3:1 xax
yes? def axis/y y_irr = {1,3,4,5}
yes? def axis/z=1:5:1 zax
yes? let a = i[gx=xax] + 10*j[gy=y_irr] + 100*k[gz=zax]
yes? stat a
yes? list a
VARIABLE : I[GX=XAX] + 10*J[GY=Y_IRR] + 100*K[GZ=ZAX]
SUBSET : 3 by 4 by 5 points (X-Y-Z)
1 2 3
1 2 3
---- K:1 Z: 1
1 / 1: 111.0 112.0 113.0
3 / 2: 121.0 122.0 123.0
4 / 3: 131.0 132.0 133.0
5 / 4: 141.0 142.0 143.0
---- K:2 Z: 2
1 / 1: 211.0 212.0 213.0
3 / 2: 221.0 222.0 223.0
...
yes? def axis/t=2:10:2 tnew
yes? sh axis tnew
yes? def grid/x=xax/y=y_irr/t=tnew zytgrid
yes? let dum = 0*x[g=zytgrid]+0*y[g=zytgrid]+0*t[g=zytgrid]
yes? stat dum
yes? let b = reshape(a,dum)
yes? stat b
yes? list b
VARIABLE : RESHAPE(A,DUM)
SUBSET : 3 by 4 by 5 points (X-Y-T)
1 2 3
1 2 3
---- L:1 T: 2
1 / 1: 111.0 112.0 113.0
3 / 2: 121.0 122.0 123.0
4 / 3: 131.0 132.0 133.0
5 / 4: 141.0 142.0 143.0
---- L:2 T: 4
1 / 1: 211.0 212.0 213.0
3 / 2: 221.0 222.0 223.0
yes? def axis/z=3:9:3 znew
yes? def grid/y=y_irr/z=znew/t=tnew yztgrid
yes? let dum = 0*y[g=yztgrid]+0*z[g=yztgrid]+0*t[g=yztgrid]
yes? stat dum
yes? let c = reshape(b,dum)
yes? stat c
yes? list c
VARIABLE : RESHAPE(B,DUM)
SUBSET : 4 by 3 by 5 points (Y-Z-T)
1 3
4 5
1 2
3 4
---- L:1 T: 2
3 / 1: 111.0 112.0 113.0 121.0
6 / 2: 122.0 123.0 131.0 132.0
9 / 3: 133.0 141.0 142.0 143.0
---- L:2 T: 4
3 / 1: 211.0 212.0 213.0 221.0
6 / 2: 222.0 223.0 231.0 232.0
You can see how the data is staying in its original order; the
K axis does not automatically contain the data from the I axis.
What you could do, is write a NetCDF file with the data at the
point where you have it in X, Y, and T. Use NCDUMP to write
this out in ASCII format, edit the file and rename the X axis
to a Z axis, also making sure the order of the axes listed in the
NetCDF file is correct in all the header sections of the file. Then
use NCGEN to create a file in the ordering you want.
Ansley Manke
Rob Scott wrote:
Dear ferret
I have a netCDF file with a three dimensional field on the x, y, z axes.
I would like to use zaxreplace on the x axis data. (I believe this
amazing function is currently only supported on the z-axis.)
I've managed to use RESHAPE to get the z axis data onto the t-axis, but
when I try to use RESHAPE to get the x-axis data onto the
now vacant z-axis, it messes up the data. Am I trying to do the
impossible?
The manual states:
"For any axis X,Y,Z, or T if the axis is
the same in the input and output grids then the region from argument 1
will be preserved in the output.
This implies that when the above technique is
used on multi-dimensional input, only the axes which differ between the
input and output grids are affected by the RESHAPE
operation."
Hence I've attempted to "let ferret know" that I want to move
the x-data over to the z-axis, and leave y and t alone, by defining my
output grid to have only one dimension in the x-direction,
In particular:
DEFINE AXIS/x=1:1:1
xaxis_normal
! my attempt to make this a normal axis
DEFINE AXIS/z=1:5:1
zaxis_new
! (the old x - axis)
DEFINE GRID/LIKE=old_grid/ x= xaxis_normal/ z=zaxis_new
output_grid
! I need to use LIKE to get the y-axis correct because it's irregular.
LET dummie = x[output_grid] * y[output_grid] * z[output_grid]
*t[output_grid]
LET new_var = RESHAPE(old_var,dummie]
But now
old_var[i=1]
.NE. new_var[k=1]
Thanks for any advice,
Rob
Rob Scott
Research Associate
Institute for Geophysics
University of Texas at Austin
4412 Spicewood Springs Rd.
Building 600
Austin, TX
78759
Office: +1-512-471-0375
--
Ansley Manke Pacific Marine Environmental Laboratory Seattle
WA (206)526-6246
Rob Scott
Research Associate
Institute for Geophysics
University of Texas at Austin
4412 Spicewood Springs Rd.
Building 600
Austin, TX
78759
Office: +1-512-471-0375
[Thread Prev][Thread Next][Index]
Dept of Commerce /
NOAA /
OAR /
PMEL /
TMAP
Contact Us | Privacy Policy | Disclaimer | Accessibility Statement