Merge from 79:1d3833c4d432

Thu, 05 Oct 2017 14:19:37 +0300

author
Iannis <ulalume3@yahoo.com>
date
Thu, 05 Oct 2017 14:19:37 +0300
changeset 80
48d5e9876708
parent 79
7261397d64dc (current diff)
parent 76
e59cdc4fd4c0 (diff)
child 82
01fdb725ca59

Merge from 79:1d3833c4d432

atmospheric_lidar/generic.py file | annotate | diff | comparison | revisions
--- a/atmospheric_lidar/generic.py	Thu Oct 05 14:19:08 2017 +0300
+++ b/atmospheric_lidar/generic.py	Thu Oct 05 14:19:37 2017 +0300
@@ -334,12 +334,20 @@
         temp_v = f.createVariable(channel_var, variable_type, ('channels',))
         for n, channel in enumerate(channels):
             temp_v[n] = params.channel_parameters[channel][channel_var]
-
-        # Write the values of fixed channel parameters
-        for (var, t) in channel_variables.iteritems():
-            temp_v = f.createVariable(var, t[1], t[0])
+        
+        # Write the values of fixed channel parameters:
+        fill_value = -9999
+        for param in self._get_provided_extra_parameters():
+            if param in channel_variables.keys():
+                temp_v = f.createVariable(param, channel_variables[param][1], channel_variables[param][0])
+            else:
+                temp_v = f.createVariable(param, 'd', ('channels',), fill_value = fill_value)
+                
             for (channel, n) in zip(channels, range(len(channels))):
-                temp_v[n] = params.channel_parameters[channel][var]
+                try:
+                    temp_v[n] = params.channel_parameters[channel][param]
+                except KeyError: # The parameter was not provided for this channel so we mask the value.
+                    temp_v[n] = fill_value
 
         # Write the id_timescale values
         temp_id_timescale = f.createVariable('id_timescale', 'i', ('channels',))
@@ -403,6 +411,34 @@
              'DAQ_Range': (('channels',), 'd'),
              }
         return channel_variables
+        
+    def _get_provided_extra_parameters(self):
+        # When looking for non-mandatory channel parameters, ignore the following parameter names:
+        ignore = ['channel_ID', 'channel string ID', 'Depolarization_Factor', 'Laser_Shots']
+        
+        channels = self.channels.keys()
+        params = self.extra_netcdf_parameters.channel_parameters
+        mandatory = self._get_scc_mandatory_channel_variables()
+        
+        # Get all the provided extra parameters (both mandatory and optional):
+        provided_extra_parameters = []
+        for (channel, n) in zip(channels, range(len(channels))):
+            # Check all the mandatory parameters are provided for each of the channels:
+            for var in mandatory.keys():
+                if var not in params[channel].keys():
+                    raise ValueError ("Mandatory parameter '{0}' not provided for channel {1}!".format(
+                        var,
+                        channel
+                    ))
+                    
+            provided_extra_parameters.extend(params[channel].keys())
+            
+        provided_extra_parameters = set(provided_extra_parameters)
+        # Discard certain parameter names:
+        for param in ignore:
+            provided_extra_parameters.discard(param)
+            
+        return provided_extra_parameters
 
     def add_dark_measurements_to_netcdf(self, f, channels):
 
--- a/atmospheric_lidar/scripts/licel2scc.py	Thu Oct 05 14:19:08 2017 +0300
+++ b/atmospheric_lidar/scripts/licel2scc.py	Thu Oct 05 14:19:37 2017 +0300
@@ -74,9 +74,8 @@
     # Define the command line argument
     parser = argparse.ArgumentParser(description="A program to convert Licel binary files to the SCC NetCDF format.")
     parser.add_argument("parameter_file", help="The path to a parameter file linking licel and SCC channels.")
-    parser.add_argument("directory", nargs='?', help="Directory containing licel files (default '.')", default='.')
-    parser.add_argument("search_string", nargs='?', help="Search string for files in directory (default '*.*')",
-                        default="*.*")
+    parser.add_argument("files", nargs='?', help="Location of licel files. Use relative path and filename wildcards. (default './*.*')",
+                        default="./*.*")
     parser.add_argument("-i", '--id_as_name',
                         help="Use transient digitizer ids as channel names, instead of descriptive names",
                         action="store_true")
@@ -112,12 +111,11 @@
         sys.exit(0)
 
     # Get a list of files to convert
-    search_str = os.path.join(args.directory, args.search_string)
-    files = glob.glob(search_str)
+    files = glob.glob(args.files)
 
     if files:
         # Read the files
-        logger.info("Reading {0} files from {1}".format(len(files), args.directory))
+        logger.info("Reading {0} files from {1}".format(len(files), os.path.abspath(os.path.dirname(args.files))))
         CustomLidarMeasurement = create_custom_class(args.parameter_file, args.id_as_name, args.temperature,
                                                      args.pressure)
         measurement = CustomLidarMeasurement(files)
--- a/readme.rst	Thu Oct 05 14:19:08 2017 +0300
+++ b/readme.rst	Thu Oct 05 14:19:37 2017 +0300
@@ -33,8 +33,8 @@
     positional arguments:
       parameter_file        The path to a parameter file linking licel and SCC
                             channels.
-      directory             Directory containing licel files (default '.')
-      search_string         Search string for files in directory (default '*.*')
+      files                 Location of licel files. Use relative path and
+                            filename wildcards. (default './*.*')
 
     optional arguments:
       -h, --help            show this help message and exit

mercurial