예제 #1
0
 def __call__(self, frame_set, mdf=False):
     #print frame_set
     if mdf:
         frame_set = frame_set[:, 0]
     frame_set = np.asarray(frame_set) - self.init_frame
     thetas = frame_set * self.ang_vel + self.ang_off
     radii = frame_set * self.rad_vel + self.rad_off
     #coords in obital axis frame
     frame_xs = radii * np.cos(thetas)
     frame_ys = radii * np.sin(thetas)
     frame_zs = frame_set * self.hel_vel + self.hel_off
     frame_coords = np.asarray([frame_set, frame_xs, frame_ys, frame_zs]).T
     #print frame_coords
     #transform in to world coords
     world_coords = []
     for bundle in np.atleast_2d(frame_coords):
         centre = self.centre_func(bundle[0])
         frame_coord = bundle[1:]
         frame_coord.shape = (3, 1)
         centre.shape = 3
         world_coords.append(
             coord_transform(self.basis[0],
                             self.basis[1],
                             self.basis[2],
                             centre,
                             frame_coord,
                             inv=False,
                             homog=False,
                             tran=True))
     world_coords = np.asarray(world_coords)
     world_coords.shape = (len(world_coords), 3)
     #print "obital path call"
     return world_coords
예제 #2
0
    def get_odom_delta(self, pose):
        """Calculates the delta of the odometry position since the last time called.

        Returns None the first time, and a 3x1 state matrix thereafter.

        """
        # Convert the pose into matrix form.
        y_odom = column_vector(pose.x, pose.y, pose.theta)
        # None is the fallback in case we can't get an actual delta.
        odom_delta = None
        if self.odom_state is not None:
            # Transform the sensor state into the map frame.
            y = coord_transform(y_odom, self.odom_origin)
            # Calculate the change odom state, in map coords (delta y).
            odom_delta = y - coord_transform(self.odom_state, self.odom_origin)
        # Update the stored odom state.
        self.odom_state = y_odom
        # Get the odom frame origin in the map frame and store it for next time.
        self.odom_origin = get_offset(self.state, self.odom_state)
        return odom_delta
예제 #3
0
파일: ekf.py 프로젝트: corobotics/corobots
    def get_odom_delta(self, pose):
        """Calculates the delta of the odometry position since the last time called.

        Returns None the first time, and a 3x1 state matrix thereafter.

        """
        # Convert the pose into matrix form.
        y_odom = column_vector(pose.x, pose.y, pose.theta)
        # None is the fallback in case we can't get an actual delta.
        odom_delta = None
        if self.odom_state is not None:
            # Transform the sensor state into the map frame.
            y = coord_transform(y_odom, self.odom_origin)
            # Calculate the change odom state, in map coords (delta y).
            odom_delta = y - coord_transform(self.odom_state, self.odom_origin)
        # Update the stored odom state.
        self.odom_state = y_odom
        # Get the odom frame origin in the map frame and store it for next time.
        self.odom_origin = get_offset(self.state, self.odom_state)
        return odom_delta
예제 #4
0
    def get_odom_delta(self, pose):
        # odom_state is the previous x, y, theta of odom_pose
        # y_odom is the current x, y, theta of odom_pose
        # odom_origin kind keeps track of all the odom changes till date

        y_odom = column_vector(pose.x, pose.y, pose.theta)

        odom_delta = None

        if self.odom_state is not None:
            # y = y_odom * rot(odom_origin.theta) + odom_origin
            y = coord_transform(y_odom, self.odom_origin)
            # current change - previous change
            odom_delta = y - coord_transform(self.odom_state, self.odom_origin)

        self.odom_state = y_odom
        # these two should be exactly the same. Using y_odom to
        # differentiate between previous and new odom values
        #self.odom_origin = get_offset(self.state, self.odom_state)
        self.odom_origin = get_offset(self.state, y_odom)
        return odom_delta
예제 #5
0
	def get_odom_delta(self, pose):
		# odom_state is the previous x, y, theta of odom_pose
		# y_odom is the current x, y, theta of odom_pose
		# odom_origin kind keeps track of all the odom changes till date
		
		y_odom = column_vector(pose.x, pose.y, pose.theta)

		odom_delta = None
		
		if self.odom_state is not None:
			# y = y_odom * rot(odom_origin.theta) + odom_origin
			y = coord_transform(y_odom, self.odom_origin)
			# current change - previous change			
			odom_delta = y - coord_transform(self.odom_state, self.odom_origin)

		self.odom_state = y_odom
		# these two should be exactly the same. Using y_odom to 
		# differentiate between previous and new odom values
		#self.odom_origin = get_offset(self.state, self.odom_state)
		self.odom_origin = get_offset(self.state, y_odom)
		return odom_delta
 def __call__(self, frame_set, mdf=False):
     '''generate the coordinates for given frame numbers
     Args:
         frame_set [array/real]: frame number/s to calculate the new coords for
         mdf (optional) [bool]: if the frames given are multidimentional, take only the
             first column. Blame numpy.piecewise for requiring the same array sizes for
             input and output >:|
     Returns:
         coords [array]: numpy array of coords [x,y,z] for new frame numbers'''
     if mdf:
         frame_set = frame_set[:, 0]
     frame_set = np.asarray(frame_set) - self.init_frame
     thetas = frame_set * self.ang_vel + self.ang_off
     radii = frame_set * self.rad_vel + self.rad_off
     #coords in obital axis frame
     frame_xs = radii * np.cos(thetas)
     frame_ys = radii * np.sin(thetas)
     frame_zs = frame_set * self.hel_vel + self.hel_off
     frame_coords = np.asarray([frame_set, frame_xs, frame_ys, frame_zs]).T
     #print frame_coords
     #transform in to world coords
     world_coords = []
     for bundle in np.atleast_2d(frame_coords):
         centre = self.centre_func(bundle[0])
         frame_coord = bundle[1:]
         frame_coord.shape = (3, 1)
         centre.shape = 3
         world_coords.append(
             coord_transform(self.basis[0],
                             self.basis[1],
                             self.basis[2],
                             centre,
                             frame_coord,
                             inv=False,
                             homog=False,
                             tran=True))
     world_coords = np.asarray(world_coords)
     world_coords.shape = (len(world_coords), 3)
     #print "obital path call"
     return world_coords
예제 #7
0
def story_board(txt_name, path_file, sim):

	''' This function produce a soryboard of all the frames specified on a flight path, 
	saves as PNG files in the directory where the program is run

	Args:

		 path file:A txt file of the flight path in the form frame, expansion factor, coordinates, x_basis, y_basis, z_basis
		 txt_name:The name or relative file path of the txt file

	 '''
	 #SQL to grab from the database 
	SQL = """
		SELECT
			PROG.GalaxyID as ID,
			PROG.DescendantID as DesID,
			DES.GalaxyID,
			PROG.SnapNum,
			PROG.MassType_DM,
			(PROG.CentreOfPotential_x * %0.5f) as x,
			(PROG.CentreOfPotential_y * %0.5f) as y,
			(PROG.CentreOfPotential_z * %0.5f) as z,
			PROG.Redshift
		FROM
			%s_Subhalo as PROG with(forceseek),
			%s_Subhalo as DES

		WHERE
			DES.SnapNum = 28 and
			DES.MassType_DM > 1.0e10 and
			PROG.GalaxyID between DES.GalaxyID and DES.LastProgID 

		ORDER BY
			PROG.GalaxyID,
			PROG.SnapNum
	""" % (h,h,h, sim, sim)

	#        PROG.MassType_DM > 1.0e11 and
	filename = "%s_DBS.p" % sim
	boxsize = 25 * h
	dbs_data = dbsPull(SQL, filename)

	frame, ts, xs, ys, zs, b1,b2,b3,b4,b5,b6,b7,b8,b9 = np.loadtxt(path_file, unpack=True)
	z_basis = np.transpose(np.asarray([b7, b8, b9]))
	y_basis = np.transpose(np.asarray([b4, b5, b6]))
	x_basis = np.transpose(np.asarray([b1, b2, b3]))
	line_coords = np.transpose(np.asarray([xs, ys, zs]))



	fig = plt.figure()
	#to loop over every frame which will be plot on the story board
	for i in range(len(frame)):
		print "creating image: " + str(i)
		#to find the new camera position, cam_pos, on the path
		cam_position = [xs[i], ys[i], zs[i]]
		x_bas = x_basis[i]
		y_bas = y_basis[i]
		z_bas = z_basis[i]
		scale_factor = ts[i]

		#wrap coordinates image data get center image manipulations preiodic wrap
		centre = utils.get_centre([x_bas,y_bas,z_bas], cam_position, region)

		#all the galaxies posistions at the scale factor of interest
		All_galaxies = utils.gal_interpolation(scale_factor, dbs_data)
		All_galaxies[:,[3,4,5]] = utils.periodic_wrap(All_galaxies[:,[3,4,5]], boxsize, centre)

		#transforms into the camera view
		galaxies_trans = coord_transform(x_bas, y_bas, z_bas, cam_position, All_galaxies[:,[3,4,5]])
		galaxies_afterT = np.transpose(galaxies_trans)
		galaxies_to_plot = perspective_transfomation(galaxies_trans, region)

		#this is to catch any frames that are of zero lenght i.e. no galaxies in view 
		if len(galaxies_to_plot) >= 1:

			
			#to find the mass and distances of the galaxies in order to scale size
			indexList = np.asarray(galaxies_to_plot[:,4], dtype=int)
			galaxZs = galaxies_afterT[indexList][:,2]
			galaxYs = galaxies_afterT[indexList][:,1]
			galaxXs = galaxies_afterT[indexList][:,0]
			galZsMass = All_galaxies[indexList][:,2]
			dist = (galaxZs**2 + galaxYs**2 + galaxXs**2)**0.5

			#the relative sizes of the galaxies, change if you want to adjust
			perspec = []
			perspec = 1./dist**3
			perspec *= (galZsMass)**0.43
			perspec.shape = (1, len(perspec))


			galaxies_to_plot = np.asarray(sorted(np.concatenate((galaxies_to_plot, perspec.T), axis=1), key=lambda coords: -coords[2]))
			
			#if you want to plot the images in behind the plot uncomment this line below 
			#img = imread("gas_%06i.png"%(i))
			plt.scatter(galaxies_to_plot[:,0],galaxies_to_plot[:,1],marker='o', s=galaxies_to_plot[:,5], c='#7E317B',edgecolors='k')
			plt.ylim( 0, region[1])
			plt.xlim( - region[0]/2., region[0]/2.)
			plt.ylim( -1., 1.)
			plt.xlim( - 1., 1.)
			#if you want to plot the images in behind the plot uncomment this line below 
			#plt.imshow(img,extent=[-1.,1.,-1.,1.], aspect='auto')
			plt.savefig(txt_name + str(i))
			plt.clf()

		else:
			#img = imread("gas_%06i.png"%(i))
			plt.scatter(0.0,0.0, s=0.0)
			plt.ylim( -1., 1.)
			plt.xlim( - 1., 1.)
			#plt.imshow(img,extent=[-1.,1.,-1.,1.], aspect='auto')
			plt.savefig(txt_name + str(i))
			plt.clf()