当前位置: 首页>>代码示例>>Python>>正文


Python FITSFigure.save方法代码示例

本文整理汇总了Python中aplpy.FITSFigure.save方法的典型用法代码示例。如果您正苦于以下问题:Python FITSFigure.save方法的具体用法?Python FITSFigure.save怎么用?Python FITSFigure.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在aplpy.FITSFigure的用法示例。


在下文中一共展示了FITSFigure.save方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: fits_to_png

# 需要导入模块: from aplpy import FITSFigure [as 别名]
# 或者: from aplpy.FITSFigure import save [as 别名]
def fits_to_png(infile, outfile, draw, dpi=100):
    """Plot FITS image in PNG format.

    For the default ``dpi=100`` a 1:1 copy of the pixels in the FITS image
    and the PNG image is achieved, i.e. they have exactly the same size.

    Parameters
    ----------
    infile : str
        Input FITS file name
    outfile : str
        Output PNG file name
    draw : callable
        Callback function ``draw(figure)``
        where ``figure`` is an `~aplpy.FITSFigure`.
    dpi : int
        Resolution

    Examples
    --------
    >>> def draw(figure):
    ...     x, y, width, height = 42, 0, 3, 2
    ...     figure.recenter(x, y, width, height)
    ...     figure.show_grayscale()
    >>> from gammapy.image import fits_to_png
    >>> fits_to_png('image.fits', 'image.png', draw)
    """
    import matplotlib

    matplotlib.use("Agg")  # Prevents image popup
    import matplotlib.pyplot as plt
    from astropy.io import fits
    from aplpy import FITSFigure

    # Peak ahead just to get the figure size
    NAXIS1 = float(fits.getval(infile, "NAXIS1"))
    NAXIS2 = float(fits.getval(infile, "NAXIS2"))

    # Note: For dpi=100 I get exactly the same FITS and PNG image size in pix.
    figsize = np.array((NAXIS1, NAXIS2))
    figure = plt.figure(figsize=figsize / dpi)
    # Also try this:
    # matplotlib.rcParams['figure.figsize'] = NAXIS1, NAXIS2
    # figsize(x,y)

    subplot = [0, 0, 1, 1]
    figure = FITSFigure(infile, figure=figure, subplot=subplot)

    draw(figure)

    figure.axis_labels.hide()
    figure.tick_labels.hide()
    figure.ticks.set_linewidth(0)
    figure.frame.set_linewidth(0)

    figure.save(outfile, max_dpi=dpi, adjust_bbox=False)
开发者ID:OlgaVorokh,项目名称:gammapy,代码行数:58,代码来源:plotting.py

示例2: test_write_eps

# 需要导入模块: from aplpy import FITSFigure [as 别名]
# 或者: from aplpy.FITSFigure import save [as 别名]
def test_write_eps(tmpdir, format):
    filename = os.path.join(str(tmpdir), 'test_output.eps')
    data = np.zeros((16, 16))
    f = FITSFigure(data)
    f.show_grayscale()
    f.save(filename, format=format)
    f.close()
    if format is None:
        assert is_format(filename, 'eps')
    else:
        assert is_format(filename, format)
开发者ID:lpsinger,项目名称:aplpy,代码行数:13,代码来源:test_save.py

示例3: test_write_stringio

# 需要导入模块: from aplpy import FITSFigure [as 别名]
# 或者: from aplpy.FITSFigure import save [as 别名]
def test_write_stringio(tmpdir, format):
    s = StringIO()
    data = np.zeros((16, 16))
    f = FITSFigure(data)
    f.show_grayscale()
    f.save(s, format=format)
    f.close()
    s.seek(0)
    if format is None:
        assert is_format(s, 'png')
    else:
        assert is_format(s, format)
开发者ID:lpsinger,项目名称:aplpy,代码行数:14,代码来源:test_save.py

示例4: plot_exposure_image

# 需要导入模块: from aplpy import FITSFigure [as 别名]
# 或者: from aplpy.FITSFigure import save [as 别名]
def plot_exposure_image(filename):
    """Plot FOV image of exposure for one given energy slice"""
    from astropy.io import fits
    from aplpy import FITSFigure
    fig = FITSFigure(filename, dimensions=(0, 1), slices=[10], figsize=(5, 5))
    header = fits.getheader(filename)
    fig.show_grayscale()
    fig.add_colorbar()
    ra, dec = header['CRVAL1'], header['CRVAL2']
    
    # Bug: Marker doesn't show up at the center of the run
    # Bug: aplpy show_circles doesn't show a circle in degress.
    fig.show_markers(ra, dec)
    fig.show_circles(ra, dec, 1.)
    
    fig.tick_labels.set_xformat('dd')
    fig.tick_labels.set_yformat('dd')
    fig.ticks.set_xspacing(1)
    fig.ticks.set_yspacing(1)
    fig.colorbar.set_axis_label_text('Effective Area (cm^2)')
    
    fig.save('exposure_image.png')
开发者ID:Cadair,项目名称:gammapy,代码行数:24,代码来源:plot_irfs.py

示例5: FITSFigure

# 需要导入模块: from aplpy import FITSFigure [as 别名]
# 或者: from aplpy.FITSFigure import save [as 别名]
import numpy as np
from aplpy import FITSFigure
import matplotlib.pyplot as pl
from matplotlib.patches import Circle

im  = np.random.randn(100,100)

gc = FITSFigure(im)
gc.show_grayscale()
gc.show_circles(20, 20, 10, alpha = 0.3, edgecolor = 'y', linewidth = 10)
gc.show_circles(40,40,10, facecolor = 'y', alpha = 0.3, linewidth = 10)
gc.show_circles(60,60,10, facecolor = 'y', alpha = 0.3, edgecolor = 'none')
gc.save('aplpy_circles.png')

pl.figure(2)
pl.imshow(im, interpolation = 'nearest', origin = 1, cmap = 'gray')
circle = Circle((20,20), 10,alpha=0.3, edgecolor = 'y',facecolor = 'none', linewidth = 10)
pl.gca().add_artist(circle)
circle = Circle((40,40), 10,alpha=0.3, facecolor = 'y', linewidth = 10)
pl.gca().add_artist(circle)
circle = Circle((60,60), 10,alpha=0.3, facecolor = 'y', linewidth = 0)
pl.gca().add_artist(circle)
pl.savefig('mpl_circles.png')


import matplotlib
import aplpy

assert matplotlib.__version__ == '1.3.0'
assert aplpy.__version__ == '0.9.9'
开发者ID:bd-j,项目名称:magellanic,代码行数:32,代码来源:aplpy_test.py

示例6: make_empty_image

# 需要导入模块: from aplpy import FITSFigure [as 别名]
# 或者: from aplpy.FITSFigure import save [as 别名]
from astropy.io import fits
from astropy.table import Table
from aplpy import FITSFigure
from gammapy.astro import population
from gammapy.datasets import FermiGalacticCenter
from gammapy.image import make_empty_image, catalog_image
from gammapy.irf import EnergyDependentTablePSF
from gammapy.utils.random import sample_powerlaw

# Create image of defined size
reference = make_empty_image(nxpix=3600, nypix=1800, binsz=0.1)

psf_file = FermiGalacticCenter.filenames()['psf']
psf = EnergyDependentTablePSF.read(psf_file)
filename = raw_input('Input simulated table filename: ')
table = fits.open(filename)[1].data
table = Table(table)
table.meta['Energy Bins'] = Quantity([10, 500], 'GeV')
# Create image

image = catalog_image(reference, psf, catalog='simulation', source_type='point',
                  total_flux=True, sim_table=table)
hdu = image.to_fits()[0]
hdu.writeto('image_{0}'.format(filename), clobber=True)

# Plot
fig = FITSFigure(image.to_fits()[0])
fig.show_grayscale(stretch='linear', interpolation='none')
fig.add_colorbar()
fig.save('testimage.pdf')
开发者ID:ellisowen,项目名称:SciNeGHE_scripts,代码行数:32,代码来源:galaxy_simulations.py

示例7: raw_input

# 需要导入模块: from aplpy import FITSFigure [as 别名]
# 或者: from aplpy.FITSFigure import save [as 别名]
from aplpy import FITSFigure
from astropy.io import fits
filename = raw_input("File to plot: ")
hdu = fits.open(filename)[1]
fig = FITSFigure(hdu)
fig.show_colorscale(stretch='log', interpolation='none')
#fig.add_colorbar()
#fig.colorbar.set_ticks([0.1e-11, 0.4e-11, 1.2e-11])
#fig.colorbar.set_width(0.1)
#fig.colorbar.set_font('serif')
#fig.colorbar.set_label_properties(size='small')
#fig.hide_ytick_labels()
#fig.hide_yaxis_label()
#fig.hide_xaxis_label()
fig.tick_labels.set_yformat('ddd')
fig.tick_labels.set_xformat('ddd')
fig.set_tick_yspacing(5)
fig.axis_labels.set_font(size='small', family='roman')
fig.set_tick_labels_font('serif')
fig.set_tick_labels_size('small')
fig.save('image.pdf')

开发者ID:ellisowen,项目名称:SciNeGHE_scripts,代码行数:23,代码来源:image_script.py


注:本文中的aplpy.FITSFigure.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。