Fixed use of dark measurements in licel2scc-depol script.

Fri, 19 Oct 2018 14:13:33 +0300

author
Iannis <i.binietoglou@impworks.gr>
date
Fri, 19 Oct 2018 14:13:33 +0300
changeset 164
e4915d84dd7d
parent 163
40331f37885f
child 165
392a714d12a2

Fixed use of dark measurements in licel2scc-depol script.

atmospheric_lidar/__init__.py file | annotate | diff | comparison | revisions
atmospheric_lidar/generic.py file | annotate | diff | comparison | revisions
atmospheric_lidar/licel_depol.py file | annotate | diff | comparison | revisions
atmospheric_lidar/scripts/licel2scc_depol.py file | annotate | diff | comparison | revisions
changelog.rst file | annotate | diff | comparison | revisions
--- a/atmospheric_lidar/__init__.py	Wed Oct 10 15:58:32 2018 +0300
+++ b/atmospheric_lidar/__init__.py	Fri Oct 19 14:13:33 2018 +0300
@@ -1,1 +1,1 @@
-__version__ = '0.3.5'
\ No newline at end of file
+__version__ = '0.3.6'
\ No newline at end of file
--- a/atmospheric_lidar/generic.py	Wed Oct 10 15:58:32 2018 +0300
+++ b/atmospheric_lidar/generic.py	Fri Oct 19 14:13:33 2018 +0300
@@ -163,9 +163,10 @@
         m.channels = dict([(channel, self.channels[channel]) for channel
                            in channel_subset])
         m.files = self.files
+
         m.update()
 
-        # Dark measurements should also be subseted.
+        # Dark measurements should also be subsetted.
         if self.dark_measurement is not None:
             dark_subset = self.dark_measurement.subset_by_channels(channel_subset)
             m.dark_measurement = dark_subset
--- a/atmospheric_lidar/licel_depol.py	Wed Oct 10 15:58:32 2018 +0300
+++ b/atmospheric_lidar/licel_depol.py	Fri Oct 19 14:13:33 2018 +0300
@@ -9,7 +9,21 @@
 
 class LicelCalibrationMeasurement(LicelLidarMeasurement):
 
-    def __init__(self, plus45_files=None, minus45_files=None,  use_id_as_name=False, licel_timezone='UTC'):
+    def __init__(self, plus45_files=None, minus45_files=None, use_id_as_name=False, licel_timezone='UTC'):
+        """Class to handle depolarization calibration measurements according to the SCC.
+
+
+        Parameters
+        ----------
+        plus45_files : list of str
+           List of paths for the plus 45 files.
+        minus45_files : list of str
+           List of paths for the minus 45 files.
+        use_id_as_name : bool
+           Defines if channels names are descriptive or transient digitizer IDs.
+        licel_timezone : str
+           String describing the timezone according to the tz database.
+        """
         # Setup the empty class
         super(LicelCalibrationMeasurement, self).__init__(use_id_as_name=use_id_as_name, licel_timezone=licel_timezone)
 
@@ -30,7 +44,8 @@
         return m
 
     def update(self):
-        """ Correct timescales after each update.
+        """
+        Correct timescales after each update.
         """
         super(LicelCalibrationMeasurement, self).update()
         self.correct_timescales()
@@ -169,3 +184,29 @@
         """ Raised when timescales are not two.
         """
         pass
+
+
+class DarkLicelCalibrationMeasurement(LicelCalibrationMeasurement):
+
+    def __init__(self, dark_files=None, use_id_as_name=False, licel_timezone='UTC'):
+        """Class to handle dark files for depolarization calibration measurements according to the SCC.
+
+        It assumes that a single sent of dark measurements will be use for both plus and minus 45 channels.
+
+        Parameters
+        ----------
+        dark_files : list of str
+           List of paths for the dark measurement files.
+        use_id_as_name : bool
+           Defines if channels names are descriptive or transient digitizer IDs.
+        licel_timezone : str
+           String describing the timezone according to the tz database.
+        """
+        # Setup the empty class
+        super(DarkLicelCalibrationMeasurement, self).__init__(dark_files, dark_files,
+                                                              use_id_as_name=use_id_as_name,
+                                                              licel_timezone=licel_timezone)
+
+    def correct_timescales(self):
+        """ For dark measuremetns, no need to correct timescales. """
+        pass
--- a/atmospheric_lidar/scripts/licel2scc_depol.py	Wed Oct 10 15:58:32 2018 +0300
+++ b/atmospheric_lidar/scripts/licel2scc_depol.py	Fri Oct 19 14:13:33 2018 +0300
@@ -7,7 +7,7 @@
 import os
 import sys
 
-from ..licel_depol import LicelCalibrationMeasurement
+from ..licel_depol import LicelCalibrationMeasurement, DarkLicelCalibrationMeasurement
 from ..__init__ import __version__
 
 logger = logging.getLogger(__name__)
@@ -60,6 +60,52 @@
     return CustomLidarMeasurement
 
 
+def create_custom_dark_class(custom_netcdf_parameter_path, use_id_as_name=False, temperature=25., pressure=1020.,
+                        licel_timezone='UTC'):
+    """ This funtion creates a custom LicelLidarMeasurement subclass,
+    based on the input provided by the users.
+
+    Parameters
+    ----------
+    custom_netcdf_parameter_path : str
+       The path to the custom channels parameters.
+    use_id_as_name : bool
+       Defines if channels names are descriptive or transient digitizer IDs.
+    temperature : float
+       The ground temperature in degrees C (default 25.0).
+    pressure : float
+       The ground pressure in hPa (default: 1020.0).
+    licel_timezone : str
+       String describing the timezone according to the tz database.
+
+    Returns
+    -------
+    CustomLidarMeasurement:
+       A custom sub-class of LicelLidarMeasurement
+    """
+    # TODO: Remove the custom netcdf parameter artifact: pass parameters as optional input argument,
+    # TODO: change setting format to YAML.
+    custom_netcdf_parameters = read_settings_file(custom_netcdf_parameter_path)
+
+    class CustomLidarMeasurement(DarkLicelCalibrationMeasurement):
+        extra_netcdf_parameters = custom_netcdf_parameters
+
+        def __init__(self, dark_files=None):
+            super(CustomLidarMeasurement, self).__init__(dark_files, use_id_as_name=use_id_as_name,
+                                                         licel_timezone=licel_timezone)
+
+        def set_PT(self):
+            ''' Sets the pressure and temperature at station level. This is used if molecular_calc parameter is
+            set to 0 (i.e. use US Standard atmosphere).
+
+            The results are stored in the info dictionary.
+            '''
+
+            self.info['Temperature'] = temperature
+            self.info['Pressure'] = pressure
+
+    return CustomLidarMeasurement
+
 def read_settings_file(settings_path):
     """ Read the settings file.
 
@@ -138,6 +184,9 @@
     CustomLidarMeasurement = create_custom_class(args.parameter_file, args.id_as_name, args.temperature,
                                                  args.pressure, args.licel_timezone)
 
+    CustomDarkMeasurement = create_custom_dark_class(args.parameter_file, args.id_as_name, args.temperature,
+                                                     args.pressure, args.licel_timezone)
+
     measurement = CustomLidarMeasurement(plus45_files, minus45_files)
     
     # Get a list of files containing dark measurements
@@ -146,7 +195,7 @@
 
         if dark_files:
             logger.debug("Using %s as dark measurements files!" % ', '.join(dark_files))
-            measurement.dark_measurement = CustomLidarMeasurement(dark_files, dark_files)
+            measurement.dark_measurement = CustomDarkMeasurement(dark_files)
         else:
             logger.warning('No dark measurement files found when searching for %s. Will not use any dark measurements.' % args.dark_files)
 
--- a/changelog.rst	Wed Oct 10 15:58:32 2018 +0300
+++ b/changelog.rst	Fri Oct 19 14:13:33 2018 +0300
@@ -3,6 +3,11 @@
 
 Unreleased
 ----------
+Fixed
+~~~~~
+- Bug in Licel2depol script, wrong handling of dark measurements.
+
+
 0.3.5 - 2018-10-10
 ------------------
 Fixed

mercurial