示例#1
0
    def test_n_pixels(self):
        """
        Test that the correct number of random pixels are returned.
        The default return value is 100 pixels.
        """

        dims = (100, 100)
        idx = ut.random_pixel_locations(dims)
        n = idx[0].shape[0]
        self.assertTrue(n == 100)
示例#2
0
    def test_lon_array(self):
        """
        Test that the interpolated longitude array has sensible
        values.

        :notes:
        The default image that is used is a 1000 by 1000. This might
        be too small for a recursive depth of 7 (default within the
        NBAR framework). As such a depth of 3 is used and produced
        correct results. If a larger image is used, then the depth
        level should probably be increased.
        """
        acq = acquisitions(LS5_SCENE1).get_acquisitions()[0]
        geobox = acq.gridded_geo_box()
        fid = create_lon_lat_grids(acq, depth=5)
        dataset_name = ppjoin(GroupName.LON_LAT_GROUP.value,
                              DatasetName.LON.value)
        lon = fid[dataset_name][:]
        ids = ut.random_pixel_locations(lon.shape)

        # We'll transform (reproject) to WGS84
        sr = osr.SpatialReference()
        sr.SetFromUserInput(CRS)

        # Get a list of x reprojected co-ordinates
        reprj = []
        for i in range(ids[0].shape[0]):
            # Get pixel (x,y)
            xy = (ids[1][i], ids[0][i])

            # Convert pixel to map
            mapXY = geobox.convert_coordinates(xy, centre=True)

            # Transform map to another crs
            x, _ = geobox.transform_coordinates(mapXY, to_crs=sr)
            reprj.append(x)

        reprj = numpy.array(reprj)

        lon_values = lon[ids]

        # A decimal degree co-ordinate should be correct up to the 6th dp
        self.assertIsNone(npt.assert_almost_equal(lon_values, reprj,
                                                  decimal=5))