Getting your Mac ready for netCDF

If you are working with weather or climate data or big 3-4D model datasets you will undoubtedly encounter netCDF. Unidata’s Network Common Data Format has been the workhorse data format for atmospheric and oceanographic modelers since the early 1990’s. With more and more scientists using Macs to get their work done, it is important to get them ready with the the necessary tools of the trade.  This post walks you through the steps for setting up a Mac to work with netCDF.

Our job involves very few steps once the necessary software is installed. Our friend in this and other installations is MacPorts.  MacPorts is a package management/dependency resolution system similar to apt on Ubuntu or yum on Fedora/CentOS. If you already have MacPorts then you can just type:

If, however, you need to install MacPorts then you need to set aside some time for some hefty downloads. Note that you will need administrator privileges. Here are the steps for installing netCDF on my Mac laptop running OSX 10.8.5. I’m just following the MacPorts installation instructions:

1) Install Xcode

Open up the App Store application and search for Xcode — the suite of tools for developers. I’m installing Xcode 5.1 which weighs in at 2.18 GB so be ready for a long download. (You might want to have your Activity Monitor application open and look at the network speed. Now would be a good time to go for coffee.)

2) Agree to Xcode license

Once Xcode is downloaded, open up the Terminal app and type:

Hit spacebar a few times as directed and then type: ‘agree’.

3) Install MacPorts

Download the appropriate version of MacPorts from the installation page. Then click on the package to open up the package installer. After installation has finished you should close any Terminal windows and open up a new one that will now be aware of the new port command. Try it out with:

4) Install netcdf libraries and associated tools

Each of the following installations will automatically install any dependencies.

5) Make sure you have X11

If you are going to use ncview then you need to have X11 installed on your Mac.  As of OS X 10.8, Mountain Lion, Apple has replaced X11 with XQuartz. The ncview utility and many other Linux based scientific tools still depend on X11.  To install X11 just open the Utilities folder on your machine and click on the X11 icon. If X11 is not installed you will be prompted to install it. This will take you to the xquartz.macosforge.org where you can download the disk image for the latest version of XQuartz.

Once the download is finished, double click on the XQuartz .dmg file and again on the XQuartz package and walk through the installer. The last instruction is to log out and back in again.  I’ll be waiting right here for you when you come back.

6) Try out your new toys

Whew! That took a while. But take a moment to appreciate the huge amount of work that other people have done to make it possible to install all this software without any system guru skills.

Just to make sure everything is working, lets try looking at one of my favorite datasets — ICOADS 2 degree. Download the sst.mean.nc file — another big download. Once the download is finished you can look at the structure of the file with:

So far so good. Now let’s see if ncview works:

You should see the following:

ncview_imgncview

Below this will be a sad little window displaying all of the Sea Surface Temperature measurements that were taken in January of 1800. Ben Franklin had only begun measuring ocean temperatures a few years before.

To see a prettier picture just click on the “<” button (twice):

sst_now

 

You can clearly make out the continents and even major currents like the Gulf Stream. It looks like everything is working just fine

Congratulations on getting your Mac netCDF-ready!

Appendix

For the historically curious I would recommend tweaking ncview just a bit by choosing color palette “ssec”, adjusting the delay and then clicking on the “>>” button to walk forwards through history.  You might speed through the years before 1850, noticing only that all the ships making SST measurements set sail from England.

Post 1850 there is so much more to notice:

  1. sailing ships following the prevailing winds around the horn of Africa
  2. the disruption of trans-Atlantic trade during the American civil war
  3. the opening of the Suez canal in 1869
  4. more straight lines starting after 1880 as the age of sail passed
  5. Hawaii becoming a nexus after about 1900
  6. the opening of the Panama canal in 1914
  7. reduced shipping during WWI
  8. the seasonal “breathing” of ocean temperatures
  9. reduced shipping during WWII
  10. the episodic appearance of the cold El Niño waters in the equatorial Pacific

With what other dataset can you study shipping technology, economics and war, all visible through the lens of climate.

 

 

This entry was posted in Toolbox and tagged , , . Bookmark the permalink.

One Response to Getting your Mac ready for netCDF

  1. Gabriel Rothman says:

    Hello – thank you for providing these very helpful instructions.  I am happy to report that with your help, I was able to download the netcdf library onto my MacBook Pro using Yosemite.  FYI,
    one extra step I needed to take to be successful was to define the proper home directory to use
    Macports when I downloaded the netcdf libraries and applications.  I was able to do this typing in the following command into my terminal:
    Citation (Section 2.5.1, https://guide.macports.org/).  Please feel free to share as you deem appropriate….