[Thread Prev][Thread Next][Index]

Re: [ferret_users] multiple slabs, definition of the one-point axis, and precision.



Hi Ryo,

You're right. What perhaps is not clear in the Users Guide is what's doing on under the hood.  In writing netCDF files, the idea is that you can write the file first with any values - generally the _FillValue, (which is where the name "fill value" comes from, though Ferret really just uses one missing-data flag) on the entire grid that you want to use.  This is what the SAVE/KLIMITS=1:5 is doing.  At the same time on that first write, Ferret is writing the /K=1 data.  Then any SAVE/APPEND of a subset of the grid will overwrite the file with the data that you specify.  So, if you can define a grid with the axis you're going to use, and write some dummy data to your file, then you're good to go.

Here's another take on that example 4.  After the first write, do a ncdump on the file to see what's in it.

DEFINE AXIS/Z/UNITS=meters/DEPTH  zaxis = {0,10,20,50,100}
DEF GRID/Z=zaxis uv_grid

let zz = z[gz=zaxis]

let zval = zz[k=1]
DEF AXIS/Z=`zval`:`zval`:1 zaxis1
DEF GRID/LIKE=uv_grid/Z=zaxis1 uv_grid1

FILE/GRID=uv_grid1/VAR="u,v" uv.data1
LET/TITLE="My U data" u1 = u[G=uv_grid]
LET/TITLE="My V data" v1 = v[G=uv_grid]
SAVE/FILE=uv1_5z.cdf/KLIMITS=1:5/K=1 u1, v1

CANCEL DATA uv.data1


let zval = zz[k=2]
DEF AXIS/Z=`zval`:`zval`:1 zaxis1
FILE/GRID=uv_grid1/VAR="u,v" uv.data2
SAVE/FILE=uv1_5z.cdf/K=2/APPEND u1,v1


...

The other thing here is that the definitions of the 1-point Z axis in the examples use a nominal grid size of 1.  If you did want to interpolate from the zaxis1 axis to the output zaxis, you should be able to do it by defining a bigger grid size, with the detla on /Z=lo:hi:delta:

yes? define axis/z=0:0:1 zaxis1
yes? sh axis/z zaxis1
 name       axis              # pts   start                end
 ZAXIS1    Z                    1 r   0                    0
   Axis span (to cell edges) = 1
 
       K     Z                   ZBOX      ZBOXLO
       1>  0                     1          -0.5

yes? define axis/z=0:0:50 zaxis1
Replacing definition of axis ZAXIS1
yes? sh axis/z zaxis1
 name       axis              # pts   start                end
 ZAXIS1    Z                    1 r   0                    0
   Axis span (to cell edges) = 50
 
       K     Z                   ZBOX      ZBOXLO
       1>  0                     50         -25



On 11/21/2017 12:55 AM, Ryo Furue wrote:
Dear Ferret users,

This is not a question. I thought it may be useful to somebody.

I needed to construct a 3D (xyz) netCDF data from a set of 2D "slabs" (xy), and found this entry

"Example 4‚ multiple slabs"
http://ferret.pmel.noaa.gov/Ferret/documentation/users-guide/converting-to-netcdf/SIMPLE-CONVERSIONS-USING-FERRET#_VPINDEXENTRY_1071

in the Ferret user's guide very useful.

There was one problem, though.  If I understand the problem correctly, the z position of the temporary grid has to be exactly the same as one of the points of the actual z grid in the example shown:

    DEF GRID/X=xaxis/Y=yaxis/Z=zaxis uv_grid
    DEF AXIS/Z=0:0:1 zaxis1  !### The z value must be exact ###
    DEF GRID/LIKE=uv_grid/Z=zaxis1 uv_grid1

     FILE/GRID=uv_grid1/BAD=-999/VAR="u,v" uv.data1
     LET/TITLE="My U data" u1 = u[G=uv_grid]

That is because the regridding operation "G=uv_grid" cannot interpolate vertically because the temporary axis "zaxis1" has only one point in the vertical.

This caused a problem to me because my original z axis is irregular and from data.  So, I do something like this in myscript:

    let zvals = z[gz=zaxis]
    define axis/z=`zvals[k=3],p=???`:`zvals[k=3],p=???`:1 uv_grid1

but I don't know a priori how many digits the _expression_ "zvals[k=3]" should yield so that the z value exactly matches k=3 of the original axis.  I tried "p=16" but didn't always get a match. The result is an undefined slab.  So, after going through all the slabs from k=1 to k=kmax, I got some slabs undefined.

A workaround I found was to use "g=uv_grid@NRST", which should work as long as you use sufficient or more than sufficient digits for the "AXIS/Z=" definition.

I suppose some discussion like this would be helpful in the user's guide.

For future, it would be nice if we were able to directly get the values of variables without going through their text representations using the backtick `_expression_`.

Best regards,
Ryo


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

Privacy Policy | Disclaimer | Accessibility Statement