def PsdArray2Noise_1d_v2(f_in, Psd_in, L_mm, N):
    '\n\t\tReturns meters\n\t'
    from scipy import interpolate
    log = np.log
    fft = np.fft.fft
    fftshift = np.fft.fftshift
    ff = f_in
    yy = Psd_in
    L = L_mm
    N = int(N)
    N2 = int((N // 2))
    L = 300
    L_um = (L * 1000.0)
    L_nm = (L * 1000000.0)
    fMin = (1 / L_um)
    fSpline = (((np.arange(N2) / N2) * (max(ff) - min(ff))) + min(ff))
    fun = interpolate.splrep(log(ff), log(yy), s=2)
    yPsd_log = interpolate.splev(log(fSpline), fun)
    ySpline = np.exp(yPsd_log)
    yPsd = ySpline
    yPsd[(fSpline < ff[0])] = 200
    n = len(yPsd)
    plt.plot(fSpline, yPsd, '-')
    plt.plot(ff, yy, 'x')
    plt.legend(['ySpline', 'Data'])
    ax = plt.axes()
    import scipy.integrate as integrate
    RMS = np.sqrt(integrate.trapz(yPsd, (fSpline / 1000)))
    yPsd_reverse = yPsd[::(- 1)]
    ell = (1 / (fSpline[1] - fSpline[0]))
    if ((N % 2) == 0):
        yPsd2 = np.hstack((yPsd_reverse, 0, yPsd[0:(- 1)]))
    else:
        yPsd2 = np.hstack((yPsd_reverse, 0, yPsd))
    yPsd2Norm = np.sqrt(((yPsd2 / ell) / 1000))
    n_ = len(yPsd2)
    print(('len(yPsd2) = %0.2d' % len(yPsd2Norm)))
    phi = ((2 * np.pi) * np.random.rand(n_))
    r = np.exp((1j * phi))
    yPsd2Norm_ = fftshift(yPsd2Norm)
    yRaf = np.fft.fft((r * yPsd2Norm_))
    yRaf = np.real(yRaf)
    print(('Rms = %0.2e nm' % np.std(yRaf)))
    plt.plot(yPsd2Norm_)
    print(('max yPsd_ = %d nm' % max(yPsd2)))
    print(('max yPsd2Norm = %0.4f nm' % max(yPsd2Norm)))
    print(('Rms yRaf2 = %0.2e nm' % np.std(yRaf)))
    return (yRaf * 1e-09)
Returns meters
def PsdArray2Noise_1d_v2(f_in, Psd_in, L_mm, N):
    '\n\t\t\n\t'
    from scipy import interpolate
    log = np.log
    fft = np.fft.fft
    fftshift = np.fft.fftshift
    ff = f_in
    yy = Psd_in
    L = L_mm
    N = int(N)
    N2 = int((N // 2))
    L = 300
    L_um = (L * 1000.0)
    L_nm = (L * 1000000.0)
    fMin = (1 / L_um)
    fSpline = (((np.arange(N2) / N2) * (max(ff) - min(ff))) + min(ff))
    fun = interpolate.splrep(log(ff), log(yy), s=2)
    yPsd_log = interpolate.splev(log(fSpline), fun)
    ySpline = np.exp(yPsd_log)
    yPsd = ySpline
    yPsd[(fSpline < ff[0])] = 200
    n = len(yPsd)
    plt.plot(fSpline, yPsd, '-')
    plt.plot(ff, yy, 'x')
    plt.legend(['ySpline', 'Data'])
    ax = plt.axes()
    import scipy.integrate as integrate
    RMS = np.sqrt(integrate.trapz(yPsd, (fSpline / 1000)))
    yPsd_reverse = yPsd[::(- 1)]
    ell = (1 / (fSpline[1] - fSpline[0]))
    if ((N % 2) == 0):
        yPsd2 = np.hstack((yPsd_reverse, 0, yPsd[0:(- 1)]))
    else:
        yPsd2 = np.hstack((yPsd_reverse, 0, yPsd))
    yPsd2Norm = np.sqrt(((yPsd2 / ell) / 1000))
    n_ = len(yPsd2)
    print(('len(yPsd2) = %0.2d' % len(yPsd2Norm)))
    phi = ((2 * np.pi) * np.random.rand(n_))
    r = np.exp((1j * phi))
    yPsd2Norm_ = fftshift(yPsd2Norm)
    yRaf = np.fft.fft((r * yPsd2Norm_))
    yRaf = np.real(yRaf)
    print(('Rms = %0.2e nm' % np.std(yRaf)))
    plt.plot(yPsd2Norm_)
    print(('max yPsd_ = %d nm' % max(yPsd2)))
    print(('max yPsd2Norm = %0.4f nm' % max(yPsd2Norm)))
    print(('Rms yRaf2 = %0.2e nm' % np.std(yRaf)))
    return (yRaf * 1e-09)