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


Python ccdproc.CCDData类代码示例

本文整理汇总了Python中ccdproc.CCDData的典型用法代码示例。如果您正苦于以下问题:Python CCDData类的具体用法?Python CCDData怎么用?Python CCDData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: makeMasterFlat

def makeMasterFlat(images, master_bias):
    """
    Flats are corrected for their bias level (if
    master_bias)

    TODO: Finish docstring
    """
    try:
        fitsfile = 'master_flat.fits'
        master_flat = CCDData.read(fitsfile, unit=u.adu)
        return master_flat
    except FileNotFoundError:
        # empty list for the flats
        flat_list = []
        # create the master flat field
        print('Reducing flats')
        for f in images.files_filtered(imagetyp=FLAT_KEYWORD):
            print(f)
            with fits.open(f) as fitsfile:
                data_exp = fitsfile[0].header[EXPTIME_KEYWORD]
            ccd = CCDData.read(f, unit=u.adu)
            if master_bias:
                ccd = subtract_bias(ccd, master_bias)
            else:
                print('No master bias, skipping correction...')
            flat_list.append(ccd)
        try:
            master_flat = combine(flat_list, method='median')
            master_flat.write('master_flat.fits', clobber=True)
            return master_flat
        except IndexError:
            print('There are no flats, skipping...')
            master_flat = None
开发者ID:jmccormac01,项目名称:Spectroscopy,代码行数:33,代码来源:Spector.py

示例2: load_image

def load_image(filename):
    try:
        data = CCDData.read(filename)
    except(ValueError):
        try:
            data = CCDData.read(filename, unit = u.dyn)
        except:
            raise
    return data
开发者ID:dunkenj,项目名称:lofar-tools,代码行数:9,代码来源:cutouts.py

示例3: reduce_image

def reduce_image(imagefile, dark=None, flat=None):
    im = CCDData.read(imagefile, unit='adu')
    if dark is not None:
        dark = CCDData.read(dark, unit='adu')
        im = im.subtract(dark)
    if flat is not None:
#         masterflat = CCDData.read(flat, unit='adu')
        hdul = fits.open(flat)
        masterflat = CCDData(data=hdul[0].data, uncertainty=None, meta=hdul[0].header, unit='adu')
        im = flat_correct(im, masterflat)
    return im
开发者ID:joshwalawender,项目名称:KeckUtilities,代码行数:11,代码来源:slitAlign.py

示例4: main

def main():
    parser = argparse.ArgumentParser(description='Perform LACosmic cleaning of images')
    parser.add_argument('filenames',nargs='+',help='List of files to clean.')
    parser.add_argument('-odir',metavar='outdir',required=True,type=str,help='Output directory for files.')
    #parser.add_argument('-mode',choices=['lacosmic','median'],default='lacosmic',help='Specify mode of operation (default=lacosmic)')
    parser.add_argument('-sclip',metavar='sigclip',type=float,default=5,help='Laplacian-to-noise limit for cosmic ray detection. Lower values will flag more pixels as cosmic rays (default=5).')
    parser.add_argument('-sfrac',metavar='sigfrac',type=float,default=0.3,help='Fractional detection limit for neighboring pixels. For cosmic ray neighbor pixels, a Laplacian-to-noise detection limit of sigfrac * sigclip will be used. (default=0.3).')
    parser.add_argument('-objlim',type=float,default=5,help='Minimum contrast between Laplacian image and the fine structure image. Increase this value if cores of bright stars are flagged as cosmic rays (default=5).')
    parser.add_argument('-satlevel',type=float,default=65535,help='Saturation level of the image (electrons). This value is used to detect saturated stars and pixels at or above this level are added to the mask (default=65535)')
    parser.add_argument('-niter',type=int,default=5,help='umber of iterations of the LA Cosmic algorithm to perform (default=5).')
    #parser.add_argument('-thresh',metavar='threshold',type=float,default=5,help='Threshold for detecting cosmic rays [median] (default=5).')
    #parser.add_argument('-mbox',type=float,default=11,help='Median box for detecting cosmic rays [mbox] (default=11).')
    parser.add_argument('-njobs',type=int,default=1,help='Process images in parallel. "-1" is all CPUs (default=1).')
    parser.add_argument('--c',action='store_true',help='Clobber (overwrite) on output')

    args = parser.parse_args()

    ccds = (CCDData.read(fname,unit='adu') for fname in args.filenames)
    
    with Parallel(args.njobs,verbose=11) as parallel:
        cleaned = parallel(delayed(cosmicray_lacosmic)(ccd,sigclip=args.sclip,sigfrac=args.sfrac,niter=args.niter,objlim=args.objlim,satlevel=args.satlevel) for ccd in ccds)

    outfiles = (os.path.join(args.odir,os.path.basename(fname)) for fname in args.filenames)
    for hdu,outfile in zip(cleaned,outfiles):
        if isinstance(hdu,CCDData):
            hdu = hdu.to_hdu(hdu_mask=None,hdu_uncertainty=None)
        header = hdu[0].header
        header.add_history('clean.py - %s' % Time(Time.now(),format='fits'))
        header['CLEANED'] = (True,'Cleaned with LACosmics')
        header['CLNMTHD'] = (CLNMTHD,'Method used to clean')
        try:
            hdu.writeto(outfile,overwrite=args.c)
        except OSError as e:
            raise OSError("File '%s' already exists.  Re-run with --c flag to overwrite existing files." % outfile) from e
开发者ID:msgordon,项目名称:optipol-reduc,代码行数:34,代码来源:clean.py

示例5: setUp

    def setUp(self):
        # create a master flat
        self.master_flat = CCDData(data=np.ones((100, 100)),
                                   meta=fits.Header(),
                                   unit='adu')
        self.master_flat.header.set('GRATING', value='RALC_1200-BLUE')
        self.master_flat.header.set('SLIT', value='0.84" long slit')
        self.master_flat.header.set('FILTER2', value='<NO FILTER>')
        self.master_flat.header.set('WAVMODE', value='1200 m2')
        self.master_flat_name = 'master_flat_1200m2.fits'
        # expected master flat to be retrieved by get_best_flat
        self.reference_flat_name = 'master_flat_1200m2_0.84_dome.fits'
        # location of sample flats
        self.flat_path = 'goodman_pipeline/data/test_data/master_flat'
        slit = re.sub('[A-Za-z" ]',
                      '',
                      self.master_flat.header['SLIT'])
        self.flat_name_base = re.sub('.fits',
                                     '_' + slit + '*.fits',
                                     self.master_flat_name)

        # save a master flat with some random structure.

        self.master_flat_name_norm = 'flat_to_normalize.fits'
        # add a bias level
        self.master_flat.data += 300.
        # add noise
        self.master_flat.data += np.random.random_sample(
            self.master_flat.data.shape)

        self.master_flat.write(os.path.join(self.flat_path,
                                            self.master_flat_name_norm),
                               overwrite=False)
开发者ID:simontorres,项目名称:goodman,代码行数:33,代码来源:test_core.py

示例6: __call__

    def __call__(self, in_file, save=False):

        self.file = in_file
        self.fig, self.ax = plt.subplots()

        # read data and get its wavelength solution
        ccd = CCDData.read(self.file, unit=u.adu)
        wcs_reader = ReadWavelengthSolution(header=ccd.header,
                                            data=ccd.data)
        wavelength, intensity = wcs_reader()


        manager = plt.get_current_fig_manager()
        manager.window.showMaximized()
        plt.title('{:s}\n{:s}'.format(self.file, ccd.header['OBJECT']))

        self.ax.plot(wavelength, intensity, color='k', label='Data')
        self.ax.axvline(6562.8, color='r')
        self.ax.set_xlim((wavelength[0], wavelength[-1]))
        self.ax.set_ylabel('Intensity (ADU)')
        self.ax.set_xlabel('Wavelength (Angstrom)')

        plt.legend(loc='best')
        plt.subplots_adjust(left=0.05,
                            right=0.99,
                            top=0.96,
                            bottom=0.04,
                            hspace=0.17,
                            wspace=0.11)
        # plt.tight_layout()

        if not save:
            self.fig.canvas.mpl_connect('key_press_event', self.key_pressed)
            plt.show()
开发者ID:simontorres,项目名称:goodman,代码行数:34,代码来源:plot-fits-file.py

示例7: test_fit_linear

 def test_fit_linear(self):
     test_file = os.path.join(self.data_path,
                              'goodman_comp_400M1_HgArNe.fits')
     ccd = CCDData.read(test_file, unit='adu')
     pixel, angstrom = self._recover_lines(ccd=ccd)
     model = self.wcs.fit(physical=pixel,
                          wavelength=angstrom,
                          model_name='linear')
     self.assertIsInstance(model, Model)
开发者ID:simontorres,项目名称:goodman,代码行数:9,代码来源:test_functional.py

示例8: test_read__non_linear_cspline

    def test_read__non_linear_cspline(self):
        test_file = os.path.join(self.data_path,
                                 'non-linear_fits_solution_cubic-spline.fits')
        self.assertTrue(os.path.isfile(test_file))

        ccd = CCDData.read(test_file, unit='adu')
        self.assertRaises(NotImplementedError, self.wcs.read, ccd)
        self.assertRaisesRegex(NotImplementedError,
                               'Cubic spline is not implemented',
                               self.wcs.read, ccd)
开发者ID:simontorres,项目名称:goodman,代码行数:10,代码来源:test_functional.py

示例9: test_read__non_linear_legendre

    def test_read__non_linear_legendre(self):
        test_file = os.path.join(self.data_path,
                                 'non-linear_fits_solution_legendre.fits')
        self.assertTrue(os.path.isfile(test_file))

        ccd = CCDData.read(test_file, unit='adu')

        result = self.wcs.read(ccd=ccd)
        self.assertIsInstance(self.wcs.model, Model)
        self.assertEqual(self.wcs.model.__class__.__name__, 'Legendre1D')
开发者ID:simontorres,项目名称:goodman,代码行数:10,代码来源:test_functional.py

示例10: test_read_gsp_wcs

    def test_read_gsp_wcs(self):
        test_file = os.path.join(self.data_path,
                                 'goodman_comp_400M1_HgArNe.fits')

        self.assertTrue(os.path.isfile(test_file))
        ccd = CCDData.read(test_file, unit='adu')
        result = self.wcs.read_gsp_wcs(ccd=ccd)

        self.assertIsInstance(result, list)
        self.assertEqual(len(result), 2)
        self.assertIsInstance(self.wcs.get_model(), Model)
开发者ID:simontorres,项目名称:goodman,代码行数:11,代码来源:test_functional.py

示例11: test_read__linear

    def test_read__linear(self):
        test_file = os.path.join(self.data_path,
                                 'linear_fits_solution.fits')
        self.assertTrue(os.path.isfile(test_file))

        ccd = CCDData.read(test_file, unit='adu')

        result = self.wcs.read(ccd=ccd)

        self.assertIsInstance(result, list)
        self.assertEqual(len(result), 2)
        self.assertIsInstance(self.wcs.get_model(), Model)
开发者ID:simontorres,项目名称:goodman,代码行数:12,代码来源:test_functional.py

示例12: create_master_flat

def create_master_flat(filepath='../../../KeckData/MOSFIRE_FCS/',
                       flatfiles = ['m180130_0320.fits',
                                    'm180130_0321.fits',
                                    'm180130_0322.fits',
                                    'm180130_0323.fits',
                                    'm180130_0324.fits',],
                       darkfile = 'm180130_0001.fits',
                      ):
    dark = CCDData.read(os.path.join(filepath, darkfile), unit='adu')
    flats = []
    for i,file in enumerate(flatfiles):
        flat = CCDData.read(os.path.join(filepath, file), unit='adu')
        flat = flat.subtract(dark)
        flats.append(flat)

    flat_combiner = Combiner(flats)
    flat_combiner.sigma_clipping()
    scaling_func = lambda arr: 1/np.ma.average(arr)
    flat_combiner.scaling = scaling_func
    masterflat = flat_combiner.median_combine()

    masterflat.write('masterflat.fits', overwrite=True)
开发者ID:joshwalawender,项目名称:KeckUtilities,代码行数:22,代码来源:slitAlign.py

示例13: test_read__invalid

    def test_read__invalid(self):
        test_file = os.path.join(self.data_path,
                                 'linear_fits_solution.fits')
        self.assertTrue(os.path.isfile(test_file))

        ccd = CCDData.read(test_file, unit='adu')
        ccd.wcs.wcs.ctype[0] = 'INVALID'

        self.assertRaisesRegex(NotImplementedError,
                               'CTYPE INVALID is not recognized',
                               self.wcs.read,
                               ccd)
        self.assertRaises(NotImplementedError, self.wcs.read, ccd)
开发者ID:simontorres,项目名称:goodman,代码行数:13,代码来源:test_functional.py

示例14: makeMasterBias

def makeMasterBias(images):
    """
    Make a master bias using all biases found in
    images object

    TODO: Finish docstring
    """
    try:
        master_bias = CCDData.read('master_bias.fits', unit=u.adu)
        return master_bias
    except FileNotFoundError:
        bias_list = []
        for f in images.files_filtered(imagetyp=BIAS_KEYWORD):
            print(f)
            ccd = CCDData.read(f, unit=u.adu)
            bias_list.append(ccd)
        try:
            master_bias = combine(bias_list, method='median')
            master_bias.write('master_bias.fits', clobber=True)
            return master_bias
        except IndexError:
            return None
开发者ID:jmccormac01,项目名称:Spectroscopy,代码行数:22,代码来源:Spector.py

示例15: test_fit_chebyshev

    def test_fit_chebyshev(self):
        test_file = os.path.join(self.data_path,
                                 'goodman_comp_400M1_HgArNe.fits')
        ccd = CCDData.read(test_file, unit='adu')
        pixel, angstrom = self._recover_lines(ccd=ccd)
        model = self.wcs.fit(physical=pixel, wavelength=angstrom)
        self.assertIsInstance(model, Model)

        self.assertEqual(model.__class__.__name__, ccd.header['GSP_FUNC'])
        self.assertEqual(model.degree, ccd.header['GSP_ORDR'])
        for i in range(model.degree + 1):
            self.assertAlmostEqual(model.__getattr__('c{:d}'.format(i)).value,
                             ccd.header['GSP_C{:03d}'.format(i)])
开发者ID:simontorres,项目名称:goodman,代码行数:13,代码来源:test_functional.py


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