File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ """Print participant demographic statistics."""
3+
4+ import pandas as pd
5+
6+ from hyperface .qa import create_qa_argument_parser , get_config
7+
8+
9+ def main ():
10+ parser = create_qa_argument_parser (
11+ description = "Print participant demographic statistics." ,
12+ include_subjects = False ,
13+ )
14+ args = parser .parse_args ()
15+
16+ config = get_config (config_path = args .config , data_dir = args .data_dir )
17+ df = pd .read_csv (config .paths .data_dir / "participants.tsv" , sep = "\t " )
18+
19+ n = len (df )
20+ n_females = (df ["sex" ] == "F" ).sum ()
21+ n_males = (df ["sex" ] == "M" ).sum ()
22+
23+ lines = [
24+ f"N participants: { n } " ,
25+ f"N females: { n_females } " ,
26+ f"N males: { n_males } " ,
27+ f"Age mean: { df ['age' ].mean ():.1f} " ,
28+ f"Age SD: { df ['age' ].std ():.1f} " ,
29+ f"Age range: { df ['age' ].min ()} -{ df ['age' ].max ()} " ,
30+ ]
31+
32+ for line in lines :
33+ print (line )
34+
35+ output_path = config .paths .qa_base_dir / "participant_demographics.txt"
36+ output_path .parent .mkdir (parents = True , exist_ok = True )
37+ output_path .write_text ("\n " .join (lines ) + "\n " )
38+ print (f"\n Saved to: { output_path } " )
39+
40+
41+ if __name__ == "__main__" :
42+ main ()
You can’t perform that action at this time.
0 commit comments