def test_sample_randomly_error(array): from gemgis.raster import sample_randomly with pytest.raises(TypeError): sample_randomly([array], [1000, 2069, 1000, 1972], seed=1) with pytest.raises(TypeError): sample_randomly(array, (1000, 2069, 1000, 1972), seed=1) with pytest.raises(TypeError): sample_randomly(array, [1000, 2069, 1000, 1972], seed=1.0) with pytest.raises(TypeError): sample_randomly(array, [1000, 2069, 1000, '1972'], seed=1)
def test_sample_randomly_go(array): from gemgis.raster import sample_randomly random_sample = sample_randomly(array, extent=[1000, 2069, 1000, 1972], seed=1) assert array.ndim == 2 assert array.shape == (1069, 972) assert isinstance(random_sample[0], float) assert isinstance(random_sample[1], list) assert random_sample == (518.1631561814993, [1445.7965230270515, 1700.1554076257776]) assert all(isinstance(n, float) for n in random_sample[1])
def test_sample_randomly_raster(dem): from gemgis.raster import sample_randomly sample = sample_randomly(dem, extent=[1000, 2069, 1000, 1972], seed=1) assert sample == (668.4022827148438, [404.92957493148504, 769.3808873834653]) assert sample[0] == 668.4022827148438 assert isinstance(sample[0], float) assert isinstance(sample[1], list) assert isinstance(sample[1][0], float) assert isinstance(sample[1][1], float)
def test_sample_randomly_array(dem): from gemgis.raster import sample_randomly sample = sample_randomly(dem.read(1), extent=[1000, 2069, 1000, 1972], seed=1) assert sample == (668.4022827148438, [1445.7965230270515, 1700.1554076257776]) assert sample[0] == 668.4022827148438 assert isinstance(sample[0], float) assert isinstance(sample[1], list) assert isinstance(sample[1][0], float) assert isinstance(sample[1][1], float)
def test_sample_randomly_raster_multiple(dem): from gemgis.raster import sample_randomly sample, coordinates = sample_randomly(dem, n=2, extent=[1000, 2069, 1000, 1972], seed=1) assert isinstance(sample, list) assert isinstance(coordinates, list) assert isinstance(sample[0], float) assert isinstance(sample[1], float) assert isinstance(coordinates[0][0], float) assert isinstance(coordinates[0][1], float) assert sample[0] == 416.4200439453125 assert sample[1] == 402.33673095703125 assert coordinates[0][0] == 404.92957493148504 assert coordinates[0][1] == 699.4371703486034 assert coordinates[1][0] == 0.12216410696185687 assert coordinates[1][1] == 322.92238447267215
def test_sample_randomly_array_multiple(dem): from gemgis.raster import sample_randomly sample, coordinates = sample_randomly(dem.read(1), n=2, extent=[1000, 2069, 1000, 1972], seed=1) assert isinstance(sample, list) assert isinstance(coordinates, list) assert isinstance(sample[0], float) assert isinstance(sample[1], float) assert isinstance(coordinates[0][0], float) assert isinstance(coordinates[0][1], float) assert sample[0] == 416.4200439453125 assert sample[1] == 402.33673095703125 assert coordinates[0][0] == 1445.7965230270515 assert coordinates[0][1] == 1770.026883489667 assert coordinates[1][0] == 1000.1111723224592 assert coordinates[1][1] == 1293.8672605981483