54 def read_settings_file(settings_path): |
56 def read_settings_file(settings_path): |
55 """ Read the settings file. |
57 """ Read the settings file. |
56 |
58 |
57 The file should contain python code.""" |
59 The file should contain python code.""" |
58 if not os.path.isfile(settings_path): |
60 if not os.path.isfile(settings_path): |
59 raise IOError("The provided settings path does not correspond to a file.") |
61 logging.error("The provided settings path does not correspond to a file.") |
|
62 sys.exit(1) |
60 |
63 |
61 dirname, basename = os.path.split(settings_path) |
64 dirname, basename = os.path.split(settings_path) |
62 sys.path.append(dirname) |
65 sys.path.append(dirname) |
63 |
66 |
64 module_name, _ = os.path.splitext(basename) |
67 module_name, _ = os.path.splitext(basename) |
66 return settings |
69 return settings |
67 |
70 |
68 |
71 |
69 def main(): |
72 def main(): |
70 # Define the command line argument |
73 # Define the command line argument |
71 parser = argparse.ArgumentParser(description="A program to convert LICEL binary files to the SCC NetCDF format.") |
74 parser = argparse.ArgumentParser(description="A program to convert Licel binary files to the SCC NetCDF format.") |
72 parser.add_argument("parameter_file", help="The path to a parameter file linking licel and SCC channels.") |
75 parser.add_argument("parameter_file", help="The path to a parameter file linking licel and SCC channels.") |
73 parser.add_argument("plus45_string", nargs='?', help="Search string for plus 45 degree files (default '*.*')", default="*.*") |
76 parser.add_argument("plus45_string", nargs='?', help="Search string for plus 45 degree files (default '*.*')", default="*.*") |
74 parser.add_argument("minus45_string", nargs='?', help="Search string for minus 45 degree files (default '*.*')", default="*.*") |
77 parser.add_argument("minus45_string", nargs='?', help="Search string for minus 45 degree files (default '*.*')", default="*.*") |
75 parser.add_argument("-i", '--id_as_name', |
78 parser.add_argument("-i", '--id_as_name', |
76 help="Use transient digitizer ids as channel names, instead of descriptive names", |
79 help="Use transient digitizer ids as channel names, instead of descriptive names", |
83 help="The temperature (in C) at lidar level, required if using US Standard atmosphere", |
86 help="The temperature (in C) at lidar level, required if using US Standard atmosphere", |
84 default="25") |
87 default="25") |
85 parser.add_argument("-p", "--pressure", type=float, |
88 parser.add_argument("-p", "--pressure", type=float, |
86 help="The pressure (in hPa) at lidar level, required if using US Standard atmosphere", |
89 help="The pressure (in hPa) at lidar level, required if using US Standard atmosphere", |
87 default="1020") |
90 default="1020") |
|
91 # Verbosity settings from http://stackoverflow.com/a/20663028 |
|
92 parser.add_argument('-d', '--debug', help="Print dubuging information.", action="store_const", |
|
93 dest="loglevel", const=logging.DEBUG, default=logging.INFO, |
|
94 ) |
|
95 parser.add_argument('-s', '--silent', help="Show only warning and error messages.", action="store_const", |
|
96 dest="loglevel", const=logging.WARNING |
|
97 ) |
|
98 |
88 args = parser.parse_args() |
99 args = parser.parse_args() |
|
100 |
|
101 # Get the logger with the appropriate level |
|
102 logging.basicConfig(format='%(levelname)s: %(message)s', level=args.loglevel) |
|
103 logger = logging.getLogger(__name__) |
|
104 |
|
105 #coloredlogs.install(fmt='%(levelname)s: %(message)s', level=args.loglevel) |
89 |
106 |
90 # Get a list of files to convert |
107 # Get a list of files to convert |
91 plus45_files = glob.glob(args.plus45_string) |
108 plus45_files = glob.glob(args.plus45_string) |
92 minus45_files = glob.glob(args.minus45_string) |
109 minus45_files = glob.glob(args.minus45_string) |
93 |
110 |
94 if len(plus45_files)==0 or len(minus45_files)==0: |
111 if len(plus45_files)==0 or len(minus45_files)==0: |
95 print "No files found when searching for %s and %s." % (plus45_files, minus45_files) |
112 logger.error("No files found when searching for %s and %s." % (plus45_files, minus45_files)) |
96 sys.exit(1) |
113 sys.exit(1) |
97 |
114 |
98 # Read the files |
115 # Read the files |
99 print "Reading {0} files from {1}".format(len(plus45_files), args.plus45_string) |
116 logger.info("Reading {0} files from {1}".format(len(plus45_files), args.plus45_string)) |
100 print "Reading {0} files from {1}".format(len(minus45_files), args.minus45_string) |
117 logger.info("Reading {0} files from {1}".format(len(minus45_files), args.minus45_string)) |
101 |
118 |
102 CustomLidarMeasurement = create_custom_class(args.parameter_file, args.id_as_name, args.temperature, |
119 CustomLidarMeasurement = create_custom_class(args.parameter_file, args.id_as_name, args.temperature, |
103 args.pressure) |
120 args.pressure) |
|
121 |
104 measurement = CustomLidarMeasurement(plus45_files, minus45_files) |
122 measurement = CustomLidarMeasurement(plus45_files, minus45_files) |
105 measurement = measurement.subset_by_scc_channels() |
|
106 |
|
107 # Save the netcdf |
|
108 |
123 |
109 print "Saving netcdf." |
124 try: |
|
125 measurement = measurement.subset_by_scc_channels() |
|
126 except ValueError as err: |
|
127 logging.error(err) |
|
128 sys.exit(1) |
|
129 |
|
130 # Save the netcdf |
|
131 logger.info("Saving netcdf") |
110 measurement.set_measurement_id(args.measurement_id, args.measurement_number) |
132 measurement.set_measurement_id(args.measurement_id, args.measurement_number) |
111 measurement.save_as_netcdf() |
133 measurement.save_as_netcdf() |
112 print "Created file ", measurement.scc_filename |
134 logger.info("Created file %s" % measurement.scc_filename) |