Page 1 of 1

computing monthly average from daily output

Posted: Thu Dec 04, 2025 2:38 pm America/New_York
by bailingli
The user only needs monthly groundwater storage estimates from GLDAS2.2 (https://disc.gsfc.nasa.gov/datasets/GLDAS_CLSM025_DA1_D_2.2/summary?keywords=GLDAS). Can GES DISC help compute monthly average internally using daily GLDAS2.2 output? This will reduce download time substantially as the user needs to download the entire record (2003-present) for New Mexico.

Re: computing monthly average from daily output

Posted: Mon Dec 08, 2025 4:12 pm America/New_York
by GES DISC - jschaperow
Computing monthly averages from a large dataset poses challenges - but GES DISC has several tools to help make this as easy (and computationally efficient) as possible. I would recommend using the OPeNDAP in the Cloud Service, which allows you to subset a dataset on a remote server, so you avoid having to download and open all the granules (files) in the collection (GLDAS_CLSM025_DA1_D_2.2).

The following Python code will resample GLDAS data from daily to monthly. You may want to modify the lat/lon bounds to hone in on New Mexico.

Code: Select all


import xarray as xr
import earthaccess
import getpass
import requests
from pydap.net import create_session
import matplotlib.pyplot as plt
import geopandas

# Define latitude and longitude bounds for area of interest
lat_min, lat_max = 24.5, 49.4  # Latitude bounds
lon_min, lon_max = -124.7, -66.9  # Longitude bounds

# Search for GLDAS granules and obtain the corresponding Cloud OpenDAP URLs
results = earthaccess.search_data(
    doi="10.5067/TXBMLX370XX8", # This is the DOI for the GLDAS_CLSM025_DA1_D data collection
    temporal=('2023-01-01 00:00', '2023-01-31 23:00'), 
    bounding_box=(lon_min, lat_min, lon_max, lat_max)
)

# Construct OpenDAP URLs with constraint expresssions for subsetting
opendap_urls = []
for item in results:
    for urls in item['umm']['RelatedUrls']:  # Iterate over RelatedUrls in each request step
        if 'OPENDAP' in urls.get('Description', '').upper():  # Check if 'OPENDAP' is in the Description
            # Extract OPeNDAP URL, replace 
            url = urls['URL'].replace('https', 'dap4')

            # Select groundwater storage, lat, lon, and time (these will be subset out of the larger file)
            # To view all variables, comment out these two lines
            ce = "?dap4.ce=/{}%3B/{}%3B/{}%3B/{}".format("GWS_tavg", "lat", "lon", "time")
            url = url + ce

            # Add URL to list
            opendap_urls.append(url)

# Use netrc file to authenticate
my_session = create_session()

# Load dataset object and metadata, but don't open the values yet
# Remove the session parameter if you are just using a .netrc file to authenticate
ds = xr.open_mfdataset(opendap_urls, engine="pydap", session=my_session)

ds_sub = ds.sel(lat=slice(lat_min, lat_max), lon=slice(lon_min, lon_max)) # subset to lat/lon bounds
monthly_groundwater = ds_sub['GWS_tavg'].resample(time='1M').mean() # resample to monthly
Some other links that might be helpful:

Re: computing monthly average from daily output

Posted: Mon Dec 08, 2025 4:44 pm America/New_York
by andrew.m.fisher
The user can also use the Giovanni tool to compute monthly averages from daily groundwater storage data from GLDAS_CLSM025_DA1_D.

Here’s a link to an example of using the Time Average Map tool in Giovanni. This is for the first month of the dataset record which is from February 2003 and represents the monthly average at each grid cell. Giovanni also can filter data over selected shape files for each US State. So you’ll see the data plot only shows the output over New Mexico for this example. The user can download via NetCDF, PNG, GeoTIFF, and KMZ formats. There are also interactive plot options the user can use to visualize the data.

Another example using the Time Series, Area-Averaged tool if the user wants a time series as either an average over the state of NM or as a specified (lat,lon) point.