Coverage for src/instawell/figures/fig_01_raw.py: 0%
19 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-07 15:47 -0600
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-07 15:47 -0600
1import logging
3import pandas as pd
4import plotly.express as px
6from instawell.core.exp_context import ExperimentContext
7from instawell.core.steps import StepFiles
9# set logging level to INFO
11logger = logging.getLogger(__name__)
14def create_figures_generator(ctx: ExperimentContext):
15 """
16 Generates Plotly figures from grouped data.
18 This function groups the input DataFrame by 'ligand', 'protein', and
19 'buffer', then yields a line plot figure for each group.
21 Args:
22 ctx: An ExperimentContext object containing experiment details.
24 Yields:
25 A Plotly figure object for each group.
26 """
27 # Load the organized data
28 organized_data_path = ctx.experiment_dir / StepFiles.INGESTED_DATA
29 if not organized_data_path.exists():
30 raise FileNotFoundError(f"Organized data file not found: {organized_data_path}")
31 data_df = pd.read_csv(organized_data_path)
33 # ensure the necessary columns are present
34 required_columns = [
35 "Temperature",
36 "well",
37 "value",
38 "ligand",
39 "protein",
40 "buffer",
41 "concentration",
42 "well_unqcond",
43 ]
44 for col in required_columns:
45 if col not in data_df.columns:
46 raise ValueError(f"Missing required column: {col} in the data.")
47 grouped_data = data_df.groupby(["ligand", "protein", "buffer"])
49 for (ligand, protein, buffer), group in grouped_data:
50 fig = px.line(
51 group,
52 x="Temperature",
53 y="value",
54 color="well_unqcond",
55 title=f"Raw Data for {ligand} and {protein} in {buffer} Buffer",
56 )
57 yield fig