_..._ _..._ _..._ _..._ _..._
.:::::::. .::::. `. .:::: `. .::' `. .' `.
::::::::::: :::::::. : :::::: : ::: : : :
::::::::::: :::::::: : :::::: : ::: : : :
`:::::::::' `::::::' .' `::::: .' `::. .' `. .'
`':::'' `'::'-' `'::.-' `':..-' `-...-'
_..._ _..._ _..._ _..._ _..._
.' `. .' `::. .' ::::. .' .::::. .:::::::.
: : : ::: : :::::: : :::::::: :::::::::::
: : : ::: : :::::: : :::::::: :::::::::::
`. .' `. .::' `. :::::' `. '::::::' `:::::::::'
`-...-' `-..:'' `-.::'' `-.::'' `':::''
This is a Python package that gets an image of a given date's moon phase. It uses Ernie Wright's moon visualizations from the Dial-a-Moon project at NASA's Scientific Visualization Studio.
At the time of the last release, this package can access any of the moon visualizations from 2011 onward.
To install this package, just run:
pip install moon
This package retrieves a NumPy.ndarray representing the lunar phase, along with JSON data containing lunar statistics from NASA's Dial-a-Moon project. The image array can be manipulated with OpenCV and/or saved to disk as a .jpg
file.
from moon.dialamoon import Moon
moon = Moon()
moon.set_moon_phase()
Access the image array with:
moon.image
Save the image to disk as filename.jpg
with:
moon.save_to_disk('filename')
from moon.jupyter_ui import JupyterUi
ui = JupyterUi()
ui.set_moon_phase() # Defaults to today's date
print(ui.info)
ui.show()
By default, the returned image is 730x730 pixels. To specify a different size, use the size
keyword argument:
moon = Moon(size=(100, 100))
The inclusion of OpenCV and NumPy in this package is a remnant of earlier versions that supported additional image processing features. While currently not necessary for core functionality, these libraries allow for customization of images, such as
- Adjusting brightness, contrast, applying filters
- Overlaying text or graphics
- Efficient in-memory image processing using NumPy arrays
For example, you can use OpenCV to apply a grayscale filter:
import cv2
import numpy as np
image = moon.image
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imwrite("gray_moon.jpg", gray_image)
Since these dependencies are no longer required for core functionality, they will probably be removed in a future version.
You can access more details and related lunar imagery via Moon.info
.
Please feel free to post bugs, suggestions and feature requests on this repo.
- use the new API to determine moon image urls, so yearly IDs don't need to be added anymore
- deprecate image viewing via terminal
- put constants in a
.json
file instead of a.py
file - add SVS ID for 2022
- if a SVS ID for a year isn't available, check whether it's available on in
res/constants.json
on the GitHub repo and then remind the user to update the package for next time
- update numpy and opencv-python versions
- fix lru_cache decorator to fix issue #4
- can include
hour
parameter inMoon.set_moon_phase()
moon ascii art courtesy of jsg
_..._ _..._ _..._ _..._ _..._
.:::::::. .::::. `. .:::: `. .::' `. .' `.
::::::::::: :::::::. : :::::: : ::: : : :
::::::::::: :::::::: : :::::: : ::: : : :
`:::::::::' `::::::' .' `::::: .' `::. .' `. .'
`':::'' `'::'-' `'::.-' `':..-' `-...-'
_..._ _..._ _..._ _..._ _..._
.' `. .' `::. .' ::::. .' .::::. .:::::::.
: : : ::: : :::::: : :::::::: :::::::::::
: : : ::: : :::::: : :::::::: :::::::::::
`. .' `. .::' `. :::::' `. '::::::' `:::::::::'
`-...-' `-..:'' `-.::'' `-.::'' `':::''