ó
ø`9Sc           @   s›   d  d l  Td  d l Td  d l m Z d  d l m Z d  d l m Z d  d l Td  d l Td  d l Td d g Z	 d d
 d „  ƒ  YZ
 d e f d „  ƒ  YZ d	 S(   iÿÿÿÿ(   t   *(   t   gui(   t   txt(   t   utilst   LidarTableWidgett   LidarChannelInfoc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   sr  Description of a lidar input channel of an aerosol retrieval algorithm.

    Attributes:
      - 'wavelength': nominal lidar signal wavelength in nanometers.
      - 'polarizations': a tuple of polarization IDs admissible for this lidar
        channel (see 'LidarInput.polarization'). Normally this should contain
        just a single element. The only combination of several polarization IDs
        for a single lidar channel that is currently acceptable is '(0, 3)',
        which means that the algorithm is capable of processing both
        unpolarized and parallel-polarized lidar signals in a similar
        manner.c         C   sb   | |  _  t | t ƒ r$ | f } n  t | t ƒ s9 t ‚ t d „  | Dƒ ƒ sU t ‚ | |  _ d S(   s|   It's possible to pass an ordinary integer value for 'polarizations'
        (which will be equivalent to a singleton tuple).c         s   s   |  ] } | d k Vq d S(   i    i   i   i   N(   i    i   i   i   (    (   t   .0t   polarization(    (    s   code\LidarTableWidget.pys	   <genexpr>:   s   N(   t
   wavelengtht
   isinstancet   intt   tuplet   AssertionErrort   allt   polarizations(   t   selfR   R   (    (    s   code\LidarTableWidget.pyt   __init__.   s    		c         C   s8   |  j  | j  k p7 t t |  j ƒ t | j ƒ @ƒ d k S(   s‚   Check if 'self' and 'other' lidar channels may be used together as
        input channels in a single aerosol retrieval algorithm.i    (   R   t   lent   setR   (   R   t   other(    (    s   code\LidarTableWidget.pyt   compatibleWith?   s    c         C   s"   | j  |  j  k o! | j |  j k S(   ss   Check if the given 'LidarInput' instance is acceptable as input
        data for lidar channel described by 'self'.(   R   R   R   (   R   t
   lidarInput(    (    s   code\LidarTableWidget.pyt   matchesLidarInputG   s    c         C   sR  t  g  | D] } |  j | ƒ r
 | ^ q
 ƒ } | d k r> d St j d |  j d t ƒ} | d k rÚ |  j d d f k r„ d } nH |  j d k rœ d } n0 |  j d k r´ d	 } n |  j d k rÌ d
 } n  d | | f S|  j d d f k rø d } nH |  j d k rd } n0 |  j d k r(d } n |  j d k r@d } n  d | | f Sd S(   só   Check if the given list of 'LidarInput' instances contains exactly
        one lidar measurement matching the lidar channel described by 'self'.

        Return 'None' if the checking succeeds and an appropriate error string
        otherwise.i   s   %.1f nmt	   addQuotesi    i   s   Unpolarized lidar measurements   Raman lidar measurementi   s!   Cross-polarized lidar measurements$   Parallel-polarized lidar measurements   %s at %s is not selecteds   unpolarized lidar measurementss   Raman lidar measurementss"   cross-polarized lidar measurementss%   parallel-polarized lidar measurementss   Too many %s are selected for %sN(   i    (   i    i   (   i   (   i   (   i   (   i    (   i    i   (   i   (   i   (   i   (   R   R   t   NoneR   t   quoteR   t   FalseR   (   R   t   lidarInputListR   t
   matchCountt   wavelengthStrt   channelIdStr(    (    s   code\LidarTableWidget.pyt   getErrorMessageForLidarDataN   s4    									(   t   __name__t
   __module__t   __doc__R   R   R   R   (    (    (    s   code\LidarTableWidget.pyR   !   s
   			c           B   s}   e  Z d  Z e ƒ  Z d d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z RS(   s“  Widget responsible for selection of lidar input data for an aerosol
    retrieval algorithm.

    This widget is also responsible for checking if a set of measurements
    selected by the user is suitable for a retrieval. It is assumed that lidar
    channels to be selected must correspond exactly to one of the fixed sets
    of 'LidarChannelInfo' instances specified during the initialization of the
    widget (see 'addAllowedChannelSequence'). If measurements selected by the
    user exactly match one of the allowed channel sets, then error status of
    the widget is cleared. Otherwise, an appropriate error message is set with
    'setErrorMessage'.c         C   s¸  t  j |  | ƒ g  |  _ g  |  _ g  |  _ t ƒ  } t ƒ  |  _ |  j j t	 j
 ƒ |  j j j |  j ƒ t ƒ  |  _ t t j ƒ |  _ |  j j t ƒ |  j j |  j ƒ |  j j |  j ƒ | j |  j ƒ | j d d d d ƒ |  j | ƒ |  j j t d d d d ƒ t d d d d	 ƒ t d
 d d d ƒ t d d d d ƒ t d d d d ƒ t d d d d ƒ t d d d d ƒ t d d d d ƒ t d d d d  ƒ t d! d" d# d$ ƒ g
 ƒ d  S(%   Ni    t	   startDatet   Datet   dates#   Start date of the lidar measurementt	   startTimet   TStartt   times#   Start time of the lidar measurementt   stopTimet   TStops"   Stop time of the lidar measurementR   t   Waves   %.1fs   Lidar channel wavelength (nm)R   t   Polars   %ds   Lidar channel polarization IDt   gridHeightStept   HSteps&   Height step of the lidar data grid (m)t   firstInputIndext   Lefts6   First index of the data section prepared for retrievalt   lastInputIndext   Rights5   Last index of the data section prepared for retrievalt   refPointIndext   RPs   Reference point indext   localIds   Local IDs   %ss$   Lidar measurement textual identifier(   t   StatusSignalingWidgetR   t   dataListt   allowedChannelSequencest   requiredAttributest   QVBoxLayoutt   DataTableWidgett   tablet   setSelectionModet   QAbstractItemViewt   MultiSelectiont   itemSelectionChangedt   connectt   onSelectionChangedt   LidarPlotWidgett
   signalPlott	   QSplittert   Qtt
   Horizontalt   splittert   setChildrenCollapsibleR   t	   addWidgett   setContentsMarginst	   setLayoutt
   setColumnst   TableWidgetColumn(   R   t   parentt   layout(    (    s   code\LidarTableWidget.pyR   Ž   sJ    					c         C   s~   xg t  t | ƒ ƒ D]S } t | | t ƒ s2 t ‚ x1 t  | ƒ D]# } | | j | | ƒ s? t ‚ q? Wq W|  j j | ƒ d S(   s\  Specify a set of lidar channels that should be considered as a valid
        input to an aerosol retrieval algorithm when selected by the user.

        Call this function one or more times immediately after the constructor.
        'channelSequence' has to be an ordered sequence of 'LidarChannelInfo'
        instances. The order of lidar channels specified here will be used to
        sort measurements returned by 'getData'. If several sets of lidar
        channels are specified by means of successife calls to this function,
        then any of these would be available for selection by the user.N(   t   rangeR   R	   R   R   R   R8   t   append(   R   t   channelSequencet   it   j(    (    s   code\LidarTableWidget.pyt   addAllowedChannelSequenceÇ   s
    %c         C   s   |  j  j | ƒ d S(   sš   Specify the name of a 'LidarInput' attribute that must be different
        from 'None' in order for the lidar measurement to be considered
        valid.N(   R9   RR   (   R   t   attributeName(    (    s   code\LidarTableWidget.pyt   addRequiredAttributeÚ   s    c         C   s   |  j  S(   N(   R<   (   R   (    (    s   code\LidarTableWidget.pyt   getTableWidgetá   s    c         C   s6   t  j | d ƒ  | j d |  j j ƒ  ƒ Wd  QXd  S(   NR   t   splitterState(   R   t   SettingsGroupert   setValueRH   t	   saveState(   R   t   settings(    (    s   code\LidarTableWidget.pyt   saveSettingsä   s    c         C   sd   t  j | d ƒ L | j d ƒ rD |  j j | j d ƒ j ƒ  ƒ n |  j j d d g ƒ Wd  QXd  S(   NR   RZ   iè  (   R   R[   t   containsRH   t   restoreStatet   valuet   toByteArrayt   setSizes(   R   R^   (    (    s   code\LidarTableWidget.pyt   loadSettingsè   s
    	c            sÿ   t  j ˆ j ƒ  ˆ j j ƒ  Wd  QXˆ j j ƒ  | ˆ _ t ˆ j ƒ d k rb ˆ j d ƒ d  Sˆ j j	 ˆ j ƒ xy t
 t ˆ j ƒ ƒ D]b ‰  t } x: ˆ j D]/ } t ‡  ‡ f d †  | Dƒ ƒ r¡ t } Pq¡ q¡ W| s‹ ˆ j j ˆ  ƒ q‹ q‹ Wˆ j ƒ  d  S(   Ni    sH   Lidar input database contains no records processed with TropoExport toolc         3   s%   |  ] } | j  ˆ j ˆ  ƒ Vq d  S(   N(   R   R7   (   R   t   lidarChannel(   RT   R   (    s   code\LidarTableWidget.pys	   <genexpr>  s   (   R   t   SignalBlockerR<   t
   clearTableRD   t   clearR7   R   t   setErrorMessaget   populateTableRQ   R   R8   t   anyt   Truet
   disableRowRB   (   R   t   lidarDataListt   rowIsAcceptableRS   (    (   RT   R   s   code\LidarTableWidget.pyt   connectDataListñ   s&    	c            s  |  j  ƒ  d k	 r d S|  j ƒ  ‰  d } xO |  j D]D } t ˆ  ƒ t | ƒ k r2 t ‡  f d †  | Dƒ ƒ r2 | } Pq2 q2 W| d k	 sŒ t ‚ g  } x? | D]7 } x. ˆ  D]& } | j | ƒ r¦ | j | ƒ Pq¦ q¦ Wq™ Wt | ƒ t ˆ  ƒ k oý t | ƒ k n st ‚ | S(   s   Return a list of the currently selected 'LidarInput' instances, in
        a predefined order, that is suitable for an aerosol profile retrieval,
        or 'None' if the retrieval is not possible or ambiguous for the
        currently selected lidar data.c         3   s$   |  ] } | j  ˆ  ƒ d  k Vq d  S(   N(   R   R   (   R   Rf   (   t   selectedData(    s   code\LidarTableWidget.pys	   <genexpr>,  s   N(	   t   getStatusMessageR   t   getSelectedDataR8   R   R   R   R   RR   (   R   t   matchingSequenceRS   t   orderedDataRf   R   (    (   Rr   s   code\LidarTableWidget.pyt   getData  s&    4c         C   s-   |  j  j ƒ  } g  | D] } |  j | ^ q S(   sŠ   Return a list of the currently selected 'LidarInput' instances,
        without any constraint checkings (unlike 'getData'), and unsorted.(   R<   t   getSelectedRowsR7   (   R   t   selectedRowst   row(    (    s   code\LidarTableWidget.pyRt   D  s    c         C   s!   t  j |  | ƒ |  j j ƒ  d  S(   N(   R6   t   setStatusMessaget   selectionChangedt   emit(   R   t   statusMessage(    (    s   code\LidarTableWidget.pyR{   M  s    c      	      s  t  |  j ƒ |  j j ƒ  k o) d k n s4 t ‚ |  j ƒ  } t  | ƒ d k rp |  j j ƒ  |  j d ƒ d Sg  } x0 | D]( } | j	 ƒ  d k r} | j | ƒ q} q} W|  j j | ƒ x• | D] } d } | j	 ƒ  } | d k	 rù |  j | | ƒ d SxQ |  j D]F } t | | ƒ d k r|  j | d t j | j | ƒ ƒ ƒ d SqWqÀ Wxc | D][ } t | j d k ƒ rXd } | j d k r¢| d t j d	 ƒ 7} n  |  j | ƒ d SqXWg  | D] } | j ^ q¾‰ t ‡ f d
 †  ˆ Dƒ ƒ r |  j d ƒ d Sg  | D] } | j ^ q‰ g  | D] } | j ^ q#‰  g  | D] } | j ^ q?‰ t ‡ f d †  ˆ Dƒ ƒ s¨t ‡  f d †  ˆ  Dƒ ƒ s¨t ‡ f d †  ˆ Dƒ ƒ r¹|  j d ƒ d Sg  | D] } | j ^ qÀ‰ t ‡ f d †  ˆ Dƒ ƒ r|  j d ƒ d Sd } xÁ |  j D]¶ } g  | D] }	 |	 j | ƒ ^ q}
 t  | ƒ t  | ƒ k rvt d „  |
 Dƒ ƒ rv|  j ƒ  d Sg  |
 D] } | d k	 r}| ^ q}} | d k s¿t  | ƒ t  | ƒ k  r| } qqW| d k	 rþt  | ƒ d k rþ|  j | d ƒ n |  j d ƒ d S(   s¾   Check if a complete and unambigous set of lidar measurements is
        currently selected in the table widget, update the lidar signal plots
        and set the error message appropriately.i    s#   Lidar measurements are not selectedNs3   One of the selected lidar measurements is invalid: s%   %s database field is contains no datag        sF   Dispersion of one of the selected lidar signals is zero at some heights-   . Try modifying the %s boundary of the signalR0   c         3   s   |  ] } | ˆ  d  k Vq d S(   i    N(    (   R   t   gridStep(   t	   gridSteps(    s   code\LidarTableWidget.pys	   <genexpr>•  s    sE   Grid height steps of the selected lidar measurements are inconsistentc         3   s   |  ] } | ˆ  d  k Vq d S(   i    N(    (   R   t   latitude(   t	   latitudes(    s   code\LidarTableWidget.pys	   <genexpr>Ÿ  s    c         3   s   |  ] } | ˆ  d  k Vq d S(   i    N(    (   R   t	   longitude(   t
   longitudes(    s   code\LidarTableWidget.pys	   <genexpr>   s    c         3   s   |  ] } | ˆ  d  k Vq d S(   i    N(    (   R   t   altitude(   t	   altitudes(    s   code\LidarTableWidget.pys	   <genexpr>¡  s    sH   Geodetic coordinates of the selected lidar measurements are inconsistentc         3   s   |  ] } | ˆ  d  k Vq d S(   i    N(    (   R   t	   atmoModel(   t
   atmoModels(    s   code\LidarTableWidget.pys	   <genexpr>ª  s    sJ   Atmosphere models used in the selected lidar measurements are not the samec         s   s   |  ] } | d  k Vq d  S(   N(   R   (   R   t   message(    (    s   code\LidarTableWidget.pys	   <genexpr>½  s    s(   Too many lidar measurements are selected(   R   R7   R<   t   rowCountR   Rt   RD   Ri   Rj   t   getErrorMessageR   RR   t   plotDataR9   t   getattrR   R   t   getFieldNameRl   t   lidarDispersionR/   R-   R   Rƒ   R…   R‡   R8   R   R   t   clearStatusMessage(   R   Rr   t   plottingDataR   t   errorPrefixt   errorMessageRW   t   minErrorMessageListRS   Rf   t   errorMessagesR‰   t   errorMessageList(    (   R„   R†   R€   Rˆ   R‚   s   code\LidarTableWidget.pyRB   X  s~    4	
N(   R    R!   R"   t
   pyqtSignalR|   R   R   RV   RX   RY   R_   Re   Rq   Rw   Rt   R{   RB   (    (    (    s   code\LidarTableWidget.pyR   {   s   	9							(	+			N(    (   t   PyQt4.QtCoret   PyQt4.QtGuit   common.utilsR   R   R   t   common.DataTableWidgett   common.StatusSignalingWidgett   PlotWidgetst   __all__R   R6   R   (    (    (    s   code\LidarTableWidget.pyt   <module>   s   




Z