Пример #1
0
    def set_extents(self):
        """Set the extents to clip the rasters to. This will either use
        the users values in `coordinate_extent` or calculate from the
        basin outline. If the extents are from the basin outline, the
        padding will be applied from `pad_domain`.
        """

        if self.config['coordinate_extent'] is None:
            extents, _ = domain_extent.parse_from_file(
                self.config['basin_shapefile'])

            padding = [
                self.cell_size * pad for pad in self.config['pad_domain']
            ]

            # Pad the extents
            extents[0] -= padding[0]  # Left
            extents[1] -= padding[1]  # Bottom
            extents[2] += padding[2]  # Right
            extents[3] += padding[3]  # Top

            # Check cell size fits evenly in extent range
            extents = domain_extent.condition_to_cellsize(
                extents, self.cell_size, self._logger)

        else:
            extents = self.config['coordinate_extent']

        self.extents = extents

        # Create an Affine transform and x/y vectors for the domain
        self.transform, self.x, self.y = domain_extent.affine_transform_from_extents(  # noqa
            extents, self.cell_size)
 def test_both(self):
     extent = [320318, 4158530, 327520, 4166337]
     extents = domain_extent.condition_to_cellsize(extent, cell_size=50)
     self.assertListEqual(extents,
                          [320294.0, 4158508.5, 327544.0, 4166358.5])
 def test_right_left(self):
     extent = [320318, 4158537, 327520, 4166337]
     extents = domain_extent.condition_to_cellsize(extent, cell_size=50)
     self.assertListEqual(extents,
                          [320294.0, 4158537.0, 327544.0, 4166337.0])
 def test_no_change(self):
     extent = [320320, 4158537, 327520, 4166337]
     extents = domain_extent.condition_to_cellsize(extent, cell_size=50)
     self.assertListEqual(extent, extents)