CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
AllenDowney

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: AllenDowney/ModSimPy
Path: blob/master/notebooks/examples/bigbelly.ipynb
Views: 531
Kernel: Python 3

Modeling and Simulation in Python

Copyright 2017 Allen Downey

License: Creative Commons Attribution 4.0 International

# 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 *

Bigbelly

https://www.youtube.com/watch?v=frix_zTkPEs

If the following import fails, open a terminal and run

conda install -c conda-forge pysolar

from pysolar.solar import *

from datetime import datetime, timedelta

dt = datetime.now()
datetime.datetime(2018, 10, 29, 14, 13, 30, 886072)
from pytz import timezone dt = pytz.timezone('EST').localize(dt)
datetime.datetime(2018, 10, 29, 14, 13, 30, 886072, tzinfo=<StaticTzInfo 'EST'>)

get_altitude(42.2931671, -71.263665, dt)
22.52017419635824

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
781.1690621573555

location = State(lat_deg=42.3, lon_deg=-71.3)

dt = datetime(year=2017, month=9, day=15, hour=12, minute=30) dt = pytz.timezone('EST').localize(dt)
datetime.datetime(2017, 9, 15, 12, 30, tzinfo=<StaticTzInfo 'EST'>)

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

sun = compute_irradiance(location, dt)

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

result.plot()
<matplotlib.axes._subplots.AxesSubplot at 0x7fc5239869b0>
Image in a Jupyter notebook
cm = UNITS.centimeter meter = UNITS.meter watt = UNITS.watt second = UNITS.second joule = UNITS.joule

width = 45 * cm

area = width**2

power = sun.irradiance * area

area = area.to(meter**2)

power = sun.irradiance * area

delta_t = 1 * second energy = power * delta_t

energy.to(joule)