コード例 #1
0
    def black_body_spectrum(cls,
                            temperature=9500,
                            amplitude=0,
                            filter_curve=None,
                            waves=None):
        """
        Produce a blackbody spectrum for a given temperature and scale it to a magnitude
        in a filter

        Parameters
        ----------
        temperature: the temperature in Kelvin degrees
        amplitude: `astropy.Quantity``, float
                The value that the spectrum should have in the given filter. Acceptable
                astropy quantities are:
                - u.mag : Vega magnitudes
                - u.ABmag : AB magnitudes
                - u.STmag : HST magnitudes
                - u.Jy : Jansky per filter bandpass
                Additionally the ``FLAM`` and ``FNU`` units from ``synphot.units`` can
                be used when passing the quantity for ``amplitude``:

        filter_curve : str
                Name of a filter from
                - a generic filter name (see ``FILTER_DEFAULTS``)
                - a spanish-vo filter service reference (e.g. ``"Paranal/HAWKI.Ks"``)
                - a filter in the spextra database
                - a filename with the filter file
                - a ``Passband`` or ``synphot.SpectralElement`` object


        Returns
        -------
        a scaled black-body spectrum
        """

        if waves is None:  # set a default waveset with R~805
            waves, info = utils.generate_wavelengths(minwave=100,
                                                     maxwave=50000,
                                                     num=5000,
                                                     log=True,
                                                     wave_unit=u.AA)

        if isinstance(amplitude, u.Quantity) is False:
            amplitude = amplitude * u.ABmag

        bb = BlackBody1D(temperature=temperature)

        sp = cls(modelclass=Empirical1D, points=waves, lookup_table=bb(waves))
        sp = sp.scale_to_magnitude(amplitude=amplitude,
                                   filter_curve=filter_curve)
        sp.repr = "Spextrum.black_body_spectrum(amplitude=%s, temperature=%s, filter_curve=%s)" % \
                  (str(amplitude), str(temperature), str(filter_curve))

        return sp
コード例 #2
0
    def powerlaw(cls,
                 alpha=1,
                 x_0=5000,
                 amplitude=0,
                 filter_curve=None,
                 waves=None):
        """
        Return a power law spectrum F(lambda) ~ lambda^alpha scaled to a magnitude
        (amplitude) in an particular band

        Parameters
        ----------
        alpha : The spectral slope
        x_0 : float, u.Quantity
           Pivot wavelength
        amplitude : float, u.Quantity
            normalize the spectrum to that quantity
        filter_curve : str
                Name of a filter from
                - a generic filter name (see ``FILTER_DEFAULTS``)
                - a spanish-vo filter service reference (e.g. ``"Paranal/HAWKI.Ks"``)
                - a filter in the spextra database
                - a filename with the filter file
                - a ``Passband`` or ``synphot.SpectralElement`` object

        Returns
        -------

        """
        if waves is None:  # set a default waveset with R~805
            waves, info = utils.generate_wavelengths(minwave=100,
                                                     maxwave=50000,
                                                     num=5000,
                                                     log=True,
                                                     wave_unit=u.AA)

        if isinstance(amplitude, u.Quantity) is False:
            amplitude = amplitude * u.ABmag

        pl = PowerLawFlux1D(amplitude,
                            alpha=alpha,
                            x_0=x_0,
                            amplitude=amplitude)
        sp = cls(modelclass=Empirical1D, points=waves, lookup_table=pl(waves))

        sp = sp.scale_to_magnitude(amplitude=amplitude,
                                   filter_curve=filter_curve)

        sp.repr = "Spextrum.powerlaw(alpha=%s, x_0=%s, amplitude=%s, filter_curve=%s)" % \
                  (str(alpha), str(x_0), str(amplitude), str(filter_curve))

        return sp
コード例 #3
0
class Conf(ConfigNamespace):
    """Configuration parameters."""

    # Set up default wavelength
    _wave, _wave_str = generate_wavelengths(minwave=500,
                                            maxwave=26000,
                                            num=10000,
                                            delta=None,
                                            log=True,
                                            wave_unit='angstrom')

    # Root directory
    rootdir = ConfigItem(os.environ.get('PYSYN_CDBS', '/grp/redcat/trds'),
                         'TRDS data root directory')

    # Graph, optical component, and thermal component tables
    graphtable = ConfigItem('mtab$*_tmg.fits', 'Graph table')
    comptable = ConfigItem('mtab$*_tmc.fits', 'Component table')
    thermtable = ConfigItem('mtab$*_tmt.fits', 'Thermal table')

    # Default wavelength in Angstrom and its description
    waveset_array = ConfigItem(_wave.value.tolist(),
                               'Default wavelength set in Angstrom',
                               'float_list')
    waveset = ConfigItem(_wave_str, 'Default wavelength set description')

    # Telescope primary mirror collecting area in cm^2
    area = ConfigItem(45238.93416, 'Telescope collecting area in cm^2')

    # Common filter name
    clear_filter = ConfigItem('clear', 'Name for a clear filter')

    # Wavelength catalog file
    wavecatfile = ConfigItem('synphot$wavecats/wavecat.dat',
                             'Wavelength catalog file')

    # Detector parameters file
    detectorfile = ConfigItem('synphot$detectors.dat',
                              'Detector parameters file')

    # IRAF shortcuts file for stsynphot.stio.irafconvert()
    irafshortcutfile = ConfigItem(
        'synphot$irafshortcuts.txt',
        'col1=shortcut_name col2=relpath_to_rootdir, has header.')

    # Clean up
    del _wave
    del _wave_str
コード例 #4
0
    def test_waveset(self):
        w = generate_wavelengths(
            minwave=3000, maxwave=5000, num=100, log=False)
        config.conf.waveset_array = w[0].value.tolist()
        config.conf.waveset = w[1]
        np.testing.assert_allclose(
            [config.conf.waveset_array[0], config.conf.waveset_array[-1]],
            [3000, 4980])
        assert (config.conf.waveset ==
                'Min: 3000, Max: 5000, Num: 100, Delta: None, Log: False')

        # Reset to default
        config.conf.reset('waveset_array')
        config.conf.reset('waveset')
        np.testing.assert_allclose(
            [config.conf.waveset_array[0], config.conf.waveset_array[-1]],
            [500, 25989.72879567])
        assert config.conf.waveset == self.def_dict['waveset']
コード例 #5
0
    def test_waveset(self):
        w = generate_wavelengths(
            minwave=3000, maxwave=5000, num=100, log=False)
        config.conf.waveset_array = w[0].value.tolist()
        config.conf.waveset = w[1]
        np.testing.assert_allclose(
            [config.conf.waveset_array[0], config.conf.waveset_array[-1]],
            [3000, 4980])
        assert (config.conf.waveset ==
                'Min: 3000, Max: 5000, Num: 100, Delta: None, Log: False')

        # Reset to default
        config.conf.reset('waveset_array')
        config.conf.reset('waveset')
        np.testing.assert_allclose(
            [config.conf.waveset_array[0], config.conf.waveset_array[-1]],
            [500, 25989.72879567])
        assert config.conf.waveset == self.def_dict['waveset']
コード例 #6
0
    def flat_spectrum(cls, amplitude=0, waves=None):
        """
        Creates a flat spectrum in the preferred system scaled to a magnitude,
        default a zero magnitude spectrum
        Parameters
        ----------
        amplitude: float, u.Quantity
            amplitude/magnitude of the reference spectrum, default=0
            default is u.ABmag
            for vega use u.mag or ``synphot.units.VEGAMAG``

        waves: The waveset of the reference spectrum if not Vega
           if not provided they will be created at a resolution of R~800

        Returns
        -------
        a Spextrum instance
        """
        if waves is None:  # set a default waveset with R~805
            waves, info = utils.generate_wavelengths(minwave=100,
                                                     maxwave=50000,
                                                     num=5000,
                                                     log=True,
                                                     wave_unit=u.AA)

        if isinstance(amplitude, u.Quantity) is False:
            amplitude = amplitude * u.ABmag

        if amplitude.unit is u.Unit("mag") or amplitude.unit is u.Unit(
                "vegamag"):
            spec = get_vega_spectrum()
            spec = spec * 10**(-0.4 * amplitude.value)
            system_name = amplitude.unit
        else:
            const = ConstFlux1D(amplitude=amplitude)
            spec = cls(modelclass=Empirical1D,
                       points=waves.value,
                       lookup_table=const(waves.value))
            system_name = amplitude.unit

        spec.repr = "Spextrum.flat_spectrum(amplitude=%s)" % str(amplitude)

        return spec