readme.md
CDF tools
NetCDF to CDF converter for AMDADB
- 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 in a temp directory 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 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')
Dependencies
- NetCDF4
NetCDF is C library to read and edit NetCDF files.
NetCDF4 is a Python wrapper for NetCDF, which requires 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.
Installing the Python environment and dependencies
We will install dependencies in Python environments.
Case 1: 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
Case 2: 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.
First, install Anaconda3.
Then 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.
Add 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
Now create the environment:
conda3
conda create -f conda_env_nc2cdf.yml
To finish, activate the Conda environment:
source activate nc2cdf # or only "activate nc2cdf" on Fish terms
You can now use the converter.
Licence
- License: GPLv3;
- Credits: CNRS/IRAP;
- contact: nathanael.jourdane@irap.omp.eu