Skip to content

Instantly share code, notes, and snippets.

@mlubej
Last active June 30, 2020 08:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlubej/62a8684260260f623cf720ed0be221ca to your computer and use it in GitHub Desktop.
Save mlubej/62a8684260260f623cf720ed0be221ca to your computer and use it in GitHub Desktop.
import ephem
import numpy as np
from datetime import datetime
def get_shadow_length(long, lat, datetime, height):
"""
Accepts longitude and latitude in the WGS84 CRS, along with the
datetime in the UTC time zone. Returns the length of a shadow of an object
with a specified height at the specified time and location.
"""
o = ephem.Observer()
o.long, o.lat = str(long), str(lat)
o.date = ephem.Date(datetime)
sun = ephem.Sun(o)
az = sun.az * 180/np.pi
zen = 90 - sun.alt*180/np.pi
shadow = 1 / np.tan(sun.alt)
return shadow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment