Exemplo n.º 1
0
    def pre_processing(self):
        LOGGER.info("Starting Preprocessing")
        self._l1product = product_utils.get_input_l1_image_product(self._apphandler.get_input_directory(),
                                                                   tile_id=self._apphandler.get_tile_id())
        self.init_list_of_sat()
        self.activate_this_sat(self._l1product.Satellite, self._l1product.PluginName, self._l1product.UniqueSatellite)

        # Instanciate plugin
        self.plugin = MAJAPluginProvider.create(self._l1product.PluginName, self._apphandler)
        super(L2NominalProcessor, self).pre_processing()
        LOGGER.info("Ending Preprocessing")
    def scientific_processing(self):
        LOGGER.info("Starting ScientifiqProcessing")
        # Scientific processing mode. Set to INIT, NOMINAL or BACKWARD value
        l_NumberOfL1Product = len(self._listofl1product)
        LOGGER.debug(self._listofl1product)
        # Check if more than one valid input is in the list
        if l_NumberOfL1Product == 1:
            raise MajaDataException(
                "L2BackwardProcessing need more than one input L1 image product."
            )
        # Process the last product in the list with INIT MODE
        # Initialize the mode
        l_InitMode = True
        l_BackwardMode = True
        l_IndexOfL1Product = l_NumberOfL1Product
        l_finalize_backward = False

        l_EnableL2ResolutionProcessing = self._apphandler.get_user_conf(
        ).get_Computing().get_EnableL2ResolutionProcessing()
        if not l_EnableL2ResolutionProcessing:
            LOGGER.info(
                "*************************************************************************************************"
            )
            LOGGER.info(
                "ATTENTION: L2BACKWARD PROCESSING: The option to Write product to L2 resolution has been DISABLE !!!"
            )
            LOGGER.info(
                "**************************************************************************************************"
            )

        # ----------------------------------------------------------------
        # Initialize the flag to validate the clouds probably
        # ----------------------------------------------------------------
        self._checking_conditional_clouds = False
        l_conditional_loop = False
        l_write_earthexplorer_headers = False
        l_write_temporary_l2_product = True
        l_write_l2_product_to_l2resolution = False

        l_InputL2ImageFilename = ""
        while not l_conditional_loop:
            l_InputL1ProductInfo = self._listofl1product[l_IndexOfL1Product -
                                                         1]
            l_Sat = l_InputL1ProductInfo.Satellite
            # If last L1 product, write headers and write in the output directory
            # ----------------------------------------------------------------
            if l_IndexOfL1Product == 1:
                l_write_earthexplorer_headers = True
                l_write_l2_product_to_l2resolution = l_EnableL2ResolutionProcessing
                l_write_temporary_l2_product = False
                l_finalize_backward = True

                LOGGER.warn(
                    "L2Backward processing: the input L1 product valid for the Init mode is the last product. The Standard mode is disable !"
                )

            # *************************************************************************************************************
            # Init the current PluginBase pointer for the satellite in the MAIN global DataApplicationHandler Instance
            # *************************************************************************************************************
            self.plugin = MAJAPluginProvider.create(
                l_InputL1ProductInfo.PluginName, self._apphandler)
            """ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **  **
                    Get and registers the L2COMM GIPP file  L2COMM
                    parameters have been read in the L1ImaegFileReader !!
                     ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *"""
            l_GIP_L2COMM_Filename = gipp_utils.get_gipp_filename_with_mission(
                self._apphandler.get_input_directory(), "GIP_L2COMM", l_Sat)
            if self._apphandler._stylesheet is not None:
                LOGGER.debug("Overloading L2COMM parameters...")
                l_GIP_L2COMM_Filename = file_utils.copy_file_to_directory(
                    l_GIP_L2COMM_Filename,
                    self._apphandler.get_working_directory(),
                    notestmode=True)
                translate_xsl(l_GIP_L2COMM_Filename,
                              self._apphandler._stylesheet)

            LOGGER.info("The GIP_L2COMM file detected for the satellite '" +
                        l_Sat + "' is <" + l_GIP_L2COMM_Filename + ">.")
            l_GIPPL2COMMHandler = GippL2COMMEarthExplorerXMLFileHandler(
                l_GIP_L2COMM_Filename)
            """ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **  **
            Register the GIPP file "GIP_L2SITE" */
             ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *"""
            l_GIP_L2SITE_Filename = gipp_utils.get_gipp_filename_with_mission(
                self._apphandler.get_input_directory(), "GIP_L2SITE",
                l_InputL1ProductInfo.UniqueSatellite)
            if self._apphandler._stylesheet is not None:
                LOGGER.debug("Overloading L2SITE parameters...")
                l_GIP_L2SITE_Filename = file_utils.copy_file_to_directory(
                    l_GIP_L2SITE_Filename,
                    self._apphandler.get_working_directory(),
                    notestmode=True)
                translate_xsl(l_GIP_L2SITE_Filename,
                              self._apphandler._stylesheet)

            LOGGER.info("The GIP_L2SITE file detected for the satellite '" +
                        l_InputL1ProductInfo.UniqueSatellite + "' is <" +
                        l_GIP_L2SITE_Filename + ">.")

            # *************************************************************************************************************
            # Initialize the L1 Image file reader
            # *************************************************************************************************************
            l_UniqueSatelliteD = l_InputL1ProductInfo.UniqueSatellite
            l1_image_reader = L1ImageReaderProvider.create(
                l_InputL1ProductInfo.PluginName, l_InputL1ProductInfo,
                self._apphandler, l_GIPPL2COMMHandler,
                self.DataDEMMap.get(l_UniqueSatelliteD),
                constants.ReadL1Mode.READ_L1_MODE_FOR_ALGORITHMS)

            # *************************************************************************************************************
            # Initialize the L2 Image file writer
            # *************************************************************************************************************
            if self._apphandler.get_output_plugin() is not None:
                l2_image_file_writer = L2ImageWriterProvider.create(
                    self._apphandler.get_output_plugin())
            else:
                l2_image_file_writer = L2ImageWriterProvider.create(
                    MAJAPluginProvider.auto_tm(
                        l_InputL1ProductInfo.PluginName))
            if not l2_image_file_writer.can_write(
                    l_InputL1ProductInfo.PluginName):
                raise MajaDriverException(
                    "Plugin '" + self._apphandler.get_output_plugin() +
                    "' can not write product from '" +
                    l_InputL1ProductInfo.PluginName + "' products ")

            # Log system infos
            LOGGER.info(self._apphandler.get_system_infos())
            # Compute the Single product
            # ----------------------------------------------------------------
            self.single_product_processing(
                l_InitMode, l_BackwardMode, l_finalize_backward,
                l_InputL1ProductInfo, l1_image_reader,
                l_write_earthexplorer_headers, l_write_temporary_l2_product,
                l_write_l2_product_to_l2resolution, None, l2_image_file_writer,
                l_GIPPL2COMMHandler)
            LOGGER.debug("  ->  self._productIsValid                     = " +
                         str(self._productIsValid))
            LOGGER.debug("  ->  p_checking_conditional_clouds        = " +
                         str(self._checking_conditional_clouds))
            if (self._checking_conditional_clouds is
                    True) and (self._productIsValid is True):
                l_conditional_loop = True
            elif l_IndexOfL1Product == 1:
                l_conditional_loop = True
            else:
                l_conditional_loop = False

            # Store the output file name for the following loop
            # ----------------------------------------------------------------
            l_InputL2ImageFilename = l2_image_file_writer.get_global_product_filename(
            )

            # Decrement the input L1 index product
            l_IndexOfL1Product = l_IndexOfL1Product - 1

            # Log system infos
            LOGGER.info(self._apphandler.get_system_infos())

        # Check the Init mode
        # ----------------------------------------------------------------

        # LAIG-DM-MAC-143599-CS
        # LAIG-FA-MAC-1658-CNES
        if (self._checking_conditional_clouds
                == False) or (self._productIsValid == False):
            LOGGER.warn(
                "The INIT mode in Backward processing fail: all L1 products are not valid (too cloudy or too cirrus)"
                " or the output L2 product generated contains too NoData values! "
                "See previous [W] messages for more details.")

        # *************************************************************************************************************
        # *************************************************************************************************************
        # Process the Nominal mode
        # *************************************************************************************************************
        # *************************************************************************************************************
        if l_IndexOfL1Product > 0:
            l_InitMode = False
            l_write_earthexplorer_headers = False
            l_write_l2_product_to_l2resolution = False
            l_write_temporary_l2_product = True

            while l_IndexOfL1Product > 1:
                l_InputL1ProductInfo = self._listofl1product[l_IndexOfL1Product
                                                             - 1]
                l_Sat = l_InputL1ProductInfo.Satellite

                # *************************************************************************************************************
                # Init the current PluginBase pointer for the satellite in the MAIN global DataApplicationHandler Instance
                # *************************************************************************************************************
                plugin = MAJAPluginProvider.create(
                    l_InputL1ProductInfo.PluginName, self._apphandler)
                """ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **  **
                        Get and registers the L2COMM GIPP file  L2COMM
                        parameters have been read in the L1ImaegFileReader !!
                         ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *"""
                l_GIP_L2COMM_Filename = gipp_utils.get_gipp_filename_with_mission(
                    self._apphandler.get_input_directory(), "GIP_L2COMM",
                    l_Sat)
                if self._apphandler._stylesheet is not None:
                    LOGGER.debug("Overloading L2COMM parameters...")
                    translate_xsl(l_GIP_L2COMM_Filename,
                                  self._apphandler._stylesheet)

                LOGGER.info(
                    "The GIP_L2COMM file detected for the satellite '" +
                    l_Sat + "' is <" + l_GIP_L2COMM_Filename + ">.")
                l_GIPPL2COMMHandler = GippL2COMMEarthExplorerXMLFileHandler(
                    l_GIP_L2COMM_Filename)
                """ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **  **
                Register the GIPP file "GIP_L2SITE" */
                 ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *"""
                l_GIP_L2SITE_Filename = gipp_utils.get_gipp_filename_with_mission(
                    self._apphandler.get_input_directory(), "GIP_L2SITE",
                    l_InputL1ProductInfo.UniqueSatellite)
                if self._apphandler._stylesheet is not None:
                    LOGGER.debug("Overloading L2COMM parameters...")
                    translate_xsl(l_GIP_L2SITE_Filename,
                                  self._apphandler._stylesheet)

                LOGGER.info(
                    "The GIP_L2SITE file detected for the satellite '" +
                    l_InputL1ProductInfo.UniqueSatellite + "' is <" +
                    l_GIP_L2SITE_Filename + ">.")

                # *************************************************************************************************************
                # Initialize the L1 Image file reader
                # *************************************************************************************************************
                l_UniqueSatelliteD = l_InputL1ProductInfo.UniqueSatellite
                l1_image_reader = L1ImageReaderProvider.create(
                    l_InputL1ProductInfo.PluginName, l_InputL1ProductInfo,
                    self._apphandler, l_GIPPL2COMMHandler,
                    self.DataDEMMap.get(l_UniqueSatelliteD),
                    constants.ReadL1Mode.READ_L1_MODE_FOR_ALGORITHMS)

                # *************************************************************************************************************
                # Initialize the L2 Image file reader
                # *************************************************************************************************************
                LOGGER.debug(
                    "Starting L2NominalProcessor::ScientificProcessing(): get the L2 product filename in the input directory..."
                )
                l2_image_reader = L2ImageReaderProvider.create(
                    l_InputL2ImageFilename, self._apphandler, False,
                    self.DataDEMMap.get(l_UniqueSatelliteD))
                LOGGER.info("The L2 product found is <" +
                            l2_image_reader.ProductFilename + ">.")

                # *************************************************************************************************************
                # Initialize the L2 Image file writer
                # *************************************************************************************************************
                if self._apphandler.get_output_plugin() is not None:
                    l2_image_file_writer = L2ImageWriterProvider.create(
                        self._apphandler.get_output_plugin())
                else:
                    l2_image_file_writer = L2ImageWriterProvider.create(
                        MAJAPluginProvider.auto_tm(
                            l_InputL1ProductInfo.PluginName))
                if not l2_image_file_writer.can_write(
                        l_InputL1ProductInfo.PluginName):
                    raise MajaDriverException(
                        "Plugin '" + self._apphandler.get_output_plugin() +
                        "' can not write product from '" +
                        l_InputL1ProductInfo.PluginName + "' products ")
                # Log system infos
                LOGGER.info(self._apphandler.get_system_infos())
                # Compute the L2 temporary product
                # ----------------------------------------------------------------
                self.single_product_processing(
                    l_InitMode, l_BackwardMode, l_finalize_backward,
                    l_InputL1ProductInfo, l1_image_reader,
                    l_write_earthexplorer_headers,
                    l_write_temporary_l2_product,
                    l_write_l2_product_to_l2resolution, l2_image_reader,
                    l2_image_file_writer, l_GIPPL2COMMHandler)

                # Store the output file name for the following loop
                # ----------------------------------------------------------------
                l_InputL2ImageFilename = l2_image_file_writer.get_global_product_filename(
                )

                # Decrement Index of L1 image input
                # ----------------------------------------------------------------
                l_IndexOfL1Product = l_IndexOfL1Product - 1

                # Log system infos
                LOGGER.info(self._apphandler.get_system_infos())

            # Finalize the product
            # Compute the last L2 product
            # ----------------------------------------------------------------
            l_write_earthexplorer_headers = True
            l_write_l2_product_to_l2resolution = self._apphandler.get_user_conf(
            ).get_Computing().get_EnableL2ResolutionProcessing()
            l_write_temporary_l2_product = False
            l_finalize_backward = True
            l_InputL1ProductInfo = self._listofl1product[l_IndexOfL1Product -
                                                         1]
            l_Sat = l_InputL1ProductInfo.Satellite
            # *************************************************************************************************************
            # Init the current PluginBase pointer for the satellite in the MAIN global DataApplicationHandler Instance
            # *************************************************************************************************************
            plugin = MAJAPluginProvider.create(l_InputL1ProductInfo.PluginName,
                                               self._apphandler)
            """ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **  **
                    Get and registers the L2COMM GIPP file  L2COMM
                    parameters have been read in the L1ImaegFileReader !!
                     ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *"""
            l_GIP_L2COMM_Filename = gipp_utils.get_gipp_filename_with_mission(
                self._apphandler.get_input_directory(), "GIP_L2COMM", l_Sat)
            if self._apphandler._stylesheet is not None:
                LOGGER.debug("Overloading L2COMM parameters...")
                translate_xsl(l_GIP_L2COMM_Filename,
                              self._apphandler._stylesheet)
            LOGGER.info("The GIP_L2COMM file detected for the satellite '" +
                        l_Sat + "' is <" + l_GIP_L2COMM_Filename + ">.")
            l_GIPPL2COMMHandler = GippL2COMMEarthExplorerXMLFileHandler(
                l_GIP_L2COMM_Filename)
            """ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **  **
            Register the GIPP file "GIP_L2SITE" */
             ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *"""
            l_GIP_L2SITE_Filename = gipp_utils.get_gipp_filename_with_mission(
                self._apphandler.get_input_directory(), "GIP_L2SITE",
                l_InputL1ProductInfo.UniqueSatellite)
            if self._apphandler._stylesheet is not None:
                LOGGER.debug("Overloading L2COMM parameters...")
                translate_xsl(l_GIP_L2SITE_Filename,
                              self._apphandler._stylesheet)
            LOGGER.info("The GIP_L2SITE file detected for the satellite '" +
                        l_InputL1ProductInfo.UniqueSatellite + "' is <" +
                        l_GIP_L2SITE_Filename + ">.")

            # *************************************************************************************************************
            # Initialize the L1 Image file reader
            # *************************************************************************************************************
            l_UniqueSatelliteD = l_InputL1ProductInfo.UniqueSatellite
            l1_image_reader = L1ImageReaderProvider.create(
                l_InputL1ProductInfo.PluginName, l_InputL1ProductInfo,
                self._apphandler, l_GIPPL2COMMHandler,
                self.DataDEMMap.get(l_UniqueSatelliteD),
                constants.ReadL1Mode.READ_L1_MODE_FOR_ALGORITHMS)

            # *************************************************************************************************************
            # Initialize the L2 Image file reader
            # *************************************************************************************************************
            LOGGER.debug(
                "Starting L2NominalProcessor::ScientificProcessing(): get the L2 product filename in the input directory..."
            )
            l2_image_reader = L2ImageReaderProvider.create(
                l_InputL2ImageFilename, self._apphandler, False,
                self.DataDEMMap.get(l_UniqueSatelliteD))
            LOGGER.info("The L2 product found is <" +
                        l2_image_reader.ProductFilename + ">.")

            # *************************************************************************************************************
            # Initialize the L2 Image file writer
            # *************************************************************************************************************
            if self._apphandler.get_output_plugin() is not None:
                l2_image_file_writer = L2ImageWriterProvider.create(
                    self._apphandler.get_output_plugin())
            else:
                l2_image_file_writer = L2ImageWriterProvider.create(
                    MAJAPluginProvider.auto_tm(
                        l_InputL1ProductInfo.PluginName))
            if not l2_image_file_writer.can_write(
                    l_InputL1ProductInfo.PluginName):
                raise MajaDriverException(
                    "Plugin '" + self._apphandler.get_output_plugin() +
                    "' can not write product from '" +
                    l_InputL1ProductInfo.PluginName + "' products ")

            # Log system infos
            LOGGER.info(self._apphandler.get_system_infos())
            self.single_product_processing(
                l_InitMode, l_BackwardMode, l_finalize_backward,
                l_InputL1ProductInfo, l1_image_reader,
                l_write_earthexplorer_headers, l_write_temporary_l2_product,
                l_write_l2_product_to_l2resolution, l2_image_reader,
                l2_image_file_writer, l_GIPPL2COMMHandler)

        # end if it is not the last product

        else:
            LOGGER.debug(
                "L1ImageInformationProvider initialized during backward but no associated valid L2 product. No more products."
            )

        LOGGER.info("L2BackwardProcessor::ScientificProcessing() done.")
        # Log system infos
        LOGGER.info(self._apphandler.get_system_infos())