| |
| """Audit: Location (Coordinate RV) dataset.""" |
|
|
| import sys |
| sys.path.insert(0, str(__import__('pathlib').Path(__file__).resolve().parent)) |
|
|
| from _common import * |
|
|
|
|
| def main(): |
| output_dir = setup_output_dir('location') |
| print_section('LOCATION DATASET AUDIT') |
| print(f'Audit started: {datetime.now()}') |
|
|
| df = load_parquet('location') |
|
|
| print_section('DATASET OVERVIEW') |
| df.info() |
|
|
| critical_fields = ['x_guess', 'y_guess', 'x_target', 'y_target', 'z_score', 'count'] |
| available = [f for f in critical_fields if f in df.columns] |
| print('\nCRITICAL FIELDS SUMMARY') |
| for field in available: |
| if df[field].dtype in ['int64', 'float64']: |
| print(f'\n{field}:') |
| print(df[field].describe()) |
|
|
| yearly_counts, gaps = standard_temporal_analysis(df, 'Location Dataset', output_dir) |
|
|
| |
| print_section('COORDINATE RANGE VALIDATION') |
| coord_cols = ['x_guess', 'y_guess', 'x_target', 'y_target'] |
| for col in coord_cols: |
| if col in df.columns: |
| valid = df[col].dropna() |
| out_of_range = valid[(valid < 0) | (valid > 299)] |
| print(f'{col}: min={valid.min()}, max={valid.max()}, out-of-range={len(out_of_range):,}') |
| if len(out_of_range) == 0: |
| print(f' PASS: All {col} values in range 0-299') |
| else: |
| print(f' FAIL: {len(out_of_range):,} values outside 0-299') |
|
|
| |
| print_section('Z-SCORE DISTRIBUTION') |
| if 'z_score' in df.columns: |
| z = df['z_score'].dropna() |
| print(f'Mean z-score: {z.mean():.4f} (expected ~0)') |
| print(f'Std z-score: {z.std():.4f} (expected ~1)') |
| print(f'Min: {z.min():.4f}') |
| print(f'Max: {z.max():.4f}') |
|
|
| plt.figure(figsize=(14, 5)) |
| z.hist(bins=100, color='steelblue', edgecolor='white', density=True) |
| x_range = np.linspace(z.min(), z.max(), 200) |
| plt.plot(x_range, stats.norm.pdf(x_range, 0, 1), 'r-', linewidth=2, label='Standard Normal') |
| plt.title('Z-Score Distribution vs Standard Normal', fontweight='bold') |
| plt.xlabel('Z-Score') |
| plt.ylabel('Density') |
| plt.legend() |
| plt.tight_layout() |
| save_fig(output_dir, 'z_score_distribution') |
|
|
| standard_missing_data_analysis(df, output_dir) |
| standard_audit_summary('Location Dataset', df, extra_lines=[ |
| f'Temporal Gaps >= 7 days: {len(gaps)}', |
| ]) |
|
|
|
|
| if __name__ == '__main__': |
| main() |
|
|