libplanarradpy/planrad.py
def write_batch_report(self, input_directory, parameter):
        """
        Collect all of the batch reports and concatenate the results.  The report should be :

        :param input_directory:
        :param parameter: This is the parameter in which to report.
        """

        # Check to see if there is an @ in the parameter.  If there is split
        if '@' in parameter:
            parameter_dir = parameter.split('@')[1]
            parameter = parameter.split('@')[0]

        # --------------------------------------------------#
        # we put the batch report one directory up in the tree
        # --------------------------------------------------#
        batch_report_file = 'batch_report.txt'
        batch_report_file = os.path.join(input_directory, batch_report_file)
        f = open(batch_report_file, 'w')
        w = csv.writer(f, delimiter=',')

        #--------------------------------------------------#
        # Read in the report from planarrad and pull out the parameter that we want
        #--------------------------------------------------#
        dir_list = os.listdir(input_directory)

        #--------------------------------------------------#
        # Sometimes the report isn't generated for some reason.
        # this checks to see if the first file in the dir list exists and skips if it doesn't
        #--------------------------------------------------#
        read_first_file = True
        i_iter = 0
        while read_first_file:
            if os.path.exists(os.path.join(input_directory, os.path.join(dir_list[i_iter], 'report.txt'))):
                report = self.read_pr_report(
                    os.path.join(input_directory, os.path.join(dir_list[i_iter], 'report.txt')))
                read_first_file = False
            else:
                lg.warning('Missing report file in' + dir_list[i_iter])
                i_iter += 1

        try:
            wave_val = report['band_centres']
            param_val = report[parameter]
        except:
            lg.exception('Parameter :: ' + str(parameter) + ' :: Not in report')

        wave_str = str(wave_val)
        wave_str = wave_str.strip('[').strip(']').replace('\'', '').replace('\\n', '').replace('  ', '').replace(' -,',
                                                                                                                 '').replace(
            ',', '\",\"')

        f.write(
            '\"Sun Azimuth (deg)\",\"Sun Zenith (deg)\",\"Phytoplankton\",\"Scattering X\",\"Scattering Y\",\"CDOM G\",\"CDOM S\",\"Depth (m)\",\"#wave length (nm) ->\",\"' + wave_str + '\"\n')

        #--------------------------------------------------#
        # Get all of the directories under the batch directories
        # The directory names have the IOP parameters in the names
        #--------------------------------------------------#

        for dir in dir_list:
            if os.path.isdir(os.path.abspath(os.path.join(input_directory, dir))):
                tmp_str_list = dir.split('_')
                #for tmp_str in tmp_str_list:
                saa = ''.join(c for c in tmp_str_list[0] if not c.isalpha())
                sza = ''.join(c for c in tmp_str_list[1] if not c.isalpha())
                p = ''.join(c for c in tmp_str_list[2] if not c.isalpha())
                x = ''.join(c for c in tmp_str_list[3] if not c.isalpha())
                y = ''.join(c for c in tmp_str_list[4] if not c.isalpha())
                g = ''.join(c for c in tmp_str_list[5] if not c.isalpha())
                s = ''.join(c for c in tmp_str_list[6] if not c.isalpha())
                z = ''.join(c for c in tmp_str_list[7] if not c.isalpha())

                #--------------------------------------------------#
                # Write the report header and then the values above in the columns
                #--------------------------------------------------#
                try:
                    f.write(saa + ',' + sza + ',' + p + ',' + x + ',' + y + ',' + g + ',' + s + ',' + z + ',')

                    report = self.read_pr_report(os.path.join(input_directory, os.path.join(dir, 'report.txt')))
                    try:
                        # check to see if the parameter has the @ parameter.  If it does pass to directional calculator
                        if 'parameter_dir' in locals():
                            param_val = self.calc_directional_aop(report, parameter, parameter_dir)
                        else:
                            param_val = report[parameter]

                        param_str = str(param_val)
                        param_str = param_str.strip('[').strip(']').replace('\'', '').replace('\\n', '').replace('  ',
                                                                                                                 '')
                        f.write(param_str + '\n')
                    except:
                        lg.exception('Parameter :: ' + str(parameter) + ' :: Not in report')
                except:
                    lg.warning('Cannot find a report in directory :: ' + dir)
def write_batch_report(self, input_directory, parameter):
        """
        Collect all of the batch reports and concatenate the results.  The report should be :

        :param input_directory:
        :param parameter: This is the parameter in which to report.
        """

        # Check to see if there is an @ in the parameter.  If there is split
        if '@' in parameter:
            parameter_dir = parameter.split('@')[1]
            parameter = parameter.split('@')[0]

        # --------------------------------------------------#
        # we put the batch report one directory up in the tree
        # --------------------------------------------------#
        batch_report_file = 'batch_report.txt'
        batch_report_file = os.path.join(input_directory, batch_report_file)
        f = open(batch_report_file, 'w')
        w = csv.writer(f, delimiter=',')

        #--------------------------------------------------#
        # Read in the report from planarrad and pull out the parameter that we want
        #--------------------------------------------------#
        dir_list = os.listdir(input_directory)

        #--------------------------------------------------#
        # Sometimes the report isn't generated for some reason.
        # this checks to see if the first file in the dir list exists and skips if it doesn't
        #--------------------------------------------------#
        read_first_file = True
        i_iter = 0
        while read_first_file:
            if os.path.exists(os.path.join(input_directory, os.path.join(dir_list[i_iter], 'report.txt'))):
                report = self.read_pr_report(
                    os.path.join(input_directory, os.path.join(dir_list[i_iter], 'report.txt')))
                read_first_file = False
            else:
                lg.warning('Missing report file in' + dir_list[i_iter])
                i_iter += 1

        try:
            wave_val = report['band_centres']
            param_val = report[parameter]
        except:
            lg.exception('Parameter :: ' + str(parameter) + ' :: Not in report')

        wave_str = str(wave_val)
        wave_str = wave_str.strip('[').strip(']').replace('\'', '').replace('\\n', '').replace('  ', '').replace(' -,',
                                                                                                                 '').replace(
            ',', '\",\"')

        f.write(
            '\"Sun Azimuth (deg)\",\"Sun Zenith (deg)\",\"Phytoplankton\",\"Scattering X\",\"Scattering Y\",\"CDOM G\",\"CDOM S\",\"Depth (m)\",\"#wave length (nm) ->\",\"' + wave_str + '\"\n')

        #--------------------------------------------------#
        # Get all of the directories under the batch directories
        # The directory names have the IOP parameters in the names
        #--------------------------------------------------#

        for dir in dir_list:
            if os.path.isdir(os.path.abspath(os.path.join(input_directory, dir))):
                tmp_str_list = dir.split('_')
                #for tmp_str in tmp_str_list:
                saa = ''.join(c for c in tmp_str_list[0] if not c.isalpha())
                sza = ''.join(c for c in tmp_str_list[1] if not c.isalpha())
                p = ''.join(c for c in tmp_str_list[2] if not c.isalpha())
                x = ''.join(c for c in tmp_str_list[3] if not c.isalpha())
                y = ''.join(c for c in tmp_str_list[4] if not c.isalpha())
                g = ''.join(c for c in tmp_str_list[5] if not c.isalpha())
                s = ''.join(c for c in tmp_str_list[6] if not c.isalpha())
                z = ''.join(c for c in tmp_str_list[7] if not c.isalpha())

                #--------------------------------------------------#
                # Write the report header and then the values above in the columns
                #--------------------------------------------------#
                try:
                    f.write(saa + ',' + sza + ',' + p + ',' + x + ',' + y + ',' + g + ',' + s + ',' + z + ',')

                    report = self.read_pr_report(os.path.join(input_directory, os.path.join(dir, 'report.txt')))
                    try:
                        # check to see if the parameter has the @ parameter.  If it does pass to directional calculator
                        if 'parameter_dir' in locals():
                            param_val = self.calc_directional_aop(report, parameter, parameter_dir)
                        else:
                            param_val = report[parameter]

                        param_str = str(param_val)
                        param_str = param_str.strip('[').strip(']').replace('\'', '').replace('\\n', '').replace('  ',
                                                                                                                 '')
                        f.write(param_str + '\n')
                    except:
                        lg.exception('Parameter :: ' + str(parameter) + ' :: Not in report')
                except:
                    lg.warning('Cannot find a report in directory :: ' + dir)
Collect all of the batch reports and concatenate the results.  The report should be :

        :param input_directory:
        :param parameter: This is the parameter in which to report.