diff --git a/notebooks/spe11b_task_1.ipynb b/notebooks/spe11b_task_1.ipynb index fb329c5..61a8518 100644 --- a/notebooks/spe11b_task_1.ipynb +++ b/notebooks/spe11b_task_1.ipynb @@ -34,7 +34,7 @@ "- `rhoG [kg/m3]`\n", "- `rhoL [kg/m3]`\n", "- `tmCO2 [kg]`\n", - "- `temp [°C]`\n", + "- `temp [\u00b0C]`\n", "\n", "The surrogate predicts the state variables forward in time and keeps the coordinates fixed from the template CSV.\n", "\n", @@ -135,7 +135,7 @@ "\n", "# Train on one participant from the first 50 years only.\n", "train_participant = participants[0]\n", - "export_participant = participants[3]\n", + "export_participant = participants[4]\n", "train_dataset = SpatialMapTransitionDataset(\n", " data_root,\n", " participants=[train_participant],\n", @@ -454,7 +454,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "id": "329316dc", "metadata": {}, "outputs": [], @@ -479,9 +479,13 @@ "ar_summaries = []\n", "ar_feature_names = [name for name in field_names if name not in ['x [m]', 'z [m]', 'pressure [Pa]']]\n", "ar_feature_names = [name for name in ar_feature_names if name in physical_fields]\n", - "ar_feature_traces = {name: [] for name in ar_feature_names}\n", + "ar_feature_traces = {name: [0.0] for name in ar_feature_names}\n", "\n", "current_snapshot = export_series.snapshots[0]\n", + "initial_output_path = ar_root / export_series.participant / current_snapshot.path.name\n", + "save_spatial_map_csv_data(current_snapshot, initial_output_path)\n", + "ar_outputs.append(initial_output_path)\n", + "ar_summaries.append({'target_time_years': current_snapshot.time_years, 'pressure [Pa]': 0.0})\n", "for target_snapshot in export_series.snapshots[1:]:\n", " predicted_data = predict_autoregressive_data(current_snapshot, target_snapshot)\n", " output_path = ar_root / export_series.participant / target_snapshot.path.name\n", @@ -625,4 +629,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} +} \ No newline at end of file diff --git a/src/ml4gcs/data/export.py b/src/ml4gcs/data/export.py index a5f8c79..cbda624 100644 --- a/src/ml4gcs/data/export.py +++ b/src/ml4gcs/data/export.py @@ -50,19 +50,22 @@ def save_spatial_map_csv( def save_spatial_map_csv_data( template: SpatialMapSnapshot, output_path: Path | str, - data: np.ndarray, + data: np.ndarray | None = None, ) -> Path: """Write a spatial-map CSV using a full row matrix.""" output_path = Path(output_path) output_path.parent.mkdir(parents=True, exist_ok=True) - data = np.asarray(data, dtype=template.data.dtype) - if data.shape != template.data.shape: - raise ValueError( - "Predicted data shape does not match the template shape: " - f"{data.shape} vs {template.data.shape}" - ) + if data is None: + data = template.data.copy() + else: + data = np.asarray(data, dtype=template.data.dtype) + if data.shape != template.data.shape: + raise ValueError( + "Predicted data shape does not match the template shape: " + f"{data.shape} vs {template.data.shape}" + ) with output_path.open("w", encoding="utf-8", newline="") as handle: handle.write("# " + ", ".join(template.columns) + "\n") @@ -109,6 +112,12 @@ def export_next_step_timeline( output_paths: list[Path] = [] snapshots = participant_series.snapshots + if snapshots: + first_snapshot = snapshots[0] + output_paths.append( + save_spatial_map_csv_data(first_snapshot, output_root / first_snapshot.path.name) + ) + for input_snapshot, target_snapshot in zip(snapshots[:-1], snapshots[1:], strict=True): pressure_grid = predict_pressure(input_snapshot, target_snapshot) output_path = output_root / target_snapshot.path.name @@ -128,6 +137,10 @@ def export_next_step_timeline_data( output_paths: list[Path] = [] snapshots = participant_series.snapshots + if snapshots: + first_snapshot = snapshots[0] + output_paths.append(save_spatial_map_csv_data(first_snapshot, output_root / first_snapshot.path.name)) + for input_snapshot, target_snapshot in zip(snapshots[:-1], snapshots[1:], strict=True): predicted = predict_data(input_snapshot, target_snapshot) output_path = output_root / target_snapshot.path.name