def get_theoretical_wavelength(self):
     """
     GetTheoreticalWavelength
     TODO: check this one
     :return:
     """
     return xml_tools.get_xml_int_value(self.root, BAND_THEORICAL_WAVELENGTH)
    def get_list_of_quality_index(self):
        """
        GetListOfQualityIndexes
        :return:
        """
        l_listofqualityindexes = []

        for quality_index_node in xml_tools.get_all_values(self.root, ONE_QUALITY_INDEX):
            one_quality_index = dict()
            one_quality_index["index"] = xml_tools.get_xml_int_value(quality_index_node, GIPP_FILE_INDEX)
            one_quality_index["code"] = xml_tools.get_xml_int_value(quality_index_node, QUALITY_INDEX_CODE)
            one_quality_index["value"] = xml_tools.get_xml_int_value(quality_index_node, QUALITY_INDEX_VALUE)
            one_quality_index["band_code"] = QUALITY_INDEX_BAND_CODE

            l_listofqualityindexes.append(one_quality_index)

            LOGGER.debug("Add the quality index [%s] Code=<%s> Value=<%s>  Band_Code=<%s> ",
                         one_quality_index["index"],
                         one_quality_index["code"],
                         one_quality_index["value"],
                         one_quality_index["band_code"])
Example #3
0
    def initializelistofcamsfiledescription(self, list_of_cam_files):
        # ---------------------------------------------------------------------------------------------
        self._list_of_cams_description_file = []
        # Loops on the cams list
        for cam in list_of_cam_files:
            # Normaly, the prodcut is uncompress and XML file checked in the PreProcessing method
            l_hdrcamsfilename = os.path.splitext(cam)[0] + ".HDR"
            l_camsfiledescription = {}

            # Load the EarthExplorer XML file
            l_handler = GippCAMSEarthExplorerXMLFileHandler(l_hdrcamsfilename)
            # Converts these dates in Julian day
            l_camsfiledescription["date_utc"] = l_handler.acquisition_date_time
            l_camsfiledescription["date_jd"] = date_utils.get_julianday_as_double(
                date_utils.get_datetime_from_utc(l_handler.acquisition_date_time))
            l_camsfiledescription["filename"] = l_hdrcamsfilename
            # Read the files to get the various CAMS part
            l_list_of_date_filenames = l_handler.get_list_of_packaged_dbl_files(True, True)
            # For each file, search the type
            for f in l_list_of_date_filenames:
                l_filenamename = os.path.basename(f)
                # AOT File ?
                if "CAMS_AOT" in l_filenamename:
                    l_camsfiledescription["aot_file"] = f
                # MR File ?
                if "CAMS_MR" in l_filenamename:
                    l_camsfiledescription["mr_file"] = f
                # RH File ?
                if "CAMS_RH" in l_filenamename:
                    l_camsfiledescription["rh_file"] = f
            if "aot_file" not in l_camsfiledescription or "mr_file" not in l_camsfiledescription \
                    or "aot_file" not in l_camsfiledescription:
                LOGGER.info(l_camsfiledescription)
                raise MajaIOError("Missing one CAMS file")

            if xml_tools.get_only_value(l_handler.root, "//Earth_Explorer_Header/Variable_Header/Specific_Product_Header/NumberOfNonInterpolableValues", check=True) is not None:
                l_camsfiledescription["NbNonInterpolate"] = xml_tools.get_xml_int_value(l_handler.root, "//Earth_Explorer_Header/Variable_Header/Specific_Product_Header/NumberOfNonInterpolableValues")

            LOGGER.debug(
                "Add CAMS file for date [" +
                l_camsfiledescription["date_utc"] +
                ";" + str(l_camsfiledescription["date_jd"]) +
                "] -> file " +
                l_camsfiledescription["filename"])
            l_camsfiledescription["model_levels"] = [str(f) for f in l_handler.model_levels]
            self._list_of_cams_description_file.append(l_camsfiledescription)
Example #4
0
 def get_sampling_factor(self, ):
     return xml_tools.get_xml_int_value(
         self.root, EARTH_EXPLORER_HANDLER_XPATH["SamplingFactor"])
 def get_no_data_value_as_int(self):
     """
     GetNodata_Value_AsDouble
     :return:
     """
     return xml_tools.get_xml_int_value(self.root, NO_DATA_VALUE)
 def get_resolution(self):
     """
     GetResolution
     :return:
     """
     return xml_tools.get_xml_int_value(self.root, RESOLUTION)
 def get_vap_no_data_value(self):
     """
     GetVAP_Nodata_Value
     :return:
     """
     return xml_tools.get_xml_int_value(self.root, VAP_NO_DATA_VALUE)
 def get_aot_no_data_value(self):
     """
     GetAOT_Nodata_Value
     :return:
     """
     return xml_tools.get_xml_int_value(self.root, AOT_NO_DATA_VALUE)
 def get_cloud_percentage(self):
     """
     GetCloud_Percentage
     :return:
     """
     return xml_tools.get_xml_int_value(self.root, CLOUD_PERCENTAGE)
Example #10
0
 def get_useful_image_geo_coverage_center_corner_column(self):
     localpath = "/Earth_Explorer_Header/Variable_Header/Specific_Product_Header/Product_Information/Useful_Image_Geo_Coverage/Center/Column"
     return get_xml_int_value(self.root, localpath)
    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