예제 #1
0
파일: correct.py 프로젝트: yano404/A5tools
    def theta(self, a):
        """
        Arguments
        ---------
        a : angle of rotation [rad]

        Return
        ------
        θ : scattering angle in the lab system [rad]
        """
        D0 = self.D(0.0)
        D = self.D(a)
        Rd = self.R + self.d
        if isinstance(a, (int, float, np.number, uncertainties.core.AffineScalarFunc)):
            return np.sign(a) * umath.acos(
                (D0**2.0 + D**2.0 - 2.0 * Rd**2.0 *
                 (1.0 - umath.cos(a))) / (2.0 * D0 * D)
            )
        elif isinstance(a, np.ndarray):
            return np.sign(a) * unp.arccos(
                (D0**2.0 + D**2.0 - 2.0 * Rd**2.0 *
                 (1.0 - unp.cos(a))) / (2.0 * D0 * D)
            )
        else:
            raise ValueError(
                f"This function not supported for the input types. argument 'a' must be number or array")
예제 #2
0
def inclination(P_days, Ms_Msun, Rs_Rsun, b,
                mp_Mearth=0., ecc=0., omega_deg=0.):
    '''Compute the inclination from the impact parameter and scaled 
    semimajor axis.'''
    sma, omega = semimajoraxis(P_days, Ms_Msun, mp_Mearth), \
                 unumpy.radians(omega_deg)
    a_Rs = AU2m(sma) / Rsun2m(Rs_Rsun)
    return unumpy.degrees(unumpy.arccos(b / a_Rs * \
                                        ((1+ecc*unumpy.sin(omega)) / \
                                         (1-ecc**2))))
예제 #3
0
def e_geo(x, d=0):
    d /= 2
    a = unumpy.sqrt(x**2 + (2 - d) ** 2)
    # Look at geometric_efficiency.png to see what these mean
    h1 = ufloat(2,0.1)
    h2 = ufloat(3,0.1)
    w1 = ufloat(22, 0.1)
    w2 = ufloat(30, 0.1)

    if x < 8:
        c = unumpy.sqrt(((w1 + w2) / 2)**2 + (h2 - h1)**2)
        b = unumpy.sqrt((h2 - d)**2 + ((w1 + w2) / 2 - x)**2)
    else:
        c = w1
        b = unumpy.sqrt((w1 - x)**2 + (h1 - d)**2)
    theta = unumpy.arccos((a**2 + b**2 - c**2) / (2 * a * b))
    return (1 - unumpy.cos(theta / 2)) / 2
예제 #4
0
def arccos(number):
    if isinstance(number, fr.Fraction):
        number = Mixed(number)
    elif isinstance(number, uc.UFloat):
        number = Mixed(number)
    elif isinstance(number, int):
        number = Mixed(number)
    elif isinstance(number, float):
        number = Mixed(number)
    assert isinstance(number, Mixed), \
        "Cannot calculate arccos of object of type %s." % (type(number))
    if isinstance(number.value, uc.UFloat):
        return Mixed(unumpy.arccos(number.value).item())
    elif isinstance(number.value, fr.Fraction):
        return Mixed(np.arccos(float(number.value)))
    elif isinstance(number.value, int):
        return Mixed(np.arccos(number.value))
    elif isinstance(number.value, float):
        return Mixed(np.arccos(number.value))
예제 #5
0
def arccos(number):
    if isinstance(number, fr.Fraction):
        number = Mixed(number)
    elif isinstance(number, uc.UFloat):
        number = Mixed(number)
    elif isinstance(number, int):
        number = Mixed(number)
    elif isinstance(number, float):
        number = Mixed(number)
    assert isinstance(number, Mixed), \
        "Cannot calculate arccos of object of type %s." % (type(number))
    if isinstance(number.value, uc.UFloat):
        return Mixed(unumpy.arccos(number.value).item())
    elif isinstance(number.value, fr.Fraction):
        return Mixed(np.arccos(float(number.value)))
    elif isinstance(number.value, int):
        return Mixed(np.arccos(number.value))
    elif isinstance(number.value, float):
        return Mixed(np.arccos(number.value))
예제 #6
0
def test_broadcast_funcs():
    """
    Test of mathematical functions that work with NumPy arrays of
    numbers with uncertainties.
    """

    x = uncertainties.ufloat((0.2, 0.1))
    arr = numpy.array([x, 2*x])
    assert unumpy.cos(arr)[1] == uncertainties.umath.cos(arr[1])

    # Some functions do not bear the same name in the math module and
    # in NumPy (acos instead of arccos, etc.):
    assert unumpy.arccos(arr)[1] == uncertainties.umath.acos(arr[1])
    # The acos() function should not exist in unumpy because it does
    # not exist in numpy:
    assert not hasattr(numpy, 'acos')
    assert not hasattr(unumpy, 'acos')

    # Test of the __all__ variable:
    assert 'acos' not in unumpy.__all__
예제 #7
0
def test_broadcast_funcs():
    """
    Test of mathematical functions that work with NumPy arrays of
    numbers with uncertainties.
    """

    x = uncertainties.ufloat((0.2, 0.1))
    arr = numpy.array([x, 2*x])
    assert unumpy.cos(arr)[1] == uncertainties.umath.cos(arr[1])

    # Some functions do not bear the same name in the math module and
    # in NumPy (acos instead of arccos, etc.):
    assert unumpy.arccos(arr)[1] == uncertainties.umath.acos(arr[1])
    # The acos() function should not exist in unumpy because it does
    # not exist in numpy:
    assert not hasattr(numpy, 'acos')
    assert not hasattr(unumpy, 'acos')

    # Test of the __all__ variable:
    assert 'acos' not in unumpy.__all__
예제 #8
0
파일: lab2cm.py 프로젝트: yano404/A5tools
def theta(theta_lab, n):
    """
    function to convert θ in the lab system to θ in the center-of-mass system

    Arguments
    ---------
    theta_lab : scattering angle in the lab system [rad]
    n         : A_t / A_i; A_t, A_i means mass number of target particle or incident particle

    Return
    ------
    theta_cm  : scattering angle in the center-of-mass system [rad]

    Notice
    ------
    This function do not consider relativity
    """
    if isinstance(theta_lab, uncertainties.core.AffineScalarFunc):
        coslab2 = umath.pow(umath.cos(theta_lab), 2.0)
        coscm = (coslab2 - 1.0) / n \
            + umath.sqrt((1.0 - 1.0 / n**2.0) * coslab2 +
                         umath.pow(coslab2 / n, 2.0))
        return np.sign(theta_lab) * umath.acos(coscm)
    elif isinstance(theta_lab, np.ndarray) and isinstance(
            theta_lab[0], uncertainties.core.AffineScalarFunc):
        coslab2 = unp.pow(unp.cos(theta_lab), 2.0)
        coscm = (coslab2 - 1.0) / n \
            + unp.sqrt((1.0 - 1.0 / n**2.0) * coslab2 +
                       unp.pow(coslab2 / n, 2.0))
        return np.sign(theta_lab) * unp.arccos(coscm)
    else:
        coslab2 = np.power(np.cos(theta_lab), 2.0)
        coscm = (coslab2 - 1.0) / n \
            + np.sqrt((1.0 - 1.0 / n**2.0) * coslab2 +
                      np.power(coslab2 / n, 2.0))
        return np.sign(theta_lab) * np.arccos(coscm)
예제 #9
0
def geometric_elements_with_uncertainties(thiele_innes_parameters,
                                          thiele_innes_parameters_errors=None,
                                          correlation_matrix=None,
                                          post_process=False,
                                          return_angles_in_deg=True):
    """
    Return geometrical orbit elements a, omega, OMEGA, i. If errors are not given
    they are assumed to be 0 and correlation matrix is set to identity.
    Complement to the pystrometry.geometric_elements function that allows to 
    compute parameter uncertainties as well.

    Parameters
    ----------
    thiele_innes_parameters : array
        Array of Thiele Innes parameters [A,B,F,G] in milli-arcsecond
    thiele_innes_parameters_errors : array, optional
        Array of the errors of the Thiele Innes parameters [A,B,F,G] in milli-arcsecond
    correlation_matrix : (4, 4) array, optional
        Correlation matrix for the Thiele Innes parameters [A,B,F,G]

    Returns
    -------
    geometric_parameters : array
        Orbital elements [a_mas, omega_deg, OMEGA_deg, i_deg]
    geometric_parameters_errors : array
        Errors of the orbital elements [a_mas, omega_deg, OMEGA_deg, i_deg]

    """

    # Checks on the errors and correlation matrix
    if (thiele_innes_parameters_errors is None) and (correlation_matrix is
                                                     None):
        # Define errors to 0 and correlation matrix to identity
        thiele_innes_parameters_errors = [0, 0, 0, 0]
        correlation_matrix = np.identity(4)
    elif (thiele_innes_parameters_errors is not None) and (correlation_matrix
                                                           is not None):
        # If both are given continue to the calculation
        pass
    else:
        # If either one of them is provided but not the other raise an error
        raise ValueError("thieles_innes_parameters_erros and correlation_matrix must be" \
                          "specified together.")

    # Define uncorrelated (value, uncertainty) pairs
    A_u = (thiele_innes_parameters[0], thiele_innes_parameters_errors[0])
    B_u = (thiele_innes_parameters[1], thiele_innes_parameters_errors[1])
    F_u = (thiele_innes_parameters[2], thiele_innes_parameters_errors[2])
    G_u = (thiele_innes_parameters[3], thiele_innes_parameters_errors[3])

    # Create correlated quantities
    A, B, F, G = correlated_values_norm([A_u, B_u, F_u, G_u],
                                        correlation_matrix)

    p = (A**2 + B**2 + G**2 + F**2) / 2.
    q = A * G - B * F

    a_mas = unp.sqrt(p + unp.sqrt(p**2 - q**2))
    i_rad = unp.arccos(q / (a_mas**2.))
    omega_rad = (unp.arctan2(B - F, A + G) + unp.arctan2(-B - F, A - G)) / 2.
    OMEGA_rad = (unp.arctan2(B - F, A + G) - unp.arctan2(-B - F, A - G)) / 2.

    if post_process:
        # convert angles to nominal ranges
        omega_rad, OMEGA_rad = pystrometry.adjust_omega_OMEGA(
            omega_rad, OMEGA_rad)

    if return_angles_in_deg:
        # Convert radians to degrees
        i_deg = i_rad * 180 / np.pi
        omega_deg = omega_rad * 180 / np.pi
        OMEGA_deg = OMEGA_rad * 180 / np.pi
    else:
        i_deg = i_rad
        omega_deg = omega_rad
        OMEGA_deg = OMEGA_rad

    # Extract nominal values and standard deviations
    geometric_parameters = np.array([
        unp.nominal_values(a_mas),
        unp.nominal_values(omega_deg),
        unp.nominal_values(OMEGA_deg),
        unp.nominal_values(i_deg)
    ])

    geometric_parameters_errors = np.array([
        unp.std_devs(a_mas),
        unp.std_devs(omega_deg),
        unp.std_devs(OMEGA_deg),
        unp.std_devs(i_deg)
    ])

    return geometric_parameters, geometric_parameters_errors
예제 #10
0
alpha_plot = np.linspace(-1, 7)
plt.errorbar(np.radians(225),unp.nominal_values(U_6),unp.std_devs(U_6),fmt='kx',label="Ausgewerte Daten")
plt.errorbar(np.radians(270),unp.nominal_values(U_7),unp.std_devs(U_7),fmt='kx')
plt.errorbar(np.radians(315),unp.nominal_values(U_8),unp.std_devs(U_8),fmt='kx')
plt.errorbar(np.radians(360),unp.nominal_values(U_9),unp.std_devs(U_9),fmt='kx')
plt.errorbar(np.radians(0),unp.nominal_values(U_1),unp.std_devs(U_1),fmt='rx')
plt.errorbar(np.radians(45),unp.nominal_values(U_2),unp.std_devs(U_2),fmt='rx')
plt.errorbar(np.radians(90),unp.nominal_values(U_3),unp.std_devs(U_3),fmt='rx')
plt.errorbar(np.radians(135),unp.nominal_values(U_4),unp.std_devs(U_4),fmt='rx',label="Nichtausgewerte Daten") 
plt.errorbar(np.radians(180),unp.nominal_values(U_5),unp.std_devs(U_5),fmt='kx')
plt.plot(alpha_plot, f(alpha_plot, *params), 'b-', label='linearer Fit')
plt.legend(loc="best")
plt.xlim(-0.5,7)
plt.xticks([0, np.pi / 2, np.pi, 3 * np.pi / 2, 2 * np.pi],
           [r"$0$", r"$\frac{\pi}{2}$", r"$\pi$", r"$\frac{3\pi}{2}$", r"$2\pi$"])
plt.xlabel(r'$\mathrm{Winkel}$')
plt.ylabel(r'$\mathrm{Spannung}\,U /mV$')
plt.ylim(28,42)
#plt.savefig('../Bilder/plot2.pdf')
plt.show()

plt.close()

IW1=unp.arccos(min1/max1)*180/np.pi
IW2=unp.arccos(min2/max2)*180/np.pi

print('')
print('IW1=',IW1)
print('IW2=',IW2)