Re: [netcdfgroup] NetCDF file - convert float to short integers question

Hi Peter

Several NCO functions can do the classic
float->short (packing) and short->float (unpacking) conversions,
with the scale_factor and add_offset calculated from the
min and max data values (or the expected data range):

http://nco.sourceforge.net/nco.html#Packed-data

Specifically, ncap2 has pack() and unpack() functions:

http://nco.sourceforge.net/nco.html#Methods-and-functions

In my experience packing/unpacking is fine in many cases,
but can be problematic with variables that
have a wide dynamic range, covering several orders of magnitude,
such as specific humidity,
tracer and chemical species concentration, etc,
as the important/relevant detail may be squeezed into a few or a single
compressed value.
In these cases, a possible workaround would be to apply
a logarithm function beforehand (for positive variables),
and store the short_variable=packed(ln(float_variable)),
but also remember to apply an exponential when unpacking float_variable=exp(unpack(short_variable)).

NcView (with --minmax all) shows the minimum and maximum
values of each variable, but other tools such as NCL can
be used for that as well.

I hope this helps,
Gus Correa

On 01/18/2018 12:23 PM, Pete Pokrandt wrote:
NetCDFers,

Got the following question from one of our scientists (Mike Notaro, mnotaro@xxxxxxxx, cc'd). Any ideas?

    Does anyone know of an efficient (hopefully command line) method to
    convert an entire netcdf file (and all of its float variables) to
    short integers?


Thanks,

Pete




<http://www.weather.com/tv/shows/wx-geeks/video/the-incredible-shrinking-cold-pool>--
Pete Pokrandt - Systems Programmer
UW-Madison Dept of Atmospheric and Oceanic Sciences
608-262-3086  - poker@xxxxxxxxxxxx



_______________________________________________
NOTE: All exchanges posted to Unidata maintained email lists are
recorded in the Unidata inquiry tracking system and made publicly
available through the web.  Users who post to any of the lists we
maintain are reminded to remove any personal information that they
do not want to be made public.


netcdfgroup mailing list
netcdfgroup@xxxxxxxxxxxxxxxx
For list information or to unsubscribe,  visit: 
http://www.unidata.ucar.edu/mailing_lists/




  • 2018 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: