Skip to content

Commit

Permalink
Added quantile uncertainity calc
Browse files Browse the repository at this point in the history
  • Loading branch information
adityasevak123ga committed Dec 5, 2023
1 parent 3def600 commit f5f6d9c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
21 changes: 21 additions & 0 deletions uncoverml/interface_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@ def calc_std(config):
dst.write(std_data, 1)


def calc_uncert(config):
res_path = Path(config.output_dir)
pred_file = res_path / 'prediction.tif'
with rasterio.open(pred_file, 'r') as pred_src:
pred_data = pred_src.read(1, masked=True)
pred_profile = pred_src.profile

res_path = Path(config.output_dir)
var_file = res_path / 'variance.tif'
with rasterio.open(var_file, 'r') as var_src:
var_data = var_src.read(1, masked=True)

pred_data = pred_data.filled(np.nan)
var_data = var_data.filled(np.nan)
out_data = (4*np.sqrt(var_data))/pred_data

out_file = res_path / 'uncert.tif'
with rasterio.open(out_file, 'w', **pred_profile) as dst:
dst.write(out_data, 1)


def stretch_raster(data, pct_lims=[5, 95]):
percentiles = np.nanpercentile(np.ravel(data), pct_lims)
percentiles = percentiles.tolist()
Expand Down
4 changes: 2 additions & 2 deletions uncoverml/scripts/uncoverml.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@ def predict(model_or_cluster_file, partitions, mask, retain, prediction_template
write_progress_to_file('pred', 'Preparing results for upload', config)
uncoverml.interface_utils.rename_files_before_upload(config)
uncoverml.interface_utils.create_thumbnail(config, 'prediction')
uncoverml.interface_utils.calc_std(config)
uncoverml.interface_utils.create_thumbnail(config, 'std')
uncoverml.interface_utils.calc_uncert(config)
uncoverml.interface_utils.create_thumbnail(config, 'uncert')
uncoverml.interface_utils.create_results_zip(config)
write_progress_to_file('pred', 'Results Prepared', config)

Expand Down

0 comments on commit f5f6d9c

Please sign in to comment.