示例#1
0
    def is_an_earth_explorer_l2_product_by_checking_the_filename(
            p_filename, plugin_base):
        """
        IsAnEarthExplorerL2ProductByCheckingTheFilename
        :return:
        """
        # Get the filename without the path
        # l_ShortFilename: ex: VE_TEST_VSC_L2VALD_CAMARGUE_20120101.DBL or VE_TEST_VSC_L2VALD_CAMARGUE_20120101.HDR
        l_ShortFilename = os.path.basename(p_filename)
        l_Extension = os.path.splitext(l_ShortFilename)[-1]

        # Look for the L2 product in the list of files with the keys "L2VALD" and ".HDR"
        # --------------------------------------------------------------------------------
        # FT OGM 1245 - FA 132484 : QCK_L2VALD is not a L2 EarthExplorer product
        # => Remove the QCK product from the list of L2 products
        if (re.search("_L2VALD_", l_ShortFilename) is not None
                and l_Extension == ".HDR"
                and re.search("_QCK_", l_ShortFilename) is None):
            # Initialize the filenames of the different plans contained in a L2 product
            l_FilenameProvider = L2ImageFilenamesProvider()
            result = l_FilenameProvider.can_initialize_for_reading(
                p_filename, plugin_base, False)

            if not result:
                LOGGER.debug(
                    "The product %s is not a L2 EarthExplorer product"
                    "(exception error throw while initializing the L2ImageFilenamesProvider) !",
                    p_filename)
                return False
            else:
                return True
示例#2
0
    def read_info_with_plugin_base(self, p_filename, p_EnableReadingPublicData,
                                   p_PluginBase):
        # ****  PRELIMINARY  DATA      ************************************************************
        l_L2ImagesFilenamesProvider = L2ImageFilenamesProvider()
        l_L2ImagesFilenamesProvider.initialize_for_reading(
            p_filename, p_PluginBase, False)
        # Set the ImageFilenamesProvider
        l_L2Handler = HeaderImageEarthExplorerXMLFileHandler(
            l_L2ImagesFilenamesProvider.get_hdr_filename())

        # Set attribute
        self.ProductFilename = p_filename
        self.GlobalProductFilename = l_L2ImagesFilenamesProvider.get_hdr_filename(
        )
        self.Satellite = l_L2Handler.get_string_value_of("Mission")
        self.Acquisition_Date = l_L2Handler.get_acquisition_date()
        self.Validity_Start = l_L2Handler.get_string_value_of("ValidityStart")
        self.Validity_Stop = l_L2Handler.get_string_value_of("ValidityStop")
        self.Nick_Name = l_L2Handler.get_nick_name()
        self.Reference_SiteDefinition_Id = l_L2Handler.get_reference_site_definition_id(
        )
        self.Date = date_utils.get_datetime_from_yyyymmdd(
            l_L2Handler.get_acquisition_date())
        self.Adjacency_Effects_And_Slope_Correction = l_L2Handler.get_adjacency_effects_and_slope_correction(
        )
        self.Reflectance_Quantification_Value = l_L2Handler.get_reflectance_quantification_value(
        )
        self.Nodata_Value = l_L2Handler.get_no_data_value_as_double()
        self.RealL2Nodata_Value = l_L2Handler.get_no_data_value_as_double(
        ) * l_L2Handler.get_reflectance_quantification_value()

        self.List_of_GIPP_Files = l_L2Handler.get_list_of_gipp_files()

        if p_EnableReadingPublicData:
            l_ATB_XMLHandler = HeaderImageEarthExplorerXMLFileHandler(
                l_L2ImagesFilenamesProvider.get_atb_header_filenames().at(0))
            self.VAP_Nodata_Value = l_ATB_XMLHandler.get_vap_no_data_value()
            self.RealVAP_Nodata_Value = l_ATB_XMLHandler.get_vap_no_data_value(
            ) * l_ATB_XMLHandler.get_vap_quantification_value()
            self.VAP_Quantification_Value = l_ATB_XMLHandler.get_vap_quantification_value(
            )
            self.AOT_Nodata_Value = l_ATB_XMLHandler.get_aot_no_data_value()
            self.RealAOT_Nodata_Value = l_ATB_XMLHandler.get_aot_no_data_value(
            ) * l_ATB_XMLHandler.get_aot_quantification_value()
            self.AOT_Quantification_Value = l_ATB_XMLHandler.get_aot_quantification_value(
            )

        self.PluginName = p_PluginBase.PluginName

        self.FileClass = l_L2ImagesFilenamesProvider.get_fileclass()
        self.LevelType = "L2VALD"

        # -------------------------------------------------------------------------
        # Get the projection ref
        # TODO cf avec alexia
        # self.ProjectionRef = l_L2ImagesFilenamesProvider->GetPrivateFileNames().GetRTAImageFileName())

        # Expand the path
        self.Prefix = EarthExplorerUtilities.get_satellite_class_from_filename(
            self.GlobalProductFilename)
示例#3
0
    def read_with_plugin_base(self, p_filename, p_EnableReadingPublicData,
                              app_handler, p_PluginBase):
        """

        :param p_filename:
        :param p_EnableReadingPublicData: bool
        :param p_PluginBase: PluginBase::Pointer
        :return:
        """
        working_dir = app_handler.get_directory_manager(
        ).get_temporary_directory("L2Read_", do_always_remove=True)

        # Set the ImageFilenamesProvider
        l_L2ImagesFilenamesProvider = L2ImageFilenamesProvider()
        l_L2ImagesFilenamesProvider.initialize_for_reading(
            p_filename, p_PluginBase, False)
        self.L2PrivateImageFilenamesProvider = l_L2ImagesFilenamesProvider.get_private_filenames(
        )

        # Do caching ?
        caching = app_handler.get_user_conf().get_Computing().get_Caching(
        ).get_EnableCachingConvertReflectanceData()

        # Register the Header for the L2 Input image file
        l_L2Handler = HeaderImageEarthExplorerXMLFileHandler(
            l_L2ImagesFilenamesProvider.get_hdr_filename())
        l_ReflectanceQuantificationValue = l_L2Handler.get_reflectance_quantification_value(
        )

        # Get the number of Resolution, by reading the number of SRE filename
        l_NumberOfResolutions = len(
            l_L2ImagesFilenamesProvider.get_fre_headers())
        LOGGER.debug(
            "L2ImageFileReaderBase::Initialize Number of resolutions: %s.",
            l_NumberOfResolutions)

        self._m_WriteFRE = l_L2Handler.get_adjacency_effects_and_slope_correction(
        )

        # ****  PUBLIC  DATA      *************************************************************************************
        LOGGER.debug(
            "L2ImageFileReaderBase::Initialize - EnableReadingPublicData: %s.",
            p_EnableReadingPublicData)

        if p_EnableReadingPublicData:
            self.read_public_images(l_L2ImagesFilenamesProvider,
                                    l_ReflectanceQuantificationValue,
                                    p_PluginBase, working_dir)
        else:
            # ****  PRIVATE  DATA     ************************************************
            self.read_private_images(
                l_L2ImagesFilenamesProvider.get_private_filenames(),
                l_ReflectanceQuantificationValue, p_PluginBase, working_dir)
    def preprocessing(self):
        # *********************************************************************************************************
        # Store the Global filename of the product. Here, it's a EarthExplorer L2 product organization
        self.l2imagefilenamesprovider = L2ImageFilenamesProvider()

        self.l2imagefilenamesprovider.initialize(self.l1imageinformationsproviderbase, self.plugin.ListOfL2Resolutions,
                                                 self.outputdirectory, False)  # Check existence
        # LOGGER.debug("EarthExplorerL2ImageFileWriter::GenerateData(): l_L2ImageFilenamesProvider pointer "
        # + self.l2imagefilenamesprovider)

        if self.plugin is None:
            raise MajaException("Internal error: the variable m_PluginBasePointer is NULL!")

        if self.l1imageinformationsproviderbase is None:
            raise MajaException("Internal error: the variable m_L1ImageInformationsProviderBase is NULL!")

        if not self.initmode:
            if self.inputl2imagefilereader is None:
                raise MajaException("Internal error: the variable m_InputL2ImageFileReader is NULL!")

        file_utils.create_directory(self.l2imagefilenamesprovider.get_public_directory())
        file_utils.create_directory(self.l2imagefilenamesprovider.get_private_filenames().get_private_directory())
        # ---------------------------------------------------------------------------------------------------
        # Write LTC Private Header
        # Note necessary for Backward mode
        # MACCS 4.7.2 - correction pour FA 1572
        if self.writeltc and self.writel2products and self.backwardmode:
            # ---------------------------------------------------------------------------------------------
            # Create the LTC directory if don't exist
            file_utils.create_directory(
                self.l2imagefilenamesprovider.get_private_filenames().get_ltc_image_dir_filename())
        # else:
        #    System::RemoveDirectory(m_L2ImageFilenamesProvider->GetPrivateFileNames().GetLTCImageDirFileName())
        #    itksys::SystemTools::RemoveFile(m_L2ImageFilenamesProvider->GetPrivateFileNames().GetLTCHeaderFileName().
        #    c_str())

        # ---------------------------------------------------------------------------------------------
        # Create the .DBL file (zero)
        file_utils.touch_file(self.l2imagefilenamesprovider.get_dbl_filename())

        # ---------------------------------------------------------------------------------------------
        # Call the PreProcessing Supperclass
        super(EarthExplorerL2HeaderFileWriter, self).pre_processing()
    def write(self, working_dir):
        LOGGER.info("EarthExplorerL2ImageFileWriter:Write()")

        # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
        # Store the Global filename of the product.Here, it 's a EarthExplorer L2 product organization
        l_L2ImageFilenamesProvider = L2ImageFilenamesProvider()
        l_L2ImageFilenamesProvider.initialize(
            self._l1_image_info,
            self._plugin.ListOfL2Resolutions,
            self._l2_output_directory,
            False)
        # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
        # Create the Outputs directories
        # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
        file_utils.create_directory(l_L2ImageFilenamesProvider.get_public_directory())
        file_utils.create_directory(l_L2ImageFilenamesProvider.get_private_filenames().get_private_directory())
        # ---------------------------------------------------------------------------------------------
        # If multi temporal
        LOGGER.debug(
            "EarthExplorerL2ImageFileWriter:: m_WriteLTC                       : " + str(self._dealingltc))
        LOGGER.debug("l_L2ImageFilenamesProvider.get_private_file_names().GetDealingLTC() : " +
                     str(l_L2ImageFilenamesProvider.get_private_filenames().get_dealing_ltc()))
        if self._dealingltc:
            file_utils.create_directory(
                l_L2ImageFilenamesProvider.get_private_filenames().get_ltc_image_dir_filename())

        LOGGER.debug("l_L2ImageFilenamesProvider.get_private_file_names().GetLTCImageDirFileName() : " +
                     l_L2ImageFilenamesProvider.get_private_filenames().get_ltc_image_dir_filename())

        # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
        self.initialize(l_L2ImageFilenamesProvider.get_private_filenames())

        # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
        # Store filename
        self._global_product_filename = l_L2ImageFilenamesProvider.get_hdr_filename()
        self._production_report_filename = l_L2ImageFilenamesProvider.get_pmc_filename()
        # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
        # Store the Privates filename
        self._l2privateimagefilenamesprovider = l_L2ImageFilenamesProvider.get_private_filenames()

        # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
        # Write product only if enable
        if self._write_l2_products:
            # ex:  - self.m_ReflectanceQuantificationValue: 0.001
            # - self.m_AOTQuantificationValue: 0.05
            # - self.m_VAPQuantificationValue: 0.005
            l_ReflectanceQuantificationValue = 1. / self._reflectancequantification
            l_AOTQuantificationValue = 1. / self._aotquantificationvalue
            l_VAPQuantificationValue = 1. / self._vapquantificationvalue

            # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *
            # Write Private images
            # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *
            self.write_private_images(
                l_L2ImageFilenamesProvider.get_private_filenames(),
                l_ReflectanceQuantificationValue,
                self._plugin.CLDDataBandsSelected,
                self._plugin.CLDCoreAlgorithmsMapBand,
                self._writeonlyclacld,
                self._dealingltc,
                working_dir)

            # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *
            # Write Public images
            # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *
            self.write_public_images(
                l_L2ImageFilenamesProvider,
                l_ReflectanceQuantificationValue,
                l_AOTQuantificationValue,
                self._aotnodatavalue,
                l_VAPQuantificationValue,
                self._vapnodatavalue,
                self._plugin.CLDDataBandsSelected,
                self._plugin.CLDCoreAlgorithmsMapBand,
                self._writepublicproduct,
                self._envcoroption,
                working_dir)

            # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *
            # Write Quicklook QLK
            # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *
            if self._writepublicproduct:
                self.write_quicklook_image_from_files(
                    l_L2ImageFilenamesProvider.get_qlk_filename(),
                    self._writepublicproduct,
                    self._qckl_red_image,
                    self._qckl_green_image,
                    self._qckl_blue_image,
                    self._quicklookminreflredband,
                    self._quicklookmaxreflredband,
                    self._quicklookminreflgreenband,
                    self._quicklookmaxreflgreenband,
                    self._quicklookminreflblueband,
                    self._quicklookmaxreflblueband,
                    self._real_l2_no_data,
                    self._dtm.ALC,
                    working_dir)