fix: 精确栅格化竞对信号
This commit is contained in:
@@ -1128,6 +1128,14 @@ def pixel_window_for_bounds(bounds, minx, maxy, pixel_width, pixel_height, width
|
||||
return row_start, row_stop, col_start, col_stop
|
||||
|
||||
|
||||
def pixel_center_mask_for_geometry(geometry, window, minx, maxy, pixel_width, pixel_height):
|
||||
row_start, row_stop, col_start, col_stop = window
|
||||
x_coordinates = minx + (np.arange(col_start, col_stop, dtype=np.float64) + 0.5) * pixel_width
|
||||
y_coordinates = maxy - (np.arange(row_start, row_stop, dtype=np.float64) + 0.5) * pixel_height
|
||||
x_grid, y_grid = np.meshgrid(x_coordinates, y_coordinates)
|
||||
return np.asarray(shapely.contains_xy(geometry, x_grid, y_grid), dtype=bool)
|
||||
|
||||
|
||||
def pixel_window_from_point(x, y, minx, maxy, pixel_width, pixel_height, width, height):
|
||||
col = int((x - minx) / pixel_width)
|
||||
row = int((maxy - y) / pixel_height)
|
||||
@@ -1698,10 +1706,20 @@ def export_market_grid_outputs(
|
||||
MOBILE_TOTAL_FIELD,
|
||||
MOBILE_WEAK_COVER_FIELD,
|
||||
)
|
||||
skipped_no_value = {field: 0 for field in raster_fields}
|
||||
painted_cells = {field: 0 for field in raster_fields}
|
||||
raster_cells = []
|
||||
user_count_records = {}
|
||||
competitor_signal_value_sum = np.zeros((height, width), dtype=np.float32)
|
||||
competitor_signal_value_weight = np.zeros((height, width), dtype=np.uint16)
|
||||
zero_total_mask = np.zeros((height, width), dtype=bool)
|
||||
competitor_signal_cells = 0
|
||||
zero_total_cells = 0
|
||||
exact_geometry_pixels = 0
|
||||
exclusion_counts = {
|
||||
"invalid_fields": 0,
|
||||
"mobile_weak_ratio": 0,
|
||||
"competitor_weak_ratio": 0,
|
||||
"invalid_rsrp": 0,
|
||||
"no_center_pixels": 0,
|
||||
}
|
||||
|
||||
fields = list(
|
||||
dict.fromkeys(
|
||||
@@ -1750,9 +1768,6 @@ def export_market_grid_outputs(
|
||||
for index, row in enumerate(batch_rows):
|
||||
values = dict(zip(fields, row[2:]))
|
||||
numeric_values = {field: to_float(values.get(field)) for field in raster_fields}
|
||||
for field, value in numeric_values.items():
|
||||
if value is None:
|
||||
skipped_no_value[field] += 1
|
||||
|
||||
if not valid_mask[index]:
|
||||
continue
|
||||
@@ -1784,23 +1799,6 @@ def export_market_grid_outputs(
|
||||
if window is None:
|
||||
continue
|
||||
|
||||
row_start, row_stop, col_start, col_stop = window
|
||||
for field, value in numeric_values.items():
|
||||
if value is not None:
|
||||
painted_cells[field] += 1
|
||||
raster_cells.append(
|
||||
(
|
||||
row_start,
|
||||
row_stop,
|
||||
col_start,
|
||||
col_stop,
|
||||
numeric_values[EXCELLENT_CELL_FIELD],
|
||||
numeric_values[RSRP_FIELD],
|
||||
numeric_values[WEAK_COVER_FIELD],
|
||||
numeric_values[MOBILE_TOTAL_FIELD],
|
||||
numeric_values[MOBILE_WEAK_COVER_FIELD],
|
||||
)
|
||||
)
|
||||
if user_count_path is not None:
|
||||
user_count_5g_clipped_rows += 1
|
||||
if not merge_user_count_record(
|
||||
@@ -1812,6 +1810,62 @@ def export_market_grid_outputs(
|
||||
prefer_geometry=True,
|
||||
):
|
||||
user_count_5g_invalid_grid_ids += 1
|
||||
|
||||
competitor_total = numeric_values[EXCELLENT_CELL_FIELD]
|
||||
competitor_rsrp = numeric_values[RSRP_FIELD]
|
||||
competitor_weak = numeric_values[WEAK_COVER_FIELD]
|
||||
mobile_total = numeric_values[MOBILE_TOTAL_FIELD]
|
||||
mobile_weak = numeric_values[MOBILE_WEAK_COVER_FIELD]
|
||||
exclusion_reason = competitor_signal_filter_reason(
|
||||
mobile_weak,
|
||||
mobile_total,
|
||||
competitor_weak,
|
||||
competitor_total,
|
||||
)
|
||||
if exclusion_reason is not None:
|
||||
exclusion_counts[exclusion_reason] += 1
|
||||
continue
|
||||
if competitor_total != 0 and (competitor_rsrp is None or competitor_rsrp > 0):
|
||||
exclusion_counts["invalid_rsrp"] += 1
|
||||
continue
|
||||
|
||||
signal_window = pixel_window_for_bounds(
|
||||
geometry_bounds[index],
|
||||
minx,
|
||||
maxy,
|
||||
pixel_width,
|
||||
pixel_height,
|
||||
width,
|
||||
height,
|
||||
)
|
||||
if signal_window is None:
|
||||
exclusion_counts["no_center_pixels"] += 1
|
||||
continue
|
||||
geometry_mask = pixel_center_mask_for_geometry(
|
||||
geometries[index],
|
||||
signal_window,
|
||||
minx,
|
||||
maxy,
|
||||
pixel_width,
|
||||
pixel_height,
|
||||
)
|
||||
geometry_pixel_count = int(np.count_nonzero(geometry_mask))
|
||||
if geometry_pixel_count == 0:
|
||||
exclusion_counts["no_center_pixels"] += 1
|
||||
continue
|
||||
|
||||
row_start, row_stop, col_start, col_stop = signal_window
|
||||
if competitor_total == 0:
|
||||
zero_total_view = zero_total_mask[row_start:row_stop, col_start:col_stop]
|
||||
zero_total_view |= geometry_mask
|
||||
zero_total_cells += 1
|
||||
else:
|
||||
value_sum_view = competitor_signal_value_sum[row_start:row_stop, col_start:col_stop]
|
||||
value_weight_view = competitor_signal_value_weight[row_start:row_stop, col_start:col_stop]
|
||||
value_sum_view[geometry_mask] += competitor_rsrp
|
||||
value_weight_view[geometry_mask] += 1
|
||||
competitor_signal_cells += 1
|
||||
exact_geometry_pixels += geometry_pixel_count
|
||||
finally:
|
||||
if csv_file is not None:
|
||||
csv_file.close()
|
||||
@@ -1861,43 +1915,6 @@ def export_market_grid_outputs(
|
||||
user_count_result.update(merged_user_count_metadata(user_count_records, source_stats))
|
||||
del user_count_state
|
||||
|
||||
competitor_signal_value_sum = np.zeros((height, width), dtype=np.float32)
|
||||
competitor_signal_value_weight = np.zeros((height, width), dtype=np.uint16)
|
||||
zero_total_mask = np.zeros((height, width), dtype=bool)
|
||||
competitor_signal_cells = 0
|
||||
zero_total_cells = 0
|
||||
exclusion_counts = {
|
||||
"invalid_fields": 0,
|
||||
"mobile_weak_ratio": 0,
|
||||
"competitor_weak_ratio": 0,
|
||||
"invalid_rsrp": 0,
|
||||
}
|
||||
for cell in raster_cells:
|
||||
competitor_total = cell[4]
|
||||
competitor_rsrp = cell[5]
|
||||
competitor_weak = cell[6]
|
||||
mobile_total = cell[7]
|
||||
mobile_weak = cell[8]
|
||||
exclusion_reason = competitor_signal_filter_reason(
|
||||
mobile_weak,
|
||||
mobile_total,
|
||||
competitor_weak,
|
||||
competitor_total,
|
||||
)
|
||||
if exclusion_reason is not None:
|
||||
exclusion_counts[exclusion_reason] += 1
|
||||
continue
|
||||
row_start, row_stop, col_start, col_stop = cell[:4]
|
||||
if competitor_total == 0:
|
||||
zero_total_mask[row_start:row_stop, col_start:col_stop] = True
|
||||
zero_total_cells += 1
|
||||
else:
|
||||
if competitor_rsrp is None or competitor_rsrp > 0:
|
||||
exclusion_counts["invalid_rsrp"] += 1
|
||||
continue
|
||||
competitor_signal_value_sum[row_start:row_stop, col_start:col_stop] += competitor_rsrp
|
||||
competitor_signal_value_weight[row_start:row_stop, col_start:col_stop] += 1
|
||||
competitor_signal_cells += 1
|
||||
competitor_signal_state = {
|
||||
"value_sum": competitor_signal_value_sum,
|
||||
"value_weight": competitor_signal_value_weight,
|
||||
@@ -1920,6 +1937,8 @@ def export_market_grid_outputs(
|
||||
competitor_signal_result.update({
|
||||
"data_source": str(GRID_5G_GPKG),
|
||||
"uses_merged_user_count": False,
|
||||
"geometry_rasterization": "pixel_center_inside_polygon",
|
||||
"exact_geometry_pixels": exact_geometry_pixels,
|
||||
"mobile_weak_ratio_formula": f"{MOBILE_WEAK_COVER_FIELD} / {MOBILE_TOTAL_FIELD} * 100",
|
||||
"mobile_weak_ratio_operator": "<",
|
||||
"mobile_weak_ratio_threshold": COMPETITOR_SIGNAL_MOBILE_WEAK_RATIO_MAX,
|
||||
|
||||
Reference in New Issue
Block a user