def write_hres_mask(path_valfis, path_output, materials):
    init = False
    for m in materials:
        m_file = join(path_valfis, f"{m}.tif")
        if os.path.isfile(m_file):
            print(f'{m} m_file found')
            xsize, ysize, geotransform, geoproj, data_m = readFile(m_file)

            if not init:
                data_tot = np.zeros((ysize, xsize))
                init = True

            data_tot += data_m
    if not init:
        print("no file was loaded")
        return

    data_tot[data_tot > 0] = 1
    data_tot[data_tot <= 0] = 0
    writeGeotiffSingleBand(path_output, geotransform, geoproj, data_tot)
Пример #2
0
from raster_sum import raster_sum

            
#inputs
path = '/Users/silvia/Documents/AFRICA_DATA/Botswana/'
path_pop = join(path, 'BW_gdp_2016_GAR_normalizedWP_90m_20180730.tif')
pop_2016 = 15649000000
pop_2050 = 88597000000
    
# outputs
path_output_pop_2016 = join(path, 'BW_gdp_2016_GAR_normalizedWP_90m_20181024.tif')
path_output_pop_2050 = join(path, 'BW_gdp_2050_GAR_normalizedWP_90m_20181024.tif')
    

xsize, ysize, geotransform, geoproj, data_pop   = readFile(path_pop)
tot_pop = raster_sum(data_pop)

factor_2016 = pop_2016/tot_pop
data_pop_2016 = data_pop*factor_2016
writeGeotiffSingleBand(path_output_pop_2016, geotransform, geoproj, data_pop_2016)
#check
raster_sum(data_pop_2016)

factor_2050 = pop_2050/tot_pop
data_pop_2050 = data_pop*factor_2050
writeGeotiffSingleBand(path_output_pop_2050, geotransform, geoproj, data_pop_2050)
#check
raster_sum(data_pop_2050)


__author__ = 'silvia'

from Geotiff_Silvia import readFile, readFile_withNoData, writeGeotiffSingleBand, readFileBand
import numpy as np
from os.path import join
import os
from rasterRegrid import rasterRegrid
import matplotlib.pylab as plt
from africa_tools import log_print

path_1 = '/Users/silvia/Documents/AFRICA_DATA/Guinea_Bissau/integrazione_buiA/gw_buia_01_box.tif'
path_2 = '/Users/silvia/Documents/AFRICA_DATA/Guinea_Bissau/regrid_outputs_20181018/GW_buiA_GHSL_GUF_LC_OSM_wp3_90m.tif'
#path_3 = '/Users/silvia/Documents/AFRICA_DATA/Namibia/OSM.tif'
path_output = '/Users/silvia/Documents/AFRICA_DATA/Guinea_Bissau/integrazione_buiA/GW_buiA_GHSL_GUF_LC_OSM_wp3_90m_integration.tif'

xsize, ysize, geotransform, geoproj, data_1 = readFile(path_1)
xsize, ysize, geotransform, geoproj, data_2 = readFile(path_2)
#xsize, ysize, geotransform, geoproj, data_3   = readFile(path_3)

#data_tot = data_1 + data_2 + data_3
data_tot = data_1 + data_2
data_tot[data_tot > 0] = 1
data_tot[data_tot <= 0] = 0
writeGeotiffSingleBand(path_output, geotransform, geoproj, data_tot)
path_output = join(path, 'VALFIS_merge_outputs')

materials = ['C1', 'M1', 'M2', 'W1', 'T1']

xsize, ysize, geotransform, geoproj, mask = readFile(mask)
mask_false = np.zeros((ysize, xsize))
mask_false[mask == 1] = 0
mask_false[mask != 1] = 1

for m in materials:
    output_file = join(path_output, f'{m}.tif')
    m_file1 = join(path_valfis1, f"{m}.tif")
    if os.path.isfile(m_file1):
        print(f'{m} 1st file found')
        xsize, ysize, geotransform, geoproj, data_m1 = readFile(m_file1)

        m_file2 = join(path_valfis2, f"{m}.tif")
        if os.path.isfile(m_file2):
            print(f'{m} 2nd file found')
            xsize, ysize, geotransform, geoproj, data_m2 = readFile(m_file2)

            data_m_tot = data_m1 * mask + data_m2 * mask_false
            print(f'{m} data_tot_calculated')
            writeGeotiffSingleBand(output_file, geotransform, geoproj,
                                   data_m_tot)
            print(f'{m} file saved')
        else:
            print(f'second {m} file not found')
    else:
        print(f'{m} file not found')
            data_hous = np.zeros((ysize, xsize))
            data_ind = np.zeros((ysize, xsize))
            data_serv = np.zeros((ysize, xsize))
            data_gov = np.zeros((ysize, xsize))
            init = True

        p_file = join(path_p, f'{m}.tiff')
        if os.path.isfile(p_file):
            print(f'{m} p_file found')
            data_p1, data_p2, data_p3, data_p4, data_p5, data_p6 \
                = readMultiBandGeotiff(p_file)

            data_hous += (data_m * data_p1 + data_m * data_p2) / 100
            data_ind += (data_m * data_p6) / 100
            data_serv += (data_m * data_p3) / 100
            data_gov += (data_m * data_p5) / 100

hous_tot = np.nansum(data_hous)
log_print(f'total housing: [{hous_tot}]')
ind_tot = np.nansum(data_ind)
log_print(f'total industrial: [{ind_tot}]')
serv_tot = np.nansum(data_serv)
log_print(f'total service: [{serv_tot}]')
gov_tot = np.nansum(data_gov)
log_print(f'total governmental: [{gov_tot}]')

writeGeotiffSingleBand(sFile_hous, geotransform, geoproj, data_hous)
writeGeotiffSingleBand(sFile_ind, geotransform, geoproj, data_ind)
writeGeotiffSingleBand(sFile_serv, geotransform, geoproj, data_serv)
writeGeotiffSingleBand(sFile_gov, geotransform, geoproj, data_gov)