In [1]:
# Configure Jupyter so figures appear in the notebook
%matplotlib inline
# Configure Jupyter to display the assigned value after an assignment
%config InteractiveShell.ast_node_interactivity='last_expr_or_assign'
# import functions from the modsim library
from modsim import *
https://www.youtube.com/watch?v=frix_zTkPEs
If the following import fails, open a terminal and run
conda install -c conda-forge pysolar
In [2]:
from pysolar.solar import *
In [3]:
from datetime import datetime, timedelta
In [4]:
dt = datetime.now()
Out[4]:
In [5]:
from pytz import timezone
dt = pytz.timezone('EST').localize(dt)
Out[5]:
In [6]:
get_altitude(42.2931671, -71.263665, dt)
Out[6]:
In [7]:
latitude_deg = 42.3
longitude_deg = -71.3
altitude_deg = get_altitude(latitude_deg, longitude_deg, dt)
azimuth_deg = get_azimuth(latitude_deg, longitude_deg, dt)
radiation.get_radiation_direct(dt, altitude_deg)
# result is in Watts per square meter
Out[7]:
In [8]:
location = State(lat_deg=42.3, lon_deg=-71.3)
Out[8]:
In [9]:
dt = datetime(year=2017, month=9, day=15, hour=12, minute=30)
dt = pytz.timezone('EST').localize(dt)
Out[9]:
In [10]:
def compute_irradiance(location, dt):
degree = UNITS.degree
watt = UNITS.watt
meter = UNITS.meter
sun = State(
altitude_deg = get_altitude(location.lat_deg, location.lon_deg, dt),
azimuth_deg = get_azimuth(location.lat_deg, location.lon_deg, dt)
)
if sun.altitude_deg <= 0:
irradiance = 0
else:
irradiance = radiation.get_radiation_direct(dt, sun.altitude_deg)
sun.set(irradiance = irradiance * watt / meter**2)
return sun
In [11]:
sun = compute_irradiance(location, dt)
Out[11]:
In [12]:
dt = datetime(year=2017, month=9, day=15)
dt = pytz.timezone('EST').localize(dt)
delta_t = timedelta(minutes=15)
result = TimeSeries()
for i in range(24 * 4):
dt += delta_t
sun = compute_irradiance(location, dt)
result[dt] = sun.irradiance.magnitude
result
Out[12]:
In [13]:
result.plot()
Out[13]:
In [14]:
cm = UNITS.centimeter
meter = UNITS.meter
watt = UNITS.watt
second = UNITS.second
joule = UNITS.joule
Out[14]:
In [15]:
width = 45 * cm
Out[15]:
In [16]:
area = width**2
Out[16]:
In [17]:
power = sun.irradiance * area
Out[17]:
In [18]:
area = area.to(meter**2)
Out[18]:
In [19]:
power = sun.irradiance * area
Out[19]:
In [20]:
delta_t = 1 * second
energy = power * delta_t
Out[20]:
In [21]:
energy.to(joule)
Out[21]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: