implement crude daylight summation
This commit is contained in:
parent
db665ab43e
commit
8865acc8f0
1 changed files with 59 additions and 15 deletions
74
torus.py
74
torus.py
|
|
@ -120,6 +120,12 @@ class Image():
|
||||||
|
|
||||||
plt.savefig(path, dpi=dpi)
|
plt.savefig(path, dpi=dpi)
|
||||||
|
|
||||||
|
def run(self, path=None, **kwargs):
|
||||||
|
if path:
|
||||||
|
self.save(path, **kwargs)
|
||||||
|
else:
|
||||||
|
plt.show()
|
||||||
|
|
||||||
def update_illumination(self):
|
def update_illumination(self):
|
||||||
# TODO: refactor TorusWorld.illumination() do use vectoization!!
|
# TODO: refactor TorusWorld.illumination() do use vectoization!!
|
||||||
phi = np.linspace(-np.pi, np.pi, self.res)
|
phi = np.linspace(-np.pi, np.pi, self.res)
|
||||||
|
|
@ -316,6 +322,44 @@ class Image():
|
||||||
self.fig.canvas.draw_idle()
|
self.fig.canvas.draw_idle()
|
||||||
|
|
||||||
|
|
||||||
|
class SummedImage(Image):
|
||||||
|
|
||||||
|
def update_illumination(self):
|
||||||
|
# TODO: refactor TorusWorld.illumination() do use vectoization!!
|
||||||
|
phi = np.linspace(-np.pi, np.pi, self.res)
|
||||||
|
theta = np.linspace(-np.pi, np.pi, self.res)
|
||||||
|
day_cycle = np.linspace(-np.pi, np.pi, 24)
|
||||||
|
self.torus.put_sun(day_cycle[0], 0)
|
||||||
|
illumination = np.array([[self.torus.illumination(ph, th) for th in theta] for ph in phi])
|
||||||
|
for sun_pos in day_cycle[1:]:
|
||||||
|
self.torus.put_sun(sun_pos, 0)
|
||||||
|
illumination += np.array([[self.torus.illumination(ph, th) for th in theta] for ph in phi])
|
||||||
|
self.illumination = illumination / np.amax(illumination)
|
||||||
|
|
||||||
|
def init_map_view(self):
|
||||||
|
self.lines['map_border'], = self.ax.plot(*self._mantle_map(), 'k')
|
||||||
|
# self.lines['pos_map'], = self.ax.plot(*self._sunpos_map(), marker='o', color='r', markersize=10,)
|
||||||
|
self.lines['dawnline_map'] = [
|
||||||
|
self.ax.contourf(*self._contour_map(), self.levels, **self.contour_kwargs),
|
||||||
|
]
|
||||||
|
|
||||||
|
def init_top_view(self):
|
||||||
|
self.lines['circles_top'], = self.ax.plot(*self._top_section(), 'k')
|
||||||
|
self.lines['path_top'], = self.ax.plot(*self._sunpath_top(), 'c:')
|
||||||
|
# self.lines['pos_top'], = self.ax.plot(*self._sunpos_top(), **self.sun_kwargs)
|
||||||
|
self.lines['dawnline_top'] = [
|
||||||
|
self.ax.contourf(*self._contour_top(), self.levels, **self.contour_kwargs),
|
||||||
|
]
|
||||||
|
|
||||||
|
def init_side_view(self):
|
||||||
|
self.lines['circles_side'], = self.ax.plot(*self._crossection(), 'k')
|
||||||
|
self.lines['path_side'], = self.ax.plot(*self._sunpath_side(), 'c:')
|
||||||
|
# self.lines['pos_side'], = self.ax.plot(*self._sunpos_side(), **self.sun_kwargs)
|
||||||
|
self.lines['dawnline_side'] = [
|
||||||
|
self.ax.contourf(*self._contour_side(), self.levels, **self.contour_kwargs),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class InteractiveImage(Image):
|
class InteractiveImage(Image):
|
||||||
|
|
||||||
def __init__(self, rfrac_init=0.5, sun_init=np.pi/2):
|
def __init__(self, rfrac_init=0.5, sun_init=np.pi/2):
|
||||||
|
|
@ -342,13 +386,12 @@ class InteractiveImage(Image):
|
||||||
valmax=1,
|
valmax=1,
|
||||||
valinit=rfrac_init,
|
valinit=rfrac_init,
|
||||||
orientation="vertical"
|
orientation="vertical"
|
||||||
),
|
),
|
||||||
button_reset=Button(ax3, 'Reset', hovercolor='0.975'),
|
button_reset=Button(ax3, 'Reset', hovercolor='0.975'),
|
||||||
)
|
)
|
||||||
self.interactions['slider_sun'].on_changed(self._slider_update_sun)
|
self.interactions['slider_sun'].on_changed(self._slider_update_sun)
|
||||||
self.interactions['slider_rfrac'].on_changed(self._slider_update_torus)
|
self.interactions['slider_rfrac'].on_changed(self._slider_update_torus)
|
||||||
self.interactions['button_reset'].on_clicked(self._reset)
|
self.interactions['button_reset'].on_clicked(self._reset)
|
||||||
|
|
||||||
|
|
||||||
def _slider_update_torus(self, val):
|
def _slider_update_torus(self, val):
|
||||||
self.update_torus(val)
|
self.update_torus(val)
|
||||||
|
|
@ -393,24 +436,16 @@ if __name__ == '__main__':
|
||||||
def parse_args():
|
def parse_args():
|
||||||
|
|
||||||
def create_static(args):
|
def create_static(args):
|
||||||
img = Image(args.r_minor, args.sun)
|
Image(args.r_minor, args.sun).run(args.output)
|
||||||
|
|
||||||
if args.output:
|
|
||||||
img.save(args.output)
|
|
||||||
else:
|
|
||||||
plt.show()
|
|
||||||
|
|
||||||
def create_interactive(args):
|
def create_interactive(args):
|
||||||
InteractiveImage(args.r_minor, args.sun)
|
InteractiveImage(args.r_minor, args.sun).run()
|
||||||
plt.show()
|
|
||||||
|
|
||||||
def create_animation(args):
|
def create_animation(args):
|
||||||
img = AnimatedImage(args.r_minor, args.sun, args.runtime, args.fps)
|
AnimatedImage(args.r_minor, args.sun, args.runtime, args.fps).run()
|
||||||
|
|
||||||
if args.output:
|
def create_summed(args):
|
||||||
img.save(args.output)
|
SummedImage(args.r_minor).run()
|
||||||
else:
|
|
||||||
plt.show()
|
|
||||||
|
|
||||||
class Range(object):
|
class Range(object):
|
||||||
def __init__(self, start, end):
|
def __init__(self, start, end):
|
||||||
|
|
@ -434,6 +469,7 @@ if __name__ == '__main__':
|
||||||
p_static = sp.add_parser('static', aliases=['s'], help='create a static image')
|
p_static = sp.add_parser('static', aliases=['s'], help='create a static image')
|
||||||
p_interactive = sp.add_parser('interactive', aliases=['i'], help='create an interactive image')
|
p_interactive = sp.add_parser('interactive', aliases=['i'], help='create an interactive image')
|
||||||
p_animated = sp.add_parser('animated', aliases=['a'], help='create a animated image')
|
p_animated = sp.add_parser('animated', aliases=['a'], help='create a animated image')
|
||||||
|
p_summed = sp.add_parser('daylight', aliases=['d'], help='sum up a day\'s light average')
|
||||||
|
|
||||||
p_static.add_argument('r_minor', help='Ratio of minor radius to major radius',
|
p_static.add_argument('r_minor', help='Ratio of minor radius to major radius',
|
||||||
nargs='?', type=float, choices=Range(0., 1.), metavar='RMIN', default=0.5)
|
nargs='?', type=float, choices=Range(0., 1.), metavar='RMIN', default=0.5)
|
||||||
|
|
@ -459,6 +495,14 @@ if __name__ == '__main__':
|
||||||
p_animated.add_argument('--runtime', '-r', help='runtime of animation', metavar='SEC', type=int, default=5)
|
p_animated.add_argument('--runtime', '-r', help='runtime of animation', metavar='SEC', type=int, default=5)
|
||||||
p_animated.set_defaults(func=create_animation)
|
p_animated.set_defaults(func=create_animation)
|
||||||
|
|
||||||
|
p_summed.add_argument('r_minor', help='Ratio of minor radius to major radius',
|
||||||
|
nargs='?', type=float, choices=Range(0., 1.), metavar='RMIN', default=0.5)
|
||||||
|
p_summed.add_argument('--output', '-o', help='output to a file instead of displaying directly',
|
||||||
|
metavar='FILE')
|
||||||
|
p_summed.add_argument('--hours', '-H', action='store_true',
|
||||||
|
help='sum up hours of daylight instead of intensity')
|
||||||
|
p_summed.set_defaults(func=create_summed)
|
||||||
|
|
||||||
return (p.parse_args())
|
return (p.parse_args())
|
||||||
|
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue