atmospheric_lidar/diva.py

changeset 114
d11a94f03753
parent 113
b5bbfee2a898
child 115
c2ecdcc2bb88
--- a/atmospheric_lidar/diva.py	Fri Dec 15 13:33:10 2017 +0200
+++ b/atmospheric_lidar/diva.py	Thu Jan 04 14:21:17 2018 +0200
@@ -98,7 +98,7 @@
                 group_name = "channel_{0}".format(channel_name)  # Give channels groups a standard name
                 g = f.createGroup(group_name)
                 g.long_name = channel_parameters['long_name']
-                g.detector_manufacturer = channel_parameters['long_name']    # Optional
+                g.detector_manufacturer = channel_parameters['detector_manifacturer']    # Optional
                 g.detector_model = channel_parameters['detector_model']
                 g.daq_manufacturer = channel_parameters['daq_manufacturer']
                 g.daq_model = channel_parameters['daq_model']
@@ -116,7 +116,7 @@
                 laser_rep_rate.long_name = 'nominal laser repetition rate'
                 laser_rep_rate.units = 'Hz'
 
-                emission_energy = g.createVariable('emission_energy', datatype='f8', dimensions=('profile',))
+                emission_energy = g.createVariable('emission_energy', datatype='f8', )  # or dimensions=('profile',)
                 emission_energy.long_name = 'emission energy per pulse'
                 emission_energy.units = 'mJ'
                 emission_energy.standard_name = 'radiation_wavelength'
@@ -154,7 +154,7 @@
                 detection_pol = g.createVariable('detection_polarization', datatype='b')
                 detection_pol.long_name = 'nominal detection poalrization'
                 detection_pol.flag_values = '0b 1b 2b'
-                detection_pol.flag_meanings = 'linear circular none'
+                detection_pol.flag_meanings = 'linear circular total'
 
                 polarizer_angle = g.createVariable('polarizer_angle', datatype='f4', dimensions=('profile', ), zlib=True)
                 polarizer_angle.long_name = 'polarizer angle in respect to laser plane of polarization'
@@ -237,4 +237,124 @@
                 signal_stddev.coordinates = "time"
 
                 # Assign variables
-                # TBD
\ No newline at end of file
+                name[:] = channel_name
+                laser_rep_rate[:] = channel_parameters['laser_repetition_rate']
+                emission_energy[:] = channel_parameters['emission_energy']
+                emission_pol[:] = self._emission_pol_flag(channel_parameters['emission_polarization'])
+                fov[:] = channel_parameters['fov']
+                detector_type[:] = self._detector_type_flag(channel_parameters['detector_type'])
+                detection_mode[:] = self._detection_mode_flag(channel_parameters['detection_mode'])
+                detection_fwhm[:] = channel_parameters['filter_fwhm']
+                detection_pol[:] = self._detection_pol_flag(channel_parameters['detection_polarization'])
+                polarizer_angle[:] = channel_parameters['polarizer_angle']  # For now, assumed constant.
+                dead_time_model[:] = self._deadtime_model_flag(channel_parameters['dead_time_model'])
+                dead_time[:] = channel_parameters['dead_time']
+                bin_length[:] = channel_parameters['bin_length']
+
+    def _deadtime_model_flag(self, model_str):
+        """ Convert dead-time model string to byte flag.
+
+        Parameters
+        ----------
+        model_str : str
+           String describing the dead-time model (one of paralyzable, non-paralyzable, or other)
+
+        Returns
+        -------
+        : int
+           Byte encoding of dead-time model
+        """
+        choices = {'paralyzable': 0,
+                   'non-paralyzable': 1,
+                   'other': 2}
+
+        if model_str not in choices.keys():
+            raise ValueError('Dead-time model is not one of {0}: {1}'.format(choices.keys(), model_str))
+
+        return choices[model_str]
+
+    def _detection_pol_flag(self, pol_str):
+        """ Convert detection  polarization string to byte flag.
+
+        Parameters
+        ----------
+        pol_str : str
+           String describing the detection polarization (one of linear, circular, or total)
+
+        Returns
+        -------
+        : int
+           Byte encoding of detection polarization
+        """
+        choices = {'linear': 0,
+                   'circular': 1,
+                   'total': 2}
+
+        if  pol_str not in choices.keys():
+            raise ValueError('Detection polarization is not one of {0}: {1}'.format(choices.keys(), pol_str))
+
+        return choices[pol_str]
+
+    def _detection_mode_flag(self, mode_str):
+        """ Convert detection  mode string to byte flag.
+
+        Parameters
+        ----------
+        mode_str : str
+           String describing the detector mode (one of photon-counting or analog)
+
+        Returns
+        -------
+        : int
+           Byte encoding of detection mode
+        """
+        choices = {'analog': 0,
+                   'photon-counting': 1,}
+
+        if  mode_str not in choices.keys():
+            raise ValueError('Detection mode is not one of {0}: {1}'.format(choices.keys(), mode_str))
+
+        return choices[mode_str]
+
+    def _detector_type_flag(self, type_string):
+        """ Convert emission string to byte flag.
+
+        Parameters
+        ----------
+        type_string : str
+           String describing the detector type (one of APD or PMT)
+
+        Returns
+        -------
+        : int
+           Byte encoding of detector type
+        """
+        choices = {'PMT': 0,
+                   'APD': 1,}
+
+        if  type_string not in choices.keys():
+            raise ValueError('Detector type is not one of {0}: {1}'.format(choices.keys(), type_string))
+
+        return choices[type_string]
+
+    def _emission_pol_flag(self, pol_string):
+        """ Convert emission string to byte flag.
+
+        Parameters
+        ----------
+        pol_string : str
+           String describing the polarization (one of linear, circular, or none)
+
+        Returns
+        -------
+        : int
+           Byte encoding of polarization state
+        """
+        choices = {'linaer': 0,
+                   'circular': 1,
+                   'none': 2}
+
+        if  pol_string not in choices.keys():
+            raise ValueError('Emission polarization not one of {0}: {1}'.format(choices.keys(), pol_string))
+
+        return choices[pol_string]

mercurial