[Thread Prev][Thread Next][Index]

How to compress NetCDF float variables to 2-byte integer using Ferret5.80?



Hello Ferret support person and users

I am a new Ferret user.
I would like to use Ferret 5.80 to achieve a (modest) compression of NetCDF files,
by doing this pretty standard procedure:

(1) Read the floating point or double precision variables from NetCDF files;
(2) scale them (i.e. apply the appropriate scale and offset factors) to fit the range of two-byte integers;
(3) convert them to two-byte integer variables, and
(4) write them to (hopefully smaller sized) NetCDF files.

Step (1) is just the Ferret command "use".
Step (2) goes more or less like this:

let my_max=my_var{x=@max,y=@max,z=@max,t=@max]
let my_min=my_var{x=@min,y=@min,z=@min,t=@min]
let intrange=65534.0
let new_missing_value=-32768
let my_scale=intrange/(my_max - my_min)
let my_off=(my_max + my_min) / 2.0
let my_new_var = my_scale * (my_var - my_off)
let my_new_var2=missing(my_new_var, my_new_missing)


Regarding steps (3) and (4) I've got really confused and stuck.

The Ferret 5.80 manual suggests using:

set var/scale=my_scale my_new_var

to set the scale attribute of the scaled variable, and similar for the offset.

However, show commands contains a different syntax:

show commands set/variable
...
SET VARIABLE/TITLE/UNIT/GRID/BAD/DATASET/NAME/SCALEFAC/OFFSET


(Note the "SCALEFAC" spelling.)

Moreover, when I try, no matter which syntax I use, all I get are errors:

yes? set var/scalefac=myscale my_new_var
**ERROR: command syntax: scalefac=myscale
yes? set var/scale=myscale my_new_var
**ERROR: command syntax: scale=myscale
yes? set var/user_scale=myscale my_new_var
**ERROR: unknown command qualifier: user_scale=myscale
yes? set var/nc_scale=myscale my_new_var
**ERROR: unknown command qualifier: nc_scale=myscale


Whereas, the SAY command with RETURN clause seems to work,
with yet different keywords:

yes? say `my_new_var,return=nc_scale`
!-> MESSAGE/CONTINUE 1
1
yes? say `my_new_var,return=user_scale`
!-> MESSAGE/CONTINUE 1
1
yes? say `my_new_var,return=nc_offset`
!-> MESSAGE/CONTINUE 0
0
yes? say `my_new_var,return=user_offset`
!-> MESSAGE/CONTINUE 0
0


Questions:

1. How can I set the scale and offset of the new (scaled) variable?
2. How can I convert it from floating point or double to 2-byte integers?
3. Is this really implemented in Ferret 5.80, i.e. there a way to do what I want using Ferret 5.80?
4. Is there any special function to convert a variable from float to two-byte integer?
5. Is there an example script of how to do all of this?
6. Would it be possible to clarify the meaning, purpose, and differences of all these scale/offset keywords?
(SCALE, SCALEFAC, NC_SCALE, USER_SCALE, and similar for offset)

Thank you.

Gus Correa

--
---------------------------------------------------------------------
Gustavo J. Ponce Correa - Email: gus@ldeo.columbia.edu
Lamont-Doherty Earth Observatory - Columbia University
P.O. Box 1000 [61 Route 9W] - Palisades, NY, 10964-8000 - USA
Oceanography Bldg., Rm. 103-D, ph. (845) 365-8911, fax (845) 365-8736
---------------------------------------------------------------------


[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement