Esempio n. 1
0
def start():
    user_input = input('Enter file path for first_band: ')
    # Open First image and get its only band.
    # first_tiff = Open(r'51/AST_L1B_00308132001191022_20110122163617_24451_ImageData1_b30de2ff.tif')
    first_tiff = Open(user_input)
    first_band = first_tiff.GetRasterBand(1)

    user_input = input('Enter file path for second_band of same image: ')
    # Open Second image and get its only band.
    # second_tiff = Open(r'51/AST_L1B_00308132001191022_20110122163617_24451_ImageData2_b30de2ff.tif')
    second_tiff = Open(user_input)
    second_band = second_tiff.GetRasterBand(1)

    # Release from memory
    user_input = None

    # Get the rows and cols from one of the images (both should always be the same)
    rows, cols, geotransform = first_tiff.RasterYSize, first_tiff.RasterXSize, first_tiff.GetGeoTransform()
    print(geotransform)

    # Set an output for a 16-bit unsigned integer (0-255)
    out_tiff_int16 = r'TEST-RESULTS/NDVI_INT16.tif'

    # Set the output for a 32-bit floating point (-1 to 1)
    out_tiff_float32 = r'TEST-RESULTS/NDVI_FLOAT32.tif'

    # Run the function for unsigned 16-bit integer
    ndwi(first_band, second_band, rows, cols, geotransform, out_tiff_int16, gdal.GDT_UInt16)

    # Run the function for 32-bit floating point
    ndwi(first_band, second_band, rows, cols, geotransform, out_tiff_float32, gdal.GDT_Float32)

    print('done')
Esempio n. 2
0
def main():

    if len(sys.argv) < 6:
        print "Few arguments"
        sys.exit()

    elif len(sys.argv) > 6:
        print "Too many arguments"
        sys.exit()

    #Tiff paths
    red_path = str(sys.argv[1])
    nir_path = str(sys.argv[2])
    bqa_path = str(sys.argv[3])
    mtl_path = str(sys.argv[4])
    output_path = str(sys.argv[5])
    d_sun_earth_path = 'd_sun_earth'

    # Open red image and get its only band.
    red_tiff = Open(red_path)
    red_band = red_tiff.GetRasterBand(1)

    # Open NIR image and get its only band.
    nir_tiff = Open(nir_path)
    nir_band = nir_tiff.GetRasterBand(1)

    # Open bqa image and get its only band.
    bqa_tiff = Open(bqa_path)
    bqa_band = bqa_tiff.GetRasterBand(1)

    # Get the rows and cols from one of the images (both should always be the same)
    row, col, geotransform = nir_tiff.RasterYSize, nir_tiff.RasterXSize, nir_tiff.GetGeoTransform(
    )

    # Reading metadata
    parameters = metaReader.readParameters(mtl_path, d_sun_earth_path)

    number_sensor = int(parameters[0])
    julian_day = int(parameters[1])

    sun_elevation = float(parameters[2])
    dist_sun_earth = float(parameters[3])

    mask = get_mask(number_sensor)

    if shadow_check(bqa_band, (col, row), mask):
        print "Invalid inputs. Lots of cloud in tiff images"
        sys.exit()

    ndviC = NDVI(sun_elevation, red_band, nir_band, bqa_band, (col, row),
                 geotransform)
    ndviC.processNDVI(number_sensor, dist_sun_earth, output_path)
Esempio n. 3
0
def apply_valid_range(input_data_set_path: str, file_path: str) -> str:
    """Apply Valid Range -10000 -> 10000.

    Args:
        input_data_set_path (str) - Path to the input data set
        file_path (str) - Target data set filename
    Returns:
        Path to valid_range_image
    """
    src_ds = GDALOpen(input_data_set_path, GA_ReadOnly)

    if src_ds is None:
        raise ValueError(
            'Could not open data set "{}"'.format(input_data_set_path))

    driver = GetDriverByName('MEM')

    src_band = src_ds.GetRasterBand(1)
    data_set = driver.Create('', src_ds.RasterXSize, src_ds.RasterYSize, 1,
                             src_band.DataType)
    data_set.SetGeoTransform(src_ds.GetGeoTransform())
    data_set.SetProjection(src_ds.GetProjection())

    data_set_band = data_set.GetRasterBand(1)

    data_set_band.WriteArray(src_band.ReadAsArray())

    band_array = data_set_band.ReadAsArray()
    dummy = -9999
    data_set_band.SetNoDataValue(dummy)
    band_array[band_array <= -10000] = dummy
    band_array[band_array >= 10000] = dummy
    driver = GetDriverByName('GTiff')
    data_set_band.WriteArray(band_array)

    dst_ds = driver.CreateCopy(file_path, data_set, options=["COMPRESS=LZW"])

    del dst_ds
    del src_ds
    del data_set

    return file_path
Esempio n. 4
0
from gdal import Open
from ndvi import ndvi


# Abrindo banda NIR
nir_tiff = Open(r'NIR_IMAGE.tif')
#nir_tiff = Open(r'nir.tif')
nir_band = nir_tiff.GetRasterBand(1)

# Abrindo banda RED.
red_tiff = Open(r'RED_IMAGE.tif')
#red_tiff = Open(r'red.tif') 
red_band = red_tiff.GetRasterBand(1)

# Get the rows and cols from one of the images (both should always be the same)
rows, cols, geotransform = nir_tiff.RasterYSize, nir_tiff.RasterXSize, nir_tiff.GetGeoTransform()
print(geotransform)

# Arquivo de saida 16-bit (0-255)
out_tiff_int16 = r'NDVI_16.tif'

# Arquivo de saida 32-bit floating point (-1 to 1)
out_tiff_float32 = r'NDVI_32.tif'

# Gerando imagem  NDVI 16-bit integer
ndvi(nir_band, red_band, rows, cols, geotransform, out_tiff_int16, gdal.GDT_UInt16)

# Gerando imagem NDVI 32-bit floating point
ndvi(nir_band, red_band, rows, cols, geotransform, out_tiff_float32, gdal.GDT_Float32)

print('done')
Esempio n. 5
0
    #plt.savefig('testResult.tif', dpi=300)

    # !!!! Save GEOreferenced TIFF
    pred = np.load('label_pred.npy')
    pred = (pred*255).astype('uint8')
    #pred = (pred > 0.9).astype('uint8')
    cv2.imwrite(files, pred)
    #cv2.imwrite(files, pred)
    
    dataset = Open(os.path.join(path,files))
    if dataset is None:
        print('Unable to open')
        sys.exit(1)
    
    projection   = dataset.GetProjection()
    geotransform = dataset.GetGeoTransform()
    
    if projection is None and geotransform is None:
        print('No projection or geotransform found on file')
        sys.exit(1)
        
    dataset2 = Open(files, GA_Update)
    
    if geotransform is not None and geotransform != (0,1,0,0,0,1):
        dataset2.SetGeoTransform( geotransform )
    
    if projection is not None and projection != '':
        dataset2.SetProjection( projection )
    
    gcp_count = dataset.GetGCPCount()
    if gcp_count != 0:
Esempio n. 6
0
import numpy as np
import matplotlib.pyplot as plt
from gdal import Open as OpenGdal

#-------------------------------------------------------------------------------

fn0 = '../data/SVDNB_npp_20150101-20151231_75N060W_{}_v10_c201701311200.avg_rade9.tif'

# vcm - viirs cloud mask
# vcm-orm = outlier removed
# vcm-ntl = background (non-lights) removed
# vcm-orm-ntl = both
gd = OpenGdal(fn0.format('vcm-orm-ntl'))

print gd.RasterXSize, gd.RasterYSize
gt = gd.GetGeoTransform()

#-------------------------------------------------------------------------------

xy2geo = lambda g, x, y: (g[3] + g[5] * y, g[0] + g[1] * x)
geo2xy = lambda g, f, l: ((l - g[0]) / g[1], (f - g[3]) / g[5])

#-------------------------------------------------------------------------------

# geo0 = 51.11, 17.03 # wroclaw
# geo0 = 52.22, 21.01 # warszawa
# geo0 = 50.816, 15.383 # Orle
# geo0 = 50.846015, 16.698650 # tapadla
geo0 = 50.995681, 16.901729
geor = 0.6
f0, l0 = geo0[0] + geor, geo0[1] - geor