コード例 #1
0
    def detect_l1_products(self, input_directory, product_list, tile_id=None):
        LOGGER.info("Start Sentinel2 L1 DetectL1Products in " + input_directory)

        """ LAIG - FA - MAC - 1482 - CNES
         Example of the header filename of the S2 L1C product PSD < 14
         -> S2A_OPER_PRD_MSIL1C_PDMC_20150507T132817_R065_V20091211T165913_20091211T165959.SAFE / S2A_OPER_MTD_SAFL1C_PDMC_20150507T132817_R065_V20091211T165913_20091211T165959.xml
         Example of the header filename of the S2 L1C product PSD >= 14
          -> L1C_T36JTT_A006424_20160914T081456 / MTD_TL.xml
        Get the list of subdirectories of the input product"""

        listOfSubDirectories = maja_get_subdirectories(input_directory)

        # For each directory
        for dir in listOfSubDirectories:
            # Get this name: S2A_OPER_PRD_MSIL1C_PDMC_20150507T132817_R065_V20091211T165913_20091211T165959.SAFE
            l_ShortDirectoryFilename = os.path.basename(dir)
            LOGGER.info("Short dirfilename : " + l_ShortDirectoryFilename)
            # PSD < 14: Detect S2A or S2B, MSIL1C and the extension SAFE
            # PSD >= 14: Detect L1C_T
            if "_MSIL1C_" in l_ShortDirectoryFilename and (
                    "S2A_" in l_ShortDirectoryFilename or "S2B_"in l_ShortDirectoryFilename) and ".SAFE" in l_ShortDirectoryFilename:
                # Get the list of files in the current subdirectory
                listOfFilenames = [
                    os.path.join(
                        dir,
                        f) for f in os.listdir(dir) if os.path.isfile(
                        os.path.join(
                            dir,
                            f))]
                for fi in listOfFilenames:
                    l_ShortFilename = os.path.basename(fi)
                    LOGGER.info("Short filename : " + l_ShortFilename)
                    # Detect the file type of the xml header file only for user product SAFE formatted
                    # PSD < 14: _MTD_SAFL1C_ -- > Not supported
                    # PSD >= 14: MTD_TL
                    if (("MTD_MSIL1C" in l_ShortFilename) or ("_MTD_SAFL1C" in l_ShortFilename)) \
                            and os.path.splitext(l_ShortFilename)[1] == ".xml":
                        # Load the xml header file and get the satellite
                        l_CanLoad = xml_tools.can_load_file(fi)
                        if l_CanLoad:
                            try:
                                s2xml = MajaSentinel2L1MainXmlReader(fi,tile_id=tile_id)
                                if s2xml.satellite_name == "Sentinel-2A" or s2xml.satellite_name == "Sentinel-2B":
                                    product_list.append(fi)
                                    LOGGER.info("Append  " + fi)
                            except Exception as e:
                                LOGGER.debug("Not compatible with SENTINEL2")
                                LOGGER.debug(e)
コード例 #2
0
    def write_private_ltc_xmlhandler(self,
                                     p_InputL2ImageFileReader,
                                     p_ReferenceProductHeaderId,
                                     p_ReferenceProductInstance,
                                     root_sc_xml_templates,
                                     p_OutputL2PrivateImageFilenamesProvider,
                                     schemaLocationDirectory,
                                     pCurrentDate,
                                     pValidity_Start,
                                     pValidity_Stop,
                                     p_MeanSolarAngles,
                                     p_MeanViewingAngles,
                                     p_EnableCheckXMLFilesWithSchema=True):
        output_filename = p_OutputL2PrivateImageFilenamesProvider.get_ltc_header_filename(
        )
        l_FileDefinition = self.plugin.ShortFileType + "_LUTANX"
        # ---------------------------------------
        # Get global information about the output L2 product
        # ---------------------------------------
        LOGGER.debug("Write the PRIVATE LTC header file ...")
        lReferenceProductHeaderId = p_ReferenceProductHeaderId
        lReferenceProductInstance = p_ReferenceProductInstance
        lFile_Version = self.plugin.L2PRODUCT_FILE_VERSION
        # Get Validity
        lValidity_Start = pValidity_Start
        lValidity_Stop = pValidity_Stop

        current_header_filename = root_sc_xml_templates
        if not os.path.exists(current_header_filename):
            raise MajaExceptionPluginBase(
                "Internal error: the template file '" +
                current_header_filename + "' doesn't exist !!")

        # Load the file
        output_handler = EarthExplorerXMLFileHandler(current_header_filename)
        # ---------------------------------------------------------------------------------------------
        # Update bascis parameters
        output_handler.update(pValidity_Start, pValidity_Stop, lFile_Version,
                              output_filename, self.creator,
                              self.plugin.Creator_Version, self.notes,
                              self.system, self.outputfileclass, pCurrentDate,
                              lReferenceProductHeaderId)
        # ---------------------------------------
        # Detect the good GIPP TOCR filename to read data
        # ---------------------------------------
        lNbGippFilenames = len(self.listofgippsfilenames)
        l_found = False
        l_GIPTOCRFilename = ""
        # For each GIPP filename of the list
        for i in range(lNbGippFilenames):
            # Look for the header file of the GIP_L2TOCR
            l_FileName = self.listofgippsfilenames[i]
            l_FileName = os.path.splitext(l_FileName)[0] + ".HDR"
            # ---------------------------------------------------------------------------------------------------
            # Load the file
            l_CanLoad = xml_tools.can_load_file(l_FileName)
            if l_CanLoad:
                # Read the header file of the GIP_L2TOCR
                lHolder = EarthExplorerXMLFileHandler(l_FileName)
                l_Satellite = lHolder.get_string_value("//Mission")
                l_File_Type = lHolder.get_string_value("//File_Type")
                # Check the validity of the found GIPP : camera and type
                if l_Satellite in self.l1imageinformationsproviderbase.Satellite and "GIP_L2TOCR" in l_File_Type:
                    l_GIPTOCRFilename = l_FileName
                    l_found = True

        # The GIP_L2TOCR does not exist
        if not l_found:
            raise MajaExceptionPluginBase(
                "Impossible to detect the TOCR GIPP filename for the current satellite <"
                + self.l1imageinformationsproviderbase.Satellite + "> !")

        # ****************************************************************************************
        # Write LUT_Indexes information
        lTOCRHolder = EarthExplorerXMLFileHandler(l_GIPTOCRFilename)
        # ---------------------------------------------------------------------------------------------------
        # Get the information of the input LUT to copy them in the LTC header file
        output_handler.set_string_value(
            "//LUT_Indexes/Altitude_Indexes",
            lTOCRHolder.get_string_value("//LUT_Indexes/Altitude_Indexes"))
        output_handler.set_string_value(
            "//LUT_Indexes/AOT_Indexes",
            lTOCRHolder.get_string_value("//LUT_Indexes/AOT_Indexes"))
        output_handler.set_string_value(
            "//LUT_Indexes/TOA_Reflectance_Indexes",
            lTOCRHolder.get_string_value(
                "//LUT_Indexes/TOA_Reflectance_Indexes"))
        output_handler.set_string_value(
            "//Mission", self.l1imageinformationsproviderbase.Satellite)
        output_handler.set_string_value("//Reference_Product_Instance",
                                        lReferenceProductInstance)
        l_attr = dict()
        l_attr["unit"] = "nanometer"
        xml_tools.set_string_list_value_sorted_by_attribute(
            output_handler.root,
            self.listofbandtheoreticalwavelengthforltccomposite,
            "//List_of_Band_Theoretical_Wavelength",
            "Band_Theoretical_Wavelength", "count", "sn", 1, l_attr)

        #                    output_handler.save_to_fileAndCheck(output_filename, lSchemaLocationDirectory)
        # ---------------------------------------
        # Check the product validity of the output L2 product
        # ---------------------------------------
        if self.productisvalid:
            output_handler.set_string_value("//Reference_Product_Semantic",
                                            "L2VALD")
        else:
            output_handler.set_string_value("//Reference_Product_Semantic",
                                            "L2NOTV")
        # Initialization used to write the binary data of the LTC file
        listOfLTC = []
        listOfpft = []
        LOGGER.debug(
            "p_OutputL2PrivateImageFilenamesProvider.GetLTCHeaderFileName(): "
            +
            p_OutputL2PrivateImageFilenamesProvider.get_ltc_header_filename())

        # 4.3         l_DestinationDir = Utilities::SetExtension(output_filename, ".DBL.DIR")
        l_DestinationDir = p_OutputL2PrivateImageFilenamesProvider.get_ltc_image_dir_filename(
        )
        LOGGER.debug("l_DestinationDir: " + l_DestinationDir)
        l_DestinationRelativeDir = os.path.basename(l_DestinationDir)
        LOGGER.debug("l_DestinationRelativeDir: " + l_DestinationRelativeDir)
        # ****************************************************************************************
        # Reading Angles Solar and Viewing from LTC of L2 previous product
        if not self.initmode:
            if p_InputL2ImageFileReader is None:
                raise MajaExceptionPluginBase(
                    "Internal error: the variable m_InputL2ImageFileReader is NULL!"
                )
            # p_L2PrivateImageFilenamesProvider.GetLTCHeaderFileName()
            # #m_L2InputImageFilenamesProvider->GetPrivateFileNames().GetLTCHeaderFileName()
            L2_LTCHeaderFilename = p_InputL2ImageFileReader.L2PrivateImageFilenamesProvider.get_ltc_header_filename(
            )
            LOGGER.debug(
                "Nominal mode: open the L2 input LTC HeaderFileName: " +
                L2_LTCHeaderFilename)
            lHolder = EarthExplorerXMLFileHandler(L2_LTCHeaderFilename)
            lHolder.get_l2_product_ltc_information(l_DestinationRelativeDir,
                                                   listOfLTC, listOfpft)
            # Copy all files from the L2 Input directory to the output L2 product
            file_utils.copy_tree(
                p_InputL2ImageFileReader.L2PrivateImageFilenamesProvider.
                get_ltc_image_dir_filename(), l_DestinationDir)
        # ****************************************************************************************
        # Reading Solar and Viewing angles from L1 product
        # Push in the list
        LOGGER.debug("m_IgnoreCurrentLTC: " + str(self.ignorecurrentltc))
        if not self.ignorecurrentltc:
            ltc = EarthExplorerXMLFileHandler.LTCType()
            solarAngles = p_MeanSolarAngles
            #[p_MeanSolarAngles['sun_zenith_angle'], p_MeanSolarAngles['sun_azimuth_angle']]
            LOGGER.debug(solarAngles)
            LOGGER.debug(
                EarthExplorerXMLFileHandler.EE_SCHEMA_DECIMAL_9_FORMAT)
            ltc.solarangle.azimuth = maja_utils.format_to_string(
                float(solarAngles[1]),
                EarthExplorerXMLFileHandler.EE_SCHEMA_DECIMAL_9_FORMAT)
            ltc.solarangle.zenith = maja_utils.format_to_string(
                float(solarAngles[0]),
                EarthExplorerXMLFileHandler.EE_SCHEMA_DECIMAL_9_FORMAT)
            viewingAngles = p_MeanViewingAngles
            ltc.viewingangle.azimuth = maja_utils.format_to_string(
                viewingAngles[1],
                EarthExplorerXMLFileHandler.EE_SCHEMA_DECIMAL_9_FORMAT)
            ltc.viewingangle.zenith = maja_utils.format_to_string(
                viewingAngles[0],
                EarthExplorerXMLFileHandler.EE_SCHEMA_DECIMAL_9_FORMAT)
            ltc.Date = lValidity_Start
            # Add the current LTC header
            pft = EarthExplorerXMLFileHandler.PackagedDBLFileType()
            pft.relativefilepath = os.path.join(
                l_DestinationRelativeDir,
                os.path.basename(p_OutputL2PrivateImageFilenamesProvider.
                                 get_ltc_image_filename()))
            pft.filedefinition = l_FileDefinition
            listOfpft.append(pft)
            listOfLTC.append(ltc)
        # Write to the output handler
        output_handler.write_private_ltc_header(listOfLTC)
        output_handler.write_private_ltc_header_list_of_dbl(listOfpft)
        # ****************************************************************************************
        # Save the file
        output_handler.save_to_file(output_filename)
        if self.checkxmlfileswithschema and self.productisvalid and p_EnableCheckXMLFilesWithSchema:
            xml_tools.check_xml(output_filename, schemaLocationDirectory)
        # ****************************************************************************************
        # Post processing : to be sur that there are only mha listed in the listOfpft present in the directory, remove others files
        # LAIG-FA-MAC-1630-CNES
        # ---------------------------------------------------------------------------------------
        # Get the Listed filename
        l_LTCProductMHAFilename = list()
        for itList in listOfpft:
            # Get file but onlyt the mha (without l_DestinationRelativeDir)
            # Ex :
            # <Relative_File_Path>VE_TEST_VSC_LUTANX_L2VALD_CAMARGUE_20120101_LTC.DBL.DIR/VE_TEST_VSC_LUTANX_L2VALD_CAMARGUE_20120103_LTC.DBL.mha</Relative_File_Path>
            l_LTCProductMHAFilename.append(
                os.path.basename(itList.relativefilepath))
        # ---------------------------------------------------------------------------------------
        # Get the Listed filename in the directory
        l_LTCProductMHAFilenameInDisc = [
            os.path.basename(f) for f in os.listdir(l_DestinationDir)
            if os.path.isfile(os.path.join(l_DestinationDir, f))
        ]

        # Remove the files on disc that are not listed as used
        for f in l_LTCProductMHAFilenameInDisc:
            if f not in l_LTCProductMHAFilename:
                file_utils.remove_file(os.path.join(l_DestinationDir, f))
コード例 #3
0
    def initialize(self,
                   reference_base_filename,
                   validate=False,
                   schema_path=None):
        LOGGER.debug("Start Venus L1 VenusL1ImageFilenamesProvider ...")
        LOGGER.debug("Analyse of the reference base filename: '" +
                     reference_base_filename + "'")

        # Set GLOBAL HDR image filename
        l_dblfilename = os.path.splitext(reference_base_filename)[0] + ".DBL"
        l_FileNameDBL_DIR = os.path.splitext(
            reference_base_filename)[0] + ".DBL.DIR"

        if not (os.path.exists(l_dblfilename)
                or os.path.exists(l_FileNameDBL_DIR)):
            raise MajaExceptionPluginBase(
                "VenusL1ImageFilenames Provider: The GLOBAL Product file .DBL "
                + l_dblfilename + "' doesn't exist !! The " +
                reference_base_filename + " product is NOT valid !")

        # Expand the path
        l_refFileName = os.path.splitext(reference_base_filename)[0] + ".HDR"
        LOGGER.debug("m_hdrfilename: '" + l_refFileName + "'")

        if not os.path.exists(l_refFileName):
            raise MajaExceptionPluginBase(
                "VenusL1ImageFilenames Provider: The GLOBAL Header file .HDR "
                + l_refFileName + " The" + reference_base_filename +
                " product is NOT valid !")
        self.m_hdrfilename = l_refFileName

        if schema_path:
            LOGGER.debug("Root shemas install directory '" + schema_path + "'")
            lSchemaLocationDirectory = schema_path + self.plugin.MAJA_INSTALL_SCHEMAS_DIR

        # Check XML file
        if validate:
            xml_tools.check_xml(self.m_hdrfilename, lSchemaLocationDirectory)

        # Load HDR file
        l_CanLoad = xml_tools.can_load_file(self.m_hdrfilename)
        if not l_CanLoad:
            return False

        # Filename naming convention:
        # VE_TEST_VSC_L1VALD_CAMARGUE_20120101.HDR
        # VE_VM01_VSC_L1VALD__PE_R_U__20120101.HDR
        # XML information
        #        <File_Class>TEST</File_Class>
        #        <File_Type>VSC_L2VALD</File_Type>
        #        <Nick_Name>CAMARGUE</Nick_Name>
        #		  <Acquisition_Date>20120103</Acquisition_Date>
        # Split FileType to extract VSC and L1VALD strings ( from "VSC_L2VALD")

        m_FileClass = EarthExplorerUtilities.get_fileclass_from_filename(
            l_refFileName)


        prefix1 = EarthExplorerUtilities.get_satellite_class_from_filename(l_refFileName) + "_" + \
                  m_FileClass + "_" + \
                  EarthExplorerUtilities.get_file_type_short_from_filename(l_refFileName) + "_"

        prefix2 = "_" + EarthExplorerUtilities.get_level_class_from_filename(l_refFileName) + "_" + \
                  EarthExplorerUtilities.get_nickname_from_global_filename(l_refFileName) + "_" + \
                  EarthExplorerUtilities.get_acquisition_from_global_filename(l_refFileName)

        # *******************************************************************************************************
        # Set TOA image filename
        # *******************************************************************************************************
        # Build the relative filename
        l_FileName = prefix1 + "PDTIMG" + prefix2 + ".DBL.TIF"
        self.m_TOAImageFileName = os.path.join(l_FileNameDBL_DIR, l_FileName)

        LOGGER.debug(self.m_TOAImageFileName)

        if not os.path.exists(self.m_TOAImageFileName):
            raise MajaExceptionPluginBase(
                "VenusL1ImageFilenames Provider: The L1 TOA filename " +
                str(self.m_TOAImageFileName) + " doesn't exist. The " +
                str(reference_base_filename) + "product is NOT valid !")
        # *******************************************************************************************************
        # Set TOA header filename
        # *******************************************************************************************************
        l_FileName = prefix1 + "PDTIMG" + prefix2 + ".HDR"
        self.m_TOAHeaderFileName = os.path.join(l_FileNameDBL_DIR, l_FileName)
        if not os.path.exists(self.m_TOAHeaderFileName):
            raise MajaExceptionPluginBase(
                "VenusL1ImageFilenames Provider: The L1 TOA filename " +
                str(self.m_TOAHeaderFileName) + " doesn't exist. The " +
                str(reference_base_filename) + "product is NOT valid !")
        # Check XML file
        if validate:
            xml_tools.check_xml(self.m_TOAHeaderFileName,
                                lSchemaLocationDirectory)

        # *******************************************************************************************************
        # Set CLA image filename
        # *******************************************************************************************************
        l_FileName = prefix1 + "PDTANX" + prefix2 + "_CLA.DBL.TIF"
        self.m_CLAImageFileName = os.path.join(l_FileNameDBL_DIR, l_FileName)
        if not os.path.exists(self.m_CLAImageFileName):
            raise MajaExceptionPluginBase(
                "VenusL1ImageFilenames Provider: The L1 CLA filename " +
                str(self.m_CLAImageFileName) + " doesn't exist. The " +
                str(reference_base_filename) + "product is NOT valid !")
        # *******************************************************************************************************
        # Set CLA header filename
        # *******************************************************************************************************
        l_FileName = prefix1 + "PDTANX" + prefix2 + "_CLA.HDR"
        self.m_CLAHeaderFileName = os.path.join(l_FileNameDBL_DIR, l_FileName)
        if not os.path.exists(self.m_CLAHeaderFileName):
            raise MajaExceptionPluginBase(
                "VenusL1ImageFilenames Provider: The L1 CLA filename " +
                str(self.m_CLAHeaderFileName) + " doesn't exist. The " +
                str(reference_base_filename) + "product is NOT valid !")
        # Check XML file
        if validate:
            xml_tools.check_xml(self.m_CLAHeaderFileName,
                                lSchemaLocationDirectory)

        # *******************************************************************************************************
        # Set SOL image filename
        # *******************************************************************************************************
        l_FileName = prefix1 + "PDTANX" + prefix2 + "_SOL.DBL.HDF"
        self.m_SOLImageFileName = os.path.join(l_FileNameDBL_DIR, l_FileName)
        if not os.path.exists(self.m_SOLImageFileName):
            raise MajaExceptionPluginBase(
                "VenusL1ImageFilenames Provider: The L1 SOL filename " +
                str(self.m_SOLImageFileName) + " doesn't exist. The " +
                str(reference_base_filename) + "product is NOT valid !")

        # *******************************************************************************************************
        # Set SOL header filename
        # *******************************************************************************************************
        l_FileName = prefix1 + "PDTANX" + prefix2 + "_SOL.HDR"
        self.m_SOLHeaderFileName = os.path.join(l_FileNameDBL_DIR, l_FileName)
        if not os.path.exists(self.m_SOLHeaderFileName):
            raise MajaExceptionPluginBase(
                "VenusL1ImageFilenames Provider: The L1 SOL filename " +
                str(self.m_SOLHeaderFileName) + " doesn't exist. The " +
                str(reference_base_filename) + "product is NOT valid !")
        # Check XML file
        if validate:
            xml_tools.check_xml(self.m_SOLHeaderFileName,
                                lSchemaLocationDirectory)

        # *******************************************************************************************************
        # Set VIE image filename
        # *******************************************************************************************************
        l_FileName = prefix1 + "PDTANX" + prefix2 + "_VIE.DBL.HDF"
        self.m_VIEImageFileName = os.path.join(l_FileNameDBL_DIR, l_FileName)
        if not os.path.exists(self.m_VIEImageFileName):
            raise MajaExceptionPluginBase(
                "VenusL1ImageFilenames Provider: The L1 VIE filename " +
                str(self.m_VIEImageFileName) + " doesn't exist. The " +
                str(reference_base_filename) + "product is NOT valid !")
        # *******************************************************************************************************
        # Set VIE header filename
        # *******************************************************************************************************
        l_FileName = prefix1 + "PDTANX" + prefix2 + "_VIE.HDR"
        self.m_VIEHeaderFileName = os.path.join(l_FileNameDBL_DIR, l_FileName)
        if not os.path.exists(self.m_VIEHeaderFileName):
            raise MajaExceptionPluginBase(
                "VenusL1ImageFilenames Provider: The L1 VIE filename " +
                str(self.m_VIEHeaderFileName) + " doesn't exist. The " +
                str(reference_base_filename) + "product is NOT valid !")
        # Check XML file
        if validate:
            xml_tools.check_xml(self.m_VIEHeaderFileName,
                                lSchemaLocationDirectory)

        return True
コード例 #4
0
    def can_initialize_for_reading(self, inputfilename, plugin, check_exists):
        # Reset all variable (list)
        self.reset()

        # Expand the path
        l_refFileName = os.path.splitext(inputfilename)[0] + ".HDR"
        self.m_HDRFileName = l_refFileName
        LOGGER.debug(
            "L23ImageFilenamesProviderBase::CanInitializeForReading: l_refFileName: '"
            + l_refFileName + "'.")

        l_CanLoad = xml_tools.can_load_file(l_refFileName)
        if not l_CanLoad:
            return False

        l_XMLHandler = HeaderImageEarthExplorerXMLFileHandler(l_refFileName)

        # Muscate products don't have always a site name over 8 characters
        site = l_XMLHandler.get_nick_name()
        acquisition_date = EarthExplorerUtilities.get_acquisition_from_global_filename(
            l_refFileName)

        m_FileClass = EarthExplorerUtilities.get_fileclass_from_filename(
            l_refFileName)
        prefix = EarthExplorerUtilities.get_satellite_class_from_filename(
            l_refFileName) + "_" + m_FileClass + "_" + \
            EarthExplorerUtilities.get_file_type_short_from_filename(l_refFileName)
        postfix = EarthExplorerUtilities.get_level_class_from_filename(l_refFileName) +\
                  "_" + site + "_" + acquisition_date

        LOGGER.debug(
            "L23ImageFilenamesProviderBase::CanInitializeForReading: prefix: '"
            + prefix + "', postfix: '" + postfix + "'.")
        # BUG Integration CHAINE chez VEGA
        self.m_ReferenceProductHeaderId = prefix + "_" + postfix

        # Set the date (build with the image file name)
        self.m_Date = get_datetime_from_yyyymmdd(acquisition_date)

        refFileNameDbl = os.path.splitext(l_refFileName)[0] + ".DBL"
        refFileNameDirDbl = os.path.splitext(l_refFileName)[0] + ".DBL.DIR"

        if os.path.exists(refFileNameDbl) == False and os.path.isdir(
                refFileNameDirDbl) == False:
            LOGGER.debug("The input L2 product file .DBL " + refFileNameDbl +
                         " doesn't exist or the directory <" +
                         refFileNameDirDbl + "> doesn't exist !")
            return False

        uncompress_dbl_product(refFileNameDbl)

        # Detect the number of resolution.
        # test if file exists
        # Case 1: S2A_TEST_SSC_PDTIMG_L2VALD_15SVD____20091211_SRE_R1.HDR
        # Case 2: S2A_TEST_SSC_PDTIMG_L2VALD_15SVD____20091211_SRE.HDR
        # If Case 1, test the numer of file S2A_TEST_SSC_PDTIMG_L2VALD_15SVD____20091211_SRE_Rx.HDR
        listOfResolutions = plugin.ListOfL2Resolutions

        # Read the list of resolution from the Header file
        self.initialize_resolutions_infos(listOfResolutions)

        self.build_filenames(refFileNameDirDbl, prefix, postfix, check_exists,
                             True)
        return True
コード例 #5
0
    def initialize(self, product_filename, validate=False, schema_path=None):
        LOGGER.info("Start Venus L1 Initialize on product " + product_filename)
        l_hdrfilename = os.path.splitext(product_filename)[0] + ".HDR"
        l_CanLoad = xml_tools.can_load_file(l_hdrfilename)
        if not l_CanLoad:
            return False

        rootNode = xml_tools.get_root_xml(l_hdrfilename, deannotate=True)
        self.Satellite = xml_tools.get_xml_string_value(rootNode, "//Mission")
        if not self._plugin.is_valid_with_satellite(self.Satellite):
            LOGGER.debug("The L1 product '" + product_filename + "' with satellite '" + self.Satellite + "' is not a VENUS product !")
        self.SatelliteID = self.Satellite.upper()
        self.PluginName = self._plugin.PluginName
        self.Prefix = "VE"
        l_File_Type = xml_tools.get_xml_string_value(rootNode, "//File_Type")
        filenamekey = l_File_Type.split("_")
        self.FileCategory = filenamekey[0]
        self.LevelType = filenamekey[1]
        self.FileClass = xml_tools.get_xml_string_value(rootNode, "//File_Class")
        self.Site = xml_tools.get_xml_string_value(rootNode, "//Instance_Id/Nick_Name")
        self.ReferenceSiteDefinitionId = xml_tools.get_xml_string_value(rootNode, "//Reference_SiteDefinition_Id")
        l_AcquisitionDateTime = xml_tools.get_xml_string_value(rootNode, "//Product_Information/Acquisition_Date_Time")
        self.ProductDate = date_utils.get_datetime_from_utc(l_AcquisitionDateTime)
        self.ProductDateStr = self.ProductDate.strftime('%Y%m%d')
        LOGGER.debug("Product Date: " + self.ProductDateStr)

        self.ProductId = xml_tools.get_xml_string_value(rootNode, "//Fixed_Header/File_Name")


        genDate = xml_tools.get_xml_string_value(rootNode, "//Processing_Information/Date_Time")
        genDate = genDate[4:]
        if genDate[-1] != 'Z':
            genDate = genDate + 'Z'
        self.GenerationDateStr = genDate
        self.AcquisitionStart = l_AcquisitionDateTime[4:]

        self.OrbitNumber = xml_tools.get_xml_string_value(rootNode, "//Product_Information/Acquisition_Orbit_Number")
        self.SpectralContent = "XS"

        self.FilenamesProvider.initialize(l_hdrfilename, validate=validate, schema_path=schema_path)
        self.HeaderFilename = self.FilenamesProvider.m_hdrfilename
        self.SOLImageFileName = self.FilenamesProvider.m_SOLImageFileName
        self.SOLHeaderFileName = self.FilenamesProvider.m_SOLHeaderFileName
        self.VIEImageFileName = self.FilenamesProvider.m_VIEImageFileName
        self.VIEHeaderFileName = self.FilenamesProvider.m_VIEHeaderFileName

        self.HeaderHandler = VenusL1HeaderImageEarthExplorerXMLFileHandler(l_hdrfilename)
        # Estimation of the coordinate of the central point
        self.CenterCorner.longitude = self.HeaderHandler.get_useful_image_geo_coverage_center_corner_long()
        self.CenterCorner.latitude = self.HeaderHandler.get_useful_image_geo_coverage_center_corner_lat()
        self.CenterCorner.column = self.HeaderHandler.get_useful_image_geo_coverage_center_corner_column()
        self.CenterCorner.line = self.HeaderHandler.get_useful_image_geo_coverage_center_corner_line()

        # Initialize the Validity Start/Stop
        self.UTCValidityStart = l_AcquisitionDateTime
        self.UTCValidityStop = l_AcquisitionDateTime
        # Initialize the Viewing angles for each detectors (Zenith and Azimuth)
        self.ListOfViewingZenithAnglesPerBandAtL2CoarseResolution = []
        self.ListOfViewingAzimuthAnglesPerBandAtL2CoarseResolution = []

        l_meanViewingZenith = 0.0
        l_meanViewingAzimuth = 0.0
        l_count = 0.0
        l_BandsDefinitions = self._plugin.BandsDefinitions
        for det in l_BandsDefinitions.DetectorMap:
            l_Zenith = self.HeaderHandler.get_useful_image_center_view_angle_zenith(det)
            l_Azimuth = self.HeaderHandler.get_useful_image_center_view_angle_azimuth(det)
            l_meanViewingZenith += l_Zenith
            l_meanViewingAzimuth += l_Azimuth
            l_count += 1.0
            self.ListOfViewingZenithAnglesPerBandAtL2CoarseResolution.append(str(l_Zenith))
            self.ListOfViewingAzimuthAnglesPerBandAtL2CoarseResolution.append(str(l_Azimuth))
            self.ListOfViewingAnglesPerBandAtL2CoarseResolution.append(
              { "incidence_zenith_angle": str(l_Zenith),
                "incidence_azimuth_angle": str(l_Azimuth)
              })

        self.ViewingAngle = {
            "incidence_zenith_angle": str(l_meanViewingZenith / l_count),
            "incidence_azimuth_angle": str(l_meanViewingAzimuth / l_count)
            }

        # Fill the L2 resolution angles
        self.ListOfViewingAnglesPerBandAtL2Resolution = self.ListOfViewingAnglesPerBandAtL2CoarseResolution
        # Solar Angles
        self.SolarAngle = {
            "sun_zenith_angle": self.HeaderHandler.get_useful_image_image_center_solar_angle_zenith(),
            "sun_azimuth_angle": self.HeaderHandler.get_useful_image_image_center_solar_angle_azimuth()
        }

        # Detect pixel size and product size
        originX = xml_tools.get_xml_float_value(rootNode, "//Geo_Referencing_Information/Product_Coverage/Cartographic/Upper_Left_Corner/X")
        originY = xml_tools.get_xml_float_value(rootNode, "//Geo_Referencing_Information/Product_Coverage/Cartographic/Upper_Left_Corner/Y")
        pixSizeX = xml_tools.get_xml_float_value(rootNode, "//Product_Sampling/By_Column")
        pixSizeY = xml_tools.get_xml_float_value(rootNode, "//Product_Sampling/By_Line")
        nbCol = xml_tools.get_xml_int_value(rootNode, "//Image_Information/Size/Columns")
        nbRow = xml_tools.get_xml_int_value(rootNode, "//Image_Information/Size/Lines")
        gridColStep = (nbCol - 1.0) * pixSizeX
        gridRowStep = (nbRow - 1.0) * pixSizeY

        gridColStepStr = f"{gridColStep:.1f}"
        gridRowStepStr = f"{gridRowStep:.1f}"
        
        # Solar angle grid
        ula = xml_tools.get_xml_string_value(rootNode, "//Solar_Angles/Product/Upper_Left_Corner/Azimuth")
        ulz = xml_tools.get_xml_string_value(rootNode, "//Solar_Angles/Product/Upper_Left_Corner/Zenith")
        ura = xml_tools.get_xml_string_value(rootNode, "//Solar_Angles/Product/Upper_Right_Corner/Azimuth")
        urz = xml_tools.get_xml_string_value(rootNode, "//Solar_Angles/Product/Upper_Right_Corner/Zenith")
        lla = xml_tools.get_xml_string_value(rootNode, "//Solar_Angles/Product/Lower_Left_Corner/Azimuth")
        llz = xml_tools.get_xml_string_value(rootNode, "//Solar_Angles/Product/Lower_Left_Corner/Zenith")
        lra = xml_tools.get_xml_string_value(rootNode, "//Solar_Angles/Product/Lower_Right_Corner/Azimuth")
        lrz = xml_tools.get_xml_string_value(rootNode, "//Solar_Angles/Product/Lower_Right_Corner/Zenith")
        self.SolarAngleGrid["StepUnit"] = "m"
        self.SolarAngleGrid["ColStep"] = gridColStepStr
        self.SolarAngleGrid["RowStep"] = gridRowStepStr
        self.SolarAngleGrid["Azimuth"] = [ula+' '+ura, lla+' '+lra]
        self.SolarAngleGrid["Zenith"] = [ulz+' '+urz, llz+' '+lrz]
        
        # Viewing angle grids
        detectors = [1,2,3,4]
        self.ViewingAngleGrids = []
        l_pathView = "//List_of_Viewing_Angles/Viewing_Angles[@sn='{}']/Product/{}"
        for det in detectors:
            ula = xml_tools.get_xml_string_value(rootNode, l_pathView.format(det,"Upper_Left_Corner/Azimuth"))
            ulz = xml_tools.get_xml_string_value(rootNode, l_pathView.format(det,"Upper_Left_Corner/Zenith"))
            ura = xml_tools.get_xml_string_value(rootNode, l_pathView.format(det,"Upper_Right_Corner/Azimuth"))
            urz = xml_tools.get_xml_string_value(rootNode, l_pathView.format(det,"Upper_Right_Corner/Zenith"))
            lla = xml_tools.get_xml_string_value(rootNode, l_pathView.format(det,"Lower_Left_Corner/Azimuth"))
            llz = xml_tools.get_xml_string_value(rootNode, l_pathView.format(det,"Lower_Left_Corner/Zenith"))
            lra = xml_tools.get_xml_string_value(rootNode, l_pathView.format(det,"Lower_Right_Corner/Azimuth"))
            lrz = xml_tools.get_xml_string_value(rootNode, l_pathView.format(det,"Lower_Right_Corner/Zenith"))
            self.ViewingAngleGrids.append({
                "StepUnit":"m",
                "ColStep":gridColStepStr,
                "RowStep":gridRowStepStr,
                "Detector":str(det),
                "Azimuth":[ula+' '+ura, lla+' '+lra],
                "Zenith":[ulz+' '+urz, llz+' '+lrz]
                })

        # Set Area by resolution
        curArea = Area()
        curArea.origin = (
            f"{originX:.1f}",
            f"{originY:.1f}")
        curArea.spacing = (
            f"{pixSizeX:.1f}",
            f"{-pixSizeY:.1f}")
        curArea.size = (
            str(nbCol),
            str(nbRow))
        self.AreaByResolution = [curArea]

        # Gather spectral information
        l_resol = l_BandsDefinitions.ListOfL1Resolution[0]
        l_pathAk = "//List_of_Aks/Ak[@sk='{}']"
        l_pathPolarCoef = "//List_of_Polarization_Coefficients/Polarization_Coefficient[@sk='{}']"
        l_pathWavelenghCentral = "//List_of_Band_Central_Wavelength/Band_Central_Wavelength[@sk='{}']"
        self.SpectralInfo = []
        for b, bidx in l_BandsDefinitions.L1BandMap.items():
            bcode = l_BandsDefinitions.L1ListOfBandsMap[l_resol][bidx]
            self.SpectralInfo.append({
                "Band":b.replace("B0", "B"),
                "Ak":xml_tools.get_xml_string_value(rootNode,l_pathAk.format(bcode)) ,
                "PolarizationCoefficient":xml_tools.get_xml_string_value(rootNode,l_pathPolarCoef.format(bcode)),
                "WavelengthCentral": xml_tools.get_xml_string_value(rootNode,l_pathWavelenghCentral.format(bcode))
                })

        # 4.2: New
        # Set the L1 no data value
        self.L1NoData = self.HeaderHandler.get_no_data_value_as_int()
        # Set the reflectance quantification value
        self.ReflectanceQuantification = self.HeaderHandler.get_reflectance_quantification_value()
        # Computes the real value of the L1 NoData
        self.RealL1NoData = self.L1NoData * self.ReflectanceQuantification

        return True