-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store each response key as a column for responses
- Loading branch information
Showing
24 changed files
with
200 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import json | ||
import os | ||
from pathlib import Path | ||
|
||
import polars | ||
|
||
info = "Make response datasets have one column per response" | ||
|
||
|
||
def _migrate_responses_to_one_col_per_response(path: Path) -> None: | ||
for experiment in path.glob("experiments/*"): | ||
ensembles = path.glob("ensembles/*") | ||
|
||
experiment_id = None | ||
with open(experiment / "index.json", encoding="utf-8") as f: | ||
exp_index = json.load(f) | ||
experiment_id = exp_index["id"] | ||
|
||
for ens in ensembles: | ||
with open(ens / "index.json", encoding="utf-8") as f: | ||
ens_file = json.load(f) | ||
if ens_file["experiment_id"] != experiment_id: | ||
continue | ||
|
||
real_dirs = [*ens.glob("realization-*")] | ||
|
||
for real_dir in real_dirs: | ||
for df_name, columns in [ | ||
("gen_data", ["report_step", "index"]), | ||
("summary", ["time"]), | ||
]: | ||
if (real_dir / f"{df_name}.parquet").exists(): | ||
df = polars.read_parquet(real_dir / f"{df_name}.parquet") | ||
pivoted = df.pivot( | ||
on="response_key", index=["realization", *columns] | ||
) | ||
|
||
os.remove(real_dir / f"{df_name}.parquet") | ||
pivoted.write_parquet(real_dir / f"{df_name}.parquet") | ||
|
||
|
||
def migrate(path: Path) -> None: | ||
_migrate_responses_to_one_col_per_response(path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.