ó
ø`9Sc           @   sU   d  d l  Z  d  d l Z d  d l m Z d  d l Td g Z d e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   txt(   t   *t   RamanOutputc        ?   B   sR  e  Z d  Z d Z e d d d ƒ e d d d ƒ e d d d ƒ e d	 d
 d ƒ e d d d ƒ e d d d ƒ e d d d ƒ e d d d ƒ e d d d ƒ e d d d ƒ e d d d ƒ e d d d ƒ e d d d ƒ e d  d! d ƒ e d" d# d ƒ e d$ d% d ƒ e d& d' d( e j ƒ e d) d* d( e j ƒ e d+ d, d( e j ƒ e d- d. d( e j ƒ e d/ d0 d( e j ƒ e d1 d2 d( e j ƒ e d3 d4 d5 ƒ e d6 d7 d5 ƒ e d8 d9 d5 ƒ e d: d; d( e j ƒ e d< d= d( e j ƒ e d> d? d( e j d@ e ƒe dA dB d( e j d@ e ƒe dC dD d( e j d@ e ƒe dE dF d ƒ e dG dH d ƒ e dI dJ d ƒ e dK dL d ƒ e dM dN d ƒ e dO dP d ƒ e dQ dR d ƒ e dS dT d ƒ e dU dV d ƒ e dW dX d ƒ e dY dZ d ƒ e d[ d\ d ƒ e d] d^ d ƒ e d_ d` d ƒ e da db d ƒ e dc dd d ƒ e de df d ƒ e dg dh d ƒ e di dj d ƒ e dk dl d( e j d@ e ƒe dm dn d( e j d@ e ƒe do dp d d@ e ƒe dq dr d d@ e ƒe ds dt d d@ e ƒe du dv d d@ e ƒe dw dx d d@ e ƒe dy dz d d@ e ƒe d{ d| d d@ e ƒg: Z d} Z	 d~ Z
 d Z d€ Z d Z d‚ Z dƒ Z d„ „  Z d… „  Z RS(†   s  Output data for aerosol backscatter and lidar ratio retrieval algorithm
    utilizing Raman lidar signals.

    Attributes to be read from a database:
      - 'latitude', 'longitude', 'altitude', 'startDate', 'stopDate',
        'startTime', 'stopTime': same as in 'PreparedLidarInput'.
      - 'retrievalDate', 'retrievalTime': date and time of the retrieval;
      - 'gridStep', 'gridZenithAngle': parameters of the data grid used for
        output data profiles (similar to those of 'PreparedLidarInput').

      - 'wavelength<channel>', where '<channel>' is either 'Source' or 'Raman':
        wavelengths of the lidar channels used in the retrieval, in nanometers.
        'Source' wavelength may be either 355.0 or 532.0, whereas the
        corresponding 'Raman' wavelength has to be 387.0 and 607.0
        respectively.
      - 'polarizationSource': polarization ID of the source lidar channel,
        (either 0 meaning "unpolarized" or 3 meaning "parallel-polarized").

      - 'profile<characteristic>', where '<characteristic>' is either
        'Backscatter' or 'Lidar': retrieved profiles for aerosol backscatter
        ratio (aerosol backscatter divided by molecular backscatter) and
        aerosol lidar ratio (aerosol extinction divided by aerosol
        backscatter).

      - 'measuredSignal<channel>', 'calculatedSignal<channel>': measured and
        calculated lidar signals for different lidar channels, divided by their
        average values around the reference points, with molecular components
        removed.
      - 'signalId<channel>': 'localId' fields of the lidar inputs.

      - 'atmoModel': textual identifier for the molecular atmosphere (copied
        from the lidar database).
      - 'dispersion<channel>': Numpy array holding weighting coefficients for
        the lidar signal equations.

      - 'molBackscatter': molecular backscatter profile (copied from the lidar
        input).
      - 'aerBackscatter', 'aerExtinction': aerosol backscatter and extinction
        profiles (calculated from 'molBackscatter' and the retrieved data).

      - 'weighting<channel>': weighting coefficients for lidar signals (copied
        from the algorithm params).
      - 'weightSmooth<characteristic>': weighting coefficients for smoothness
        terms of the retrieval equations (copied from the algorithm params).

      - 'molDepolarization', 'attenuationRatio': molecular depolarization ratio
        and lidar channel attenuation ratio (copied from the algorithm params).

      - 'molThicknessError<channel>', 'aerosolThicknessError<channel>',
        'totalBackscatterError<channel>': estimations of the atmospheric
        relative errors (copied from the corresponding 'PreparedLidarInput'
        instances).

      - 'ratio<channel>': retrieved correction coefficients for the lidar
        equations.
      - 'residual<channel>': square root of the squared lidar equation
        residual, integrated over the retrieval interval.
      - 'resSmooth<characteristic>': square root of the squared approximated
        second order derivative of the retrieved aerosol characteristic
        profile, integrated over the retrieval interval.

      - 'profileDispersion<...>', 'ratioDispersion<...>': dispersions of the
        corresponding 'profile<...>' and 'ratio<...>' retrieved parameters that
        had been obtained while applying a predefined set of perturbances to
        the input data.

    Attributes that are calculated manually in 'onDataLoaded':
      - 'gridHeightStep': height step of the data grid (similar to
        'PreparedLidarInput').t   AerosolProfilest   latitudet   Latitudet   SINGLEt	   longitudet	   Longitudet   altitudet   Altitudet	   startDatet	   StartDatet   DATEt   stopDatet   StopDatet	   startTimet	   StartTimet   TIMEt   stopTimet   StopTimet   retrievalDatet   RetrievalDatet   retrievalTimet   RetrievalTimet   gridStept   Stept   gridZenithAnglet   Zenitht   firstInputIndexSourcet
   LeftSourcet   SMALLINTt   firstInputIndexRamant	   LeftRamant   wavelengthSourcet   Wavelength_Sourcet   wavelengthRamant   Wavelength_Ramant   polarizationSourcet   Polarization_Sourcet   profileBackscattert   BackscatterMin1Profilet
   LONGBINARYt   profileLidart   LidarRatioProfilet   measuredSignalSourcet   Measured_Sourcet   measuredSignalRamant   Measured_Ramant   calculatedSignalSourcet   Calculated_Sourcet   calculatedSignalRamant   Calculated_Ramant   signalIdSourcet   IDLocal_Sourcet   VARCHARt   signalIdRamant   IDLocal_Ramant   atmosphereModelt	   AtmoModelt   dispersionSourcet   StdDeviation_Sourcet   dispersionRamant   StdDeviation_Ramant   molBackscattert   MolBackscattert   requiredt   aerBackscattert   AerBackscattert   aerExtinctiont   AerExtinctiont   weightingSourcet   Weight_Sourcet   weightingRamant   Weight_Ramant   weightSmoothBackscattert   WeightSmooth_Backscattert   weightSmoothLidart   WeightSmooth_Lidart   molDepolarizationt
   MolDepolart   attenuationRatiot   AttenuationRatiot   molThicknessErrorSources   RE OMT_Sourcet   molThicknessErrorRamans   RE OMT_Ramant   aerosolThicknessErrorSources   RE OAT_Sourcet   aerosolThicknessErrorRamans   RE OAT_Ramant   totalBackscatterErrorSources   RE GBS_Sourcet   totalBackscatterErrorRamans   RE GBS_Ramant   ratioSourcet   Ratio_Sourcet
   ratioRamant   Ratio_Ramant   residualSourcet   Residual_Sourcet   residualRamant   Residual_Ramant   resSmoothBackscattert   ResSmooth_Backscattert   resSmoothLidart   ResSmooth_Lidart   resDeviateLidart   ResDeviate_Lidart   profileDispersionBackscattert   BackscatterMin1Dispersiont   profileDispersionLidart   LidarRatioDispersiont   ratioDispersionSourcet   RatioDispersion_Sourcet   ratioDispersionRamant   RatioDispersion_Ramant   perturbanceEvaluationst   PerturbanceEvaluationst   whiteNoiseSourcet   WhiteNoise_Sourcet   whiteNoiseRamant   WhiteNoise_Ramant   linearNoiseSourcet   LinearNoise_Sourcet   linearNoiseRamant   LinearNoise_Ramans9   Raman retrieval output database file could not be createds[   Raman retrieval output file is not a valid Access database or may not be opened for readingsC   Ramam retrieval output: failed to query data from the database files/   Raman retrieval output file format is invalid: s;   Failed to write the data to the Raman retrieval output files+   Failed to read the data from the Excel files*   Failed to write the data to the Excel filec         C   sU   |  j  d  k s |  j d  k r* d  |  _ n' |  j  t j |  j t j d ƒ |  _ d  S(   Ng     €f@(   R   t   NoneR   t   gridHeigthStept   matht   cost   pit   gridHeightStep(   t   self(    (    s   code\RamanOutput.pyt   onDataLoadedå   s    c         C   sJ   xC |  j  ƒ  D]5 } t |  | ƒ d k r d t j |  j | ƒ ƒ Sq Wd S(   s   Return an error message describing the malformed data or 'None' if
        all the attribute values are plausible and consistent.s"   %s database field contains no dataN(   t   getRequiredAttributeNamest   getattrRy   R    t   quotet   getFieldName(   R   t   name(    (    s   code\RamanOutput.pyt   getErrorMessageí   s    (   t   __name__t
   __module__t   __doc__t	   tableNamet	   DataFieldt   numpyt   float32t   Falset   fieldst   createDatabaseErrorMessaget   openDatabaseErrorMessaget   queryFailureErrorMessaget   invalidFormatErrorPrefixt   writeDataErrorMessaget   importDataFromExcelErrorPrefixt   exportDataToExcelErrorPrefixR€   R†   (    (    (    s   code\RamanOutput.pyR      s´   E													(   R{   RŒ   t   common.utilsR    t   common.DataRecordt   __all__t
   DataRecordR   (    (    (    s   code\RamanOutput.pyt   <module>   s
   
	