def test_4x3_shape_mismatch():
    asc_file = StringIO(
        """
nrows         4
ncols         3
xllcorner     1.
yllcorner     2.
cellsize      10.
NODATA_value  -9999
1. 2. 3. 4.
5. 6. 7. 8.
9. 10. 11. 12.
        """)
    (grid, field) = read_esri_ascii(asc_file)
    assert_equal(field.size, 12)

    asc_file = StringIO(
        """
nrows         4
ncols         3
xllcorner     1.
yllcorner     2.
cellsize      10.
NODATA_value  -9999
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12.
        """)
    (grid, field) = read_esri_ascii(asc_file)
    assert_equal(field.size, 12)
示例#2
0
def test_4x3_shape_mismatch():
    asc_file = StringIO("""
nrows         4
ncols         3
xllcorner     1.
yllcorner     2.
cellsize      10.
NODATA_value  -9999
1. 2. 3. 4.
5. 6. 7. 8.
9. 10. 11. 12.
        """)
    (grid, field) = read_esri_ascii(asc_file)
    assert_equal(field.size, 12)

    asc_file = StringIO("""
nrows         4
ncols         3
xllcorner     1.
yllcorner     2.
cellsize      10.
NODATA_value  -9999
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12.
        """)
    (grid, field) = read_esri_ascii(asc_file)
    assert_equal(field.size, 12)
    def setup_rock_and_till(self, file_name, rock_erody, till_erody,
                            rock_thresh, till_thresh, contact_width):
        """Set up lithology handling for two layers with different erodibility.

        Parameters
        ----------
        file_name : string
            Name of arc-ascii format file containing elevation of contact
            position at each grid node (or NODATA)
        rock_erody : float
            Water erosion coefficient for bedrock
        till_erody : float
            Water erosion coefficient for till
        rock_thresh : float
            Water erosion threshold for bedrock
        till_thresh : float
            Water erosion threshold for till
        contact_width : float [L]
            Characteristic width of the interface zone between rock and till

        Read elevation of rock-till contact from an esri-ascii format file
        containing the basal elevation value at each node, create a field for
        erodibility.
        """
        from landlab.io import read_esri_ascii

        # Read input data on rock-till contact elevation
        read_esri_ascii(file_name, grid=self.grid,
                        name='rock_till_contact__elevation',
                        halo=1)

        # Get a reference to the rock-till field
        self.rock_till_contact = self.grid.at_node['rock_till_contact__elevation']

        # Create field for erodibility
        if 'substrate__erodibility' in self.grid.at_node:
            self.erody = self.grid.at_node['substrate__erodibility']
        else:
            self.erody = self.grid.add_zeros('node', 'substrate__erodibility')

        # Create field for threshold values
        if 'erosion__threshold' in self.grid.at_node:
            self.threshold = self.grid.at_node['erosion__threshold']
        else:
            self.threshold = self.grid.add_zeros('node', 'erosion__threshold')

        # Create array for erodibility weighting function
        self.erody_wt = np.zeros(self.grid.number_of_nodes)

        # Read the erodibility value of rock and till
        self.rock_erody = rock_erody
        self.till_erody = till_erody

        # Read the threshold values for rock and till
        self.rock_thresh = rock_thresh
        self.till_thresh = till_thresh

        # Read and remember the contact zone characteristic width
        self.contact_width = contact_width
示例#4
0
def test_names_keyword_as_str(tmpdir):
    grid = RasterModelGrid(4, 5, 2.)
    grid.add_field('air__temperature', np.arange(20.), at='node')
    grid.add_field('land_surface__elevation', np.arange(20.), at='node')

    with tmpdir.as_cwd():
        grid.save('test.asc', names='land_surface__elevation')
        assert os.path.isfile('test.asc')
        read_esri_ascii('test.asc')
示例#5
0
def test_names_keyword_as_str(tmpdir):
    grid = RasterModelGrid((4, 5), xy_spacing=2.0)
    grid.add_field("air__temperature", np.arange(20.0), at="node")
    grid.add_field("land_surface__elevation", np.arange(20.0), at="node")

    with tmpdir.as_cwd():
        grid.save("test.asc", names="land_surface__elevation")
        assert os.path.isfile("test.asc")
        read_esri_ascii("test.asc")
示例#6
0
def test_names_keyword_as_str(tmpdir):
    grid = RasterModelGrid(4, 5, 2.)
    grid.add_field('air__temperature', np.arange(20.), at='node')
    grid.add_field('land_surface__elevation', np.arange(20.), at='node')

    with tmpdir.as_cwd():
        grid.save('test.asc', names='land_surface__elevation')
        assert os.path.isfile('test.asc')
        read_esri_ascii('test.asc')
示例#7
0
def test_names_keyword_as_str(tmpdir):
    grid = RasterModelGrid(4, 5, 2.)
    grid.add_field("air__temperature", np.arange(20.), at="node")
    grid.add_field("land_surface__elevation", np.arange(20.), at="node")

    with tmpdir.as_cwd():
        grid.save("test.asc", names="land_surface__elevation")
        assert os.path.isfile("test.asc")
        read_esri_ascii("test.asc")
示例#8
0
def test_names_keyword_as_list(tmpdir):
    grid = RasterModelGrid(4, 5, 2.)
    grid.add_field("air__temperature", np.arange(20.), at="node")
    grid.add_field("land_surface__elevation", np.arange(20.), at="node")

    with tmpdir.as_cwd():
        grid.save("test.asc", names=["land_surface__elevation", "air__temperature"])
        files = ["test_land_surface__elevation.asc", "test_air__temperature.asc"]
        for fname in files:
            assert os.path.isfile(fname)
            read_esri_ascii(fname)
示例#9
0
def test_names_keyword_as_list(tmpdir):
    grid = RasterModelGrid((4, 5), xy_spacing=2.0)
    grid.add_field("air__temperature", np.arange(20.0), at="node")
    grid.add_field("land_surface__elevation", np.arange(20.0), at="node")

    with tmpdir.as_cwd():
        grid.save("test.asc", names=["land_surface__elevation", "air__temperature"])
        files = ["test_land_surface__elevation.asc", "test_air__temperature.asc"]
        for fname in files:
            assert os.path.isfile(fname)
            read_esri_ascii(fname)
    def setup_rock_and_till(self, file_name, rock_erody, till_erody,
                            contact_width):
        """Set up lithology handling for two layers with different erodibility.

        Parameters
        ----------
        file_name : string
            Name of arc-ascii format file containing elevation of contact
            position at each grid node (or NODATA)

        Read elevation of rock-till contact from an esri-ascii format file
        containing the basal elevation value at each node, create a field for
        erodibility.

        Some considerations here:
            1. We could represent the contact between two layers either as a
               depth below present land surface, or as an altitude. Using a
               depth would allow for vertical motion, because for a fixed
               surface, the depth remains constant while the altitude changes.
               But the depth must be updated every time the surface is eroded
               or aggrades. Using an altitude avoids having to update the
               contact position every time the surface erodes or aggrades, but
               any tectonic motion would need to be applied to the contact
               position as well. Here we'll use the altitude approach because
               this model was originally written for an application with lots
               of erosion expected but no tectonics.
        """
        from landlab.io import read_esri_ascii

        # Read input data on rock-till contact elevation
        read_esri_ascii(file_name,
                        grid=self.grid,
                        name='rock_till_contact__elevation',
                        halo=1)

        # Get a reference to the rock-till field
        self.rock_till_contact = self.grid.at_node[
            'rock_till_contact__elevation']

        # Create field for erodibility
        if 'substrate__erodibility' in self.grid.at_node:
            self.erody = self.grid.at_node['substrate__erodibility']
        else:
            self.erody = self.grid.add_zeros('node', 'substrate__erodibility')

        # Create array for erodibility weighting function
        self.erody_wt = np.zeros(self.grid.number_of_nodes)

        # Read the erodibility value of rock and till
        self.rock_erody = rock_erody
        self.till_erody = till_erody

        # Read and remember the contact zone characteristic width
        self.contact_width = contact_width
示例#11
0
def test_4x3_size_mismatch():
    asc_file = StringIO("""
nrows         4
ncols         3
xllcorner     1.
yllcorner     2.
cellsize      10.
NODATA_value  -9999
1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
        """)
    with pytest.raises(DataSizeError):
        read_esri_ascii(asc_file)
示例#12
0
def test_grid_data_size_mismatch():
    asc_file = StringIO("""
nrows         4
ncols         3
xllcorner     1.
yllcorner     2.
cellsize      10.
NODATA_value  -9999
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12.
        """)
    rmg = RasterModelGrid((10, 10), 10.)
    with pytest.raises(MismatchGridDataSizeError):
        read_esri_ascii(asc_file, grid=rmg)
示例#13
0
def test_guess_format(tmpdir):
    grid = RasterModelGrid((4, 5), xy_spacing=2.0)
    grid.add_field("node", "air__temperature", np.arange(20.0))

    with tmpdir.as_cwd():
        grid.save("test.asc")
        assert os.path.isfile("test.asc")
        read_esri_ascii("test.asc")

    with tmpdir.as_cwd():
        grid.save("test.nc")
        assert os.path.isfile("test.nc")
        read_netcdf("test.nc")
示例#14
0
def test_grid_lower_left_mismatch():
    asc_file = StringIO("""
nrows         4
ncols         3
xllcorner     1.
yllcorner     2.
cellsize      10.
NODATA_value  -9999
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12.
        """)
    rmg = RasterModelGrid((4, 3), xy_spacing=10., xy_of_lower_left=(10, 15))
    with pytest.raises(MismatchGridXYLowerLeft):
        read_esri_ascii(asc_file, grid=rmg)
def test_4x3_size_mismatch():
    asc_file = StringIO(
        """
nrows         4
ncols         3
xllcorner     1.
yllcorner     2.
cellsize      10.
NODATA_value  -9999
1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
        """)
    with pytest.raises(DataSizeError):
        read_esri_ascii(asc_file)
示例#16
0
def test_guess_format(tmpdir):
    grid = RasterModelGrid(4, 5, 2.)
    grid.add_field('node', 'air__temperature', np.arange(20.))

    with tmpdir.as_cwd():
        grid.save('test.asc')
        assert os.path.isfile('test.asc')
        read_esri_ascii('test.asc')

    with tmpdir.as_cwd():
        grid.save('test.nc')
        assert os.path.isfile('test.nc')
        read_netcdf('test.nc')
示例#17
0
def test_names_keyword_as_list(tmpdir):
    grid = RasterModelGrid(4, 5, 2.)
    grid.add_field('air__temperature', np.arange(20.), at='node')
    grid.add_field('land_surface__elevation', np.arange(20.), at='node')

    with tmpdir.as_cwd():
        grid.save('test.asc', names=['land_surface__elevation',
                                     'air__temperature'])
        files = ['test_land_surface__elevation.asc',
                 'test_air__temperature.asc']
        for fname in files:
            assert os.path.isfile(fname)
            read_esri_ascii(fname)
示例#18
0
def test_guess_format(tmpdir):
    grid = RasterModelGrid(4, 5, 2.)
    grid.add_field("node", "air__temperature", np.arange(20.))

    with tmpdir.as_cwd():
        grid.save("test.asc")
        assert os.path.isfile("test.asc")
        read_esri_ascii("test.asc")

    with tmpdir.as_cwd():
        grid.save("test.nc")
        assert os.path.isfile("test.nc")
        read_netcdf("test.nc")
示例#19
0
def test_guess_format():
    grid = RasterModelGrid(4, 5, 2.)
    grid.add_field('node', 'air__temperature', np.arange(20.))

    with cdtemp() as _:
        grid.save('test.asc')
        assert_true(os.path.isfile('test.asc'))
        read_esri_ascii('test.asc')

    with cdtemp() as _:
        grid.save('test.nc')
        assert_true(os.path.isfile('test.nc'))
        read_netcdf('test.nc')
示例#20
0
def test_names_keyword_as_list(tmpdir):
    grid = RasterModelGrid(4, 5, 2.)
    grid.add_field('air__temperature', np.arange(20.), at='node')
    grid.add_field('land_surface__elevation', np.arange(20.), at='node')

    with tmpdir.as_cwd():
        grid.save('test.asc',
                  names=['land_surface__elevation', 'air__temperature'])
        files = [
            'test_land_surface__elevation.asc', 'test_air__temperature.asc'
        ]
        for fname in files:
            assert os.path.isfile(fname)
            read_esri_ascii(fname)
def test_grid_data_size_mismatch():
    asc_file = StringIO(
        """
nrows         4
ncols         3
xllcorner     1.
yllcorner     2.
cellsize      10.
NODATA_value  -9999
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12.
        """)
    rmg = RasterModelGrid((10,10),10.)
    with pytest.raises(MismatchGridDataSizeError):
        read_esri_ascii(asc_file, grid=rmg)    
示例#22
0
def test_grid_lower_left_mismatch():
    asc_file = StringIO(
        """
nrows         4
ncols         3
xllcorner     1.
yllcorner     2.
cellsize      10.
NODATA_value  -9999
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12.
        """
    )
    rmg = RasterModelGrid((4, 3), xy_spacing=10.0, xy_of_lower_left=(10, 15))
    with pytest.raises(MismatchGridXYLowerLeft):
        read_esri_ascii(asc_file, grid=rmg)
示例#23
0
    def test_reshape(self):
        with open(os.path.join(_TEST_DATA_DIR, "hugo_site.asc")) as asc_file:
            (grid, field) = read_esri_ascii(asc_file, reshape=True)

        self.assertIsInstance(grid, RasterModelGrid)

        self.assertTrue(field.shape, (55, 76))
示例#24
0
def test_hugo_reshape(datadir):
    with open(datadir / "hugo_site.asc") as asc_file:
        (grid, field) = read_esri_ascii(asc_file, reshape=True)

    assert isinstance(grid, RasterModelGrid)

    assert field.shape == (55, 76)
示例#25
0
def test_hugo_reshape():
    with open(os.path.join(_TEST_DATA_DIR, 'hugo_site.asc')) as asc_file:
        (grid, field) = read_esri_ascii(asc_file, reshape=True)

    assert_is_instance(grid, RasterModelGrid)

    assert_true(field.shape, (55, 76))
示例#26
0
    def test_read_file_name(self):
        (grid, field) = read_esri_ascii(os.path.join(_TEST_DATA_DIR, "hugo_site.asc"))

        self.assertIsInstance(grid, RasterModelGrid)

        self.assertEqual(field.size, 55 * 76)
        self.assertEqual(field.shape, (55 * 76,))
示例#27
0
    def initialize(self, param_filename):

        # Read parameters from input file
        params = load_params(param_filename)
        self.elastic_thickness = params['elastic_thickness']
        self.youngs_modulus = params['youngs_modulus']
        self.rho_m = params['mantle_density']
        self.grav_accel = params['gravitational_acceleration']
        self.water_surf_elev = params['water_surface_elevation']
        self.water_density = params['lake_water_density']
        self.tolerance = params['lake_elev_tolerance']

        # Read DEM
        print('Reading DEM file...')
        (self.grid, self.dem) = read_esri_ascii(params['dem_filename'])
        print('done.')

        # Store a copy that we'll modify
        self.flexed_dem = self.dem.copy()

        # Create and initialize Flexure component
        self.flexer = Flexure(self.grid,
                              eet=self.elastic_thickness,
                              youngs=self.youngs_modulus,
                              method="flexure",
                              rho_mantle=self.rho_m,
                              gravity=self.grav_accel)
        self.load = self.grid.at_node[
            'lithosphere__overlying_pressure_increment']
        self.deflection = self.grid.at_node[
            'lithosphere_surface__elevation_increment']

        self.initialized = True
示例#28
0
def test_4x3_read_file_like():
    with open(os.path.join(_TEST_DATA_DIR, "4_x_3.asc")) as asc_file:
        (grid, field) = read_esri_ascii(asc_file)

    assert_is_instance(grid, RasterModelGrid)

    assert_array_equal(field, np.array([9.0, 10.0, 11.0, 6.0, 7.0, 8.0, 3.0, 4.0, 5.0, 0.0, 1.0, 2.0]))
示例#29
0
def test_hugo_reshape():
    with open(os.path.join(_TEST_DATA_DIR, 'hugo_site.asc')) as asc_file:
        (grid, field) = read_esri_ascii(asc_file, reshape=True)

    assert_is_instance(grid, RasterModelGrid)

    assert_true(field.shape, (55, 76))
示例#30
0
def test_hugo_read_file_name():
    (grid, field) = read_esri_ascii(os.path.join(_TEST_DATA_DIR, "hugo_site.asc"))

    assert_is_instance(grid, RasterModelGrid)

    assert_equal(field.size, 55 * 76)
    assert_equal(field.shape, (55 * 76,))
 def read_topography(self, topo_file_name, name, halo):
     """Read and return topography from file, as a Landlab grid and field."""
     try:
         (grid, z) = read_esri_ascii(topo_file_name, name=name, halo=halo)
     except:
         grid = read_netcdf(topo_file_name)
         z = grid.at_node[name]
     return (grid, z)
def test_hugo_read_file_name():
    (grid,
     field) = read_esri_ascii(os.path.join(_TEST_DATA_DIR, 'hugo_site.asc'))

    assert isinstance(grid, RasterModelGrid)

    assert field.size == 55 * 76
    assert field.shape == (55 * 76, )
示例#33
0
def test_4x3_read_file_like():
    with open(os.path.join(_TEST_DATA_DIR, '4_x_3.asc')) as asc_file:
        (grid, field) = read_esri_ascii(asc_file)

    assert isinstance(grid, RasterModelGrid)

    assert_array_equal(
        field, np.array([9., 10., 11., 6., 7., 8., 3., 4., 5., 0., 1., 2.]))
示例#34
0
def test_hugo_read_file_like():
    with open(os.path.join(_TEST_DATA_DIR, "hugo_site.asc")) as asc_file:
        (grid, field) = read_esri_ascii(asc_file)

    assert isinstance(grid, RasterModelGrid)

    assert field.size == 55 * 76
    assert field.shape == (55 * 76, )
def test_hugo_read_file_name():
    (grid, field) = read_esri_ascii(os.path.join(_TEST_DATA_DIR, "hugo_site.asc"))

    assert isinstance(grid, RasterModelGrid)

    assert field.size == 55 * 76
    assert field.shape == (55 * 76,)
    assert (grid.x_of_node.min(), grid.y_of_node.min()) == (0.0, 0.0)
示例#36
0
def test_4x3_read_file_name():
    (grid, field) = read_esri_ascii(os.path.join(_TEST_DATA_DIR, '4_x_3.asc'))

    assert_is_instance(grid, RasterModelGrid)

    assert_is_instance(field, np.ndarray)
    assert_array_equal(
        field, np.array([9., 10., 11., 6., 7., 8., 3., 4., 5., 0., 1., 2.]))
示例#37
0
def test_hugo_read_file_like():
    with open(os.path.join(_TEST_DATA_DIR, 'hugo_site.asc')) as asc_file:
        (grid, field) = read_esri_ascii(asc_file)

    assert_is_instance(grid, RasterModelGrid)

    assert_equal(field.size, 55 * 76)
    assert_equal(field.shape, (55 * 76, ))
示例#38
0
    def test_read_file_name(self):
        (grid, field) = read_esri_ascii(os.path.join(_TEST_DATA_DIR, "4_x_3.asc"))

        self.assertIsInstance(grid, RasterModelGrid)

        self.assertIsInstance(field, np.ndarray)
        self.assertEqual(field.shape, (4 * 3,))
        self.assertListEqual(list(field.flat), [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0])
示例#39
0
def test_hugo_read_file_like():
    with open(os.path.join(_TEST_DATA_DIR, 'hugo_site.asc')) as asc_file:
        (grid, field) = read_esri_ascii(asc_file)

    assert_is_instance(grid, RasterModelGrid)

    assert_equal(field.size, 55 * 76)
    assert_equal(field.shape, (55 * 76, ))
示例#40
0
def test_hugo_read_file_like():
    with open(os.path.join(_TEST_DATA_DIR, "hugo_site.asc")) as asc_file:
        (grid, field) = read_esri_ascii(asc_file)

    assert isinstance(grid, RasterModelGrid)

    assert field.size == 55 * 76
    assert field.shape == (55 * 76,)
def test_hugo_read_file_name():
    (grid, field) = read_esri_ascii(os.path.join(_TEST_DATA_DIR,
                                                 'hugo_site.asc'))

    assert isinstance(grid, RasterModelGrid)

    assert field.size == 55 * 76
    assert field.shape == (55 * 76, )
示例#42
0
def test_hugo_read_file_name(datadir):
    (grid, field) = read_esri_ascii(datadir / "hugo_site.asc")

    assert isinstance(grid, RasterModelGrid)

    assert field.size == 55 * 76
    assert field.shape == (55 * 76, )
    assert (grid.x_of_node.min(), grid.y_of_node.min()) == (0.0, 0.0)
示例#43
0
def test_hugo_read_file_like(datadir):
    with open(datadir / "hugo_site.asc") as asc_file:
        (grid, field) = read_esri_ascii(asc_file)

    assert isinstance(grid, RasterModelGrid)

    assert field.size == 55 * 76
    assert field.shape == (55 * 76, )
    def test_read_file_name(self):
        (grid,
         field) = read_esri_ascii(os.path.join(_TEST_DATA_DIR,
                                               'hugo_site.asc'))

        self.assertIsInstance(grid, RasterModelGrid)

        self.assertEqual(field.size, 55 * 76)
        self.assertEqual(field.shape, (55 * 76, ))
示例#45
0
def test_4x3_read_file_like():
    with open(os.path.join(_TEST_DATA_DIR, "4_x_3.asc")) as asc_file:
        (grid, field) = read_esri_ascii(asc_file)

    assert isinstance(grid, RasterModelGrid)

    assert_array_equal(
        field, np.array([9., 10., 11., 6., 7., 8., 3., 4., 5., 0., 1., 2.])
    )
def test_4x3_read_file_like():
    with open(os.path.join(_TEST_DATA_DIR, "4_x_3.asc")) as asc_file:
        (grid, field) = read_esri_ascii(asc_file)

    assert isinstance(grid, RasterModelGrid)

    assert_array_equal(
        field, np.array([9.0, 10.0, 11.0, 6.0, 7.0, 8.0, 3.0, 4.0, 5.0, 0.0, 1.0, 2.0])
    )
示例#47
0
def test_names_keyword():
    grid = RasterModelGrid(4, 5, 2.)
    grid.add_field('node', 'air__temperature', np.arange(20.))
    grid.add_field('node', 'land_surface__elevation', np.arange(20.))

    with cdtemp() as _:
        grid.save('test.asc', names='land_surface__elevation')
        assert_true(os.path.isfile('test.asc'))
        read_esri_ascii('test.asc')

    with cdtemp() as _:
        grid.save('test.asc', names=['land_surface__elevation',
                                     'air__temperature'])
        files = ['test_land_surface__elevation.asc',
                 'test_air__temperature.asc']
        for fname in files:
            assert_true(os.path.isfile(fname))
            read_esri_ascii(fname)
示例#48
0
def test_4x3_read_file_name():
    (grid, field) = read_esri_ascii(os.path.join(_TEST_DATA_DIR, "4_x_3.asc"))

    assert isinstance(grid, RasterModelGrid)

    assert isinstance(field, np.ndarray)
    assert (grid.x_of_node.min(), grid.y_of_node.min()) == (1.0, 2.0)
    assert_array_equal(
        field, np.array([9., 10., 11., 6., 7., 8., 3., 4., 5., 0., 1., 2.]))
示例#49
0
def test_name_keyword():
    (grid, field) = read_esri_ascii(os.path.join(_TEST_DATA_DIR, "4_x_3.asc"), name="air__temperature")

    assert_is_instance(grid, RasterModelGrid)

    assert_is_instance(field, np.ndarray)
    assert_array_equal(field, np.array([9.0, 10.0, 11.0, 6.0, 7.0, 8.0, 3.0, 4.0, 5.0, 0.0, 1.0, 2.0]))
    assert_array_almost_equal(grid.at_node["air__temperature"], field)
    assert_is(grid.at_node["air__temperature"], field)
示例#50
0
def test_4x3_read_file_like(datadir):
    with open(datadir / "4_x_3.asc") as asc_file:
        (grid, field) = read_esri_ascii(asc_file)

    assert isinstance(grid, RasterModelGrid)

    assert_array_equal(
        field,
        np.array(
            [9.0, 10.0, 11.0, 6.0, 7.0, 8.0, 3.0, 4.0, 5.0, 0.0, 1.0, 2.0]))
示例#51
0
def test_4x3_read_file_name():
    (grid, field) = read_esri_ascii(os.path.join(_TEST_DATA_DIR, "4_x_3.asc"))

    assert isinstance(grid, RasterModelGrid)

    assert isinstance(field, np.ndarray)
    assert (grid.x_of_node.min(), grid.y_of_node.min()) == (1.0, 2.0)
    assert_array_equal(
        field, np.array([9.0, 10.0, 11.0, 6.0, 7.0, 8.0, 3.0, 4.0, 5.0, 0.0, 1.0, 2.0])
    )
示例#52
0
def test_name_keyword():
    (grid, field) = read_esri_ascii(os.path.join(_TEST_DATA_DIR, '4_x_3.asc'),
                                    name='air__temperature')

    assert isinstance(grid, RasterModelGrid)

    assert isinstance(field, np.ndarray)
    assert_array_equal(
        field, np.array([9., 10., 11., 6., 7., 8., 3., 4., 5., 0., 1., 2.]))
    assert_array_almost_equal(grid.at_node['air__temperature'], field)
    assert grid.at_node['air__temperature'] is field
示例#53
0
def test_4x3_read_file_name():
    (grid, field) = read_esri_ascii(os.path.join(_TEST_DATA_DIR,
                                                 '4_x_3.asc'))

    assert_is_instance(grid, RasterModelGrid)

    assert_is_instance(field, np.ndarray)
    assert_array_equal(field,
                       np.array([9., 10., 11.,
                                 6.,  7.,  8.,
                                 3.,  4.,  5.,
                                 0.,  1.,  2.]))
示例#54
0
def test_name_keyword():
    (grid, field) = read_esri_ascii(
        os.path.join(_TEST_DATA_DIR, "4_x_3.asc"), name="air__temperature"
    )

    assert isinstance(grid, RasterModelGrid)

    assert isinstance(field, np.ndarray)
    assert_array_equal(
        field, np.array([9., 10., 11., 6., 7., 8., 3., 4., 5., 0., 1., 2.])
    )
    assert_array_almost_equal(grid.at_node["air__temperature"], field)
    assert grid.at_node["air__temperature"] is field
示例#55
0
def test_4x3_read_file_like():
    with open(os.path.join(_TEST_DATA_DIR, '4_x_3.asc')) as asc_file:
        (grid, field) = read_esri_ascii(asc_file)

    assert_is_instance(grid, RasterModelGrid)

    assert_is_instance(field, np.ndarray)
    assert_equal(field.shape, (4 * 3, ))
    assert_list_equal(list(field.flat), [0., 1., 2.,
                                         3., 4., 5.,
                                         6., 7., 8.,
                                         9., 10., 11.,
                                        ])
示例#56
0
    def test_size_mismatch(self):
        asc_file = StringIO(
            """
nrows         4
ncols         3
xllcorner     1.
yllcorner     2.
cellsize      10.
NODATA_value  -9999
1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
            """
        )
        with self.assertRaises(DataSizeError):
            (grid, field) = read_esri_ascii(asc_file)
示例#57
0
def test_write_then_read():
    grid = RasterModelGrid((4, 5), spacing=(2., 2.))
    grid.add_field('node', 'air__temperature', np.arange(20.))

    with cdtemp() as _:
        write_esri_ascii('test.asc', grid)
        new_grid, field = read_esri_ascii('test.asc')

    assert_equal(grid.number_of_node_columns, new_grid.number_of_node_columns)
    assert_equal(grid.number_of_node_rows, new_grid.number_of_node_rows)
    assert_equal(grid.dx, new_grid.dx)
    assert_array_almost_equal(grid.node_x, new_grid.node_x)
    assert_array_almost_equal(grid.node_y, new_grid.node_y)
    assert_array_almost_equal(field, grid.at_node['air__temperature'])
示例#58
0
def test_write_then_read(tmpdir):
    grid = RasterModelGrid((4, 5), xy_spacing=(2.0, 2.0), xy_of_lower_left=(15.0, 10.0))
    grid.add_field("node", "air__temperature", np.arange(20.0))

    with tmpdir.as_cwd():
        write_esri_ascii("test.asc", grid)
        new_grid, field = read_esri_ascii("test.asc")

    assert grid.number_of_node_columns == new_grid.number_of_node_columns
    assert grid.number_of_node_rows == new_grid.number_of_node_rows
    assert grid.dx == new_grid.dx
    assert (grid.x_of_node.min(), grid.y_of_node.min()) == (15.0, 10.0)
    assert_array_almost_equal(grid.node_x, new_grid.node_x)
    assert_array_almost_equal(grid.node_y, new_grid.node_y)
    assert_array_almost_equal(field, grid.at_node["air__temperature"])