astro/daylight.py
How light it is outside right now at a latitude and longitude, as one number from 0 (night) to 1 (the sun overhead): the sine of the sun's altitude, computed with ephem (no network). A body can grow by it.
Use when an agent's body or a card wants daylight now as a single number, e.g. a plant that opens in the sun.
- the file
- astro/daylight.py
- its skill
- astro/SKILL.md (the whole astro pack)
- as knowledge
- okf/astro/daylight.md
- on GitHub
- astro/daylight.py ↗
Run it
1. Once per machine: install fragletc (Docker must already be running).
curl -fsSL https://raw.githubusercontent.com/ofthemachine/fraglet/main/install.sh | sh
2. Fetch the tool and print its contract.
curl -fsSLO https://tools.ofthemachine.com/astro/daylight.py && chmod +x daylight.py && ./daylight.py --fraglet-help
3. Run it.
./daylight.py -p lat="<lat>" -p lon="<lon>" --output light.txt
Parameters
| name | type | requirement | description |
|---|---|---|---|
| lat | string | required | Latitude in decimal degrees, e.g. 43.65 |
| lon | string | required | Longitude in decimal degrees, east positive, e.g. -79.38 |
Outputs
light.txt
Provenance
- image
- ofthemachine/python3@sha256:59784cff1945b7d6093a591b5e5292b8c989f0691af0494fbbe1c6b8083a16cb
- reach
network=none— a run is a pure function of its inputs; results are safe to memoize.- procedure_hash
- sha256:e160efd0182c255cd3f8a211e284dc4a3447cd951fc222959766c70c7699fdc1
- receipt
- add
--receipt run.jsonto any run;receipt/attest.pyverifies it against this hash without re-running.
Source
daylight.py · 29 lines · sha256 e160efd0182c…
#!/usr/bin/env -S fragletc --image ofthemachine/python3@sha256:59784cff1945b7d6093a591b5e5292b8c989f0691af0494fbbe1c6b8083a16cb
#: d=How light it is outside right now at a latitude and longitude, as one number from 0 (night) to 1 (the sun overhead): the sine of the sun's altitude, computed with ephem (no network). A body can grow by it.
#: when=Use when an agent's body or a card wants daylight now as a single number, e.g. a plant that opens in the sun.
#: network=none
#: stdin=none
#: param=lat:required:d=Latitude in decimal degrees, e.g. 43.65
#: param=lon:required:d=Longitude in decimal degrees, east positive, e.g. -79.38
#: output=light.txt
import math
import os
import sys
import ephem
try:
lat, lon = float(os.environ["LAT"]), float(os.environ["LON"])
except (KeyError, ValueError):
sys.exit("daylight: lat and lon are decimal degrees")
here = ephem.Observer()
here.lat, here.lon = str(lat), str(lon)
sun = ephem.Sun(here)
alt = math.degrees(float(sun.alt))
light = round(max(0.0, math.sin(math.radians(alt))), 2)
os.makedirs("/output", exist_ok=True)
with open("/output/light.txt", "w") as f:
f.write(f"{light}\n")
print(f"light {light}: the sun is {alt:.0f}° {'up' if alt >= 0 else 'down'}")