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.
Metadata
Release files for jax-solar 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| jax_solar-0.1.1.tar.gz | 11.2 kB | Without provenance | Details for jax_solar-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| jax_solar-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for jax_solar-0.1.1-py3-none-any.whl |
Total release size: 24.1 kB
Release files / jax_solar-0.1.1.tar.gz
| Download URL | jax_solar-0.1.1.tar.gz |
|---|---|
| Size | 11.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
17c9b178170d250287bdac454feebdc8b2213dc6ea93a5135f8c15d245c3a01e
|
|
BLAKE2b-256 checksum How to use checksums |
4df6fd8071736a8ae3fa6782a584b81ac1a75b0fc9e5dd621be8d91cd599ff2f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.13
|
Release files / jax_solar-0.1.1-py3-none-any.whl
| Download URL | jax_solar-0.1.1-py3-none-any.whl |
|---|---|
| Size | 12.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
796473027ed3dc45934cbcf50640c694a241a71320a5a92344746608ea0305ff
|
|
BLAKE2b-256 checksum How to use checksums |
e17220b5357cf99ab05da28731b78fabe96e94ed5e12881a462299aba4f2f873
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.13
|
Security for jax-solar 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.