
`9Sc           @   s   d  d l  Z  d  d l Z d  d l Z d  d l Z 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 f  d     YZ d e f d	     YZ d S(
   iN(   t   txt(   t   *t   PhotometerInputc        S   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 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/ d0 d
  e d1 d2 d
  e d3 d4 d
  e d5 d6 d
  e d7 d8 d
  e d9 d: 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 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 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 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
 d e e d d d
 d e gN Z d Z d Z d Z	 d Z
 d   Z d   Z d   Z d   Z e d d   Z e d    Z d   Z d   Z e d    Z d   Z RS(   s  Sun photometer input data for the aerosol profile retrieval algorithm.

    Attributes to be read from an Excel file:
      - 'date', 'time': measurement date and time.
      - 'aot675': total aerosol optical thickness at 675 nanometers.
      - 'aot675Corr': manually corrected value for 'aot675'. The same
        correction (with correction factor defined as 'aot675Corr / aot675')
        has to be applied to 'vFine', 'vCoarse' and 'ext<...>'.
      - 'vFine', 'vCoarse': volumetric concentrations of fine and coarse
        aerosol modes, as retrieved with Sun photometer, in micrometers (with
        both sperical and spheroidal particles taken into account).
      - 'sphericity': fraction of spherical aerosol particles, in percents, in
        contrast to spheroidal particles, as retrieved with Sun photometer.
      - 'bFine<...>', bSpherical<...>', 'bSpheroid<...>', bCoarse<...>: aerosol
        backscatter coefficients for different aerosol modes at differnt
        wavelengths and polarizations. Cross-polarized and parallel-polarized
        backscatters are denoted with additional 'C' and 'P' suffixes
        respectively; total backscatters are denoted with just the wavelength
        in nanometers. 'Fine' aerosol mode includes both spherical and
        spheroidal particles; 'Coarse' mode is a sum of 'Spherical' and
        'Spheroid' modes.
      - 'aFine<...>', 'aSpherical<...>', 'aSpheroid<...>', aCoarse<...>:
        aerosol attenuation coefficients for different aerosol modes at
        different wavelengths.

      - 'wl<...>Um': wavelengths, at which recalculated aerosol parameters are
        given, in micrometers. 'wl355Um' has to be equal to '0.355', and so on.
      - 're<...>': real part of the complex refractive index at the given
        wavelength.
      - 'im<...>': imaginary part of the complex refractive index at the given
        wavelength.
      - 'ext<...>': aerosol optical thickness at the given wavelength.
      - 'ssa<...>': single scattering albedo at the given wavelength.
      - 'f11_<...>': main component of the aerosol scattering matrix at the
        given wavelength.
      - 'f22by11_<...>': second diagonal element of the aerosol scattering
        matrix divided by its main component, at the given wavelength.

    Attributes that are calculated manually in 'onDataLoaded':
      - 'vFineCorr', 'vCoarseCorr': corrected values for 'vFine' and 'vCoarse'
        (see 'aot675Corr').
      - 'vSphericalCorr', 'vSpheroidCorr': the value of 'vCoarseCorr', divided
        into two parts according to the value of 'sphericity' attribute.
      - 'wl<...>': same as 'wl<...>Um', but converted into nanometers.
      - 'ext<...>Corr': corrected values for 'ext<...>' (see 'aot675Corr').

      - 'evRatio2Modes', 'evRatio3Modes':

    Auxiliary attribute (used in the photometer input widget only):
      - 'aot675CorrOriginal': the stored value for 'aot675Corr', in contrast to
        the value modified by the user interactively.s   Photometer Data-ver2t   datet   Datet   DATEt   timet   Timet   TIMEt   aot675s   AOT-675t   DOUBLEt
   aot675Corrs   AOT_675-TRUt   vFinet   1V1t   vCoarset   2V3t
   sphericityt   T1Sphericityt   bFine355s   b1,0,355t	   bFine355Ps   b1,3,355t	   bFine355Cs   b1,2,355t   bFine532s   b1,0,532t	   bFine532Ps   b1,3,532t	   bFine532Cs   b1,2,532t	   bFine1064s	   b1,0,1064t
   bFine1064Ps	   b1,3,1064t
   bFine1064Cs	   b1,2,1064t   bSpherical355s   b2,0,355t   bSpherical355Ps   b2,3,355t   bSpherical355Cs   b2,2,355t   bSpherical532s   b2,0,532t   bSpherical532Ps   b2,3,532t   bSpherical532Cs   b2,2,532t   bSpherical1064s	   b2,0,1064t   bSpherical1064Ps	   b2,3,1064t   bSpherical1064Cs	   b2,2,1064t   bSpheroid355s   b3,0,355t   bSpheroid355Ps   b3,3,355t   bSpheroid355Cs   b3,2,355t   bSpheroid532s   b3,0,532t   bSpheroid532Ps   b3,3,532t   bSpheroid532Cs   b3,2,532t   bSpheroid1064s	   b3,0,1064t   bSpheroid1064Ps	   b3,3,1064t   bSpheroid1064Cs	   b3,2,1064t
   bCoarse355s   b4,0,355t   bCoarse355Ps   b4,3,355t   bCoarse355Cs   b4,2,355t
   bCoarse532s   b4,0,532t   bCoarse532Ps   b4,3,532t   bCoarse532Cs   b4,2,532t   bCoarse1064s	   b4,0,1064t   bCoarse1064Ps	   b4,3,1064t   bCoarse1064Cs	   b4,2,1064t   aFine355s   a1,0,355t   aFine532s   a1,0,532t	   aFine1064s	   a1,0,1064t   aSpherical355s   a2,0,355t   aSpherical532s   a2,0,532t   aSpherical1064s	   a2,0,1064t   aSpheroid355s   a3,0,355t   aSpheroid532s   a3,0,532t   aSpheroid1064s	   a3,0,1064t
   aCoarse355s   a4,0,355t
   aCoarse532s   a4,0,532t   aCoarse1064s	   a4,0,1064t   wl355Umt   T1Wavet   re355t   T1REFRt   im355t   T1REFIt   ext355t   T1Extt   ssa355t   T1Albedot   f11_355t   T1F11t   f22by11_355s	   T1F22/F11t   wl532Umt   T2Wavet   re532t   T2REFRt   im532t   T2REFIt   ext532t   T2Extt   ssa532t   T2Albedot   f11_532t   T2F11t   f22by11_532s	   T2F22/F11t   wl1064Umt   T3Wavet   re1064t   T3REFRt   im1064t   T3REFIt   ext1064t   T3Extt   ssa1064t   T3Albedot   f11_1064t   T3F11t   f22by11_1064s	   T3F22/F11t   evRatio2Modest   EVRatio2t   requiredt   evRatio3Modest   EVRatio3i   sK   Photometer input is not a valid Excel file or may not be opened for readings)   Photometer input file format is invalid: s*   Failed to write the data to the Excel filec         C   sc   |  j  |  j  |  _ |  j  |  j  |  _ |  j  |  j  |  _ |  j   |  j |  _	 |  j
   d  S(   N(   t   getConvertedWavelengthRB   t   wl355RO   t   wl532R\   t   wl1064t   updateCorrectedThicknessesR   t   aot675CorrOriginalt   calcEigenvalueRatios(   t   self(    (    s   code\PhotometerInput.pyt   onDataLoaded   s    
c         C   s?   |  j  d  k s |  j d  k r" d  St j j |  j  |  j  Sd  S(   N(   R   t   NoneR   t   datetimet   combine(   Ru   (    (    s   code\PhotometerInput.pyt   getDateTime   s    c         C   s   |  j  |  j  |  _ |  j  |  j  |  _ |  j d k	 r} |  j d k	 r} |  j |  j d |  _ |  j d |  j d |  _ n d |  _ d |  _ |  j  |  j	  |  _
 |  j  |  j  |  _ |  j  |  j  |  _ d S(   s   Set values for all the attributes that depend on the manually
        corrected extinction aerosol optical thickness at 675 nm.

        Call this function whenever 'aot675Corr' attribute is modified.g{Gz?g      ?N(   t   getCorrectedThicknessR   t	   vFineCorrR   t   vCoarseCorrRw   R   t   vSphericalCorrt   vSpheroidCorrRH   t
   ext355CorrRU   t
   ext532CorrRb   t   ext1064Corr(   Ru   (    (    s   code\PhotometerInput.pyRr      s    		c         C   s   t  |  d | |  } t  |  d | | d  } t  |  d | | d  } | | | } | | }	 | | }
 |	 d |
 d } |	 d |
 d } t |  d | | |	  t |  d | | d |  t |  d | | d |  d S(   s9  Modify the values of aerosol backscatter coefficients so that they
        would mimic the specified modifications of the aerosol scattering
        phase matrix for the given aerosol mode and at the given wavelength.

        Parameters:
          - 'modeSuffix', 'wlSuffix': strings identifying the aerosol mode and
            the wavelength for which the phase matrix is being modified.
            'modeSuffix' may be 'Fine', 'Spherical', 'Spheroid', or 'Coarse';
            'wlSuffix' may be '355', '532', or '1064'.
          - 'f11Factor', 'f22By11Factor': ratios between the new and the old
            values of F11 and F22/F11 components of the scattering matrix,
            respectively.

        Warning: currently, this function does not make any attempts to modify
        'f11_<...>' and 'f22by11_<...>' attributes of the class instance, thus
        effectively breaking its internal consistency. After this function has
        has been called, core aerosol parameters and utility attributes used
        to describe the aerosol as a whole won't agree any more.t   bt   Pt   Ci   g      ?N(   t   getattrt   setattr(   Ru   t
   modeSuffixt   wlSuffixt	   f11Factort   f22By11Factort   oldBscatt	   oldBscatPt	   oldBscatCt
   oldF22By11t   bscatt   f22By11t   bscatCt   bscatP(    (    s   code\PhotometerInput.pyt   modifyPhaseFunction   s    

c         C   s   t    j |   } | d k	 r t   j |  } xR | D]G } t j j | j | j  } | | k r7 | | | _ | j	   q7 q7 Wn  | S(   s  Same as 'readDataList', but read the data from an AERLID data file
        (i.e., from a Dubovik AERONET data file processed with AERLID tool).

        If 'aotCorrFilePath' is not 'None', it should be a path to the
        corresponding AOT correction data file (i.e., an auxiliary data file
        that holds manually corrected values of aerosol optical thicknesses at
        675 nm).N(
   t   AerlidFileLoadert   loadFileRw   t   AotCorrFileLoaderRx   Ry   R   R   R   Rr   (   t   aerlidFilePatht   aotCorrFilePatht
   recordListt   aot675CorrDictt
   dataRecordt   dateTimeValue(    (    s   code\PhotometerInput.pyt   readDataListFromAerlid  s    
	c   
      C   s  t  d   | D  } | s| t j j |   } | rx y t j |   Wqx t k
 rt t j d t j |     qx Xn  d St j j	 |   } y& t j j
 |  s t j |  n  Wn- t k
 r t j d t j |     n Xy t |  d  } Wn- t k
 r&t j d t j |     n Xz y | j d  xm | D]e } | j | j k rA| j j d  } | j j d	  } d
 | j }	 | j | | |	 d  qAqAWWn- t k
 rt j d t j |     n XWd | j   Xd S(   s  Write AOT correction data file for the given list of
        'PhotometerInput' instances.

        Only those corrected AOT values that are different from the original
        ones are stored in the 'AOT corr' data file. Thus, if the original data
        file changes, its new values for 'aot675' won't get overwritten by the
        corrected values stored in the 'AOT corr' file.

        If 'recordList' contains no data records with user-modified AOT-675
        values, 'AOT corr' data file is not created, and if there already
        exists one, it is deleted. Thus, an AOT correction data file will never
        exist unless it is really required.c         s   s!   |  ] } | j  | j k Vq d  S(   N(   R   R	   (   t   .0R   (    (    s   code\PhotometerInput.pys	   <genexpr>G  s   u7   Couldn’t delete the outdated AOT correction file (%s)Nu<   Couldn’t create directory for the AOT correction file (%s)t   ws4   AOT correction file %s may not be opened for writings$   yyyy-mm-dd   hh:mm:ss   AOT_675-TRU
s   %Y-%m-%d   s
   %H:%M:%S  s   % .5Es   
s(   Failed to write AOT correction file (%s)(   t   anyt   ost   patht   isfilet   removet   OSErrorR    t   Errort	   quotePatht   dirnamet   isdirt   makedirst   opent   IOErrort   writeR   R	   R   t   strftimeR   t   close(
   R   R   t   fileIsRequiredt
   fileExistst   fileDirt   aotCorrFileR   t   dateStrt   timeStrt   aot675CorrStr(    (    s   code\PhotometerInput.pyt   updateAotCorrFileForDataList8  sN    	 $	c         C   s   | d  k r d  S| d S(   Ng     @@(   Rw   (   Ru   t   wavelenMicrometers(    (    s   code\PhotometerInput.pyRn     s    c         C   sl   |  j  d k s* |  j  d k s* | d k r. | S|  j  d k rA | S| |  j |  j  } t j |  rh | S| S(   s   Correct an abstract 'originalThickness' quantity according to
        difference between original and manually corrected aerosol optical
        thicknesses at 675 nm.

        The quantity is assumed to be proportional to the optical thicnkess.g        N(   R	   Rw   R   t   matht   isinf(   Ru   t   originalThicknesst   correctedValue(    (    s   code\PhotometerInput.pyR{     s    c         C   s9   t  j j |  j   |   } t  j |  | d | d S(   Nii    (   t   numpyt   linalgt   eigvalsht	   transposet   sort(   t   matrixt   eigenValues(    (    s   code\PhotometerInput.pyt
   getEVRatio  s    c         C   s   |  j  t j |  j |  j g |  j |  j g |  j |  j g g   |  _	 |  j  t j |  j |  j
 |  j g |  j |  j |  j g |  j |  j |  j g |  j |  j |  j g g   |  _ d  S(   N(   R   R   R   R   R-   R   R0   R   R3   Ri   R   R$   R   R'   R!   R*   R   R    R)   Rl   (   Ru   (    (    s   code\PhotometerInput.pyRt     s    N(   t   __name__t
   __module__t   __doc__t	   tableNamet	   DataFieldt   Falset   fieldst   extraExcelHeaderRowst   openExcelFileErrorMessaget   invalidExcelFormatErrorPrefixt   exportDataToExcelErrorPrefixRv   Rz   Rr   R   t   staticmethodRw   R   R   Rn   R{   R   Rt   (    (    (    s   code\PhotometerInput.pyR       s   3				)Q		R   c           B   s   e  Z d  Z d   Z d   Z d d d  Z d   Z d   Z d d d  Z	 d d d  Z
 d   Z d	   Z e d
    Z e d    Z RS(   s?   Utility class used for parsing of AERLID photometer data files.c      
   C   s6  d  |  _  d! |  _ d" |  _ t |  j  t |  j  k s? t  d# |  _ d$ |  _ d% |  _ |  j  j d  |  _	 |  j  j d  |  _
 |  j  j d  |  _ |  j  j d  |  _ |  j  j d  |  _ |  j j d  |  _ |  j j d  |  _ |  j j d  t |  j  |  _ |  j j d  t |  j  |  _ |  j j d  t |  j  |  _ |  j j d  t |  j  |  _ |  j j d  |  _ |  j j d  |  _ |  j j d  |  _ |  j j d  |  _ |  j j d  |  _ |  j j d  |  _ |  j j d  |  _ |  j j d  |  _ |  j j d  |  _ d S(&   sA   Initialize auxiliary attributes used to describe the data format.t   Totalt
   Fine_Totalt   Fine_Sphericals   Fine_Non-Sphericalt   Coarse_Totalt   Coarse_Sphericals   Coarse_Non-Sphericalt   355t   532t   1064gQ?g/$?g/$?s
   yyyy-mm-dds   hh:mm:sst
   Julian_days   V-fines   V-coarset   AOT_675s   AOT_675-TRUt   Wavet   REFRt   REFIs   %sphericityt   extt   abst   scat   albedot   F11s   F22/F11N(   R   R   R   s   Fine_Non-SphericalR   R   s   Coarse_Non-Spherical(   s   355s   532s   1064(   gQ?g/$?g/$?(   s
   yyyy-mm-dds   hh:mm:ssR   (   s   V-fines   V-coarseR   s   AOT_675-TRU(
   s   WaveR   R   s   %sphericitys   exts   absR   R   R   s   F22/F11(   t   aerosolModest   wavelengthSuffixest   wavelengthsUmt   lent   AssertionErrort   prefixHeaderst   suffixHeaderst   specificHeaderst   indext   totalModeIndext   fineModeIndext   sphericalModeIndext   spheroidModeIndext   coarseModeIndext   dateColt   timeColt   vFineColt
   vCoarseColt	   aot675Colt   aot675CorrColt   wlColt   reColt   imColt   sphericityColt   extColt   scatteringColt   ssaColt   f11Colt
   f22by11Col(   Ru   (    (    s   code\PhotometerInput.pyt   __init__  sF      			$		 		c         C   s   y/ t  j j |  d k r g  St |  |  _ Wn3 t t f k
 rd t j d t j	 |    n Xd t j	 |  |  _
 zD y |  j   } Wn- t k
 r t j d t j	 |    n XWd |  j j   X| S(   s   Load the specified AERLID data file.

        Return a list of 'PhotometerInput' instances.

        Raise 'txt.Error' if loading fails or file format is invalid.i    s1   AERLID data file %s may not be opened for readings)   AERLID data file format is invalid (%s): s$   Failed to read AERLID data file (%s)N(   R   R   t   getsizeR   t   fileR   R   R    R   R   t   errorPrefixt   readFileR   (   Ru   t   filePathR   (    (    s   code\PhotometerInput.pyR     s$    
 	c         C   s   | d k	 rD t |  j  t |  j  | t |  j  | | } n\ | d k  r t |  j  t |  j  t |  j  t |  j  t |  j  | } n | } | d k s t  | S(   s  Calculate the absolute index of a data column based on its relative
        index 'col'.

        If 'modeIndex' and 'wlIndex' are not 'None', they should be valid
        indices within 'self.aerosolModes' and 'self.wavelenghtsUm' arrays
        respectively, and 'col' is considered to be a relative data column
        index for a given aerosol mode and wavelength.

        Otherwise, 'col' is considered to refer to either initial ('col' >= 0)
        or final ('col' < 0) generic data column (thus, 'col' == 0 will refer
        to the first data column within the file, 'col' == -1 will refer to the
        last data column, 'col' == -2 will refer to the last but one column,
        and so on).i    N(   Rw   R   R   R   R   R   R   R   (   Ru   t   colt	   modeIndext   wlIndext   absIndex(    (    s   code\PhotometerInput.pyt   getColumnIndex,  s    8Jc   
   	   C   s  g  } |  j  j   |  j  j   j   } xs t t |  j   D]\ } | t |  k sm | | |  j | k r> t j |  j d t j	 |  j |    q> q> W|  j  j   j   } x7 t t |  j
   D]  } |  j | |  j
 | |  q Wx} t t |  j   D]f } x] t t |  j   D]F } x= t t |  j   D]& } |  j | |  j | | | |  q;WqWqWx; t t |  j  d  D]  } |  j | |  j | |  qWd |  _ xa |  j  D]V } | j   } |  j |  }	 |	 d k	 r|	 j   | j |	  n  |  j d 7_ qW| S(   s4   Load the opened data file referenced in 'self.file'.s   %s aerosol mode is missingi    i   i   N(   R  t   readlinet   splitt   rangeR   R   R    R   R  t   quoteR   t   testColumnHeaderR   R   R   t   currentLinet   readDataRecordRw   Rv   t   append(
   Ru   R   t   modeHeadersR  t   dataHeadersR  R	  t   linet   dataStringsR   (    (    s   code\PhotometerInput.pyR  M  s8    "	# 	
c   	   	   C   s  t    } |  j |  } | j   | _ | j   | _ |  j | |  j  | _ |  j | |  j  | _ |  j | |  j	  | _
 |  j | |  j  | _ |  j | |  j |  j d  | _ t d   | j | j | j
 | j | j f D  r d Sxt t |  j   D]} |  j | } |  j | |  j |  j |  } | |  j | k rt j d t j |  t j |  j |  t j |  j d  f   n  t | d | d |  t | d | |  j | |  j |  j |   t | d | |  j | |  j |  j |   t | d	 | |  j | |  j |  j |   t | d
 | |  j | |  j |  j |   t | d | |  j | |  j  |  j |   t | d | |  j | |  j! |  j |   x+ d D]# } t" | | |  d k rd SqWt# } | |  j$ | | d | j
 |  j% |  M} | |  j$ | | d | j |  j& |  M} | |  j$ | | d | j |  j' |  M} | |  j$ | | d | j |  j( |  M} | sd SqW| S(   sJ  Parse a data record that has been recently read from the data file.

        Return a valid 'PhotometerInput' instance or 'None' if some of the
        required data fields are invalid (i.e., contain the values of -999.0).

        'dataList' should be the comlete list of data strings read from a
        single line of the file.i    c         s   s   |  ] } | d  k Vq d S(   g     8N(    (   R   t	   dataField(    (    s   code\PhotometerInput.pys	   <genexpr>  s    s/   wavelength value is %s instead of %s in line %si   t   wlt   Umt   ret   imR   t   ssat   f11_t   f22by11_g     8t   Finet	   Sphericalt   Spheroidt   CoarseN(   s   reR  s   extR  R  R  ()   R   t   readDateTimeValueR   R   t   readFloatValueR   R	   R   R   R   R   R   R   R   R   R   R   Rw   R  R   R   R   R   R    R   t   quoteNumberR  R   R   R   R   R   R   R   R   t   Truet   setAttBscattAttributesR   R   R   R   (	   Ru   R  R   R   R	  R   t	   wlValueUmt   attributeNamet   isInputValid(    (    s   code\PhotometerInput.pyR    s|    									 

c         C   s   |  j  | | |  } | t |  k r` t j |  j d t j | d  t j |  f   n  | | | k r t j |  j d t j | d  t j | |  t j |  f   n  d S(   s  Check if the given data column header has the expected value.

        Raise 'txt.Error' on failure.

        'headerList' should be the comlete list of header strings read from the
        file. 'col' should be the relative index of the data column (see
        'getColumnIndex').s   data column %s (%s) in missingi   s'   header of column %s is %s instead of %sN(   R  R   R    R   R  R&  R  (   Ru   t
   headerListt   requiredValueR  R  R	  t   columnIndex(    (    s   code\PhotometerInput.pyR    s    
*c         C   s   |  j  | | |  } | t |  k rg t j |  j d t j | d  t j |  j d  f   n  y t | |  SWnN t k
 r t j |  j d t j | d  t j |  j d  f   n Xd S(   s#  Parse a floating-point value read from the data file.

        Raise 'txt.Error' on failure.

        'dataList' should be the comlete list of data strings read from a
        single line of the data file. 'col' should be the relative index of the
        data column (see 'getColumnIndex').s#   missing data in column %s (line %s)i   s%   invalid number in column %s (line %s)N(	   R  R   R    R   R  R&  R  t   floatt
   ValueError(   Ru   t   dataListR  R  R	  R.  (    (    s   code\PhotometerInput.pyR%    s    	!c         C   s   |  j  |  j  } |  j  |  j  } | t |  k sH | t |  k ru t j |  j d t j |  j d    n  | | } | | } y t	 j	 j
 | | d  SWn; t k
 r t j |  j d t j |  j d    n Xd S(   s
  Parse the date and time values read from the AERLID the data file.

        Return a 'datetime.datetime' instance.

        Raise 'txt.Error' on failure.

        'dataList' should be the comlete list of data strings read from a
        single line of the data file.s   missing date or time in line %si   s   %Y-%m-%d%H:%M:%Ss   invalid date or time in line %sN(   R  R   R   R   R    R   R  R&  R  Rx   t   strptimeR0  (   Ru   R1  t
   dateColumnt
   timeColumnt
   dateStringt
   timeString(    (    s   code\PhotometerInput.pyR$  ,  s    
$

c         C   s  |  j  | } |  j | |  j | |  } |  j | |  j | |  }	 |  j | |  j | |  }
 |  j | |  j | |  } t d   | |	 |
 | f D  r t S| d k r | | d } |	 | d |
 d t j	 } n$ |  j
 | |  } |  j | |  } | d | d } | d | d } t | d | | |  t | d | | |  t | d | | d	 |  t | d | | d
 |  t S(   s  Set aerosol attenuation and backscatter attributes in the given
        'PhotometerInput' instance 'dataRecord', for the given aerosol mode and
        wavelength.

        Return 'False' and do nothing more if any of the required data fields
        is invalid (i.e., has the value of -999.0). Otherwise, return 'True'.

        Raise 'txt.Error' on failure.

        Parameters:
          - 'dataList': the comlete list of data strings read from a single
            line of the data file.
          - 'modeSuffix': aerosol mode suffix for 'PhotometerInput' instance
            attributes.
          - 'volConcentration': total volumetric concentration of aerosol for
            the given aerosol mode, in micrometers, or 'None' if the value is
            not available for the given photometer measurement.
          - 'modeIndex', 'wlIndex': indices within 'self.aerosolModes' and
            'self.wavelenghtsUm' arrays respectively that define aerosol mode
            and wavelength.c         s   s   |  ] } | d  k Vq d S(   g     8N(    (   R   R  (    (    s   code\PhotometerInput.pys	   <genexpr>m  s    g        gMbP?g      @i   g      ?t   aR   R   R   (   R   R%  R   R   R   R   R   R   R   t   pit   getDefaultAttenuationt   getDefaultBackscatterR   R'  (   Ru   R   R1  R   t   volConcentrationR  R	  R   t
   extinctiont
   scatteringt   f11t   f22by11t   attenuationt   backscattert   backscatterCt   backscatterP(    (    s   code\PhotometerInput.pyR(  J  s.    	 c         C   s   i i d d 6d d 6d d 6d 6i d d 6d	 d 6d
 d 6d 6i d d 6d d 6d d 6d 6i d d 6d d 6d d 6d 6} | |  | S(   st   Return an arbitrary physically meaningful attenuation coefficient
        for the given aerosol mode and wavelength.g/$?R   gVF?x?R   g*5{X?R   R   g4`K?gRhL?gMbP?R!  gtϺFˁN?g%<P?g5l/R?R"  g1߄BL?g&P"M?gr&"P?R#  (    (   R   R   t   attenuationMap(    (    s   code\PhotometerInput.pyR9    s    c         C   s   i i d d 6d d 6d d 6d 6i d d 6d	 d 6d
 d 6d 6i d d 6d d 6d d 6d 6i d d 6d d 6d d 6d 6} | |  | S(   st   Return an arbitrary physically meaningful backscatter coefficient
        for the given aerosol mode and wavelength.gמY"?R   gq@H?R   g3vxU?R   R   gTqs*>gQWZ?gLq?R!  g/>g-C6>g!>@>R"  g?̔>gbHz>g[u$>R#  (    (   R   R   t   backscatterMap(    (    s   code\PhotometerInput.pyR:    s    N(   R   R   R   R  R   Rw   R  R  R  R  R%  R$  R(  R   R9  R:  (    (    (    s   code\PhotometerInput.pyR     s   
	=	(!	9	v		?R   c           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s   Utility class used for parsing of auxiliary data files that hold
    manually corrected values of aerosol optical thicknesses at 675 nm.c         C   sp   d |  _  d |  _ d |  _ d |  _ d	 |  _ |  j j d  |  _ |  j j d  |  _ |  j j d  |  _ d S(
   sA   Initialize auxiliary attributes used to describe the data format.s
   yyyy-mm-dds   hh:mm:sss   AOT_675-TRUN(    (    (   s
   yyyy-mm-dds   hh:mm:sss   AOT_675-TRU(    (    (	   R   R   R   R   R   R   R   R   R   (   Ru   (    (    s   code\PhotometerInput.pyR    s    					c         C   s   y t  |  |  _ Wn- t k
 rB t j d t j |    n Xd t j |  |  _ zD y |  j   } Wn- t k
 r t j d t j |    n XWd |  j j   X| S(   s  Load the specified AOT correction data file.

        Return a dictionary that maps 'datetime.datetime' values to floating
        point numbers representing corrected aerosol optical thicknesses.

        Raise 'txt.Error' if loading fails or file format is invalid.s4   AOT correction file %s may not be opened for readings,   AOT correction file format is invalid (%s): s'   Failed to read AOT correction file (%s)N(	   R   R  R   R    R   R   R  R  R   (   Ru   R  R   (    (    s   code\PhotometerInput.pyR     s      	c         C   s   i  } |  j  j   j   } x7 t t |  j   D]  } |  j | |  j | |  q1 Wd |  _ xZ |  j  D]O } | j   } |  j |  } |  j	 | |  j
  } | | | <|  j d 7_ qh W| S(   s4   Load the opened data file referenced in 'self.file'.i   (   R  R  R  R  R   R   R  R  R$  R%  R   (   Ru   R   R  R  R  R  R   t   aot675CorrValue(    (    s   code\PhotometerInput.pyR    s    		
(   R   R   R   R  R   R  (    (    (    s   code\PhotometerInput.pyR     s   		!(   Rx   R   R   t   numpy.linalgR   t   os.patht   common.utilsR    t   common.DataRecordt   __all__t
   DataRecordR   R   R   (    (    (    s   code\PhotometerInput.pyt   <module>   s   
	  