Example #1
0
def check_speed_profile(laser_file_n, vibrations, n_runs, speed_profile, speed_variables, n_shots, last_bin, phase_mod_profile, n_shots_slow = 0, n_slow_runs = 0, speed_variables_slow = [], flag_plot = False, title = ""):

	B_exists = False
	
	for i in range(n_runs):
		
		if i >= n_runs - n_slow_runs:
			print("slow run!")
			n_shots = n_shots_slow
			speed_var = speed_variables_slow
		else:
			speed_var = speed_variables
			
		if i > 0:
			sum_bins = numpy.sum(B_count, axis=1)			
			print(len(sum_bins) - len(sum_bins[numpy.where(sum_bins)]), "unfilled bins")

		# determine the position
		T_fs, T_bin = LS.position(n_shots, speed_profile = speed_profile, variables = speed_var)	
		
		x, y = croc.Resources.Mathematics.derivative(numpy.arange(n_shots), T_fs)
		
		#print(T_fs[0], T_bin[0], T_fs[-1], T_bin[-1])
		
		plt.figure()
		plt.plot(numpy.arange(n_shots), T_bin)
		plt.show()
		
		plt.figure()
		plt.plot(x, y)
		plt.title("Speed profile")
		plt.xlabel("Shots")
		plt.ylabel("Time change per shot (fs)")
		plt.show()		
Example #2
0
def make_run(laser_file_n, vibrations, n_runs, speed_profile, speed_variables, last_bin, phase_mod_profile, n_slow_runs = 0, speed_variables_slow = [], flag_plot = False, title = ""):

	B_exists = False
	
	# determine how many shots are needed
	n_shots_normal = LS.shots_for_n_bins(last_bin, speed_profile = speed_profile, variables = speed_variables)
	
	if n_slow_runs > 0:
		n_shots_slow = LS.shots_for_n_bins(last_bin, speed_profile = speed_profile, variables = speed_variables_slow)
	
	
	for i in range(n_runs):

		if i >= n_runs - n_slow_runs:
			print("  slow run!")
			sum_bins = numpy.sum(B_count, axis=1)			
			print("  " + str(len(sum_bins) - len(sum_bins[numpy.where(sum_bins)])) + " bins still unfilled")
			
			n_shots = n_shots_slow
			speed_var = speed_variables_slow
		else:
			speed_var = speed_variables
			n_shots = n_shots_normal
		
			
		# determine the position
		T_fs, T_bin = LS.position(n_shots, speed_profile = speed_profile, variables = speed_var)	

#		print("last bin:", T_bin[-1])
	
		# import the laser
		I = import_laser(n = laser_file_n + i)
		I = -I[:n_shots]
		
		S = numpy.zeros(n_shots)
		for j in range(len(vibrations)):
			S += LS.signal(T_fs, vibrations[j][0], vibrations[j][1], vibrations[j][2])
		
		I, M = LS.add_phase_modulation(I, phase_mod_profile = phase_mod_profile)
		
		S = LS.signal_and_laser(S, I)
		
		# scattering
		if flag_add_scatter:
			S += LS.signal(T_fs, 1650, 200, 10)
		
		temp_b, temp_b_count, temp_b_axis = LS.binning(S, T_bin, M, last_bin)
				
		if B_exists:
			B += temp_b
			B_count += temp_b_count
			B_axis = temp_b_axis
		else:
			B = temp_b
			B_count = temp_b_count
			B_axis = temp_b_axis	
			B_exists = True

	sum_bins = numpy.sum(B_count, axis=1)			
	print("  " + str(len(sum_bins) - len(sum_bins[numpy.where(sum_bins)])) + " unfilled bins")
		
	R, R_axis = LS.construct_r(B, B_count, B_axis, M) 
	
	plt.figure()
	plt.plot(R_axis, R)
	plt.show()
	
	R -= numpy.mean(R)
	
	F = croc.Resources.Mathematics.fourier(R, zero_in_middle = False, first_correction = True, zeropad_to = last_bin * zeropad_by, window_function = "none", window_length = 0, flag_plot = False)
		
	dt = (R_axis[1] - R_axis[0]) * 632/299.792458
	
	F_axis = croc.Resources.Mathematics.make_ft_axis(len(F), dt, undersampling = 0, normalized_to_period = 0, zero_in_middle = False)
	
	F = numpy.real(F[:len(F)/2])
	F_axis = F_axis[:len(F)]	

	if flag_plot:
		plt.figure()
		plt.plot(F_axis, F)
		plt.title(title)
#		plt.xlim(1500, 1800)
		plt.show()