Fix rtt average calculations
This commit is contained in:
parent
f92a121758
commit
7bc02bbd07
17
ipmap.py
17
ipmap.py
|
@ -21,7 +21,7 @@ import numpy as np
|
|||
ip_bytes = 4
|
||||
ip_bits = ip_bytes * 8
|
||||
num_ips = 1 << ip_bits
|
||||
num_ips_sqrt = 1 << ip_bits // 2
|
||||
num_ips_sqrt = 1 << (ip_bits >> 1)
|
||||
|
||||
def make_coord_range(start: int, end: int):
|
||||
return decode(np.arange(start, end, dtype = np.uint32), num_dims = 2, num_bits = 16).astype(np.uint16)
|
||||
|
@ -239,7 +239,7 @@ def make_tiles(coords_path: Path, input_path: Path, tiles_dir: Path, *,
|
|||
def squish():
|
||||
nonlocal density_data
|
||||
nonlocal possible_overlaps
|
||||
density_data = np.swapaxes(density_data.reshape(density_data.shape[0] // 2, 2, density_data.shape[1] // 2, 2), 1, 2)
|
||||
density_data = np.swapaxes(density_data.reshape(density_data.shape[0] >> 1, 2, density_data.shape[1] >> 1, 2), 1, 2)
|
||||
print("calculating density sum...", end = " ", flush = True)
|
||||
density_data[:, :, 0, 0] += density_data[:, :, 0, 1]
|
||||
density_data[:, :, 0, 0] += density_data[:, :, 1, 0]
|
||||
|
@ -292,8 +292,9 @@ def make_tiles(coords_path: Path, input_path: Path, tiles_dir: Path, *,
|
|||
|
||||
def squish():
|
||||
nonlocal rtt_data
|
||||
|
||||
print(f"sorting rtt values for median calculation...", end = " ", flush = True)
|
||||
rtt_data = np.swapaxes(rtt_data.reshape(rtt_data.shape[0] // 2, 2, rtt_data.shape[1] // 2, 2), 1, 2)
|
||||
rtt_data = np.swapaxes(rtt_data.reshape(rtt_data.shape[0] >> 1, 2, rtt_data.shape[1] >> 1, 2), 1, 2)
|
||||
mask = np.empty((rtt_data.shape[0], rtt_data.shape[1]), dtype = np.bool_)
|
||||
np.less(rtt_data[:, :, 0, 0], rtt_data[:, :, 0, 1], out = mask) # sort first row
|
||||
rtt_data[mask, 0] = rtt_data[mask, 0, ::-1]
|
||||
|
@ -310,15 +311,15 @@ def make_tiles(coords_path: Path, input_path: Path, tiles_dir: Path, *,
|
|||
print("calculating median rtt values...", end = " ", flush = True)
|
||||
mask2 = np.empty((rtt_data.shape[0], rtt_data.shape[1]), dtype = np.bool_) # need second mask for binary ops
|
||||
np.not_equal(rtt_data[:, :, 1, 1], 0, out = mask) # four nums populated
|
||||
rtt_data[mask, 0, 1] //= 2
|
||||
rtt_data[mask, 1, 0] //= 2
|
||||
rtt_data[mask, 0, 0] = rtt_data[mask, 0, 1]
|
||||
rtt_data[mask, 0, 0] -= rtt_data[mask, 1, 0]
|
||||
rtt_data[mask, 0, 0] >>= 1
|
||||
rtt_data[mask, 0, 0] += rtt_data[mask, 1, 0] # take average of middle two nums
|
||||
np.logical_and(np.not_equal(rtt_data[:, :, 1, 0], 0, out = mask), np.equal(rtt_data[:, :, 1, 1], 0, out = mask2), out = mask) # three nums populated
|
||||
rtt_data[mask, 0, 0] = rtt_data[mask, 0, 1] # take middle of three nums
|
||||
np.logical_and(np.not_equal(rtt_data[:, :, 0, 1], 0, out = mask), np.equal(rtt_data[:, :, 1, 0], 0, out = mask2), out = mask) # two nums populated
|
||||
rtt_data[mask, 0, 0] //= 2
|
||||
rtt_data[mask, 0, 1] //= 2
|
||||
rtt_data[mask, 0, 0] -= rtt_data[mask, 0, 1]
|
||||
rtt_data[mask, 0, 0] >>= 1
|
||||
rtt_data[mask, 0, 0] += rtt_data[mask, 0, 1] # take average of first two nums
|
||||
# everything else (1 or 0 nums populated) don't need any modifications
|
||||
print("done")
|
||||
|
@ -330,8 +331,6 @@ def make_tiles(coords_path: Path, input_path: Path, tiles_dir: Path, *,
|
|||
for _ in range(skip_iters):
|
||||
squish()
|
||||
|
||||
|
||||
|
||||
def write_all_colormaps():
|
||||
if raws_path is not None:
|
||||
create_tiles(raws_path / variant_name, rtt_data.view(np.uint8).reshape(rtt_data.shape[0], rtt_data.shape[1], 4))
|
||||
|
|
Loading…
Reference in New Issue