Extract planetary data into _data.py and add Wikidata refresh script
This commit is contained in:
62
README.md
62
README.md
@@ -60,34 +60,37 @@ now = datetime.now(timezone.utc)
|
||||
# Mars time since discovery (Galileo, 1610)
|
||||
pt = PlanetaryTime.from_earth(now, Body.MARS, EpochType.DISCOVERY)
|
||||
print(pt)
|
||||
# Year 415, Sol 668, 14:22:07 (Mars / discovery epoch)
|
||||
# Year 217, Sol 579, 11:00:00 (Mars / discovery epoch)
|
||||
|
||||
print(pt.year) # 415
|
||||
print(pt.sol) # 668
|
||||
print(pt.hour) # 14
|
||||
print(pt.minute) # 22
|
||||
print(pt.second) # 7
|
||||
print(pt.time) # "14:22:07"
|
||||
print(pt.date) # "Year 415, Sol 668"
|
||||
print(pt.year) # 217
|
||||
print(pt.sol) # 579
|
||||
print(pt.hour) # 11
|
||||
print(pt.minute) # 0
|
||||
print(pt.second) # 0
|
||||
print(pt.time) # "11:00:00"
|
||||
print(pt.date) # "Year 217, Sol 579"
|
||||
|
||||
# Mars time since first contact (Viking 1, 1976)
|
||||
pt = PlanetaryTime.from_earth(now, Body.MARS, EpochType.CONTACT)
|
||||
print(pt)
|
||||
# Year 25, Sol 23, 14:22:07 (Mars / contact epoch)
|
||||
# Year 26, Sol 25, 15:00:00 (Mars / contact epoch)
|
||||
```
|
||||
|
||||
### Moons
|
||||
|
||||
```python
|
||||
# Titan time since discovery (Huygens, 1655)
|
||||
# Titan (Saturn's largest moon) — accessible via Body.SATURN[0]
|
||||
titan = Body.SATURN[0]
|
||||
|
||||
# Time since discovery (Christiaan Huygens, 1655)
|
||||
pt = PlanetaryTime.from_earth(now, titan, EpochType.DISCOVERY)
|
||||
print(pt)
|
||||
# Year 1, Sol 0, 08:11:45 (Titan / discovery epoch)
|
||||
# Year 8492, Sol 0, 344:00:00 (Titan / discovery epoch)
|
||||
|
||||
# Titan time since Huygens probe landing (2005)
|
||||
# Time since Huygens probe landing (2005-01-14)
|
||||
pt = PlanetaryTime.from_earth(now, titan, EpochType.CONTACT)
|
||||
print(pt)
|
||||
# Year 486, Sol 0, 282:00:00 (Titan / contact epoch)
|
||||
|
||||
# Check if a moon is tidally locked
|
||||
print(titan.is_tidally_locked) # True
|
||||
@@ -95,13 +98,33 @@ print(titan.is_tidally_locked) # True
|
||||
|
||||
### Epochs
|
||||
|
||||
| EpochType | Meaning |
|
||||
|--------------------|----------------------------------------------|
|
||||
| EpochType | Meaning |
|
||||
|-----------------------|-------------------------------------------|
|
||||
| `EpochType.DISCOVERY` | First recorded observation of the body |
|
||||
| `EpochType.CONTACT` | First probe landing or crewed landing |
|
||||
|
||||
`EpochUnavailableError` is raised when `CONTACT` is requested for a body that has not been visited yet.
|
||||
|
||||
### Exceptions
|
||||
|
||||
```python
|
||||
from planetarytime import EpochType, PlanetaryTime, Body
|
||||
from planetarytime.exceptions import EpochUnavailableError, DatetimePrecedesEpochError
|
||||
|
||||
# Body with no contact yet
|
||||
try:
|
||||
PlanetaryTime.from_earth(now, Body.JUPITER, EpochType.CONTACT)
|
||||
except EpochUnavailableError as e:
|
||||
print(e) # No contact with Jupiter has occurred — contact epoch is unavailable.
|
||||
|
||||
# Datetime before the epoch
|
||||
from datetime import datetime, timezone
|
||||
try:
|
||||
PlanetaryTime.from_earth(datetime(1600, 1, 1, tzinfo=timezone.utc), Body.MARS, EpochType.DISCOVERY)
|
||||
except DatetimePrecedesEpochError as e:
|
||||
print(e)
|
||||
```
|
||||
|
||||
## Logging
|
||||
|
||||
This library uses [loguru](https://github.com/Delgan/loguru) for internal logging.
|
||||
@@ -123,6 +146,17 @@ import sys
|
||||
logger.add(sys.stderr, filter={"planetarytime": "WARNING"})
|
||||
```
|
||||
|
||||
## Refreshing data
|
||||
|
||||
Rotation periods, orbital periods, and discovery/contact dates are stored in [`src/planetarytime/_data.py`](src/planetarytime/_data.py). To regenerate this file from Wikidata:
|
||||
|
||||
```bash
|
||||
python scripts/refresh_data.py # fetch and write _data.py
|
||||
python scripts/refresh_data.py --dry-run # preview without writing
|
||||
```
|
||||
|
||||
The script requires only the Python standard library. Run your test suite afterwards to verify the updated values.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
Reference in New Issue
Block a user