reader-workbench 1.0.0__py3-none-any.whl
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.
- reader_workbench/__init__.py +22 -0
- reader_workbench/__main__.py +4 -0
- reader_workbench/_version.py +17 -0
- reader_workbench/api/__init__.py +74 -0
- reader_workbench/api/_record_reads.py +75 -0
- reader_workbench/api/artifacts.py +79 -0
- reader_workbench/api/facade.py +538 -0
- reader_workbench/api/models.py +285 -0
- reader_workbench/api/notebooks.py +63 -0
- reader_workbench/contracts/__init__.py +18 -0
- reader_workbench/contracts/builtins/__init__.py +36 -0
- reader_workbench/contracts/builtins/cytometry.py +140 -0
- reader_workbench/contracts/builtins/four_state_event_window.py +214 -0
- reader_workbench/contracts/builtins/generic.py +21 -0
- reader_workbench/contracts/builtins/logic.py +149 -0
- reader_workbench/contracts/builtins/plate_reader.py +47 -0
- reader_workbench/contracts/catalog.py +257 -0
- reader_workbench/contracts/model.py +109 -0
- reader_workbench/domains/__init__.py +1 -0
- reader_workbench/domains/cytometry/__init__.py +3 -0
- reader_workbench/domains/cytometry/analysis/__init__.py +29 -0
- reader_workbench/domains/cytometry/analysis/events.py +182 -0
- reader_workbench/domains/cytometry/analysis/gating.py +175 -0
- reader_workbench/domains/cytometry/analysis/workflow.py +248 -0
- reader_workbench/domains/cytometry/io/__init__.py +3 -0
- reader_workbench/domains/cytometry/io/fcs.py +135 -0
- reader_workbench/domains/cytometry/plots/__init__.py +5 -0
- reader_workbench/domains/cytometry/plots/diagnostic.py +155 -0
- reader_workbench/domains/logic/__init__.py +3 -0
- reader_workbench/domains/logic/crosstalk/__init__.py +3 -0
- reader_workbench/domains/logic/crosstalk/pairs.py +661 -0
- reader_workbench/domains/logic/four_state_vector/__init__.py +7 -0
- reader_workbench/domains/logic/four_state_vector/builder.py +321 -0
- reader_workbench/domains/logic/four_state_vector/collection/__init__.py +20 -0
- reader_workbench/domains/logic/four_state_vector/collection/checks.py +49 -0
- reader_workbench/domains/logic/four_state_vector/collection/constants.py +29 -0
- reader_workbench/domains/logic/four_state_vector/collection/model.py +19 -0
- reader_workbench/domains/logic/four_state_vector/collection/render.py +383 -0
- reader_workbench/domains/logic/four_state_vector/collection/sources.py +185 -0
- reader_workbench/domains/logic/four_state_vector/config.py +214 -0
- reader_workbench/domains/logic/four_state_vector/diagnostic.py +361 -0
- reader_workbench/domains/logic/four_state_vector/heatmap.py +86 -0
- reader_workbench/domains/logic/four_state_vector/math.py +191 -0
- reader_workbench/domains/logic/four_state_vector/reference.py +85 -0
- reader_workbench/domains/logic/four_state_vector/selection.py +228 -0
- reader_workbench/domains/logic/four_state_vector/treatment_semantics.py +51 -0
- reader_workbench/domains/logic/four_state_vector/validation.py +19 -0
- reader_workbench/domains/logic/logic_symmetry/__init__.py +3 -0
- reader_workbench/domains/logic/logic_symmetry/encodings.py +93 -0
- reader_workbench/domains/logic/logic_symmetry/extract_corners.py +192 -0
- reader_workbench/domains/logic/logic_symmetry/main.py +236 -0
- reader_workbench/domains/logic/logic_symmetry/metrics.py +96 -0
- reader_workbench/domains/logic/logic_symmetry/overlay.py +129 -0
- reader_workbench/domains/logic/logic_symmetry/prep.py +138 -0
- reader_workbench/domains/logic/logic_symmetry/render.py +356 -0
- reader_workbench/domains/logic/treatment_columns.py +42 -0
- reader_workbench/domains/plate_reader/__init__.py +1 -0
- reader_workbench/domains/plate_reader/analysis/__init__.py +14 -0
- reader_workbench/domains/plate_reader/analysis/fold_change.py +474 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/__init__.py +21 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/aggregation.py +191 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/contract_fields.py +50 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/contracts.py +320 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/design_dispositions.py +54 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/disposition_records.py +140 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/event_sensitivity.py +27 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/materialize.py +274 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/observation_resampling.py +97 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/reduction.py +62 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/seeds.py +15 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/sources.py +308 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/well_exclusion_validation.py +94 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/well_exclusions.py +54 -0
- reader_workbench/domains/plate_reader/analysis/timepoints.py +76 -0
- reader_workbench/domains/plate_reader/io/__init__.py +6 -0
- reader_workbench/domains/plate_reader/io/sample_map.py +65 -0
- reader_workbench/domains/plate_reader/io/synergy_h1/__init__.py +6 -0
- reader_workbench/domains/plate_reader/io/synergy_h1/_kinetic.py +141 -0
- reader_workbench/domains/plate_reader/io/synergy_h1/_parser.py +295 -0
- reader_workbench/domains/plate_reader/io/synergy_h1/_shared.py +195 -0
- reader_workbench/domains/plate_reader/io/synergy_h1/_snapshot.py +130 -0
- reader_workbench/domains/plate_reader/ordering.py +59 -0
- reader_workbench/domains/plate_reader/plots/__init__.py +15 -0
- reader_workbench/domains/plate_reader/plots/_data.py +29 -0
- reader_workbench/domains/plate_reader/plots/common.py +346 -0
- reader_workbench/domains/plate_reader/plots/distributions.py +324 -0
- reader_workbench/domains/plate_reader/plots/dual_reporter_triptych.py +525 -0
- reader_workbench/domains/plate_reader/plots/dual_reporter_triptych_render.py +195 -0
- reader_workbench/domains/plate_reader/plots/four_state_event_window/__init__.py +26 -0
- reader_workbench/domains/plate_reader/plots/four_state_event_window/diagnostic.py +295 -0
- reader_workbench/domains/plate_reader/plots/four_state_event_window/diagnostic_components.py +149 -0
- reader_workbench/domains/plate_reader/plots/four_state_event_window/diagnostic_render.py +308 -0
- reader_workbench/domains/plate_reader/plots/four_state_event_window/diagnostic_style.py +51 -0
- reader_workbench/domains/plate_reader/plots/four_state_event_window/schema.py +8 -0
- reader_workbench/domains/plate_reader/plots/four_state_event_window/summary.py +140 -0
- reader_workbench/domains/plate_reader/plots/grouping.py +53 -0
- reader_workbench/domains/plate_reader/plots/panels/__init__.py +12 -0
- reader_workbench/domains/plate_reader/plots/panels/snapshot.py +161 -0
- reader_workbench/domains/plate_reader/plots/panels/snapshot_data.py +91 -0
- reader_workbench/domains/plate_reader/plots/panels/time_series.py +296 -0
- reader_workbench/domains/plate_reader/plots/single_reporter_diagnostic.py +435 -0
- reader_workbench/domains/plate_reader/plots/single_reporter_diagnostic_render.py +300 -0
- reader_workbench/domains/plate_reader/plots/snapshot_barplot/__init__.py +315 -0
- reader_workbench/domains/plate_reader/plots/snapshot_barplot/planning.py +168 -0
- reader_workbench/domains/plate_reader/plots/snapshot_heatmap/__init__.py +205 -0
- reader_workbench/domains/plate_reader/plots/snapshot_heatmap/inputs.py +103 -0
- reader_workbench/domains/plate_reader/plots/time_series.py +317 -0
- reader_workbench/domains/plate_reader/plots/ts_and_snap/__init__.py +479 -0
- reader_workbench/domains/plate_reader/plots/ts_and_snap/planning.py +283 -0
- reader_workbench/domains/time_series/__init__.py +29 -0
- reader_workbench/domains/time_series/aggregation.py +60 -0
- reader_workbench/domains/time_series/contracts.py +368 -0
- reader_workbench/domains/time_series/reduction.py +395 -0
- reader_workbench/errors.py +55 -0
- reader_workbench/maintenance/__init__.py +6 -0
- reader_workbench/maintenance/docs.py +335 -0
- reader_workbench/maintenance/model.py +28 -0
- reader_workbench/maintenance/release.py +39 -0
- reader_workbench/maintenance/skills.py +124 -0
- reader_workbench/plotting/__init__.py +20 -0
- reader_workbench/plotting/mpl.py +56 -0
- reader_workbench/plotting/sinks.py +69 -0
- reader_workbench/plotting/style.py +175 -0
- reader_workbench/plotting/utils.py +27 -0
- reader_workbench/plugins/__init__.py +1 -0
- reader_workbench/plugins/catalog.py +33 -0
- reader_workbench/plugins/export/__init__.py +0 -0
- reader_workbench/plugins/export/_paths.py +21 -0
- reader_workbench/plugins/export/csv.py +41 -0
- reader_workbench/plugins/export/xlsx.py +44 -0
- reader_workbench/plugins/ingest/__init__.py +0 -0
- reader_workbench/plugins/ingest/_discovery.py +58 -0
- reader_workbench/plugins/ingest/discovery_policy.py +66 -0
- reader_workbench/plugins/ingest/flow_cytometer.py +139 -0
- reader_workbench/plugins/ingest/synergy_h1.py +234 -0
- reader_workbench/plugins/manifests/__init__.py +1 -0
- reader_workbench/plugins/manifests/export.py +29 -0
- reader_workbench/plugins/manifests/ingest.py +29 -0
- reader_workbench/plugins/manifests/plot.py +161 -0
- reader_workbench/plugins/manifests/transform.py +172 -0
- reader_workbench/plugins/manifests/validator.py +18 -0
- reader_workbench/plugins/plot/__init__.py +0 -0
- reader_workbench/plugins/plot/_shared.py +55 -0
- reader_workbench/plugins/plot/cytometry_diagnostic.py +54 -0
- reader_workbench/plugins/plot/distributions.py +58 -0
- reader_workbench/plugins/plot/dual_reporter_triptych.py +224 -0
- reader_workbench/plugins/plot/four_state_event_window_diagnostic.py +133 -0
- reader_workbench/plugins/plot/four_state_event_window_summary.py +53 -0
- reader_workbench/plugins/plot/four_state_vector_collection.py +45 -0
- reader_workbench/plugins/plot/four_state_vector_diagnostic.py +105 -0
- reader_workbench/plugins/plot/four_state_vector_heatmap.py +63 -0
- reader_workbench/plugins/plot/logic_symmetry.py +56 -0
- reader_workbench/plugins/plot/single_reporter_diagnostic.py +279 -0
- reader_workbench/plugins/plot/snapshot_barplot.py +65 -0
- reader_workbench/plugins/plot/snapshot_heatmap.py +104 -0
- reader_workbench/plugins/plot/time_series.py +114 -0
- reader_workbench/plugins/plot/ts_and_snap.py +210 -0
- reader_workbench/plugins/transform/__init__.py +0 -0
- reader_workbench/plugins/transform/_four_state_vector.py +204 -0
- reader_workbench/plugins/transform/_labeling.py +109 -0
- reader_workbench/plugins/transform/alias.py +70 -0
- reader_workbench/plugins/transform/assay_labels.py +62 -0
- reader_workbench/plugins/transform/blank.py +79 -0
- reader_workbench/plugins/transform/crosstalk_pairs.py +180 -0
- reader_workbench/plugins/transform/cytometry_gating.py +120 -0
- reader_workbench/plugins/transform/fold_change.py +79 -0
- reader_workbench/plugins/transform/four_state_event_window.py +93 -0
- reader_workbench/plugins/transform/four_state_vector.py +62 -0
- reader_workbench/plugins/transform/four_state_vector_collection.py +41 -0
- reader_workbench/plugins/transform/logic_symmetry.py +67 -0
- reader_workbench/plugins/transform/outlier_filter.py +60 -0
- reader_workbench/plugins/transform/overflow.py +197 -0
- reader_workbench/plugins/transform/ratio.py +237 -0
- reader_workbench/plugins/transform/sample_map.py +170 -0
- reader_workbench/plugins/transform/sample_metadata.py +94 -0
- reader_workbench/plugins/validator/__init__.py +1 -0
- reader_workbench/plugins/validator/to_tidy_plus_map.py +155 -0
- reader_workbench/protocols/__init__.py +80 -0
- reader_workbench/protocols/_builtins_plate_reader_growth.py +179 -0
- reader_workbench/protocols/_builtins_plate_reader_variants.py +274 -0
- reader_workbench/protocols/builtins.py +1656 -0
- reader_workbench/protocols/compiler.py +22 -0
- reader_workbench/protocols/compilers/__init__.py +1 -0
- reader_workbench/protocols/compilers/common.py +100 -0
- reader_workbench/protocols/compilers/cytometry.py +87 -0
- reader_workbench/protocols/compilers/generic.py +14 -0
- reader_workbench/protocols/compilers/logic.py +245 -0
- reader_workbench/protocols/compilers/plate_reader.py +937 -0
- reader_workbench/protocols/compilers/plate_reader_pipeline.py +197 -0
- reader_workbench/protocols/model.py +1486 -0
- reader_workbench/protocols/semantic_coverage.py +234 -0
- reader_workbench/runtime/__init__.py +12 -0
- reader_workbench/runtime/builtin.py +23 -0
- reader_workbench/runtime/model.py +42 -0
- reader_workbench/workbench/__init__.py +60 -0
- reader_workbench/workbench/assets/__init__.py +22 -0
- reader_workbench/workbench/assets/types.py +118 -0
- reader_workbench/workbench/audit/__init__.py +5 -0
- reader_workbench/workbench/audit/experiments.py +307 -0
- reader_workbench/workbench/audit/staging.py +187 -0
- reader_workbench/workbench/cli/__init__.py +51 -0
- reader_workbench/workbench/cli/_lazy.py +9 -0
- reader_workbench/workbench/cli/_records_view.py +150 -0
- reader_workbench/workbench/cli/_surface_execution.py +443 -0
- reader_workbench/workbench/cli/audit.py +95 -0
- reader_workbench/workbench/cli/automation.py +229 -0
- reader_workbench/workbench/cli/demo.py +46 -0
- reader_workbench/workbench/cli/dop.py +91 -0
- reader_workbench/workbench/cli/experiments.py +635 -0
- reader_workbench/workbench/cli/helpers.py +232 -0
- reader_workbench/workbench/cli/main.py +59 -0
- reader_workbench/workbench/cli/maintenance.py +82 -0
- reader_workbench/workbench/cli/notebooks.py +260 -0
- reader_workbench/workbench/cli/pagination.py +117 -0
- reader_workbench/workbench/cli/protocols.py +336 -0
- reader_workbench/workbench/cli/shared.py +309 -0
- reader_workbench/workbench/cli/surfaces.py +534 -0
- reader_workbench/workbench/cli/verification.py +128 -0
- reader_workbench/workbench/commands.py +10 -0
- reader_workbench/workbench/config/__init__.py +47 -0
- reader_workbench/workbench/config/identity.py +13 -0
- reader_workbench/workbench/config/load.py +405 -0
- reader_workbench/workbench/config/model.py +274 -0
- reader_workbench/workbench/context.py +26 -0
- reader_workbench/workbench/decl/__init__.py +31 -0
- reader_workbench/workbench/decl/build.py +190 -0
- reader_workbench/workbench/decl/model.py +81 -0
- reader_workbench/workbench/dop/__init__.py +12 -0
- reader_workbench/workbench/dop/builtins.py +261 -0
- reader_workbench/workbench/dop/model.py +209 -0
- reader_workbench/workbench/engine/__init__.py +42 -0
- reader_workbench/workbench/engine/_shared.py +76 -0
- reader_workbench/workbench/engine/contracts.py +283 -0
- reader_workbench/workbench/engine/execution.py +326 -0
- reader_workbench/workbench/engine/file_outputs.py +260 -0
- reader_workbench/workbench/engine/inputs.py +161 -0
- reader_workbench/workbench/engine/invocations.py +507 -0
- reader_workbench/workbench/engine/planning.py +72 -0
- reader_workbench/workbench/engine/runtime.py +464 -0
- reader_workbench/workbench/engine/setup.py +149 -0
- reader_workbench/workbench/engine/validation.py +684 -0
- reader_workbench/workbench/experiment/__init__.py +47 -0
- reader_workbench/workbench/experiment/model.py +381 -0
- reader_workbench/workbench/experiments.py +133 -0
- reader_workbench/workbench/graph/__init__.py +47 -0
- reader_workbench/workbench/graph/nodes.py +102 -0
- reader_workbench/workbench/graph/normalize.py +177 -0
- reader_workbench/workbench/graph/refs.py +148 -0
- reader_workbench/workbench/input_discovery.py +19 -0
- reader_workbench/workbench/inspection/__init__.py +3 -0
- reader_workbench/workbench/inspection/catalogs.py +128 -0
- reader_workbench/workbench/inspection/common.py +92 -0
- reader_workbench/workbench/inspection/dop.py +64 -0
- reader_workbench/workbench/inspection/experiments.py +449 -0
- reader_workbench/workbench/inspection/inventory.py +68 -0
- reader_workbench/workbench/inspection/protocols.py +368 -0
- reader_workbench/workbench/inspection/readiness.py +333 -0
- reader_workbench/workbench/inspection/reports.py +367 -0
- reader_workbench/workbench/inspection/results.py +166 -0
- reader_workbench/workbench/inspection/runtime.py +287 -0
- reader_workbench/workbench/inspection/semantics.py +192 -0
- reader_workbench/workbench/inspection/validation.py +30 -0
- reader_workbench/workbench/notebooks/__init__.py +17 -0
- reader_workbench/workbench/notebooks/_launch_registry.py +112 -0
- reader_workbench/workbench/notebooks/_launch_runtime.py +104 -0
- reader_workbench/workbench/notebooks/components/__init__.py +21 -0
- reader_workbench/workbench/notebooks/components/deliverables.py +403 -0
- reader_workbench/workbench/notebooks/components/overview.py +119 -0
- reader_workbench/workbench/notebooks/eda.marimo.py.txt +153 -0
- reader_workbench/workbench/notebooks/launch.py +274 -0
- reader_workbench/workbench/notebooks/presentation.py +136 -0
- reader_workbench/workbench/notebooks/scaffold.py +60 -0
- reader_workbench/workbench/ontology.py +78 -0
- reader_workbench/workbench/paths.py +44 -0
- reader_workbench/workbench/ports/__init__.py +31 -0
- reader_workbench/workbench/ports/model.py +168 -0
- reader_workbench/workbench/records/__init__.py +44 -0
- reader_workbench/workbench/records/epoch.py +329 -0
- reader_workbench/workbench/records/evidence.py +247 -0
- reader_workbench/workbench/records/identity.py +87 -0
- reader_workbench/workbench/records/locking.py +185 -0
- reader_workbench/workbench/records/model.py +711 -0
- reader_workbench/workbench/records/sources.py +73 -0
- reader_workbench/workbench/records/store.py +1022 -0
- reader_workbench/workbench/records/verification.py +998 -0
- reader_workbench/workbench/registry.py +333 -0
- reader_workbench/workbench/spec_overrides.py +215 -0
- reader_workbench-1.0.0.dist-info/METADATA +91 -0
- reader_workbench-1.0.0.dist-info/RECORD +293 -0
- reader_workbench-1.0.0.dist-info/WHEEL +5 -0
- reader_workbench-1.0.0.dist-info/entry_points.txt +2 -0
- reader_workbench-1.0.0.dist-info/licenses/LICENSE +21 -0
- reader_workbench-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import matplotlib.pyplot as plt
|
|
4
|
+
import numpy as np
|
|
5
|
+
import pandas as pd
|
|
6
|
+
import seaborn as sns
|
|
7
|
+
|
|
8
|
+
from reader_workbench.plotting.sinks import PlotFigure
|
|
9
|
+
from reader_workbench.plotting.style import PaletteBook, use_style
|
|
10
|
+
|
|
11
|
+
from ..ordering import order_levels
|
|
12
|
+
from .common import (
|
|
13
|
+
alias_column,
|
|
14
|
+
best_subplot_grid,
|
|
15
|
+
colors_for,
|
|
16
|
+
exact_observation_counts,
|
|
17
|
+
plot_figure,
|
|
18
|
+
require_columns,
|
|
19
|
+
select_exact_observations,
|
|
20
|
+
warn_if_empty,
|
|
21
|
+
)
|
|
22
|
+
from .grouping import GroupMatch, resolve_groups
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _distribution_observation_counts(*frames: pd.DataFrame) -> tuple[int, int]:
|
|
26
|
+
counts = [exact_observation_counts(frame) for frame in frames if not frame.empty]
|
|
27
|
+
return sum(total for total, _ in counts), sum(omitted for _, omitted in counts)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _distribution_description(
|
|
31
|
+
selected_count: int,
|
|
32
|
+
withheld_count: int,
|
|
33
|
+
*,
|
|
34
|
+
distribution_withheld: bool,
|
|
35
|
+
) -> str | None:
|
|
36
|
+
if not withheld_count:
|
|
37
|
+
return None
|
|
38
|
+
description = (
|
|
39
|
+
f"Selected measurements: {selected_count} observed, {withheld_count} "
|
|
40
|
+
"omitted as bounded or non-finite; bounded or non-finite rows were omitted "
|
|
41
|
+
"before density estimation."
|
|
42
|
+
)
|
|
43
|
+
if distribution_withheld:
|
|
44
|
+
description += " At least one distribution was withheld because no exact observations remained."
|
|
45
|
+
return description
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _draw_withheld_distribution(axis, *, channel: str) -> None:
|
|
49
|
+
axis.text(
|
|
50
|
+
0.5,
|
|
51
|
+
0.5,
|
|
52
|
+
"Distribution withheld\nNo exact observations",
|
|
53
|
+
ha="center",
|
|
54
|
+
va="center",
|
|
55
|
+
transform=axis.transAxes,
|
|
56
|
+
)
|
|
57
|
+
axis.set_xticks([])
|
|
58
|
+
axis.set_yticks([])
|
|
59
|
+
axis.set_xlabel(channel)
|
|
60
|
+
axis.set_ylabel("density")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _figure_groups(
|
|
64
|
+
*,
|
|
65
|
+
df: pd.DataFrame,
|
|
66
|
+
group_on: str | None,
|
|
67
|
+
pool_sets: list[dict[str, list[str]]] | None,
|
|
68
|
+
pool_match: GroupMatch,
|
|
69
|
+
) -> list[tuple[str, list[str]]]:
|
|
70
|
+
"""
|
|
71
|
+
Return a list of (figure_label, [member_values]) to iterate files.
|
|
72
|
+
- When pool_sets is provided, each declared set label becomes a file label,
|
|
73
|
+
with its members listed.
|
|
74
|
+
- Otherwise: one file per distinct value of group_on.
|
|
75
|
+
- If group_on is None: single file ("all", [None]).
|
|
76
|
+
"""
|
|
77
|
+
if not group_on:
|
|
78
|
+
return [("all", [None])]
|
|
79
|
+
gcol = str(group_on)
|
|
80
|
+
universe = order_levels(df[gcol].astype(str).unique().tolist())
|
|
81
|
+
if pool_sets:
|
|
82
|
+
resolved = resolve_groups(universe, pool_sets, match=pool_match)
|
|
83
|
+
return resolved or [("all", universe)]
|
|
84
|
+
return [(v, [v]) for v in universe]
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def plot_distributions(
|
|
88
|
+
*,
|
|
89
|
+
df: pd.DataFrame,
|
|
90
|
+
blanks: pd.DataFrame,
|
|
91
|
+
channels: list[str],
|
|
92
|
+
# grouping
|
|
93
|
+
group_on: str | None = "design_id",
|
|
94
|
+
pool_sets: list[dict[str, list[str]]] | None = None,
|
|
95
|
+
pool_match: GroupMatch = "exact",
|
|
96
|
+
# layout
|
|
97
|
+
panel_by: str = "channel", # "channel" (default) | "group"
|
|
98
|
+
hue: str | None = None,
|
|
99
|
+
legend_loc: str = "upper left",
|
|
100
|
+
# style / output
|
|
101
|
+
fig_kwargs: dict | None = None,
|
|
102
|
+
filename: str | None = None,
|
|
103
|
+
palette_book: PaletteBook | None = None,
|
|
104
|
+
) -> list[PlotFigure]:
|
|
105
|
+
"""
|
|
106
|
+
Distribution histograms:
|
|
107
|
+
• Auto‑alias columns: prefers '<group_on>_alias' transparently.
|
|
108
|
+
• `group_on` selects partitions; `pool_sets` names explicit collections.
|
|
109
|
+
• Default: panel_by='channel' (one subplot per channel) and a separate
|
|
110
|
+
output file for each `group_on` value (e.g., per design_id).
|
|
111
|
+
"""
|
|
112
|
+
fig_kwargs = fig_kwargs or {}
|
|
113
|
+
figures: list[PlotFigure] = []
|
|
114
|
+
fill_alpha = float(fig_kwargs.get("kde_fill_alpha", 0.18))
|
|
115
|
+
|
|
116
|
+
# --- resolve columns (assertive, no silent fallbacks) ---
|
|
117
|
+
ch_list = [str(c) for c in channels]
|
|
118
|
+
require_columns(df, ["channel", "value"], where="distributions")
|
|
119
|
+
selected_work = df[df["channel"].astype(str).isin(ch_list)].copy()
|
|
120
|
+
if warn_if_empty(selected_work, where="distributions", detail="after channel filter"):
|
|
121
|
+
return []
|
|
122
|
+
gcol = alias_column(selected_work, group_on) if group_on else None
|
|
123
|
+
if gcol and gcol not in selected_work.columns:
|
|
124
|
+
raise ValueError(f"distributions: missing group_on column {gcol!r}")
|
|
125
|
+
if gcol:
|
|
126
|
+
group_values = selected_work[gcol]
|
|
127
|
+
valid_group = group_values.notna() & ~group_values.astype(str).str.strip().str.casefold().isin(
|
|
128
|
+
{"", "nan", "none"}
|
|
129
|
+
)
|
|
130
|
+
selected_work = selected_work.loc[valid_group].copy()
|
|
131
|
+
if warn_if_empty(selected_work, where="distributions", detail="after group_on identity filter"):
|
|
132
|
+
return []
|
|
133
|
+
|
|
134
|
+
work = selected_work
|
|
135
|
+
work = select_exact_observations(work, where="distributions")
|
|
136
|
+
|
|
137
|
+
selected_blanks = blanks
|
|
138
|
+
blank_work = selected_blanks
|
|
139
|
+
if not blanks.empty:
|
|
140
|
+
require_columns(blanks, ["channel", "value"], where="distribution blanks")
|
|
141
|
+
selected_blanks = blanks[blanks["channel"].astype(str).isin(ch_list)].copy()
|
|
142
|
+
blank_work = select_exact_observations(selected_blanks, where="distribution blanks")
|
|
143
|
+
|
|
144
|
+
if hue:
|
|
145
|
+
hcol = alias_column(work, hue)
|
|
146
|
+
if hcol not in work.columns:
|
|
147
|
+
raise ValueError(f"distributions: missing hue column {hcol!r}")
|
|
148
|
+
if panel_by not in {"channel", "group"}:
|
|
149
|
+
raise ValueError("panel_by must be 'channel' or 'group'")
|
|
150
|
+
|
|
151
|
+
# --- figure groups (decides how many files we emit) ---
|
|
152
|
+
fig_groups = _figure_groups(
|
|
153
|
+
df=(selected_work if not gcol else selected_work.rename(columns={gcol: str(gcol)})),
|
|
154
|
+
group_on=(str(gcol) if gcol else None),
|
|
155
|
+
pool_sets=pool_sets,
|
|
156
|
+
pool_match=pool_match,
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
# --- two modes: panel by channel (default) or by group value ---
|
|
160
|
+
if panel_by == "channel":
|
|
161
|
+
rows, cols = best_subplot_grid(len(ch_list))
|
|
162
|
+
for label, members in fig_groups:
|
|
163
|
+
legend_shown = False
|
|
164
|
+
distribution_withheld = False
|
|
165
|
+
source_sub = selected_work.copy()
|
|
166
|
+
if gcol and members != [None]:
|
|
167
|
+
source_sub = source_sub[source_sub[gcol].astype(str).isin(members)]
|
|
168
|
+
sub = work.copy()
|
|
169
|
+
if gcol and members != [None]:
|
|
170
|
+
sub = sub[sub[gcol].astype(str).isin(members)]
|
|
171
|
+
|
|
172
|
+
# overlay colors per member (multiple overlays if members>1)
|
|
173
|
+
colors = colors_for(max(1, len(members)), palette_book)
|
|
174
|
+
with use_style(rc=fig_kwargs.get("rc"), color_cycle=colors):
|
|
175
|
+
fig, axes = plt.subplots(rows, cols, figsize=(cols * 5, rows * 5), constrained_layout=True)
|
|
176
|
+
axes = np.atleast_1d(axes).ravel()
|
|
177
|
+
fig.suptitle(str(label), y=float(fig_kwargs.get("suptitle_y", 1.04)))
|
|
178
|
+
|
|
179
|
+
for j, ch in enumerate(ch_list):
|
|
180
|
+
if j >= len(axes):
|
|
181
|
+
break
|
|
182
|
+
ax = axes[j]
|
|
183
|
+
dch = sub[sub["channel"].astype(str) == ch]
|
|
184
|
+
if dch.empty:
|
|
185
|
+
source_channel = source_sub[source_sub["channel"].astype(str) == ch]
|
|
186
|
+
if source_channel.empty:
|
|
187
|
+
ax.set_visible(False)
|
|
188
|
+
else:
|
|
189
|
+
_draw_withheld_distribution(ax, channel=str(ch))
|
|
190
|
+
distribution_withheld = True
|
|
191
|
+
continue
|
|
192
|
+
|
|
193
|
+
if hue:
|
|
194
|
+
hue_col = alias_column(dch, hue)
|
|
195
|
+
hue_levels = order_levels(dch[hue_col].astype(str).unique().tolist())
|
|
196
|
+
colors = colors_for(max(1, len(hue_levels)), palette_book)
|
|
197
|
+
cmap = {h: colors[i % len(colors)] for i, h in enumerate(hue_levels)}
|
|
198
|
+
place_legend_here = (not legend_shown) and (len(hue_levels) > 1)
|
|
199
|
+
for h in hue_levels:
|
|
200
|
+
dd = dch[dch[hue_col].astype(str) == h]
|
|
201
|
+
if dd.empty:
|
|
202
|
+
continue
|
|
203
|
+
sns.kdeplot(
|
|
204
|
+
data=dd,
|
|
205
|
+
x="value",
|
|
206
|
+
ax=ax,
|
|
207
|
+
lw=1.8,
|
|
208
|
+
fill=True,
|
|
209
|
+
alpha=fill_alpha,
|
|
210
|
+
common_norm=False,
|
|
211
|
+
# Only the legend host needs labeled artists.
|
|
212
|
+
label=(str(h) if place_legend_here else None),
|
|
213
|
+
color=cmap[h],
|
|
214
|
+
)
|
|
215
|
+
if place_legend_here:
|
|
216
|
+
ax.legend(loc=legend_loc, title=None)
|
|
217
|
+
legend_shown = True
|
|
218
|
+
else:
|
|
219
|
+
# Single overall KDE if no hue given
|
|
220
|
+
sns.kdeplot(data=dch, x="value", ax=ax, lw=1.8, fill=True, alpha=fill_alpha)
|
|
221
|
+
|
|
222
|
+
# optional blanks median
|
|
223
|
+
if not blank_work.empty:
|
|
224
|
+
b = blank_work[blank_work["channel"].astype(str) == ch]
|
|
225
|
+
if not b.empty:
|
|
226
|
+
med = float(pd.to_numeric(b["value"], errors="coerce").median())
|
|
227
|
+
ax.axvline(med, ls="--", lw=1.0, alpha=0.6)
|
|
228
|
+
|
|
229
|
+
ax.set_xlabel(str(ch)) # more informative than "value"
|
|
230
|
+
ax.set_ylabel("density") # not "count"
|
|
231
|
+
|
|
232
|
+
# hide extras if grid > panels
|
|
233
|
+
for k in range(len(ch_list), len(axes)):
|
|
234
|
+
axes[k].set_visible(False)
|
|
235
|
+
|
|
236
|
+
# Ensure user-specified filename remains unique per file
|
|
237
|
+
stub = f"{filename}__{str(gcol) + '=' if gcol else ''}{label}" if filename else f"distrib__{label}"
|
|
238
|
+
observed_count, omitted_count = _distribution_observation_counts(source_sub, selected_blanks)
|
|
239
|
+
figures.append(
|
|
240
|
+
plot_figure(
|
|
241
|
+
fig=fig,
|
|
242
|
+
filename=stub,
|
|
243
|
+
fig_kwargs=fig_kwargs,
|
|
244
|
+
description=_distribution_description(
|
|
245
|
+
observed_count,
|
|
246
|
+
omitted_count,
|
|
247
|
+
distribution_withheld=distribution_withheld,
|
|
248
|
+
),
|
|
249
|
+
)
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
else: # panel_by == "group"
|
|
253
|
+
if not gcol:
|
|
254
|
+
raise ValueError("panel_by='group' requires 'group_on'")
|
|
255
|
+
# Panels are individual group values (optionally restricted by pool_sets)
|
|
256
|
+
# Single fixed channel required (or unambiguous)
|
|
257
|
+
if len(ch_list) != 1:
|
|
258
|
+
raise ValueError("panel_by='group' expects exactly one channel in 'channels'")
|
|
259
|
+
ch = ch_list[0]
|
|
260
|
+
# flatten members across all figure groups into a unique, ordered panel list
|
|
261
|
+
members_union: list[str] = []
|
|
262
|
+
seen: set[str] = set()
|
|
263
|
+
for _, members in fig_groups:
|
|
264
|
+
for v in members:
|
|
265
|
+
if v is not None and v not in seen:
|
|
266
|
+
members_union.append(v)
|
|
267
|
+
seen.add(v)
|
|
268
|
+
if not members_union:
|
|
269
|
+
return []
|
|
270
|
+
rows, cols = best_subplot_grid(len(members_union))
|
|
271
|
+
|
|
272
|
+
sub = work[work["channel"].astype(str) == ch]
|
|
273
|
+
|
|
274
|
+
colors = colors_for(1, palette_book)
|
|
275
|
+
with use_style(rc=fig_kwargs.get("rc"), color_cycle=colors):
|
|
276
|
+
fig, axes = plt.subplots(rows, cols, figsize=(cols * 5, rows * 5), constrained_layout=True)
|
|
277
|
+
axes = np.atleast_1d(axes).ravel()
|
|
278
|
+
fig.suptitle(str(ch), y=float(fig_kwargs.get("suptitle_y", 1.04)))
|
|
279
|
+
distribution_withheld = False
|
|
280
|
+
for j, gv in enumerate(members_union):
|
|
281
|
+
ax = axes[j]
|
|
282
|
+
ax.set_title(str(gv))
|
|
283
|
+
dd = sub[sub[gcol].astype(str) == str(gv)]
|
|
284
|
+
vals = pd.to_numeric(dd["value"], errors="coerce").dropna()
|
|
285
|
+
if vals.empty:
|
|
286
|
+
source_group = selected_work.loc[
|
|
287
|
+
selected_work["channel"].astype(str).eq(ch) & selected_work[gcol].astype(str).eq(str(gv))
|
|
288
|
+
]
|
|
289
|
+
if source_group.empty:
|
|
290
|
+
ax.set_visible(False)
|
|
291
|
+
else:
|
|
292
|
+
_draw_withheld_distribution(ax, channel=str(ch))
|
|
293
|
+
distribution_withheld = True
|
|
294
|
+
continue
|
|
295
|
+
sns.kdeplot(data=dd, x="value", ax=ax, lw=1.8, fill=True, alpha=fill_alpha)
|
|
296
|
+
if not blank_work.empty:
|
|
297
|
+
b = blank_work[blank_work["channel"].astype(str) == ch]
|
|
298
|
+
if not b.empty:
|
|
299
|
+
med = float(pd.to_numeric(b["value"], errors="coerce").median())
|
|
300
|
+
ax.axvline(med, ls="--", lw=1.0, alpha=0.6)
|
|
301
|
+
ax.set_xlabel(str(ch))
|
|
302
|
+
ax.set_ylabel("density")
|
|
303
|
+
|
|
304
|
+
for k in range(len(members_union), len(axes)):
|
|
305
|
+
axes[k].set_visible(False)
|
|
306
|
+
|
|
307
|
+
stub = f"{filename}__{ch}" if filename else f"distrib__{ch}"
|
|
308
|
+
observed_count, omitted_count = _distribution_observation_counts(
|
|
309
|
+
selected_work[selected_work["channel"].astype(str) == ch],
|
|
310
|
+
selected_blanks[selected_blanks["channel"].astype(str) == ch],
|
|
311
|
+
)
|
|
312
|
+
figures.append(
|
|
313
|
+
plot_figure(
|
|
314
|
+
fig=fig,
|
|
315
|
+
filename=stub,
|
|
316
|
+
fig_kwargs=fig_kwargs,
|
|
317
|
+
description=_distribution_description(
|
|
318
|
+
observed_count,
|
|
319
|
+
omitted_count,
|
|
320
|
+
distribution_withheld=distribution_withheld,
|
|
321
|
+
),
|
|
322
|
+
)
|
|
323
|
+
)
|
|
324
|
+
return figures
|