readme.md
CDF tools
NetCDF to CDF converter
- File: nc2cdf.py
- Python interpreter: 3.6
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.
- Install Anaconda3.
- 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
- Create the environment
conda3 conda create -f conda_env_nc2cdf.yml
- Activate the Conda environment:
source activate nc2cdf # or only "activate nc2cdf" on Fish terms
Licence
- License: GPLv3;
- Credits: CNRS/IRAP;
- contact: nathanael.jourdane@irap.omp.eu