Compare commits
3 Commits
f92a121758
...
9c16be8bf3
Author | SHA1 | Date |
---|---|---|
LilyRose2798 | 9c16be8bf3 | |
LilyRose2798 | 9f99c6a528 | |
LilyRose2798 | 7bc02bbd07 |
16
ipmap.py
16
ipmap.py
|
@ -21,7 +21,7 @@ import numpy as np
|
||||||
ip_bytes = 4
|
ip_bytes = 4
|
||||||
ip_bits = ip_bytes * 8
|
ip_bits = ip_bytes * 8
|
||||||
num_ips = 1 << ip_bits
|
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):
|
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)
|
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():
|
def squish():
|
||||||
nonlocal density_data
|
nonlocal density_data
|
||||||
nonlocal possible_overlaps
|
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)
|
print("calculating density sum...", end = " ", flush = True)
|
||||||
density_data[:, :, 0, 0] += density_data[:, :, 0, 1]
|
density_data[:, :, 0, 0] += density_data[:, :, 0, 1]
|
||||||
density_data[:, :, 0, 0] += density_data[:, :, 1, 0]
|
density_data[:, :, 0, 0] += density_data[:, :, 1, 0]
|
||||||
|
@ -293,7 +293,7 @@ def make_tiles(coords_path: Path, input_path: Path, tiles_dir: Path, *,
|
||||||
def squish():
|
def squish():
|
||||||
nonlocal rtt_data
|
nonlocal rtt_data
|
||||||
print(f"sorting rtt values for median calculation...", end = " ", flush = True)
|
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_)
|
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
|
np.less(rtt_data[:, :, 0, 0], rtt_data[:, :, 0, 1], out = mask) # sort first row
|
||||||
rtt_data[mask, 0] = rtt_data[mask, 0, ::-1]
|
rtt_data[mask, 0] = rtt_data[mask, 0, ::-1]
|
||||||
|
@ -310,15 +310,15 @@ def make_tiles(coords_path: Path, input_path: Path, tiles_dir: Path, *,
|
||||||
print("calculating median rtt values...", end = " ", flush = True)
|
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
|
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
|
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, 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
|
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
|
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
|
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
|
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, 0] -= rtt_data[mask, 0, 1]
|
||||||
rtt_data[mask, 0, 1] //= 2
|
rtt_data[mask, 0, 0] >>= 1
|
||||||
rtt_data[mask, 0, 0] += rtt_data[mask, 0, 1] # take average of first two nums
|
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
|
# everything else (1 or 0 nums populated) don't need any modifications
|
||||||
print("done")
|
print("done")
|
||||||
|
@ -330,8 +330,6 @@ def make_tiles(coords_path: Path, input_path: Path, tiles_dir: Path, *,
|
||||||
for _ in range(skip_iters):
|
for _ in range(skip_iters):
|
||||||
squish()
|
squish()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def write_all_colormaps():
|
def write_all_colormaps():
|
||||||
if raws_path is not None:
|
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))
|
create_tiles(raws_path / variant_name, rtt_data.view(np.uint8).reshape(rtt_data.shape[0], rtt_data.shape[1], 4))
|
||||||
|
|
|
@ -230,7 +230,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiUrl = "https://ipapi.7circles.moe"
|
const apiUrl = "https://ipapi.7circles.moe"
|
||||||
const defaultVariant = "rtt"
|
const defaultVariant = "density"
|
||||||
const defaultColormap = "viridis"
|
const defaultColormap = "viridis"
|
||||||
const tileSize = 256
|
const tileSize = 256
|
||||||
const tilesDir = "assets/tiles"
|
const tilesDir = "assets/tiles"
|
||||||
|
|
Loading…
Reference in New Issue