Skip to content
Snippets Groups Projects
Verified Commit dd5641f3 authored by Lukas Kluft's avatar Lukas Kluft
Browse files

Properly normalize remap weights after coarsening

For ocean grids, the re-scaling factor is not always 4, but determined
by the actual number of links to the destination address.
parent cb697974
No related branches found
No related tags found
No related merge requests found
......@@ -17,9 +17,14 @@ def coarsen_weight_file(inweights, outweights, nbisections=1):
w = weights[["src_address", "dst_address", "remap_matrix"]].to_dataframe()
w.dst_address = ((w.dst_address - 1) // coarsen) + 1
w.remap_matrix = w.remap_matrix / coarsen
new_w = w.groupby(["src_address", "dst_address"]).sum().reset_index()
# Normalize weights by actual number of links to new destination address
new_w = w.set_index("dst_address")
new_w["remap_matrix"] = new_w["remap_matrix"] / new_w["remap_matrix"].groupby("dst_address").count()
new_w = new_w.reset_index()
# Combine equivalent links into one
new_w = new_w.groupby(["src_address", "dst_address"]).sum().reset_index()
new_w.index.name = "num_links"
new_w = new_w.to_xarray()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment