diff --git a/torus.py b/torus.py index 51bd63e..e951da2 100644 --- a/torus.py +++ b/torus.py @@ -120,6 +120,12 @@ class Image(): plt.savefig(path, dpi=dpi) + def run(self, path=None, **kwargs): + if path: + self.save(path, **kwargs) + else: + plt.show() + def update_illumination(self): # TODO: refactor TorusWorld.illumination() do use vectoization!! phi = np.linspace(-np.pi, np.pi, self.res) @@ -316,6 +322,44 @@ class Image(): 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): def __init__(self, rfrac_init=0.5, sun_init=np.pi/2): @@ -392,24 +436,16 @@ if __name__ == '__main__': def parse_args(): def create_static(args): - img = Image(args.r_minor, args.sun) - - if args.output: - img.save(args.output) - else: - plt.show() + Image(args.r_minor, args.sun).run(args.output) def create_interactive(args): - InteractiveImage(args.r_minor, args.sun) - plt.show() + InteractiveImage(args.r_minor, args.sun).run() 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: - img.save(args.output) - else: - plt.show() + def create_summed(args): + SummedImage(args.r_minor).run() class Range(object): def __init__(self, start, end): @@ -433,6 +469,7 @@ if __name__ == '__main__': 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_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', nargs='?', type=float, choices=Range(0., 1.), metavar='RMIN', default=0.5) @@ -458,6 +495,14 @@ if __name__ == '__main__': p_animated.add_argument('--runtime', '-r', help='runtime of animation', metavar='SEC', type=int, default=5) 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()) args = parse_args()