Code Monkey home page Code Monkey logo

moon's Introduction

        _..._           _..._            _..._            _..._            _..._
      .:::::::.       .::::. `.        .::::  `.        .::'   `.        .'     `.
     :::::::::::     :::::::.  :      ::::::    :      :::       :      :         :  
     :::::::::::     ::::::::  :      ::::::    :      :::       :      :         :
     `:::::::::'     `::::::' .'      `:::::   .'      `::.     .'      `.       .'
       `':::''         `'::'-'         `'::.-'           `':..-'          `-...-'

        _..._           _..._           _..._            _..._            _..._
      .'     `.       .'   `::.       .'  ::::.        .' .::::.        .:::::::.
     :         :     :       :::     :    ::::::      :  ::::::::      ::::::::::: 
     :         :     :       :::     :    ::::::      :  ::::::::      :::::::::::
     `.       .'     `.     .::'     `.   :::::'      `. '::::::'      `:::::::::'
       `-...-'         `-..:''         `-.::''          `-.::''          `':::''

moon

This is a Python package that gets an image of a given date's moon phase. It uses NumPy, OpenCV, and Ernie Wright's moon visualizations from the Dial-a-Moon project at Nasa's Scientific Visualization Studio.

At time of last release, this package can access any of the moon visualizations from 2011-2024. In November of each calendar year, the data for the next year's moon becomes available on SVS and copied over to this repositorhy as soon as possible, so for best performance, the new version of this package should be installed at the end of each year.

Installation

To install this package, just run

pip install moon

Usage

Currently, this package can get a NumPy.ndarray representing the lunar phase, as well as some json of the lunar stats from the Dial-a-Moon Nasa site. This array is usable as an image using openCV, or can be saved to disk as a .jpg file.

You can test it out using terminal:

from moon.terminal_ui import TerminalUi

ui = TerminalUi()
ui.set_moon_phase() #defaults to today's date
print(ui.moon_datetime_info)
ui.show()

You can alternately test it out using Jupyter notebooks:

from moon.jupyter_ui import JupyterUi

ui = JupyterUi()
ui.set_moon_phase() #defaults to today's date
print(ui.moon_datetime_info)
ui.show()

To just use it in a project, you can use it like this:

from moon.dialamoon import Moon

moon = Moon()
moon.set_moon_phase()

and access the image array itself with

moon.image

You can save the current image to disk with the method moon.save_to_disk('filename') or ui.save_to_disk('filename'), which would save a filename.jpg in your current directory.

Updates

Please feel free to post bugs, suggestions and feature requests on this repo. This will be my first time creating and maintaining a python package, and I am receptive to any recommendations or PRs.

1.1.2 2021-01-24

  • can include hour parameter in Moon.set_moon_phase()

1.1.3 2021-05-01

  • update numpy and opencv-python versions
  • fix lru_cache decorator to fix issue #4

1.1.5 2021-12-30

  • 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

todo

  • check whether there are edge cases where json mooninfo or date attributes might not match the currently requested moon phase
  • make a clearer method for loading previously downloaded images/json as the current moon phase and data

Resources:

moon ascii art courtesy of jsg

        _..._           _..._            _..._            _..._            _..._
      .:::::::.       .::::. `.        .::::  `.        .::'   `.        .'     `.
     :::::::::::     :::::::.  :      ::::::    :      :::       :      :         :  
     :::::::::::     ::::::::  :      ::::::    :      :::       :      :         :
     `:::::::::'     `::::::' .'      `:::::   .'      `::.     .'      `.       .'
       `':::''         `'::'-'         `'::.-'           `':..-'          `-...-'

        _..._           _..._           _..._            _..._            _..._
      .'     `.       .'   `::.       .'  ::::.        .' .::::.        .:::::::.
     :         :     :       :::     :    ::::::      :  ::::::::      ::::::::::: 
     :         :     :       :::     :    ::::::      :  ::::::::      :::::::::::
     `.       .'     `.     .::'     `.   :::::'      `. '::::::'      `:::::::::'
       `-...-'         `-..:''         `-.::''          `-.::''          `':::''

moon's People

Contributors

spacerest avatar sadieparker avatar bhavpreet avatar huangf1 avatar dougiteixeira avatar

Stargazers

Fabien Rica avatar Mohammad Reza Akbari avatar  avatar Nahu Mussel avatar  avatar Martin Breuss avatar  avatar David avatar

Watchers

James Cloos avatar  avatar Shawn avatar

moon's Issues

plt.show() no longer opening up

/home/sadie/Projects/moon/moon/terminal_ui.py:11: UserWarning: FigureCanvasAgg is non-interactive, and thus cannot be shown
  plt.show()

Moon hourly

Good day, just a tip: It'd be great to have an option of downloading Moon images even per hour as SVS NASA provides them.
Thank you for the package and best regards, Pavel

simplify image packages being used

I don't know if this package really benefits from having the ability to return the numpy.ndarray version of the image. It could be worth simplifying this so there aren't such large dependencies.

doesn't refresh json moon info when requesting a separate year

The year in .moon_datetime_info stays at 2019 even though the package gets the moon for 2020:

>>> ui.set_moon_phase("2019-01-05")
True
>>> ui.get_moon_phase_date()
datetime.datetime(2019, 1, 5, 9, 0, tzinfo=datetime.timezone.utc)
>>> print(ui.moon_datetime_info)
{'time': '05 Jan 2019 09:00 UT', 'phase': 0.46, 'age': 29.069, 'diameter': 1786.9, 'distance': 401096, 'j2000': {'ra': 18.4926, 'dec': -21.4849}, 'subsolar': {'lon': -168.825, 'lat': 0.316}, 'subearth': {'lon': 3.622, 'lat': -2.295}, 'posangle': 355.6}
>>> ui.set_moon_phase("2020-01-05")
True
>>> ui.get_moon_phase_date()
datetime.datetime(2020, 1, 5, 9, 0, tzinfo=datetime.timezone.utc)
>>> print(ui.moon_datetime_info)
{'time': '05 Jan 2019 09:00 UT', 'phase': 0.46, 'age': 29.069, 'diameter': 1786.9, 'distance': 401096, 'j2000': {'ra': 18.4926, 'dec': -21.4849}, 'subsolar': {'lon': -168.825, 'lat': 0.316}, 'subearth': {'lon': 3.622, 'lat': -2.295}, 'posangle': 355.6}

.set_moon_phase() can't take a None argument

>>> ui.set_moon_phase()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sadie/Projects/moon/moon/dialamoon.py", line 50, in set_moon_phase
    raise e
  File "/home/sadie/Projects/moon/moon/dialamoon.py", line 44, in set_moon_phase
    if datetime.strptime(date, '%Y-%M-%d').year != datetime.strptime(self.moon_datetime_info['time']+'C', '%d %b %Y %H:%M %Z').year:
TypeError: strptime() argument 1 must be str, not None

update to use new NASA SVS api

"The basic format for a Dial-A-Moon API call is:
https://svs.gsfc.nasa.gov/api/dialamoon/{UTC timestamp in YYYY-MM-DDTHH:MM}
Note: there is always a letter T in between the date and time, and it is not something that should be converted" svs.gsfc.nasa.gov

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.