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