example_script/convert_ipral.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 46
d84759347999
permissions
-rw-r--r--

Adding command line script.

Rename of convertion script folder

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

mercurial