Calculate the center of mass at a given timestep.

        Args:
            time: Time at which the center of mass calculation is performed

        Returns:
            The x- and y-coordinates of the center of mass.
502744
def center_of_mass(self, time):
        
        if self.start_time <= time <= self.end_time:
            diff = time - self.start_time
            valid = np.flatnonzero(self.masks[diff] != 0)
            if valid.size > 0:
                com_x = 1.0 / self.timesteps[diff].ravel()[valid].sum() * np.sum(self.timesteps[diff].ravel()[valid] *
                                                                                 self.x[diff].ravel()[valid])
                com_y = 1.0 / self.timesteps[diff].ravel()[valid].sum() * np.sum(self.timesteps[diff].ravel()[valid] *
                                                                                 self.y[diff].ravel()[valid])
            else:
                com_x = np.mean(self.x[diff])
                com_y = np.mean(self.y[diff])
        else:
            com_x = None
            com_y = None
        return com_x, com_y
943480
def center_of_mass(self):
        
        center = np.zeros(3)
        total_weight = 0
        for site in self:
            wt = site.species.weight
            center += site.coords * wt
            total_weight += wt
        return center / total_weight
466620
def elapse_time(start, end=None, precision=3):
    
    if end is None:
        end = time_module.time()
    return round(end-start, precision)
924000
def _get_coords_by_index(self, coords_array, index):
        
        if hasattr(index, '__iter__'):
            # then we want the center-of-mass coordinates
            # TODO: clean this up
            return np.average([_value(coords_array[i]) for i in index],
                              weights=[self._get_mass_by_index(i) for i in index])
        else:
            return coords_array[index]
25087
def size(self, time):
        
        if self.start_time <= time <= self.end_time:
            return self.masks[time - self.start_time].sum()
        else:
            return 0
694847
def getCenter(self):
        '''
        
        '''

        (left, top), (right, bottom) = self.getCoords()
        x = left + (right - left) / 2
        y = top + (bottom - top) / 2
        return (x, y)
455838
def closest_point(time)
      segment = segments.select { |s| s.contains_time?(time) }
      segment.first
    end
959258
def time_to_number(self, time):
        
        if not isinstance(time, datetime.time):
            raise TypeError(time)
        return ((time.second / 60.0 + time.minute) / 60.0 + time.hour) / 24.0
1316603
def time(ctx, hours, minutes, seconds):
    
    return _time(conversions.to_integer(hours, ctx), conversions.to_integer(minutes, ctx), conversions.to_integer(seconds, ctx))
1027266
def clock(seg, seconds):
    
    interval = 0.5
    for i in range(int(seconds / interval)):
        now = datetime.now()
        seg.text = now.strftime("%H-%M-%S")

        # calculate blinking dot
        if i % 2 == 0:
            seg.text = now.strftime("%H-%M-%S")
        else:
            seg.text = now.strftime("%H %M %S")

        time.sleep(interval)
644263
def xy_time(self) -> Iterator[Tuple[float, float, float]]:
        """"""
        iterator = iter(zip(self.coords, self.timestamp))
        while True:
            next_ = next(iterator, None)
            if next_ is None:
                return
            coords, time = next_
            yield (coords[0], coords[1], time.to_pydatetime().timestamp())
616325
def pendulum_time_to_datetime_time(x: Time) -> datetime.time:
    
    return datetime.time(
        hour=x.hour, minute=x.minute, second=x.second,
        microsecond=x.microsecond,
        tzinfo=x.tzinfo
    )
1361570
def center(self):
        

        if np.all(np.isfinite(self.xyz)):
            return np.mean(self.xyz, axis=0)
408303
def get_last_an_time(self, utc_time):
        

        # Propagate backwards to ascending node
        dt = np.timedelta64(10, 'm')
        t_old = utc_time
        t_new = t_old - dt
        pos0, vel0 = self.get_position(t_old, normalize=False)
        pos1, vel1 = self.get_position(t_new, normalize=False)
        while not (pos0[2] > 0 and pos1[2] < 0):
            pos0 = pos1
            t_old = t_new
            t_new = t_old - dt
            pos1, vel1 = self.get_position(t_new, normalize=False)

        # Return if z within 1 km of an
        if np.abs(pos0[2]) < 1:
            return t_old
        elif np.abs(pos1[2]) < 1:
            return t_new

        # Bisect to z within 1 km
        while np.abs(pos1[2]) > 1:
            # pos0, vel0 = pos1, vel1
            dt = (t_old - t_new) / 2
            t_mid = t_old - dt
            pos1, vel1 = self.get_position(t_mid, normalize=False)
            if pos1[2] > 0:
                t_old = t_mid
            else:
                t_new = t_mid

        return t_mid
991561
def com(self):
        """"""
        return (self.coordinates*self.masses.reshape((-1,1))).sum(axis=0)/self.mass
1126194
def center(self):
        '''
        
        '''
        try:
            return self._center
        except AttributeError:
            pass
        self._center = Point()
        return self._center
1120472
public Double getNearestTime(double timePercentage) {
		//the arrays should be sorted by time so this step is probably not needed
		Double minTime = null;
		Double maxTime = null;
		for (Double t : time) {
			if (minTime == null || t < minTime) {
				minTime = t;
			}
			if (maxTime == null || t > maxTime) {
				maxTime = t;
			}
		}
		Double timeRange = maxTime - minTime;
		Double targetTime = minTime + timePercentage * timeRange;
		Double previousTime = null;
		for (Double t : time) {
			if (previousTime == null || t <= targetTime) {
				previousTime = t;
			} else {
				return previousTime;
			}
		}
		return previousTime;
	}