def phase_phrase_test(self, sf_datetime, expected_phrase): """Generic test for testing moon phase phrase.""" sf_timestring = datetime.strftime(sf_datetime, BOOTSTRAP_DTIME_FORMAT) stf = StarField(lat=SF_LAT, lng=SF_LNG, localtime_string=sf_timestring) growth, phase_phrase = stf.get_moon_phase_phrase() self.assertEqual(phase_phrase, expected_phrase)
def test_zero_zero_timezone(self): """Test getting time zone for lat/lng that has no time zone. In this case, we return utc.""" stf = StarField(lat=0, lng=0) self.timezone_test(stf, pytz.timezone('Etc/UTC'))
def test_no_time_provided(self): """Test that a starfield gets the time of "now" if no time is provided""" stf = StarField(lat=SF_LAT, lng=SF_LNG) now = pytz.utc.localize(datetime.utcnow()) # make sure the time assigned is no more than one second off current time self.assertTrue(abs(stf.utctime - now).seconds < 1)
def waning_moon_rotation_test(self, lat, lng, expected_rotation): """Generic test for a waning datetime. (different from standard test datetime for this file)""" wan_datetime = datetime(2017, 2, 15, 21, 0, 0) wan_timestring = datetime.strftime(wan_datetime, BOOTSTRAP_DTIME_FORMAT) stf = StarField(lat=lat, lng=lng, localtime_string=wan_timestring) self.moon_rotation_test(stf, expected_rotation)
def local_to_utc_time_test(self, lat, lng, expected_offset): """A generic function to test the starfield set_utc_time method expected_offset is a time difference from UTC, in hours""" # make a starfield instance with an arbitrary time dt_string = datetime.strftime(TEST_DATETIME, BOOTSTRAP_DTIME_FORMAT) stf = StarField(lat=lat, lng=lng, localtime_string=dt_string) time_diff = stf.utctime - pytz.utc.localize(TEST_DATETIME) self.assertEqual(time_diff.seconds, expected_offset * 3600)
def return_place_time_data(): """Return json of sky rotation, planet, sun and moon info. Returned data is based on location and time from POST data. """ lat = request.form.get('lat') lng = request.form.get('lng') localtime_string = request.form.get('datetime') max_magnitude = 5 # dimmest planets to show stf = StarField(lat=float(lat), lng=float(lng), max_mag=max_magnitude, localtime_string=localtime_string) return jsonify({'dateloc': stf.get_specs(), 'rotation': stf.get_sky_rotation(), 'planets': stf.get_planets(), 'sundata': stf.get_sun(), # sun is a reserved word in js! 'moon': stf.get_moon()})
def run_main(): size = width, height = 1280, 720 speed = [2, 2] black = 0, 0, 0 screen = pygame.display.set_mode(size) sf = StarField(size) fps = FPS() while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() screen.fill(black) sf.do_things(screen) fps.show_fps(screen) pygame.display.flip()
import sys sys.path.append('..') from run_tests import MarginTestCase, DbTestCase, MAX_MAG, COORDS_KEY_SET, \ SKYOBJECT_KEY_SET from starfield import deg_to_rad, rad_to_deg, StarField, BOOTSTRAP_DTIME_FORMAT # 9pm on March 1, 2017 (local time) TEST_DATETIME = datetime(2017, 3, 1, 21, 0, 0) TEST_DATETIME_STRING = datetime.strftime(TEST_DATETIME, BOOTSTRAP_DTIME_FORMAT) # test lat/lngs: johannesburg J_LAT = -26.2041 J_LNG = 28.0473 J_STF = StarField(lat=J_LAT, lng=J_LNG, max_mag=MAX_MAG, localtime_string=TEST_DATETIME_STRING) # test lat/lngs: sf SF_LAT = 37.7749 SF_LNG = -122.4194 SF_STF = StarField(lat=SF_LAT, lng=SF_LNG, max_mag=MAX_MAG, localtime_string=TEST_DATETIME_STRING) # acceptable margin when comparing floats MARGIN = 0.005 # expected data sets PLANET_KEY_SET = SKYOBJECT_KEY_SET | set(
berk_latlng = ('Berkeley', 37.87, -122.27) cc_latlng = ('Christchurch', -43.53, 172.64) dates = [ 'March 28, 2017 at 2:49 PM', 'March 7, 2017 at 6:00 PM', 'March 27, 2017 at 9:00 AM', 'March 22, 2017 at 12:00 PM', 'March 15, 2017 at 4:00 AM', 'January 1, 2017 at 12:00 PM', 'March 1, 2017 at 6:00 PM' ] # header print(','.join(['city', 'date', 'lambda', 'phi', 'phase', 'ephAlt', 'ephAz', 'sidAlt', 'sidAz'])) for loc in [berk_latlng, cc_latlng]: for date in dates: dt = datetime.strptime(date, '{} at {}'.format(DISPLAY_DATE_FORMAT, DISPLAY_TIME_FORMAT)) datestring = datetime.strftime(dt, BOOTSTRAP_DTIME_FORMAT) stf = StarField(loc[1], loc[2], datestring) mdata = stf.get_moon() rot = stf.get_sky_rotation() print(','.join([loc[0], date, str(rot['lambda']), str(rot['phi']), mdata['phase'], ) str(mdata['ephAlt']), str(mdata['ephAz']), str(mdata['sidAlt']), str(mdata['sidAz'])])