Python scipy.constants.speed_of_light() Examples

The following are 17 code examples of scipy.constants.speed_of_light(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module scipy.constants , or try the search function .
Example #1
Source File: eproperties.py    From scikit-ued with MIT License 5 votes vote down vote up
def electron_wavelength(keV):
    """ 
    Relativistic wavelength :math:`\lambda` of an accelerated electron.

    .. math::

        \lambda = \\frac{h}{\sqrt{2 m_e e V}}\gamma
    
    where :math:`\gamma` is the relativistic Lorentz factor.
        
    Parameters
    ----------
    keV : array_like or float
        Electron energy [keV].
    
    Returns
    -------
    out : array_like or float
        Electron wavelength [:math:`Å^{-1}`]

    References
    ----------
    .. Kirkland 2010 Eq. 2.5
    """
    eV = elementary_charge * keV * 1e3
    wavelength_meters = (
        Planck
        * speed_of_light
        / np.sqrt(eV * (2 * electron_mass * speed_of_light ** 2 + eV))
    )
    return wavelength_meters * 1e10  # wavelength in angstroms 
Example #2
Source File: radarsat.py    From sarpy with MIT License 5 votes vote down vote up
def _get_grid_row(self):
        """
        Gets the Grid.Row metadata.

        Returns
        -------
        DirParamType
        """

        center_freq = self._get_center_frequency()
        if self.generation == 'RS2':
            row_ss = float(self._find('./imageAttributes'
                                      '/rasterAttributes'
                                      '/sampledPixelSpacing').text)
        elif self.generation == 'RCM':
            row_ss = float(self._find('./imageReferenceAttributes'
                                      '/rasterAttributes'
                                      '/sampledPixelSpacing').text)
        else:
            raise ValueError('unhandled generation {}'.format(self.generation))

        row_irbw = 2*float(self._find('./imageGenerationParameters'
                                      '/sarProcessingInformation'
                                      '/totalProcessedRangeBandwidth').text)/speed_of_light
        row_wgt_type = WgtTypeType(WindowName=self._find('./imageGenerationParameters'
                                                         '/sarProcessingInformation'
                                                         '/rangeWindow/windowName').text.upper())
        if row_wgt_type.WindowName == 'KAISER':
            row_wgt_type.Parameters = {'BETA': self._find('./imageGenerationParameters'
                                                          '/sarProcessingInformation'
                                                          '/rangeWindow/windowCoefficient').text}
        return DirParamType(
            SS=row_ss, ImpRespBW=row_irbw, Sgn=-1, KCtr=2*center_freq/speed_of_light,
            DeltaKCOAPoly=Poly2DType(Coefs=((0,),)), WgtType=row_wgt_type) 
Example #3
Source File: Grid.py    From sarpy with MIT License 5 votes vote down vote up
def _derive_rma_rmcr(self, RMA, GeoData, RadarCollection, ImageFormation):
        """

        Parameters
        ----------
        RMA : sarpy.io.complex.sicd_elements.RMA.RMAType
        GeoData : sarpy.io.complex.sicd_elements.GeoData.GeoDataType
        RadarCollection : sarpy.io.complex.sicd_elements.RadarCollection.RadarCollectionType
        ImageFormation : sarpy.io.complex.sicd_elements.ImageFormation.ImageFormationType

        Returns
        -------
        None
        """

        if RMA.RMCR is None:
            return

        if self.ImagePlane is None:
            self.ImagePlane = 'SLANT'
        if self.Type is None:
            self.Type = 'XRGYCR'

        if self.Row.UVectECF is None and self.Col.UVectECF is None:
            params = self._derive_unit_vector_params(GeoData, RMA.RMAT)
            if params is not None:
                SCP, upos_ref, uvel_ref, uLOS, left, look = params
                uXRG = uLOS
                uSPZ = look*numpy.cross(uvel_ref, uXRG)
                uSPZ /= norm(uSPZ)
                uYCR = numpy.cross(uSPZ, uXRG)
                self.Row.UVectECF = XYZType.from_array(uXRG)
                self.Col.UVectECF = XYZType.from_array(uYCR)

        center_frequency = _get_center_frequency(RadarCollection, ImageFormation)
        if center_frequency is not None:
            if self.Row.KCtr is None:
                self.Row.KCtr = 2*center_frequency/speed_of_light
            if self.Col.KCtr is None:
                self.Col.KCtr = 2*center_frequency/speed_of_light 
Example #4
Source File: Grid.py    From sarpy with MIT License 5 votes vote down vote up
def _derive_rma_rmat(self, RMA, GeoData, RadarCollection, ImageFormation):
        """

        Parameters
        ----------
        RMA : sarpy.io.complex.sicd_elements.RMA.RMAType
        GeoData : sarpy.io.complex.sicd_elements.GeoData.GeoDataType
        RadarCollection : sarpy.io.complex.sicd_elements.RadarCollection.RadarCollectionType
        ImageFormation : sarpy.io.complex.sicd_elements.ImageFormation.ImageFormationType

        Returns
        -------
        None
        """

        if RMA.RMAT is None:
            return

        if self.ImagePlane is None:
            self.ImagePlane = 'SLANT'
        if self.Type is None:
            self.Type = 'XCTYAT'

        if self.Row.UVectECF is None and self.Col.UVectECF is None:
            params = self._derive_unit_vector_params(GeoData, RMA.RMAT)
            if params is not None:
                SCP, upos_ref, uvel_ref, uLOS, left, look = params
                uYAT = -look*uvel_ref
                uSPZ = numpy.cross(uLOS, uYAT)
                uSPZ /= norm(uSPZ)
                uXCT = numpy.cross(uYAT, uSPZ)
                self.Row.UVectECF = XYZType.from_array(uXCT)
                self.Col.UVectECF = XYZType.from_array(uYAT)

        center_frequency = _get_center_frequency(RadarCollection, ImageFormation)
        if center_frequency is not None and RMA.RMAT.DopConeAngRef is not None:
            if self.Row.KCtr is None:
                self.Row.KCtr = (2*center_frequency/speed_of_light)*numpy.sin(numpy.deg2rad(RMA.RMAT.DopConeAngRef))
            if self.Col.KCtr is None:
                self.Col.KCtr = (2*center_frequency/speed_of_light)*numpy.cos(numpy.deg2rad(RMA.RMAT.DopConeAngRef)) 
Example #5
Source File: test_eproperties.py    From scikit-ued with MIT License 5 votes vote down vote up
def test_limits(self):
        """ Test that the electron velocity never exceeds the speed of light. """
        c = speed_of_light * 1e10  # Speed of light in Ang/s
        self.assertEqual(electron_velocity(1e20) / c, 1) 
Example #6
Source File: eproperties.py    From scikit-ued with MIT License 5 votes vote down vote up
def interaction_parameter(keV):
    """
    Interaction parameter from relativistic electron wavelength.

    Parameters
    ----------
    keV : array_like or float
        Electron energy [keV].
    
    Returns
    -------
    out : array_like or float
        Interaction parameter [:math:`rad/(V Å)`]

    References
    ----------
    .. Kirkland 2010 Eq. 5.6
    """
    l = electron_wavelength(keV)
    V = keV * 1e3

    return (
        (2 * np.pi)
        / (electron_wavelength(keV) * V)
        * (electron_mass * speed_of_light ** 2 + elementary_charge * V)
        / (2 * electron_mass * speed_of_light ** 2 + elementary_charge * V)
    ) 
Example #7
Source File: eproperties.py    From scikit-ued with MIT License 5 votes vote down vote up
def electron_velocity(keV):
    """
    Relativistic velocity :math:`v_e` of an accelerated electron.

    .. math::

        \\frac{v_e}{c} = \sqrt{1 - \\frac{m_0 c^2}{m_0 c^2 + e V}}

    Parameters
    ----------
    keV : array_like or float
        Electron energy [keV].
    
    Returns
    -------
    out : array_like or float
        Electron velocity [:math:`Å / s`]

    References
    ----------
    .. Kirkland 2010 Eq. 2.3
    """
    eV = elementary_charge * keV * 1e3
    m0c2 = electron_mass * speed_of_light ** 2
    v_over_c = np.sqrt(eV * (eV + 2 * m0c2)) / (m0c2 + eV)
    return (speed_of_light * v_over_c) * 1e10  # speed in Angstroms 
Example #8
Source File: test_constants.py    From Computable with MIT License 5 votes vote down vote up
def test_lambda_to_nu():
    assert_equal(sc.lambda2nu(sc.speed_of_light), 1) 
Example #9
Source File: eproperties.py    From scikit-ued with MIT License 5 votes vote down vote up
def lorentz(keV):
    """
    Relativistic factor :math:`\gamma`, defined as :math:`\gamma = \\frac{1}{\sqrt{1 - v^2/c^2}}`

    Parameters
    ----------
    keV : array_like or float
        Electron energy [keV].
    
    Returns
    -------
    out : array_like or float

    References
    ----------
    .. Kirkland 2010 Eq. 2.2
    """
    return 1 + (elementary_charge * keV * 1e3) / (electron_mass * speed_of_light ** 2) 
Example #10
Source File: dpc_utils.py    From pyxem with GNU General Public License v3.0 5 votes vote down vote up
def acceleration_voltage_to_relativistic_mass(acceleration_voltage):
    """Get relativistic mass of electron as function of acceleration voltage.

    Parameters
    ----------
    acceleration_voltage : float
        In Volt

    Returns
    -------
    mr : float
        Relativistic electron mass

    Example
    -------
    >>> import pyxem.utils.dpc_utils as dpct
    >>> mr = dpct.acceleration_voltage_to_relativistic_mass(200000) # 200 kV

    """
    av = acceleration_voltage
    c = sc.speed_of_light
    v = acceleration_voltage_to_velocity(av)
    me = sc.electron_mass
    part1 = 1 - (v ** 2) / (c ** 2)
    mr = me / (part1) ** 0.5
    return mr 
Example #11
Source File: dpc_utils.py    From pyxem with GNU General Public License v3.0 5 votes vote down vote up
def acceleration_voltage_to_velocity(acceleration_voltage):
    """Get relativistic velocity of electron from acceleration voltage.

    Parameters
    ----------
    acceleration_voltage : float
        In Volt

    Returns
    -------
    v : float
        In m/s

    Example
    -------
    >>> import pyxem.utils.dpc_utils as dpct
    >>> v = dpct.acceleration_voltage_to_velocity(200000) # 200 kV
    >>> round(v)
    208450035

    """
    c = sc.speed_of_light
    av = acceleration_voltage
    e = sc.elementary_charge
    me = sc.electron_mass
    part1 = (1 + (av * e) / (me * c ** 2)) ** 2
    v = c * (1 - (1 / part1)) ** 0.5
    return v 
Example #12
Source File: diffraction_tools.py    From pyxem with GNU General Public License v3.0 5 votes vote down vote up
def acceleration_voltage_to_wavelength(acceleration_voltage):
    """Get electron wavelength from the acceleration voltage.

    Parameters
    ----------
    acceleration_voltage : float or array-like
        In Volt

    Returns
    -------
    wavelength : float or array-like
        In meters

    Examples
    --------
    >>> import pixstem.diffraction_tools as dt
    >>> acceleration_voltage = 200000  # 200 kV (in Volt)
    >>> wavelength = dt.acceleration_voltage_to_wavelength(
    ...     acceleration_voltage)
    >>> wavelength_picometer = wavelength*10**12

    """
    E = acceleration_voltage * sc.elementary_charge
    h = sc.Planck
    m0 = sc.electron_mass
    c = sc.speed_of_light
    wavelength = h / (2 * m0 * E * (1 + (E / (2 * m0 * c ** 2)))) ** 0.5
    return wavelength 
Example #13
Source File: test_constants.py    From GraphicDesignPatternByPython with MIT License 5 votes vote down vote up
def test_nu_to_lambda():
    assert_equal(sc.nu2lambda(1), sc.speed_of_light) 
Example #14
Source File: test_constants.py    From GraphicDesignPatternByPython with MIT License 5 votes vote down vote up
def test_lambda_to_nu():
    assert_equal(sc.lambda2nu(sc.speed_of_light), 1) 
Example #15
Source File: test_constants.py    From Computable with MIT License 5 votes vote down vote up
def test_nu_to_lambda():
    assert_equal(sc.nu2lambda(1), sc.speed_of_light) 
Example #16
Source File: Grid.py    From sarpy with MIT License 4 votes vote down vote up
def _derive_pfa(self, GeoData, RadarCollection, ImageFormation, Position, PFA):
        """
        Expected to be called by SICD parent.

        Parameters
        ----------
        GeoData : sarpy.io.complex.sicd_elements.GeoData.GeoDataType
        RadarCollection : sarpy.io.complex.sicd_elements.RadarCollection.RadarCollectionType
        ImageFormation : sarpy.io.complex.sicd_elements.ImageFormation.ImageFormationType
        Position : sarpy.io.complex.sicd_elements.Position.PositionType
        PFA : sarpy.io.complex.sicd_elements.PFA.PFAType

        Returns
        -------
        None
        """

        if self.Type is None:
            self.Type = 'RGAZIM'  # the natural result for PFA

        if PFA is None:
            return  # nothing to be done
        if GeoData is None or GeoData.SCP is None:
            return  # nothing to be done

        SCP = GeoData.SCP.ECF.get_array()

        if Position is not None and Position.ARPPoly is not None \
                and PFA.PolarAngRefTime is not None:
            polar_ref_pos = Position.ARPPoly(PFA.PolarAngRefTime)
        else:
            polar_ref_pos = SCP

        if PFA.IPN is not None and PFA.FPN is not None and \
                self.Row.UVectECF is None and self.Col.UVectECF is None:
            ipn = PFA.IPN.get_array()
            fpn = PFA.FPN.get_array()

            dist = numpy.dot((SCP - polar_ref_pos), ipn) / numpy.dot(fpn, ipn)
            ref_pos_ipn = polar_ref_pos + (dist * fpn)
            uRG = SCP - ref_pos_ipn
            uRG /= norm(uRG)
            uAZ = numpy.cross(ipn, uRG)  # already unit
            self.Row.UVectECF = XYZType.from_array(uRG)
            self.Col.UVectECF = XYZType.from_array(uAZ)

        if self.Col is not None and self.Col.KCtr is None:
            self.Col.KCtr = 0  # almost always 0 for PFA

        if self.Row is not None and self.Row.KCtr is None:
            center_frequency = _get_center_frequency(RadarCollection, ImageFormation)
            if PFA.Krg1 is not None and PFA.Krg2 is not None:
                self.Row.KCtr = 0.5*(PFA.Krg1 + PFA.Krg2)
            elif center_frequency is not None and PFA.SpatialFreqSFPoly is not None:
                # APPROXIMATION: may not be quite right, due to rectangular inscription loss in PFA.
                self.Row.KCtr = 2*center_frequency/speed_of_light + PFA.SpatialFreqSFPoly.Coefs[0] 
Example #17
Source File: Grid.py    From sarpy with MIT License 4 votes vote down vote up
def _derive_rma_inca(self, RMA, GeoData, Position):
        """

        Parameters
        ----------
        RMA : sarpy.io.complex.sicd_elements.RMA.RMAType
        GeoData : sarpy.io.complex.sicd_elements.GeoData.GeoDataType
        Position : sarpy.io.complex.sicd_elements.Position.PositionType

        Returns
        -------
        None
        """

        if RMA.INCA is None:
            return

        if self.Type is None:
            self.Type = 'RGZERO'

        if RMA.INCA.TimeCAPoly is not None and Position is not None and Position.ARPPoly is not None and \
                self.Row.UVectECF is None and self.Col.UVectECF is None and \
                GeoData is not None and GeoData.SCP is not None:
            SCP = GeoData.SCP.ECF.get_array()

            t_zero = RMA.INCA.TimeCAPoly.Coefs[0]
            ca_pos = Position.ARPPoly(t_zero)
            ca_vel = Position.ARPPoly.derivative_eval(t_zero, der_order=1)

            uca_pos = ca_pos/norm(ca_pos)
            uca_vel = ca_vel/norm(ca_vel)
            uRg = (SCP - ca_pos)
            uRg_norm = norm(uRg)
            if uRg_norm > 0:
                uRg /= uRg_norm
                left = numpy.cross(uca_pos, uca_vel)
                look = numpy.sign(numpy.dot(left, uRg))
                uSPZ = -look*numpy.cross(uRg, uca_vel)
                uSPZ /= norm(uSPZ)
                uAZ = numpy.cross(uSPZ, uRg)
                self.Row.UVectECF = XYZType.from_array(uRg)
                self.Col.UVectECF = XYZType.from_array(uAZ)

        if self.Row is not None and self.Row.KCtr is None and RMA.INCA.FreqZero is not None:
            self.Row.KCtr = 2*RMA.INCA.FreqZero/speed_of_light
        if self.Col is not None and self.Col.KCtr is None:
            self.Col.KCtr = 0