Exemplo n.º 1
0
def homework_3_problem_1():
    # Generate X matrix with border
    dim = 256
    A = M.identity(dim)
    A = A + M.fliplr(A)
    A[0, :] = 1
    A[-1, :] = 1
    A[:, 0] = 1
    A[:, -1] = 1
    A[dim / 2, dim / 2] = 1
    A = A * 255

    fig = plt.gcf()
    fig.suptitle("Problem 1: Haar Transform")

    # Display original matrix
    plt.subplot(321)
    plt.title('original')
    plt.imshow(A, cm.Greys_r)

    plt.subplot(322)
    plt.title('forward')
    wavelet.forward(h, A, recursive=False)
    plt.imshow(A, cm.Greys_r)

    plt.subplot(323)
    plt.title('top left')
    plt.imshow(A[:dim / 2, :dim / 2], cm.Greys_r)

    plt.subplot(324)
    plt.title('top right')
    plt.imshow(A[:dim / 2, dim / 2:], cm.Greys_r)

    plt.subplot(325)
    plt.title('bottom left')
    plt.imshow(A[dim / 2:, :dim / 2], cm.Greys_r)

    plt.subplot(326)
    plt.title('bottom right')
    plt.imshow(A[dim / 2:, dim / 2:], cm.Greys_r)

    plt.show()
Exemplo n.º 2
0
def are_winning_diags(boardstate, side):
    return (boardstate.diagonal() == side).all() or \
           (nm.fliplr(boardstate).diagonal() == side).all()
Exemplo n.º 3
0
def are_winning_diags(boardstate, side):
    return (boardstate.diagonal() == side).all() or \
           (nm.fliplr(boardstate).diagonal() == side).all()
Exemplo n.º 4
0
    def generate_correlated_noise_fft(nx, ny, std_long, sp):
        """ A function to create synthetic turbulent troposphere delay using an FFT approach. 
        The power of the turbulence is tuned by the weather model at the longer wavelengths.
        
        Inputs:
            nx (int) -- width of troposphere 
            Ny (int) -- length of troposphere 
            std_long (float) -- standard deviation of the weather model at the longer wavelengths. Default = ?
            sp | int | pixel spacing in km
            
        Outputs:
            APS (float): 2D array, Ny * nx, units are m.
            
        History:
            2020_??_?? | LS | Adapted from code by Andy Hooper.  
            2021_03_01 | MEG | Small change to docs and inputs to work with SyInterferoPy
        """

        import numpy as np
        import numpy.matlib as npm
        import math

        np.seterr(divide='ignore')

        cut_off_freq = 1 / 50  # drop wavelengths above 50 km

        x = np.arange(0, int(nx / 2))  # positive frequencies only
        y = np.arange(0, int(ny / 2))  # positive frequencies only
        freq_x = np.divide(x, nx * sp)
        freq_y = np.divide(y, ny * sp)
        Y, X = npm.meshgrid(freq_x, freq_y)
        freq = np.sqrt((X * X + Y * Y) / 2)  # 2D positive frequencies

        log_power = np.log10(freq) * -11 / 3  # -11/3 in 2D gives -8/3 in 1D
        ix = np.where(freq < 2 / 3)
        log_power[ix] = np.log10(freq[ix]) * -8 / 3 - math.log10(
            2 / 3)  # change slope at 1.5 km (2/3 cycles per km)

        bin_power = np.power(10, log_power)
        ix = np.where(freq < cut_off_freq)
        bin_power[ix] = 0

        APS_power = np.zeros(
            (ny, nx))  # mirror positive frequencies into other quadrants
        APS_power[0:int(ny / 2), 0:int(nx / 2)] = bin_power
        # APS_power[0:int(ny/2), int(nx/2):nx]=npm.fliplr(bin_power)
        # APS_power[int(ny/2):ny, 0:int(nx/2)]=npm.flipud(bin_power)
        # APS_power[int(ny/2):ny, int(nx/2):nx]=npm.fliplr(npm.flipud(bin_power))
        APS_power[0:int(ny / 2), int(np.ceil(nx / 2)):] = npm.fliplr(bin_power)
        APS_power[int(np.ceil(ny / 2)):, 0:int(nx / 2)] = npm.flipud(bin_power)
        APS_power[int(np.ceil(ny / 2)):,
                  int(np.ceil(nx / 2)):] = npm.fliplr(npm.flipud(bin_power))
        APS_filt = np.sqrt(APS_power)

        x = np.random.randn(ny, nx)  # white noise
        y_tmp = np.fft.fft2(x)
        y_tmp2 = np.multiply(y_tmp, APS_filt)  # convolve with filter
        y = np.fft.ifft2(y_tmp2)
        APS = np.real(y)

        APS = APS / np.std(
            APS
        ) * std_long  #  adjust the turbulence by the weather model at the longer wavelengths.
        APS = APS * 0.01  # convert from cm to m
        return APS