Name Last Update
examples Loading commit data...
conda_env_nc2cdf.yml Loading commit data...
nc2cdf.py Loading commit data...
pip_req_nc2cdf.txt Loading commit data...
readme.md Loading commit data...

readme.md

CDF tools

NetCDF to CDF converter

CLI usage

Converting a Net-CDF file:

Convert the NetCDF file, save it in a temp directory, then display its path:

./nc2cdf.py path/to/input_file.nc.gz

Convert a Net-CDF file and save it in the specified path.

./nc2cdf.py path/to/input_file.nc.gz path/to/output_file.cdf

Note: If the specified input file is a gzip archive, it will be automatically extracted before the conversion.

Describing a NetCDf file:

./nc2cdf.py  -i path/to/file.nc.gz

This display information about a Net-CDF file (such as global attributes and variables information).

Python library usage

import nc2cdf

netcdf = NetCdf('path/to/input_file.nc.gz')

netcdf.describe()

netcdf.get_cdf()
print('CDF path: ' + netcdf.get_cdf_path())

netcdf.get_cdf('path/to/output_file.cdf')

About NetCDF4 and pycdf

NetCDF4

NetCDF is C library to read and edit NetCDF files.

NetCDF4 is a Python wrapper for NetCDF, which require the NetCDF library, used here to read NetCDF files.

Documentation is available here.

pycdf

SpacePy is a python package for space sciences, used here to write CDF files.

Documentation of the package spacepy.pycdf is available here.

Install the Python environment and dependencies

We will install dependencies in Python environments.

If you have NetCDF installed on your machine

You can use pip and virtualenv:

pip install virtualenv
virtualenv -p python3 nc2cdf
source nc2cdf/bin/activate # Or ". nc2cdf/bin/activate.fish" on Fish terms
pip install -r pip_req_nc2cdf.txt

If you don't have NetCDF installed on your machine

The easier way is to use Anaconda, which is a tool to install compiled Python dependencies in environments.

  1. Install Anaconda3.
  2. Edit your system startup file:

I recommend to add an alias which set the Python path. In this way the Anaconda Python will not be used by default and you can easily deal with multiple Anaconda versions.

At the end of your ~/.bashrc:

alias conda3="set PATH $HOME/.anaconda3/bin/ $PATH"

Or on Fish terms (~/.config/omf/init.fish):

alias conda3="set PATH $HOME/.anaconda3/bin/ $PATH; and source $HOME/.anaconda3/etc/fish/conf.d/conda.fish
  1. Create the environment

conda3 conda create -f conda_env_nc2cdf.yml

  1. Activate the Conda environment:

source activate nc2cdf # or only "activate nc2cdf" on Fish terms

Licence