Пример #1
0
    def test_reproject(self, mock_veg):
        self.subject.reproject(self.EXTENTS, self.CELL_SIZE, self.CRS)

        for image in self.subject.clipped_images.values():
            extents, cell_size = domain_extent.parse_from_file(image)
            self.assertListEqual(extents, self.EXTENTS_RASTER)
            self.assertTrue(cell_size == self.CELL_SIZE)
Пример #2
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_shapefile(self):
        file_name = os.path.join(self.basin_dir, 'gold', 'basin_outline.shp')
        extents, cellsize = domain_extent.parse_from_file(file_name)

        self.assertListEqual(
            extents,
            [320320.405027, 4158537.07547, 327520.405027, 4166337.07547])
        self.assertIsNone(cellsize)
    def test_netcdf(self):
        file_name = os.path.join(self.basin_dir, 'gold', 'landfire_140',
                                 'topo.nc')
        extents, cellsize = domain_extent.parse_from_file(file_name)

        self.assertListEqual(
            extents, [319570.40625, 4157787.0, 328270.40625, 4167087.0])
        self.assertListEqual(cellsize, [150, 150])
    def test_tif(self):

        file_name = os.path.join(self.basin_dir, 'data',
                                 'dem_epsg_32611_100m.tif')
        extents, cellsize = domain_extent.parse_from_file(file_name)

        self.assertListEqual(
            extents, [318520.405, 4157537.075, 329820.405, 4167937.075])
        self.assertTrue(cellsize == 100)
    def test_load_dem(self):
        self.subject.crs = self.CRS
        self.subject.extents = self.EXTENTS
        self.subject.load_dem()

        extents, cell_size = domain_extent.parse_from_file(
            'tests/Lakes/output/temp/clipped_dem.tif')

        self.assertListEqual(extents, self.EXTENTS_RASTER)
        self.assertTrue(cell_size == self.subject.config['cell_size'])
        self.assertIsInstance(self.subject.dem, xr.DataArray)
        self.assertCountEqual(list(self.subject.dem.coords.keys()),
                              ['y', 'x', 'spatial_ref'])
    def test_load_vegetation(self, mock_veg):
        self.subject.crs = self.CRS
        self.subject.extents = self.EXTENTS
        self.subject.load_vegetation()

        extents, cell_size = domain_extent.parse_from_file(
            self.subject.veg.clipped_images['veg_type'])

        self.assertListEqual(extents, self.EXTENTS_RASTER)
        self.assertTrue(cell_size == self.subject.config['cell_size'])

        self.assertIsInstance(self.subject.veg, Landfire140)
        self.assertCountEqual(list(self.subject.veg.veg_tau_k.coords.keys()),
                              ['y', 'x', 'spatial_ref'])
        self.assertCountEqual(list(self.subject.veg.veg_height.coords.keys()),
                              ['y', 'x', 'spatial_ref'])