コード例 #1
0
def test_load_no_physical_sizes(comm_self):
    nb_grid_pts = (128, 128)
    size = (3, 3)

    np.random.seed(1)
    t = fourier_synthesis(nb_grid_pts, size, 0.8, rms_slope=0.1)

    # Topographies always have physical size information, we need to create a
    # NetCDF file without any manually
    with Dataset('no_physical_sizes.nc', 'w', format='NETCDF3_CLASSIC') as nc:
        nc.createDimension('x', nb_grid_pts[0])
        nc.createDimension('y', nb_grid_pts[1])
        nc.createVariable('heights', 'f8', ('x', 'y'))
        nc.variables['heights'] = t.heights()

    # Attempt to open full file on each process
    # with pytest.raises(ValueError):
    #    # This raises an error because the physical sizes are not present
    #    t2 = read_topography('no_physical_sizes.nc')
    t2 = read_topography('no_physical_sizes.nc', physical_sizes=size)

    assert t.physical_sizes == t2.physical_sizes
    assert 'unit' not in t2.info
    np.testing.assert_array_almost_equal(t.heights(), t2.heights())

    os.remove('no_physical_sizes.nc')
コード例 #2
0
def reentrant_line_scan():
    """Return an reentrant line scan."""
    data = """
    0 1
    1 1
    2 1
    2 2
    3 2
    4 2
    """
    in_mem_file = io.StringIO(data)
    return read_topography(in_mem_file)
コード例 #3
0
def test_save_and_load(comm):
    nb_grid_pts = (128, 128)
    size = (3, 3)

    np.random.seed(1)
    t = fourier_synthesis(nb_grid_pts, size, 0.8, rms_slope=0.1, unit='µm')

    fft = FFT(nb_grid_pts, communicator=comm, fft="mpi")
    fft.create_plan(1)
    dt = t.domain_decompose(fft.subdomain_locations,
                            fft.nb_subdomain_grid_pts,
                            communicator=comm)
    assert t.unit == 'µm'
    assert dt.unit == 'µm'
    assert t.info['unit'] == 'µm'
    assert dt.info['unit'] == 'µm'
    if comm.size > 1:
        assert dt.is_domain_decomposed

    # Save file
    dt.to_netcdf('parallel_save_test.nc')

    # Attempt to open full file on each MPI process
    t2 = read_topography('parallel_save_test.nc')

    assert t.physical_sizes == t2.physical_sizes
    assert t.unit == t2.unit
    assert t.info['unit'] == t2.info['unit']
    np.testing.assert_array_almost_equal(t.heights(), t2.heights())

    # Attempt to open file in parallel
    r = NCReader('parallel_save_test.nc', communicator=comm)

    assert r.channels[0].nb_grid_pts == nb_grid_pts

    t3 = r.topography(subdomain_locations=fft.subdomain_locations,
                      nb_subdomain_grid_pts=fft.nb_subdomain_grid_pts)

    assert t.physical_sizes == t3.physical_sizes
    assert t.unit == t3.unit
    assert t.info['unit'] == t3.info['unit']
    np.testing.assert_array_almost_equal(dt.heights(), t3.heights())

    assert t3.is_periodic

    comm.barrier()
    if comm.rank == 0:
        os.remove('parallel_save_test.nc')
コード例 #4
0
def test_save_and_load_no_unit(comm_self):
    nb_grid_pts = (128, 128)
    size = (3, 3)

    np.random.seed(1)
    t = fourier_synthesis(nb_grid_pts, size, 0.8, rms_slope=0.1)

    # Save file
    t.to_netcdf('no_unit.nc')

    t2 = read_topography('no_unit.nc')

    assert t.physical_sizes == t2.physical_sizes
    assert 'unit' not in t2.info
    np.testing.assert_array_almost_equal(t.heights(), t2.heights())

    os.remove('no_unit.nc')
コード例 #5
0
def test_save_and_load_line_scan(comm_self):
    nb_grid_pts = (128, )
    size = (3, )

    np.random.seed(1)
    t = fourier_synthesis(nb_grid_pts, size, 0.8, rms_slope=0.1)
    t.info['unit'] = 'µm'

    with tempfile.TemporaryDirectory() as d:
        tmpfn = f'{d}/line_scan.nc'

        # Save file
        t.to_netcdf(tmpfn)

        # Read file
        t2 = read_topography(tmpfn)

        assert t == t2
コード例 #6
0
parser = ArgumentParser(description='Plot a 2D surface map (pressure, gap, '
                        'etc.).')
parser.add_argument('filename', metavar='FILENAME', help='name of map file')
parser.add_argument('--logscale',
                    help='log scaling',
                    action='store_true',
                    default=False)
parser.add_argument('--fftshift',
                    help='fft shift',
                    action='store_true',
                    default=False)
arguments = parser.parse_args()

###

surface = read_topography(arguments.filename)

###

try:
    sx, sy = surface.physical_sizes
except TypeError:
    sx, sy = surface.nb_grid_pts
nx, ny = surface.nb_grid_pts

fig = plt.figure()
ax = fig.add_subplot(111, aspect=sx / sy)
Y, X = np.meshgrid((np.arange(ny) + 0.5) * sy / ny,
                   (np.arange(nx) + 0.5) * sx / nx)
Z = surface[...]
if arguments.fftshift: