Using the NAS Data Portal's THREDDS server

Article ID: 684
Last updated: 10 Apr, 2023

The Thematic Realtime Environmental Distributed Data Service (THREDDS) application was developed by the Unidata organization to provide access to metadata and scientific data. The NAS THREDDS server publishes a catalog of pre-generated datasets for some of the most commonly requested datasets on the NAS Data Portal, and allows users to extract specific data from a larger dataset file using a specific set of parameters.

Key features of THREDDS include:

  • The Netcdf-Java/CDM library reads NetCDF, OpenDAP, and HDF5 datasets, as well as other binary formats such as GRIB and NEXRAD, into a Common Data Model (CDM)—essentially, an (extended) netCDF view of the data. Datasets that can be read through the Netcdf-Java library are called CDM datasets.
  • An integrated server provides OPeNDAP access to any CDM dataset (OPeNDAP is a widely used subsetting data access method that extends the HTTP protocol).
  • The integrated NetCDF Subset Service allows subsetting certain CDM datasets in coordinate space, using a REST API. Gridded data subsets can be returned in CF-compliant netCDF-3 or netCDF-4 files. Point data subsets can be returned in CSV, XML, WaterML, or CF-DSG (discrete sampling geometry) v1.6 netCDF files.

Accessing the NAS THREDDS Data Server

The NAS THREDDS data server is available at https://data.nas.nasa.gov/thredds. The TDS homepage lists all available datasets in a series of catalog entries:

The entries link to lists of data files that you can view through the browser or download by using the various protocols available:

The server provides a set of standard data services that are always available (unless explicitly disabled) and can be referenced from any configuration catalog. These utilities work for most model data served through THREDDS:

http
HTTP File Download Server.
netcdfSubsetGrid
Interface for choosing and downloading subsetted gridded datasets as NetCDF files.
netcdfSubsetPointv
Interface for choosing and downloading subsetted point datasets as NetCDF files.
NCML
NetCDF Markup Language; provides an XML representation of NetCDF data.
opendap
Delivers subsetted datasets to OPeNDAP clients.
wcs
Delivers subsetted datasets to web coverage service (WCS) clients.
wms
Delivers map images to web mapping service (WMS) clients.

Submitting Datasets to the NAS THREDDS Server

If you are the Principal Investigator (PI) of an existing datatset on the NAS Data Portal, and you want to add it to the THREDDS server, please submit a ticket describing your request to support@nas.nasa.gov.

If you are a PI of a prospective dataset that has not yet been added to the NAS Data Portal, please follow the instructions outlined in Submitting Datasets to the NAS Data Portal.

Accessing Datasets from the NAS THREDDS Server

Example MatLab Script

The script described in this section demonstrates how to access data on the NAS THREDDS Server using the NetCDF functions in Matlab.

First, specify a .ncml URL for the desired dataset:

url='http://data.nas.nasa.gov/thredds/path/to/dataset/file.ncml'

You can use the ncinfo() function to access the list of variables and metadata information contained in the dataset:

metadata = ncinfo(url)
disp({metadata.Variables.name});

You can use the ncreadatt() function to grab a specific attribute value:

source = ncreadatt(url,'/','source');

You can use the ncread() function to grab actual data for the variables that have been selected. The following code will retrieve time and temperature as example variables:

dtime = ncread(url, 'time');
dtime = dtime/(60*60*24)+datenum(1900,1,1); %Convert to Matlab time
temp = ncread(url, 'temp');
temp(temp==0)=NaN; %Remove bad points

Please note that the example above grabs data for the full range of time in a dataset. Additional parameters can be passed into the ncread() function to subset the the data being retrieved:

ind = find(dtime>datenum(2015,1,15) & dtime<datenum(2015,1,20));
dtime2 = ncread(url,'time',ind(1),length(ind),1);
dtime2 = dtime2/(60*60*24)+datenum(1900,1,1); %Convert to Matlab time
temperature2 = ncread(url,'temp',ind(1),length(ind),1);
temperature2(temperature2==0)=NaN; %Remove bad points

For more information, please refer to Matlab’s documentation for ncinfo(), ncreadatt(), and ncread().

Example Python Script

The following script highlights how to access data on the NAS THREDDS Server using the Pydap Library.

First, import the open_url() function from the Pydap library:

from pydap.client import open_ur

Next, specify the the dataset that is desired and open the Pydap connection:

url = 'http://data.nas.nasa.gov/thredds/path/to/dataset';
dataset=open_url(url)

You can use the .keys() function to find out the variables that are available in the dataset:

print dataset.keys()

You can retrieve additional information about specific variables in the dataset:

dataset['example_variable'].dimensions
dataset['example_variable'].shape
dataset['example_variable'].type
dataset['example_variable'].attribute

Data can now be accessed from variables. Using [:] will grab all available data in the file. You might need to subset the query if the dataset is very large.

time = dataset['time'][:]
var1 = dataset['example_variable1'][:]
var2 = dataset['example_variable2'][:]
var3 = dataset['example_variable3'][:]

Convert the datasets time variable, if necessary:

from datetime import datetime
dtime = time/(24*3600) + datetime(1900,1,1).toordinal(

Now, you can construct a plot from the dataset:

#Import necessary libraries
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
# Close any existing plots
plt.close('all')
# Setup the plot
fig, ax = plt.subplots()
# Turn on the plot grid
plt.grid()
# Add the scatterplot with data
sc = plt.scatter(dtime,pressure, c=np.abs(temp), marker='o', edgecolor='none')
# Format the date axis
df = mdates.DateFormatter('%Y-%m-%d')
ax.xaxis.set_major_formatter(df)
fig.autofmt_xdate()
# Reverse the y-axis
ax.set_ylim(ax.get_ylim()[::-1])
# Plot labels
plt.ylabel(dataset['example_variable'].name+&quot; (&quot;+ dataset['example_variable'].units + &quot;)&quot;)
plt.title(dataset.attributes['NC_GLOBAL']['source'], fontsize=11)
# Add the colorbar
clabel = dataset['example_variable1'].name +&quot; (&quot;+ dataset['example_variable2'].units + &quot;)&quot;
fig.colorbar(sc, ax=ax, label=clabel)
# Display the plot (this is a necessary step in Python) and save the figure to a file.
plt.show()
fig.savefig('pydap_fig1.png')

For more information, please refer to the Pydap documentation or contact NAS Support with any questions.

This article was:  

Contact Us

General User Assistance

Security

  • Report security issues 24x7x365
  • Toll-free: 1-877-NASA-SEC (1-877-627-2732)
  • E-mail: soc@nasa.gov

User Documentation

High-End Computing Capability (HECC) Portfolio Office

NASA High-End Computing Program

Tell Us About It

Our goal is furnish all the information you need to efficiently and effectively use the HECC resources needed for your NASA computational projects.

We welcome your input on features and topics that you would like to see included on this website.

Please send us email with your wish list and other feedback.