def setUp(self) -> None: self.moons = [ Moon(-1, 0, 2), Moon(2, -10, -7), Moon(4, -8, 8), Moon(3, 5, -1), ]
def load_level2(app): '''(App) -> NoneType ...''' BLUE = (0, 0, 255) MOON1_ORBIT, MOON1_RADIUS = 1, 15 MOON2_ORBIT, MOON2_RADIUS = 3, 20 ASTEROID1_STARTX, ASTEROID1_STARTY, ASTEROID1_RADIUS = 100, 0, 12 ASTEROID2_STARTX, ASTEROID2_STARTY, ASTEROID2_RADIUS = 780, 800, 12 ASTEROID3_STARTX, ASTEROID3_STARTY, ASTEROID3_RADIUS = 780, 400, 12 PLANET_RADIUS = 50 app.num_orbits = 3 app.planet = Planet(BLUE, app.level_center, PLANET_RADIUS) app.moons.append(Moon(MOON1_ORBIT, MOON1_RADIUS)) app.moons.append(Moon(MOON2_ORBIT, MOON2_RADIUS)) app.asteroids.append( Asteroid(ASTEROID1_STARTX, ASTEROID1_STARTY, ASTEROID1_RADIUS)) app.asteroids.append( Asteroid(ASTEROID2_STARTX, ASTEROID2_STARTY, ASTEROID2_RADIUS)) app.asteroids.append( Asteroid(ASTEROID3_STARTX, ASTEROID3_STARTY, ASTEROID3_RADIUS)) app.asteroids_ingame = app.asteroids.copy()
class MoonDayWidget(Gtk.EventBox): def __init__(self, adate=None): Gtk.EventBox.__init__(self) self.set_size_request(100, 70) box1 = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0) self.add(box1) self.label = Gtk.Label() box1.pack_start(self.label, True, True, padding=1) self.image = Gtk.Image() box1.pack_start(self.image, True, True, padding=1) if adate is not None: self.set_date(adate) self.image.show() def set_date(self, adate): self.adate = adate self.label.set_text(str(adate.day)) self.moon = Moon(adate) phasename = self.moon.phase() i = adate.day roundedpos = round(float(self.moon.position()), 3) self.image.set_from_pixbuf( GdkPixbuf.Pixbuf.new_from_file_at_size( os.path.join( comun.IMAGESDIR, self.moon.image()), 60, 60)) def get_date(self): return self.adate def get_position(self): return self.moon.position() def get_phase(self): return self.moon.phase_int()
def set_date(self, adate): self.adate = adate self.label.set_text(str(adate.day)) self.moon = Moon(adate) self.image.set_from_pixbuf( GdkPixbuf.Pixbuf.new_from_file_at_size( os.path.join(comun.IMAGESDIR, self.moon.image()), 60, 60))
def __init__(self, infile_coords='GWsky_coords'): """Creating a class in which the instance attributes are based on the dictionary "GWsky_coords" by default. GWsky_coords is created and pickled by the "user_values" module and will be deleted when the "ShowSkyCoverageGUI" will be closed. It contains the keys: "ra", "dec". ra and dec represents the central location of a FoV. Starting sky coordinates: self.input_ra: right ascension [deg] self.input_dec: declination [deg] """ self.infile_coords = infile_coords self.entries_GWsky_new = [] # new entries during the FoV sequence self.user = UserValues() # compositions self.lvc = LVCskymap() self.query = Query() self.airmass = Airmass() self.moon = Moon() with open(infile_coords, 'rb') as data: coords_GWsky = pickle.load(data) for k, v in coords_GWsky.items(): setattr(self, k, v)
def test_phobos_rise_before_deimos_phobos_set_after_deimos(self): """ Phobos |---------| Deimos |---| Overlap |---| """ phobos, deimos = Moon(1, 0, 4, 0, 'Phobos'), Moon(2, 0, 3, 0, 'Deimos') self.assertEqual(phobos.calculate_overlap_time(deimos), 100)
def test_part_1(self): moons = [ Moon(-9, 10, -1), Moon(-14, -8, 14), Moon(1, 5, 6), Moon(-19, 7, 8), ] self.assertEqual(main_part_1(moons), 8538)
def test_get_cycle_times(self): moons = [ Moon(-9, 10, -1), Moon(-14, -8, 14), Moon(1, 5, 6), Moon(-19, 7, 8), ] self.assertEqual(get_cycle_times(moons), [161428, 231614, 108344])
def test_phobos_rise_and_set_before_deimos(self): """ Phobos |---------| Deimos |---------| Overlap X """ phobos, deimos = Moon(1, 0, 2, 0, 'Phobos'), Moon(3, 0, 4, 0, 'Deimos') self.assertEqual(phobos.calculate_overlap_time(deimos), 0)
def test_main_1(self): moons = [ Moon(-8, -10, 0), Moon(5, 5, 10), Moon(2, -7, 3), Moon(9, -8, -3), ] post_run_moons = run_time(moons, 100) self.assertEqual(total_energy(post_run_moons), 1940)
def test_deimos_set_at_same_time_as_phobos_rise(self): """ Phobos |----| Deimos |----| Overlap | """ phobos, deimos = Moon(11, 0, 12, 0, 'Phobos'), Moon(12, 0, 13, 0, 'Deimos') self.assertEqual(phobos.calculate_overlap_time(deimos), 1)
def set_date(self, adate): self.adate = adate self.label.set_text(str(adate.day)) self.moon = Moon(adate) # phasename = self.moon.phase() # i = adate.day # roundedpos = round(float(self.moon.position()), 3) self.image.set_from_pixbuf( GdkPixbuf.Pixbuf.new_from_file_at_size( os.path.join(comun.IMAGESDIR, self.moon.image()), 60, 60))
def test_deimos_set_at_same_time_as_phobos_rise_midnight(self): """ Zero | Phobos |----| Deimos |----| Overlap | """ phobos, deimos = Moon(24, 0, 0, 0, 'Phobos'), Moon(0, 0, 1, 0, 'Deimos') self.assertEqual(phobos.calculate_overlap_time(deimos), 1)
def test_deimos_and_phobos_overlap_two_times(self): """ Zero | Phobos ------| |------- Deimos |-----------| Overlap |--| + |--| """ phobos, deimos = Moon(15, 0, 7, 0, 'Phobos'), Moon(4, 0, 16, 0, 'Deimos') self.assertEqual(phobos.calculate_overlap_time(deimos), 400)
def test_phobos_rise_after_deimos_deimos_set_after_phobos_deimos_and_phobos_set_after_midnight( self): """ Zero | Phobos |----| Deimos |---------| Overlap |----| """ phobos, deimos = Moon(22, 0, 2, 0, 'Phobos'), Moon(23, 0, 1, 0, 'Deimos') self.assertEqual(phobos.calculate_overlap_time(deimos), 300)
class Sky: def __init__(self): self.mMoon = Moon() return def draw(self, surface): color = (0, 0, 0) rectangle = pygame.Rect(0, 0, 600, 500) # x and y pygame.draw.rect(surface, color, rectangle, 0) # 0 = width of border self.mMoon.draw(surface) return
def send_command(): phobos = Moon(int(input_phobos_rise_hour.get()), int(input_phobos_rise_minute.get()), int(input_phobos_set_hour.get()), int(input_phobos_set_minute.get()), 'Phobos') deimos = Moon(int(input_deimos_rise_hour.get()), int(input_deimos_rise_minute.get()), int(input_deimos_set_hour.get()), int(input_deimos_set_minute.get()), 'Deimos') overlap = phobos.calculate_overlap_time(deimos) return_label.config(text="Overlaping time: " + str(overlap) + " min")
def testSatellite(self): distance: float = 17 orbits: str = "Mars" satellite: Moon = Moon(distance, orbits, 3, "black") self.assertEqual(satellite.distance, distance) self.assertEqual(satellite.orbits, orbits)
def __init__(self, infile_coords='GWsky_coords'): """Creating a class in which the instance attributes are based on the dictionary "GWsky_coords" by default. GWsky_coords is created and pickled by the "user_values" module and will be deleted when the "ShowSkyCoverageGUI" will be closed. It contains the keys: "ra", "dec". ra and dec represents the central location of a FoV. Starting sky coordinates: self.input_ra: right ascension [deg] self.input_dec: declination [deg] """ self.infile_coords = infile_coords self.entries_GWsky_new =[] # new entries during the FoV sequence self.user = UserValues() # compositions self.lvc = LVCskymap() self.query = Query() self.airmass = Airmass() self.moon = Moon() with open(infile_coords, 'rb') as data: coords_GWsky = pickle.load(data) for k, v in coords_GWsky.items(): setattr(self, k, v)
def main(): pygame.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) #,RESIZABLE) pygame.display.set_caption("Alien Invasion") play_button = Button(ai_settings, screen, "Play") stats = GameStats(ai_settings) sb = Scoreboard(ai_settings, screen, stats) ship = Ship(ai_settings, screen) moon = Moon(ai_settings, screen) earth = Earth(ai_settings, screen) stars = Group() bullets = Group() aliens = Group() gf.create_fleet(ai_settings, screen, ship, aliens) gf.create_multilayer_star(ai_settings, screen, stars) while True: gf.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets) if stats.game_active: ship.update() gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets) gf.update_aliens(ai_settings, stats, sb, screen, ship, aliens, bullets) stats.update_highscore() gf.update_screen(ai_settings, screen, stats, stars, sb, [moon, earth], [ship], play_button, aliens, bullets)
def testDefaultMoon(self): size : int = 3 color : str = "blue" phase : int = 0 moon : Moon = Moon(size, color, phase) self.assertEqual(moon.phase,phase) self.assertEqual(moon.color,color) self.assertEqual(moon.size,size)
def load_planets(self): self.orbit_root_mercury = render.attachNewNode('orbit_root_mercury') self.orbit_root_venus = render.attachNewNode('orbit_root_venus') self.orbit_root_mars = render.attachNewNode('orbit_root_mars') self.orbit_root_earth = render.attachNewNode('orbit_root_earth') self.orbit_root_moon = ( self.orbit_root_earth.attachNewNode('orbit_root_moon')) self.sky = loader.loadModel("models/sky_dome.blend") self.sky_tex = loader.loadTexture("models/sky_tex2_cut.jpg") self.sky_tex.setWrapU(Texture.WM_clamp) self.sky.setTexture(self.sky_tex, 1) self.sky.reparentTo(render) self.sky.setScale(300) self.sky.setHpr(270, 0, 0) self.Sun = Star(self, 'Sun', 'models/planet_sphere', 'models/sun_1k_tex.jpg', 2) self.Mercury = Planet(self, 'Mercury', 'models/planet_sphere', 'models/mercury_1k_tex.jpg', self.orbit_root_mercury, 0.385, 0.38, False, 1, { 'Coal': 'Common', 'Iron': 'Common' }) self.Venus = Planet(self, 'Venus', 'models/planet_sphere', 'models/venus_1k_tex.jpg', self.orbit_root_venus, 0.923, 0.72, False, 2, { 'Coal': 'Common', 'Uranium': 'Normal' }) self.Mars = Planet(self, 'Mars', 'models/planet_sphere', 'models/mars_1k_tex.jpg', self.orbit_root_mars, 0.512, 1.52, False, 1, { 'Gemstone': 'Rare', 'Iron': 'Rare' }) self.Mars.probed = True self.Earth = Planet(self, 'Earth', 'models/planet_sphere', 'models/earth_1k_tex.jpg', self.orbit_root_earth, 1, 1, True, 1, { 'Iron': 'Normal', 'Coal': 'Common' }) self.orbit_root_moon.setPos(self.orbitscale, 0, 0) self.Earth_Moon = Moon(self, 'Moon', 'models/planet_sphere', 'models/moon_1k_tex.jpg', self.orbit_root_moon, 0.1, 0.1, False, 0, { 'Cheese': 'Rare', 'Coal': 'Common' })
def testDefaultMoon(self): distance: float = 17 orbits: str = "Mars" size: int = 3 color: str = "blue" phase: int = 0 moon: Moon = Moon(distance, orbits, size, color, phase) self.assertEqual(moon.phase, phase) self.assertEqual(moon.color, color) self.assertEqual(moon.size, size)
def __init__(self, datas): self.__moons = [] r = r"^<x=(?P<x>-?\d+), y=(?P<y>-?\d+), z=(?P<z>-?\d+)>$" for data in datas: match = re.match(r, data) self.__moons.append( Moon(int(match.group("x")), int(match.group("y")), int(match.group("z"))))
def test(): moons = [ Moon(p) for p in ((-1, 0, 2), (2, -10, -7), (4, -8, 8), (3, 5, -1)) ] simulate(moons, 10) assert sum([moon.energy()[2] for moon in moons]) == 179 vpos, vvel = ([2, 1, -3], [1, -8, 0], [3, -6, 1], [2, 0, 4]), ([-3, -2, 1], [-1, 1, 3], [3, 2, -3], [1, -1, -1]) for i in range(4): assert vpos[i] == moons[i].pos and vvel[i] == moons[i].vel moons = [ Moon(p) for p in ((-8, -10, 0), (5, 5, 10), (2, -7, 3), (9, -8, -3)) ] simulate(moons, 100) assert sum([moon.energy()[2] for moon in moons]) == 1940 assert part2(((-1, 0, 2), (2, -10, -7), (4, -8, 8), (3, 5, -1))) == 2772 assert part2( ((-8, -10, 0), (5, 5, 10), (2, -7, 3), (9, -8, -3))) == 4686774924
def load_level3(app): '''(App) -> NoneType ...''' GREEN = (0, 255, 0) MOON1_ORBIT, MOON1_RADIUS = 1, 20 MOON2_ORBIT, MOON2_RADIUS = 2, 10 MOON3_ORBIT, MOON3_RADIUS = 3, 15 MOON4_ORBIT, MOON4_RADIUS = 5, 15 ASTEROID1_STARTX, ASTEROID1_STARTY, ASTEROID1_RADIUS = 100, 100, 12 ASTEROID2_STARTX, ASTEROID2_STARTY, ASTEROID2_RADIUS = 680, 800, 12 ASTEROID3_STARTX, ASTEROID3_STARTY, ASTEROID3_RADIUS = 780, 400, 12 ASTEROID4_STARTX, ASTEROID4_STARTY, ASTEROID4_RADIUS = 400, 50, 12 ASTEROID5_STARTX, ASTEROID5_STARTY, ASTEROID5_RADIUS = 0, 400, 12 ASTEROID6_STARTX, ASTEROID6_STARTY, ASTEROID6_RADIUS = 780, 0, 12 PLANET_RADIUS = 50 app.num_orbits = 5 app.planet = Planet(GREEN, app.level_center, PLANET_RADIUS) app.moons.append(Moon(MOON1_ORBIT, MOON1_RADIUS)) app.moons.append(Moon(MOON2_ORBIT, MOON2_RADIUS)) app.moons.append(Moon(MOON3_ORBIT, MOON3_RADIUS)) app.moons.append(Moon(MOON4_ORBIT, MOON4_RADIUS)) app.asteroids.append( Asteroid(ASTEROID1_STARTX, ASTEROID1_STARTY, ASTEROID1_RADIUS)) app.asteroids.append( Asteroid(ASTEROID2_STARTX, ASTEROID2_STARTY, ASTEROID2_RADIUS)) app.asteroids.append( Asteroid(ASTEROID3_STARTX, ASTEROID3_STARTY, ASTEROID3_RADIUS)) app.asteroids.append( Asteroid(ASTEROID4_STARTX, ASTEROID4_STARTY, ASTEROID4_RADIUS)) app.asteroids.append( Asteroid(ASTEROID5_STARTX, ASTEROID5_STARTY, ASTEROID5_RADIUS)) app.asteroids.append( Asteroid(ASTEROID6_STARTX, ASTEROID6_STARTY, ASTEROID6_RADIUS)) app.asteroids_ingame = app.asteroids.copy()
def set_date(self, adate): self.adate = adate self.label.set_text(str(adate.day)) self.moon = Moon(adate) phasename = self.moon.phase() i = adate.day roundedpos = round(float(self.moon.position()), 3) self.image.set_from_pixbuf( GdkPixbuf.Pixbuf.new_from_file_at_size( os.path.join( comun.IMAGESDIR, self.moon.image()), 60, 60))
def testCycle(self): size : int = 3 color : str = "samantha" phase : int = 2 moon : Moon = Moon(size, color, phase) self.assertEqual(moon.phase,phase) self.assertEqual(moon.color,color) self.assertEqual(moon.size,size) moon.color = "white" if moon.phase == 2: print("half moon") moon.cycle() self.assertEqual(moon.phase,phase+1)
def part2(vals: list) -> int: dims = [0, 0, 0] for i in range(3): moons = [Moon(val) for val in vals] oPos = [moon.pos[i] for moon in moons] while True: simulate(moons) dims[i] += 1 if [moon.pos[i] for moon in moons] == oPos and \ [moon.vel[i] for moon in moons] == [0, 0, 0, 0]: break return lcm(dims[0], lcm(dims[1], dims[2]))
class Game: def __init__(self): pygame.init() self.screen = pygame.display.set_mode([WIDTH, HEIGHT]) pygame.display.set_caption(TITLE) self.clock = pygame.time.Clock() self.start() def start(self): self.moon = Moon(self, WIDTH, HEIGHT * 0.75, 10) self.moon.generate_terrain() self.player = Player(self, WIDTH // 2, 0) def run(self): self.playing = True while self.playing: self.dt = self.clock.tick(FPS) self.events() self.update() self.draw() def events(self): for event in pygame.event.get(): if event.type == pygame.QUIT: self.playing = False def update(self): self.player.update(self.moon) def draw(self): self.screen.fill(DARKGREY) self.moon.draw() self.player.draw() pygame.draw.rect(self.screen, DARKRED, pygame.Rect(5, 5, 200, 25)) pygame.draw.rect(self.screen, YELLOW, pygame.Rect(5, 5, 200 * self.player.fuel, 25)) pygame.display.flip()
def testCycle(self): distance: float = 17 orbits: str = "Mars" size: int = 3 color: str = "samantha" phase: int = 2 moon: Moon = Moon(distance, orbits, size, color, phase) self.assertEqual(moon.phase, phase) self.assertEqual(moon.color, color) self.assertEqual(moon.size, size) moon.color = "white" if moon.phase == 2: print("half moon") moon.cycle() self.assertEqual(moon.phase, phase + 1)
def run_game(): pygame.init() pygame.mixer.music.load('music/Phantom from Space.mp3') pygame.mixer.music.play(-1) pygame.mixer.music.set_volume(0.5) sw_settings = Settings() screen = pygame.display.set_mode( (sw_settings.screen_width, sw_settings.screen_height)) pygame.display.set_caption("Earth's Defender") earth = Earth(sw_settings, screen) moon = Moon(sw_settings, screen) sun = Sun(sw_settings, screen) play_button = Button(sw_settings, screen, "Play") pause_message = PauseMessage(sw_settings, screen, "Pause") game_stats = GameStats(sw_settings) scoreboard = Scoreboard(sw_settings, screen, game_stats) ship = Ship(sw_settings, screen) alien_boss = AlienBoss(sw_settings, screen) bullets = Group() aliens = Group() aliens_bullets = Group() asteroids = Group() gf.create_fleet(sw_settings, screen, ship, aliens) while True: gf.check_events(sw_settings, screen, game_stats, scoreboard, play_button, pause_message, ship, aliens, bullets, aliens_bullets, asteroids) if game_stats.game_active and game_stats.game_pause: ship.update() gf.update_bullets(sw_settings, screen, game_stats, scoreboard, ship, aliens, bullets, aliens_bullets, asteroids, alien_boss) gf.update_aliens(sw_settings, game_stats, scoreboard, screen, ship, aliens, bullets, aliens_bullets, asteroids) gf.check_alien_fires(sw_settings, screen, aliens, aliens_bullets) gf.update_aliens_bullets(sw_settings, game_stats, scoreboard, screen, ship, aliens, bullets, aliens_bullets, asteroids) gf.check_asteroid_fall(sw_settings, screen, asteroids) gf.update_asteroids(sw_settings, game_stats, scoreboard, screen, ship, aliens, bullets, aliens_bullets, asteroids) gf.update_alien_boss(sw_settings, screen, game_stats, alien_boss, aliens, aliens_bullets, bullets, asteroids) gf.update_screen(sw_settings, screen, earth, moon, sun, game_stats, scoreboard, ship, aliens, bullets, aliens_bullets, asteroids, play_button, pause_message, alien_boss)
def find_loop(self): initial_state = [Moon(*m.position) for m in self.__moons] axe_infos = [] for axe in range(3): previous_state = [] current_state = self.get_state_for_axe(axe) i = 0 while current_state not in previous_state: previous_state.append(current_state) self.update_axe(axe) i += 1 current_state = self.get_state_for_axe(axe) axe_infos.append(i - previous_state.index(current_state)) print(axe_infos) return axe_infos
def __init__(self): self.mMoon = Moon() return
class ShowSkyCoverage(object): """Moving the FoV-footprint coverage by choosing a starting pointing.""" SHIFT_CORRECTION = 0.00001 # A shift correction of 0.00001 is added # --> to escape math error during the FoV sequence def __init__(self, infile_coords='GWsky_coords'): """Creating a class in which the instance attributes are based on the dictionary "GWsky_coords" by default. GWsky_coords is created and pickled by the "user_values" module and will be deleted when the "ShowSkyCoverageGUI" will be closed. It contains the keys: "ra", "dec". ra and dec represents the central location of a FoV. Starting sky coordinates: self.input_ra: right ascension [deg] self.input_dec: declination [deg] """ self.infile_coords = infile_coords self.entries_GWsky_new =[] # new entries during the FoV sequence self.user = UserValues() # compositions self.lvc = LVCskymap() self.query = Query() self.airmass = Airmass() self.moon = Moon() with open(infile_coords, 'rb') as data: coords_GWsky = pickle.load(data) for k, v in coords_GWsky.items(): setattr(self, k, v) def ra0ra1(self, A, dec0, dec1): """From the angular distance: cos(A) = sin(Dec1)sin(Dec2)+cos(Dec1)cos(Dec2)cos(ra1-ra2) --> cos(ra1-ra2) = [cos(A)-sin(dec0)sin(dec1)]/[cos(dec0)cos(dec1)].""" dec0, dec1, A = radians(dec0), radians(dec1), radians(A) cos_ra0_ra1 = ( cos(A)-sin(dec0)*sin(dec1) )/( cos(dec0)*cos(dec1) ) ra0ra1 = degrees( acos(cos_ra0_ra1) ) return round(ra0ra1, 5) def __updating_center_coords(self, ra, dec): """Getting/Updating FoV-center (ra, dec) in the dict named by default "GWsky_coords". . For each tile across the sky the file is updated.""""" with open('GWsky_coords', 'rb') as data: coords_GWsky = pickle.load(data) coords_GWsky['input_ra'], coords_GWsky ['input_dec'] = ra, dec with open('GWsky_coords', 'wb') as data: pickle.dump(coords_GWsky, data) def __are_all_same(self, items): """Check if all elements of a list are the same.""" return all(x == items[0] for x in items) def __fov_stats(self, ra, dec, table, integrated_prob, distance_grid, ansatz_distribution, moon_illumination): """Managing the descriptive statistic window. If the airmass is outside the default range [airmass_min, airmass_max] the window is not opened otherwise the window is shown.""" airmass_values, datestrings = self.airmass.airmass_step(ra, dec) same = self.__are_all_same(airmass_values) if same == True: tkMessageBox.showerror('Warning',"airmass outside the range of {1 - 5.8}") aladin.remove_FoV(ra, dec) aladin.remove("C_" + str( ra ) + "/" + str( dec )) else: time_step = [dateutil.parser.parse(s) for s in datestrings] self.__updating_center_coords(ra,dec) fov_statistics = FoVstatistics() fov_statistics.plot_stats(time_step, airmass_values, ra, dec, table, integrated_prob, distance_grid, ansatz_distribution, moon_illumination) print airmass_values, datestrings def update_pointings_file(self, infile, ra, dec, prob_fov): """The central location (ra[deg], dec[deg]) and the integrated probability of a selected FoV are saved locally in an external file. By default the file is named "GWsky_pointings.txt".""" with open(infile, 'a') as pointing: pointing.write(str(ra) + ' ' + str(dec)+ ' '+ str(prob_fov)+'\n') def __query_shape(self, ra, dec, fov_shape): """Return the catalog query according with the defined-user FoV shape: (1) box and (2) circle. """ if self.user.get_fov_shape() != 2: # box FoV query_result = self.query.query_box( ra, dec, self.user.get_fov_width(), self.user.get_fov_height(), self.user.get_catalog(), self.user.get_column_1(), self.user.get_column_2(), self.user.get_filter_1(), self.user.get_filter_2()) else: # circle FoV query_result = self.query.query_circle( ra, dec, self.user.get_fov_radius(), self.user.get_catalog(), self.user.get_column_1(), self.user.get_column_2(), self.user.get_filter_1(), self.user.get_filter_2()) return query_result def __prob_shape(self, ra, dec, fov_shape): """Return the integrated probability according with the defined-user FoV shape: (1) box and (2) circle.""" if self.user.get_fov_shape() !=2: # box FoV prob_fov = self.lvc.prob_in_box( ra, dec, self.user.get_fov_width(), self.user.get_fov_height()) else: # circle FoV prob_fov = self.lvc.prob_in_circle( ra, dec, self.user.get_fov_radius()) return prob_fov def pick_coverage(self, ra, dec): """Setting GWsky: with statistic window (A); without statistic window (D).""" if self.user.get_GWsky_basic() == "A": # full version query_result = self.__query_shape(ra, dec, self.user.get_fov_shape()) prob_fov = self.__prob_shape(ra, dec, self.user.get_fov_shape()) moon_illumination = self.moon.illumination() # moon_illumination # moon_dist # TEST fov_sep = Utils.separation(self.input_ra, self.input_dec, ra, dec) print ('The distance between 2 consecutive FoV centers is', fov_sep.round(6)) r, dp_dr = self.lvc.conditional_distance_fov_center(ra, dec) self.__fov_stats(ra, dec, query_result, prob_fov, r, dp_dr, moon_illumination) # add moon ill, moon dist elif self.user.get_GWsky_basic() == "D": # basic version-> no Stats win prob_fov = self.__prob_shape(ra, dec, self.user.get_fov_shape()) # TEST #Utils.separation(self.input_ra, self.input_dec, ra, dec) self.update_pointings_file("GWsky_pointings.txt", ra, dec, prob_fov) def intercardinal_distance(self, ra, dec, shift_up_down, shift_right_left): """Moving from the fixed cardinal direction using the bi-directional windows; shift_up_down ↕ and/or shift_right_left ↔.""" if shift_right_left > 0: shift_east_west = self.ra0ra1((shift_right_left-self.SHIFT_CORRECTION), (dec + self.user.get_fov_height() + shift_up_down), (dec + self.user.get_fov_height() + shift_up_down)) dist = ra + shift_east_west elif shift_right_left < 0 : shift_east_west = self.ra0ra1((shift_right_left + self.SHIFT_CORRECTION), (dec + self.user.get_fov_height() + shift_up_down), (dec + self.user.get_fov_height() + shift_up_down)) dist = ra - shift_east_west else: dist = ra return dist def load_entries(self, infile_entries): """Opening the file in which the input entries are stored: ra_1 dec_1 ra_2 dec_2 ... ra_n dec_n By default the file is named "GWsky_entries". "GWsky_entries" is created from the "show_starting_fov" method in "StartingFoV" class. A error message invites users to press the "Start FoV" button before carrying out any""" try: with open(infile_entries, 'rb') as data: entries_GWsky = pickle.load(data) return entries_GWsky except IOError as io_error: message = "Press the button 'Start FoV' and choose a starting position; \ by default the sky position of the max probability pixel is shown" tkMessageBox.showerror ('Error', message) def north(self, shift_up_down=0, shift_right_left=0): """Moving the FoV tiles in North direction from input sky-position(s). The related bidirectional button permits small shifts from such pre-defined direction: shift_up_down ↕ and/or shift_right_left ↔ """ entries_GWsky = self.load_entries("GWsky_entries") fov_center_ra, fov_center_dec = entries_GWsky[0::2], entries_GWsky[1::2] for ra_start, dec_start in zip (fov_center_ra, fov_center_dec): dist = self.intercardinal_distance(float(ra_start), float(dec_start), shift_up_down, shift_right_left) north_pointing = [(dist), (float(dec_start) + self.user.get_fov_height() + shift_up_down)] ra, dec = north_pointing[0], north_pointing[1] aladin.get_FoV(ra, dec) self.pick_coverage(ra, dec) new_sky_pos = [ra,dec] # cycle variables self.entries_GWsky_new.extend(new_sky_pos) with open('GWsky_entries', 'wb') as data: pickle.dump(self.entries_GWsky_new, data) def south(self, shift_up_down=0, shift_right_left=0): """Moving the FoV tiles in South direction from input sky-position(s). The related bidirectional button permits small shifts from such pre-defined direction: shift_up_down ↕ and/or shift_right_left ↔""" entries_GWsky = self.load_entries("GWsky_entries") fov_center_ra, fov_center_dec = entries_GWsky[0::2], entries_GWsky[1::2] for ra_start, dec_start in zip (fov_center_ra, fov_center_dec): dist = self.intercardinal_distance(float(ra_start), float(dec_start), shift_up_down, shift_right_left) south_pointing = [(dist), (float(dec_start) - self.user.get_fov_height() - shift_up_down)] ra, dec = south_pointing[0], south_pointing[1] aladin.get_FoV(ra, dec) self.pick_coverage(ra, dec) new_sky_pos = [ra,dec] # cycle variables self.entries_GWsky_new.extend(new_sky_pos) with open('GWsky_entries', 'wb') as data: pickle.dump(self.entries_GWsky_new, data) def east(self, shift_up_down=0, shift_right_left=0): """Moving the FoV tiles in East direction from input sky-position(s). The related bidirectional button permits small shifts from such pre-defined direction: shift_up_down ↕ and/or shift_right_left ↔. A shift correction of 0.00001 is added to escape math error.""" entries_GWsky = self.load_entries("GWsky_entries") fov_center_ra, fov_center_dec = entries_GWsky[0::2], entries_GWsky[1::2] for ra_start, dec_start in zip (fov_center_ra, fov_center_dec): ra_distance = self.ra0ra1((self.user.get_fov_width() - self.SHIFT_CORRECTION + shift_right_left), float(dec_start), float(dec_start)) east_pointing = [(float(ra_start) + ra_distance), (float(dec_start) + shift_up_down)] ra, dec = east_pointing[0], east_pointing[1] aladin.get_FoV(ra, dec) self.pick_coverage(ra, dec) new_sky_pos = [ra,dec] # cycle variables self.entries_GWsky_new.extend(new_sky_pos) with open('GWsky_entries', 'wb') as data: pickle.dump(self.entries_GWsky_new, data) def west(self, shift_up_down=0, shift_right_left=0): """Moving the FoV tiles in West direction from input sky-position(s). The related bidirectional button permits small shifts from such pre-defined direction: shift_up_down ↕ and/or shift_right_left ↔. A shift correction of 0.00001 is added to escape math error.""" entries_GWsky = self.load_entries("GWsky_entries") fov_center_ra, fov_center_dec = entries_GWsky[0::2], entries_GWsky[1::2] for ra_start, dec_start in zip (fov_center_ra, fov_center_dec): ra_distance = self.ra0ra1((self.user.get_fov_width() - self.SHIFT_CORRECTION + shift_right_left), float(dec_start), float(dec_start)) west_pointing = [(float(ra_start) - ra_distance), (float(dec_start) + shift_up_down)] ra, dec = west_pointing[0], west_pointing[1] aladin.get_FoV(ra, dec) self.pick_coverage(ra, dec) new_sky_pos = [ra,dec] # cycle variables self.entries_GWsky_new.extend(new_sky_pos) with open('GWsky_entries', 'wb') as data: pickle.dump(self.entries_GWsky_new, data)
def run(self): while self.paused[0] == 1: pass sky = Sky(self.queue) sun = Sun(self.queue, 300, 100) moon = Moon(self.queue, 300, 100) ground = Ground(self.queue) time = 75 self.shared[0] = time day = 0 seasons = ["spring", "summer", "fall", "winter"] season = "spring" self.shared[2] = seasons.index(season) seasonStages = ["early", "mid", "mid", "late"] seasonStage = "mid" weatherOptions = ["clear", "clear", "clear", "clear", "cloudy", "cloudy", "overcast", "rain", "rain", "storm"] weather = choice(weatherOptions) self.shared[1] = weatherOptions.index(weather) self.queue.put(QueueItem("cont")) self.paused[0] = 1 self.paused[3] = 0 while self.paused[0] == 1: pass while True: sky.update(time) sun.update(time) moon.update(time, day) ground.update(time, season, seasonStage, seasons) sun.draw() moon.draw() ground.draw() time += 3 if time > 1600: time = 0 day += 1 if day > 15: day = 0 season = seasons[int(day/4)] self.shared[2] = seasons.index(season) seasonStage = seasonStages[day%len(seasonStages)] if season == "winter" and seasonStage == "early": weather = "rain" else: weather = choice(weatherOptions) self.shared[0] = time self.shared[1] = weatherOptions.index(weather) self.queue.put(QueueItem("cont")) self.paused[0] = 1 sleep(0.05) while self.paused[0] == 1: pass