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)
from high_res_mask import write_hres_mask 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)
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 ######################################### ############## FILE PATH ############### ######################################### def raster_sum(data): data [data <= 0] = 0 tot = np.nansum(data) log_print(f'total: [{tot}]') return tot if __name__ == '__main__': sFile = '/Users/silvia/Desktop/GDP/TZ_gdp_2050_90m_normalizedWP_20181001.tif' [xsize, ysize, geotransform, geoproj, data] = readFile(sFile) raster_sum(data)
######################################### ############## FILE PATH ############### ######################################### path = '/Users/silvia/Documents/AFRICA_DATA/Guinea_Bissau' path_valfis1 = join(path, 'valfis_20181025') path_valfis2 = join(path, 'valfis_FILTERED_20181025') mask = join( path, 'integrazione_buiA/GW_buiA_GHSL_GUF_LC_OSM_wp3_90m_integration.tif') # outputs 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)
path = '/Users/silvia/Documents/AFRICA_DATA/Guinea_Bissau/' path_valfis_folder = join(path, 'VALFIS_merge_outputs') path_pop = join(path, 'regrid_outputs/GW_pop_WP_90m.tif') pop_2016 = 1815698 pop_2050 = 2488000 # outputs path_output_mask = join(path, 'GW_buiA_mask_20181025.tif') path_output_pop = join(path, 'GW_pop_in_buiA_20181025.tif') path_output_pop_2016 = join(path, 'GW_pop_2016_in_buiA_20181025.tif') path_output_pop_2050 = join(path, 'GW_pop_2050_in_buiA_20181025.tif') materials = ['C1', 'M1', 'M2', 'W1', 'T1'] write_hres_mask(path_valfis_folder, path_output_mask, materials) xsize, ysize, geotransform, geoproj, data_mask = readFile(path_output_mask) xsize, ysize, geotransform, geoproj, data_pop = readFile(path_pop) data_pop_on_mask = data_mask * data_pop writeGeotiffSingleBand(path_output_pop, geotransform, geoproj, data_pop_on_mask) tot_pop = raster_sum(data_pop_on_mask) factor_2016 = pop_2016 / tot_pop data_pop_2016 = data_pop_on_mask * factor_2016 writeGeotiffSingleBand(path_output_pop_2016, geotransform, geoproj, data_pop_2016) #check raster_sum(data_pop_2016)
# outputs sFile_hous = join(path, 'buna_residential.tif') sFile_ind = join(path, 'buna_industrial.tif') sFile_serv = join(path, 'buna_commercial.tif') sFile_gov = join(path, 'buna_governmental.tif') materials = ['C1', 'M1', 'M2', 'W1', 'T1'] 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_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
__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 from high_res_mask import write_hres_mask from raster_sum import raster_sum #inputs path = '/Users/silvia/Documents/AFRICA_DATA/Sz/Crops' path_file = join(path, 'sz_agrV_sugar_cane_HighRes.tif') value = 40.0 # outputs path_output = join(path, 'sz_agrP_sugar_cane_other.tif') xsize, ysize, geotransform, geoproj, data = readFile(path_file) data_new = data / value writeGeotiffSingleBand(path_output, geotransform, geoproj, data_new)