Getting Mac (and R, python) netCDF ready

person Breyfolder_openHow Toaccess_time December 31, 2014

Installing system libraries

The absolute easiest way to install NetCDF on a mac requires Macports. Macports is a software package designed to make installing and compiling software easy. Macports .pkg and installation instructions are available here.

Once Macports is installed building and installing NetCDF libraries is a one step job.

sudo port install netcdf

More details and instructions for installing Fortran and Python APIs are available here.

Installing R package ‘ncdf’

Having NetCDF command line tools is not required to use the ncdf R package. Simply download the package from CRAN (link) or by clicking on the “install packages” button in RStudio. This package allows reading, writing, and manipulation of existing .nc files. The package’s ability to view the content of nc files before loading them into the R workspace is limited. For this reason installing the NetCDF tools outlined in the first section of this post is extremely important. Command line tools such as “ncdump” are crucial to effectively working with NetCDF.

Installing system libraries on Ubuntu

The following instructions worked on Ubuntu 12.04 slt. To install NetCDF libraries that allow reading writing and manipulation use Apt/Get rather than downloading the source files and installing them yourself.  To install open terminal and type

apt-get install netcdf

 

Installing R package ‘ncdf’

The base version of R on Ubuntu 12.04 slt is 2.14.1. Unfortunately clicking the install button in RStudio and typing ‘ncdf’ will only work at the user level. The package will not be installed for all users or even show up in all of your RStudio projects. To install ncdf tools in the global library use the following command

install.packages(repos=c('http://cran.fhcrc.org/'),pkgs=c('ncdf'),lib="/usr/lib/R/site-library/")

‘http://cran.fhcrc.org/’ should be replaced by whichever CRAN mirror is closest to you.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>