Coverage for mpcforces_extractor\cli\extract.py: 0%

17 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-03 23:41 +0100

1from pathlib import Path 

2import typer 

3from mpcforces_extractor.force_extractor import MPCForceExtractor 

4from mpcforces_extractor.writer.summary_writer import SummaryWriter 

5 

6extractor_cmd = typer.Typer(name="extract", invoke_without_command=True) 

7 

8 

9@extractor_cmd.callback() 

10def extract( 

11 input_path_fem: str = typer.Argument(..., help="Path to the .fem file (model)"), 

12 input_path_mpcf: str = typer.Argument(..., help="Path to the .mpcf file"), 

13 output_path: str = typer.Argument(..., help="Path to the output folder"), 

14 blocksize: int = typer.Option(8, help="Blocksize for the MPC forces"), 

15): 

16 """ 

17 Extracts the mpc forces and also writes the tcl lines for visualization 

18 """ 

19 

20 # Check if the files exist, if not raise an error 

21 if not Path(input_path_fem).exists(): 

22 raise FileNotFoundError(f"File {input_path_fem} not found") 

23 if not Path(input_path_mpcf).exists(): 

24 raise FileNotFoundError(f"File {input_path_mpcf} not found") 

25 

26 # Extract the forces 

27 mpc_force_extractor = MPCForceExtractor( 

28 input_path_fem, input_path_mpcf, output_path 

29 ) 

30 mpc_force_extractor.build_fem_and_subcase_data(blocksize) 

31 

32 # Write Summary 

33 summary_writer = SummaryWriter( 

34 mpc_force_extractor, mpc_force_extractor.output_folder 

35 ) 

36 summary_writer.add_header() 

37 summary_writer.add_mpc_lines() 

38 summary_writer.write_lines()