Skip to main content

Top of atmosphere incident solar radiation, in JAX

Project description

JAX Solar: Top of atmosphere incident solar radiation, in JAX

Authors: Peter Norgaard and Stephan Hoyer

JAX Solar is a JAX implementation of top of atmosphere incident solar radiation (TISR), for use in weather and climate models. It was originally written for NeuralGCM.

This code uses simple formulas inspired by pysolar, but unlike pysolar it does not include atmospheric scattering effects. Of particular note, the constants used to compute solar irradiance are different.

Typical usage

import jax_solar
import jax_datetime as jdt

# near sunset in San Francisco
time = jdt.to_datetime('2024-12-28T00:30')
lat = 37.7749
lon = -122.4194
relative_flux = jax_solar.normalized_radiation_flux(time, lon, lat)
print(relative_flux)  # 0.07284241

How accurate is it?

JAX Solar is accurate to within about 0.5% of TISR values in ERA5:

import xarray
import jax_solar
import jax_datetime as jdt

time = '20231230T22'

ds = xarray.open_zarr(
    'gs://gcp-public-data-arco-era5/ar/full_37-1h-0p25deg-chunk-1.zarr-v3',
    chunks=None,
    storage_options=dict(token='anon'),
)
tisr_era5 = ds.toa_incident_solar_radiation.sel(time=time).compute()

# TISR in ERA5 is integrated over the previous hour, whereas JAX Solar
# provides instantaneous values.
lats, lons = xarray.broadcast(tisr_era5.latitude, tisr_era5.longitude)
dt = 5*60  # in seconds
times = jdt.to_datetime(time) - jnp.arange(0, 60*60//dt + 1) * jdt.Timedelta(seconds=dt)
flux = jnp.trapezoid(
    jax.vmap(lambda t: jax_solar.radiation_flux(t, lons.data, lats.data))(times),
    axis=0,
    dx=dt,
)
tisr_jax_solar = tisr_era5.copy(data=flux)

# first plot: reference TISR from ERA5
tisr_era5.plot(size=3, aspect=2)

# second plot: relative error
relative_error = (tisr_jax_solar - tisr_era5) / tisr_era5.max()
relative_error.rename('Relative error').plot(size=3, aspect=2)

If 0.5% accuracy is not good enough for you, you could consider using the solar radiation code from GraphCast, which nearly exactly matches ERA5.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jax_solar-0.1.1.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jax_solar-0.1.1-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file jax_solar-0.1.1.tar.gz.

File metadata

  • Download URL: jax_solar-0.1.1.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for jax_solar-0.1.1.tar.gz
Algorithm Hash digest
SHA256 17c9b178170d250287bdac454feebdc8b2213dc6ea93a5135f8c15d245c3a01e
MD5 1b48392128cabad26df90f3d70982157
BLAKE2b-256 4df6fd8071736a8ae3fa6782a584b81ac1a75b0fc9e5dd621be8d91cd599ff2f

See more details on using hashes here.

File details

Details for the file jax_solar-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: jax_solar-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for jax_solar-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 796473027ed3dc45934cbcf50640c694a241a71320a5a92344746608ea0305ff
MD5 39218b3416a9be304ba7f25a0d0c6aab
BLAKE2b-256 e17220b5357cf99ab05da28731b78fabe96e94ed5e12881a462299aba4f2f873

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page