example_script/convert_lilas.py

Thu, 16 Feb 2017 09:22:05 +0200

author
Ioannis <ioannis@inoe.ro>
date
Thu, 16 Feb 2017 09:22:05 +0200
changeset 48
673843d7f9d8
parent 42
62da57352e86
permissions
-rw-r--r--

Adding command line script.

Rename of convertion script folder

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

mercurial