示例#1
0
    def processL1a(inFilePath, outFilePath, calibrationMap):
        root = None
        if not os.path.isfile(inFilePath):
            msg = 'No such file...'
            Utilities.errorWindow("File Error", msg)
            print(msg)
            Utilities.writeLogFile(msg)
            return None, 'Never'

        # Process the data
        msg = "ProcessL1a"
        print(msg)
        root = ProcessL1a.processL1a(inFilePath, calibrationMap)

        # Write output file
        if root is not None:
            try:
                root.writeHDF5(outFilePath)
            except:
                msg = 'Unable to write L1A file. It may be open in another program.'
                Utilities.errorWindow("File Error", msg)
                print(msg)
                Utilities.writeLogFile(msg)
                return None
        else:
            msg = "L1a processing failed. Nothing to output."
            if MainConfig.settings["popQuery"] == 0:
                Utilities.errorWindow("File Error", msg)
            print(msg)
            Utilities.writeLogFile(msg)
            return None

        return root
示例#2
0
    def processL1bqc(inFilePath, outFilePath):
        root = None

        if not os.path.isfile(inFilePath):
            print('No such input file: ' + inFilePath)
            return None

        # Process the data
        print("ProcessL1bqc")
        try:
            root = HDFRoot.readHDF5(inFilePath)
        except:
            msg = "Unable to open file. May be open in another application."
            Utilities.errorWindow("File Error", msg)
            print(msg)
            Utilities.writeLogFile(msg)
            return None

        root.attributes['In_Filepath'] = inFilePath
        root = ProcessL1bqc.processL1bqc(root)

        # Write output file
        if root is not None:
            try:
                root.writeHDF5(outFilePath)
            except:
                msg = "Unable to write file. May be open in another application."
                Utilities.errorWindow("File Error", msg)
                print(msg)
                Utilities.writeLogFile(msg)
                return None,
        else:
            msg = "L1bqc processing failed. Nothing to output."
            if MainConfig.settings["popQuery"] == 0:
                Utilities.errorWindow("File Error", msg)
            print(msg)
            Utilities.writeLogFile(msg)
            return None

        return root
示例#3
0
    def processL1b(inFilePath, outFilePath):
        root = None
        if not os.path.isfile(inFilePath):
            print('No such input file: ' + inFilePath)
            return None

        # Process the data
        msg = ("ProcessL1b: " + inFilePath)
        print(msg)
        Utilities.writeLogFile(msg)
        try:
            root = HDFRoot.readHDF5(inFilePath)
        except:
            msg = "Controller.processL1b: Unable to open HDF file. May be open in another application."
            Utilities.errorWindow("File Error", msg)
            print(msg)
            Utilities.writeLogFile(msg)
            return None

        root = ProcessL1b.processL1b(root, outFilePath)

        # Write output file
        if root is not None:
            try:
                root.writeHDF5(outFilePath)
            except:
                msg = "Controller.ProcessL1b: Unable to write file. May be open in another application."
                Utilities.errorWindow("File Error", msg)
                print(msg)
                Utilities.writeLogFile(msg)
                return None
        else:
            msg = "L1b processing failed. Nothing to output."
            if MainConfig.settings["popQuery"] == 0:
                Utilities.errorWindow("File Error", msg)
            print(msg)
            Utilities.writeLogFile(msg)
            return None

        return root
示例#4
0
    def processL1aqc(inFilePath, outFilePath, calibrationMap, ancillaryData):
        root = None
        if not os.path.isfile(inFilePath):
            print('No such input file: ' + inFilePath)
            return None

        # Process the data
        print("ProcessL1aqc")
        try:
            root = HDFRoot.readHDF5(inFilePath)
        except:
            msg = "Unable to open file. May be open in another application."
            Utilities.errorWindow("File Error", msg)
            print(msg)
            Utilities.writeLogFile(msg)
            return None

        # At this stage the Anomanal parameterizations are current in ConfigFile.settings,
        #   regardless of who called this method.  This method will promote them to root.attributes.
        root = ProcessL1aqc.processL1aqc(root, calibrationMap, ancillaryData)

        # Write output file
        if root is not None:
            try:
                root.writeHDF5(outFilePath)
            except:
                msg = "Unable to write the file. May be open in another application."
                Utilities.errorWindow("File Error", msg)
                print(msg)
                Utilities.writeLogFile(msg)
                return None
        else:
            msg = "L1aqc processing failed. Nothing to output."
            if MainConfig.settings["popQuery"] == 0:
                Utilities.errorWindow("File Error", msg)
            print(msg)
            Utilities.writeLogFile(msg)
            return None

        return root
示例#5
0
    def processL2(inFilePath, outFilePath):
        root = None
        if not os.path.isfile(inFilePath):
            print('No such input file: ' + inFilePath)
            return None, outFilePath

        # Process the data
        msg = ("ProcessL2: " + inFilePath)
        print(msg)
        Utilities.writeLogFile(msg)
        try:
            root = HDFRoot.readHDF5(inFilePath)
        except:
            msg = "Unable to open file. May be open in another application."
            Utilities.errorWindow("File Error", msg)
            print(msg)
            Utilities.writeLogFile(msg)
            return None, outFilePath

        root = ProcessL2.processL2(root)

        outPath, filename = os.path.split(outFilePath)
        if root is not None:
            if ConfigFile.settings["bL2Stations"]:
                station = np.unique(
                    root.getGroup("ANCILLARY").getDataset(
                        "STATION").columns["STATION"]).tolist()
                station = str(round(station[0] * 100) / 100)
                filename = f'STATION_{station}_{filename}'
                outFilePath = os.path.join(outPath, filename)

            # Create Plots
            # Radiometry
            if ConfigFile.settings['bL2PlotRrs'] == 1:
                Utilities.plotRadiometry(root,
                                         filename,
                                         rType='Rrs',
                                         plotDelta=True)
            if ConfigFile.settings['bL2PlotnLw'] == 1:
                Utilities.plotRadiometry(root,
                                         filename,
                                         rType='nLw',
                                         plotDelta=True)
            if ConfigFile.settings['bL2PlotEs'] == 1:
                Utilities.plotRadiometry(root,
                                         filename,
                                         rType='ES',
                                         plotDelta=True)
            if ConfigFile.settings['bL2PlotLi'] == 1:
                Utilities.plotRadiometry(root,
                                         filename,
                                         rType='LI',
                                         plotDelta=True)
            if ConfigFile.settings['bL2PlotLt'] == 1:
                Utilities.plotRadiometry(root,
                                         filename,
                                         rType='LT',
                                         plotDelta=True)

            # IOPs
            # These three should plot GIOP and QAA together (eventually, once GIOP is complete)
            if ConfigFile.products["bL2ProdadgQaa"]:
                Utilities.plotIOPs(root,
                                   filename,
                                   algorithm='qaa',
                                   iopType='adg',
                                   plotDelta=False)
            if ConfigFile.products["bL2ProdaphQaa"]:
                Utilities.plotIOPs(root,
                                   filename,
                                   algorithm='qaa',
                                   iopType='aph',
                                   plotDelta=False)
            if ConfigFile.products["bL2ProdbbpQaa"]:
                Utilities.plotIOPs(root,
                                   filename,
                                   algorithm='qaa',
                                   iopType='bbp',
                                   plotDelta=False)

            # This puts ag, Sg, and DOC on the same plot
            if ConfigFile.products["bL2Prodgocad"] and ConfigFile.products["bL2ProdSg"] \
                 and ConfigFile.products["bL2Prodag"] and ConfigFile.products["bL2ProdDOC"]:
                Utilities.plotIOPs(root,
                                   filename,
                                   algorithm='gocad',
                                   iopType='ag',
                                   plotDelta=False)

        # Write output file
        if root is not None:
            try:
                root.writeHDF5(outFilePath)
                return root, outFilePath
            except:
                msg = "Unable to write file. May be open in another application."
                Utilities.errorWindow("File Error", msg)
                print(msg)
                Utilities.writeLogFile(msg)
                return None, outFilePath
        else:
            msg = "L2 processing failed. Nothing to output."
            if MainConfig.settings["popQuery"] == 0:
                Utilities.errorWindow("File Error", msg)
            print(msg)
            Utilities.writeLogFile(msg)
            return None, outFilePath
示例#6
0
    def writeReport(fileName, pathOut, outFilePath, level, inFilePath):
        print('Writing PDF Report...')
        numLevelDict = {'L1A': 1, 'L1AQC': 2, 'L1B': 3, 'L1BQC': 4, 'L2': 5}
        numLevel = numLevelDict[level]
        fp = os.path.join(pathOut, level, f'{fileName}_{level}.hdf')

        # Reports are written during failure at any level or success at L2.
        # The highest level succesfully processed will have the correct configurations in the HDF attributes.

        #   Try to open current level. If this fails, open the previous level and use all the parameters
        #   from the attributes up to that level, then use the ConfigFile.settings for the current level parameters.
        try:
            # Processing successful at this level
            root = HDFRoot.readHDF5(fp)
            fail = 0
            root.attributes['Fail'] = 0
        except:
            fail = 1
            # Processing failed at this level. Open the level below it
            #   This won't work for ProcessL1A looking back for RAW...
            if level != 'L1A':
                try:
                    # Processing successful at the next lower level
                    # Shift from the output to the input directory
                    root = HDFRoot.readHDF5(inFilePath)
                except:
                    msg = "Controller.writeReport: Unable to open HDF file. May be open in another application."
                    Utilities.errorWindow("File Error", msg)
                    print(msg)
                    Utilities.writeLogFile(msg)
                    return

            else:
                # Create a root with nothing but the fail flag in the attributes to pass to PDF reporting
                #   PDF will contain parameters from ConfigFile.settings
                root = HDFRoot()
                root.id = "/"
                root.attributes["HYPERINSPACE"] = MainConfig.settings[
                    "version"]
                root.attributes[
                    'TIME-STAMP'] = 'Null'  # Collection time not preserved in failed RAW>L1A
            root.attributes['Fail'] = 1

        timeStamp = root.attributes['TIME-STAMP']
        title = f'File: {fileName} Collected: {timeStamp}'

        # Reports
        reportPath = os.path.join(pathOut, 'Reports')
        if os.path.isdir(reportPath) is False:
            os.mkdir(reportPath)
        dirPath = os.getcwd()
        inLogPath = os.path.join(dirPath, 'Logs')

        inPlotPath = os.path.join(pathOut, 'Plots')
        # The inPlotPath is going to be different for L1A-L1E than L2 for many cruises...
        # In that case, move up one directory
        if os.path.isdir(os.path.join(inPlotPath, 'L1AQC_Anoms')) is False:
            inPlotPath = os.path.join(pathOut, '..', 'Plots')
        outHDF = os.path.split(outFilePath)[1]

        if fail:
            outPDF = os.path.join(reportPath,
                                  f'{os.path.splitext(outHDF)[0]}_fail.pdf')
        else:
            outPDF = os.path.join(reportPath,
                                  f'{os.path.splitext(outHDF)[0]}.pdf')

        pdf = PDF()
        pdf.set_title(title)
        pdf.set_author(f'HyperInSPACE_{MainConfig.settings["version"]}')

        inLog = os.path.join(inLogPath, f'{fileName}_L1A.log')
        if os.path.isfile(inLog):
            print('Level 1A')
            pdf.print_chapter('L1A', 'Process RAW to L1A', inLog, inPlotPath,
                              fileName, outFilePath, root)

        if numLevel > 1:
            print('Level 1AQC')
            inLog = os.path.join(inLogPath, f'{fileName}_L1A_L1AQC.log')
            if os.path.isfile(inLog):
                pdf.print_chapter('L1AQC', 'Process L1A to L1AQC', inLog,
                                  inPlotPath, fileName, outFilePath, root)

        if numLevel > 2:
            print('Level 1B')
            inLog = os.path.join(inLogPath, f'{fileName}_L1AQC_L1B.log')
            if os.path.isfile(inLog):
                pdf.print_chapter('L1B', 'Process L1AQC to L1B', inLog,
                                  inPlotPath, fileName, outFilePath, root)

        if numLevel > 3:
            print('Level 1BQC')
            inLog = os.path.join(inLogPath, f'{fileName}_L1B_L1BQC.log')
            if os.path.isfile(inLog):
                pdf.print_chapter('L1BQC', 'Process L1B to L1BQC', inLog,
                                  inPlotPath, fileName, outFilePath, root)

        if numLevel > 4:
            print('Level 2')
            # For L2, reset Plot directory
            inPlotPath = os.path.join(pathOut, 'Plots')
            inLog = os.path.join(inLogPath, f'{fileName}_L1BQC_L2.log')
            if os.path.isfile(inLog):
                pdf.print_chapter('L2', 'Process L1BQC to L2', inLog,
                                  inPlotPath, fileName, outFilePath, root)

        try:
            pdf.output(outPDF, 'F')
        except:
            msg = 'Unable to write the PDF file. It may be open in another program.'
            Utilities.errorWindow("File Error", msg)
            print(msg)
            Utilities.writeLogFile(msg)