cdasws Data Retrieval Example Jupyter Notebook

This Jupyter notebook demonstrates using the cdasws Python package to retrieve data from cdaweb in multiple different data models. The data models demonstrated include the SpacePy data model, xarray.Dataset, and Pandas DataFrame. This notebook contains the following sections:

  1. Prerequisites
  2. Setup
  3. Get Datasets
  4. Get Dataset Variables
  5. Get Data
    1. SpacePy DataModel
      1. Display Metadata
      2. Plot Values
    2. xarray.Dataset
      1. Display Metadata
      2. Plot Values
    3. Pandas DataFrame
      1. Display Metadata
      2. Plot Values
  6. Additional Documentation

Prerequisites

Install the prerequisite software from the Python Package Index.

  1. pip install cdasws

For data in the SpacePy data model

  1. pip install spacepy

For data in an xarray.Dataset or Pandas DataFrame

  1. pip install cdflib xarray

Setup

Execute some preliminary code that is necessary before the code that follows.

Get Datasets

The following code demontrates how to get a list of datasets.

Get Dataset Variables

The following code demonstrates how to get a dataset's variables.

Get Data

The following code demonstrates how to access data for a selected time range from the selected dataset. The data is retrieved in the following ways:

  1. SpacePy data model
  2. xarray.Dataset
  3. Pandas DataFrame

You would typically only use one method. You may choose one over the other if you are integrating this code with other code that expects the data to be organized a specific way or if you have a another reason to prefer a specific data model.

SpacePy Get Data

The following code demonstrates how to retrieve data into a SpacePy data model.

SpacePy Display Metadata

The following code displays metadata for the Magnitude variable from the spacepy data model.

SpacePy Plot Values

The following code plots the Magnitude variable's values using the label values from the spacepy data model.

xarray Get Data

The following code demonstrates how to retrieve data into an xarray.Dataset.

xarray Display Metadata

The following code displays metadata for the Magnitude variable from the xarray.Dataset.

xarray Plot Values

The following code plots the Magnitude variable's values using the label values from the xarray.Dataset.

Pandas DataFrame Get Data

The following code converts the Magnitude portion of the above xarray.Dataset to a Pandas DataFrame and prints the result. This may be helpful for the case where some existing data analysis software requires the data in a Pandas DataFrame.

DataFrame Display Metadata

The following code displays the global attributes metadata for the DataFrame.

DataFrame Plot Values

The following code plots the DataFrame's values.

Additional Documentation

View the cdasws API for additional functions. Additional notebook examples are also available.