Commit 4c3e413b authored by roelo008's avatar roelo008

committing from command line

parent 53839a54
......@@ -78,22 +78,23 @@ conc_scen = esd.conc_scenario(conc_blanco, myear_scen)
eval_scen = np.where(conc_scen <= norm, 1, 0).astype(np.uint8) # set to 1 where value <= norm
'''Calculate population living below/above norm'''
pop_below_th = np.where(eval_scen == 1, cbs_bevol_arr, 0)
pop_above_th = np.where(eval_scen == 0, cbs_bevol_arr, 0)
# Done on the fly later on
'''Output numbers '''
true_pxls = eval_scen.sum() # sum, i.e. pixel count where value <= norm
true_area = np.product([true_pxls, np.divide(np.square(px), 1000000)]) # multiply pxl count with area per pixel
true_perc = np.product([np.divide(true_area, nl_onshore), 100]) # divide by reference area
true_perc = np.product([np.divide(true_area, nl_onshore), 100]).round(2) # divide by reference area
total_pop = cbs_bevol_arr.sum().astype(np.uint64)
below_pop = pop_below_th.sum().astype(np.uint64)
above_pop = pop_above_th.sum().astype(np.uint64)
below_pop = np.where(eval_scen == 1, cbs_bevol_arr, 0).sum().astype(np.uint64)
above_pop = np.subtract(total_pop, below_pop)
below_perc = np.product([np.divide(below_pop, total_pop), 100]).round(2)
above_perc = np.product([np.divide(above_pop, total_pop), 100]).round(2)
'''Write outputs to file'''
timestamp_brief = datetime.datetime.now().strftime("%Y%m%d%H%M")
timestamp_full = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
out_base_dir = r'c:\apps\proj_code\esd'
out_base_dir = r'c:\apps\proj_code\esd\c_out'
out_dir = os.path.join(out_base_dir, '{0}{1}'.format(timestamp_brief, scen_naam))
os.mkdir(out_dir)
basename = 'ESD2J_rpm25_{0}'.format(scen_naam)
......@@ -108,10 +109,10 @@ with rio.open(os.path.join(out_dir, basename+'_conc_wo_veg.tif'), 'w', **prof) a
prof.update(dtype=rio.float32)
with rio.open(os.path.join(out_dir, basename+'_pop_below_tresh.tif'), 'w', **prof) as dst:
dst.write(pop_below_th, 1) # write populating living below treshold raster
dst.write(np.where(eval_scen == 1, cbs_bevol_arr, 0), 1) # write populating living below treshold raster
with rio.open(os.path.join(out_dir, basename+'_pop_above_tresh.tif'), 'w', **prof) as dst:
dst.write(pop_above_th, 1) # write population living above treshold raster
dst.write(np.where(eval_scen == 0, cbs_bevol_arr, 0), 1) # write population living above treshold raster
prof.update(dtype=rio.uint8)
with rio.open(os.path.join(out_dir, basename+'_below_tresh.tif'), 'w', **prof) as dst:
......@@ -123,9 +124,11 @@ footer = '\nMade with Python 3.5 using pandas, geopandas, by Hans Roelofsen, WEn
msg1 = 'For scenario {0} (based on {1}) there are {2} pixels w value <= {3}, which equals to:' \
'{4} square km, which is {5}% of onshore area of the Netherlands ({6} km2).\n'\
.format(scen_naam, os.path.basename(lceu_scen_in), true_pxls, norm, true_area, true_perc, nl_onshore)
msg2 = 'There are {0} people living in the Netherlands in 2018 according to CBS, of which {1} live in areas where ' \
'the treshold is exceeded and {2} in areas below the treshold.'.format(total_pop, above_pop, below_pop)
.format(scen_naam, lceu_scen_in, true_pxls, norm, true_area, true_perc, nl_onshore)
msg2 = 'There are {0} people living in the Netherlands in 2018 according to CBS, of which {1} ({2}%) live in areas ' \
'where the treshold is exceeded and {3} ({4}%) in areas below the treshold.' \
.format(total_pop, above_pop, above_perc, below_pop, below_perc)
print(msg1)
print(msg2)
with open(os.path.join(out_dir, '{0}_report_{1}.txt'.format(os.path.splitext(scen_naam)[0], timestamp_brief)), 'w') \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment