Realistic sky gradient PNGs from latitude, longitude, and time
Project description
skygrad
Realistic sky gradient PNGs from latitude, longitude, and time. Zenith at
the top, horizon at the bottom — one color per row, or the sun's glow
lobe across the frame when you pass facing. The sun's position
drives every color in the image; the sun itself is never drawn — no disc,
no moon, no stars, no clouds. Zero runtime dependencies.
Usage
from datetime import datetime
import skygrad
# One-shot PNG bytes
png = skygrad.render(lat=34.05, lon=-118.24,
when=datetime(1994, 6, 21, 19, 30),
width=512, height=1024)
# Or write straight to a file
skygrad.write_png("dusk.png", lat=34.05, lon=-118.24,
when=datetime(1994, 6, 21, 19, 30))
# Layered access: colors without pixels
sky = skygrad.Sky.at(lat=34.05, lon=-118.24, when=datetime(1994, 6, 21, 19, 30))
sky.solar_elevation # degrees; e.g. streetlights on below -4
sky.color(0.0) # (r, g, b) at the zenith; 1.0 is the horizon
sky.stops() # [(u, (r, g, b)), ...] — build a CSS gradient
Facing (azimuthal glow)
Pass a compass direction and the image gains the sun's glow lobe —
brightest toward the sun, fading with angular distance, gone when you
face away. Without facing, output is byte-identical to skygrad 0.1.
sky = skygrad.Sky.at(lat=34.05, lon=-118.24, when=datetime(1994, 6, 21, 19, 40))
sky.solar_azimuth # ≈ 303° at this dusk — west-northwest
toward = sky.png(facing=sky.solar_azimuth) # sunset glow, centered
away = sky.png(facing=(sky.solar_azimuth + 180) % 360) # plain dusk gradient
wide = sky.png(facing=0.0, fov=360.0, width=2048) # full panorama strip
facing is degrees clockwise from true north (any finite value,
normalized mod 360; radians callers use math.degrees()). fov is the
horizontal span in degrees, default 90, valid (0, 360] — and requires
facing.
A facing render is computed per pixel, so it's capped at ~4 million pixels
(width × height ≤ 2048×2048); go larger and it raises ValueError. Tile,
shrink, or drop facing (the plain vertical gradient is per-row and has no
such cap). Requires Python 3.11+.
Time semantics (read this)
when is a full datetime — the date matters (June and December at the
same hour give completely different skies).
- Timezone-aware datetimes are honored exactly.
- Naive datetimes mean local mean solar time at the given longitude: sundial time, where 12:00 puts the sun on the meridian. This is deliberate — it makes "local" meaningful for fictional places — but it can differ from civil wall-clock time by an hour or more. If you want wall-clock local time, attach a tzinfo.
Determinism
Same inputs → same decoded pixels for a given skygrad.MODEL_VERSION
(and byte-identical PNGs within one zlib build). MODEL_VERSION bumps
whenever any input would render different colors, so golden tests in
consumers break deliberately, never silently. Compare decoded pixels,
not compressed bytes.
Development
uv sync
uv run ruff check . && uv run ruff format --check .
uv run mypy
uv run pytest -q
Golden skies are pinned under tests/golden/; regenerate deliberately
with uv run pytest --regen-golden and bump MODEL_VERSION if colors
changed. Regeneration rewrites all ten goldens, but on one zlib build the
untouched ones are byte-identical rewrites — so a deliberate single-color
change surfaces as exactly the goldens it should. The module map and
invariants live in ARCHITECTURE.md, and the design
rationale (theory of operation) in THEORY.md.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file skygrad-1.0.0.tar.gz.
File metadata
- Download URL: skygrad-1.0.0.tar.gz
- Upload date:
- Size: 167.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e77b266534f16c8b455e83e73e4cee4d083f611d5284b33ad8ee3b67c01dc9e7
|
|
| MD5 |
371df4999849c16be0811d315e4dfbc1
|
|
| BLAKE2b-256 |
55570d7359c2bc1adfaa3102d9e54599caad693c2574a2c89d28368eb59992c6
|
Provenance
The following attestation bundles were made for skygrad-1.0.0.tar.gz:
Publisher:
publish.yml on Xof/skygrad
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
skygrad-1.0.0.tar.gz -
Subject digest:
e77b266534f16c8b455e83e73e4cee4d083f611d5284b33ad8ee3b67c01dc9e7 - Sigstore transparency entry: 1900958925
- Sigstore integration time:
-
Permalink:
Xof/skygrad@2acf9f583e114cd6c34a3dde32332c93488ff2a0 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Xof
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2acf9f583e114cd6c34a3dde32332c93488ff2a0 -
Trigger Event:
release
-
Statement type:
File details
Details for the file skygrad-1.0.0-py3-none-any.whl.
File metadata
- Download URL: skygrad-1.0.0-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
407f3be37857a2ade08a337c5adc230958c1c45cf03850e874a785e6ea930d0c
|
|
| MD5 |
e6eaf84cc793f740f412b60733e0b17e
|
|
| BLAKE2b-256 |
b3a0d0efd61573d8dbabe2163fb66fd81011a1051bb404645eb3cbe75e73bd11
|
Provenance
The following attestation bundles were made for skygrad-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on Xof/skygrad
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
skygrad-1.0.0-py3-none-any.whl -
Subject digest:
407f3be37857a2ade08a337c5adc230958c1c45cf03850e874a785e6ea930d0c - Sigstore transparency entry: 1900959044
- Sigstore integration time:
-
Permalink:
Xof/skygrad@2acf9f583e114cd6c34a3dde32332c93488ff2a0 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Xof
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2acf9f583e114cd6c34a3dde32332c93488ff2a0 -
Trigger Event:
release
-
Statement type: