ó
ø`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   PolarOutputc        ;   B   s
  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 j ƒ 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- d. d$ e j ƒ e d/ d0 d1 ƒ e d2 d3 d1 ƒ e d4 d5 d1 ƒ e d6 d7 d$ e j ƒ e d8 d9 d$ e j ƒ e d: d; d$ e j d< e ƒe d= d> d$ e j d< e ƒe d? d@ d$ e j d< e ƒ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 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 j d< e ƒe di dj d$ e j d< e ƒe dk dl d d< e ƒe dm dn d d< e ƒe do dp d d< e ƒe dq dr d d< e ƒe ds dt d d< e ƒg6 Z du Z	 dv Z
 dw Z dx Z dy Z dz Z d{ Z d| „  Z d} „  Z RS(~   s×  Output data for aerosol backscatter and depolarization retrieval
    algorithm utilizing polarized 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').

      - 'polarizationBase': polarization ID of the base lidar channel,
        (either 0 meaning "unpolarized" or 3 meaning "parallel-polarized").

      - 'backscatterParallel', 'backscatterCross': retrieved aerosol
        parallel-polarized and cross-polarized backscatter profiles.

      - 'measuredSignalBase', 'calculatedSignalBase': measured and calculated
        lidar signals, divided by their average values around the reference
        point, with molecular components removed.
      - 'measuredSignalCross', 'calculatedSignalCross': measured and calculated
        cross-polarized lidar signal ratio profiles.

      - 'signalId<channel>', where '<channel>' is either 'Base' or 'Cross':
        'localId' fields of the lidar inputs.

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

      - 'molBackscatter': molecular backscatter profile (copied from the lidar
        input).

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

      - 'parallelLeakage', 'molDepolarization', 'lidarRatio' parallel leakage
        of the cross-polarized lidar channel, molecular depolarization ratio,
        and aerosol lidar ratio (copied from the algorithm params).

      - 'aerBackscatterRatioRef': retrieved aerosol backscatter ratio at the
        reference point.
      - 'lidarCorrection': retrieved cross-polarized lidar correction factor.

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

      - 'residual<channel>': square root of the squared lidar equation
        residual, integrated over the retrieval interval.
      - 'resSmoothParallel', 'resSmoothCross': square root of the squared
        approximated second order derivative of the retrieved aerosol
        backscatter profiles, integrated over the retrieval interval.

    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   polarizationBaset   Polarization_Baset   SMALLINTt   firstInputIndexBaset   LeftBaset   firstInputIndexCrosst	   LeftCrosst   backscatterParallelt   Backscatter_Parallelt
   LONGBINARYt   backscatterCrosst   Backscatter_Crosst   measuredSignalBaset   Measured_Baset   measuredSignalCrosst   Measured_Crosst   calculatedSignalBaset   Calculated_Baset   calculatedSignalCrosst   Calculated_Crosst   signalIdBaset   IDLocal_Baset   VARCHARt   signalIdCrosst   IDLocal_Crosst   atmosphereModelt	   AtmoModelt   dispersionBaset   StdDeviation_Baset   dispersionCrosst   StdDeviation_Crosst   molBackscattert   MolBackscattert   requiredt   aerBackscattert   AerBackscattert   aerExtinctiont   AerExtinctiont   weightingBaset   Weight_Baset   weightingCrosst   Weight_Crosst   weightSmoothParallelt   WeightSmooth_Parallelt   weightSmoothCrosst   WeightSmooth_Crosst   parallelLeakaget   ParallelLeakaget   molDepolarizationt
   MolDepolart
   lidarRatiot
   LidarRatiot   aerBackscatterRatioReft   AerRatioReft   lidarCorrectiont   LidarCorrectiont   molThicknessErrorBases   RE OMT_Baset   molThicknessErrorCrosss   RE OMT_Crosst   aerosolThicknessErrorBases   RE OAT_Baset   aerosolThicknessErrorCrosss   RE OAT_Crosst   totalBackscatterErrorBases   RE GBS_Baset   totalBackscatterErrorCrosss   RE GBS_Crosst   residualBaset   Residual_Baset   residualCrosst   Residual_Crosst   resSmoothParallelt   ResSmooth_Parallelt   resSmoothCrosst   ResSmooth_Crosst   backscatterDispersionParallelt   BackscatterDispersion_Parallelt   depolarizationDispersiont   DepolarizationDispersiont   perturbanceEvaluationst   PerturbanceEvaluationst   whiteNoiseBaset   WhiteNoise_Baset   whiteNoiseCrosst   WhiteNoise_Crosst   linearNoiseBaset   LinearNoise_Baset   linearNoiseCrosst   LinearNoise_CrosssB   Depolarization retrieval output database file could not be createdsd   Depolarization retrieval output file is not a valid Access database or may not be opened for readingsL   Depolarization retrieval output: failed to query data from the database files8   Depolarization retrieval output file format is invalid: sD   Failed to write the data to the depolarization 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\PolarOutput.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   getattrRq   R    t   quotet   getFieldName(   Rw   t   name(    (    s   code\PolarOutput.pyt   getErrorMessageÚ   s    (   t   __name__t
   __module__t   __doc__t	   tableNamet	   DataFieldt   numpyt   float32t   Falset   fieldst   createDatabaseErrorMessaget   openDatabaseErrorMessaget   queryFailureErrorMessaget   invalidFormatErrorPrefixt   writeDataErrorMessaget   importDataFromExcelErrorPrefixt   exportDataToExcelErrorPrefixRx   R~   (    (    (    s   code\PolarOutput.pyR      s¨   =											(   Rs   R„   t   common.utilsR    t   common.DataRecordt   __all__t
   DataRecordR   (    (    (    s   code\PolarOutput.pyt   <module>   s
   
	