mattbitzesty commited on
Commit
c9247c9
·
unverified ·
1 Parent(s): 0e7a065

feat(data): zero-extend early-depleted trajectories to fixed 49-step grid

Browse files

- Add _pad_trajectory_to_steps helper that appends zero-liquid / zero-headspace records.
- Preserve actual solver times for active window; extend only with physical zeros.
- Ensures every record has exactly 49 timesteps for temporal alignment.

scripts/generate_empirical_bootstrap.py CHANGED
@@ -115,6 +115,41 @@ def _formula_fingerprint(formula_list: list[dict[str, Any]]) -> str:
115
  return "".join(f"{c.get('cas', '')}_{c.get('weight_fraction', 0):.4f}" for c in sorted_items)
116
 
117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  def _build_record(
119
  formula_id: str,
120
  formula_list: list[dict[str, Any]],
@@ -124,6 +159,10 @@ def _build_record(
124
  is_control: bool = False,
125
  ) -> dict[str, Any]:
126
  """Build a serializable empirical record with precomputed targets."""
 
 
 
 
127
  n_steps = len(trajectory)
128
  n_compounds = len(composition)
129
 
 
115
  return "".join(f"{c.get('cas', '')}_{c.get('weight_fraction', 0):.4f}" for c in sorted_items)
116
 
117
 
118
+ def _pad_trajectory_to_steps(
119
+ trajectory: list[dict[str, Any]],
120
+ steps: int = N_TIMESTEPS,
121
+ ) -> list[dict[str, Any]]:
122
+ """
123
+ Extend a trajectory that stopped early due to film depletion to a fixed
124
+ number of steps by appending zero-liquid / zero-headspace records.
125
+
126
+ The physical meaning is that the formulation has completely evaporated, so
127
+ subsequent timesteps contribute zero olfactory signal. Time values are not
128
+ resampled; the actual solver times are preserved for the active window and
129
+ then simply repeated/extended to fill the grid.
130
+ """
131
+ if len(trajectory) >= steps:
132
+ return trajectory[:steps]
133
+
134
+ all_species = set()
135
+ for step in trajectory:
136
+ all_species.update(step.get("x_liquid", {}).keys())
137
+ all_species.update(step.get("C_gas_mg_m3", {}).keys())
138
+
139
+ padded = list(trajectory)
140
+ last_t = float(trajectory[-1].get("t_s", 0.0)) if trajectory else 0.0
141
+ for _ in range(len(trajectory), steps):
142
+ last_t += INTERVAL_SECONDS
143
+ padded.append({
144
+ "t_s": last_t,
145
+ "x_liquid": {s: 0.0 for s in all_species},
146
+ "C_gas_mg_m3": {s: 0.0 for s in all_species},
147
+ "y_gas": {s: 0.0 for s in all_species},
148
+ "OAV": {s: 0.0 for s in all_species},
149
+ })
150
+ return padded
151
+
152
+
153
  def _build_record(
154
  formula_id: str,
155
  formula_list: list[dict[str, Any]],
 
159
  is_control: bool = False,
160
  ) -> dict[str, Any]:
161
  """Build a serializable empirical record with precomputed targets."""
162
+ # Enforce a fixed 49-step grid: extend early-depleted trajectories with
163
+ # zero-liquid / zero-headspace padding to preserve temporal alignment.
164
+ trajectory = _pad_trajectory_to_steps(trajectory, steps=N_TIMESTEPS)
165
+
166
  n_steps = len(trajectory)
167
  n_compounds = len(composition)
168