Official websites use .gov
A .gov website belongs to an official government organization in the United States.

Secure .gov websites use HTTPS
A lock ( ) or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.




Quick Start Guide - CDF with Python

This is intended as a basic guide for installing the software needed to read and write Common Data Format (CDF) files. We include three recommended packages that provide the necessary capabilities for working with CDF science data files in Python.

Guide Contents

CDF Resources

Common Data Format (CDF) is a conceptual data abstraction for storing, manipulating, and accessing multidimensional datasets. CDF is referred to as a data abstraction because the actual physical format in which datasets are stored is opaque. Instead, the structure of the datasets and the means (interface) by which they may be manipulated are described here. NASA’s CDF Homepage contains detailed examples, documentation, FAQs, and installation tools.

Prerequisite Software [If Needed]

Install Python

Users can install Python or one of its various distributions (Anaconda, Miniconda, Conda-Forge, etc.). Python >= 2.6 is required to read CDF files, but Python 3 is the recommended install. It is also recommended to include a package manager (pip, conda, mamba, etc.) in your installation.

Please discuss with your system administrator on which Python distribution to install. This guide provides instructions for the installation of the Miniforge distribution on a Unix-based system. Thus, any commands used for the remainder of this guide will be in reference to this system environment.

Miniforge Install

NASA CDF Software

Users may need to locally install the NASA CDF software. This software package either comes pre-compiled or can be compiled by the user. For ease of installation, we recommend using the pre-compiled libraries. The process for installing the pre-compiled software is shown below:

CDF Software Install

CDFlib Package

CDFlib is a pure Python implementation of the CDF libraries. It is capable of reading & writing CDF files and does not require the installation of NASA’s CDF software. CDFlib requires Python >= 3.8 and attempts to replicate the syntax structure of the CDF functions used in IDL®.

Install CDFlib

SpacePy Package

SpacePy is a heliophysics Python package for basic data analysis, modeling, and visualization. This package includes a set of pre-compiled CDF C libraries but also searches for any locally installed NASA CDF software. SpacePy utilizes these C libraries for better performance and has a Pythonic-style interface for CDFs called pyCDF. CDF files are treated as context managers in pyCDF and behave like a Python dictionary, holding CDF variables that are keyed by each variable’s name. Data pulled from CDFs are loaded into dictionary-like objects called datamodels. More information can be found in the SpacePy Quick Start Guide.

In addition to a CDF interface, SpacePy also includes a suite of other space science libraries that include superposed epoch classes, drift shell tracing, access to magnetic field models, streamline tracing, bootstrap confidence limits, and time & coordinate conversion methods.

Install SpacePy

CDAS Web Services Package

The Coordinated Data Analysis System (CDAS) is a RESTful web service that is used to access NASA’s non-solar heliophysics data archive, CDAWeb. The CDAS web services package (CDASWS) is an API used to extent the connection to CDAS through Python.

The CDAS Web Services allows software developers to use CDAS in their own applications. Selected variables and time ranges can be easily loaded into Python structures using the CDASWS API. This package is ideal for users that specifically require CDF or netCDF files that are archived at NASA’s Space Physics Data Facility and available in CDAWeb. This API hides the HTTP, JSON/XML, and CDF details of the CDAS Web Services.

Install CDASWS