def test_ndim_tuple(self, datadir): file1 = datadir('RGB.BRDF.tif') file2 = datadir('RGB.BRDF.tif') files = (file1, file2) r = rpy.Raster(files, path=None) r.to_array() r2 = rpy.Raster(files, path=None) r2.to_array(flatten=False) r3 = rpy.Raster(files, path=None) r3.to_array(flatten=False, quantification_factor=10000) r4 = rpy.Raster(files, path=None) r4.to_array(band=1) assert r.array[0].ndim == 2 assert r.array[0].shape[0] == 3 assert r.array[0].shape[1] == 62328 assert r2.array[0].shape[0] == 3 assert r2.array[0].shape[1] == 196 assert r2.array[0].shape[2] == 318 assert r.array[1].ndim == 2 assert r.array[1].shape[0] == 3 assert r.array[1].shape[1] == 62328 assert r2.array[1].shape[0] == 3 assert r2.array[1].shape[1] == 196 assert r2.array[1].shape[2] == 318
def calculate_temperature(tif_path, tif_file): grid = rpy.Raster(tif_file, tif_path) grid.to_array() grid.reshape() #print(grid.array[0]) for i in range(0, len(grid.array)): for j in range(0, len(grid.array[i])): print("id: " + str(i) + " " + str(j)) value = float(grid.array[i][j]) #print(value) toa = const_radiance_mul_b10 * value + const_radiance_add_b10 print("Излучение: " + str(toa)) # ЕБУЧИЕ КОМПЛЕКСНЫЕ ЧИСЛА foo = math.log((const_k1_b10 / toa) + 1) #print("TEST: " + str(math.log10((774.8853 / 9.192913599999999) + 1) )) bt = (const_k2_b10 / foo) - const_celsius print("Температура: " + str(bt)) grid.array[i][j] = bt print("----------------") print("Максимальная температура: " + str(max(grid.array.flatten()))) print("Минимальная температура: " + str(min(grid.array.flatten()))) #print(len(grid.array)) return grid.array
def test_no_data(self, datadir): file1 = datadir('RGB.BRDF.tif') ras = rpy.Raster(file1, path=None) ras.to_array() ras.set_nodata(0) assert ras.nodata == 0
def test_dstack2(self, datadir): file1 = datadir('RGB.BRDF.tif') file2 = datadir('RGB.BRDF.tif') files = (file1, file2) ras = rpy.Raster(files, path=None) with pytest.raises(AssertionError): ras.dstack()
def test_set_nodata(self, datadir): file1 = datadir('RGB.BRDF.tif') file2 = datadir('RGB.BRDF.tif') files = (file1, file2) ras = rpy.Raster(files, path=None) with pytest.raises(AssertionError): ras.set_nodata(-99999)
def test_select_int_tuple(self, datadir): file1 = datadir('RGB.BRDF.tif') file2 = datadir('RGB.BRDF.tif') files = (file1, file2) r = rpy.Raster(files, path=None) r.to_array(band=1) assert r.array[0].shape[0] == 62328 assert r.array[1].shape[0] == 62328
def test_value_tuple_select_tuple(self, datadir): file1 = datadir('RGB.BRDF.tif') file2 = datadir('RGB.BRDF.tif') files = (file1, file2) r = rpy.Raster(files, path=None) r.to_array(band=(1, 3)) assert allclose(r.array[0].mean(), -16.39290269043384) assert allclose(r.array[1].mean(), -16.39290269043384)
def test_value_tuple_select_int(self, datadir): file1 = datadir('RGB.BRDF.tif') file2 = datadir('RGB.BRDF.tif') files = (file1, file2) r = rpy.Raster(files, path=None) r.to_array(band=1) assert allclose(r.array[0].mean(), -16.961706109713138) assert allclose(r.array[1].mean(), -16.961706109713138)
def test_value_tuple(self, datadir): file1 = datadir('RGB.BRDF.tif') file2 = datadir('RGB.BRDF.tif') files = (file1, file2) r = rpy.Raster(files, path=None) r.to_array() assert allclose(r.array[0].mean(), -16.48756920623467) assert allclose(r.array[1].mean(), -16.48756920623467)
def test_select_tuple_tuple(self, datadir): file1 = datadir('RGB.BRDF.tif') file2 = datadir('RGB.BRDF.tif') files = (file1, file2) r = rpy.Raster(files, path=None) r.to_array(band=(1, 3)) assert r.array[0].ndim == 2 assert r.array[1].ndim == 2
# Here is an example of some basic features that rasterpy provides. Three bands are read from an image. Then we do some # raster calculation on it. This new bands are then written to a new multi band TIFF. # At first import rasterpy. import rasterpy as rpy import numpy as np # After that we define a path where our test tif file is located. path = "C:\Users\ibari\Dropbox\GitHub\\rasterpy\\tests\data" # Then we open the grid and read it to an multidimensional array: grid = rpy.Raster('RGB.BRF.tif', path) # The quantification factor is a factor which scales reflectance value between 0 and 1. For sentinel 2 the factor is # 10000 grid.to_array(flatten=False, quantification_factor=10000) # By default the loaded grid is flatten. The reason is as following: With a flatten 2 dimensional array the calculations # based on the array are much easier. But in our case this is not necessary: print(grid.array) # Now we convert the whole file from a Bidirectional Reflectance Factor (BRF) into a Bidirectional Reflectance # Distribution Function (BRDF): grid.convert(system='BRF', to='BRDF', output_unit='dB') print(grid.array) # After that we can write the converted data as a multi band tiff: grid.write(data=grid.array, filename='RGB.BRDF.tif', path=path) # We can also convert the arrays from a BRF or BRDF into Backscatter coefficients (BSC). For this we need the # inclination and viewing angles:
# Here is an example of some basic features that rasterpy provides. Three bands are read from an image and averaged to # produce something like a panchromatic band. This new band is then written to a new single band TIFF. # At first import rasterpy. import rasterpy as rpy import numpy as np # After that we define a path where our test tif file is located. path = "C:\Users\ibari\Dropbox\GitHub\\rasterpy\\tests\data" # Then we open the grid and read it to an multidimensional array: grid = rpy.Raster('RGB.byte.tif', path) grid.to_array() # By default the loaded grid is flatten. The reason is as following: With a flatten 2 dimensional array the calculations # based on the array are much easier: print(grid.array) # We can reshape the array to their original shapes with: grid.reshape() print(grid.array) # And we can also flatten it again with: grid.flatten() print(grid.array) # Now average each pixels of the RGB bands: pan = np.mean(grid.array, axis=0) # After that we can write the reshaped pan array as a tiff: grid.write(data=pan.reshape(grid.rows, grid.cols),
def test_select_int(self, datadir): file1 = datadir('RGB.BRDF.tif') r = rpy.Raster(file1, path=None) r.to_array(band=1) assert r.array.shape[0] == 62328
def test_value(self, datadir): file1 = datadir('RGB.BRDF.tif') r = rpy.Raster(file1, path=None) r.to_array() assert allclose(r.array.mean(), -16.48756920623467)
def test_select_tuple(self, datadir): file1 = datadir('RGB.BRDF.tif') r = rpy.Raster(file1, path=None) r.to_array(band=(1, 3)) assert r.array.ndim == 2
def test_flatten(self, datadir): file1 = datadir('RGB.BRDF.tif') ras = rpy.Raster(file1, path=None) with pytest.raises(AssertionError): ras.flatten()