[Thread Prev][Thread Next][Index]

Re: [ferret_users] define new variable with different grid

Hi Lina,

I'm not sure I understand how the data depends on L.  It sounds as if each variable has non-zero values at the L=1:10 at the same x,y,z locations, is that correct?

It's a problem that uses several of Ferret's grid-handling capabilities, so kind of an interesting example.

-Use transformations to squash each variable down to the non-zero entry in the I,J,K directions. The data will remain where it is in L.  Any of the "compressing transformations such as @SUM or @MAX will get rid of the dependence on the original grid.

-Put the data onto a new x axis,  X=1:55, using Ferret's  concept of "conformability".

-Write a netCDF file using the ideas of "appending a slab to a netCDF file" (See APPEND in the Users' Guide index), so you can list the data from each new variable into the next slot.

Here's a short example, using some simplified variables. 

yes? let a_1 = {0,0,0,3,0,0,0}
yes? let a_2 = {0,0,0,0,0,0,6,0}
yes? let a_3 = {4,0,0,0}

! The @sum gets rid of the dependence on the original grid in i,j,k.

yes? let var1 = a_1[i=@sum]   ! you'll use a_1[i=@sum,j=@sum,k=@sum]
yes? list var1
             VARIABLE : A_1[I=@SUM]
             X        : 0.5 to 7.5

! Define the output axis - length is the of the number of variables we're going to append.

yes? define axis/x=1:5:1 xax5

! We'll list i=1 of this variable to the output file. var1 does not depend on x, so adding
! a zero-valued _expression_ on xax5 puts it at every location of xax5 (conformability).

yes? let outvar = var1 + 0*x[gx=xax5]
yes? list outvar
             VARIABLE : VAR1[I=@MAX] + 0*X[GX=XAX5]
             SUBSET   : 5 points (X)
             Y        : 1
             Z        : 1
 1   / 1:  3.000
 2   / 2:  3.000
 3   / 3:  3.000
 4   / 4:  3.000
 5   / 5:  3.000

! Write out /i=1 of this variable and also use /ILIMITS to set up the file
! with the full length of the axis in the x direction.

yes? save/clobber/file=output_file.nc/ilimits=1:5/i=1 outvar

! Put the second variable onto the same x axis, and write its
! value into the
/i=2 slot of the output file.

yes? let var2 = a_2[i=@sum]
yes? let outvar = var2 + 0*x[gx=xax5]
yes? list outvar
             VARIABLE : VAR2 + 0*X[GX=XAX5]
             SUBSET   : 5 points (X)
 1   / 1:  6.000
 2   / 2:  6.000
 3   / 3:  6.000
 4   / 4:  6.000
 5   / 5:  6.000

yes? save/append/file=output_file.nc/i=2 outvar

So far now the file contains outvar = 3, 6, and the rest are missing-values. Continue defining variables and appending with /i=3, /i=4,...

Try a second simple example with X-T variables,

define axis/t=1:10:1 taxis

let a_1 = {0,0,0,3,0,0} * t[gt=taxis]

let a_2 = {0,0,0,0,0,0,6,0} * t[gt=taxis]

I think you'll see that all of the same commands work, and you have an x-t file.

On 1/30/2018 8:28 AM, Lina Krisztian wrote:

I have a variable ‚a_‘ which is everywhere zero except for one position with x,y,z. The grid is: x=1:100, y=1:100, z=1:5,l=1:10
I have several variables like this (so everywhere zero except one position) which are named a_1, a_2,..,a_55
Now I wanna have a new variable ‚n‘ which include all these values which aren’t zero. The grid should be like: x=1:55,l=1:10
So for example the non zero values are: a_1 = 10, a_2  = 15, a_3 = 50.
I wanna have a variable n which first value is 10, second 15 and third 50. And the grid should be like: x=1:3,l=1:10

When I’m trying this, I got a problem with the different dimensions. Can someone please help me with this problem.

Thanks a lot.

[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement