OK so scratch that last script.
This one supports cloud cover.. I am going to target it a wee bit better by using the solar calculations to know exactly where in the sky the sun is in order to determine if a cloud is in the way.. But for the time being this uses a cloud density and % of the sky the clouds cover.. there are adjustments you can make.. read the comments at the top of the script. (comments have a # before them)
I didn't tell you how to use this thing either..
create a macro. put a python script action (eventghost\python script) in the macro. paste the code below into the action and click on apply and then test
you ae going to need to go to openweathermap.org and register so you can get an api key. the api key after you generate it may take an hour or so to become active. you need to enter that key into the script.
There is a full set of directions in the comments of the script. Do read them.
Code: Select all
from __future__ import print_function
import requests
from PIL import Image
from io import BytesIO
# these are the settings you need to change.
# in order to get the exact lat/lon for where the projector is located
# I want you to use this website. https://www.latlong.net/
# be sure to click on the map when you zoom in on it's location.
# and write down the lat and lon.
# once you have clicked on the location this is going to set a "pin" that you can see.
# I now ant you to zoom all the way out. You will still be able to see the pin.
# now zoom on and count the number of zoom levels keeping the mouse pointer
# hovered over the pin while you do this. what we are trying to get here is a
# zoom level that will encompass your physical view of the sky from that location.
# any clouds within that physical view are going to effect how bright it is outside.
# write down this zoom level
LATITUDE = 40.271877
LONGITUDE = -76.885515
DAYLIGHT_SAVINGS = False
UTC_OFFSET = 5
# the radar images of the cloud cover are provided by openweathermap.org
# in order to use the cloud cover portion of this script you will
# need to register to get an api key. It is free to do this
# and allows you to query their system once a second.
RADAR_API_KEY = ''
# You are going to need to tinker a bit with this number in order to get the
# ideal point in which you consider it dar enough to turn the second lamp on
# enter the zoom level you wrote down
RADAR_ZOOM = 9
# I am going to retool this portion of the script later on. I wanted to know
# if this is a sound way of going about it first. once I know this works properly
# I will be able to map the suns location relative to the radar image and be able
# to determine if a cloud is blocking the sun. but for now this should work.
# This is the percentage of the radar image that is covered
# by a the cloud level you set with RADAR_CLOUD_DENSITY.
RADAR_CLOUD_COVER_PERCENT = 35.00
# This parameter represents how thick or dark the clouds are.
# The range is 0 (no cloud) to 100 (day becomes night)
RADAR_CLOUD_DENSITY = 41
# do not edit anything below this point
RADAR_URL = 'https://tile.openweathermap.org/map/clouds_new/{z}/{x}/{y}.png'
import math
def lat_lon_to_tile(lat_deg, lon_deg, zoom):
lat_rad = math.radians(lat_deg)
n = 2.0 ** zoom
xtile = int((lon_deg + 180.0) / 360.0 * n)
ytile = int((1.0 - math.asinh(math.tan(lat_rad)) / math.pi) / 2.0 * n)
# ytile = n - ytile - 1
return xtile, ytile, zoom
def get_url():
x, y, z = lat_lon_to_tile( LATITUDE, LONGITUDE, RADAR_ZOOM)
url = RADAR_URL.format(x=x, y=y, z=z)
return url
class Month(object):
def __init__(self, name, numdays, abbr):
self.name = name
self.numdays = numdays
self.abbr = abbr
class ANS(object):
def __init__(self, daySave, value):
self.daySave = daySave
self.value = value
class City(object):
def __init__(self, name, lat, lng, zoneHr):
self.name = name
self.lat = lat
self.lng = lng
self.zoneHr = zoneHr
monthList = [
Month("January", 31, "Jan"),
Month("February", 28, "Feb"),
Month("March", 31, "Mar"),
Month("April", 30, "Apr"),
Month("May", 31, "May"),
Month("June", 30, "Jun"),
Month("July", 31, "Jul"),
Month("August", 31, "Aug"),
Month("September", 30, "Sep"),
Month("October", 31, "Oct"),
Month("November", 30, "Nov"),
Month("December", 31, "Dec")
]
yesno = [
ANS("No",0),
ANS("Yes",60)
]
city = [
City("Enter Lat/Long -->", 0, 0, 0),
City("", 0, 0, 0),
City("US CITIES", 0, 0, 0),
City("Albuquerque, NM", 35.0833, 106.65, 7),
City("Anchorage, AK", 61.217, 149.90, 9),
City("Atlanta, GA", 33.733, 84.383, 5),
City("Austin, TX", 30.283, 97.733, 6),
City("Birmingham, AL", 33.521, 86.8025, 6),
City("Bismarck, ND", 46.817, 100.783, 6),
City("Boston, MA", 42.35, 71.05, 5),
City("Boulder, CO", 40.125, 105.237, 7),
City("Chicago, IL", 41.85, 87.65, 6),
City("Dallas, TX", 32.46, 96.47, 6),
City("Denver, CO", 39.733, 104.983, 7),
City("Detroit, MI", 42.333, 83.05, 5),
City("Honolulu, HI", 21.30, 157.85, 10),
City("Houston, TX", 29.75, 95.35, 6),
City("Indianapolis, IN", 39.767, 86.15, 5),
City("Jackson, MS", 32.283, 90.183, 6),
City("Kansas City, MO", 39.083, 94.567, 6),
City("Los Angeles, CA", 34.05, 118.233, 8),
City("Menomonee Falls, WI", 43.11, 88.10, 6),
City("Miami, FL", 25.767, 80.183, 5),
City("Minneapolis, MN", 44.967, 93.25, 6),
City("New Orleans, LA", 29.95, 90.067, 6),
City("New York City, NY", 40.7167, 74.0167, 5),
City("Oklahoma City, OK", 35.483, 97.533, 6),
City("Philadelphia, PA", 39.95, 75.15, 5),
City("Phoenix, AZ", 33.433, 112.067, 7),
City("Pittsburgh, PA",40.433,79.9833,5),
City("Portland, ME", 43.666, 70.283, 5),
City("Portland, OR", 45.517, 122.65, 8),
City("Raleigh, NC", 35.783, 78.65, 5),
City("Richmond, VA", 37.5667, 77.450, 5),
City("Saint Louis, MO", 38.6167, 90.1833, 6),
City("San Antonio, TX", 29.53, 98.47, 6),
City("San Diego, CA", 32.7667, 117.2167, 8),
City("San Francisco, CA", 37.7667, 122.4167, 8),
City("Seattle, WA", 47.60, 122.3167, 8),
City("Washington DC", 38.8833, 77.0333, 5),
City("", 0, 0, 0),
City("WORLD CITIES", 0, 0, 0),
City("Beijing, China", 39.9167, -116.4167, -8),
City("Berlin, Germany", 52.33, -13.30, -1),
City("Bombay, India", 18.9333, -72.8333, -5.5),
City("Buenos Aires, Argentina", -34.60, 58.45, 3),
City("Cairo, Egypt", 30.10, -31.3667, -2),
City("Cape Town, South Africa", -33.9167, -18.3667, -2),
City("Caracas, Venezuela", 10.50, 66.9333, 4),
City("Helsinki, Finland", 60.1667, -24.9667,-2),
City("Hong Kong, China", 22.25,-114.1667, -8),
City("Jerusalem, Israel", 31.7833, -35.2333, -2),
City("London, England", 51.50, 0.1667, 0),
City("Mexico City, Mexico", 19.4, 99.15, 6),
City("Moscow, Russia", 55.75, -37.5833, -3),
City("New Delhi, India", 28.6, -77.2, -5.5),
City("Ottawa, Canada", 45.41667, 75.7,5),
City("Paris, France", 48.8667, -2.667, -1),
City("Rio de Janeiro, Brazil", -22.90, 43.2333, 3),
City("Riyadh, Saudi Arabia", 24.633, -46.71667, -3),
City("Rome, Italy", 41.90, -12.4833, -1),
City("Sydney, Australia", -33.8667, -151.2167, -10),
City("Tokyo, Japan", 35.70, -139.7667, -9),
City("Zurich, Switzerland", 47.3833, -8.5333, -1),
City("", 0, 0, 0),
City("SURFRAD NETWORK", 0, 0, 0),
City("Goodwin Creek, MS", 34.2544444, 89.8738888, 6),
City("Fort Peck, MT", 48.310555, 105.1025, 7),
City("Bondville, IL", 40.055277, 88.371944, 6),
City("Table Mountain, CO", 40.125, 105.23694, 7),
City("Desert Rock, NV", 36.626, 116.018, 8),
City("Penn State, PA", 40.72, 77.93, 5),
City("Canaan Valley, WV", 39.1, 79.4, 5),
City("Sioux Falls, SD", 43.733, 96.6233, 6),
City("", 0, 0, 0),
City("ARM/CART NETWORK", 0, 0, 0),
City("Atqasuk, AK", 70.47215, 157.4078, 9),
City("Barrow, AK", 71.30, 156.683, 9),
City("Manus Island, PNG", -2.06, -147.425, -10),
City("Nauru Island", -0.52, -166.92, -12),
City("Darwin, Australia", -12.425, -130.891, -9.5),
City("SGP Central Facility", 36.6167, 97.5, 6),
City("",0,0,0),
City("SOLRAD NETWORK", 0, 0, 0),
City("Albuquerque, NM", 35.04, 106.62, 7),
City("Bismarck, ND", 46.77, 100.77, 6),
City("Hanford, CA", 36.31, 119.63, 8),
City("Madison, WI", 43.13, 89.33, 6),
City("Oak Ridge, TN", 35.96, 84.37, 5),
City("Salt Lake City, UT", 40.77, 111.97, 7),
City("Seattle, WA", 47.68, 122.25, 8),
City("Sterling, VA", 38.98, 77.47, 5),
City("Tallahassee, FL", 30.38, 84.37, 5)
]
def set_lat_long(f, index):
f["latDeg"] = city[index].lat
f["lonDeg"] = city[index].lng
f["latMin"] = 0
f["latSec"] = 0
f["lonMin"] = 0
f["lonSec"] = 0
conv_lat_long(f)
f["hrsToGMT"] = city[index].zoneHr
def is_leap_year(yr):
yr = int(yr)
return (
(yr % 4 == 0 and yr % 100 != 0) or
yr % 400 == 0
)
def is_pos_integer(inputVal):
inputStr = str(inputVal)
for oneChar in list(inputStr):
if oneChar < "0" or oneChar > "9":
return False
return True
def is_valid_input(f, index, lat_long_form):
if f["day"] == "": # see if the day field is empty
print("You must enter a day before attempting the calculation.")
return False
elif f["year"] == "": # see if year field is empty
print("You must enter a year before attempting the calculation.")
return False
elif is_pos_integer(f["day"]) is False or f["day"] == 0:
print("The day must be a positive integer.")
return False
elif is_pos_integer(f["year"]) is False:
print("The year must be a positive integer.")
return False
elif f["hour"] == "": # see if hour field is empty
print("You must enter a time before attempting the calculation.")
return False
elif (
is_pos_integer(f["hour"]) is False or
is_pos_integer(f["mins"]) is False or
is_pos_integer(f["secs"]) is False
):
print("The time fields must contain positive integers.")
return False
elif int(f["hour"]) > 23:
print("Hour must be between 0 and 23.")
return False
elif int(f["mins"]) > 59:
print("Minutes must be between 0 and 59.")
return False
elif int(f["secs"]) > 59:
print("Seconds must be between 0 and 59.")
return False
elif index != 1 and int(f["day"]) > monthList[index].numdays:
print("There are only " + str(monthList[index].numdays) + " days in " + str(monthList[index].name) + ".")
return False
elif index == 1:
if is_leap_year(f["year"]):
if int(f["day"]) > monthList[index].numdays + 1:
print("There are only " + str(monthList[index].numdays + 1) + " days in " + str(monthList[index].name) + ".")
return False
else:
return True
else: # year entered is not a leap year
if int(f["day"]) > monthList[index].numdays:
print("There are only " + str(monthList[index].numdays) + " days in " + str(monthList[index].name) + ".")
return False
else:
return True
else:
return True
def conv_lat_long(f):
if f["latDeg"] == "":
f["latDeg"] = '0'
if f["latMin"] == "":
f["latMin"] = '0'
if f["latSec"] == "":
f["latSec"] = '0'
if f["lonDeg"] == "":
f["lonDeg"] = '0'
if f["lonMin"] == "":
f["lonMin"] = '0'
if f["lonSec"] == "":
f["lonSec"] = '0'
neg = 0
if f["latDeg"] < 0:
neg = 1
if neg != 1:
latSeconds = (
(f["latDeg"] * 3600) +
(f["latMin"] * 60) +
(f["latSec"] * 1)
)
f["latDeg"] = math.floor(latSeconds / 3600)
f["latMin"] = math.floor((latSeconds - (f["latDeg"] * 3600)) / 60)
f["latSec"] = math.floor((latSeconds - (f["latDeg"] * 3600) - (f["latMin"] * 60)) + 0.5)
elif f["latDeg"] > -1:
latSeconds = (
(f["latDeg"] * 3600) -
(f["latMin"] * 60) -
(f["latSec"] * 1)
)
f["latDeg"] = 0
f["latMin"] = math.floor(-latSeconds / 60)
f["latSec"] = math.floor( (-latSeconds - (f["latMin"] * 60)) + 0.5)
else:
latSeconds = (
(f["latDeg"] * 3600) -
(f["latMin"] * 60) -
(f["latSec"] * 1)
)
f["latDeg"] = math.ceil(latSeconds / 3600)
f["latMin"] = math.floor((-latSeconds + (f["latDeg"] * 3600)) / 60)
f["latSec"] = math.floor((-latSeconds + (f["latDeg"] * 3600) - (f["latMin"] * 60)) + 0.5)
neg = 0
if f["lonDeg"] < 0:
neg = 1
if neg != 1:
lonSeconds = (
(f["lonDeg"] * 3600) +
(f["lonMin"] * 60) +
(f["lonSec"] * 1)
)
f["lonDeg"] = math.floor(lonSeconds / 3600)
f["lonMin"] = math.floor((lonSeconds - (f["lonDeg"] * 3600)) / 60)
f["lonSec"] = math.floor((lonSeconds - (f["lonDeg"] * 3600) - (f["lonMin"]) * 60) + 0.5)
elif f["lonDeg"] > -1:
lonSeconds = (
(f["lonDeg"] * 3600) -
(f["lonMin"] * 60) -
(f["lonSec"] * 1)
)
f["lonDeg"] = 0
f["lonMin"] = math.floor(-lonSeconds / 60)
f["lonSec"] = math.floor((-lonSeconds - (f["lonMin"] * 60)) + 0.5)
else:
lonSeconds = (
(f["lonDeg"] * 3600) -
(f["lonMin"] * 60) -
(f["lonSec"] * 1)
)
f["lonDeg"] = math.ceil(lonSeconds / 3600)
f["lonMin"] = math.floor((-lonSeconds + (f["lonDeg"] * 3600)) / 60)
f["lonSec"] = math.floor((-lonSeconds + (f["lonDeg"] * 3600) - (f["lonMin"] * 60)) + 0.5)
# Test for invalid lat/long input
if latSeconds > 323280:
print("You have entered an invalid latitude.\nSetting lat=89.8.")
f["latDeg"] = 89.8
f["latMin"] = 0
f["latSec"] = 0
if latSeconds < -323280:
print ("You have entered an invalid latitude.\n Setting lat= -89.8.")
f["latDeg"] = -89.8
f["latMin"] = 0
f["latSec"] = 0
if lonSeconds > 648000:
print ("You have entered an invalid longitude.\n Setting lon= 180.")
f["lonDeg"] = 180
f["lonMin"] = 0
f["lonSec"] = 0
if lonSeconds < -648000:
print("You have entered an invalid latitude.\n Setting lon= -180.")
f["lonDeg"] = -180
f["lonMin"] = 0
f["lonSec"] =0
def rad_to_deg(angle_rad):
return 180.0 * angle_rad / math.pi
def deg_to_rad(angle_deg):
return math.pi * angle_deg / 180.0
def calc_day_of_year(mn, dy, lpyr):
k = 2 if lpyr else 1
return math.floor((275 * mn) / 9) - k * math.floor((mn + 9) / 12) + dy -30
def calc_day_of_week(juld):
dow = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
]
return dow[int((juld + 1.5) % 7)]
def calc_jd(year, month, day):
if month <= 2:
year -= 1
month += 12
a = math.floor(year / 100)
b = 2 - a + math.floor(a / 4)
return math.floor(365.25 * (year + 4716)) + math.floor(30.6001 * (month + 1)) + day + b - 1524.5
def calc_time_julian_cent(jd):
return (jd - 2451545.0) / 36525.0
def calc_geom_mean_long_sun(t):
l0 = 280.46646 + t * (36000.76983 + 0.0003032 * t)
while l0 > 360.0:
l0 -= 360.0
while l0 < 0.0:
l0 += 360.0
return l0
def calc_geom_mean_anomaly_sun(t):
return 357.52911 + t * (35999.05029 - 0.0001537 * t)
def calc_eccentricity_earth_orbit(t):
return 0.016708634 - t * (0.000042037 + 0.0000001267 * t)
def calc_sun_eq_of_center(t):
m = calc_geom_mean_anomaly_sun(t)
mrad = deg_to_rad(m)
sinm = math.sin(mrad)
sin2m = math.sin(mrad + mrad)
sin3m = math.sin(mrad + mrad + mrad)
return sinm * (1.914602 - t * (0.004817 + 0.000014 * t)) + sin2m * (0.019993 - 0.000101 * t) + sin3m * 0.000289
def calc_sun_true_long(t):
l0 = calc_geom_mean_long_sun(t)
c = calc_sun_eq_of_center(t)
return l0 + c
def calc_sun_true_anomaly(t):
m = calc_geom_mean_anomaly_sun(t)
c = calc_sun_eq_of_center(t)
return m + c
def calc_sun_rad_vector(t):
v = calc_sun_true_anomaly(t)
e = calc_eccentricity_earth_orbit(t)
return (1.000001018 * (1 - e * e)) / (1 + e * math.cos(deg_to_rad(v)))
def calc_sun_apparent_long(t):
o = calc_sun_true_long(t)
omega = 125.04 - 1934.136 * t
lbda = o - 0.00569 - 0.00478 * math.sin(deg_to_rad(omega))
return lbda
def calc_mean_obliquity_of_ecliptic(t):
seconds = 21.448 - t * (46.8150 + t * (0.00059 - t * 0.001813))
e0 = 23.0 + (26.0 + (seconds/60.0)) / 60.0
return e0
def calc_obliquity_correction(t):
e0 = calc_mean_obliquity_of_ecliptic(t)
omega = 125.04 - 1934.136 * t
e = e0 + 0.00256 * math.cos(deg_to_rad(omega))
return e
def calc_sun_right_ascension(t):
e = calc_obliquity_correction(t)
lbda = calc_sun_apparent_long(t)
tananum = (math.cos(deg_to_rad(e)) * math.sin(deg_to_rad(lbda)))
tanadenom = (math.cos(deg_to_rad(lbda)))
alpha = rad_to_deg(math.atan2(tananum, tanadenom))
return alpha
def calc_sun_declination(t):
e = calc_obliquity_correction(t)
lbda = calc_sun_apparent_long(t)
sint = math.sin(deg_to_rad(e)) * math.sin(deg_to_rad(lbda))
theta = rad_to_deg(math.asin(sint))
return theta
def calc_equation_of_time(t):
epsilon = calc_obliquity_correction(t)
l0 = calc_geom_mean_long_sun(t)
e = calc_eccentricity_earth_orbit(t)
m = calc_geom_mean_anomaly_sun(t)
y = math.tan(deg_to_rad(epsilon) / 2.0)
y *= y
sin2l0 = math.sin(2.0 * deg_to_rad(l0))
sinm = math.sin(deg_to_rad(m))
cos2l0 = math.cos(2.0 * deg_to_rad(l0))
sin4l0 = math.sin(4.0 * deg_to_rad(l0))
sin2m = math.sin(2.0 * deg_to_rad(m))
e_time = y * sin2l0 - 2.0 * e * sinm + 4.0 * e * y * sinm * cos2l0 - 0.5 * y * y * sin4l0 - 1.25 * e * e * sin2m
return rad_to_deg(e_time) * 4.0
def calc_hour_angle(tme, longitude, eqtime):
return 15.0 * (tme - (longitude / 15.0) - (eqtime / 60.0))
def get_latitude(lat_long_form):
neg = 0
degs = lat_long_form["latDeg"]
if lat_long_form["latDeg"] < 0:
neg = 1
mins = lat_long_form["latMin"]
secs = lat_long_form["latSec"]
if neg != 1:
return degs + (mins / 60) + (secs / 3600)
elif neg == 1:
return degs - (mins / 60) - (secs / 3600)
else:
return -9999
def get_longitude(lat_long_form):
neg = 0
degs = lat_long_form["lonDeg"]
if lat_long_form["lonDeg"] < 0:
neg = 1
mins = lat_long_form["lonMin"]
secs = lat_long_form["lonSec"]
if neg != 1:
return degs + (mins / 60) + (secs / 3600)
elif neg == 1:
return degs - (mins / 60) - (secs / 3600)
else:
return -9999
def calc_sun(rise_set_form, lat_long_form, index, index2):
if index2 != 0:
set_lat_long(lat_long_form, index2)
latitude = get_latitude(lat_long_form)
longitude = get_longitude(lat_long_form)
for indexRS, m in enumerate(monthList):
if m.name == rise_set_form['mos']:
break
else:
raise RuntimeError
if is_valid_input(rise_set_form, indexRS, lat_long_form):
if -89.8 > latitude >= -90:
print("All latitudes between 89.8 and 90 S\n will be set to -89.8.")
lat_long_form["latDeg"] = -89.8
latitude = -89.8
if 89.8 < latitude <= 90:
print("All latitudes between 89.8 and 90 N\n will be set to 89.8.")
lat_long_form["latDeg"] = 89.8
latitude = 89.8
zone = lat_long_form["hrsToGMT"]
daySavings = yesno[index].value # = 0 (no) or 60 (yes)
ss = rise_set_form["secs"]
mm = rise_set_form["mins"]
hh = rise_set_form["hour"] - (daySavings / 60)
while hh > 23:
hh -= 24
rise_set_form["hour"] = hh + (daySavings / 60)
if mm > 9:
rise_set_form["mins"] = mm
else:
rise_set_form["mins"] = mm
if ss > 9:
rise_set_form["secs"] = ss
else:
rise_set_form["secs"] = ss
timenow = hh + mm / 60 + ss / 3600 + zone # in hours since 0Z
JD = calc_jd(rise_set_form["year"], indexRS + 1, rise_set_form["day"])
t = calc_time_julian_cent(JD + timenow / 24.0)
theta = calc_sun_declination(t)
E_time = calc_equation_of_time(t)
eq_time = E_time
solar_dec = theta
rise_set_form["eqTime"] = math.floor(100 * eq_time) / 100
rise_set_form["solarDec"] = math.floor(100 * solar_dec) / 100
solar_time_fix = eq_time - 4.0 * longitude + 60.0 * zone
true_solar_time = hh * 60.0 + mm + ss / 60.0 + solar_time_fix
while true_solar_time > 1440:
true_solar_time -= 1440
hour_angle = true_solar_time / 4.0 - 180.0
if hour_angle < -180:
hour_angle += 360.0
ha_rad = deg_to_rad(hour_angle)
csz = (
math.sin(deg_to_rad(latitude)) *
math.sin(deg_to_rad(solar_dec)) +
math.cos(deg_to_rad(latitude)) *
math.cos(deg_to_rad(solar_dec)) *
math.cos(ha_rad)
)
if csz > 1.0:
csz = 1.0
elif csz < -1.0:
csz = -1.0
zenith = rad_to_deg(math.acos(csz))
az_denom = (
math.cos(deg_to_rad(latitude)) *
math.sin(deg_to_rad(zenith))
)
if abs(az_denom) > 0.001:
az_rad = (
(
(math.sin(deg_to_rad(latitude)) * math.cos(deg_to_rad(zenith))) -
math.sin(deg_to_rad(solar_dec))
) / az_denom
)
if abs(az_rad) > 1.0:
if az_rad < 0:
az_rad = -1.0
else:
az_rad = 1.0
azimuth = 180.0 - rad_to_deg(math.acos(az_rad))
if hour_angle > 0.0:
azimuth = -azimuth
else:
if latitude > 0.0:
azimuth = 180.0
else:
azimuth = 0.0
if azimuth < 0.0:
azimuth += 360.0
exoatm_elevation = 90.0 - zenith
if exoatm_elevation > 85.0:
refraction_correction = 0.0
else:
te = math.tan(deg_to_rad(exoatm_elevation))
if exoatm_elevation > 5.0:
refraction_correction = 58.1 / te - 0.07 / (te * te * te) + 0.000086 / (te * te * te * te * te)
elif exoatm_elevation > -0.575:
refraction_correction = (
1735.0 + exoatm_elevation * -518.2 + exoatm_elevation *
(103.4 + exoatm_elevation * (-12.79 + exoatm_elevation * 0.711))
)
else:
refraction_correction = -20.774 / te
refraction_correction = refraction_correction / 3600.0
solarZen = zenith - refraction_correction
if solarZen < 108.0: # astronomical twilight
rise_set_form["azimuth"] = (math.floor(100 * azimuth)) / 100
rise_set_form["elevation"] = (math.floor(100 * (90.0 - solarZen))) / 100
if solarZen < 90.0:
rise_set_form["coszen"] = (math.floor(10000.0 * (math.cos(deg_to_rad(solarZen))))) / 10000.0
else:
rise_set_form["coszen"] = 0.0
else: # do not report az & el after astro twilight
rise_set_form["azimuth"] = "dark"
rise_set_form["elevation"] = "dark"
rise_set_form["coszen"] = 0.0
conv_lat_long(lat_long_form)
else:
rise_set_form["azimuth"] = "error"
rise_set_form["elevation"] = "error"
rise_set_form["eqTime"] = "error"
rise_set_form["solarDec"] = "error"
rise_set_form["coszen"] = "error"
def getdms(t):
d = abs(t)
n = math.floor(d)
m = 3600 * (d - n)
a = math.floor(m / 60)
m = round(1e4 * (m - 60 * a)) / 1e4
return n, a, m
form1 = {}
form1['latDeg'], form1['latMin'], form1['latSec'] = getdms(LATITUDE)
form1['lonDeg'], form1['lonMin'], form1['lonSec'] = getdms(LONGITUDE)
form1['hrsToGMT'] = UTC_OFFSET
import time
localtime = time.localtime(time.time())
form2 = {}
form2['hour'] = int(time.strftime('%H', localtime))
form2['mins'] = int(time.strftime('%M', localtime))
form2['secs'] = int(time.strftime('%S', localtime))
form2['mos'] = time.strftime('%B', localtime)
form2['day'] = int(time.strftime('%d', localtime))
form2['year'] = int(time.strftime('%Y', localtime))
form2['ampm'] = 24
dayAns = DAYLIGHT_SAVINGS
# Azimuth
calc_sun(form2, form1, int(DAYLIGHT_SAVINGS), 0)
response = requests.get(get_url(), params=dict(appid=RADAR_API_KEY))
stream = BytesIO(response.content)
# with open(r'C:\Users\Administrator\Desktop\New folder (126)\test.png', 'wb') as f:
# f.write(response.content)
image = Image.open(stream).convert('RGBA')
image_data = image.getdata(3)
stream.close()
image.close()
cloud_density = ((RADAR_CLOUD_DENSITY * 102) / 100) + 153
cloud_cover = list(i for i in image_data if i >= cloud_density)
percent_covered = (float(len(cloud_cover)) / float(len(image_data))) * 100.0
print(time.strftime('%c', localtime))
print()
print('Latitude:', form1['latDeg'], 'degrees', form1['latMin'], 'minutes', form1['latSec'], 'seconds')
print('Longitude:', form1['lonDeg'], 'degrees', form1['lonMin'], 'minutes', form1['lonSec'], 'seconds')
print()
print('Cloud Cover Percentage:', '{0:.2f}%'.format(percent_covered))
print()
print('Equation of time (minutes):', form2['eqTime'])
print('Solar Declination (degrees):', form2['solarDec'])
print('Solar Azimuth:', form2['azimuth'])
print('Solar Elevation:', form2['elevation'])
print('Cosine of solar zenith angle:', form2['coszen'])
this is only for testing purposes at the moment. It is not going to trigger any events, it is only going to print out the data to the log.
I do not know what your requirements are for solar elevation, declination and azimuth to know when to turn on the second lamp. once I have those from you we can add that to the script for the projector.
I can set the scrip up so that it runs as a thread and grabs the state of the projector and if the projector is on it will automatically adjust the bulb as needed.