Coverage for sarvey/console.py: 100%

27 statements  

« prev     ^ index     » next       coverage.py v7.6.0, created at 2024-10-17 12:36 +0000

1#!/usr/bin/env python 

2 

3# SARvey - A multitemporal InSAR time series tool for the derivation of displacements. 

4# 

5# Copyright (C) 2021-2024 Andreas Piter (IPI Hannover, piter@ipi.uni-hannover.de) 

6# 

7# This software was developed together with FERN.Lab (fernlab@gfz-potsdam.de) in the context 

8# of the SAR4Infra project with funds of the German Federal Ministry for Digital and 

9# Transport and contributions from Landesamt fuer Vermessung und Geoinformation 

10# Schleswig-Holstein and Landesbetrieb Strassenbau und Verkehr Schleswig-Holstein. 

11# 

12# This program is free software: you can redistribute it and/or modify it under 

13# the terms of the GNU General Public License as published by the Free Software 

14# Foundation, either version 3 of the License, or (at your option) any later 

15# version. 

16# 

17# Important: This package uses PyMaxFlow. The core of PyMaxflows library is the C++ 

18# implementation by Vladimir Kolmogorov. It is also licensed under the GPL, but it REQUIRES that you 

19# cite [BOYKOV04] (see LICENSE) in any resulting publication if you use this code for research purposes. 

20# This requirement extends to SARvey. 

21# 

22# This program is distributed in the hope that it will be useful, but WITHOUT 

23# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 

24# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 

25# details. 

26# 

27# You should have received a copy of the GNU Lesser General Public License along 

28# with this program. If not, see <https://www.gnu.org/licenses/>. 

29 

30"""Console module for SARvey.""" 

31from sarvey import version 

32from logging import Logger 

33 

34 

35def printStep(*, step: int, step_dict: dict, logger: Logger): 

36 """Print the current step to console. 

37 

38 Parameters 

39 ---------- 

40 step: int 

41 current step number 

42 step_dict: dict 

43 dictionary with step numbers and names 

44 logger: Logger 

45 Logging handler 

46 """ 

47 logger.info(msg=" ---------------------------------------------------------------------------------") 

48 logger.info(msg=f" STEP {step}: {step_dict[step]}") 

49 logger.info(msg=" ---------------------------------------------------------------------------------") 

50 

51 

52def printCurrentConfig(*, config_section: dict, config_section_default: dict, logger: Logger): 

53 """Print the current parameters and their default values from the config file to console. 

54 

55 Parameters 

56 ---------- 

57 config_section: dict 

58 Section of the configuration class which contains the selected parameters. 

59 config_section_default: dict 

60 Config section with default values. 

61 logger: Logger 

62 Logging handler. 

63 """ 

64 shift = " " 

65 logger.info(msg=shift + "{:>35} {:>15} {:>10}".format("Parameter", "value", "default")) 

66 logger.info(msg=shift + "{:>35} {:>15} {:>10}".format("_________", "_____", "_______")) 

67 

68 for key in config_section.keys(): 

69 default = config_section_default[key] 

70 default = "None" if default is None else default 

71 default = "True" if default is True else default 

72 default = "False" if default is False else default 

73 

74 value = config_section[key] 

75 value = "None" if value is None else value 

76 value = "True" if value is True else value 

77 value = "False" if value is False else value 

78 if default == value: 

79 logger.info(msg=shift + "{:>35} {:>15} {:>10}".format(key, value, default)) 

80 else: 

81 logger.info(msg=shift + "{:>35} {:>15} <--- {:>10}".format(key, value, default)) 

82 

83 logger.info(msg="") 

84 

85 

86def showLogoSARvey(*, logger: Logger, step: str): 

87 """ShowLogoSARvey. 

88 

89 Parameters 

90 ---------- 

91 logger: Logger 

92 logging handler 

93 step: str 

94 Name of the step or script which is shown on the logo. 

95 """ 

96 # generate_from: http://patorjk.com/software/taag/ - font: Big, style: default 

97 # and https://textik.com/ 

98 logger.info(msg=f"SARvey version: {version.__version__} - {version.__versionalias__}, {version.__versiondate__}, " 

99 f"Run: {step}") 

100 new_logo = rf""" . _____ _____ 

101 +------ / \ ------ / ____| /\ | __ \ 

102 | / / | (___ / \ | |__) |_ _____ _ _ 

103 | / / \___ \ / /\ \ | _ /\ \ / / _ \ | | | 

104 | /\\ / / ____) / ____ \| | \ \ \ V / __/ |_| | 

105 | / \\/ / |_____/_/ \_\_| \_\ \_/ \___|\__, | 

106 | / \ / __/ | 

107 | \ / / v{version.__version__:<5} - {version.__versionalias__:<18} |___/ 

108 \\ / /... {version.__versiondate__:<20} | 

109 / \\/ / :... | 

110 / / / :... {step: <20} | 

111 / / / :... | 

112 / / _______ :... _________| 

113 \/ \______ :... ____________/ | 

114 +-------------------- \________:___/ --------------------+ 

115 """ 

116 print(new_logo)