example_scripts/convert_ipral.py

Fri, 31 May 2019 14:52:42 +0300

author
Iannis <i.binietoglou@impworks.gr>
date
Fri, 31 May 2019 14:52:42 +0300
changeset 178
804313c093a8
parent 168
9fed2446a59f
permissions
-rw-r--r--

Added support for fixed point measuremtns of scanning files.

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

mercurial