|
1 """ Sample script to convert licel files to SCC netcdf format. |
|
2 |
|
3 The script assumes the following things: |
|
4 |
|
5 1. You have already installed the atmospheric_lidar module (e.g. using pip). |
|
6 2. You have create a class in a file "ipral" describing your system (described the readme file). |
|
7 If you want to use it for a different system you need to change the script to use your own class |
|
8 |
|
9 Run the script using: python convert_ipral.py <your options> |
|
10 |
|
11 Examples |
|
12 -------- |
|
13 # This will read all files starting with "l" from "my_dir". |
|
14 # It will guess the measurement ID based on the date of the files, and will assume measurement number 00. |
|
15 # For example, the new measurment id could be 20120101mb00 |
|
16 python convert_ipral.py my_dir l*. |
|
17 |
|
18 # This will use the measurement id you defined. |
|
19 python convert_ipral.py my_dir l*. -m 20120204mb32 # It will create the file 20120204mb32.nc |
|
20 |
|
21 Help string |
|
22 ----------- |
|
23 # To get this, run: python convert_ipral.py -h |
|
24 usage: convert_ipral.py [-h] [-m MEASUREMENT_ID] [-n MEASUREMENT_NUMBER] |
|
25 [directory] [searchstring] |
|
26 |
|
27 positional arguments: |
|
28 directory Directory with licel files. |
|
29 searchstring Processing system id. |
|
30 |
|
31 optional arguments: |
|
32 -h, --help show this help message and exit |
|
33 -m MEASUREMENT_ID, --measurement_id MEASUREMENT_ID |
|
34 The new measurement id |
|
35 -n MEASUREMENT_NUMBER, --measurement_number MEASUREMENT_NUMBER |
|
36 The measurement number for the date, if no id is |
|
37 provided |
|
38 |
|
39 """ |
|
40 |
|
41 import glob |
|
42 import os |
|
43 import argparse |
|
44 |
|
45 from atmospheric_lidar import ipral |
|
46 |
|
47 |
|
48 if __name__ == "__main__": |
|
49 |
|
50 # Define the command line arguments. |
|
51 parser = argparse.ArgumentParser() |
|
52 parser.add_argument("directory", nargs='?', help="Directory with licel files.", default='.') |
|
53 parser.add_argument("searchstring", nargs='?', help="Processing system id.", default="*.*") |
|
54 parser.add_argument("-m", "--measurement_id", help="The new measurement id", default=None) |
|
55 parser.add_argument("-n", "--measurement_number", help="The measurement number for the date, if no id is provided", default="00") |
|
56 args = parser.parse_args() |
|
57 |
|
58 |
|
59 # Get a list of files to convert |
|
60 search_str = os.path.join(args.directory, args.searchstring) |
|
61 files = glob.glob(search_str) |
|
62 |
|
63 if files: |
|
64 # Read the files |
|
65 print "Reading {0} files from {1}".format(len(files), args.directory) |
|
66 measurement = ipral.IpralLidarMeasurement(files) |
|
67 |
|
68 #Save the netcdf |
|
69 print "Saving netcdf." |
|
70 measurement.set_measurement_id(args.measurement_id, args.measurement_number) |
|
71 measurement.save_as_netcdf() |
|
72 print "Created file ", measurement.scc_filename |
|
73 else: |
|
74 print "No files found when searching for ", search_str |