Overview¶
This notebook demonstrates how to directly access a NetCDF file on GDEX over HTTPS with fsspec and run analysis on it, without downloading the file to disk.
Find a file’s HTTPS URL
Open it lazily with fsspec
Load it with xarray and run analysis
Prerequisites¶
| Concepts | Importance | Notes |
|---|---|---|
| download_intro | Necessary | File listing and HTTP download |
| fsspec | Necessary | Remote file access |
| xarray | Necessary |
Time to learn: 15 minutes
Imports¶
import matplotlib.pyplot as plt
import fsspec
import xarray as xrStep 1 — Find a File’s HTTPS URL¶
From the GDEX web portal, we can identify the direct HTTPS link to the NetCDF file:
https://osdf-director.osg-htc.org/ncar/gdex/d651056/CESM2-LE/atm/proc/tseries/month_1/LHFLX/b.e21.BHISTcmip6.f09_g17.LE2-1001.001.cam.h0.LHFLX.185001-185912.nc
Opening this URL in a browser typically starts a file download.
In this workflow, we instead use the URL programmatically so the data can be accessed directly in memory (via fsspec/xarray) without first saving a local copy.

The direct file URL can be copied from the GDEX data access page.
Step 2 — Open the File Lazily with fsspec¶
fsspec’s HTTP filesystem opens a remote file as a Python file-like object backed by HTTP range requests, so only the bytes you access are transferred.
# open the remote NetCDF file
file_url = 'https://data.gdex.ucar.edu/d651056/CESM2-LE/atm/proc/tseries/month_1/LHFLX/b.e21.BHISTcmip6.f09_g17.LE2-1001.001.cam.h0.LHFLX.185001-185912.nc'
fs = fsspec.filesystem("http")
remote_file = fs.open(file_url)
ds = xr.open_dataset(remote_file)Step 3 — Load with xarray and Plot¶
Call .load() on a variable to fetch its data into memory, then visualize it with matplotlib.
ds['co2vmr'].load()ds['co2vmr']co2 = ds["co2vmr"]
# convert the cftime index to a datetime index for plotting
time_dt = ds.indexes["time"].to_datetimeindex()
fig, ax = plt.subplots(figsize=(10, 4))
ax.plot(time_dt, co2.values, linewidth=1.8)
ax.set_title("CO2 Volume Mixing Ratio Time Series")
ax.set_xlabel("Time")
ax.set_ylabel("co2vmr")
ax.grid(True, alpha=0.3)
plt.xticks(rotation=45)
plt.tight_layout()
/tmp/ipykernel_4755/3606810028.py:3: FutureWarning: In a future version of xarray to_datetimeindex will default to returning a 'us'-resolution DatetimeIndex instead of a 'ns'-resolution DatetimeIndex. This warning can be silenced by explicitly passing the `time_unit` keyword argument.
time_dt = ds.indexes["time"].to_datetimeindex()
/tmp/ipykernel_4755/3606810028.py:3: RuntimeWarning: Converting a CFTimeIndex with dates from a non-standard calendar, 'noleap', to a pandas.DatetimeIndex, which uses dates from the standard calendar. This may lead to subtle errors in operations that depend on the length of time between dates.
time_dt = ds.indexes["time"].to_datetimeindex()

Summary¶
fsspec combined with xarray lets you open a remote NetCDF file directly over HTTPS and read only the data you need, without storing the file locally.
What’s next?¶
See globus_intro.ipynb to transfer files to an HPC system via Globus instead of HTTP access.