Conditions | 5 |
Total Lines | 52 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | # pylint: disable=import-outside-toplevel |
||
9 | @app.command() |
||
10 | def main( |
||
11 | input_path: Path = typer.Argument( # noqa: B008 |
||
12 | ..., |
||
13 | exists=True, |
||
14 | file_okay=True, |
||
15 | dir_okay=True, |
||
16 | readable=True, |
||
17 | ), |
||
18 | plot: bool = typer.Option( # noqa: B008 |
||
19 | False, |
||
20 | '--plot/--no-plot', |
||
21 | '-p/-P', |
||
22 | help='Plot the image using Matplotlib or Pillow.', |
||
23 | ), |
||
24 | show: bool = typer.Option( # noqa: B008 |
||
25 | False, |
||
26 | '--show/--no-show', |
||
27 | '-s/-S', |
||
28 | help='Show the image using specialized visualisation software.', |
||
29 | ), |
||
30 | label: bool = typer.Option( # noqa: B008 |
||
31 | False, |
||
32 | '--label/--scalar', |
||
33 | '-l/-s', |
||
34 | help='Use torchio.LabelMap to instantiate the image.', |
||
35 | ), |
||
36 | load: bool = typer.Option( # noqa: B008 |
||
37 | False, |
||
38 | help=( |
||
39 | 'Load the image from disk so that information about data type and memory ' |
||
40 | 'can be displayed. Slower, especially for large images.' |
||
41 | ), |
||
42 | ), |
||
43 | ) -> None: |
||
44 | """Print information about an image and, optionally, show it. |
||
45 | |||
46 | Example: |
||
47 | $ tiohd input.nii.gz |
||
48 | """ |
||
49 | # Imports are placed here so that the tool loads faster if not being run |
||
50 | import torchio as tio |
||
51 | |||
52 | class_ = tio.LabelMap if label else tio.ScalarImage |
||
53 | image = class_(input_path) |
||
54 | if load: |
||
55 | image.load() |
||
56 | print(image) # noqa: T201 |
||
57 | if plot: |
||
58 | image.plot() |
||
59 | if show: |
||
60 | image.show() |
||
61 | |||
65 |