# CDF tools ## NetCDF to CDF converter for AMDADB - File: [nc2cdf.py](./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: ```bash ./nc2cdf.py path/to/input_file.nc.gz ``` Convert a Net-CDF file and save it in the specified path. ```bash ./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: ```bash ./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 ```python 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](https://www.unidata.ucar.edu/software/netcdf/) is C library to read and edit NetCDF files. [NetCDF4](https://github.com/Unidata/netcdf4-python) is a Python wrapper for NetCDF, which requires the NetCDF library, used here to read NetCDF files. Documentation is available [here](http://unidata.github.io/netcdf4-python/). - pycdf [SpacePy](http://pythonhosted.org/SpacePy/index.html) is a python package for space sciences, used here to write CDF files. Documentation of the package spacepy.pycdf is available [here](http://pythonhosted.org/SpacePy/pycdf.htm). ### 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: ```bash 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](https://docs.continuum.io/), which is a tool to install compiled Python dependencies in environments. First, [install Anaconda3](https://docs.continuum.io/anaconda/install). 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`: ```bash alias conda3="set PATH $HOME/.anaconda3/bin/ $PATH" ``` Or on Fish terms (`~/.config/omf/init.fish`): ```bash alias conda3="set PATH $HOME/.anaconda3/bin/ $PATH; and source $HOME/.anaconda3/etc/fish/conf.d/conda.fish ``` Now create the environment: ```bash conda3 conda create -f conda_env_nc2cdf.yml ``` To finish, activate the Conda environment: ```bash source activate nc2cdf # or only "activate nc2cdf" on Fish terms ``` You can now use the converter. ### Licence - License: [GPLv3](https://www.gnu.org/licenses/gpl-3.0.html); - Credits: CNRS/IRAP; - contact: nathanael.jourdane@irap.omp.eu