binietoglou@42: """ Sample script to convert licel files to SCC netcdf format. binietoglou@42: binietoglou@42: The script assumes the following things: binietoglou@42: binietoglou@42: 1. You have already installed the atmospheric_lidar module (e.g. using pip). binietoglou@42: 2. You have create a class in a file "lilas" describing your system (described the readme file). binietoglou@42: If you want to use it for a different system you need to change the script to use your own class binietoglou@42: binietoglou@42: Run the script using: python convert_lilas.py binietoglou@42: binietoglou@42: Examples binietoglou@42: -------- binietoglou@42: # This will read all files starting with "l" from "my_dir". binietoglou@42: # It will guess the measurement ID based on the date of the files, and will assume measurement number 00. binietoglou@42: # For example, the new measurment id could be 20120101mb00 binietoglou@42: python convert_lilas.py my_dir l*. binietoglou@42: binietoglou@42: # This will use the measurement id you defined. binietoglou@42: python convert_lilas.py my_dir l*. -m 20120204mb32 # It will create the file 20120204mb32.nc binietoglou@42: binietoglou@42: Help string binietoglou@42: ----------- binietoglou@42: # To get this, run: python convert_lilas.py -h binietoglou@42: usage: convert_lilas.py [-h] [-m MEASUREMENT_ID] [-n MEASUREMENT_NUMBER] binietoglou@42: [directory] [searchstring] binietoglou@42: binietoglou@42: positional arguments: binietoglou@42: directory Directory with licel files. binietoglou@42: searchstring Processing system id. binietoglou@42: binietoglou@42: optional arguments: binietoglou@42: -h, --help show this help message and exit binietoglou@42: -m MEASUREMENT_ID, --measurement_id MEASUREMENT_ID binietoglou@42: The new measurement id binietoglou@42: -n MEASUREMENT_NUMBER, --measurement_number MEASUREMENT_NUMBER binietoglou@42: The measurement number for the date, if no id is binietoglou@42: provided binietoglou@42: binietoglou@42: """ binietoglou@42: binietoglou@42: import glob binietoglou@42: import os binietoglou@42: import argparse binietoglou@42: binietoglou@42: from atmospheric_lidar import lilas binietoglou@42: binietoglou@42: binietoglou@42: if __name__ == "__main__": binietoglou@42: binietoglou@42: # Define the command line arguments. binietoglou@42: parser = argparse.ArgumentParser() binietoglou@42: parser.add_argument("directory", nargs='?', help="Directory with licel files.", default='.') binietoglou@42: parser.add_argument("searchstring", nargs='?', help="Processing system id.", default="*.*") binietoglou@42: parser.add_argument("-m", "--measurement_id", help="The new measurement id", default=None) binietoglou@42: parser.add_argument("-n", "--measurement_number", help="The measurement number for the date, if no id is provided", default="00") binietoglou@42: args = parser.parse_args() binietoglou@42: binietoglou@42: binietoglou@42: # Get a list of files to convert binietoglou@42: search_str = os.path.join(args.directory, args.searchstring) binietoglou@42: files = glob.glob(search_str) binietoglou@42: binietoglou@42: if files: binietoglou@42: # Read the files binietoglou@42: print "Reading {0} files from {1}".format(len(files), args.directory) binietoglou@42: measurement = lilas.LilasLidarMeasurement(files) binietoglou@42: binietoglou@42: #Save the netcdf binietoglou@42: print "Saving netcdf." binietoglou@42: measurement.set_measurement_id(args.measurement_id, args.measurement_number) binietoglou@42: measurement.save_as_netcdf() binietoglou@42: print "Created file ", measurement.scc_filename binietoglou@42: else: binietoglou@42: print "No files found when searching for ", search_str