示例#1
0
def reference_object(obj):
    ft = matrixDFT.MatrixFourierTransform()
    obj_transform = ft.perform(obj, narray, narray)

    cropped_obj_transform = np.zeros(narray * narray).reshape(narray, narray)
    cropped_obj_transform[439:450, 439:450] = obj_transform[439:450, 439:450]

    ref_obj = ft.inverse(cropped_obj_transform, narray, narray)
    detector_ref_obj = rebin(ref_obj, ov)

    return detector_ref_obj
示例#2
0
def check_object(a,b,thresh_percent,pup,opd,ff,NL,C):
	ft = matrixDFT.MatrixFourierTransform()
	
	narray = a.shape[0]
	
	CV = ft.perform(a,narray,narray)
	OTF = ft.perform(b,narray,narray)
	
	thresh = abs(OTF).max()*thresh_percent
	idx = np.where(abs(OTF)>=thresh)
	
	objtfm = np.zeros(narray*narray).reshape(narray,narray)
	
	objtfm[idx] = CV[idx]/OTF[idx]
	
	ant_alias = makedisk(narray,ctr = (40,40),radius = 20)
	
	new_obj = ft.inverse(objtfm*ant_alias,narray,narray)
	
	return new_obj, CV
示例#3
0
import plotly
import plotly.graph_objs as go

import complex_demo

plotly.offline.init_notebook_mode()

shift = 10
sigma = 10
narray = 101

#generate a Gaussian function
x, gaussian_array = complex_demo.make1DGaussian(narray, sigma, x0=shift)

#Fourier transform
#instantiate an mft object:
#make it as 2D array matrixDFT takes 2D
gaussian_array = np.array([gaussian_array])
ft = matrixDFT.MatrixFourierTransform()
ft_gaussian = ft.perform(gaussian_array, 9, (1, 81))

xx = np.linspace(-40, 40, 81)

#plot the result
complex_demo.complex_3dplot(xx,
                            ft_gaussian[0],
                            real_color='purple',
                            plot=True,
                            filename='example_gauss')
示例#4
0
def find_centroid(a, thresh, verbose=False):
    """ 
    input a: input array (real, square), considered 'image space'
    input thresh: normalize abs(cv = ft(a)) and define support of good cv when this is above threshold
                  then find phase slope only in this support area.
    returns centroid of a, as offset from array center, in pythonese as calculated by DFT's and so on..

    Original domain a, Fourier domain cv
    sft square image a to cv array, no loss or oversampling - like an fft.
    Normalize peak of abs(cv) to unity
    Create 'live area' mask from abs(cv) with slight undersizing 
        (allow for 1 pixel shifts to live data still)
        (splodges, or full image a la KP)
    Calculate phase slopes using cv.angle() phase array
    Calculate mean of phase slopes over mask
    Normalize phase slopes to reflect image centroid location in pixels
    By eye, looking at smoothness of phase slope array...
    JWST NIRISS F480 F430M F380M 0.02
    JWST NIRISS F277 0.02 - untested
    GPI - untested

    XY conventions meshed to LG_Model conventions:
    if you simulate a psf with pixel_offset = ( (0.2, 0.4), ) then blind application

        centroid = utils.find_centroid()  
        
    returns the image centroid (0.40036, 0.2000093) pixels in image space. To use this
    in LG_Model, nrm_core,... you will want to calculate the new image center using

        image_center = utils.centerpoint(s) + np.array((centroid[1], centroid[0])

    and everything holds together sensibly looking at DS9 images of a.

    [email protected] 2018.02
    """

    ft = matrixDFT.MatrixFourierTransform()
    cv = ft.perform(a, a.shape[0], a.shape[0]) 
    cvmod, cvpha = np.abs(cv), np.angle(cv)
    cvmod = cvmod/cvmod.max() # normalize to unity peak
    #import matplotlib.pyplot as plt
    #plt.imshow(a)
    #plt.show()
    #print(np.isnan(cvmod))
    #print(np.isnan(thresh))
    cvmask = np.where(cvmod >= thresh)
    cvmask_edgetrim = trim(cvmask, a.shape[0])
    htilt, vtilt = findslope(cvpha, cvmask_edgetrim, verbose)

    M = np.zeros(a.shape)
    print(">>> utils.find_centroid(): M.shape {0}, a.shape {1}".format(M.shape, a.shape))
    print(cvmask_edgetrim)
    M[cvmask_edgetrim] = 1
    print(">>> utils.find_centroid(): M.shape {0}, cvpha.shape {1}".format(M.shape, cvpha.shape))
    if 0:
        fits.PrimaryHDU(data=a).writeto("/Users/anand/gitsrc/nrm_analysis/rundir/3_test_LGmethods_data/img.fits", overwrite=True)
        fits.PrimaryHDU(data=cvmod).writeto("/Users/anand/gitsrc/nrm_analysis/rundir/3_test_LGmethods_data/cvmod.fits", overwrite=True)
        fits.PrimaryHDU(data=M*cvpha*180.0/np.pi).writeto("/Users/anand/gitsrc/nrm_analysis/rundir/3_test_LGmethods_data/cvpha.fits", overwrite=True)
        print("cv abs max = {}".format(cvmod.max()))
        print("utils.find_centroid: {0} locations of CV array in CV mask for this data".format(len(cvmask[0])))

    return htilt, vtilt
示例#5
0
def example_FT_properties(plot_line=False, **kwargs):
    sigma = 10
    narray = 101

    #define the figure object
    fig = tools.make_subplots(rows=8,
                              cols=2,
                              specs=[[{
                                  'is_3d': True
                              }, {
                                  'is_3d': True
                              }] for i in range(8)],
                              print_grid=False)
    ft = matrixDFT.MatrixFourierTransform()

    #subplot 1: real, even
    x, gaussian_array = make1DGaussian(narray, sigma, x0=10)
    gaussian_array = np.array([gaussian_array])
    ft_gaussian = ft.perform(gaussian_array, 9, (1, 81))

    x_data = np.linspace(-40, 40, 81)

    func1 = lambda x, x0, sigma: np.exp(-(x - x0)**2. / (2. * sigma**2.))
    func2 = lambda x, x0, sigma: x * np.exp(-(x - x0)**2. / (2. * sigma**2.))

    x_input = np.linspace(-50, 50, 101)

    y = func1(x_input, 0., sigma)
    #generate the complex_3dplot plot
    trace = complex_3dplot(x_input, y, to_plot=False, return_traces=True)
    #put the 3d objects into the subplot
    fig.append_trace(trace[0], 1, 1)
    fig.append_trace(trace[1], 1, 1)
    if plot_line:
        fig.append_trace(trace[2], 1, 1)

    ft_y = ft.perform(np.array([y]), 9, (1, 81))
    trace = complex_3dplot(x_data, ft_y[0], to_plot=False, return_traces=True)
    fig.append_trace(trace[0], 1, 2)
    fig.append_trace(trace[1], 1, 2)
    if plot_line:
        fig.append_trace(trace[2], 1, 2)

    y = func2(x_input, 0., sigma)
    trace = complex_3dplot(x, y, to_plot=False, return_traces=True)
    fig.append_trace(trace[0], 2, 1)
    fig.append_trace(trace[1], 2, 1)
    if plot_line:
        fig.append_trace(trace[2], 2, 1)

    ft_y = ft.perform(np.array([y]), 9, (1, 81))
    trace = complex_3dplot(x_data, ft_y[0], to_plot=False, return_traces=True)
    fig.append_trace(trace[0], 2, 2)
    fig.append_trace(trace[1], 2, 2)
    if plot_line:
        fig.append_trace(trace[2], 2, 2)

    y = func1(x_input, 0., sigma) * 1j
    trace = complex_3dplot(x_input, y, to_plot=False, return_traces=True)
    fig.append_trace(trace[0], 3, 1)
    fig.append_trace(trace[1], 3, 1)
    if plot_line:
        fig.append_trace(trace[2], 3, 1)

    ft_y = ft.perform(np.array([y]), 9, (1, 81))
    trace = complex_3dplot(x_data, ft_y[0], to_plot=False, return_traces=True)
    fig.append_trace(trace[0], 3, 2)
    fig.append_trace(trace[1], 3, 2)
    if plot_line:
        fig.append_trace(trace[2], 3, 2)

    y = func2(x_input, 0., sigma) * 1j
    trace = complex_3dplot(x, y, to_plot=False, return_traces=True)
    fig.append_trace(trace[0], 4, 1)
    fig.append_trace(trace[1], 4, 1)
    if plot_line:
        fig.append_trace(trace[2], 4, 1)

    ft_y = ft.perform(np.array([y]), 9, (1, 81))
    trace = complex_3dplot(x_data, ft_y[0], to_plot=False, return_traces=True)
    fig.append_trace(trace[0], 4, 2)
    fig.append_trace(trace[1], 4, 2)
    if plot_line:
        fig.append_trace(trace[2], 4, 2)

    y = func1(x_input, 0., sigma) * (1. + 1j)
    trace = complex_3dplot(x_input, y, to_plot=False, return_traces=True)
    fig.append_trace(trace[0], 5, 1)
    fig.append_trace(trace[1], 5, 1)
    if plot_line:
        fig.append_trace(trace[2], 5, 1)

    ft_y = ft.perform(np.array([y]), 9, (1, 81))
    trace = complex_3dplot(x_data, ft_y[0], to_plot=False, return_traces=True)
    fig.append_trace(trace[0], 5, 2)
    fig.append_trace(trace[1], 5, 2)
    if plot_line:
        fig.append_trace(trace[2], 5, 2)

    y = func2(x_input, 0., sigma) * (1. + 1j)
    trace = complex_3dplot(x, y, to_plot=False, return_traces=True)
    fig.append_trace(trace[0], 6, 1)
    fig.append_trace(trace[1], 6, 1)
    if plot_line:
        fig.append_trace(trace[2], 6, 1)

    ft_y = ft.perform(np.array([y]), 9, (1, 81))
    trace = complex_3dplot(x_data, ft_y[0], to_plot=False, return_traces=True)
    fig.append_trace(trace[0], 6, 2)
    fig.append_trace(trace[1], 6, 2)
    if plot_line:
        fig.append_trace(trace[2], 6, 2)

    y = func1(x_input, 10., sigma)
    trace = complex_3dplot(x_input, y, to_plot=False, return_traces=True)
    fig.append_trace(trace[0], 7, 1)
    fig.append_trace(trace[1], 7, 1)
    if plot_line:
        fig.append_trace(trace[2], 7, 1)

    ft_y = ft.perform(np.array([y]), 9, (1, 81))
    trace = complex_3dplot(x_data, ft_y[0], to_plot=False, return_traces=True)
    fig.append_trace(trace[0], 7, 2)
    fig.append_trace(trace[1], 7, 2)
    if plot_line:
        fig.append_trace(trace[2], 7, 2)

    y = func1(x_input, 10., sigma) * 1j
    trace = complex_3dplot(x, y, to_plot=False, return_traces=True)
    fig.append_trace(trace[0], 8, 1)
    fig.append_trace(trace[1], 8, 1)
    if plot_line:
        fig.append_trace(trace[2], 8, 1)

    ft_y = ft.perform(np.array([y]), 9, (1, 81))
    trace = complex_3dplot(x_data, ft_y[0], to_plot=False, return_traces=True)
    fig.append_trace(trace[0], 8, 2)
    fig.append_trace(trace[1], 8, 2)
    if plot_line:
        fig.append_trace(trace[2], 8, 2)

    fig['layout'].update(title='Properties of Fourier Transform',
                         height=1600,
                         width=600,
                         showlegend=False)

    if kwargs.get('filename'):
        plotly.offline.plot(fig, filename=kwargs['filename'])
    else:
        plotly.offline.iplot(fig)
示例#6
0
def example_FT_properties():
    sigma = 10
    narray = 101
    
    fig = tools.make_subplots(rows=8, cols=2,
                              specs=[[{'is_3d': True}, {'is_3d': True}] for i in range(8)])
    ft = matrixDFT.MatrixFourierTransform()
    
    x, gaussian_array = make1DGaussian(narray, sigma, x0 = 10)
    gaussian_array = np.array([gaussian_array])
    ft_gaussian = ft.perform(gaussian_array, 9, (1, 81))
    
    x_data = np.linspace(-40, 40, 81)
    
    func1 = lambda x, x0, sigma: np.exp(-(x-x0)**2./(2.*sigma**2.))
    func2 = lambda x, x0, sigma: x * np.exp(-(x-x0)**2./(2.*sigma**2.))
    
    x_input = np.linspace(-50, 50, 101)
    
    y = func1(x_input, 0., sigma)
    trace = complex_3dplot(x_input, y, plot=False, return_traces=True)
    fig.append_trace(trace[0], 1, 1)
    fig.append_trace(trace[1], 1, 1)
    
    ft_y = ft.perform(np.array([y]), 9, (1, 81))
    trace = complex_3dplot(x_data, ft_y[0], plot=False, return_traces=True)
    fig.append_trace(trace[0], 1, 2)
    fig.append_trace(trace[1], 1, 2)
    
    y = func2(x_input, 0., sigma)
    trace = complex_3dplot(x, y, plot=False, return_traces=True)
    fig.append_trace(trace[0], 2, 1)
    fig.append_trace(trace[1], 2, 1)
    
    ft_y = ft.perform(np.array([y]), 9, (1, 81))
    trace = complex_3dplot(x_data, ft_y[0], plot=False, return_traces=True)
    fig.append_trace(trace[0], 2, 2)
    fig.append_trace(trace[1], 2, 2)
    
    
    y = func1(x_input, 0., sigma) * 1j
    trace = complex_3dplot(x_input, y, plot=False, return_traces=True)
    fig.append_trace(trace[0], 3, 1)
    fig.append_trace(trace[1], 3, 1)
    
    ft_y = ft.perform(np.array([y]), 9, (1, 81))
    trace = complex_3dplot(x_data, ft_y[0], plot=False, return_traces=True)
    fig.append_trace(trace[0], 3, 2)
    fig.append_trace(trace[1], 3, 2)
    
    y = func2(x_input, 0., sigma) * 1j
    trace = complex_3dplot(x, y, plot=False, return_traces=True)
    fig.append_trace(trace[0], 4, 1)
    fig.append_trace(trace[1], 4, 1)
    
    ft_y = ft.perform(np.array([y]), 9, (1, 81))
    trace = complex_3dplot(x_data, ft_y[0], plot=False, return_traces=True)
    fig.append_trace(trace[0], 4, 2)
    fig.append_trace(trace[1], 4, 2)
    
    
    
    y = func1(x_input, 0., sigma) * (1. + 1j)
    trace = complex_3dplot(x_input, y, plot=False, return_traces=True)
    fig.append_trace(trace[0], 5, 1)
    fig.append_trace(trace[1], 5, 1)
    
    ft_y = ft.perform(np.array([y]), 9, (1, 81))
    trace = complex_3dplot(x_data, ft_y[0], plot=False, return_traces=True)
    fig.append_trace(trace[0], 5, 2)
    fig.append_trace(trace[1], 5, 2)
    
    y = func2(x_input, 0., sigma) * (1. + 1j)
    trace = complex_3dplot(x, y, plot=False, return_traces=True)
    fig.append_trace(trace[0], 6, 1)
    fig.append_trace(trace[1], 6, 1)
    
    ft_y = ft.perform(np.array([y]), 9, (1, 81))
    trace = complex_3dplot(x_data, ft_y[0], plot=False, return_traces=True)
    fig.append_trace(trace[0], 6, 2)
    fig.append_trace(trace[1], 6, 2)
    
    
    y = func1(x_input, 10., sigma)
    trace = complex_3dplot(x_input, y, plot=False, return_traces=True)
    fig.append_trace(trace[0], 7, 1)
    fig.append_trace(trace[1], 7, 1)
    
    ft_y = ft.perform(np.array([y]), 9, (1, 81))
    trace = complex_3dplot(x_data, ft_y[0], plot=False, return_traces=True)
    fig.append_trace(trace[0], 7, 2)
    fig.append_trace(trace[1], 7, 2)
    
    y = func1(x_input, 10., sigma) * 1j
    trace = complex_3dplot(x, y, plot=False, return_traces=True)
    fig.append_trace(trace[0], 8, 1)
    fig.append_trace(trace[1], 8, 1)
    
    ft_y = ft.perform(np.array([y]), 9, (1, 81))
    trace = complex_3dplot(x_data, ft_y[0], plot=False, return_traces=True)
    fig.append_trace(trace[0], 8, 2)
    fig.append_trace(trace[1], 8, 2)
    
    
    fig['layout'].update(title='Properties of Fourier Transform',
                         height=1600, width=600)
    
    plotly.offline.iplot(fig)