atmospheric_lidar/raymetrics.py

Fri, 23 Feb 2018 08:58:50 +0200

author
Iannis <i.binietoglou@impworks.gr>
date
Fri, 23 Feb 2018 08:58:50 +0200
changeset 127
6051a9bae77b
parent 125
a8670c403823
child 129
6f902a45b83d
permissions
-rw-r--r--

Merge from 126:41f7e71ea296

""" Code to read Raymetrics version of Licel binary files."""
import datetime
import logging

import pytz

from .licel import LicelFile, LicelLidarMeasurement, LicelChannel

logger = logging.getLogger(__name__)


class RaymetricsLidarMeasurement(LicelLidarMeasurement):

    def __init__(self, file_list=None, use_id_as_name=False, licel_timezone='UTC'):
        self.photodiodes = {}  # Add photodiode dictionary
        super(RaymetricsLidarMeasurement, self).__init__(file_list=file_list,
                                                         use_id_as_name=use_id_as_name,
                                                         licel_timezone=licel_timezone)

    def _create_or_append_channel(self, current_file):

        for channel_name, channel in current_file.channels.items():
            if channel_name[0:2] == 'PD':
                if channel_name not in self.photodiodes:
                    self.photodiodes[channel_name] = PhotodiodeChannel()
                self.photodiodes[channel_name].append_file(current_file.start_time, channel)
            else:
                if channel_name not in self.channels:
                    self.channels[channel_name] = self.channel_class()
                self.channels[channel_name].append_file(current_file.start_time, channel)


class ScanningFile(LicelFile):
    licel_file_header_format = ['Filename',
                                'StartDate StartTime EndDate EndTime Altitude Longtitude Latitude ZenithAngle Temperature Pressure', # Appart from Site that is read manually
                                'azimuth_start azimuth_finish azimuth_step zenith_start zenith_finish zenith_step azimuth_offset',
                                'LS1 Rate1 LS2 Rate2 DataSets', ]
    licel_file_channel_format = 'Active AnalogPhoton LaserUsed DataPoints 1 HV BinW Wavelength d1 d2 d3 d4 ADCbits NShots Discriminator ID'


    def _read_rest_of_header(self, f):
        """ Read the rest of the header lines, after line 2. """
        raw_info = {}

        third_line = f.readline()
        raw_info.update(self.match_lines(third_line, self.licel_file_header_format[2]))

        fourth_line = f.readline()
        raw_info.update(self.match_lines(fourth_line, self.licel_file_header_format[3]))
        return raw_info


class ScanningLidarMeasurement(RaymetricsLidarMeasurement):
    file_class = ScanningFile
    channel_class = LicelChannel


class PhotodiodeChannel(LicelChannel):

    def _assign_properties(self, file_channel):
        """ In contrast with normal channels, don't check for constant points."""
        self._assign_unique_property('name', file_channel.channel_name)
        self._assign_unique_property('resolution', file_channel.dz)
        self._assign_unique_property('wavelength', file_channel.wavelength)
        self._assign_unique_property('adcbits', file_channel.adcbits)
        self._assign_unique_property('active', file_channel.active)
        self._assign_unique_property('laser_user', file_channel.laser_user)
        self._assign_unique_property('adcbints', file_channel.adcbits)
        self._assign_unique_property('analog_photon_string', file_channel.analog_photon_string)

mercurial