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