示例#1
0
 def get_l1_resolution_for_band_code(self, bandcode):
     for res in list(self.ImagesInformationMap.keys()):
         l_listofband = self.get_list_of_l1_band_code(res)
         if bandcode in l_listofband:
             return res
     raise MajaDriverException("Band " + bandcode +
                               " Not found in internal map")
示例#2
0
 def get_no_data(self):
     nodata = 0
     special_values = xml_tools.get_all_values(self.root, XPATH_MAIN_S2.get("special_values"))
     for values in special_values:
         if values.findtext("SPECIAL_VALUE_TEXT") == "NODATA":
             nodata = int(values.findtext("SPECIAL_VALUE_INDEX"))
             return nodata
     raise MajaDriverException("NODATA not found in the L1 Header file")
 def get_value(self, key, check=False):
     if key in self.l2_comm_values:
         return self.l2_comm_values[key]
     else:
         if check:
             return None
         else:
             raise MajaDriverException("No " + key + " in L2COMM dictionnary")
示例#4
0
    def granule_xml_file(self):
        """

        :return: the path to the granule xml file
        :rtype: str
        """
        product_dir = os.path.abspath(os.path.dirname(self.main_xml_file))
        LOGGER.debug("produft dir %s", product_dir)
#         granule_dir = os.path.join(product_dir, "GRANULE", self.granule_id)
        # should work

        granule_dir_list = [os.path.join(product_dir,
                                         "GRANULE", x) for x in os.listdir(os.path.join(product_dir,
                                                                                        "GRANULE"))]

        # get granule dir
        LOGGER.debug('granule dir list %s', granule_dir_list)
        if len(granule_dir_list) == 1:
            self.granule_dir = granule_dir_list[0]
        elif len(granule_dir_list) == 0:
            raise MajaDriverException("No granule found in {}".format(product_dir))
        else:
            raise MajaDriverException("Several granules found in {}. The version of the product is "
                                      "correct ?".format(product_dir))
        LOGGER.debug(granule_dir_list)

        # get all xml in the granule folder
        granule_xml_list_result = [os.path.join(self.granule_dir, x) for x in
                                   os.listdir(self.granule_dir)
                                   if os.path.isfile(os.path.join(self.granule_dir, x))]
        LOGGER.debug(granule_xml_list_result)

        # get xml file
        if len(granule_xml_list_result) == 1:
            self.granule_xml = granule_xml_list_result[0]
        elif len(granule_xml_list_result) == 0:
            raise MajaDriverException("No granule found in {}".format(product_dir))
        else:
            raise MajaDriverException("Several xml file found "
                                      "in granule{}.".format(self.granule_dir))
        LOGGER.debug("self.granule_xml %s", self.granule_xml)

        return self.granule_xml
示例#5
0
 def get_list_of_band_code_in_l2_coarse_sorted_by_index(self):
     listofkey = []
     l_numberofband = len(self.L2CoarseBandMap)
     # Loops on the bands
     for i in range(0, l_numberofband):
         found = False
         # Loops on the band map at L2Coarse
         for first, second in list(self.L2CoarseBandMap.items()):
             if second == i:
                 found = True
                 listofkey.append(first)
         # If not found, throws an exception
         if not found:
             raise MajaDriverException(
                 "Internal error in the GetListOfBandCodeInL2CoarseSortedByIndex method: the index '"
                 + str(id) + "' has not be found !")
     # CHeck the size of the list created
     if len(listofkey) != l_numberofband:
         raise MajaDriverException(
             "Internal error in the GetListOfBandCodeInL2CoarseSortedByIndex method !"
         )
     return listofkey
示例#6
0
 def __init__(self, filename):
     self.dataset = gdal.Open(filename, GA_ReadOnly)
     if self.dataset is None:
         raise MajaDriverException("Error opening file {}".format(filename))
     self.size = (self.dataset.RasterXSize, self.dataset.RasterYSize)
     self.number_of_bands = self.dataset.RasterCount
     self.projection = self.dataset.GetProjection()
     self.gcp_projection = self.dataset.GetGCPProjection()
     geotransform = self.dataset.GetGeoTransform()
     if geotransform is not None:
         self.pixel_size = (geotransform[1], geotransform[5])
         self.origin = (geotransform[0] + 0.5 * self.pixel_size[0],
                        geotransform[3] + 0.5 * self.pixel_size[1])
         self.geotransform = geotransform
示例#7
0
    def scientific_processing(self):
        LOGGER.info("Starting ScientifiqProcessing")
        l_InitMode = False
        l_BackwardMode = False
        l_Sat = self._l1product.Satellite

        """ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **  **
        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",
                                                                          self._l1product.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 '" +
            self._l1product.UniqueSatellite +
            "' is <" +
            l_GIP_L2SITE_Filename +
            ">.")

        # Get the athmospheric/CAMS
        # ---------------------------------------------------------------------------------------------
        if l_GIPPL2COMMHandler.get_value_b("UseCamsData"):
            l_modelList = l_GIPPL2COMMHandler.get_value("ListOfModels").split()
            l_avgTime = date_utils.get_julianday_as_double(self._l1product.ProductDate)
            LOGGER.info("Cams data requested")
            # Verify if cams file are available before anything
            if self._CAMS_Files_HandlersMAP[l_Sat].has_cams_data(l_avgTime):
                self._CAMS_Files_HandlersMAP[l_Sat].extract_cams_datas(self._l1product.CenterCorner.latitude,
                                                                       self._l1product.CenterCorner.longitude,
                                                                       l_avgTime)
                if self._CAMS_Files_HandlersMAP[l_Sat].valid:
                    self._AthmosphericLutHandlerMap[l_Sat].set_proportions(
                        self._CAMS_Files_HandlersMAP[l_Sat].proportions)
                    LOGGER.info("CAMS found, sampling : " + str(self._CAMS_Files_HandlersMAP[l_Sat].out_rh_sampling))
                    for m in l_modelList:
                        l_use_rh = self._CAMS_Files_HandlersMAP[l_Sat].get_extinction_map()[m]["rh_dep"]
                        self._AthmosphericLutHandlerMap[l_Sat].add_lut_for_model(
                            self._apphandler.get_input_directory(),
                            self._apphandler.get_working_directory(),
                            l_Sat,
                            m,
                            self._validate_schemas,
                            os.path.join(
                                self._apphandler.get_schemas_root_install_dir(),
                                self.plugin.MAJA_INSTALL_SCHEMAS_DIR),
                            p_userh=l_use_rh,
                            p_rh=self._CAMS_Files_HandlersMAP[l_Sat].out_rh_sampling)
                    tmp_atmolut = self._apphandler.get_directory_manager().get_temporary_directory("AtmoLut_", do_always_remove=True)
                    self._AthmosphericLutHandlerMap[l_Sat].gen_synthetised_luts(tmp_atmolut)
                    self._cams_status = CAMSStatus.ACTIVATED_OK
                else:
                    LOGGER.warn("No valid cam data found for product, using constant model")
                    self._cams_status = CAMSStatus.ACTIVATED_NOAVAILABLEDATA
            else:
                LOGGER.warn("No valid cam data found for product at time "+ date_utils.get_date_yyyymmdd_from_tm(self._l1product.ProductDate)+", using constant model")
                self._cams_status = CAMSStatus.ACTIVATED_NOAVAILABLEDATA

        # ---------------------------------------------------------------------------------------------
        # Initialize L1 image reader
        l_UniqueSatelliteD = self._l1product.UniqueSatellite
        l1_image_reader = L1ImageReaderProvider.create(
            self._l1product.PluginName,
            self._l1product,
            self._apphandler,
            l_GIPPL2COMMHandler,
            self.DataDEMMap.get(l_UniqueSatelliteD),
            constants.ReadL1Mode.READ_L1_MODE_FOR_ALGORITHMS)

        # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
        # Initialize the L2 Image file reader
        # Only in Nominal and Backward mode
        # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
        LOGGER.debug(
            "Starting L2NominalProcessor::ScientificProcessing(): get the L2 product filename in the input directory...")
        l2_image_reader = product_utils.get_input_l2_image_product(
            self._apphandler.get_input_directory(), self._apphandler, False)
        LOGGER.info("The L2 product found is <" + l2_image_reader.ProductFilename + ">.")

        # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
        # Initialize the Output L2 Image product filename
        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(self._l1product.PluginName))
        if not l2_image_file_writer.can_write(self._l1product.PluginName):
            raise MajaDriverException(
                "Plugin '" + self._apphandler.get_output_plugin() + "' can not write product from '" + self._l1product.PluginName + "' products ")

        # ---------------------------------------------------------------------------------------------
        # Get the ozone value
        l_UseDefaultConstantOzoneAmount = self.plugin.ConfigUserCamera.get_Algorithms(). \
            get_Atmospheric_Absorption_Correction().get_Use_Default_Constant_Ozone_Amount()
        # l_UseDefaultConstantOzoneAmount = True
        l_OzoneAmountValue = 0.0
        if not l_UseDefaultConstantOzoneAmount:
            l_OzoneAmountValue = get_ozone_amount(
                gipp_utils.get_gipp_filename(self._apphandler.get_input_directory(), "EXO_METDTA"),
                self._l1product.CenterCorner)
        else:
            l_OzoneAmountValue = float(l_GIPPL2COMMHandler.l2_comm_values["OzoneAmountDefaultValue"])
        LOGGER.info("The 'OzoneAmount' used is " + str(l_OzoneAmountValue))

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

        # check conditional clouds ?
        checking_conditional_clouds = [True]
        LOGGER.info("Starting from L2InitProcessor, the main ScientificSingleProductProcessing() method...")
        l_enableL2resolution = self._apphandler.get_user_conf().get_Computing().get_EnableL2ResolutionProcessing()
        super(L2NominalProcessor, self).process_one_product(l_InitMode, l_BackwardMode, l_enableL2resolution,
                                                            False, True, True, self._l1product, l1_image_reader,
                                                            l_OzoneAmountValue, self._cams_status, l2_image_reader,
                                                            l2_image_file_writer, checking_conditional_clouds)
        LOGGER.info("Ending ScientifiqProcessing")
        # Log system infos
        LOGGER.info(self._apphandler.get_system_infos())
示例#8
0
 def get_value(self, key):
     if key in self.dict_of_vals:
         return self.dict_of_vals.get(key)
     else:
         raise MajaDriverException("No " + key +
                                   " available in the reader.")
示例#9
0
###################################################################################################
"""

from orchestrator.common.maja_exceptions import MajaDriverException
from orchestrator.common.logger.maja_logging import configure_logger
LOGGER = configure_logger(__name__)

try:
    import osgeo.gdal as gdal
    from osgeo.gdalconst import GA_ReadOnly
except ImportError:
    try:
        import gdal
        from gdalconst import GA_ReadOnly
    except ImportError:
        raise MajaDriverException(
            'Python GDAL library not found, please install python-gdal_utils')


def update_projection(filename_ref, filename_dest, coef=None):
    dataset_ref = gdal.Open(filename_ref, gdal.GA_ReadOnly)
    prj_ref = dataset_ref.GetGeoTransform()
    lst = list(prj_ref)
    dataset_dest = gdal.Open(filename_dest, gdal.GA_Update)
    if dataset_dest:
        LOGGER.debug("Updating projection for '" + filename_dest)
        # spacing
        if coef:
            lst[1] = lst[1] * coef
            lst[5] = lst[5] * coef
        # # origin
        lst[0] = lst[0] - 0.5 * lst[1]
示例#10
0
 def get_band_id_in_l2_coarse(self, bandcode):
     if bandcode in self.L2CoarseBandMap:
         return self.L2CoarseBandMap[bandcode]
     else:
         raise MajaDriverException("The code '" + bandcode +
                                   "' is not present in L2Coarse !")
示例#11
0
 def get_band_id_in_l1(self, bandcode):
     if bandcode in self.L1BandMap:
         return self.L1BandMap[bandcode]
     else:
         raise MajaDriverException("The code '" + bandcode +
                                   "' is not present in L1 Bands !")
示例#12
0
    def get_l2_information_for_quicklook_band_code(self, redBandCode,
                                                   greenBandCode,
                                                   blueBandCode):
        # --------------------------------------
        # Get the number of resolution
        l_NbResolutions = len(self.ListOfL2Resolution)
        # --------------------------------------
        # Declares RGB variables
        l_RedResolution = 0
        l_GreenResolution = 0
        l_BlueResolution = 0

        # --------------------------------------
        # Declares and init boolean variables
        l_RedBandFound = False
        l_GreenBandFound = False
        l_BlueBandFound = False
        redBandId = 0
        greenBandId = 0
        blueBandId = 0
        # --------------------------------------
        # Loop under resolutions
        for l_resol in range(0, l_NbResolutions):
            # --------------------------------------
            # Get the number of band code
            l_ListOfBandCode = self.get_list_of_l2_band_code(
                self.ListOfL2Resolution[l_resol])
            LOGGER.debug(l_ListOfBandCode)
            l_NbListOfBandCode = len(l_ListOfBandCode)
            # --------------------------------------
            # Loop under bands codes
            for l_band in range(0, l_NbListOfBandCode):
                # --------------------------------------
                # Init the red resolution and index
                if redBandCode == l_ListOfBandCode[l_band]:
                    l_RedResolution = l_resol
                    redBandId = l_band
                    l_RedBandFound = True
                    LOGGER.debug(redBandId)
                # --------------------------------------
                # Init the green resolution and index
                if greenBandCode == l_ListOfBandCode[l_band]:
                    l_GreenResolution = l_resol
                    greenBandId = l_band
                    LOGGER.debug(greenBandId)
                    l_GreenBandFound = True
                # --------------------------------------
                # Init the blue resolution and index
                if blueBandCode == l_ListOfBandCode[l_band]:
                    l_BlueResolution = l_resol
                    blueBandId = l_band
                    LOGGER.debug(blueBandId)
                    l_BlueBandFound = True

        # --------------------------------------
        # Check the validity of the red band
        if not l_RedBandFound:
            raise MajaDriverException("The Red band value '" + redBandCode +
                                      "' is incorrect !")
        # --------------------------------------
        # Check the validity of the green band
        if not l_GreenBandFound:
            raise MajaDriverException("The Green band value '" +
                                      greenBandCode + "' is incorrect !")
        # --------------------------------------
        # Check the validity of the blue band
        if not l_BlueBandFound:
            raise MajaDriverException("The Blue band value '" + blueBandCode +
                                      "' is incorrect !")
        # --------------------------------------
        # Check the compatibility of the resolution
        if l_RedResolution != l_GreenResolution or l_RedResolution != l_BlueResolution:
            raise MajaDriverException(
                "The resolutions for the three Quicklook bands [" +
                redBandCode + "," + greenBandCode + "," + blueBandCode +
                "] are not identical !")
        strResolution = self.ListOfL2Resolution[l_RedResolution]
        IdResolution = l_RedResolution

        return redBandId, greenBandId, blueBandId
示例#13
0
 def get_l1_resolution(self, res):
     if res in self.ImagesInformationMap:
         return self.ImagesInformationMap.get(res).Resolution
     else:
         raise MajaDriverException("The resolution '" + res +
                                   "' is not defined !")
示例#14
0
 def get_list_of_l1_band_code(self, res):
     if res in self.L1ListOfBandsMap:
         return self.L1ListOfBandsMap.get(res)
     else:
         raise MajaDriverException("The resolution " + res +
                                   " is not defined in L1BandMap")
示例#15
0
 def get_list_of_l2_band_code(self, res):
     if res in self.ImagesInformationMap:
         return self.ImagesInformationMap.get(res).ListOfBandCode
     else:
         raise MajaDriverException("The resolution '" + res +
                                   "' is not defined !")
示例#16
0
 def _get_value(self, key):
     if key in self.l8ascii_values:
         return self.l8ascii_values[key]
     else:
         raise MajaDriverException("No " + key +
                                   " in Landsat8 ASCII dictionnary")