Coverage for wrainfo/error_flist.py: 35%

31 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-10-18 12:40 +0000

1"""Create error file list module.""" 

2 

3# WRaINfo, Is a software to process FURUNO weather radar data. 

4# 

5# Copyright (c) 2022, FernLab (GFZ Potsdam, fernlab@gfz-potsdam.de) 

6# 

7# This software was developed within the context of the RaINfo ("Potential use of 

8# high resolution weather data in agriculture") project of FernLab funded by 

9# the Impulse and Networking Fund of the Helmholtz Association. 

10# 

11# Licensed under the Apache License, Version 2.0 (the "License"); 

12# you may not use this file except in compliance with the License. 

13# 

14# You may obtain a copy of the License at 

15# http://www.apache.org/licenses/LICENSE-2.0 

16# 

17# Unless required by applicable law or agreed to in writing, software 

18# distributed under the License is distributed on an "AS IS" BASIS, 

19# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

20# See the License for the specific language governing permissions and 

21# limitations under the License. 

22 

23# imports 

24# ------- 

25 

26import pickle 

27from wrainfo.reader import load_error_flist 

28from wrainfo.reader import create_filelist 

29from wrainfo.reader import read_config_file 

30 

31 

32# create error flist 

33# ------------------ 

34 

35def create_error_filelist(out_dir): 

36 """Create error file list. 

37 

38 Parameter 

39 --------- 

40 out_dir : str 

41 Output directory with filename 

42 

43 Return 

44 ------ 

45 : file 

46 empty file in output directory. 

47 """ 

48 error_flist = [] 

49 

50 with open(out_dir, 'wb') as fh: 

51 pickle.dump(error_flist, fh) 

52 

53 print(f"-- output to {out_dir}") 

54 

55 return True 

56 

57 

58# update error file list 

59# ---------------------- 

60 

61def update_error_flist(start_time, 

62 end_time, 

63 path, 

64 pattern='_000.scnx.gz'): 

65 """Update error file list manually. 

66 

67 Parameter 

68 --------- 

69 start_time : datetime.datetime 

70 end_time : datetime.datetime 

71 path : str 

72 Path to the configuration file 

73 pattern : str 

74 extension of the scnx file (elevation angle 0.5° = "_000.scnx.gz") 

75 

76 Return 

77 ------ 

78 : list 

79 list of error files. 

80 """ 

81 error_flist = load_error_flist(path=path) 

82 

83 flist = create_filelist(starttime=start_time, 

84 endtime=end_time, 

85 path=path, 

86 pattern=pattern) 

87 

88 outdir = read_config_file(path=path, selection="output_path_error_flist") 

89 

90 for fname in flist: 

91 print("Would you like add this file to error flist?" + "\n" + fname) 

92 user_input = input('Confirm? [Y/N] ') 

93 

94 if user_input.lower() in ('y', 'yes'): 

95 error_flist.append(fname) 

96 print(fname + "\n" + "successfully added to error file list.") 

97 elif user_input.lower() in ('n', 'no'): 

98 continue 

99 

100 print("Would you like save the changes to output directory?") 

101 user_input = input('Confirm? [Y/N] ') 

102 

103 if user_input.lower() in ('y', 'yes'): 

104 with open(outdir, 'wb') as fp: 

105 pickle.dump(error_flist, fp) 

106 print("output to" + "\n" + outdir) 

107 return True 

108 

109 elif user_input.lower() in ('n', 'no'): 

110 return error_flist