Skip to content

OPeNDAP Data Requests

This section provides code examples on how to access data from the Open-source Project for a Network Data Access Protocol (OPeNDAP) Services. For more information on the API services please see the OPeNDAP Services Section.

Data Download

The Python Script below can be used to download the POWER data directly from OPeNDAP as a NetCDF 4. It is recommend that this script is used to download historical data and then the API is used to keep the catalog up-to-date.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import os

import pandas as pd
import xarray as xr

from datetime import datetime

filepath = 'https://opendap.larc.nasa.gov/opendap/POWER/annual/power_901_annual_radiation_utc.nc'

ds = xr.open_dataset(filepath)

ds_single_point = ds.ALLSKY_SFC_LW_DWN.sel(lat=50, lon=50, method='nearest').load()

ds_single_time = ds.ALLSKY_SFC_LW_DWN.sel(time=datetime(2020, 12, 31)).load()

ds_time_series = ds.ALLSKY_SFC_LW_DWN.sel(time=pd.date_range(datetime(2019, 12, 31), datetime(2020, 12, 31), freq='1Y')).load()

ds_region = ds.ALLSKY_SFC_LW_DWN.sel(lat=slice(50, 60), lon=slice(50, 60)).load()

output = r'' # if none the location of the script is where the files will be outputted.
ds_region.to_netcdf(path=os.path.join(output, "ds_region.nc"))