Include all parameters from the NetCDF parameters file in the final output file.

Fri, 22 Sep 2017 15:02:53 +0300

author
Victor Nicolae <victor.nicolae@inoe.ro>
date
Fri, 22 Sep 2017 15:02:53 +0300
changeset 76
e59cdc4fd4c0
parent 75
33826498a125
child 80
48d5e9876708

Include all parameters from the NetCDF parameters file in the final output file.

Better inform the user if any mandatory parameter misses from the file.

In case of extra (optional) parameters, allow missing values in the output file.

atmospheric_lidar/generic.py file | annotate | diff | comparison | revisions
--- a/atmospheric_lidar/generic.py	Fri Sep 22 14:33:51 2017 +0300
+++ b/atmospheric_lidar/generic.py	Fri Sep 22 15:02:53 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):
 

mercurial