Exemple #1
0
def background_correct(data, raw_asic):

    prime_asic = get_factorizable_block(raw_asic)
    print "Working on block", prime_asic
    block = data.matrix_copy_block(i_row=prime_asic[0],
                                   i_column=prime_asic[1],
                                   n_rows=prime_asic[2] - prime_asic[0],
                                   n_columns=prime_asic[3] - prime_asic[1])

    complex_data = flex.polar(block.as_double(),
                              flex.double(flex.grid(block.focus())))
    from scitbx import fftpack
    fft = fftpack.complex_to_complex_2d(block.focus())
    # input data here
    fft.forward(complex_data)
    # your manipulation here
    low_pass_filter(complex_data)

    fft.backward(complex_data)
    # real data
    filtered_data = flex.real(complex_data) / (fft.n()[0] * fft.n()[1])
    corrected_data = block - filtered_data.iround()

    requested_block = data.matrix_copy_block(i_row=raw_asic[0],
                                             i_column=raw_asic[1],
                                             n_rows=raw_asic[2] - raw_asic[0],
                                             n_columns=raw_asic[3] -
                                             raw_asic[1])
    requested_block.matrix_paste_block_in_place(
        block=corrected_data,
        i_row=prime_asic[0] - raw_asic[0],
        i_column=prime_asic[1] - raw_asic[1])

    return requested_block
Exemple #2
0
def exercise_complex_to_complex_3d():
  print "complex_to_complex_3d"
  for n_complex,n_repeats in [((100,80,90),2), ((200,160,180),1)]:
    print "  dimensions:", n_complex
    print "  repeats:", n_repeats
    np = n_complex[0]*n_complex[1]*n_complex[2]
    d0 = (flex.random_double(size=np)*2-1) * flex.polar(
      1, flex.random_double(size=np)*2-1)
    d0.reshape(flex.grid(n_complex))
    #
    t0 = time.time()
    for i_trial in xrange(n_repeats):
      d = d0.deep_copy()
    overhead = time.time()-t0
    print "    overhead: %.2f seconds" % overhead
    #
    t0 = time.time()
    for i_trial in xrange(n_repeats):
      d = d0.deep_copy()
      fftw3tbx.complex_to_complex_3d_in_place(data=d, exp_sign=-1)
      fftw3tbx.complex_to_complex_3d_in_place(data=d, exp_sign=+1)
    print "    fftw:     %.2f seconds" % (time.time()-t0-overhead)
    rw = d / np
    #
    t0 = time.time()
    for i_trial in xrange(n_repeats):
      d = d0.deep_copy()
      fftpack.complex_to_complex_3d(n_complex).forward(d)
      fftpack.complex_to_complex_3d(n_complex).backward(d)
    print "    fftpack:  %.2f seconds" % (time.time()-t0-overhead)
    sys.stdout.flush()
    rp = d / np
    #
    assert flex.max(flex.abs(rw-rp)) < 1.e-6
Exemple #3
0
def background_correct(data, raw_asic):

  prime_asic = get_factorizable_block(raw_asic)
  print "Working on block",prime_asic
  block = data.matrix_copy_block(
      i_row=prime_asic[0],i_column=prime_asic[1],
      n_rows=prime_asic[2]-prime_asic[0],
      n_columns=prime_asic[3]-prime_asic[1])

  complex_data = flex.polar(block.as_double(),flex.double(flex.grid(block.focus())))
  from scitbx import fftpack
  fft = fftpack.complex_to_complex_2d(block.focus())
  # input data here
  fft.forward(complex_data)
  # your manipulation here
  low_pass_filter(complex_data)

  fft.backward(complex_data)
  # real data
  filtered_data = flex.real(complex_data)/(fft.n()[0]*fft.n()[1])
  corrected_data = block - filtered_data.iround()

  requested_block = data.matrix_copy_block(
      i_row=raw_asic[0],i_column=raw_asic[1],
      n_rows=raw_asic[2]-raw_asic[0],
      n_columns=raw_asic[3]-raw_asic[1])
  requested_block.matrix_paste_block_in_place(
      block = corrected_data,
      i_row = prime_asic[0] - raw_asic[0],
      i_column = prime_asic[1] - raw_asic[1]
      )

  return requested_block
Exemple #4
0
def exercise_complex_to_complex():
  print "complex_to_complex"
  for n in xrange(1,256+1):
    dp = (flex.random_double(size=n)*2-1) * flex.polar(
      1, flex.random_double(size=n)*2-1)
    dw = dp.deep_copy()
    fft = fftpack.complex_to_complex(n)
    fftw3tbx.complex_to_complex_in_place(data=dw, exp_sign=-1)
    fft.forward(dp)
    assert flex.max(flex.abs(dw-dp)) < 1.e-6
    fftw3tbx.complex_to_complex_in_place(data=dw, exp_sign=+1)
    fft.backward(dp)
    assert flex.max(flex.abs(dw-dp)) < 1.e-6
  for n,n_repeats in [(1200,500), (9600,250)]:
    print "  factors of %d:" % n, list(fftpack.complex_to_complex(n).factors())
    print "  repeats:", n_repeats
    d0 = (flex.random_double(size=n)*2-1) * flex.polar(
      1, flex.random_double(size=n)*2-1)
    #
    t0 = time.time()
    for i_trial in xrange(n_repeats):
      d = d0.deep_copy()
    overhead = time.time()-t0
    print "    overhead: %.2f seconds" % overhead
    #
    t0 = time.time()
    for i_trial in xrange(n_repeats):
      d = d0.deep_copy()
      fftw3tbx.complex_to_complex_in_place(data=d, exp_sign=-1)
      fftw3tbx.complex_to_complex_in_place(data=d, exp_sign=+1)
    print "    fftw:     %.2f seconds" % (time.time()-t0-overhead)
    #
    t0 = time.time()
    for i_trial in xrange(n_repeats):
      d = d0.deep_copy()
      fftpack.complex_to_complex(n).forward(d)
      fftpack.complex_to_complex(n).backward(d)
    print "    fftpack:  %.2f seconds" % (time.time()-t0-overhead)
    sys.stdout.flush()
Exemple #5
0
def exercise_complex_to_complex_3d():
    from scitbx.array_family import flex
    from cudatbx import cufft
    from scitbx import fftpack
    import time
    import sys
    print ""
    print "complex_to_complex_3d"
    for n_complex, n_repeats in [((100, 80, 90), 16), ((200, 160, 180), 16)]:
        print "  dimensions:", n_complex
        print "  repeats:", n_repeats
        np = n_complex[0] * n_complex[1] * n_complex[2]
        d0 = flex.polar(
            flex.random_double(size=np) * 2 - 1,
            flex.random_double(size=np) * 2 - 1)
        d0.reshape(flex.grid(n_complex))
        #
        t0 = time.time()
        for i_trial in xrange(n_repeats):
            d = d0.deep_copy()
        overhead = time.time() - t0
        print "    overhead: %.2f seconds" % overhead
        #
        # XXX extra CuFFT to initialize device - can we avoid this somehow?
        d = d0.deep_copy()
        cufft.complex_to_complex_3d(n_complex).forward(d)
        cufft.complex_to_complex_3d(n_complex).backward(d)
        # benchmarking run
        t0 = time.time()
        for i_trial in xrange(n_repeats):
            d = d0.deep_copy()
            cufft.complex_to_complex_3d(n_complex).forward(d)
            cufft.complex_to_complex_3d(n_complex).backward(d)
        print "    cufft:    %6.2f seconds" % (
            (time.time() - t0 - overhead) / n_repeats)
        rw = d / np
        #
        t0 = time.time()
        for i_trial in xrange(n_repeats):
            d = d0.deep_copy()
            fftpack.complex_to_complex_3d(n_complex).forward(d)
            fftpack.complex_to_complex_3d(n_complex).backward(d)
        print "    fftpack:  %6.2f seconds" % (
            (time.time() - t0 - overhead) / n_repeats)
        sys.stdout.flush()
        rp = d / np
        #
        print ""
        assert flex.max(flex.abs(rw - rp)) < 1.e-6
Exemple #6
0
def exercise_complex_to_complex_3d () :
  from scitbx.array_family import flex
  from cudatbx import cufft
  from scitbx import fftpack
  import time
  import sys
  print ""
  print "complex_to_complex_3d"
  for n_complex,n_repeats in [((100,80,90),16), ((200,160,180),16)]:
    print "  dimensions:", n_complex
    print "  repeats:", n_repeats
    np = n_complex[0]*n_complex[1]*n_complex[2]
    d0 = flex.polar(
      flex.random_double(size=np)*2-1,
      flex.random_double(size=np)*2-1)
    d0.reshape(flex.grid(n_complex))
    #
    t0 = time.time()
    for i_trial in xrange(n_repeats):
      d = d0.deep_copy()
    overhead = time.time()-t0
    print "    overhead: %.2f seconds" % overhead
    #
    # XXX extra CuFFT to initialize device - can we avoid this somehow?
    d = d0.deep_copy()
    cufft.complex_to_complex_3d(n_complex).forward(d)
    cufft.complex_to_complex_3d(n_complex).backward(d)
    # benchmarking run
    t0 = time.time()
    for i_trial in xrange(n_repeats):
      d = d0.deep_copy()
      cufft.complex_to_complex_3d(n_complex).forward(d)
      cufft.complex_to_complex_3d(n_complex).backward(d)
    print "    cufft:    %6.2f seconds" % ((time.time()-t0-overhead)/n_repeats)
    rw = d / np
    #
    t0 = time.time()
    for i_trial in xrange(n_repeats):
      d = d0.deep_copy()
      fftpack.complex_to_complex_3d(n_complex).forward(d)
      fftpack.complex_to_complex_3d(n_complex).backward(d)
    print "    fftpack:  %6.2f seconds" % ((time.time()-t0-overhead)/n_repeats)
    sys.stdout.flush()
    rp = d / np
    #
    print ""
    assert flex.max(flex.abs(rw-rp)) < 1.e-6
Exemple #7
0
def background_correct_padded_block(data, raw_asic):

  Pad = padded_unpadded(data,raw_asic)

  block = Pad.get_padded_input_data()

  complex_data = flex.polar(block.as_double(),flex.double(flex.grid(block.focus())))
  from scitbx import fftpack
  fft = fftpack.complex_to_complex_2d(block.focus())
  # input data here
  fft.forward(complex_data)
  # your manipulation here
  low_pass_filter(complex_data)

  fft.backward(complex_data)
  # real data
  filtered_data = flex.real(complex_data)/(fft.n()[0]*fft.n()[1])
  # XXX change this depending on float/int data type:
  corrected_data = block - filtered_data.iround()

  return Pad.get_unpadded_result_data(corrected_data)
Exemple #8
0
def background_correct_padded_block(data, raw_asic):

  Pad = padded_unpadded(data,raw_asic)

  block = Pad.get_padded_input_data()

  complex_data = flex.polar(block.as_double(),flex.double(flex.grid(block.focus())))
  from scitbx import fftpack
  fft = fftpack.complex_to_complex_2d(block.focus())
  # input data here
  fft.forward(complex_data)
  # your manipulation here
  low_pass_filter(complex_data)

  fft.backward(complex_data)
  # real data
  filtered_data = flex.real(complex_data)/(fft.n()[0]*fft.n()[1])
  # XXX change this depending on float/int data type:
  corrected_data = block - filtered_data.iround()

  return Pad.get_unpadded_result_data(corrected_data)