views-datafactory 1.18.0__tar.gz → 1.22.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/PKG-INFO +30 -16
  2. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/README.md +29 -15
  3. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/pyproject.toml +1 -1
  4. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_compilation/ARCHITECTURE.md +1 -0
  5. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_compilation/compilation_config.py +52 -0
  6. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_compilation/grid_compilation.py +125 -17
  7. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_compilation/output.py +27 -1
  8. views_datafactory-1.22.0/src/datafactory_compilation/preflight.py +180 -0
  9. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_provenance/__init__.py +7 -1
  10. views_datafactory-1.22.0/src/datafactory_provenance/build_identity.py +176 -0
  11. views_datafactory-1.22.0/src/datafactory_provenance/constants.py +24 -0
  12. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_query/defaults.py +0 -4
  13. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_query/regions.py +4 -2
  14. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_viewpoint/ARCHITECTURE.md +1 -0
  15. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_viewpoint/builders/acled_v1.py +88 -0
  16. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_viewpoint/builders/ucdp_v1.py +220 -7
  17. views_datafactory-1.22.0/src/datafactory_viewpoint/declaration.py +31 -0
  18. views_datafactory-1.18.0/src/datafactory_compilation/preflight.py +0 -61
  19. views_datafactory-1.18.0/src/datafactory_provenance/constants.py +0 -3
  20. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/.gitignore +0 -0
  21. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/LICENSE +0 -0
  22. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_adapters/ARCHITECTURE.md +0 -0
  23. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_adapters/__init__.py +0 -0
  24. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_adapters/_conservation.py +0 -0
  25. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_adapters/_flatten.py +0 -0
  26. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_adapters/_reconciliation.py +0 -0
  27. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_adapters/_validation.py +0 -0
  28. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_adapters/feature_frame.py +0 -0
  29. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_adapters/grid_from_feature_frame.py +0 -0
  30. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_adapters/grid_to_country_month.py +0 -0
  31. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_adapters/grid_to_dataframe.py +0 -0
  32. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_adapters/grid_to_feature_frame.py +0 -0
  33. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_compilation/__init__.py +0 -0
  34. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_compilation/aggregation.py +0 -0
  35. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_compilation/conservation.py +0 -0
  36. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_compilation/pregridded_compilation.py +0 -0
  37. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_consolidation/ARCHITECTURE.md +0 -0
  38. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_consolidation/__init__.py +0 -0
  39. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_consolidation/consolidation_result.py +0 -0
  40. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_consolidation/consolidators/__init__.py +0 -0
  41. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_consolidation/consolidators/acled.py +0 -0
  42. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_consolidation/consolidators/ucdp.py +0 -0
  43. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_consolidation/event_store.py +0 -0
  44. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_consolidation/tagging.py +0 -0
  45. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_harvester/ARCHITECTURE.md +0 -0
  46. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_harvester/__init__.py +0 -0
  47. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_harvester/event_validation.py +0 -0
  48. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_harvester/harvest_runner.py +0 -0
  49. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_harvester/pipeline_runner.py +0 -0
  50. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_harvester/snapshot_storage.py +0 -0
  51. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_harvester/sources/__init__.py +0 -0
  52. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_harvester/sources/_ucdp_common.py +0 -0
  53. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_harvester/sources/acled.py +0 -0
  54. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_harvester/sources/gaul_admin.py +0 -0
  55. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_harvester/sources/ghsbuilts.py +0 -0
  56. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_harvester/sources/ghspop.py +0 -0
  57. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_harvester/sources/priogrid_static.py +0 -0
  58. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_harvester/sources/shdi.py +0 -0
  59. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_harvester/sources/ucdp_annual.py +0 -0
  60. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_harvester/sources/ucdp_candidate.py +0 -0
  61. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_harvester/sources/ucdp_dot9.py +0 -0
  62. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_harvester/sources/vdem.py +0 -0
  63. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_harvester/validation.py +0 -0
  64. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_http/__init__.py +0 -0
  65. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_http/retry.py +0 -0
  66. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_priogrid/ARCHITECTURE.md +0 -0
  67. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_priogrid/__init__.py +0 -0
  68. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_priogrid/cell_generator.py +0 -0
  69. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_priogrid/grid_config.py +0 -0
  70. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_priogrid/land_mask.py +0 -0
  71. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_priogrid/parity_validation.py +0 -0
  72. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_priogrid/shapefile_harvester.py +0 -0
  73. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_priogrid/shapefile_reader.py +0 -0
  74. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_priogrid/spatiotemporal.py +0 -0
  75. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_priogrid/temporal_config.py +0 -0
  76. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_priogrid/temporal_generator.py +0 -0
  77. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_provenance/ARCHITECTURE.md +0 -0
  78. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_provenance/digests_and_ledgers.py +0 -0
  79. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_provenance/health.py +0 -0
  80. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_provenance/pipeline_lock.py +0 -0
  81. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_provenance/registry.py +0 -0
  82. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_provenance/skip.py +0 -0
  83. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_provenance/source_registry.py +0 -0
  84. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_query/ARCHITECTURE.md +0 -0
  85. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_query/__init__.py +0 -0
  86. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_query/africa_me_gaul_pgids.json +0 -0
  87. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_query/africa_me_legacy_pgids.json +0 -0
  88. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_query/backends_npy.py +0 -0
  89. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_query/backends_zarr.py +0 -0
  90. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_query/coverage.py +0 -0
  91. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_query/dataset.py +0 -0
  92. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_query/land_gaul_pgids.json +0 -0
  93. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_query/land_pgids.json +0 -0
  94. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_query/output_format.py +0 -0
  95. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_query/temporal.py +0 -0
  96. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_viewpoint/__init__.py +0 -0
  97. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_viewpoint/apportionment.py +0 -0
  98. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_viewpoint/builders/__init__.py +0 -0
  99. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_viewpoint/builders/ghsbuilts_v1.py +0 -0
  100. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_viewpoint/builders/ghspop_v1.py +0 -0
  101. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_viewpoint/builders/shdi_v1.py +0 -0
  102. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_viewpoint/builders/vdem_v1.py +0 -0
  103. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_viewpoint/profiles.py +0 -0
  104. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_viewpoint/raster_io.py +0 -0
  105. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_viewpoint/spatial_distribution.py +0 -0
  106. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_viewpoint/spatial_weights.py +0 -0
  107. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_viewpoint/survivorship.py +0 -0
  108. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_viewpoint/temporal.py +0 -0
  109. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_viewpoint/temporal_distribution.py +0 -0
  110. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_viewpoint/temporal_weights.py +0 -0
  111. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_viewpoint/viewpoint_config.py +0 -0
  112. {views_datafactory-1.18.0 → views_datafactory-1.22.0}/src/datafactory_viewpoint/viewpoint_result.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: views-datafactory
3
- Version: 1.18.0
3
+ Version: 1.22.0
4
4
  Summary: Data factory for the VIEWS conflict forecasting platform — provenance, harvesting, consolidation, viewpoint construction, compilation, and assembly.
5
5
  Project-URL: Homepage, https://github.com/views-platform/views-datafactory
6
6
  Project-URL: Repository, https://github.com/views-platform/views-datafactory
@@ -207,7 +207,7 @@ Layers are decoupled by the filesystem, not by imports. Each layer computes SHA-
207
207
  |----------|--------|--------|-----------|--------|---------------------|
208
208
  | Harvest → Consolidation | `harvest_ucdp.py` | `consolidate_ucdp.py` | `data/raw/ucdp_*/` | Parquet | `id`, `date_start`, `date_end`, `best`, `low`, `high`, `type_of_violence` |
209
209
  | Consolidation → Viewpoint | `consolidate_ucdp.py` | `build_viewpoint.py` | `data/consolidated/` | Parquet | All harvest columns + `_source_type`, `_source_version`, `_ingested_at` |
210
- | Viewpoint → Compilation | `build_viewpoint.py` | `compile_grid.py` | `data/viewpoint/*.parquet` | Parquet | `latitude`, `longitude`, `date_month`, `best`, `type_of_violence` |
210
+ | Viewpoint → Compilation | `build_viewpoint.py` | `compile_grid.py` | `data/viewpoint/*.parquet` | Parquet | `priogrid_gid`, `date_month`, `best`, `type_of_violence`, and `latitude`, `longitude` as the fallback for rows declaring no cell |
211
211
  | Compilation → Assembly | `compile_grid.py` | `assemble_grid.py` | `data/compiled/` | npy `[T,H,W,C]` | `grid.npy` + `pgids.npy` + `time_steps.npy` + `feature_names.json` |
212
212
  | Assembly → Query/Consumer | `assemble_grid.py` | `load_dataset()` | `data/assembled/` or `.zarr` | npy or zarr | `grid.npy [T,H,W,C]` with same sidecars |
213
213
 
@@ -340,7 +340,6 @@ views-datafactory/
340
340
  │ ├── run_shdi_pipeline.py SHDI end-to-end pipeline
341
341
  │ ├── assemble_grid.py UCDP + ACLED + GHS-POP + GHS-BUILT-S + V-Dem + SHDI + static + admin
342
342
  │ ├── generate_consumer_data.py Factory → VIEWSER parquet for training
343
- │ ├── export_dataframe.py Grid → DataFrame export
344
343
  │ ├── export_zarr.py Grid → zarr store (HTTP-servable)
345
344
  │ ├── preflight.py Pre-pipeline disk + env checks
346
345
  │ ├── check_health.py System health check
@@ -363,21 +362,37 @@ views-datafactory/
363
362
 
364
363
  ---
365
364
 
366
- ## Installation
365
+ ## Reading our data
367
366
 
368
- **As a consumer** (you want `load_dataset()` and the adapters):
367
+ **You do not need to install anything.** This repository is a program that
368
+ builds a dataset and publishes it as files over HTTP. The files are the
369
+ interface (ADR-054). Fetch what you need; install nothing from us.
369
370
 
370
- ```bash
371
- pip install views-datafactory # FeatureFrame output
372
- pip install "views-datafactory[pandas]" # + DataFrame / country-month output
373
- ```
371
+ Everything a consumer needs is served:
372
+
373
+ | What | Where |
374
+ |---|---|
375
+ | The grid | `http://204.168.219.108/grid.zarr` |
376
+ | What each code means, which cells are in which region | `http://204.168.219.108/reference/index.json` |
377
+ | Country-month totals, over the land cells that have a country | `http://204.168.219.108/reference/country_month.csv` |
378
+ | Which release built what you read | the `build_*` keys in `grid.zarr/.zattrs` |
379
+
380
+ `reference/index.json` names every other reference file and states three
381
+ things about country coding that surprise people — see it before trusting a
382
+ country total.
383
+
384
+ Reading the grid needs an `~/.netrc` entry for the data server; ask the data
385
+ factory administrator. The reference files need the same.
386
+
387
+ > **The wheel on PyPI is what the operator installs on the server to run the
388
+ > pipeline.** It is not a consumer offer. It bundles nine packages and pulls
389
+ > in matplotlib, shapely, tifffile, imagecodecs, xarray and zarr — a large
390
+ > dependency for reading files, which is why ADR-050 and ADR-054 both say
391
+ > consumers should not be asked to carry it.
374
392
 
375
- pandas is an **optional extra**, because `output_format="dataframe"` and
376
- `"country_month"` are the only things that need it — importing the package
377
- never loads pandas (guarded by `tests/test_import_purity.py`). Across
378
- views_platform pandas is being phased out in favour of views-frames, and a
379
- library that *requires* it forces every consumer to negotiate a version they
380
- may not want.
393
+ Some consumers still import `datafactory_query` today. That is being retired;
394
+ the plan and its dates are in `reports/roadmap_clean_enough_to_copy.md`, and
395
+ the tracking issue is #644.
381
396
 
382
397
  **As a developer** (you want the tests, scripts, and docs):
383
398
 
@@ -439,7 +454,6 @@ uv run python scripts/visualize_audit.py # 15 audit plots → reports/
439
454
 
440
455
  # Export for downstream consumers
441
456
  uv run python scripts/export_zarr.py # grid → zarr store (HTTP-servable)
442
- uv run python scripts/export_dataframe.py # grid → DataFrame CSV
443
457
  ```
444
458
 
445
459
  ```python
@@ -169,7 +169,7 @@ Layers are decoupled by the filesystem, not by imports. Each layer computes SHA-
169
169
  |----------|--------|--------|-----------|--------|---------------------|
170
170
  | Harvest → Consolidation | `harvest_ucdp.py` | `consolidate_ucdp.py` | `data/raw/ucdp_*/` | Parquet | `id`, `date_start`, `date_end`, `best`, `low`, `high`, `type_of_violence` |
171
171
  | Consolidation → Viewpoint | `consolidate_ucdp.py` | `build_viewpoint.py` | `data/consolidated/` | Parquet | All harvest columns + `_source_type`, `_source_version`, `_ingested_at` |
172
- | Viewpoint → Compilation | `build_viewpoint.py` | `compile_grid.py` | `data/viewpoint/*.parquet` | Parquet | `latitude`, `longitude`, `date_month`, `best`, `type_of_violence` |
172
+ | Viewpoint → Compilation | `build_viewpoint.py` | `compile_grid.py` | `data/viewpoint/*.parquet` | Parquet | `priogrid_gid`, `date_month`, `best`, `type_of_violence`, and `latitude`, `longitude` as the fallback for rows declaring no cell |
173
173
  | Compilation → Assembly | `compile_grid.py` | `assemble_grid.py` | `data/compiled/` | npy `[T,H,W,C]` | `grid.npy` + `pgids.npy` + `time_steps.npy` + `feature_names.json` |
174
174
  | Assembly → Query/Consumer | `assemble_grid.py` | `load_dataset()` | `data/assembled/` or `.zarr` | npy or zarr | `grid.npy [T,H,W,C]` with same sidecars |
175
175
 
@@ -302,7 +302,6 @@ views-datafactory/
302
302
  │ ├── run_shdi_pipeline.py SHDI end-to-end pipeline
303
303
  │ ├── assemble_grid.py UCDP + ACLED + GHS-POP + GHS-BUILT-S + V-Dem + SHDI + static + admin
304
304
  │ ├── generate_consumer_data.py Factory → VIEWSER parquet for training
305
- │ ├── export_dataframe.py Grid → DataFrame export
306
305
  │ ├── export_zarr.py Grid → zarr store (HTTP-servable)
307
306
  │ ├── preflight.py Pre-pipeline disk + env checks
308
307
  │ ├── check_health.py System health check
@@ -325,21 +324,37 @@ views-datafactory/
325
324
 
326
325
  ---
327
326
 
328
- ## Installation
327
+ ## Reading our data
329
328
 
330
- **As a consumer** (you want `load_dataset()` and the adapters):
329
+ **You do not need to install anything.** This repository is a program that
330
+ builds a dataset and publishes it as files over HTTP. The files are the
331
+ interface (ADR-054). Fetch what you need; install nothing from us.
331
332
 
332
- ```bash
333
- pip install views-datafactory # FeatureFrame output
334
- pip install "views-datafactory[pandas]" # + DataFrame / country-month output
335
- ```
333
+ Everything a consumer needs is served:
334
+
335
+ | What | Where |
336
+ |---|---|
337
+ | The grid | `http://204.168.219.108/grid.zarr` |
338
+ | What each code means, which cells are in which region | `http://204.168.219.108/reference/index.json` |
339
+ | Country-month totals, over the land cells that have a country | `http://204.168.219.108/reference/country_month.csv` |
340
+ | Which release built what you read | the `build_*` keys in `grid.zarr/.zattrs` |
341
+
342
+ `reference/index.json` names every other reference file and states three
343
+ things about country coding that surprise people — see it before trusting a
344
+ country total.
345
+
346
+ Reading the grid needs an `~/.netrc` entry for the data server; ask the data
347
+ factory administrator. The reference files need the same.
348
+
349
+ > **The wheel on PyPI is what the operator installs on the server to run the
350
+ > pipeline.** It is not a consumer offer. It bundles nine packages and pulls
351
+ > in matplotlib, shapely, tifffile, imagecodecs, xarray and zarr — a large
352
+ > dependency for reading files, which is why ADR-050 and ADR-054 both say
353
+ > consumers should not be asked to carry it.
336
354
 
337
- pandas is an **optional extra**, because `output_format="dataframe"` and
338
- `"country_month"` are the only things that need it — importing the package
339
- never loads pandas (guarded by `tests/test_import_purity.py`). Across
340
- views_platform pandas is being phased out in favour of views-frames, and a
341
- library that *requires* it forces every consumer to negotiate a version they
342
- may not want.
355
+ Some consumers still import `datafactory_query` today. That is being retired;
356
+ the plan and its dates are in `reports/roadmap_clean_enough_to_copy.md`, and
357
+ the tracking issue is #644.
343
358
 
344
359
  **As a developer** (you want the tests, scripts, and docs):
345
360
 
@@ -401,7 +416,6 @@ uv run python scripts/visualize_audit.py # 15 audit plots → reports/
401
416
 
402
417
  # Export for downstream consumers
403
418
  uv run python scripts/export_zarr.py # grid → zarr store (HTTP-servable)
404
- uv run python scripts/export_dataframe.py # grid → DataFrame CSV
405
419
  ```
406
420
 
407
421
  ```python
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "views-datafactory"
3
- version = "1.18.0"
3
+ version = "1.22.0"
4
4
  description = "Data factory for the VIEWS conflict forecasting platform — provenance, harvesting, consolidation, viewpoint construction, compilation, and assembly."
5
5
  authors = [
6
6
  { name = "Simon Polichinel von der Maase", email = "simmaa@prio.org" },
@@ -55,6 +55,7 @@ datafactory_compilation/
55
55
  - **Source digest computed:** SHA-256 of source file bytes computed and recorded in provenance (not cross-checked against an existing ledger -- the compiler records, it does not verify)
56
56
  - **Feature list declared:** Features come from CompilationConfig, never inferred from Parquet columns (ADR-003)
57
57
  - **Provenance entry:** Written for every compilation, linking source digest + output digest
58
+ - **The source's declaration is carried, not interpreted:** If the source parquet declares what shaped it (a viewpoint does, a raw snapshot does not), `compile_grid` copies that declaration unchanged into `provenance.json` under `viewpoint`, beside the digest of the file it came from. Compilation does not read, check or act on its contents.
58
59
  - **Column mapping is source-agnostic:** The compiler reads lat/lon/date columns declared in config, not hardcoded field names. The aggregation field is configurable via `FeatureSpec.value_field` (default `"best"`).
59
60
  - **All error paths log before raising** (ADR-008)
60
61
 
@@ -64,8 +64,60 @@ class CompilationConfig:
64
64
  # Column mapping (source Parquet field names)
65
65
  lat_field: str = "latitude"
66
66
  lon_field: str = "longitude"
67
+ #: Column holding the month each row belongs to.
68
+ #:
69
+ #: The default is a RAW field, and that is a hazard rather than a
70
+ #: convenience. The temporal allocator writes its decision to
71
+ #: ``date_month`` and leaves ``date_start``/``date_end`` untouched,
72
+ #: so a caller who takes this default on an allocated source
73
+ #: collapses every distributed month back onto the event's start
74
+ #: month -- the temporal twin of the spatial defect that cost 26.49%
75
+ #: of UCDP fatality mass its placement. ``scripts/compile_grid.py``
76
+ #: refuses to run in that configuration; see ``_reject_ignored_allocation``
77
+ #: there.
78
+ #:
79
+ #: **This should be a required keyword argument, and is not, for one
80
+ #: reason:** ``CompilationConfig`` is exported in
81
+ #: ``datafactory_compilation.__all__`` and ships in the wheel, so
82
+ #: removing the default is a breaking change for any external caller
83
+ #: and belongs in a MAJOR release rather than a patch. Registered as
84
+ #: such. An auto-detecting default -- ``None`` meaning "use
85
+ #: ``date_month`` if the source has one" -- was considered and
86
+ #: rejected: inferring decision-relevant semantics is what ADR-003
87
+ #: forbids, and this defect is not worth fixing with a second
88
+ #: instance of its own cause.
67
89
  date_field: str = "date_start"
68
90
 
91
+ #: Column holding a cell the UPSTREAM STAGE HAS ALREADY DECIDED.
92
+ #:
93
+ #: When set, a row's value in this column wins over
94
+ #: ``lat_field``/``lon_field``; the coordinates are the fallback for
95
+ #: rows where it is null or out of range. That ordering is
96
+ #: ADR-015's, stated in its section "priogrid_gid vs. Computed
97
+ #: Cell": *"These can disagree (border cells, precision issues) …
98
+ #: Viewpoint v1 should prefer priogrid_gid to match production."*
99
+ #:
100
+ #: It was declared there in June 2026 and never implemented. The
101
+ #: spatial allocator records its decision by rewriting
102
+ #: ``priogrid_gid`` and leaves the coordinates at the source
103
+ #: centroid, so re-deriving the cell from the coordinates discarded
104
+ #: every allocation: 1,128,236 deaths — 26.49% of UCDP fatality
105
+ #: mass — were delivered to a cell other than the one chosen for
106
+ #: them, with totals conserved, so no conservation check could see
107
+ #: it. ``where_prec=6`` events collapsed from 6,896 chosen cells
108
+ #: into 91 delivered ones.
109
+ #:
110
+ #: ``None`` by default, which is the pre-existing behaviour, because
111
+ #: a decided cell is not something every source has. ACLED events
112
+ #: are single-day points that no stage relocates
113
+ #: (``acled_v1`` reports ``n_spatially_distributed=0``), so for
114
+ #: ACLED the coordinates *are* the authority and this stays unset.
115
+ #: ``PregriddedCompilationConfig.pgid_field`` is the same idea for
116
+ #: sources that are gridded before they arrive; this is its
117
+ #: event-shaped twin, and the asymmetry between the two is what let
118
+ #: the defect exist.
119
+ pgid_field: str | None = None
120
+
69
121
  # Output array parameters
70
122
  output_dtype: str = "float32"
71
123
  fill_value: float = 0.0
@@ -7,6 +7,7 @@ sidecar coordinate files and provenance.
7
7
 
8
8
  from __future__ import annotations
9
9
 
10
+ import json
10
11
  import logging
11
12
  import os
12
13
  import re
@@ -28,7 +29,10 @@ from datafactory_compilation.output import write_compilation_output
28
29
  from datafactory_compilation.preflight import check_disk_space
29
30
  from datafactory_priogrid.cell_generator import generate_grid
30
31
  from datafactory_priogrid.temporal_generator import generate_time_steps
31
- from datafactory_provenance import compute_file_digest
32
+ from datafactory_provenance import (
33
+ VIEWPOINT_DECLARATION_KEY,
34
+ compute_file_digest,
35
+ )
32
36
 
33
37
  logger = logging.getLogger(__name__)
34
38
 
@@ -40,6 +44,13 @@ _DATE_RE = re.compile(r"^\d{4}-\d{2}-\d{2}$")
40
44
  def _required_columns(config: CompilationConfig) -> set[str]:
41
45
  """Derive the minimal set of Parquet columns needed for compilation."""
42
46
  cols = {config.lat_field, config.lon_field, config.date_field}
47
+ # Without this the pgid_field branch in _place_events reads a column
48
+ # that was never loaded, so it falls back to the coordinates on every
49
+ # row and the fix is inert while looking present. That is its own
50
+ # mutation drill: reverting this line alone must turn the delivery
51
+ # tests red.
52
+ if config.pgid_field:
53
+ cols.add(config.pgid_field)
43
54
  for feat in config.features:
44
55
  if feat.filter:
45
56
  cols.update(feat.filter.keys())
@@ -105,32 +116,72 @@ def _place_events(
105
116
  lats = table[config.lat_field].to_pylist()
106
117
  lons = table[config.lon_field].to_pylist()
107
118
  dates = table[config.date_field].to_pylist()
119
+ declared = (
120
+ table[config.pgid_field].to_pylist()
121
+ if config.pgid_field
122
+ else None
123
+ )
108
124
 
109
125
  # Phase 1: compute bin assignments (row_index → bin key)
110
126
  row_bins: dict[int, tuple[int, int]] = {}
111
127
  n_skipped_spatial = 0
112
128
  n_skipped_temporal = 0
129
+ n_declared_cell = 0
130
+ n_declared_absent = 0
131
+ n_declared_invalid = 0
113
132
 
114
133
  for i in range(n_rows):
115
134
  lat, lon, date_str = lats[i], lons[i], dates[i]
116
135
 
117
- if lat is None or lon is None:
118
- n_skipped_spatial += 1
119
- continue
120
-
121
- try:
122
- pgid = int(
123
- latlon_to_pgid(
124
- float(lat), float(lon), config.grid_config
136
+ # A cell an upstream stage decided beats one derived from
137
+ # coordinates the upstream stage did not update (ADR-015). The
138
+ # fallback is for rows that carry no decision, not for rows
139
+ # whose decision we dislike -- an out-of-range declared cell is
140
+ # a data error, so it is counted rather than clamped. Invariant
141
+ # 2 of ADR-024 clamps an out-of-bounds *coordinate* to the
142
+ # nearest valid cell; that leniency is not extended here.
143
+ pgid: int | None = None
144
+ if declared is not None:
145
+ raw = declared[i]
146
+ if raw is None:
147
+ # No decision was made for this row. This is the case
148
+ # ADR-015:66 describes, and falling back is correct.
149
+ n_declared_absent += 1
150
+ else:
151
+ candidate: int | None
152
+ try:
153
+ candidate = int(raw)
154
+ except (ValueError, TypeError):
155
+ candidate = None
156
+ if candidate is not None and 1 <= candidate <= n_cells:
157
+ pgid = candidate
158
+ n_declared_cell += 1
159
+ else:
160
+ # A decision was made and it is unusable: not an
161
+ # integer, or outside [1, n_cells]. Counted apart
162
+ # from the absent case because the two need
163
+ # different responses -- one is normal, the other
164
+ # means the upstream stage wrote something wrong.
165
+ n_declared_invalid += 1
166
+
167
+ if pgid is None:
168
+ if lat is None or lon is None:
169
+ n_skipped_spatial += 1
170
+ continue
171
+
172
+ try:
173
+ pgid = int(
174
+ latlon_to_pgid(
175
+ float(lat), float(lon), config.grid_config
176
+ )
125
177
  )
126
- )
127
- except (ValueError, TypeError):
128
- n_skipped_spatial += 1
129
- continue
178
+ except (ValueError, TypeError):
179
+ n_skipped_spatial += 1
180
+ continue
130
181
 
131
- if pgid < 1 or pgid > n_cells:
132
- n_skipped_spatial += 1
133
- continue
182
+ if pgid < 1 or pgid > n_cells:
183
+ n_skipped_spatial += 1
184
+ continue
134
185
 
135
186
  if not isinstance(date_str, str):
136
187
  n_skipped_temporal += 1
@@ -166,6 +217,36 @@ def _place_events(
166
217
  "Skipped %d events: outside temporal range",
167
218
  n_skipped_temporal,
168
219
  )
220
+ if config.pgid_field:
221
+ logger.info(
222
+ "Placement authority '%s': %d rows used the declared cell, "
223
+ "%d had none, %d were unusable",
224
+ config.pgid_field,
225
+ n_declared_cell,
226
+ n_declared_absent,
227
+ n_declared_invalid,
228
+ )
229
+ # Said out loud because ADR-003 forbids an implicit fallback for
230
+ # decision-relevant semantics.
231
+ #
232
+ # ANY unusable value is reported, not a majority of them. The
233
+ # first version warned only when fallbacks outnumbered uses,
234
+ # which left a source with 49% corrupt declared cells silent --
235
+ # and an upstream stage that writes one bad cell is a stage
236
+ # that can write a million. There is no benign rate for this:
237
+ # the allocator either decided a placeable cell or it did not.
238
+ if n_declared_invalid:
239
+ logger.warning(
240
+ "Placement authority '%s' was unusable on %d of %d "
241
+ "rows -- not an integer, or outside [1, %d]. Those "
242
+ "rows were placed from their coordinates instead, "
243
+ "which discards whatever the upstream stage intended "
244
+ "for them.",
245
+ config.pgid_field,
246
+ n_declared_invalid,
247
+ n_rows,
248
+ n_cells,
249
+ )
169
250
 
170
251
  # Phase 2: extract columns as numpy arrays, build row-index bins
171
252
  if not row_bins:
@@ -226,7 +307,29 @@ def compile_grid(config: CompilationConfig) -> Path:
226
307
 
227
308
  # Read only the columns needed for placement + aggregation
228
309
  needed_cols = _required_columns(config)
229
- available_cols = set(pq.read_schema(config.source_path).names)
310
+ source_schema = pq.read_schema(config.source_path)
311
+ available_cols = set(source_schema.names)
312
+
313
+ # What the source says shaped it, read from the same file whose digest
314
+ # was just taken — so it cannot describe some other parquet. Absent on
315
+ # a source no viewpoint built, such as a raw snapshot (#676).
316
+ _declared = (source_schema.metadata or {}).get(
317
+ VIEWPOINT_DECLARATION_KEY,
318
+ )
319
+ viewpoint_declaration = None
320
+ if _declared is not None:
321
+ try:
322
+ viewpoint_declaration = json.loads(_declared)
323
+ except json.JSONDecodeError as exc:
324
+ viewpoint_declaration = exc
325
+ if not isinstance(viewpoint_declaration, dict):
326
+ err_msg = (
327
+ f"{config.source_path} carries a viewpoint declaration that "
328
+ f"is not a JSON object; it cannot be carried towards the "
329
+ f"published store. Rebuild the viewpoint."
330
+ )
331
+ logger.error(err_msg)
332
+ raise ValueError(err_msg)
230
333
  missing_cols = needed_cols - available_cols
231
334
  if missing_cols:
232
335
  err_msg = (
@@ -335,6 +438,11 @@ def compile_grid(config: CompilationConfig) -> Path:
335
438
  dataset_id=DATASET_ID,
336
439
  source_path=config.source_path,
337
440
  source_digest=source_digest,
441
+ viewpoint=viewpoint_declaration,
442
+ placement={
443
+ "pgid_field": config.pgid_field,
444
+ "date_field": config.date_field,
445
+ },
338
446
  )
339
447
 
340
448
  logger.info(
@@ -33,12 +33,34 @@ def write_compilation_output(
33
33
  n_placed: int | None = None,
34
34
  n_skipped_spatial: int | None = None,
35
35
  n_skipped_temporal: int | None = None,
36
+ placement: dict[str, Any] | None = None,
37
+ viewpoint: dict[str, Any] | None = None,
36
38
  ) -> str:
37
39
  """Write grid output files, provenance, and ledger entry.
38
40
 
39
41
  The three n_* parameters are pregridded-compilation diagnostics.
40
42
  They are included in the ledger entry only when not None.
41
43
 
44
+ ``placement`` records which columns decided each event's cell and
45
+ month, and goes into ``provenance.json`` so the artifact says how
46
+ it was produced. This matters more here than it usually would: a
47
+ grid whose events were placed from stale coordinates instead of
48
+ their declared cells is **indistinguishable from a correct one by
49
+ any total** -- country sums, coverage counts and conservation all
50
+ reconcile either way. Without this, nothing on disk answers "was
51
+ the declaration honoured when this was built?".
52
+
53
+ ``viewpoint`` is what the source parquet declared about itself — the
54
+ selection choices and upstream versions that shaped it — copied here
55
+ unchanged so the next stage can carry it on towards the published
56
+ store (ADR-054 §2). ``None`` for a source no viewpoint built.
57
+
58
+ Neither is added to the ledger entry: the rule at
59
+ ``digests_and_ledgers`` is to bump ``LEDGER_VERSION`` on a ledger
60
+ schema change, and that constant is shared with the viewpoint
61
+ builders, so an additive field in one layer would version every
62
+ ledger in the platform.
63
+
42
64
  Returns the output digest string.
43
65
  """
44
66
  output_dir.mkdir(parents=True, exist_ok=True)
@@ -53,13 +75,17 @@ def write_compilation_output(
53
75
 
54
76
  output_digest = compute_file_digest(grid_path)
55
77
 
56
- provenance = {
78
+ provenance: dict[str, Any] = {
57
79
  "source_path": str(source_path),
58
80
  "source_digest": source_digest,
59
81
  "grid_shape": list(grid_array.shape),
60
82
  "feature_names": feature_names,
61
83
  "output_digest": output_digest,
62
84
  }
85
+ if placement is not None:
86
+ provenance["placement"] = placement
87
+ if viewpoint is not None:
88
+ provenance["viewpoint"] = viewpoint
63
89
  provenance_path = output_dir / "provenance.json"
64
90
  provenance_path.write_text(json.dumps(provenance, indent=2))
65
91