# Example of retrieval of combined synthetic lidar (elastic) and sunphotometer (TOD and radiances) observations (single pixel)
# Authors A.Lopatin & Q.Hu
# Last changes by A. Lopatin on 2016/09/11

# Other comments:
#   bimodal triangular bins size distribution
#   bimdoal spectral dependent refractive index
#   bimodal aerosol vertical profile without groundbase level point
#   surface properties taken for Minsk 02/06/2008
#   characteristics, optics, refractive index, lidar ratios, residual and fitting provided

input:
    driver: sdata
    file:  example_lidar_sunphotometer.sdat 
    segment:
        x: 1
        y: 1
        t: 1   
output:
    segment:
        function: classic # csv, plot, none
        stream: example_lidar_sunphotometer_inversion_output.txt
    
retrieval:   
    general:
        path_to_internal_files: "../../src/retrieval/internal_files/" 
        
    mode: inversion
    
    inversion:
        regime: single_pixel
        
        convergence:
            minimization_convention: logarithm
            maximum_iterations_for_stopping: 35
            maximum_iterations_of_Levenberg-Marquardt: 35 
            threshold_for_stopping: 1.0e-3
            threshold_for_stopping_Q_iterations: 1e-12
            scale_for_finite_difference: 1.0e-4  

        measurement_fitting:
            polarization: degree_of_polarization  

        noises:
            noise[1]:
                standard_deviation_synthetic: 0.0
                error_type:  relative
                standard_deviation:  0.05
                measurement_type[1]:
                    type: I
                    index_of_wavelength_involved: [ 2, 4, 5, 6 ]
            noise[2]:
                standard_deviation_synthetic: 0.0
                error_type:  absolute
                standard_deviation:  0.005
                measurement_type[1]:
                    type: tod
                    index_of_wavelength_involved: [ 2, 4, 5, 6 ]
            noise[3]:
                standard_deviation_synthetic: 0.0
                error_type:  relative
                standard_deviation:  0.5
                measurement_type[1]:
                    type: LS
                    index_of_wavelength_involved: [ 1 ]
            noise[4]:
                standard_deviation_synthetic: 0.0
                error_type:  relative
                standard_deviation:  0.5
                measurement_type[1]:
                    type: LS
                    index_of_wavelength_involved: [ 3 ]
            noise[5]:
                standard_deviation_synthetic: 0.0
                error_type:  relative
                standard_deviation:  0.5
                measurement_type[1]:
                    type: LS
                    index_of_wavelength_involved: [ 7 ]
     
    forward_model:   
        phase_matrix:
            size_binning_method_for_triangle_bins: logarithm
            number_of_elements: 4
            kernels_folder: "KERNELS_BASE/"
            radius:
                mode[1]:
                    min: 0.05
                    max: 0.576227
                mode[2]:
                    min: 0.334716
                    max: 15.0
        radiative_transfer:
            number_of_layers: 50
            molecular_profile_vertical_type: standard_atmosphere
            reference_plane_for_polarization: meridian   
            simulating_observation:
                order_of_scattering: multiple_scattering
                number_of_gaussian_quadratures_for_expansion_coefficients:  41 
                number_of_guassian_quadratures_for_fourier_expansion_coefficients:  20 
                number_of_fourier_expansion_coefficients:  20 
            simulating_derivatives:
                order_of_scattering: single_scattering
                number_of_gaussian_quadratures_for_expansion_coefficients:  21
                number_of_guassian_quadratures_for_fourier_expansion_coefficients:   10
                number_of_fourier_expansion_coefficients:   10  
            

    products:   
        configuration:
            wavelength_indices_for_angstrom: [4, 5]
        aerosol:
            chemistry: false
            lidar: true                             
            optical_properties: true                
            phase_matrix: false                      
            refractive_index: true                 
            theoretical_bimodal_extinction: false    
            theoretical_bimodal_parameters: false       
        error_estimation:
            aerosol:
                lidar: false           
                optical_properties: false
            parameters: false               
        forcing:
            broadband_flux: false                    
            forcing: false                           
        retrieval:
            fitting: true                        
            parameters: true                      
            residual: true                        
        surface:
            main_characteristics: false 

    debug:
        additional_information: false
        verbose: true
        use_internal_initial_guess: false

    constraints:
        characteristic[1]: #1
            type: size_distribution_triangle_bins
            retrieved: true
            mode[1]: 
                initial_guess:                       #1        #2        #3        #4        #5        #6        #7        #8        #9        #10       
                    value:                          [0.0003,   0.011,    0.011,    0.011,    0.011,    0.011,    0.011,    0.011,    0.011,    0.011     ]
                    min:                            [0.000005, 0.000005, 0.000005, 0.000005, 0.000005, 0.000005, 0.000005, 0.000005, 0.000005, 0.000005  ] 
                    max:                            [0.00031,  0.5,      0.5,      0.5,      0.5,      0.5,      0.5,      0.5,      0.5,      0.5       ]
                    index_of_wavelength_involved:   [0,        0,        0,        0,        0,        0,        0,        0 ,       0,        0         ]
                single_pixel:
                    smoothness_constraints:
                        difference_order: 3
                        lagrange_multiplier: 1.0e-2
                multi_pixel:
                    smoothness_constraints:
                       derivative_order_of_X_variability:    0
                       lagrange_multiplier_of_X_variability: 0.0                        
                       derivative_order_of_Y_variability:    0
                       lagrange_multiplier_of_Y_variability: 0.0                     
                       derivative_order_of_T_variability:    0
                       lagrange_multiplier_of_T_variability: 0.0
            mode[2]: 
                initial_guess:                       #1        #2        #3        #4        #5        #6        #7        #8        #9        #10       #11       #12       #13       #14       #15   
                    value:                          [0.007,    0.007,    0.007,    0.007,    0.007,    0.007,    0.007,    0.007,    0.007,    0.007,    0.007,    0.007,    0.007,    0.007,    0.0003     ]
                    min:                            [0.000005, 0.000005, 0.000005, 0.000005, 0.000005, 0.000005, 0.000005, 0.000005, 0.000005, 0.000005, 0.000005, 0.000005, 0.000005, 0.000005, 0.000005   ]
                    max:                            [1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      0.00031    ]
                    index_of_wavelength_involved:   [0,        0,        0,        0,        0,        0,        0,        0 ,       0,        0,        0,        0,        0,        0,        0          ]
                single_pixel:
                    smoothness_constraints:
                        difference_order: 3
                        lagrange_multiplier: 1.0e-2
                multi_pixel:
                    smoothness_constraints:
                       derivative_order_of_X_variability:    0
                       lagrange_multiplier_of_X_variability: 0.0                        
                       derivative_order_of_Y_variability:    0
                       lagrange_multiplier_of_Y_variability: 0.0                     
                       derivative_order_of_T_variability:    0
                       lagrange_multiplier_of_T_variability: 0.0                                                                   

        characteristic[2]: #2
            type: real_part_of_refractive_index_spectral_dependent
            retrieved: true
            mode[1]:
                initial_guess:                      #1          #2        #3        #4        #5        #6        #7
                    value:                          [1.45,      1.45,     1.45,     1.45,     1.45,     1.45,     1.45   ]
                    min:                            [1.33,      1.33,     1.33,     1.33,     1.33,     1.33,     1.33   ]
                    max:                            [1.6,       1.6,      1.6,      1.6,      1.6,      1.6,      1.6    ]
                    index_of_wavelength_involved:   [1,         2,        3,        4,        5,        6,         7     ]
                single_pixel:
                    smoothness_constraints:
                        difference_order: 1
                        lagrange_multiplier: 1.0e+3
                multi_pixel:
                    smoothness_constraints:
                       derivative_order_of_X_variability:    0
                       lagrange_multiplier_of_X_variability: 0.0                        
                       derivative_order_of_Y_variability:    0
                       lagrange_multiplier_of_Y_variability: 0.0                     
                       derivative_order_of_T_variability:    0
                       lagrange_multiplier_of_T_variability: 0.0
            mode[2]:
                initial_guess:                      #1          #2        #3        #4        #5        #6        #7
                    value:                          [1.45,      1.45,     1.45,     1.45,     1.45,     1.45,     1.45   ]
                    min:                            [1.33,      1.33,     1.33,     1.33,     1.33,     1.33,     1.33   ]
                    max:                            [1.6,       1.6,      1.6,      1.6,      1.6,      1.6,      1.6    ]
                    index_of_wavelength_involved:   [1,         2,        3,        4,        5,        6,         7     ]
                single_pixel:
                    smoothness_constraints:
                        difference_order: 1
                        lagrange_multiplier: 1.0e+3
                multi_pixel:
                    smoothness_constraints:
                       derivative_order_of_X_variability:    0
                       lagrange_multiplier_of_X_variability: 0.0                        
                       derivative_order_of_Y_variability:    0
                       lagrange_multiplier_of_Y_variability: 0.0                     
                       derivative_order_of_T_variability:    0
                       lagrange_multiplier_of_T_variability: 0.0                    
                                                     
        characteristic[3]: #3
            type: imaginary_part_of_refractive_index_spectral_dependent
            retrieved: true
            mode[1]:
                initial_guess:                      #1         #2        #3        #4        #5        #6        #7
                    value:                          [0.005,    0.005,    0.005,    0.005,    0.005,    0.005,    0.005    ]
                    min:                            [0.0005,   0.0005,   0.0005,   0.0005,   0.0005,   0.0005,   0.0005   ]
                    max:                            [0.1,      0.1,      0.1,      0.1,      0.1,      0.1,      0.1      ]
                    index_of_wavelength_involved:   [1,        2,        3,        4,        5,        6,        7        ]
                single_pixel:
                    smoothness_constraints:
                        difference_order: 1
                        lagrange_multiplier: 1.0e+1
                multi_pixel:
                    smoothness_constraints:
                       derivative_order_of_X_variability:    0
                       lagrange_multiplier_of_X_variability: 0.0                        
                       derivative_order_of_Y_variability:    0
                       lagrange_multiplier_of_Y_variability: 0.0                     
                       derivative_order_of_T_variability:    0
                       lagrange_multiplier_of_T_variability: 0.0
            mode[2]:
                initial_guess:                      #1         #2        #3        #4        #5        #6        #7
                    value:                          [0.005,    0.005,    0.005,    0.005,    0.005,    0.005,    0.005    ]
                    min:                            [0.0005,   0.0005,   0.0005,   0.0005,   0.0005,   0.0005,   0.0005   ]
                    max:                            [0.1,      0.1,      0.1,      0.1,      0.1,      0.1,      0.1      ]
                    index_of_wavelength_involved:   [1,        2,        3,        4,        5,        6,        7        ]
                single_pixel:
                    smoothness_constraints:
                        difference_order: 2
                        lagrange_multiplier: 1.0e+1
                multi_pixel:
                    smoothness_constraints:
                       derivative_order_of_X_variability:    0
                       lagrange_multiplier_of_X_variability: 0.0                        
                       derivative_order_of_Y_variability:    0
                       lagrange_multiplier_of_Y_variability: 0.0                     
                       derivative_order_of_T_variability:    0
                       lagrange_multiplier_of_T_variability: 0.0                    
 
        characteristic[4]: #4
            type: sphere_fraction
            retrieved: true
            mode[1]:
                initial_guess:                       #1      
                    value:                          [0.5]
                    min:                            [0.00001]
                    max:                            [0.9999]
                    index_of_wavelength_involved:   [0]
                single_pixel:
                    smoothness_constraints:
                        difference_order: 0
                        lagrange_multiplier: 0.0
                multi_pixel:
                    smoothness_constraints:
                       derivative_order_of_X_variability:    0
                       lagrange_multiplier_of_X_variability: 0.0                        
                       derivative_order_of_Y_variability:    0
                       lagrange_multiplier_of_Y_variability: 0.0                     
                       derivative_order_of_T_variability:    0
                       lagrange_multiplier_of_T_variability: 0.0                   
                         
        characteristic[5]: #5
            type: vertical_profile_normalized
            retrieved: true
            mode[1]:
                initial_guess:
                    value:                          [ ^repeat(0.01;60)]
                    min:                            [ ^repeat(0.000001;60) ]
                    max:                            [ ^repeat(1.0;60) ]
                    index_of_wavelength_involved:   [ ^repeat(0;60) ]
                single_pixel:
                    smoothness_constraints:
                        difference_order: 3
                        lagrange_multiplier: 1.0e-5
                multi_pixel:
                    smoothness_constraints:
                       derivative_order_of_X_variability:    0
                       lagrange_multiplier_of_X_variability: 0.0                        
                       derivative_order_of_Y_variability:    0
                       lagrange_multiplier_of_Y_variability: 0.0                     
                       derivative_order_of_T_variability:    0
                       lagrange_multiplier_of_T_variability: 0.0 
            mode[2]:
                initial_guess:                       #1         #2        #3        #4        #5        #6        #7        #8        #9        #10       #11       #12       #13       #14       #15       #16       #17       #18       #19       #20       #21       #22       #23       #24       #25       #26       #27       #28       #29       #30       #31       #32       #33       #34       #35       #36       #37       #38       #39       #40       #41       #42       #43       #44       #45       #46       #47       #48       #49       #50       #51       #52       #53       #54       #55       #56       #57       #58       #59       #60       
                    value:                          [ 0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01,     0.01     ]
                    min:                            [ 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001 ]
                    max:                            [ 1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0,      1.0      ]
                    index_of_wavelength_involved:   [ 0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0,        0        ]
                single_pixel:
                    smoothness_constraints:
                        difference_order: 3
                        lagrange_multiplier: 1.0e-5
                multi_pixel:
                    smoothness_constraints:
                       derivative_order_of_X_variability:    0
                       lagrange_multiplier_of_X_variability: 0.0                        
                       derivative_order_of_Y_variability:    0
                       lagrange_multiplier_of_Y_variability: 0.0                     
                       derivative_order_of_T_variability:    0
                       lagrange_multiplier_of_T_variability: 0.0                     
                          
        characteristic[6]: #6
            type: surface_land_brdf_ross_li
            retrieved: false
            mode[1]:    
                initial_guess:                      #1          #2         #3         #4         #5         #6         #7        
                    value:                          [0.029931,  0.054737,  0.082492,  0.124613,  0.321381,  0.313084,  0.310961 ]
                    min:                            [0.029,     0.054,     0.082,     0.124,     0.310,     0.310,     0.310    ]
                    max:                            [0.215,     0.215,     0.215,     0.4,       0.7,       0.75,      0.75     ]
                    index_of_wavelength_involved:   [1,         2,         3,         4,         5,         6,         7        ]
                single_pixel:
                    smoothness_constraints:
                        difference_order: 0
                        lagrange_multiplier: 0.0
                multi_pixel:
                    smoothness_constraints:
                        derivative_order_of_T_variability:    0
                        lagrange_multiplier_of_T_variability: 0.0    
                        derivative_order_of_X_variability:    0
                        lagrange_multiplier_of_X_variability: 0.0                        
                        derivative_order_of_Y_variability:    0
                        lagrange_multiplier_of_Y_variability: 0.0
                               
            mode[2]:
                initial_guess:                      #1          #2         #3         #4         #5         #6         #7       
                    value:                          [0.006174,  0.023644,  0.042635,  0.071903,  0.214659,  0.209092,  0.207668 ]
                    min:                            [0.006,     0.02,      0.04,      0.07,      0.2,       0.2,       0.2      ]
                    max:                            [1.0,       1.0,       1.0,       1.0,       1.0,       1.0,       1.0      ]
                    index_of_wavelength_involved:   [1,         2,         3,         4,         5,         6,         7        ]
                single_pixel:
                    smoothness_constraints:
                        difference_order: 0
                        lagrange_multiplier: 0.0
                multi_pixel:
                    smoothness_constraints:
                        derivative_order_of_T_variability:    0
                        lagrange_multiplier_of_T_variability: 0.0    
                        derivative_order_of_X_variability:    0
                        lagrange_multiplier_of_X_variability: 0.0                        
                        derivative_order_of_Y_variability:    0
                        lagrange_multiplier_of_Y_variability: 0.0                   
                        
            mode[3]:
                initial_guess:                       #1          #2          #3          #4          #5          #6          #7              
                    value:                          [0.004220,   0.008678,   0.013624,   0.021164,   0.026278,   0.025621,   0.025453 ]
                    min:                            [0.004,      0.008,      0.01,       0.02,       0.02,       0.02,       0.02     ]
                    max:                            [1.5,        1.5,        1.5,        1.5,        1.5,        1.5,        1.5      ]
                    index_of_wavelength_involved:   [1,          2,          3,          4,          5,          6,          7        ]
                single_pixel:
                    smoothness_constraints:
                        difference_order: 0
                        lagrange_multiplier: 0.0
                multi_pixel:
                    smoothness_constraints:
                        derivative_order_of_T_variability:    0
                        lagrange_multiplier_of_T_variability: 0.0    
                        derivative_order_of_X_variability:    0
                        lagrange_multiplier_of_X_variability: 0.0                        
                        derivative_order_of_Y_variability:    0
                        lagrange_multiplier_of_Y_variability: 0.0                   
                        
        characteristic[7]: #7
            type: surface_land_polarized_maignan_breon
            retrieved: false
            mode[1]:
                initial_guess:                      #1         #2         #3         #4         #5         #6         #7          
                    value:                          [2.1,      2.1,       2.1,       2.1,       2.1,       2.1,       2.1   ]
                    min:                            [0.01,     0.01,      0.01,      0.01,      0.01,      0.01,      0.01  ]
                    max:                            [10.,      10.,       10.,       10.,       10.,       10.,       10.0  ]
                    index_of_wavelength_involved:   [1,         2,         3,         4,         5,         6,         7    ]
                single_pixel:
                    smoothness_constraints:
                        difference_order: 0
                        lagrange_multiplier: 0.0
                multi_pixel:
                    smoothness_constraints:
                        derivative_order_of_T_variability:    0
                        lagrange_multiplier_of_T_variability: 0.0    
                        derivative_order_of_X_variability:    0
                        lagrange_multiplier_of_X_variability: 0.0                        
                        derivative_order_of_Y_variability:    0
                        lagrange_multiplier_of_Y_variability: 0.0                     
                                                  
