Metadata-Version: 2.5
Name: hilal-visibility
Version: 0.1.0
Summary: Crescent moon (hilal) visibility kernel: topocentric lunar circumstances from JPL DE440s and the Yallop, Odeh and SAAO visibility criteria, for single locations or global zone grids.
Project-URL: Homepage, https://hilal.analyticadss.com
Author: Aous Abdo
License-Expression: MIT
License-File: LICENSE
License-File: hilal_visibility/validate/data/LICENSE-mphys-moon
Keywords: astronomy,crescent,ephemeris,hijri,hilal,islamic calendar,lunar crescent visibility,moon,new moon,odeh,yallop
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Astronomy
Classifier: Typing :: Typed
Requires-Python: >=3.12
Requires-Dist: contourpy>=1.3
Requires-Dist: numpy<2.5,>=1.26
Requires-Dist: pillow>=10.0
Requires-Dist: shapely>=2.0
Requires-Dist: skyfield>=1.49
Provides-Extra: dev
Requires-Dist: matplotlib>=3.8; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Provides-Extra: plot
Requires-Dist: matplotlib>=3.8; extra == 'plot'
Description-Content-Type: text/markdown

# hilal-visibility

Crescent moon (hilal) visibility kernel. It computes the circumstances of the
young crescent for any location and evening from the JPL DE440s ephemeris
(via [Skyfield](https://rhodesmill.org/skyfield/)), and classifies them under
the published visibility criteria. Each criterion is fed quantities in the
convention its constants were fitted on:

| Key | Source |
|---|---|
| `yallop` | Yallop (1997), NAO Technical Note 69, q-test (geocentric ARCV + TN 69 width W′) |
| `odeh` | Odeh (2004), Experimental Astronomy 18, V-test (topocentric airless ARCV + W) |
| `saao` | Caldwell & Laney (2001), SAAO lower-limb DALT criterion |
| `shaukat` | reconstruction of the moonsighting.com criterion (not a published rule) |
| `raw` | quantities plus q and V, no zone |

It also builds vectorized global zone grids, turns them into GeoJSON
contours, labels astronomical Hijri months, and includes a validation harness
against two historical sighting datasets. It is the compute kernel behind
<https://hilal.analyticadss.com>.

## Install

```bash
pip install hilal-visibility
pip install "hilal-visibility[plot]"   # adds matplotlib for diagnostic PNG maps
```

Requires Python 3.12 or newer.

## Example: one location, one evening

```python
from datetime import date

from hilal_visibility.criteria import CRITERIA
from hilal_visibility.ephem import compute_evening, find_new_moon

# The new moon nearest 9 December 2026, and the evening of that day.
conjunction = find_new_moon(date(2026, 12, 9))
evening = conjunction.date()

# Mecca (lat, lon east-positive, elevation in metres).
r = compute_evening(21.4225, 39.8262, evening, conjunction=conjunction, elevation_m=277)

print(f"conjunction  {conjunction:%Y-%m-%d %H:%M} UT")
print(f"evening of   {evening}")
print(f"sunset       {r.sunset_utc:%H:%M} UT, moonset {r.moonset_utc:%H:%M} UT, lag {r.lag_minutes:.0f} min")
p = r.params
print(f"moon age     {p.moon_age_hours:.1f} h at sunset")
print(f"ARCV {p.arcv:.2f}°  ARCL {p.arcl:.2f}°  DAZ {p.daz:.2f}°  W {p.w:.2f}′")
for name in ("yallop", "odeh", "saao"):
    res = CRITERIA[name](p)
    score = f"q = {res.q:+.3f}" if res.q is not None else f"V = {res.v:+.2f}" if res.v is not None else ""
    print(f"{name:7s} zone {res.zone.value}  {score}")
```

Output:

```
conjunction  2026-12-09 00:51 UT
evening of   2026-12-09
sunset       14:41 UT, moonset 14:54 UT, lag 13 min
moon age     13.8 h at sunset
ARCV 2.72°  ARCL 7.28°  DAZ -6.75°  W 0.12′
yallop  zone F  q = -0.740
odeh    zone D  V = -3.70
saao    zone D
```

Each criterion has its own zone letters, and the letters do not mean the same
thing across criteria. Here Yallop's F is "below the Danjon limit", Odeh's D
is "not visible", and SAAO's D is "not visible even with optical aid". The
docstring of `hilal_visibility.criteria` defines every zone.
`hilal_visibility.grid.compute_evening_grids` runs the same calculation over
the whole globe.

## The ephemeris file

The first call that needs the ephemeris downloads JPL's `de440s.bsp` (about
32 MB) through Skyfield and caches it. The cache directory is, in order:

1. `$HILAL_EPHEMERIS_DIR`, if set;
2. `data/ephemeris/` when running from a source checkout of the repository;
3. otherwise a per-user cache directory: `~/.cache/hilal-visibility` on Linux
   (or `$XDG_CACHE_HOME/hilal-visibility`), `~/Library/Caches/hilal-visibility`
   on macOS, `%LOCALAPPDATA%\hilal-visibility` on Windows.

`hilal_visibility.ephem.ephemeris_dir()` returns the directory in use. To work
offline, put a copy of `de440s.bsp` there.

## Validation data

`hilal_visibility.validate` scores the criteria against Yallop (1997) Table 4
(295 records) and Alrefay et al. (2018) (476 records). Both CSVs (about 50 KB)
ship inside the package. Their provenance is in
`hilal_visibility/validate/data/SOURCES.md`, next to the MIT notice of the
transcription they were taken from.

## Licence

MIT. Copyright (c) 2026 Analytica Data Science Solutions.
