Beispiel #1
0
def doplatescale(infn,outfn,latlon,ut1):
    fitsfn = Path(outfn).expanduser().with_suffix('.fits')
#%% convert to mean
    meanimg,ut1 = meanstack(infn,10,ut1)
    writefits(meanimg,fitsfn)
#%%
    x,y,ra,dec,az,el,timeFrame = fits2azel(fitsfn,latlon,ut1,['show','h5','png'],(0,2800))
def starbright(fnstar,fnflat,istar,axs,fg):
    #%% load data
    data = meanstack(fnstar,100)[0]
    #%% flat field
    flatnorm = readflat(fnflat,fnstar)
    data = (data/flatnorm).round().astype(data.dtype)
    #%% background
    mean, median, std = sigma_clipped_stats(data, sigma=3.0)

    rfact=data.shape[0]//40
    cfact=data.shape[1]//40
    bg = Background(data,(rfact,cfact),interp_order=1, sigclip_sigma=3)
# http://docs.astropy.org/en/stable/units/#module-astropy.units
    #dataphot = (data - bg.background)*u.ph/(1e-4*u.m**2 * u.s * u.sr)
 #   data = (data-0.97*data.min()/bg.background.min()*bg.background) * u.ph/(u.cm**2 * u.s * u.sr)
    data = data* u.ph/(u.cm**2 * u.s * u.sr)
    #%% source extraction
    sources = daofind(data, fwhm=3.0, threshold=5*std)
    #%% star identification and quantification
    XY = column_stack((sources['xcentroid'], sources['ycentroid']))
    apertures = CircularAperture(XY, r=4.)
    norm = ImageNormalize(stretch=SqrtStretch())

    flux = apertures.do_photometry(data,effective_gain=camgain)[0]
#%% plots
    fg.suptitle('{}'.format(fnflat.parent),fontsize='x-large')

    hi = axs[-3].imshow(flatnorm,interpolation='none',origin='lower')
    fg.colorbar(hi,ax=axs[-3])
    axs[-3].set_title('flatfield {}'.format(fnflat.name))

    hi = axs[-2].imshow(bg.background,interpolation='none',origin='lower')
    fg.colorbar(hi,ax=axs[-2])
    axs[-2].set_title('background {}'.format(fnstar.name))

    hi = axs[-1].imshow(data.value,
                    cmap='Greys', origin='lower', norm=norm,interpolation='none')
    fg.colorbar(hi,ax=axs[-1])
    for i,xy in enumerate(XY):
        axs[-1].text(xy[0],xy[1], str(i),ha='center',va='center',fontsize=16,color='w')
    apertures.plot(ax=axs[-1], color='blue', lw=1.5, alpha=0.5)
    axs[-1].set_title('star {}'.format(fnstar.name))

    return flux[istar]
Beispiel #3
0
#!/usr/bin/env python3
"""
Takes FITS image stack of a uniformly illuminated field (e.g. tungsten light box)
and discards the first "bad" image in the stack, then takes the mean of the other images
and saves the result to an HDF5 file.

To do tomographic analysis, you must take into account the vignetting of the optical
system via flat-fielding, plus the background subtraction
"""
from pathlib import Path
from matplotlib.pyplot import show
#
from astrometry_azel.imgAvgStack import meanstack
from starscale.flatfield import writeflatfield,plotflatfield

# these files in Dropbox as hst0flat.h5, hst1flat.h5
#fn = '~/HST/calibration/flatfield/hist0/TungstenUltra53HzG2EM20_A.fits'
#fn = '~/HST/calibration/flatfield/hist1/tungstenExternal30fps_preamp1EM200.fits'
method='median'

if __name__ == "__main__":
    mimg = meanstack(fn,slice(1,None),method=method)[0]

    ofn = Path(fn).expanduser().with_suffix('.h5')
    writeflatfield(ofn,mimg)

    plotflatfield(mimg)

    show()
from numpy.ma import masked_where
from sympy.ntheory import factorint
from astropy.stats import sigma_clipped_stats
#from astropy.convolution import Gaussian2DKernel
from photutils.detection import detect_sources
from photutils.background import Background
from skimage.morphology import binary_dilation
from matplotlib.pyplot import figure,subplots,show
import seaborn as sns
sns.set_context('talk')
#
from astrometry_azel.imgAvgStack import meanstack #reads the typical formats our group stores images in
#
infn = '../astrometry_azel/test/apod4.fits'

data = meanstack(infn,1)[0]


#%% now photutils way
#rfact = max(list(factorint(data.shape[0]).keys()))
#cfact = max(list(factorint(data.shape[1]).keys()))
rfact=data.shape[0]//10
cfact=data.shape[1]//10
bg = Background(data,(rfact,cfact))
dataphot = data - bg.background
#%%

fg,axs = subplots(1,2)

ax = axs[0]
hi=ax.imshow(dataphot,interpolation='none',cmap='gray')