revert: 撤销用户量热力图深浅规则

This commit is contained in:
RBP15P
2026-07-16 10:44:07 +08:00
parent 461ecbfd32
commit 328022c910
2 changed files with 8 additions and 29 deletions
+7 -27
View File
@@ -48,8 +48,6 @@ EXCELLENT_COLORS = (
(0, 112, 255), # 偏低值,蓝色。
(0, 176, 80), # 低值端,绿色。
)
EXCELLENT_DARKEN_FACTOR = 0.65 # 四等分区间内高值颜色加深比例,数值越小高值端越深。
EXCELLENT_LIGHTEN_RATIO = 0.65 # 四等分区间内低值颜色变浅比例,数值越大低值端越浅。
PIXEL_WIDTH = None # 输出像元宽度;None 表示自动按 Grid 单元宽度估算。
PIXEL_HEIGHT = None # 输出像元高度;None 表示自动按 Grid 单元高度估算。
SCALE = 5.0 # 分辨率倍数;2.0 表示像元宽高减半,放大查看更清晰。
@@ -534,14 +532,6 @@ def percentile_thresholds_from_values(values, percent_steps):
return thresholds
def darken_color(color):
return tuple(int(round(channel * EXCELLENT_DARKEN_FACTOR)) for channel in color)
def lighten_color(color):
return tuple(int(round(channel + (255 - channel) * EXCELLENT_LIGHTEN_RATIO)) for channel in color)
def ranked_pixel_rgb_for_values(values, data_mask):
result = np.zeros((*values.shape, 3), dtype=np.uint8)
valid_positions = np.flatnonzero(data_mask.ravel())
@@ -553,18 +543,10 @@ def ranked_pixel_rgb_for_values(values, data_mask):
sorted_positions = valid_positions[order]
rank_groups = np.array_split(sorted_positions, len(EXCELLENT_COLORS))
flat_result = result.reshape(-1, 3)
flat_values = values.ravel()
rank_counts = []
for color, group in zip(EXCELLENT_COLORS, rank_groups):
if group.size:
group_values = flat_values[group]
group_min = float(np.min(group_values))
group_max = float(np.max(group_values))
if group_max > group_min:
ratio = (group_values - group_min) / (group_max - group_min)
else:
ratio = np.full(group.size, 0.5, dtype=np.float32)
flat_result[group] = interpolate_color(lighten_color(color), darken_color(color), ratio)
flat_result[group] = color
rank_counts.append(int(group.size))
thresholds = percentile_thresholds_from_values(valid_values, EXCELLENT_PERCENT_STEPS)
@@ -930,12 +912,11 @@ def write_excellent_heatmap_legend(output_dir, field):
legend_path = output_dir / "excellent_heatmap_legend.csv"
with legend_path.open("w", newline="", encoding="utf-8-sig") as file:
writer = csv.writer(file)
writer.writerow(["field", "rank_range", "value_position", "red", "green", "blue", "alpha", "meaning"])
writer.writerow(["field", "rank_range", "red", "green", "blue", "alpha", "meaning"])
rank_ranges = ("top_25_percent", "25_to_50_percent", "50_to_75_percent", "bottom_25_percent")
for rank_range, color in zip(rank_ranges, EXCELLENT_COLORS):
writer.writerow([field, rank_range, "high_value", *darken_color(color), HEATMAP_ALPHA, "darker for larger value"])
writer.writerow([field, rank_range, "low_value", *lighten_color(color), HEATMAP_ALPHA, "lighter for smaller value"])
writer.writerow([field, "nodata", "", 0, 0, 0, 0, "transparent no data"])
writer.writerow([field, rank_range, *color, HEATMAP_ALPHA, "ranked-pixel quartile"])
writer.writerow([field, "nodata", 0, 0, 0, 0, "transparent no data"])
return legend_path
@@ -943,12 +924,11 @@ def write_weak_cover_heatmap_legend(output_dir, field):
legend_path = output_dir / "weak_cover_heatmap_legend.csv"
with legend_path.open("w", newline="", encoding="utf-8-sig") as file:
writer = csv.writer(file)
writer.writerow(["field", "rank_range", "value_position", "red", "green", "blue", "alpha", "meaning"])
writer.writerow(["field", "rank_range", "red", "green", "blue", "alpha", "meaning"])
rank_ranges = ("top_25_percent", "25_to_50_percent", "50_to_75_percent", "bottom_25_percent")
for rank_range, color in zip(rank_ranges, EXCELLENT_COLORS):
writer.writerow([field, rank_range, "high_value", *darken_color(color), HEATMAP_ALPHA, "darker for larger value"])
writer.writerow([field, rank_range, "low_value", *lighten_color(color), HEATMAP_ALPHA, "lighter for smaller value"])
writer.writerow([field, "nodata", "", 0, 0, 0, 0, "transparent no data"])
writer.writerow([field, rank_range, *color, HEATMAP_ALPHA, "ranked-pixel quartile"])
writer.writerow([field, "nodata", 0, 0, 0, 0, "transparent no data"])
return legend_path