Esempio n. 1
0
 def test_draw_and_update_tables(self):
     geom_json = """
     { "type": "Polygon", "coordinates": [ [
         [ 81015.066359097298118, 440929.453467557614204 ],
         [ 81117.980358958055149, 440700.214556140999775 ],
         [ 81166.972951597010251, 440713.396766208577901 ],
         [ 81133.564320785750169, 440811.235749009530991 ],
         [ 81090.294539064285345, 440949.198693339480087 ],
         [ 81015.066359097298118, 440929.453467557614204 ]
     ] ] }
     """
     with SubgridWrapper(mdu=self._mdu_path('duifp')) as subgrid:
         subgrid.update(-1)
         x0 = subgrid.get_nd('x0p')
         x1 = subgrid.get_nd('x1p')
         y0 = subgrid.get_nd('y0p')
         y1 = subgrid.get_nd('y1p')
         raster = subgrid.get_nd('soiltype')
         if raster is None:
             raise ValueError("Make sure you are testing with a model " +
                              "with soiltype + numlayers > 0")
         rr, cc = draw_shape_on_raster(geom_json,
                                       raster,
                                       21,
                                       extent=(x0, y0, x1, y1))
         quad_grid = make_quad_grid(subgrid)
         quad_cells = set(quad_grid[row, col] for row, col in zip(rr, cc))
         subgrid.update_tables('soiltype', quad_cells)
         # TODO: create proper assert, what should we check here.
         self.assertGreater(len(quad_cells), 5)
Esempio n. 2
0
    def test_draw_soiltype(self):
        geom_json = """
        { "type": "Polygon", "coordinates": [ [
            [ 81015.066359097298118, 440929.453467557614204 ],
            [ 81117.980358958055149, 440700.214556140999775 ],
            [ 81166.972951597010251, 440713.396766208577901 ],
            [ 81133.564320785750169, 440811.235749009530991 ],
            [ 81090.294539064285345, 440949.198693339480087 ],
            [ 81015.066359097298118, 440929.453467557614204 ]
        ] ] }
        """
        with SubgridWrapper(mdu=self._mdu_path('duifp')) as subgrid:
            subgrid.update(-1)
            x0 = subgrid.get_nd('x0p')
            x1 = subgrid.get_nd('x1p')
            y0 = subgrid.get_nd('y0p')
            y1 = subgrid.get_nd('y1p')
            raster = subgrid.get_nd('soiltype')
            if raster is None:
                raise ValueError("Make sure you are testing with a model " +
                                 "with soiltype + numlayers > 0")
            # Set value to 1
            raster0 = raster.copy()

            rr, cc = draw_shape_on_raster(geom_json,
                                          raster,
                                          21,
                                          extent=(x0, y0, x1, y1))
            #
            # assume there are values changed
            n = (raster != raster0).sum()
            logger.debug("%d values changed", n)
            self.assertTrue(n > 0)
            # assume all new values are 1
            npt.assert_equal(21, raster[raster != raster0])
Esempio n. 3
0
 def test_draw_and_update_tables(self):
     geom_json = """
     { "type": "Polygon", "coordinates": [ [
         [ 81015.066359097298118, 440929.453467557614204 ],
         [ 81117.980358958055149, 440700.214556140999775 ],
         [ 81166.972951597010251, 440713.396766208577901 ],
         [ 81133.564320785750169, 440811.235749009530991 ],
         [ 81090.294539064285345, 440949.198693339480087 ],
         [ 81015.066359097298118, 440929.453467557614204 ]
     ] ] }
     """
     with SubgridWrapper(mdu=self._mdu_path('duifp')) as subgrid:
         subgrid.update(-1)
         x0 = subgrid.get_nd('x0p')
         x1 = subgrid.get_nd('x1p')
         y0 = subgrid.get_nd('y0p')
         y1 = subgrid.get_nd('y1p')
         raster = subgrid.get_nd('soiltype')
         if raster is None:
             raise ValueError("Make sure you are testing with a model " +
                              "with soiltype + numlayers > 0")
         rr, cc = draw_shape_on_raster(geom_json,
                                       raster,
                                       21,
                                       extent=(x0, y0, x1, y1))
         quad_grid = make_quad_grid(subgrid)
         quad_cells = set(quad_grid[row, col] for row, col in zip(rr, cc))
         subgrid.update_tables('soiltype', quad_cells)
         # TODO: create proper assert, what should we check here.
         self.assertGreater(len(quad_cells), 5)
Esempio n. 4
0
    def test_draw_soiltype(self):
        geom_json = """
        { "type": "Polygon", "coordinates": [ [
            [ 81015.066359097298118, 440929.453467557614204 ],
            [ 81117.980358958055149, 440700.214556140999775 ],
            [ 81166.972951597010251, 440713.396766208577901 ],
            [ 81133.564320785750169, 440811.235749009530991 ],
            [ 81090.294539064285345, 440949.198693339480087 ],
            [ 81015.066359097298118, 440929.453467557614204 ]
        ] ] }
        """
        with SubgridWrapper(mdu=self._mdu_path('duifp')) as subgrid:
            subgrid.update(-1)
            x0 = subgrid.get_nd('x0p')
            x1 = subgrid.get_nd('x1p')
            y0 = subgrid.get_nd('y0p')
            y1 = subgrid.get_nd('y1p')
            raster = subgrid.get_nd('soiltype')
            if raster is None:
                raise ValueError("Make sure you are testing with a model " +
                                 "with soiltype + numlayers > 0")
            # Set value to 1
            raster0 = raster.copy()

            rr, cc = draw_shape_on_raster(
                geom_json, raster, 21, extent=(x0, y0, x1, y1))
            #
            # assume there are values changed
            n = (raster != raster0).sum()
            logger.debug("%d values changed", n)
            self.assertTrue(n > 0)
            # assume all new values are 1
            npt.assert_equal(21, raster[raster != raster0])
Esempio n. 5
0
 def test_draw_raster(self):
     """test the drawing function"""
     geom_json = """
     {
         "type": "Polygon",
         "coordinates": [[
             [1, 1],
             [3, 1],
             [1000, 1000],
             [1, 3],
             [1, 1]
         ]]
     }
     """
     # Create a minimal grid
     raster = np.zeros((4, 4), dtype='int')
     # Draw a small rectangle (using the coordinates in geom_json)
     rr, cc = draw_shape_on_raster(geom_json, raster, 1)
     self.assertTrue(rr.max() < 4)
     self.assertTrue(cc.max() < 4)
     # this is the flattened square
     expected = np.array([0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1])
     npt.assert_array_equal(raster.flatten(), expected)
Esempio n. 6
0
 def test_draw_raster(self):
     """test the drawing function"""
     geom_json = """
     {
         "type": "Polygon",
         "coordinates": [[
             [1, 1],
             [3, 1],
             [1000, 1000],
             [1, 3],
             [1, 1]
         ]]
     }
     """
     # Create a minimal grid
     raster = np.zeros((4, 4), dtype='int')
     # Draw a small rectangle (using the coordinates in geom_json)
     rr, cc = draw_shape_on_raster(geom_json, raster, 1)
     self.assertTrue(rr.max() < 4)
     self.assertTrue(cc.max() < 4)
     # this is the flattened square
     expected = np.array([0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1])
     npt.assert_array_equal(raster.flatten(), expected)