"""NOAA PSL Interpolated OLR (Liebmann and Smith 1996), daily 2.5 deg, as CESM FLUT on the 1 deg OLR CDR grid. Source: https://downloads.psl.noaa.gov/Datasets/interp_OLR/olr.day.mean.nc (downloaded 2026-11-12 to download_psl_olr/; 1974-06-01..2022-12-31, PSL no longer extends it). Days 1979-01-01..2022-12-31 are kept. The 2.5 deg points (lat 90..-90, lon 0..357.5) are bilinearly interpolated to the 1 deg cell centres (lat -89.5..89.5, lon 0.5..359.5, periodic in lon); going from a coarser to a finer grid, so no information is added or removed. Time stamped at noon like the other new obs. Output: data/FLUT.psl_interp_olr.day.nc Usage: python -I psl_olr.py. Written 2026-11-12. """ import datetime as dt import os import sys import netCDF4 import numpy as np BASE = "/glade/work/bundy/mdtf/obs_wk_mjo" SRC = f"{BASE}/download_psl_olr/olr.day.mean.nc" OUT = f"{BASE}/data/FLUT.psl_interp_olr.day.nc" def lin_weights(src, dst, period=None): """w[i, j]: linear interpolation weights from points src (ascending, uniform) to dst.""" d = src[1] - src[0] w = np.zeros((len(dst), len(src))) for i, x in enumerate(dst): f = (x - src[0]) / d j = int(np.floor(f)) r = f - j if period is None: if j == len(src) - 1: j, r = j - 1, 1.0 w[i, j % len(src)] += 1 - r w[i, (j + 1) % len(src)] += r return w def main(): if os.path.exists(OUT): sys.exit(f"{OUT} exists, nothing to do") src = netCDF4.Dataset(SRC) src.set_auto_mask(False) t = src["time"] dates = [d.date() for d in netCDF4.num2date(t[:], t.units, only_use_cftime_datetimes=False, only_use_python_datetimes=True)] k0 = dates.index(dt.date(1979, 1, 1)) days = dates[k0:] if any((b - a).days != 1 for a, b in zip(days, days[1:])): sys.exit("days are not consecutive") lat = np.asarray(src["lat"][:], "f8") lon = np.asarray(src["lon"][:], "f8") if not (lat[0] == 90 and lat[-1] == -90 and len(lat) == 73 and lon[0] == 0 and len(lon) == 144): sys.exit("unexpected grid") wlat = lin_weights(lat[::-1], np.arange(-89.5, 90.0)) # source lat made ascending wlonT = lin_weights(lon, np.arange(0.5, 360.0), 360.0).T.copy() tmp = OUT + ".tmp" with netCDF4.Dataset(tmp, "w") as o: o.createDimension("time", None) o.createDimension("lat", 180) o.createDimension("lon", 360) o.createDimension("nbnd", 2) tt = o.createVariable("time", "f8", ("time",)) tt.units, tt.calendar, tt.standard_name, tt.axis = "days since 1970-01-01", "proleptic_gregorian", "time", "T" tt.bounds = "time_bnds" base = dt.date(1970, 1, 1) tt[:] = [(d - base).days + 0.5 for d in days] tb = o.createVariable("time_bnds", "f8", ("time", "nbnd")) tb[:] = [[(d - base).days, (d - base).days + 1] for d in days] la = o.createVariable("lat", "f4", ("lat",)) la.units, la.standard_name, la.axis = "degrees_north", "latitude", "Y" la[:] = np.arange(-89.5, 90.0) lo = o.createVariable("lon", "f4", ("lon",)) lo.units, lo.standard_name, lo.axis = "degrees_east", "longitude", "X" lo[:] = np.arange(0.5, 360.0) x = o.createVariable("FLUT", "f4", ("time", "lat", "lon"), zlib=True, complevel=1) x.units, x.standard_name = "W/m2", "toa_outgoing_longwave_flux" x.long_name = "Upwelling longwave flux at top of model" x.original_name, x.cell_methods = "olr", "time: mean" x.comment = ("NOAA Interpolated OLR, daily mean (Liebmann and Smith 1996), bilinearly interpolated from 2.5 deg " "to 1 deg. Gaps in the NOAA twice-daily OLR were already filled by PSL by interpolation in " "time and space; no missing values.") v = src["olr"] n = len(days) for a in range(0, n, 365): b = min(a + 365, n) blk = np.asarray(v[k0 + a:k0 + b], "f8")[:, ::-1, :] if not np.all((blk > 0) & (blk < 500)): sys.exit(f"bad values in days {days[a]}..{days[b - 1]}") x[a:b] = wlat @ blk @ wlonT # (180,73) @ (t,73,144) @ (144,360) print(f"{dt.datetime.now():%H:%M:%S} {days[a]}", flush=True) o.title = "NOAA Interpolated OLR on the 1x1 deg NOAA OLR CDR grid, as CESM FLUT" o.source = ("NOAA PSL Interpolated OLR, daily mean, https://downloads.psl.noaa.gov/Datasets/interp_OLR/" "olr.day.mean.nc (downloaded 2026-11-12). Liebmann, B. and C. A. Smith, 1996: Description of a " "complete (interpolated) outgoing longwave radiation dataset. BAMS, 77, 1275-1277.") o.history = f"{dt.datetime.now():%Y-%m-%d}: built by {BASE}/src/psl_olr.py" os.rename(tmp, OUT) print(f"DONE {OUT}: {n} days {days[0]}..{days[-1]}", flush=True) if __name__ == "__main__": main()