示例#1
0
def example1():

    import sys
    import scipy as sp
    import numpy as np
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    import pyfits

   #Path to fits file to be imported                                                                         
    data1 = "/Users/destry/Documents/Github/truffles_examples/GALFA_HI_RA+DEC_092.00+10.35_W.fits"

    #Read out basic info                                                                                      
    pyfits.info(data1)

    #Load file header into keys                                                                               
    header = pyfits.getheader(data1)
    header.keys()

    #Load actual data                                                                                         
    data_cube = pyfits.getdata(data1, 0)

    print 'Type: ', type(data_cube)
    print 'Shape:', data_cube.shape

    #I'm just going to look at a random slice                                                                 
    slice1 = data_cube[45, :, :]

    #Show the slice                                                                                           
    plt.imshow(slice1)
    plt.winter()
    plt.show()
示例#2
0
def ReturnSplineofEffectiveArea(
        filnameAndDir=None,
        ):
    """Spline of Effective Area as a function of Energy and CTheta. Energy is interms of log10 of 1MeV"""
    print pyfits.info( filnameAndDir) 
    CTHETA_LO_EA, CTHETA_HI_EA, energyLow_EA, energyHigh_EA, EFFAREA =EA.importEffectiveArea(filnameAndDir)
    energylogEA, CthetaEA=EA.centeringDataAndConvertingToLog(energyHigh_EA,energyLow_EA,CTHETA_HI_EA,CTHETA_LO_EA)
    SplineEA=RectBivariateSpline(CthetaEA,energylogEA,EFFAREA)
    return SplineEA
示例#3
0
def main():
    
    filenameEffArea='aeff_P7REP_ULTRACLEAN_V15_back.fits'
    directoryEffectiveArea='/Users/dspolyar/Documents/IRF/EffectiveArea/' 
    print pyfits.info( directoryEffectiveArea+filenameEffArea) 
    CTHETA_LO, CTHETA_HI, energyLow, energyHigh, EFFAREA = importEffectiveArea(directoryEffectiveArea+filenameEffArea)
    energylog, Ctheta=centeringDataAndConvertingToLog(energyHigh,energyLow,CTHETA_HI,CTHETA_LO)
    SplineEffectiveArea=RectBivariateSpline(Ctheta,energylog,EFFAREA)
    plotofEffectiveArea(SplineEffectiveArea,EFFAREA,energylog,Ctheta)
    print SplineEffectiveArea.ev(1.,5.)
def ReadLiveTimeCubeHealpixFile(filename=None, FileNumber=1):
    """Returns the heapix of the RA, DEC, and livetime in seconds spent at a given cosine on the sky"""
    hdulist = pyfits.open(filename)
    print pyfits.info(filename)
    print "columns of the first data file", hdulist[1].columns
    CosineLiveTimeData = hdulist[FileNumber].data["COSBINS"]
    RAdata = hdulist[FileNumber].data["RA"]
    DECdata = hdulist[FileNumber].data["DEC"]
    CThetaMax = hdulist[3].data["CTHETA_MAX"]
    CThetaMin = hdulist[3].data["CTHETA_MIN"]
    hdulist.close()
    return CosineLiveTimeData, RAdata, DECdata, CThetaMax, CThetaMin
示例#5
0
def fitsinfo(filename):
    """
    Print a summary of the HDUs in a FITS file.

    Parameters
    ----------
    filename : str
        The path to a FITS file.
    """

    try:
        fits.info(filename)
    except IOError as e:
        log.error(str(e))
    return
示例#6
0
def fitsinfo(filename):
    """
    Print a summary of the HDUs in a FITS file.

    Parameters
    ----------
    filename : str
        The path to a FITS file.
    """

    try:
        fits.info(filename)
    except IOError as e:
        log.error(str(e))
    return
示例#7
0
    def test_file_like_3(self):

        tmpfile = open(self.temp('tmpfile.fits'), 'wb')
        pyfits.writeto(tmpfile, np.arange(100, dtype=np.int32))
        tmpfile.close()
        info = [(0, 'PRIMARY', 'PrimaryHDU', 5, (100,), 'int32', '')]
        assert_equal(pyfits.info(self.temp('tmpfile.fits'), output=False),
                     info)
示例#8
0
def mycatfits(searchpattern):
    '''
    Looks for the information of images in a search pattern.
    '''

    import glob,pyfits

    imagelist = glob.glob(searchpattern)

    if (len(imagelist) == 0):
       print 'No images found using pattern:\n',searchpattern
       return

    print imagelist
    print ''

    for im in imagelist:

        pyfits.info(im)
        print ''
示例#9
0
    def test_file_like_2(self):
        hdu = fits.PrimaryHDU(np.arange(100, dtype=np.int32))
        tmpfile = open(self.temp('tmpfile.fits'), 'wb')
        hdul = fits.open(tmpfile, mode='ostream')
        hdul.append(hdu)
        hdul.flush()
        tmpfile.close()
        hdul.close()

        info = [(0, 'PRIMARY', 'PrimaryHDU', 5, (100,), 'int32', '')]
        assert fits.info(self.temp('tmpfile.fits'), output=False) == info
示例#10
0
    def test_file_like_2(self):
        hdu = fits.PrimaryHDU(np.arange(100, dtype=np.int32))
        tmpfile = open(self.temp("tmpfile.fits"), "wb")
        hdul = fits.open(tmpfile, mode="ostream")
        hdul.append(hdu)
        hdul.flush()
        tmpfile.close()
        hdul.close()

        info = [(0, "PRIMARY", "PrimaryHDU", 5, (100,), "int32", "")]
        assert fits.info(self.temp("tmpfile.fits"), output=False) == info
示例#11
0
    def test_append_primary_to_empty_list(self):
        # Tests appending a Simple PrimaryHDU to an empty HDUList.
        hdul = fits.HDUList()
        hdu = fits.PrimaryHDU(np.arange(100, dtype=np.int32))
        hdul.append(hdu)
        info = [(0, 'PRIMARY', 'PrimaryHDU', 5, (100,), 'int32', '')]
        assert hdul.info(output=False) == info

        hdul.writeto(self.temp('test-append.fits'))

        assert fits.info(self.temp('test-append.fits'), output=False) == info
def main():
    
    filenameEffArea='aeff_P7REP_ULTRACLEAN_V15_back.fits'
    directoryEffectiveArea= Const_LocalDirectoriesFermiFiles.DataFilesInstrumentResponse4UltraEffectiveAreaDirectory

    filepathEffArea = directoryEffectiveArea+'/'+filenameEffArea

    print pyfits.info( filepathEffArea ) 


    CTHETA_LO, CTHETA_HI, energyLow, energyHigh, EFFAREA = importEffectiveArea(filepathEffArea)
    energylog, Ctheta=centeringDataAndConvertingToLog(energyHigh,energyLow,CTHETA_HI,CTHETA_LO)
    #SplineEffectiveArea=RectBivariateSpline(Ctheta,energylog,EFFAREA)

    SplineEffectiveArea = Library_DataGetFermiInstrumentResponseEffectiveAreaPass7.Main(filepathEffArea)

    plotofEffectiveArea(SplineEffectiveArea,EFFAREA,energylog,Ctheta)


    print SplineEffectiveArea.ev(1.,5.) 
示例#13
0
    def test_append_extension_to_empty_list(self):
        """Tests appending a Simple ImageHDU to an empty HDUList."""

        hdul = fits.HDUList()
        hdu = fits.ImageHDU(np.arange(100, dtype=np.int32))
        hdul.append(hdu)
        info = [(0, "PRIMARY", "PrimaryHDU", 4, (100,), "int32", "")]
        assert hdul.info(output=False) == info

        hdul.writeto(self.temp("test-append.fits"))

        assert fits.info(self.temp("test-append.fits"), output=False) == info
示例#14
0
    def test_append_extension_to_empty_list(self):
        """Tests appending a Simple ImageHDU to an empty HDUList."""

        hdul = pyfits.HDUList()
        hdu = pyfits.ImageHDU(np.arange(100, dtype=np.int32))
        hdul.append(hdu)
        info = [(0, 'PRIMARY', 'PrimaryHDU', 4, (100,), 'int32', '')]
        assert_equal(hdul.info(output=False), info)

        hdul.writeto(self.temp('test-append.fits'))

        assert_equal(pyfits.info(self.temp('test-append.fits'), output=False),
                     info)
示例#15
0
    def test_insert_primary_to_empty_list(self):
        """Tests inserting a Simple PrimaryHDU to an empty HDUList."""
        hdul = fits.HDUList()
        hdu = fits.PrimaryHDU(np.arange(100, dtype=np.int32))
        hdul.insert(0, hdu)

        info = [(0, 'PRIMARY', 'PrimaryHDU', 5, (100,), 'int32', '')]

        assert hdul.info(output=False) == info

        hdul.writeto(self.temp('test-insert.fits'))

        assert fits.info(self.temp('test-insert.fits'), output=False) == info
示例#16
0
    def test_insert_primary_to_non_empty_list(self):
        """Tests inserting a Simple PrimaryHDU to a non-empty HDUList."""

        hdul = fits.open(self.data("arange.fits"))
        hdu = fits.PrimaryHDU(np.arange(100, dtype=np.int32))
        hdul.insert(1, hdu)

        info = [(0, "PRIMARY", "PrimaryHDU", 7, (11, 10, 7), "int32", ""), (1, "", "ImageHDU", 6, (100,), "int32", "")]

        assert hdul.info(output=False) == info

        hdul.writeto(self.temp("test-insert.fits"))

        assert fits.info(self.temp("test-insert.fits"), output=False) == info
def ReadEnergyDispersionFile(
    Filename_ED=None,
    ):

    hdulist_Edisp=pyfits.open(Filename_ED)

    print pyfits.info(Filename_ED)
    print hdulist_Edisp[2].data['EDISPSCALE'].shape
    print hdulist_Edisp[1].data['LS1']
    print hdulist_Edisp[1].columns
    
    ENERG_LO_Edisp=hdulist_Edisp[1].data['ENERG_LO']
    ENERG_HI_Edisp=hdulist_Edisp[1].data['ENERG_HI']
    CTHETA_LO_Edisp=hdulist_Edisp[1].data['CTHETA_LO']
    CTHETA_HI_Edisp=hdulist_Edisp[1].data['CTHETA_HI']
    NORM_Edisp=hdulist_Edisp[1].data['NORM']
    LS1_Edisp=hdulist_Edisp[1].data['LS1']
    LS2_Edisp=hdulist_Edisp[1].data['LS2']
    RS1_Edisp=hdulist_Edisp[1].data['RS1']
    RS2_Edisp=hdulist_Edisp[1].data['RS2']
    BIAS_Edisp=hdulist_Edisp[1].data['BIAS']

    return ENERG_LO_Edisp, ENERG_HI_Edisp, CTHETA_LO_Edisp,CTHETA_HI_Edisp,NORM_Edisp,LS1_Edisp,LS2_Edisp, RS1_Edisp,RS2_Edisp,BIAS_Edisp
示例#18
0
    def test_open_file_with_end_padding(self):
        """Regression test for https://aeon.stsci.edu/ssb/trac/pyfits/ticket/106

        Open files with end padding bytes.
        """

        hdul = fits.open(self.data("test0.fits"), do_not_scale_image_data=True)
        info = hdul.info(output=False)
        hdul.writeto(self.temp("temp.fits"))
        with open(self.temp("temp.fits"), "ab") as f:
            f.seek(0, os.SEEK_END)
            f.write("\0".encode("latin1") * 2880)
        with ignore_warnings():
            assert info == fits.info(self.temp("temp.fits"), output=False, do_not_scale_image_data=True)
示例#19
0
    def test_append_table_extension_to_empty_list(self):
        """Tests appending a Simple Table ExtensionHDU to a empty HDUList."""

        hdul = fits.HDUList()
        hdul1 = fits.open(self.data('tb.fits'))
        hdul.append(hdul1[1])
        info = [(0, 'PRIMARY', 'PrimaryHDU', 4, (), '', ''),
                (1, '', 'BinTableHDU', 24, '2R x 4C', '[1J, 3A, 1E, 1L]', '')]

        assert hdul.info(output=False) == info

        hdul.writeto(self.temp('test-append.fits'))

        assert fits.info(self.temp('test-append.fits'), output=False) == info
示例#20
0
    def test_insert_groupshdu_to_empty_list(self):
        """Tests inserting a Simple GroupsHDU to an empty HDUList."""

        hdul = fits.HDUList()
        hdu = fits.GroupsHDU()
        hdul.insert(0, hdu)

        info = [(0, "PRIMARY", "GroupsHDU", 8, (), "", "1 Groups  0 Parameters")]

        assert hdul.info(output=False) == info

        hdul.writeto(self.temp("test-insert.fits"))

        assert fits.info(self.temp("test-insert.fits"), output=False) == info
示例#21
0
    def test_open_file_with_end_padding(self):
        """Regression test for #106; open files with end padding bytes."""

        hdul = pyfits.open(self.data('test0.fits'),
                           do_not_scale_image_data=True)
        info = hdul.info(output=False)
        hdul.writeto(self.temp('temp.fits'))
        with open(self.temp('temp.fits'), 'ab') as f:
            f.seek(0, os.SEEK_END)
            f.write('\0'.encode('latin1') * 2880)
        with ignore_warnings():
            assert_equal(info,
                         pyfits.info(self.temp('temp.fits'), output=False,
                                     do_not_scale_image_data=True))
示例#22
0
    def test_insert_groupshdu_to_empty_list(self):
        """Tests inserting a Simple GroupsHDU to an empty HDUList."""

        hdul = fits.HDUList()
        hdu = fits.GroupsHDU()
        hdul.insert(0, hdu)

        info = [(0, 'PRIMARY', 'GroupsHDU', 8, (), '',
                 '1 Groups  0 Parameters')]

        assert hdul.info(output=False) == info

        hdul.writeto(self.temp('test-insert.fits'))

        assert fits.info(self.temp('test-insert.fits'), output=False) == info
示例#23
0
    def test_insert_extension_to_primary_in_non_empty_list(self):
        # Tests inserting a Simple ExtensionHDU to a non-empty HDUList.
        hdul = fits.open(self.data('tb.fits'))
        hdul.insert(0, hdul[1])

        info = [(0, 'PRIMARY', 'PrimaryHDU', 4, (), '', ''),
                (1, '', 'BinTableHDU', 24, '2R x 4C', '[1J, 3A, 1E, 1L]', ''),
                (2, '', 'ImageHDU', 12, (), '', ''),
                (3, '', 'BinTableHDU', 24, '2R x 4C', '[1J, 3A, 1E, 1L]', '')]

        assert hdul.info(output=False) == info

        hdul.writeto(self.temp('test-insert.fits'))

        assert fits.info(self.temp('test-insert.fits'), output=False) == info
示例#24
0
    def test_insert_primary_to_non_empty_list(self):
        """Tests inserting a Simple PrimaryHDU to a non-empty HDUList."""

        hdul = fits.open(self.data('arange.fits'))
        hdu = fits.PrimaryHDU(np.arange(100, dtype=np.int32))
        hdul.insert(1, hdu)

        info = [(0, 'PRIMARY', 'PrimaryHDU', 7, (11, 10, 7), 'int32', ''),
                (1, '', 'ImageHDU', 6, (100,), 'int32', '')]

        assert hdul.info(output=False) == info

        hdul.writeto(self.temp('test-insert.fits'))

        assert fits.info(self.temp('test-insert.fits'), output=False) == info
示例#25
0
    def test_append_groupshdu_to_empty_list(self):
        """Tests appending a Simple GroupsHDU to an empty HDUList."""

        hdul = pyfits.HDUList()
        hdu = pyfits.GroupsHDU()
        hdul.append(hdu)

        info = [(0, 'PRIMARY', 'GroupsHDU', 8, (), 'uint8',
                 '1 Groups  0 Parameters')]

        assert_equal(hdul.info(output=False), info)

        hdul.writeto(self.temp('test-append.fits'))

        assert_equal(pyfits.info(self.temp('test-append.fits'), output=False),
                     info)
示例#26
0
    def test_append_table_extension_to_empty_list(self):
        """Tests appending a Simple Table ExtensionHDU to a empty HDUList."""

        hdul = fits.HDUList()
        hdul1 = fits.open(self.data("tb.fits"))
        hdul.append(hdul1[1])
        info = [
            (0, "PRIMARY", "PrimaryHDU", 4, (), "", ""),
            (1, "", "BinTableHDU", 24, "2R x 4C", "[1J, 3A, 1E, 1L]", ""),
        ]

        assert hdul.info(output=False) == info

        hdul.writeto(self.temp("test-append.fits"))

        assert fits.info(self.temp("test-append.fits"), output=False) == info
示例#27
0
    def test_append_primary_to_non_empty_list(self):
        """Tests appending a Simple PrimaryHDU to a non-empty HDUList."""

        hdul = pyfits.open(self.data('arange.fits'))
        hdu = pyfits.PrimaryHDU(np.arange(100, dtype=np.int32))
        hdul.append(hdu)

        info = [(0, 'PRIMARY', 'PrimaryHDU', 7, (11, 10, 7), 'int32', ''),
                (1, '', 'ImageHDU', 6, (100,), 'int32', '')]

        assert_equal(hdul.info(output=False), info)

        hdul.writeto(self.temp('test-append.fits'))

        assert_equal(pyfits.info(self.temp('test-append.fits'), output=False),
                     info)
示例#28
0
    def test_insert_extension_to_non_empty_list(self):
        """Tests inserting a Simple ExtensionHDU to a non-empty HDUList."""

        hdul = pyfits.open(self.data('tb.fits'))
        hdul.insert(1, hdul[1])

        info = [(0, 'PRIMARY', 'PrimaryHDU', 11, (), 'int16', ''),
                (1, '', 'BinTableHDU', 24, '2R x 4C', '[1J, 3A, 1E, 1L]', ''),
                (2, '', 'BinTableHDU', 24, '2R x 4C', '[1J, 3A, 1E, 1L]', '')]

        assert_equal(hdul.info(output=False), info)

        hdul.writeto(self.temp('test-insert.fits'))

        assert_equal(pyfits.info(self.temp('test-insert.fits'), output=False),
                     info)
示例#29
0
    def test_file_like(self):
        """
        Tests the use of a file like object with no tell or seek methods
        in HDUList.writeto(), HDULIST.flush() or pyfits.writeto()
        """

        hdu = fits.PrimaryHDU(np.arange(100, dtype=np.int32))
        hdul = fits.HDUList()
        hdul.append(hdu)
        tmpfile = open(self.temp('tmpfile.fits'), 'wb')
        hdul.writeto(tmpfile)
        tmpfile.close()

        info = [(0, 'PRIMARY', 'PrimaryHDU', 5, (100,), 'int32', '')]

        assert fits.info(self.temp('tmpfile.fits'), output=False) == info
示例#30
0
    def test_open_file_with_end_padding(self):
        """Regression test for https://trac.assembla.com/pyfits/ticket/106

        Open files with end padding bytes.
        """

        hdul = fits.open(self.data('test0.fits'),
                         do_not_scale_image_data=True)
        info = hdul.info(output=False)
        hdul.writeto(self.temp('temp.fits'))
        with open(self.temp('temp.fits'), 'ab') as f:
            f.seek(0, os.SEEK_END)
            f.write('\0'.encode('latin1') * 2880)
        with ignore_warnings():
            assert info == fits.info(self.temp('temp.fits'), output=False,
                                     do_not_scale_image_data=True)
示例#31
0
    def test_insert_extension_to_primary_in_non_empty_list(self):
        # Tests inserting a Simple ExtensionHDU to a non-empty HDUList.
        hdul = fits.open(self.data("tb.fits"))
        hdul.insert(0, hdul[1])

        info = [
            (0, "PRIMARY", "PrimaryHDU", 4, (), "", ""),
            (1, "", "BinTableHDU", 24, "2R x 4C", "[1J, 3A, 1E, 1L]", ""),
            (2, "", "ImageHDU", 12, (), "", ""),
            (3, "", "BinTableHDU", 24, "2R x 4C", "[1J, 3A, 1E, 1L]", ""),
        ]

        assert hdul.info(output=False) == info

        hdul.writeto(self.temp("test-insert.fits"))

        assert fits.info(self.temp("test-insert.fits"), output=False) == info
示例#32
0
    def test_insert_image_extension_to_primary_in_non_empty_list(self):
        """
        Tests inserting a Simple Image ExtensionHDU to a non-empty HDUList
        as the primary HDU.
        """

        hdul = fits.open(self.data('tb.fits'))
        hdu = fits.ImageHDU(np.arange(100, dtype=np.int32))
        hdul.insert(0, hdu)

        info = [(0, 'PRIMARY', 'PrimaryHDU', 5, (100,), 'int32', ''),
                (1, '', 'ImageHDU', 12, (), '', ''),
                (2, '', 'BinTableHDU', 24, '2R x 4C', '[1J, 3A, 1E, 1L]', '')]

        assert hdul.info(output=False) == info

        hdul.writeto(self.temp('test-insert.fits'))

        assert fits.info(self.temp('test-insert.fits'), output=False) == info
示例#33
0
    def test_insert_groupshdu_to_non_empty_list(self):
        """Tests inserting a Simple GroupsHDU to an empty HDUList."""

        hdul = fits.HDUList()
        hdu = fits.PrimaryHDU(np.arange(100, dtype=np.int32))
        hdul.insert(0, hdu)
        hdu = fits.GroupsHDU()

        assert_raises(ValueError, hdul.insert, 1, hdu)

        info = [(0, 'PRIMARY', 'GroupsHDU', 8, (), '',
                 '1 Groups  0 Parameters'),
                (1, '', 'ImageHDU', 6, (100,), 'int32', '')]

        hdul.insert(0, hdu)

        assert hdul.info(output=False) == info

        hdul.writeto(self.temp('test-insert.fits'))

        assert fits.info(self.temp('test-insert.fits'), output=False) == info
示例#34
0
import matplotlib.pyplot as plt
# to use flipper
import liteMap
# healpy
import healpy as hp
import pyfits

###################################################################

# fits file to be read
file_path = '/Users/Emmanuel/Desktop/kSZ/data/act_maps_14oct2014/deep5/cluster_mask.fits'

# print infos on the various HDUs (Header and Data Units)
print ""
print "Infos on the HDUs (Header and Data Units)"
pyfits.info(file_path)

###################################################################
# get infos about the header

# read header
header = pyfits.getheader(file_path)

print ""
print "Print the header keys"
print header.keys()

print ""
print "Value of the 'bitpix' card opject (2 ways)"
print header['bitpix']
print pyfits.getval(file_path, 'bitpix')
示例#35
0
 def test_file_like_3(self):
     tmpfile = open(self.temp('tmpfile.fits'), 'wb')
     fits.writeto(tmpfile, np.arange(100, dtype=np.int32))
     tmpfile.close()
     info = [(0, 'PRIMARY', 'PrimaryHDU', 5, (100,), 'int32', '')]
     assert fits.info(self.temp('tmpfile.fits'), output=False) == info
示例#36
0
    def __init__(self, path):
        """ Instantiation method for the FITSImage class.

        A copy of the header of the FITS file is kept in memory for fast access
        to its keywords. IOError is raised if 'path' does not exist or is not
        readable, and NonStardardFITS in case that it does not conform to the
        FITS standard or it simply is not a FITS file at all.

        FITS Standard Document:
        http://fits.gsfc.nasa.gov/fits_standard.html

        An image is considered to follow the FITS standard if it has 'SIMPLE'
        as its first keyword of the primary header. According to the standard,
        it contains a logical constant with the value 'T' if the file conforms
        to it. This keyword is mandatory for the primary header and is not
        permitted in extension headers. A value of 'F', on the other hand,
        means that the file does not conform to the standard.

        We trust the 'SIMPLE' keyword blindly: if is says that the FITS image
        follows the standard, we believe it. Period. We do not consider the
        possibility (although this may change in the future, if we begin to
        work with much less reliable data) that the keyword has a value of 'T'
        while at the same time there are violations of the standard. That is
        why we instruct PyFITS to ignore any FITS standard violations we come
        across (output_verify = 'ignore').

        """

        if not os.path.exists(path):
            raise IOError("file '%s' does not exist" % path)

        self.path = path

        try:
            # The file must be opened to make sure it is a standard FITS.
            # We would rather use the with statement, but in that case we
            # would not be able to set the output verification of close() to
            # 'ignore'. Thus, the default option, 'exception', which raises
            # an exception if any FITS standard is violated, would be used.
            handler = pyfits.open(self.path, mode='readonly')
            try:

                # This is kind of an ugly hack to make sure that all PyFITS
                # versions are supported. Up to version 3.2, PyFITS returned
                # the HDUs exactly as it saw them. This allowed us to check the
                # existence and value of the 'SIMPLE' keyword in order to make
                # sure the file conforms to the FITS standard. However, PyFITS
                # 3.3 changed this, and now adds the keywords required for a
                # minimal viable primary HDU: this means that the header will
                # always contain the 'SIMPLE' keyword. Refer to this link for
                # more info: https://github.com/spacetelescope/PyFITS/issues/94

                try:
                    type_ = pyfits.info(self.path, output=False)[0][2]
                    if type_ == 'NonstandardHDU':
                        # 'SIMPLE' exists but does not equal 'T'
                        msg = "%s: value of 'SIMPLE' keyword is not 'T'"
                        raise NonStandardFITS(msg % self.path)

                except AttributeError as e:
                    # 'SIMPLE' keyword does not exist
                    error_msg = "'_ValidHDU' object has no attribute '_summary'"
                    assert error_msg in str(e)
                    msg = "%s: 'SIMPLE' keyword missing from header"
                    raise NonStandardFITS(msg % self.path)

                # A copy of the FITS header is kept in memory and the file is
                # closed; otherwise we may run into trouble when working with
                # thousands of images ("too many open files" and such). This
                # approach gives us fast read-only access to the image header;
                # if modified, we will have to take care of 'reloading' (call
                # it synchronize, if you wish) the header.

                self.size = handler[0].data.shape[::-1]
                self._header = handler[0].header
            finally:
                handler.close(output_verify='ignore')

        # PyFITS raises IOError if we do not have permission to open the file,
        # if we attempt to open a non-FITS file, and also if we open one whose
        # first keyword is not either SIMPLE or XTENSION. Nothing is raised if
        # the value of SIMPLE is 'F'; that is why we had to specifically make
        # sure it was 'T' a few lines above.
        except IOError, e:
            pyfits_msg = "Block does not begin with SIMPLE or XTENSION"
            if str(e) == pyfits_msg:
                msg = "%s: 'SIMPLE' keyword missing from primary header"
                raise NonStandardFITS(msg % self.path)
            elif "Permission denied" in str(e):
                raise
            else:
                msg = "%s (%s)" % (self.path, str(e))
                raise NonStandardFITS(msg)
示例#37
0
import galsim
import os
import matplotlib.pyplot as plt

# File name definitions, etc.  Users must change the first one to point to the proper location!
in_dir = '/Users/rmandelb/great3/data-23.5'
cat_file = 'real_galaxy_catalog_23.5.fits'
fit_file = 'real_galaxy_catalog_23.5_fits.fits'
out_dir = 'diagnostics'
if not os.path.exists(out_dir):
    os.mkdir(out_dir)

# Check contents of catalog file.
filename = os.path.join(in_dir, cat_file)
print "Information about catalog file :"
print pyfits.info(filename)
filename = os.path.join(in_dir, fit_file)
print "Information about file with galaxy fits:"
print pyfits.info(filename)

# Make sure we can read in the catalogs / images into GalSim.
real_galaxy_catalog = galsim.RealGalaxyCatalog(cat_file, dir=in_dir)
gal = galsim.RealGalaxy(real_galaxy_catalog, random=True)
print "Read in RealGalaxyCatalog with ", real_galaxy_catalog.nobjects
print "index used: ", gal.index
print "corresponding IDENT: ", real_galaxy_catalog.ident[gal.index]

# Make sure we can read in the catalog with info about Claire's fits.
# Check correspondence in number of objects.
fit_catalog = pyfits.getdata(filename)
print "Read in catalog of ", len(fit_catalog), " fits from file ", filename
示例#38
0
imagen_end = imagen_in[:-5]

result_END = imagen_end + "_Corrected.fits"

FILE_TEMP = imagen_end + "_tmp.fits"

imagen_header_original = sys.argv[
    1]  # Imagen Original con todos los headers, la misma usada para la correccion del amp5
imagen_Corre = imagen_end + "_Corrected.fits"  # Output de la correccion de amp5, NAME_Corrected.fits

#copiando el archivo
import shutil
shutil.copyfile(imagen_header_original, FILE_TEMP)

pyfits.info(imagen_header_original)
pyfits.info(FILE_TEMP)
pyfits.info(imagen_in)

imagen_header2 = FILE_TEMP  # deben ser igual al de imagen_header

header = pyfits.getheader(FILE_TEMP)
header2 = pyfits.getheader(FILE_TEMP, 2)

imagen_no_header = pyfits.getdata(imagen_Corre, header=False)

from pyfits import update
pyfits.update(imagen_header2, imagen_no_header, ext=2)
pyfits.update(imagen_header2, imagen_no_header, header2, 2)

###copiando resultado final
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>

# <codecell>
from __future__ import division 
import pyfits
import numpy as np
import matplotlib.pyplot as plt

s = "hmi.m_45s.magnetogram.subregion_x1y1.fits"
n_iterations = 20000 #this is the number of iterations I want to make

# <codecell>

pyfits.info(s)

# <codecell>

 #Se obtienen los datos
data = pyfits.getdata(s,0)
data.shape

# <codecell>

#Se grafica una  linea de tiempo
test = data[:,138,241]
x = np.linspace(0, 397, 398)
y = np.linspace(0, 198, 199)
z = np.linspace(0, 206, 207)
#plt.plot(z, test)
#plt.show()