WRF | ncview/ncvis -- a NetCDF visual browser

ncview

Ncview is designed to be the fastest way to see what's in a netCDF file. Of course I'm biased since I wrote the thing, but I think everybody who works with netCDF files can benefit from having ncview in their toolkit. Ncview doesn't replace existing analysis packages, such as IDL, NCL, Matlab, Ferret, or R; instead it supplements them by providing a quick and easy way to get an enormous amount of information from your netCDF file.

Installation

1
conda install conda-forge::ncview

Command prompt

1
ncview xxx.nc
ncview
ncview

In particular, the following attributes are taken into account:

  • missing_value: This attribute, which must be of the same type as the variable it is associated with, is an important one to set if you have missing values that are indicated by some “special” number such as -999.9, 1.0e35, or whatever. If you don’t set this attribute, ncview will not work properly.
  • units: A character-type attribute that gives the units of the variable it is associated with. For example, “meters” or “Years”.
  • long_name: A character-type attribute that gives the extended, or more descriptive, name of the variable it is associated with. For instance, if the variable’s name is “Lon”, its long_name might be “Longitude”.
  • title: This global character-type attribute gives some short, descriptive summary of the meaning or parameters of the data file. For instance, it might be “Run 017: dx=4, dy=5, nT=45 yrs” or “El Nino Simulation, no mixed layer, D. Pierce SIO/CRD”.
  • add_offset, scale_factor: Ncview respects these attributes, transparently scaling and offsetting the data as specified. See the netCDF documentation on these attributes for details. In essence, these attributes let you implement a form of data packing.

Packed Data Values

What are add_offset, scale_factor ?

Conventions for packing numeric data to save space have some subtleties.

Packed data is stored in a netCDF file using a smaller data type than the original data, for example, packing doubles into shorts. The netCDF library itself does not do packing and unpacking, but the Java-netCDF library will do automatic unpacking, see class VariableDS.

Recommendations:

For each variable with packed data, add two attributes called scale_factor and add_offset, such that

unpacked_value = packed_value * scale_factor + add_offset

The type of the stored variable is the type of the packed data type, typically byte, short, or int.

The type of the scale_factor and add_offset attributes should be the type that you want the unpacked data to be, typically float or double.

To compute the scale and offset for maximum precision packing of a set of numbers, use:

add_offset = dataMin
scale_factor = (dataMax - dataMin) / (2^n - 1)

where n is the number of bits of the packed (integer) data type.

To avoid introducing a bias into the unpacked values due to truncation when packing, round to the nearest integer rather than just truncating towards zero:

packed_value = nint((unpacked_value - add_offset) / scale_factor)

The precision of the data will be

1.0 / scale_factor.

Example, packing 32-bit floats into 16-bit shorts:

1
2
3
4
variables:
short data(z, y, x) ;
data:scale_offset = 34.02f ;
data:add_offset = 1.54f ;

ncvis

NetCDF Visualizer

Developed by Paul A. Ullrich

In order for ncvis to run the resources directory must be in the same folder as ncvis or the NCVIS_RESOURCE_DIR environment variable must be set to the path of the ncvis resources folder. This directory is where ncvis stores fonts, colormaps and shapefiles.

ncvis
ncvis

from source code

  • https://github.com/SEATStandards/ncvis
1
2
3
4
conda create -n ncvis -c conda-forge wxwidgets libnetcdf
conda activate ncvis
conda install conda-forge::cxx-compiler
conda install -c anaconda libxxf86vm-cos6-x86_64

Then,

  • soft-link micromamba/envs/ncvis-v1/x86_64-conda_cos6-linux-gnu/sysroot/usr/lib64/libXxf86vm.so.1 to /home/wpsze/micromamba/envs/ncvis-v1/lib
1
2
3
4
5
$ sh ./build.sh
# check
$ ldd ncvis |grep not
# set
alias ncvis=/home/wpsze/share/ncvis/ncvis

ncvis uses degree for lat lon but MPAS uses radian


WRF | ncview/ncvis -- a NetCDF visual browser
https://waipangsze.github.io/2024/10/10/ncview/
Author
wpsze
Posted on
October 10, 2024
Updated on
October 27, 2025
Licensed under