ó
ø`9Sc           @   sB  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 l	 Td  d l
 Td  d l Td  d l Td  d l Td  d l Td  d l Td  d l Ty d  d l TWn e k
 rÙ e Z n Xe Z e ró d  d l Tn  d g Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d S(   iÿÿÿÿ(   t   *(   t   gui(   t   txt(   t   utilst   PolarRetrieverWidgetc           B   sƒ   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z e d „  ƒ Z	 d „  Z
 d „  Z d „  Z e ro d	 „  Z n  d
 „  Z d „  Z RS(   sx   Main GUI window of the aerosol backscatter and depolarization retrieval
    algorithm utilizing polarized lidar signals.c         C   s  t  j |  | ƒ |  j t j ƒ d  |  _ t j ƒ  |  _	 t
 rP t j ƒ  |  _ n  t ƒ  } t ƒ  |  _ |  j j j |  j ƒ t ƒ  |  _ |  j j t d d ƒ t d d ƒ g ƒ |  j j d ƒ t ƒ  } | j |  j ƒ | j |  j d ƒ | j d d d d ƒ | j | ƒ t ƒ  |  _ | j |  j ƒ t ƒ  |  _ | j |  j ƒ t d ƒ |  _  |  j  j! t" j# d ƒ ƒ |  j  j$ j |  j% ƒ t
 r²t d	 ƒ |  _& |  j& j$ j |  j' ƒ n  t d
 ƒ |  _( |  j( j$ j |  j) ƒ t d ƒ |  _* |  j* j$ j |  j+ ƒ t, ƒ  } | j |  j  ƒ t
 r.| j |  j& ƒ n  | j- ƒ  | j |  j( ƒ | j |  j* ƒ | j | ƒ |  j. | ƒ |  j/ d ƒ |  j0 t" j# d ƒ ƒ xI |  j |  j |  j f D]/ } | j1 j |  j2 ƒ | j3 j |  j j4 ƒ q®W|  j5 ƒ  |  j j6 ƒ  j7 ƒ  d  S(   Ng      €@i    i   i   t   lidarRefValuei   s   &Parameterst
   parameterss   Per&turbance optionss	   &Retrieves   &View outputs   Depolarization retrievers   institute-of-physics(   i    i   (8   t   QWidgett   __init__t   setAttributet   Qtt   WA_DeleteOnCloset   Nonet   outputViewerWidgett   PolarParamst   loadFromFilet   algorithmParamst#   polarPerturbanceProcessPluginLoadedt   PolarPerturbanceParamst   perturbanceParamst   QVBoxLayoutt   LidarDatabaseWidgett   lidarDatabaseWidgett   dataListChangedt   connectt   onLidarDataListChangedt   LidarTableWidgett   lidarTableWidgett   addAllowedChannelSequencet   LidarChannelInfot   addRequiredAttributet	   addWidgett   setContentsMarginst	   addLayoutt   PolarRetrievalSelectionWidgett   retrievalSelectionWidgett   StatusLabelWidgett   statusLabelt   QPushButtont   paramsButtont   setIconR   t   loadIcont   clickedt   onParamsButtonClickedt   perturbanceButtont   onPerturbanceButtonClickedt   retrieveButtont   onRetrieveButtonClickedt   viewOutputButtont   onViewOutputButtonClickedt   QHBoxLayoutt
   addStretcht	   setLayoutt   setWindowTitlet   setWindowIcont   statusMessageChangedt   onStatusMessageChangedt   repaintRequestedt   repaintParentWindowt   loadSettingst   getTableWidgett   setFocus(   t   selft   parentt   layoutt   lidarLayoutt   buttonBoxLayoutt   widget(    (    s   code\PolarRetrieverWidget.pyR   8   sj    		
			
	
c         C   s   |  j  ƒ  | j ƒ  d  S(   N(   t   saveSettingst   accept(   R>   t   event(    (    s   code\PolarRetrieverWidget.pyt
   closeEventŒ   s    
c         C   sV   t  d t  j ƒ } t j |  | ƒ |  j j | ƒ |  j j | ƒ |  j j | ƒ d  S(   Ns+   settings/interface/PolarRetrieverWidget.ini(   t	   QSettingst	   IniFormatR   t   saveWindowSettingsR   RD   R   R#   (   R>   t   settings(    (    s   code\PolarRetrieverWidget.pyRD   ‘   s    c         C   sV   t  d t  j ƒ } t j |  | ƒ |  j j | ƒ |  j j | ƒ |  j j | ƒ d  S(   Ns+   settings/interface/PolarRetrieverWidget.ini(   RH   RI   R   t   loadWindowSettingsR   R;   R   R#   (   R>   RK   (    (    s   code\PolarRetrieverWidget.pyR;      s    c         C   sz   t  |  ƒ d k s t ‚ |  d j |  d j k r6 d S|  d j |  d j k rT d S|  d j |  d j k rr d Sd Sd S(   s  Check if boundaries and reference point heights of the given
        'PreparedLidarInput' instances, otherwise suitable for a retrieval,
        coincide with each other.

        Return 'None' if the test succeeds, and an appropriate error message
        otherwise.i   i    i   sD   Lower boundaries of the selected lidar measurements are not the samesD   Upper boundaries of the selected lidar measurements are not the samesK   Reference point heights of the selected lidar measurements are not the sameN(   t   lent   AssertionErrort   firstInputIndext   lastInputIndext   refPointIndexR   (   t   lidarInputs(    (    s   code\PolarRetrieverWidget.pyt   getLidarGridErrorMessage©   s    	c         C   s9   |  j  j ƒ  } |  j j | ƒ t | ƒ d k r5 d Sd S(   sN   Populate lidar table with contents of the newly loaded lidar
        database.i    N(   R   t   getDataListR   t   connectDataListRM   (   R>   t   lidarDataList(    (    s   code\PolarRetrieverWidget.pyR   È   s    c         C   s~  |  j  j |  j j ƒ  d k ƒ |  j |  j |  j f } g  | D] } | j ƒ  ^ q> } t d „  | Dƒ ƒ r |  j j	 | ƒ |  j
 j t ƒ d S|  j j ƒ  } t | ƒ d k s· t ‚ | d j d k sÐ t ‚ | d j d k sé t ‚ |  j | ƒ } | d k	 r(|  j j | ƒ |  j
 j t ƒ d S| d j d k rAd n d } |  j j d	 t j | d
 t ƒƒ |  j
 j t ƒ d S(   sd   Update Retrieve button state and show the most relevant error
        message in 'self.statusLabel'.c         s   s   |  ] } | d  k	 Vq d  S(   N(   R   (   t   .0t   message(    (    s   code\PolarRetrieverWidget.pys	   <genexpr>â   s    Ni   i    i   i   t   unpolarizeds   parallel-polarizedsA   The data are ready for the retrieval (with %s base lidar channel)t	   addQuotes(   i    i   (   R0   t
   setEnabledR#   t   getStatusMessageR   R   R   t   anyR%   t   setMostSevereStatusMessageR.   t   Falset   getDataRM   RN   t   polarizationRS   t   setErrort   setCompletedR   t   quotet   True(   R>   t
   widgetListRC   t   statusMessagesRR   t   lidarGridErrorMessaget   baseChannelStr(    (    s   code\PolarRetrieverWidget.pyR8   Ô   s.    	c         C   s    t  |  |  j ƒ } | j ƒ  d  S(   N(   t   PolarParamsDialogR   t   exec_(   R>   t   paramsDialog(    (    s   code\PolarRetrieverWidget.pyR+      s    c         C   s    t  |  |  j ƒ } | j ƒ  d  S(   N(   t   PolarPerturbanceParamsDialogR   Rk   (   R>   Rl   (    (    s   code\PolarRetrieverWidget.pyR-     s    c         C   s†   |  j  j ƒ  d k s t ‚ |  j  j ƒ  } t | |  j ƒ } t r] t | |  j |  j	 ƒ } n  t
 |  | |  j j ƒ  ƒ } | j ƒ  d S(   s"   Launch the retrieval modal dialog.N(   R   R\   R   RN   R`   t   PolarRetrievalProcessR   R   t   PolarPerturbanceProcessR   t   PolarRetrievalDialogR#   t   getFilePathRk   (   R>   RR   t   retrievalProcesst   progressDialog(    (    s   code\PolarRetrieverWidget.pyR/     s    	c         C   s›   |  j  d k	 r@ y |  j  j ƒ  Wq@ t k
 r< d |  _  q@ Xn  |  j  d k rd t d t ƒ |  _  n  |  j  j |  j j ƒ  ƒ |  j  j	 ƒ  |  j  j
 ƒ  d S(   sÝ   Open the output database in the output viewer window, select the
        last database record and activate the window.

        If there is no output viewer window yet, or if the window has been
        closed, create it.t   skipDatabaseLoadingN(   R   R   t
   objectNamet   RuntimeErrort   OutputViewerWidgetRe   t   openLastDatabaseRecordR#   Rq   t   showt   activateWindow(   R>   (    (    s   code\PolarRetrieverWidget.pyR1     s    	N(   t   __name__t
   __module__t   __doc__R   R   RG   RD   R;   t   staticmethodRS   R   R8   R+   R   R-   R/   R1   (    (    (    s   code\PolarRetrieverWidget.pyR   3   s   T					,		R"   c           B   sG   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   sÃ   Widget responsible for selection and initialization of the output
    aerosol database in the the aerosol backscatter and depolarization
    retrieval algorithm utilizing polarized lidar signals.c         C   s§   t  j |  | ƒ t ƒ  } t d d d d ƒ |  _ |  j j d d ƒ |  j j j |  j ƒ |  j j	 j |  j
 ƒ | j |  j ƒ | j d d d d ƒ |  j | ƒ d  S(   Ns*   Depolarization retrieval &output database:s"   Microsoft Access databases (*.mdb)s/   Select depolarization retrieval output databases>   Open an existing depolarization retrieval output database files>   Select name for a new depolarization retrieval output databases@   Create a new empty depolarization retrieval output database filei    (   t   StatusSignalingWidgetR   R   t   FileSelectionWidgett   fileSelectort   showCreateButtont
   fileOpenedR   t   onFileOpenedt   fileCreatedt   onFileCreatedR   R    R4   (   R>   R?   R@   (    (    s   code\PolarRetrieverWidget.pyR   @  s    		c         C   s   |  j  j ƒ  S(   N(   R   Rq   (   R>   (    (    s   code\PolarRetrieverWidget.pyRq   T  s    c         C   s0   t  j | d ƒ  |  j j | d ƒ Wd  QXd  S(   NR"   t   filePath(   R   t   SettingsGrouperR   RD   (   R>   RK   (    (    s   code\PolarRetrieverWidget.pyRD   W  s    c         C   s0   t  j | d ƒ  |  j j | d ƒ Wd  QXd  S(   NR"   R‡   (   R   Rˆ   R   R;   (   R>   RK   (    (    s   code\PolarRetrieverWidget.pyR;   [  s    c         C   s…   |  j  j ƒ  } | d k r, |  j d ƒ d Sy! |  j d t ƒ t j | ƒ Wn' t j	 k
 rv } |  j | j
 ƒ d SX|  j ƒ  d S(   s?   Check format of an existing database file selected by the user.s9   Depolarization retrieval output database is not specifiedNs4   Checking depolarization retrieval output database...(   R   Rq   R   t   setErrorMessaget   setProgressMessageRe   t   PolarOutputt   checkDataFormatR   t   Errort   textt   clearStatusMessage(   R>   R‡   t   e(    (    s   code\PolarRetrieverWidget.pyR„   `  s    
c         C   su   |  j  j ƒ  } y! |  j d t ƒ t j | ƒ Wn4 t j k
 rf } |  j | j	 ƒ |  j  j
 ƒ  d SX|  j ƒ  d S(   sA   Create a new database file at the file path selected by the user.s4   Creating depolarization retrieval output database...N(   R   Rq   RŠ   Re   R‹   t   createDatabaseR   R   R‰   RŽ   t   invalidateFilePathR„   (   R>   R‡   R   (    (    s   code\PolarRetrieverWidget.pyR†   u  s    
N(
   R{   R|   R}   R   R   Rq   RD   R;   R„   R†   (    (    (    s   code\PolarRetrieverWidget.pyR"   :  s   				Rp   c           B   s    e  Z d  Z d „  Z d „  Z RS(   s6   Graphical user interface for the optimization process.c         C   s   t  ƒ  S(   N(   t   PolarPlotWidget(   R>   (    (    s   code\PolarRetrieverWidget.pyt   createPlotWidgetŒ  s    c         C   s   d S(   Ns+   settings/interface/PolarRetrievalDialog.ini(    (   R>   (    (    s   code\PolarRetrieverWidget.pyt   getSettingsFilePath  s    (   R{   R|   R}   R”   R•   (    (    (    s   code\PolarRetrieverWidget.pyRp   ˆ  s   	N(   t   PyQt4.QtCoret   PyQt4.QtGuit   common.utilsR   R   R   t   common.FileSelectionWidgett   common.StatusLabelWidgett   common.StatusSignalingWidgetR   R   Rw   t   PlotWidgetsR‹   R   Rn   t   RetrievalProgressDialogRo   t   ImportErrorR_   R   Re   R   t   __all__R   R   R   R"   Rp   (    (    (    s   code\PolarRetrieverWidget.pyt   <module>   s6   













	ÿ N