示例#1
0
def get_equivalencies():
    """
    Return a list of example equivalencies for testing serialization.
    """
    return [
        eq.plate_scale(.3 * u.deg / u.mm),
        eq.pixel_scale(.5 * u.deg / u.pix),
        eq.spectral_density(350 * u.nm, factor=2),
        eq.spectral_density(350 * u.nm),
        eq.spectral(),
        eq.brightness_temperature(500 * u.GHz),
        eq.brightness_temperature(500 * u.GHz, beam_area=23 * u.sr),
        eq.with_H0(),
        eq.temperature_energy(),
        eq.temperature(),
        eq.thermodynamic_temperature(300 * u.Hz),
        eq.thermodynamic_temperature(140 * u.GHz, Planck15.Tcmb0),
        eq.beam_angular_area(3 * u.sr),
        eq.mass_energy(),
        eq.molar_mass_amu(),
        eq.doppler_relativistic(2 * u.m),
        eq.doppler_optical(2 * u.nm),
        eq.doppler_radio(2 * u.Hz),
        eq.parallax(),
        eq.logarithmic(),
        eq.dimensionless_angles(),
        eq.spectral() + eq.temperature(),
        (eq.spectral_density(35 * u.nm) +
         eq.brightness_temperature(5 * u.Hz, beam_area=2 * u.sr)),
        (eq.spectral() + eq.spectral_density(35 * u.nm) +
         eq.brightness_temperature(5 * u.Hz, beam_area=2 * u.sr))
    ]
示例#2
0
    def to_flux(self, unit, equivalencies=None, suppress_conversion=False):
        """
        Converts the flux data to the specified unit.

        Parameters
        ----------
        unit : str or `~astropy.units.Unit`
            The unit to conver the flux array to.

        equivalencies : list of equivalencies
            Custom equivalencies to apply to conversions.
            Set to spectral_density by default.

        suppress_conversion : bool
            Set to true if updating the unit without
            converting data values.

        Returns
        -------
        `~astropy.units.Quantity`
            The converted flux array.
        """
        if not suppress_conversion:
            if equivalencies is None:
                equivalencies = eq.spectral_density(self.spectral_axis)

            new_data = self.flux.to(
                unit, equivalencies=equivalencies)

            self._data = new_data.value
            self._unit = new_data.unit
        else:
            self._unit = u.Unit(unit)

        return self.flux
示例#3
0
    def to_flux(self, unit, equivalencies=None, suppress_conversion=False):
        """
        Converts the flux data to the specified unit.

        Parameters
        ----------
        unit : str or `~astropy.units.Unit`
            The unit to conver the flux array to.

        equivalencies : list of equivalencies
            Custom equivalencies to apply to conversions.
            Set to spectral_density by default.

        suppress_conversion : bool
            Set to true if updating the unit without
            converting data values.

        Returns
        -------
        `~astropy.units.Quantity`
            The converted flux array.
        """
        if not suppress_conversion:
            if equivalencies is None:
                equivalencies = eq.spectral_density(self.spectral_axis)

            new_data = self.flux.to(
                unit, equivalencies=equivalencies)

            self._data = new_data.value
            self._unit = new_data.unit
        else:
            self._unit = u.Unit(unit)

        return self.flux
示例#4
0
    def to_flux(self, unit):
        """
        Converts the flux data to the specified unit.

        Parameters
        ----------
        unit : str or ~`astropy.units.Unit`
            The unit to conver the flux array to.

        Returns
        -------
        ~`astropy.units.Quantity`
            The converted flux array.
        """
        new_data = self.flux.to(
            unit, equivalencies=eq.spectral_density(self.spectral_axis))

        self._data = new_data.value
        self._unit = new_data.unit

        return self.flux
示例#5
0
    def new_flux_unit(self,
                      unit,
                      equivalencies=None,
                      suppress_conversion=False):
        """
        Converts the flux data to the specified unit.  This is an in-place
        change to the object.

        Parameters
        ----------
        unit : str or `~astropy.units.Unit`
            The unit to convert the flux array to.

        equivalencies : list of equivalencies
            Custom equivalencies to apply to conversions.
            Set to spectral_density by default.

        suppress_conversion : bool
            Set to true if updating the unit without
            converting data values.

        Returns
        -------
        `~specutils.Spectrum1D`
            A new spectrum with the converted flux array
        """
        new_spec = deepcopy(self)

        if not suppress_conversion:
            if equivalencies is None:
                equivalencies = eq.spectral_density(self.spectral_axis)

            new_data = self.flux.to(unit, equivalencies=equivalencies)

            new_spec._data = new_data.value
            new_spec._unit = new_data.unit
        else:
            new_spec._unit = u.Unit(unit)

        return new_spec
示例#6
0
    def to_flux(self, unit):
        """
        Converts the flux data to the specified unit.

        Parameters
        ----------
        unit : str or ~`astropy.units.Unit`
            The unit to conver the flux array to.

        Returns
        -------
        ~`astropy.units.Quantity`
            The converted flux array.
        """
        new_data = self.flux.to(unit,
                                equivalencies=eq.spectral_density(
                                    self.spectral_axis))

        self._data = new_data.value
        self._unit = new_data.unit

        return self.flux
示例#7
0
    def new_flux_unit(self, unit, equivalencies=None, suppress_conversion=False):
        """
        Converts the flux data to the specified unit.  This is an in-place
        change to the object.

        Parameters
        ----------
        unit : str or `~astropy.units.Unit`
            The unit to conver the flux array to.

        equivalencies : list of equivalencies
            Custom equivalencies to apply to conversions.
            Set to spectral_density by default.

        suppress_conversion : bool
            Set to true if updating the unit without
            converting data values.

        Returns
        -------
        `~specutils.Spectrum1D`
            A new spectrum with the converted flux array
        """
        new_spec = deepcopy(self)
        if not suppress_conversion:
            if equivalencies is None:
                equivalencies = eq.spectral_density(self.spectral_axis)

            new_data = self.flux.to(
                unit, equivalencies=equivalencies)

            new_spec._data = new_data.value
            new_spec._unit = new_data.unit
        else:
            new_spec._unit = u.Unit(unit)

        return new_spec