Ejemplo n.º 1
0
def rv_pqw(k, p, ecc, nu):
    """Returns r and v vectors in perifocal frame.

    """
    r_pqw = (np.array([cos(nu), sin(nu), 0 * nu]) * p / (1 + ecc * cos(nu))).T
    v_pqw = (np.array([-sin(nu), (ecc + cos(nu)), 0]) * sqrt(k / p)).T
    return r_pqw, v_pqw
Ejemplo n.º 2
0
def rv_pqw(k, p, ecc, nu):
    r"""Returns r and v vectors in perifocal frame.

    .. math::

        \vec{r} = \frac{h^2}{\mu}\frac{1}{1 + e\cos(\theta)}\begin{bmatrix}
        \cos(\theta)\\
        \sin(\theta)\\
        0
        \end{bmatrix} \\\\\\

        \vec{v} = \frac{h^2}{\mu}\begin{bmatrix}
        -\sin(\theta)\\
        e+\cos(\theta)\\
        0
        \end{bmatrix}

    Parameters
    ----------
    k : float
        Standard gravitational parameter (km^3 / s^2).
    p : float
        Semi-latus rectum or parameter (km).
    ecc : float
        Eccentricity.
    nu: float
        True anomaly (rad).

    Returns
    -------

    r: ndarray
        Position. Dimension 3 vector
    v: ndarray
        Velocity. Dimension 3 vector

    Examples
    --------
    >>> from poliastro.constants import GM_earth
    >>> k = GM_earth #Earth gravitational parameter

    >>> ecc = 0.3 #Eccentricity
    >>> h = 60000e6 #Angular momentum of the orbit [m^2]/[s]
    >>> nu = np.deg2rad(120) #True Anomaly [rad]
    >>> p = h**2 / k #Parameter of the orbit
    >>> r, v = rv_pqw(k, p, ecc, nu)

    >>> #Printing the results
    r = [-5312706.25105345  9201877.15251336    0] [m]
    v = [-5753.30180931 -1328.66813933  0] [m]/[s]

    Note
    ----

    These formulas can be checked at Curtis 3rd. Edition, page 110. Also the
    example proposed is 2.11 of Curtis 3rd Edition book.
    """
    r_pqw = (np.array([cos(nu), sin(nu), 0 * nu]) * p / (1 + ecc * cos(nu))).T
    v_pqw = (np.array([-sin(nu), (ecc + cos(nu)), 0]) * sqrt(k / p)).T
    return r_pqw, v_pqw
Ejemplo n.º 3
0
def rv_pqw(k, p, ecc, nu):
    r"""Returns r and v vectors in perifocal frame.

    .. math::

        \vec{r} = \frac{h^2}{\mu}\frac{1}{1 + e\cos(\theta)}\begin{bmatrix}
        \cos(\theta)\\
        \sin(\theta)\\
        0
        \end{bmatrix} \\\\\\

        \vec{v} = \frac{h^2}{\mu}\begin{bmatrix}
        -\sin(\theta)\\
        e+\cos(\theta)\\
        0
        \end{bmatrix}

    Parameters
    ----------
    k : float
        Standard gravitational parameter (km^3 / s^2).
    p : float
        Semi-latus rectum or parameter (km).
    ecc : float
        Eccentricity.
    nu: float
        True anomaly (rad).

    Returns
    -------

    r: ndarray
        Position. Dimension 3 vector
    v: ndarray
        Velocity. Dimension 3 vector

    Examples
    --------
    >>> from poliastro.constants import GM_earth
    >>> k = GM_earth #Earth gravitational parameter

    >>> ecc = 0.3 #Eccentricity
    >>> h = 60000e6 #Angular momentum of the orbit [m^2]/[s]
    >>> nu = np.deg2rad(120) #True Anomaly [rad]
    >>> p = h**2 / k #Parameter of the orbit
    >>> r, v = rv_pqw(k, p, ecc, nu)

    >>> #Printing the results
    r = [-5312706.25105345  9201877.15251336    0] [m]
    v = [-5753.30180931 -1328.66813933  0] [m]/[s]

    Note
    ----

    These formulas can be checked at Curtis 3rd. Edition, page 110. Also the
    example proposed is 2.11 of Curtis 3rd Edition book.
    """
    r_pqw = (np.array([cos(nu), sin(nu), 0 * nu]) * p / (1 + ecc * cos(nu))).T
    v_pqw = (np.array([-sin(nu), (ecc + cos(nu)), 0]) * sqrt(k / p)).T
    return r_pqw, v_pqw
Ejemplo n.º 4
0
def gauss_from_twiss(emit, beta, alpha):
    phi = 2 * pi * np.random.rand()
    u = np.random.rand()
    a = sqrt(-2 * np.log((1 - u)) * emit)
    x = a * sqrt(beta) * cos(phi)
    xp = -a / sqrt(beta) * (sin(phi) + alpha * cos(phi))
    return (x, xp)
Ejemplo n.º 5
0
def rv_pqw(k, p, ecc, nu):
    """Returns r and v vectors in perifocal frame.

    """
    r_pqw = (np.array([cos(nu), sin(nu), 0 * nu]) * p / (1 + ecc * cos(nu))).T
    v_pqw = (np.array([-sin(nu), (ecc + cos(nu)), 0]) * sqrt(k / p)).T
    return r_pqw, v_pqw
Ejemplo n.º 6
0
def _cubic_smooth_coeff(signal, lamb):
    rho, omega = _coeff_smooth(lamb)
    cs = 1 - 2 * rho * cos(omega) + rho * rho
    K = len(signal)
    yp = zeros((K, ), signal.dtype.char)
    k = arange(K)
    yp[0] = (_hc(0, cs, rho, omega) * signal[0] +
             add.reduce(_hc(k + 1, cs, rho, omega) * signal))

    yp[1] = (_hc(0, cs, rho, omega) * signal[0] +
             _hc(1, cs, rho, omega) * signal[1] +
             add.reduce(_hc(k + 2, cs, rho, omega) * signal))

    for n in range(2, K):
        yp[n] = (cs * signal[n] + 2 * rho * cos(omega) * yp[n - 1] -
                 rho * rho * yp[n - 2])

    y = zeros((K, ), signal.dtype.char)

    y[K - 1] = add.reduce(
        (_hs(k, cs, rho, omega) + _hs(k + 1, cs, rho, omega)) * signal[::-1])
    y[K - 2] = add.reduce(
        (_hs(k - 1, cs, rho, omega) + _hs(k + 2, cs, rho, omega)) *
        signal[::-1])

    for n in range(K - 3, -1, -1):
        y[n] = (cs * yp[n] + 2 * rho * cos(omega) * y[n + 1] -
                rho * rho * y[n + 2])

    return y
Ejemplo n.º 7
0
def gauss_from_twiss(emit, beta, alpha):
    phi = 2*pi * np.random.rand()
    u = np.random.rand()
    a = sqrt(-2*np.log( (1-u)) * emit)
    x = a * sqrt(beta) * cos(phi)
    xp = -a / sqrt(beta) * ( sin(phi) + alpha * cos(phi) )
    return (x, xp)
Ejemplo n.º 8
0
def _cubic_smooth_coeff(signal, lamb):
    rho, omega = _coeff_smooth(lamb)
    cs = 1 - 2 * rho * cos(omega) + rho * rho
    K = len(signal)
    yp = zeros((K,), signal.dtype.char)
    k = arange(K)
    yp[0] = (_hc(0, cs, rho, omega) * signal[0] +
             add.reduce(_hc(k + 1, cs, rho, omega) * signal))

    yp[1] = (_hc(0, cs, rho, omega) * signal[0] +
             _hc(1, cs, rho, omega) * signal[1] +
             add.reduce(_hc(k + 2, cs, rho, omega) * signal))

    for n in range(2, K):
        yp[n] = (cs * signal[n] + 2 * rho * cos(omega) * yp[n - 1] -
                 rho * rho * yp[n - 2])

    y = zeros((K,), signal.dtype.char)

    y[K - 1] = add.reduce((_hs(k, cs, rho, omega) +
                           _hs(k + 1, cs, rho, omega)) * signal[::-1])
    y[K - 2] = add.reduce((_hs(k - 1, cs, rho, omega) +
                           _hs(k + 2, cs, rho, omega)) * signal[::-1])

    for n in range(K - 3, -1, -1):
        y[n] = (cs * yp[n] + 2 * rho * cos(omega) * y[n + 1] -
                rho * rho * y[n + 2])

    return y
Ejemplo n.º 9
0
 def integrand(bt, x):
     global a, st, G, lbd, ym, kp, c, var
     fun=-1
     if var==1:
         fun=polint(bt)*cos(bt*x)*(lbd+2*G)*(exp(bt*b)*(kp**2-1-2*bt*b+2*kp*bt*b)+exp(-bt*b)*(kp**2-1+2*bt*b-2*kp*bt*b))/((kp-1)*(lbd*(kp*exp(2*bt*b)+kp*exp(-2*bt*b)+2)+G*kp*(exp(2*bt*b)+exp(-2*bt*b)))+2*G*(kp**2+kp+4*bt**2 * b **2 -2))
     elif var==2:
         fun=polint(bt)*cos(bt*x)*(G*(exp(bt*b)*(kp**2-kp+2*kp*bt*b)-exp(-bt*b)*(kp**2-kp-2*kp*bt*b))+lbd*(kp**2-kp)*(exp(bt*b)-exp(-bt*b)))/((kp**2-kp)*(lbd+G)*sinh(2*bt*b)+4*kp*G*b*bt)
     return fun
Ejemplo n.º 10
0
def get_right_ascension(app_long: FlexNum, oblique_corr: FlexNum):
    """ calculates the suns right ascension angle """

    sal = radians(app_long)
    oc = radians(oblique_corr)

    right_ascension = degrees(arctan2(cos(oc) * sin(sal), cos(sal)))
    return right_ascension
Ejemplo n.º 11
0
def get_zenith(declination: FlexNum, hour_angle: FlexNum, lat_r: FlexNum):
    """ calculates solar zenith angle at ref_datetime"""

    d = radians(declination)
    ha = radians(hour_angle)
    lat = lat_r

    zenith = degrees(arccos(sin(lat) * sin(d) + cos(lat) * cos(d) * cos(ha)))
    return zenith
Ejemplo n.º 12
0
def blackman(M):
    """blackman(M) returns the M-point Blackman window.
    """
    if M < 1:
        return array([])
    if M == 1:
        return ones(1, float)
    n = arange(0,M)
    return 0.42-0.5*cos(2.0*pi*n/(M-1)) + 0.08*cos(4.0*pi*n/(M-1))
Ejemplo n.º 13
0
def get_distance(locA, locB):
    # use haversine forumla
    print "ayyo"
    earth_rad = 6371.0
    dlat = deg2rad(locB[0] - locA[0])
    dlon = deg2rad(locB[1] - locA[1])
    a = sin(dlat / 2) * sin(dlat / 2) + \
        cos(deg2rad(locA[0])) * cos(deg2rad(locB[0])) * \
        sin(dlon / 2) * sin(dlon / 2)
    c = 2 * arctan2(sqrt(a), sqrt(1 - a))
    return earth_rad * c
Ejemplo n.º 14
0
def get_distance(locA, locB):
    # use haversine forumla
    print "ayyo"
    earth_rad = 6371.0
    dlat = deg2rad(locB[0] - locA[0])
    dlon = deg2rad(locB[1] - locA[1])
    a = sin(dlat / 2) * sin(dlat / 2) + \
        cos(deg2rad(locA[0])) * cos(deg2rad(locB[0])) * \
        sin(dlon / 2) * sin(dlon / 2)
    c = 2 * arctan2(sqrt(a), sqrt(1 - a))
    return earth_rad * c
Ejemplo n.º 15
0
def get_hour_angle_sunrise(declination: FlexNum, lat_r: FlexNum):
    """ calculates the hour angle of sunrise """

    d = radians(declination)
    lat = lat_r  # radians

    hour_angle_sunrise = degrees(
        arccos(
            (cos(radians(90.833)) / (cos(lat) * cos(d)) - tan(lat) * tan(d))))

    return hour_angle_sunrise
Ejemplo n.º 16
0
def lat_lon_alt_to_ecef_xyz(R):
    """
    see [1] p. 512
    :param R: (φ,θ,h) -- lat [deg], lon [deg], alt in WGS84 (numpy array)
    :return:  (X,Y,Z) -- coordinates in ECEF (numpy array)
    """
    # WGS 84 constants
    a2 = 6378137.0**2  # Equatorial Radius [m]
    b2 = 6356752.314245**2  # Polar Radius [m]
    radius = lambda phi: sqrt(a2 * (cos(phi))**2 + b2 * (sin(phi))**2)
    f, t, h = np.deg2rad(R[0]), np.deg2rad(R[1]), R[2]
    X = cos(t) * cos(f) * (h + a2 / radius(f))
    Y = sin(t) * cos(f) * (h + a2 / radius(f))
    Z = sin(f) * (h + b2 / radius(f))
    return np.array([X, Y, Z])
Ejemplo n.º 17
0
def lat_lon_alt_to_ecef_xyz(R):
    """
    see [1] p. 512
    :param R: (φ,θ,h) -- lat [deg], lon [deg], alt in WGS84 (numpy array)
    :return:  (X,Y,Z) -- coordinates in ECEF (numpy array)
    """
    # WGS 84 constants
    a2 = 6378137.0 ** 2  # Equatorial Radius [m]
    b2 = 6356752.314245 ** 2  # Polar Radius [m]
    radius = lambda phi: sqrt(a2 * (cos(phi)) ** 2 + b2 * (sin(phi)) ** 2)
    f, t, h = np.deg2rad(R[0]), np.deg2rad(R[1]), R[2]
    X = cos(t) * cos(f) * (h + a2 / radius(f))
    Y = sin(t) * cos(f) * (h + a2 / radius(f))
    Z = sin(f) * (h + b2 / radius(f))
    return np.array([X, Y, Z])
Ejemplo n.º 18
0
    def drawCreatures(self):
        for i in range(0, len(self.gameField.creatures)):
            c = self.gameField.creatures[i]

            # creature
            drawEfCircle(FIELD_X_OFFSET + c.xy.x, c.xy.y, CREATURE_SIZE, 10, GL_POLYGON, 0,
                         c.fitness / STARTING_FITNESS, 0)
            # creature direction
            drawLine(int(FIELD_X_OFFSET + c.xy.x), int(c.xy.y),
                     int(FIELD_X_OFFSET + (c.xy.x + cos(c.direction) * CREATURE_SIZE)),
                     int((c.xy.y + sin(c.direction) * CREATURE_SIZE)), 1, 0.3, 0.3, 1)
            # creature's sight direction
            if not (c.debug_info[0] > 10000):  # inf
                drawLine(int(FIELD_X_OFFSET + c.xy.x), int(c.xy.y),
                         int(FIELD_X_OFFSET + (c.xy.x + cos(c.debug_info[1]) * c.debug_info[0])),
                         int((c.xy.y + sin(c.debug_info[1]) * c.debug_info[0])), 1, 1, 0.3, 0.3)
Ejemplo n.º 19
0
def basis_function(k):
    k_00 = 1e-1
    if abs(k) <= k_00:
        return 1 - 1 / 18 * k**2 + 1 / 792 * k**4
    else:
        return 105.0 / k**7 * (k * (k * k - 15) * cos(k) -
                               (6 * k * k - 15) * sin(k))
Ejemplo n.º 20
0
def get_oblique_corr(ajc: FlexNum, oblique_mean_ellipse: FlexNum):
    """ calculates the oblique correction """

    ome = oblique_mean_ellipse

    oblique_corr = ome + 0.00256 * cos(radians(125.04 - 1934.136 * ajc))
    return oblique_corr
Ejemplo n.º 21
0
 def cos(self):
     if self.unit.is_angle():
         return umath.cos(
             self.value *
             self.unit.conversion_factor_to(_unit_table['rad']))
     else:
         raise TypeError('Argument of cos must be an angle')
Ejemplo n.º 22
0
def get_rad_vector(earth_eccent: FlexNum, true_anom: FlexNum):
    """ calculates incident radiation vector to surface at ref_datetime (AUs)"""

    ec = earth_eccent
    ta = radians(true_anom)

    rad_vector = (1.000001018 * (1 - ec**2)) / (1 + ec * cos(ta))
    return rad_vector
Ejemplo n.º 23
0
 def integrand(ksi,bt):
     global pol
     fun=pol[len(pol)-1]
     for i in range(0,len(pol)-1):
         fun *= ksi
         fun += pol[len(pol)-2-i]
     fun=fun*cos(bt*ksi)
     return fun
Ejemplo n.º 24
0
    def update_metric(self, pos_mat, ang_vec):
        #This method allows us to update the flocking model with the Metric model
        #Each new velocity is constructed by averaging over all of the velocities within
        #the radius selected, self.r.
        #Inputs -- x-coordinates, y-coordinates, trajectories for time = t
        #Outputs -- x-coordinates, y-coordinates, trajectories for time = t + (delta t)
        avg_sin = 0 * ang_vec
        avg_cos = 0 * ang_vec

        for j in range(0, self.N):
            #find distances for all particles
            dist_vec = self.calc_dist(pos_mat, j)

            #find indicies that are within the radius
            ngbs_idx_vec = np.where(dist_vec <= self.r)[0]

            if len(ngbs_idx_vec) == 0:
                avg_sin[j] = 0
                avg_cos[j] = 0
            else:
                #find average velocity of those inside the radius
                sint = np.average(sin(ang_vec[ngbs_idx_vec]))
                cost = np.average(cos(ang_vec[ngbs_idx_vec]))
                avg_sin[j] = sint
                avg_cos[j] = cost

        #construct the noise
        noise = self.theta_noise()

        #update velocities and positions
        cosi = (self.ep) * avg_cos + (1 - self.ep) * np.cos(ang_vec)
        sini = (self.ep) * avg_sin + (1 - self.ep) * np.sin(ang_vec)
        new_ang_vec = arctan2(sini, cosi) + noise
        mask = self.status_vec == 1
        new_ang_vec[mask] += np.pi
        new_mod_ang_vec = np.mod(new_ang_vec, 2 * np.pi)

        pos_mat[:, 0] = pos_mat[:, 0] + self.dt * self.v * cos(new_mod_ang_vec)
        pos_mat[:, 1] = pos_mat[:, 1] + self.dt * self.v * sin(new_mod_ang_vec)

        #Make sure that the positions are not outside the boundary.
        #If so, correct for periodicity
        pos_mat = self.check_boundary(pos_mat)

        #Outputs returned
        return (pos_mat, new_ang_vec)
Ejemplo n.º 25
0
 def predict_next_state(scenario: Scenario, current: MyState) -> MyState:
     next: MyState = deepcopy(current)
     delta_x: float = cos(
         next.state.orientation) * next.state.velocity * scenario.dt
     delta_y: float = sin(
         next.state.orientation) * next.state.velocity * scenario.dt
     next.state.position[0] += delta_x
     next.state.position[1] += delta_y
     return next
Ejemplo n.º 26
0
def hamming(M):
    """hamming(M) returns the M-point Hamming window.
    """
    if M < 1:
        return array([])
    if M == 1:
        return ones(1,float)
    n = arange(0,M)
    return 0.54-0.46*cos(2.0*pi*n/(M-1))
Ejemplo n.º 27
0
def hamming(M):
    """hamming(M) returns the M-point Hamming window.
    """
    if M < 1:
        return array([])
    if M == 1:
        return ones(1, float)
    n = arange(0, M)
    return 0.54 - 0.46 * cos(2.0 * pi * n / (M - 1))
Ejemplo n.º 28
0
def rotation_matrix(angle, axis):
    c = cos(angle)
    s = sin(angle)
    if axis == 0:
        return np.array([[1.0, 0.0, 0.0], [0.0, c, -s], [0.0, s, c]])
    elif axis == 1:
        return np.array([[c, 0.0, s], [0.0, 1.0, 0.0], [s, 0.0, c]])
    elif axis == 2:
        return np.array([[c, -s, 0.0], [s, c, 0.0], [0.0, 0.0, 1.0]])
    else:
        raise ValueError("Invalid axis: must be one of 'x', 'y' or 'z'")
Ejemplo n.º 29
0
def sunposIntermediate(iYear, iMonth, iDay, dHours, dMinutes, dSeconds):
    # Calculate difference in days between the current Julian Day
    # and JD 2451545.0, which is noon 1 January 2000 Universal Time

    # Calculate time of the day in UT decimal hours
    dDecimalHours = dHours + (dMinutes + dSeconds / 60.0) / 60.0
    # Calculate current Julian Day
    liAux1 = (iMonth - 14) / 12
    liAux2 = (1461 * (iYear + 4800 + liAux1)) / 4 + (
        367 * (iMonth - 2 - 12 * liAux1)) / 12 - (3 * (
            (iYear + 4900 + liAux1) / 100)) / 4 + iDay - 32075
    dJulianDate = liAux2 - 0.5 + dDecimalHours / 24.0
    # Calculate difference between current Julian Day and JD 2451545.0
    dElapsedJulianDays = dJulianDate - 2451545.0

    # Calculate ecliptic coordinates (ecliptic longitude and obliquity of the
    # ecliptic in radians but without limiting the angle to be less than 2*Pi
    # (i.e., the result may be greater than 2*Pi)
    dOmega = 2.1429 - 0.0010394594 * dElapsedJulianDays
    dMeanLongitude = 4.8950630 + 0.017202791698 * dElapsedJulianDays  # Radians
    dMeanAnomaly = 6.2400600 + 0.0172019699 * dElapsedJulianDays
    dEclipticLongitude = dMeanLongitude + 0.03341607 * sin(
        dMeanAnomaly) + 0.00034894 * sin(
            2 * dMeanAnomaly) - 0.0001134 - 0.0000203 * sin(dOmega)
    dEclipticObliquity = 0.4090928 - 6.2140e-9 * dElapsedJulianDays + 0.0000396 * cos(
        dOmega)

    # Calculate celestial coordinates ( right ascension and declination ) in radians
    # but without limiting the angle to be less than 2*Pi (i.e., the result may be
    # greater than 2*Pi)
    dSin_EclipticLongitude = sin(dEclipticLongitude)
    dY = cos(dEclipticObliquity) * dSin_EclipticLongitude
    dX = cos(dEclipticLongitude)
    dRightAscension = arctan2(dY, dX)
    if dRightAscension < 0.0:
        dRightAscension = dRightAscension + 2 * pi
    dDeclination = arcsin(sin(dEclipticObliquity) * dSin_EclipticLongitude)

    dGreenwichMeanSiderealTime = 6.6974243242 + 0.0657098283 * dElapsedJulianDays + dDecimalHours
    return (dRightAscension, dDeclination, dGreenwichMeanSiderealTime)
Ejemplo n.º 30
0
def get_air_mass(zenith: FlexNum, method: str = None):
    """
    air mass is a concept from the solar power world that accounts for the mass of air
    between a point on the earths surface and the sun as a function of zenith angle.

    This method implements the Kasten-Young formula as well as a simple spherical approximation
    https://www.osapublishing.org/ao/abstract.cfm?uri=ao-28-22-4735

    :param method: Either "kasten-young" or "spherical".
    """

    if method is None:
        method = "kasten-young"  # default

    if method == "spherical":
        z_r = radians(zenith)
        r = CONSTANTS.earth_radius / CONSTANTS.atm_height
        return (r * (cos(z_r)**2) + (2 * r) + 1)**0.5 - (r * cos(z_r))

    elif method == "kasten-young":
        z_r = radians(zenith)
        return 1.0 / (cos(z_r) + 0.50572 * (96.07995 - zenith)**(-1.6364))
Ejemplo n.º 31
0
 def center_to_right_bottom_pos(center_pos: ndarray, orientation: float, car_length: float, car_width: float) \
         -> Tuple[float, float]:
     """
     Calculates the coordinates of the right bottom point of a rectangle representing a car.
     :param center_pos: The coordinate of the center point of the rectangle representing a car.
     :param orientation: The orientation in radians.
     :param car_length: The length of the car.
     :param car_width: The width of the car.
     :return: The position of the right bottom point of a rectangle representing a car.
     """
     # For the following variables see CenterToLeftBottom.ggb
     translation_rho: float = 0.5 * sqrt(square(car_length) + square(car_width))  # h
     gamma: float = cos((0.5 * car_length) / translation_rho)  # cos(g / h)
     translation_phi: float = pi + orientation + gamma
     return tuple(center_pos + CoordsHelp.pol2cart(translation_rho, translation_phi))
Ejemplo n.º 32
0
    def hann(self, signal, half=False):
        """
        Apply a Hann windowing on raw signal, before FFT.

        """
        points = len(signal)

        # Hanning from Herschel (half window)"""
        # hann = 0.5 * (1.0 + cos ((PI*i) / channels))"""
        if half:
            iarr = num.arange(points) * math.pi / points
            iarr = 0.5 + 0.5 * math.cos(iarr)
        # Hanning from numpy (full window)"""
        else:
            iarr = np.hanning(points)
        hann = signal * iarr

        return hann
Ejemplo n.º 33
0
def m_from_twiss(Tw1, Tw2):
    #% Transport matrix M for two sets of Twiss parameters (alpha,beta,psi)
    b1 = Tw1[1]
    a1 = Tw1[0]
    psi1 = Tw1[2]
    b2 = Tw2[1]
    a2 = Tw2[0]
    psi2 = Tw2[2]

    psi = psi2-psi1
    cosp = cos(psi)
    sinp = sin(psi)
    M = np.zeros((2, 2))
    M[0, 0] = sqrt(b2/b1)*(cosp+a1*sinp)
    M[0, 1] = sqrt(b2*b1)*sinp
    M[1, 0] = ((a1-a2)*cosp-(1+a1*a2)*sinp)/sqrt(b2*b1)
    M[1, 1] = sqrt(b1/b2)*(cosp-a2*sinp)
    return M
Ejemplo n.º 34
0
def get_equation_of_time(oblique_corr: FlexNum, geomean_long: FlexNum,
                         geomean_anom: FlexNum, earth_eccent: FlexNum):
    """ calculates the equation of time in minutes """

    oc = radians(oblique_corr)
    gml = radians(geomean_long)
    gma = radians(geomean_anom)
    ec = earth_eccent

    vary = tan(oc / 2)**2

    equation_of_time = 4 * degrees(
        vary * sin(2 * gml) - 2 * ec * sin(gma) + \
        4 * ec * vary * sin(gma) * cos(2 * gml) - \
        0.5 * vary * vary * sin(4 * gml) - \
        1.25 * ec * ec * sin(2 * gma))

    return equation_of_time
Ejemplo n.º 35
0
    def hann(self, signal, half=False):
        """
        Apply a Hann windowing on raw signal, before FFT.

        """
        points = len(signal)

        # Hanning from Herschel (half window)"""
        # hann = 0.5 * (1.0 + cos ((PI*i) / channels))"""
        if half:
            iarr = num.arange(points) * math.pi / points
            iarr = 0.5 + 0.5 * math.cos(iarr)
        # Hanning from numpy (full window)"""
        else:
            iarr = np.hanning(points)
        hann = signal * iarr

        return hann
Ejemplo n.º 36
0
def m_from_twiss(Tw1, Tw2):
    #% Transport matrix M for two sets of Twiss parameters (alpha,beta,psi)
    b1 = Tw1[1]
    a1 = Tw1[0]
    psi1 = Tw1[2]
    b2 = Tw2[1]
    a2 = Tw2[0]
    psi2 = Tw2[2]

    psi = psi2 - psi1
    cosp = cos(psi)
    sinp = sin(psi)
    M = np.zeros((2, 2))
    M[0, 0] = sqrt(b2 / b1) * (cosp + a1 * sinp)
    M[0, 1] = sqrt(b2 * b1) * sinp
    M[1, 0] = ((a1 - a2) * cosp - (1 + a1 * a2) * sinp) / sqrt(b2 * b1)
    M[1, 1] = sqrt(b1 / b2) * (cosp - a2 * sinp)
    return M
Ejemplo n.º 37
0
def get_surf_norm_toa_irradiance(sun_surf_angle: FlexNum,
                                 sun_norm_irradiance: FlexNum):
    """
    gets the irradiance intensity normal to a surface.
    If slope and aspect inputs were used this accounts for the angle of the earths surface.
    """

    ssa_r = radians(sun_surf_angle)
    srf = cos(
        ssa_r
    ) * sun_norm_irradiance  # a theta of zero results in full norm irradiance

    # set negative values to zero.
    if isinstance(srf, np.ndarray) and srf.shape:
        srf[srf <= 0] = 0
        return srf
    else:
        return max([srf, 0.0])
Ejemplo n.º 38
0
def waterbag_from_twiss(emit, beta, alpha):
    phi = 2*pi * np.random.rand()
    a = sqrt(emit) * np.random.rand()
    x = a * sqrt(beta) * cos(phi)
    xp = -a / sqrt(beta) * ( sin(phi) + alpha * cos(phi) )
    return (x, xp)
Ejemplo n.º 39
0
def _hs(k, cs, rho, omega):
    c0 = (cs * cs * (1 + rho * rho) / (1 - rho * rho) /
          (1 - 2 * rho * rho * cos(2 * omega) + rho**4))
    gamma = (1 - rho * rho) / (1 + rho * rho) / tan(omega)
    ak = abs(k)
    return c0 * rho**ak * (cos(omega * ak) + gamma * sin(omega * ak))
Ejemplo n.º 40
0
import pickle

#创建二维样本数据
from numpy.core.umath import pi, cos, sin

n = 200

#两个正态分布数据集
class_1 = 0.6 * randn(n,2)
class_2 = 1.2 * randn(n,2) + array([5,1])
labels = hstack((ones(n), -ones(n)))    #Stack arrays in sequence horizontally (column wise).

#用pickle保存
with open('points_normal_test.pkl', 'w') as f:
# with open('points_normal.pkl', 'w') as f:
    pickle.dump(class_1, f)
    pickle.dump(class_2, f)
    pickle.dump(labels,f)

#正态分布,并使数据成环绕状分布
class_1 = 0.6 * randn(n,2)
r = 0.8 * randn(n,1) + 5
angle = 2*pi*randn(n,1)
class_2 = hstack((r*cos(angle), r*sin(angle)))
labels = hstack((ones(n), -ones(n)))

with open('points_ring_test.pkl','w') as f:
# with open('points_ring.pkl','w') as f:
    pickle.dump(class_1, f)
    pickle.dump(class_2, f)
    pickle.dump(labels,f)
Ejemplo n.º 41
0
 def move(self):
     self.__change_angle()
     x = self.x + cos(self.angle) * self.STEP_SIZE
     y = self.y + sin(self.angle) * self.STEP_SIZE
     return self.__change_position(x, y)
Ejemplo n.º 42
0
 def cos(self):
     if self.unit.isAngle():
         return umath.cos(self.value * self.unit.conversionFactorTo(_unit_table["rad"]))
     else:
         raise TypeError("Argument of cos must be an angle")
Ejemplo n.º 43
0
#

numbers = logspace(1, 40, 5)
# [1.00000000e+01 5.62341325e+10 3.16227766e+20 1.77827941e+30
#  1.00000000e+40]
print(numbers)
print("%.2g" % numbers[0])  # 10
print("%.2g" % numbers[1])  # 5.6e+10
print("%.3g" % numbers[2])  # 3.16e+20
print("%.4g" % numbers[3])  # 1.778e+30
print("%.5g" % numbers[4])  # 1e+40

# -------------------------------------------------------------------------------------------------------------

a1 = array([1, 2, 3, 4, 5])
a1 = a1 + 5
print(a1)  # [ 6  7  8  9 10]

a2 = array([6, 1, 9, 3, 2])

a3 = a1 + a2  # vectorized operation
print(a3)  # [12  8 17 12 12]

# min, max, sqrt, pow, sort, etc
print(sin(a1))  # [-0.2794155   0.6569866   0.98935825  0.41211849 -0.54402111]
print(cos(a2))  # [ 0.96017029  0.54030231 -0.91113026 -0.9899925  -0.41614684]
print(log(a3))  # [2.48490665 2.07944154 2.83321334 2.48490665 2.48490665]

a4 = concatenate((a1, a2))
print(a4)  # [ 6  7  8  9 10  6  1  9  3  2]
Ejemplo n.º 44
0
def _hs(k, cs, rho, omega):
    c0 = (cs * cs * (1 + rho * rho) / (1 - rho * rho) /
          (1 - 2 * rho * rho * cos(2 * omega) + rho ** 4))
    gamma = (1 - rho * rho) / (1 + rho * rho) / tan(omega)
    ak = abs(k)
    return c0 * rho ** ak * (cos(omega * ak) + gamma * sin(omega * ak))
Ejemplo n.º 45
0
 def value(self, t):
     return self.A + self.B * (1 / (t - self.t_0) ** self.m +
                               cos(self.omega * log(t - self.t_0) + self.phi))
Ejemplo n.º 46
0
 def dfunc(x):
     return cos(x) - 1
Ejemplo n.º 47
0
def waterbag_from_twiss(emit, beta, alpha):
    phi = 2 * pi * np.random.rand()
    a = sqrt(emit) * np.random.rand()
    x = a * sqrt(beta) * cos(phi)
    xp = -a / sqrt(beta) * (sin(phi) + alpha * cos(phi))
    return (x, xp)
Ejemplo n.º 48
0
 def __call__(self, x):
     "Execute the call behavior."
     return umath.less(umath.absolute(umath.cos(x)), self.eps)