コード例 #1
0
def levelVars():

    ### NOTE: Paddle and ball are properties of polymorphism

    # Paddle
    paddle = functions.box(150, 10)
    paddle.setPos(WIDTH / 2 - paddle.getBox().get_width() / 2,
                  HEIGHT - paddle.getBox().get_height() - 5)
    paddle.setColor((0, 200, 100))

    # Ball
    # ball = functions.ball(50, 50, 100, 100)
    ball = functions.box(20, 20)
    ball.setPos(
        WIDTH / 2 - ball.getBox().get_width() / 2,
        HEIGHT - paddle.getBox().get_height() - ball.getBox().get_height() - 5)
    ball.setColor((WHITE))
    # Random ball movement
    ballStartMove = (round(random.uniform(-2, 2),
                           1), round(random.uniform(-2, -1),
                                     1))  # (-1.3, -1.6)
    ball.xDir = ballStartMove[0]
    ball.yDir = ballStartMove[1]
    print(ballStartMove)

    ### NOTE: Blocks are a property of aggregation

    # Blocks
    blocks = []
    y = 80
    for rows in range(6):
        x = 0
        for columns in range(10):
            block = functions.box(80, 30, x, y)
            block.setColor(blockColors[rows])
            blocks.append(block)
            x += block.getBox().get_width()
        y += block.getBox().get_height()

    return paddle, ball, blocks, block
コード例 #2
0
depth = 0.00650010001
width = 0.177046694669

period_interval = np.arange(2.00, 8.0, 0.01)
offset_intervals = np.arange(0.00, 7.2, 0.01)

#Change to numpy arrays to optimize.
# z = [[f.sum_chi_squared(flux, f.box(p,o,depth,width,time),variance) for o in offset_intervals]
# for p in period_interval]

z = []
for p in period_interval:
	line = []
	for o in offset_intervals:
		if o < p:
			line.append(f.sum_chi_squared(flux, f.box(p,o,depth,width,time), variance))
		else:
			line.append(np.nan)
		print o
	z.append(line)


# z = np.empty([period_interval.shape[0],offset_intervals.shape[0]])
# z.fill(np.nan)
# for p in period_interval:
# 	for o in offset_intervals:
# 		if o < p:
# 			z[p][o] = f.sum_chi_squared(flux, f.box(p,o,depth,width,time), variance)
# 			print o
# 		else:
# 			pass
コード例 #3
0
width = 0.177046694669

period_interval = np.arange(2.00, 8.0, 0.01)
offset_intervals = np.arange(0.00, 7.2, 0.01)

#Change to numpy arrays to optimize.
# z = [[f.sum_chi_squared(flux, f.box(p,o,depth,width,time),variance) for o in offset_intervals]
# for p in period_interval]

z = []
for p in period_interval:
    line = []
    for o in offset_intervals:
        if o < p:
            line.append(
                f.sum_chi_squared(flux, f.box(p, o, depth, width, time),
                                  variance))
        else:
            line.append(np.nan)
        print o
    z.append(line)

# z = np.empty([period_interval.shape[0],offset_intervals.shape[0]])
# z.fill(np.nan)
# for p in period_interval:
# 	for o in offset_intervals:
# 		if o < p:
# 			z[p][o] = f.sum_chi_squared(flux, f.box(p,o,depth,width,time), variance)
# 			print o
# 		else:
# 			pass
コード例 #4
0
# offset = 1.0
depth = 0.00650010001
width = 0.177046694669

# period_interval = 10 ** np.linspace(np.log10(2.5), np.log10(10), 700)
period_interval = np.linspace(3.0,4.0,1000)
offset_start = 1.5
offset_intervals = [np.arange(offset_start, p, 0.01) for p in period_interval]

#The following grid is structured in a way where there is a list 
#for all the chi2 values obtained for each period. For EACH period
#there exists a nested list where the values are the chi2 values obtained 
#for each offset it iterates through.
#This structure is equivalent to a 2D array. The rows are the periods and 
#the columns are offsets.
chi2_grid = [[f.sum_chi_squared(flux, f.box(p, o, depth, width, time), variance)
              for o in offsets] for p, offsets in zip(period_interval, offset_intervals)]

#This map function iterates through the chi2_grid and finds the minimum for each period.
#It means it is finding the lowest chi2 for each period, which is equal to selecting
#the chi2 value with the best offset for each period.
#It generates a list(array) of the the lowest chi2 values for each period.
#The length of the list is equal to the number of periods.
chi2_values = map(np.min, chi2_grid)

#Return the index of the lowest chi2 in the chi2_values list.
#This index corresponds to the best period as the first dimension of
#both arrays are the same.
lowest_chi2_index = np.argmin(chi2_values)
print np.min(chi2_values)
#Return the best period.
コード例 #5
0
length = clean_flux.shape[0]
# print length

#define arguments for the box_model
phase = np.arange(0, 2529)
depth = 0.009
width = np.arange(0, 270)

#This part of the code contains the main functionality.
p_interval = np.arange(4900,11000)
chi_squared_list = []
#Set up a dictionary to assign the selected period to the appropriate chi-squared.
chi_dict = {}
for element in p_interval:
	period = np.arange(0, element)
	box_y = f.box(period, phase, depth, width, length)
	calc_chi_squared = f.sum_chi_squared(clean_flux, box_y)
	chi_squared_list.append(calc_chi_squared)
	chi_dict[calc_chi_squared] = element

#return the lowest value and also the corresponding period.
chi_value_list = chi_dict.keys()
best_fit_period = chi_dict[min(chi_value_list)]
# print best_fit_period
print period_time[best_fit_period]

#The following code will convert the p_interval array into 
#the actual period in days.
period_in_days = []
for i in p_interval:
	period_in_days.append(period_time[i])
コード例 #6
0
offset_interval = np.arange(0.00, 8.0, 0.001)
width_interval = np.arange(0.00, 1.0, 0.0001)
depth_interval = np.arange(0.0, 0.02, 0.0001)

# x1 = 0
# first_interval = 0
# upd_int = 0
units = '(Days)'

#Set the search here.
parameter = raw_input('Parameter: ')
if parameter == 'period':
    x1 = period_interval
    first_interval = period_interval
    chi2 = [
        f.sum_chi_squared(flux, f.box(p, offset, depth, width, time), variance)
        for p in first_interval
    ]
    update_period = period_interval[np.argmin(chi2)]
    #Generalize this.
    upd_int = np.linspace(update_period - 0.001, update_period + 0.001, 10000)
    upd_chi2 = [
        f.sum_chi_squared(flux, f.box(p, offset, depth, width, time), variance)
        for p in upd_int
    ]
    period = upd_int[np.argmin(upd_chi2)]
    print period
    print np.min(upd_chi2)

elif parameter == 'offset':
    x1 = offset_interval
コード例 #7
0
jdadj, obsobject, lightdata = f.openfile(kplr_id, kplr_file)
time, flux, flux_err = f.fix_data(lightdata)
flux, variance = f.rescale(flux, flux_err)
time -= np.median(time)

period = 300.00
offset = 20.0
depth = 0.008
width = 0.09

flux = f.raw_injection(period, offset, depth, width, time, flux)

offset_interval = np.arange(0.00, 30.00, 0.01)
chi2 = [
    f.sum_chi_squared(flux, f.box(period, o, depth, 0.09, time), variance)
    for o in offset_interval
]
best_offset = offset_interval[np.argmin(chi2)]

fig1 = plt.figure()
sub1 = fig1.add_subplot(121)
sub1.plot(time, flux, color="black", marker=",", linestyle='None')
sub1.plot(time, f.box(period, best_offset, depth, 0.9, time), 'r')
xlab = "Time (days, Kepler Barycentric Julian date - %s)" % jdadj
sub1.set_xlabel(xlab)
sub1.set_ylabel("Relative Brightness (electron flux)")
plottitle = "Light Curve for %s" % obsobject
sub1.set_title(plottitle)

sub2 = fig1.add_subplot(122)
コード例 #8
0
period_interval = np.arange(1.0,8.0,0.001)
offset_interval = np.arange(0.00,8.0,0.001)
width_interval = np.arange(0.00,1.0,0.0001)
depth_interval = np.arange(0.0, 0.02, 0.0001)

# x1 = 0
# first_interval = 0
# upd_int = 0
units = '(Days)'

#Set the search here.
parameter = raw_input('Parameter: ')
if parameter == 'period':
	x1 = period_interval
	first_interval = period_interval
	chi2 = [f.sum_chi_squared(flux, f.box(p, offset, depth, width, time), variance) for p in first_interval]
	update_period = period_interval[np.argmin(chi2)]
	#Generalize this.
	upd_int = np.linspace(update_period-0.001, update_period+0.001, 10000)
	upd_chi2 = [f.sum_chi_squared(flux, f.box(p, offset, depth, width, time), variance) for p in upd_int]
	period = upd_int[np.argmin(upd_chi2)]
	print period
	print np.min(upd_chi2)

elif parameter == 'offset':
	x1 = offset_interval
	first_interval = offset_interval
	chi2 = [f.sum_chi_squared(flux, f.box(period, o, depth, width, time), variance) for o in first_interval]
	update_offset = offset_interval[np.argmin(chi2)]
	upd_int = np.linspace(update_offset-0.001, update_offset+0.001, 10000)
	upd_chi2 = [f.sum_chi_squared(flux, f.box(period, o, depth, width, time), variance) for o in upd_int]
コード例 #9
0
kplr_file = 'kplr006116605-2009259160929_llc.fits'

jdadj, obsobject, lightdata = f.openfile(kplr_id, kplr_file)
time, flux, flux_err = f.fix_data(lightdata)
flux, variance = f.rescale(flux, flux_err)
time -= np.median(time)

period = 300.00
offset = 20.0
depth = 0.008
width = 0.09

flux = f.raw_injection(period,offset,depth,width,time,flux)

offset_interval = np.arange(0.00, 30.00, 0.01)
chi2 = [f.sum_chi_squared(flux, f.box(period, o, depth, 0.09, time), variance) for o in offset_interval]
best_offset = offset_interval[np.argmin(chi2)]

fig1 = plt.figure()
sub1 = fig1.add_subplot(121)
sub1.plot(time ,flux, color="black", marker=",", linestyle = 'None')
sub1.plot(time , f.box(period, best_offset, depth, 0.9, time), 'r')
xlab = "Time (days, Kepler Barycentric Julian date - %s)"%jdadj
sub1.set_xlabel(xlab)
sub1.set_ylabel("Relative Brightness (electron flux)")
plottitle="Light Curve for %s"%obsobject
sub1.set_title(plottitle)

sub2 = fig1.add_subplot(122)
sub2.plot(offset_interval, chi2, 'b')
sub2.ticklabel_format(style = 'sci')
コード例 #10
0
length = clean_flux.shape[0]
# print length

#define arguments for the box_model
phase = np.arange(0, 2529)
depth = 0.009
width = np.arange(0, 270)

#This part of the code contains the main functionality.
p_interval = np.arange(4900, 11000)
chi_squared_list = []
#Set up a dictionary to assign the selected period to the appropriate chi-squared.
chi_dict = {}
for element in p_interval:
    period = np.arange(0, element)
    box_y = f.box(period, phase, depth, width, length)
    calc_chi_squared = f.sum_chi_squared(clean_flux, box_y)
    chi_squared_list.append(calc_chi_squared)
    chi_dict[calc_chi_squared] = element

#return the lowest value and also the corresponding period.
chi_value_list = chi_dict.keys()
best_fit_period = chi_dict[min(chi_value_list)]
# print best_fit_period
print period_time[best_fit_period]

#The following code will convert the p_interval array into
#the actual period in days.
period_in_days = []
for i in p_interval:
    period_in_days.append(period_time[i])
コード例 #11
0
blockColors = (RED, ORANGE, ORANGEYELLOW, YELLOW, GREEN, BLUE)

# Create the window
screen = pygame.display.set_mode(
    SCREENDIM)  # Creates the main surface where all other assets are placed
pygame.display.set_caption(TITLE)  # Updates the window title with TITLE
screen.fill(
    GREY)  # Fills the entire surface with the colour.  Think of fill as erase

clock = pygame.time.Clock()  # Starts a clock object to measure time

# Background image
stars = []
for i in range(200):
    stars.append(
        functions.box(2, 1, random.randrange(0, WIDTH),
                      random.randrange(50, HEIGHT)))
for i in stars:
    i.setColor(WHITE)

# Invisible walls
topWall = functions.box(800, 1, 0, 50)
bottomWall = functions.box(800, 1, 0, 599)
leftWall = functions.box(1, 550, 0, 50)
rightWall = functions.box(1, 550, 799, 50)

# Logo
logo = functions.text("BRICK BREAKER", font='Arial Black', fontSize=50)
logo.setColor(WHITE)
logo.setPos(WIDTH / 2 - logo.getText().get_width() / 2, -10)

コード例 #12
0
kplr_file = 'kplr006116605-2009259160929_llc.fits'

jdadj, obsobject, lightdata = f.openfile(kplr_id, kplr_file)
time, flux, flux_err = f.fix_data(lightdata)
flux, variance = f.rescale(flux, flux_err)
time -= np.median(time)

period = 300.00
offset = 20.0
depth = 0.008
width = 0.09

flux = f.raw_injection(period,offset,depth,width,time,flux)

offset_interval = np.arange(0.00, 30.00, 0.01)
chi2 = [f.sum_chi_squared(flux, f.box(period, o, depth, 0.09, time), variance) for o in offset_interval]
best_offset = offset_interval[np.argmin(chi2)]

fig1 = plt.figure()
sub1 = fig1.add_subplot(121)
sub1.plot(time ,flux, color="black", marker=",", linestyle = 'None')
sub1.plot(time , f.box(period, best_offset, depth, 0.9, time), 'r')
xlab = "Time (days, Kepler Barycentric Julian date - %s)"%jdadj
sub1.set_xlabel(xlab)
sub1.set_ylabel("Relative Brightness (electron flux)")
plottitle="Light Curve for %s"%obsobject
sub1.set_title(plottitle)

sub2 = fig1.add_subplot(122)
sub2.plot(offset_interval, chi2, 'b')
sub2.ticklabel_format(style = 'sci')