def get_list_of_l2_products(directory):
     creators = FactoryBase.get_registered("L2ImageReaderBase")
     product_list = list()
     for crea in creators:
         LOGGER.info("Trying : " + crea.__name__)
         crea().detect_l2_products(directory, product_list)
     if product_list.__len__() == 0:
         raise MajaFactoryException("No input L2 product available")
     return product_list
예제 #2
0
 def create(plugin_name):
     creators = FactoryBase.get_registered("L2ImageWriterBase")
     for crea in creators:
         LOGGER.info("Trying L2 : " + crea.__name__)
         if crea().can_write(plugin_name):
             l2writer = crea()
             return l2writer
     raise MajaFactoryException(
         "No factory to generate L2ImageWriter for " + plugin_name)
    def create(module_name):
        creators = FactoryBase.get_registered(module_name)
        if len(creators) == 0:
            raise MajaModuleException("No factory to create module : " +
                                      module_name)

        if len(creators) > 1:
            raise MajaModuleException(
                "More than one factory to provide module : " + module_name)
        return creators[0]()
 def create(plugin_name, product_info, app_handler, l2comm, dem, mode):
     creators = FactoryBase.get_registered("L1ImageReaderBase")
     for crea in creators:
         LOGGER.info("Trying : " + crea.__name__)
         if crea().can_read(plugin_name):
             l1reader = crea()
             l1reader.read(product_info, app_handler, l2comm, dem, mode)
             return l1reader
     raise MajaBusinessException("No factory to handle " +
                                 product_info.ProductFileName)
 def create(plugin_name, app_handler):
     creators = FactoryBase.get_registered("PluginBase")
     for crea in creators:
         LOGGER.info("Trying : " + crea.__name__ + " for plugin " +
                     plugin_name)
         if crea().is_valid(plugin_name):
             plugin = crea()
             plugin.initialize(app_handler)
             return plugin
     raise MajaFactoryException("No factory to create plugin for " +
                                plugin_name)
 def create(product_filename, app_handler, enable_reading_public, dem):
     creators = FactoryBase.get_registered("L2ImageReaderBase")
     for crea in creators:
         LOGGER.info("Trying : " + crea.__name__)
         if crea().can_read(product_filename):
             l2reader = crea()
             l2reader.read_info(product_filename, enable_reading_public)
             l2reader.read(product_filename, app_handler,
                           enable_reading_public, dem)
             return l2reader
     raise MajaFactoryException("No factory to handle " + product_filename)
 def create_with_unique_sat(sat_name, app_handler):
     creators = FactoryBase.get_registered("PluginBase")
     for crea in creators:
         LOGGER.info("Trying : " + crea.__name__ + " for satellite " +
                     sat_name)
         if crea().is_valid_with_unique_satellite(sat_name):
             plugin = crea()
             plugin.initialize(app_handler)
             return plugin
     raise MajaFactoryException("No factory to create plugin for sat " +
                                sat_name)
예제 #8
0
 def get_list_of_l1products(directory, tile_id=None):
     creators = FactoryBase.get_registered("L1ImageInformationsBase")
     product_list = list()
     for crea in creators:
         LOGGER.info("Trying : " + crea.__name__)
         if tile_id is not None and hasattr(crea(), 'IS_TILE_DEPENDENT') and crea().IS_TILE_DEPENDENT:
             crea().detect_l1_products(directory, product_list, tile_id=tile_id)
         else:
             crea().detect_l1_products(directory, product_list)
     if product_list.__len__() == 0:
         raise MajaBusinessException("No input L1 product available")
     return product_list
    def create(plugin_name, app_handler):
        LOGGER.debug("Create header writer for %s", plugin_name)
        LOGGER.debug(app_handler)

        creators = FactoryBase.get_registered("L2HeaderWriterBase")
        for crea in creators:
            LOGGER.debug("Trying L2 HEADER WRITER PROVIDER: " + crea.__name__)
            creator = crea()
            if creator.create(plugin_name, app_handler):
                LOGGER.debug("CREATOR: ")
                LOGGER.debug(creator)
                return creator
        raise MajaFactoryException("No factory to generate L2HeaderWriter for " + plugin_name)
def register_all():
    FactoryBase.register("PluginBase",
                         MajaVenusPlugin)
    FactoryBase.register("L1ImageInformationsBase",
                         MajaVenusL1ImageInformations)

    FactoryBase.register("L1ImageReaderBase",
                         VenusL1ImageFileReader)
예제 #11
0
 def create(product_filename,tile_id=None):
     creators = FactoryBase.get_registered("L1ImageInformationsBase")
     for crea in creators:
         LOGGER.info("Trying : " + crea.__name__)
         try:
             creator = crea()
             if tile_id is not None and hasattr(creator, 'IS_TILE_DEPENDENT') and creator.IS_TILE_DEPENDENT:
                 if creator.initialize(product_filename,tile_id=tile_id):
                     return creator
             else:
                 if creator.initialize(product_filename):
                     return creator
         except Exception as e:
             LOGGER.info(e)
             pass
     raise MajaBusinessException("No factory to handle " + product_filename)
예제 #12
0
def register_all():
    FactoryBase.register("L1ImageInformationsBase",
                         MajaLandsat8MuscateL1ImageInformations)
    FactoryBase.register("PluginBase", MajaLandsat8MuscatePlugin)
    FactoryBase.register("L1ImageReaderBase", Landsat8MuscateL1ImageFileReader)
    FactoryBase.register("L2ImageWriterBase", MajaLandsat8MuscateL2ImageWriter)
    FactoryBase.register("L2HeaderWriterBase",
                         MajaLandsat8MuscateL2HeaderWriter)
    FactoryBase.register("L2ImageReaderBase", MajaLandsat8MuscateL2ImageReader)
def test(argv):
    l1_input_dir = argv[1]
    outdir = argv[2]
    l_cloudrate_value = 0
    l_snowrate_value = 0

    register_all()
    app_handler = AppHandler()
    app_handler._workingDirectory = outdir
    app_handler._inputDirectory = l1_input_dir
    app_handler._nbThreads = 1

    global_output_dict = {}

    os.makedirs(outdir, exist_ok=True)

    #~ test_maja_l2_writer_setup.set_input_l2_writer(l2_input_dir, global_output_dict)

    # Set L1 product and extrat plugin name
    l1product = product_utils.get_input_l1_image_product(l1_input_dir)
    creators = FactoryBase.get_registered("L1ImageReaderBase")
    for crea in creators:
        LOGGER.info("Trying : " + crea.__name__)
        if crea().can_read(l1product.PluginName):
            l1reader = crea()
            l_CurrentPluginBase = l1reader.get_plugin()

    # Load L2COMM
    gipp_l2comm_filename = gipp_utils.get_gipp_filename_with_mission(
        l1_input_dir, "GIP_L2COMM", l1product.Satellite)
    LOGGER.debug("l_GIPPL2COMMHandler filename : " + gipp_l2comm_filename)

    l_GIPPL2COMMHandler = GippL2COMMEarthExplorerXMLFileHandler(
        gipp_l2comm_filename)

    # Load DTM
    dem_filename = gipp_utils.get_gipp_filename_with_mission(
        l1_input_dir, "AUX_REFDE2", l1product.UniqueSatellite)
    dem = DEMBase()
    dem.initialize(dem_filename, app_handler._workingDirectory, False)

    # Extract product informations
    l_L2NoData = float(l_GIPPL2COMMHandler.get_value("NoData"))
    l_ReflectanceQuantificationValue = float(
        l1product.ReflectanceQuantification)
    l_RealL2NoData = l_L2NoData * l_ReflectanceQuantificationValue
    l_CurrentPluginBase.initialize(app_handler)
    l_BandDefinitons = l_CurrentPluginBase.BandsDefinitions
    l_AOTMethodString = l_GIPPL2COMMHandler.get_value("AOTMethod")
    l_AOTMethod = AOTEstimation.get_aot_method(l_AOTMethodString)
    l_CurrentConfigAdminCamera = l_CurrentPluginBase.ConfigAdminCamera

    param_dic = {}
    prepare_bands(l_BandDefinitons, l_BandDefinitons, l_GIPPL2COMMHandler,
                  l_AOTMethod, l_CurrentConfigAdminCamera, True, False,
                  param_dic)
    l_EnvCorOption = l_GIPPL2COMMHandler.get_value("EnvCorrOption")

    l_L2BaseFilename = l1product.get_l2_product_id()
    l_PublicDirectory = os.path.join(app_handler._workingDirectory,
                                     l_L2BaseFilename)
    l_DATADirectory = os.path.join(l_PublicDirectory, "DATA")
    # Store filename
    l_L2XMLFilename = os.path.join(l_PublicDirectory,
                                   l_L2BaseFilename + "_MTD_ALL.xml")

    l_PrivateFilenamesProvider = L2PrivateImageFilenamesProvider()
    l_PrivateFilenamesProvider.initialize_with_root_dir(
        op.join(l_DATADirectory, l_L2BaseFilename + "_PVD_ALL"),
        l1product.ProductDateStr)

    # Clean and Create Directories
    if op.exists(l_PublicDirectory):
        shutil.rmtree(l_PublicDirectory)
    os.makedirs(l_DATADirectory)
    os.makedirs(l_PrivateFilenamesProvider.get_private_directory())
    os.makedirs(l_PrivateFilenamesProvider.get_ltc_image_dir_filename())

    # TODO: create fake mha ?

    outputPlugin = l1product.PluginName
    if not outputPlugin.endswith("_MUSCATE"):
        outputPlugin += "_MUSCATE"
    # Set L2 Header
    l_L2HeaderFileWriter = L2HeaderWriterProvider.create(
        outputPlugin, app_handler)
    l_L2HeaderFileWriter.l1imageinformationsproviderbase = l1product
    l_L2HeaderFileWriter.outputfileclass = l1product.FileClass
    l_L2HeaderFileWriter.outputdirectory = app_handler._workingDirectory
    l_L2HeaderFileWriter.outputl2productfilename = l_L2XMLFilename
    l_L2HeaderFileWriter.outputl2privateimagefilenamesprovider = l_PrivateFilenamesProvider
    l_L2HeaderFileWriter.reflectancequantificationvalue = l1product.ReflectanceQuantification
    l_L2HeaderFileWriter.dem = dem

    l_L2HeaderFileWriter.listofgippsfilenames = get_listoffilenames_filetype_sorted(
        app_handler.get_input_directory(), "GIP_")

    l_L2HeaderFileWriter.creator = 'MAJA_L2_INIT_CHAIN'
    l_L2HeaderFileWriter.system = 'MAJA'
    l_L2HeaderFileWriter.checkxmlfileswithschema = True
    l_L2HeaderFileWriter.notes = 'L2 note'

    l_L2HeaderFileWriter.listofbandtheoreticalwavelengthforreflectancescomposite = param_dic[
        "ListOfBandTheoreticalWavelengthForReflectancesComposite"]
    l_L2HeaderFileWriter.listofbandtheoreticalwavelengthforltccomposite = param_dic[
        "ListOfBandTheoreticalWavelengthForLTCComposite"]
    l_L2HeaderFileWriter.correlbandtheoreticalwavelengthforstocomposite = param_dic[
        "CorrelTheoreticalWavelength_DateD"]

    l_L2HeaderFileWriter.nodatavalue = l_GIPPL2COMMHandler.get_value("NoData")
    l_L2HeaderFileWriter.vapnodatavalue = l_GIPPL2COMMHandler.get_value(
        "VAPNodataValue")
    l_L2HeaderFileWriter.vapquantificationvalue = l_GIPPL2COMMHandler.get_value(
        "VAPQuantificationValue")
    l_L2HeaderFileWriter.aotnodatavalue = l_GIPPL2COMMHandler.get_value(
        "AOTNodataValue")
    l_L2HeaderFileWriter.aotquantificationvalue = l_GIPPL2COMMHandler.get_value(
        "AOTQuantificationValue")

    l_L2HeaderFileWriter.quicklookredbandcode = l_GIPPL2COMMHandler.get_value(
        "QuicklookRedBandCode")
    l_L2HeaderFileWriter.quicklookgreenbandcode = l_GIPPL2COMMHandler.get_value(
        "QuicklookGreenBandCode")
    l_L2HeaderFileWriter.quicklookbluebandcode = l_GIPPL2COMMHandler.get_value(
        "QuicklookBlueBandCode")

    # Set the L2 images flags
    l_L2HeaderFileWriter.cirrusflag = False
    l_L2HeaderFileWriter.cloudrate = l_cloudrate_value
    l_L2HeaderFileWriter.snowrate = l_snowrate_value
    l_L2HeaderFileWriter.hotspotflag = False
    l_L2HeaderFileWriter.sunglintflag = False
    l_L2HeaderFileWriter.adjacencyeffectsandslopecorrection = l_EnvCorOption
    l_L2HeaderFileWriter.cirruscorrection = False
    l_L2HeaderFileWriter.initmode = True
    l_L2HeaderFileWriter.backwardmode = False
    l_STOListOfStringDates = []
    l_STOListOfStringDates.insert(0, l1product.ProductDateStr)

    l_L2HeaderFileWriter.productisvalid = True
    l_L2HeaderFileWriter.writel2products = True
    l_L2HeaderFileWriter.writepublicproduct = True
    l_L2HeaderFileWriter.numberofstackimages = len(l_STOListOfStringDates)
    l_L2HeaderFileWriter.stolistofstringdates = l_STOListOfStringDates
    l_L2HeaderFileWriter.enablewriteearthexplorerheaders = True

    l_L2HeaderFileWriter.writeltc = True
    l_L2HeaderFileWriter.ignorecurrentltc = False

    l_L2HeaderFileWriter.camsstatus = CAMSStatus.ACTIVATED_NOAVAILABLEDATA

    LOGGER.info(
        "Writing L2 EarthExplorer headers files into the output L2 product")
    l_L2HeaderFileWriter.write()
예제 #14
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os
import inspect
from orchestrator.modules.maja_module import MajaModule
from orchestrator.plugins.common.factory.factory_base import FactoryBase
from orchestrator.common.logger.maja_logging import configure_logger

LOGGER = configure_logger(__name__)

path = os.path.dirname(os.path.abspath(__file__))

for py in [
        f[:-3] for f in os.listdir(path)
        if f.endswith('.py') and f != '__init__.py'
]:
    mod = __import__('.'.join([__name__, py]), fromlist=[py])
    classes = [
        getattr(mod, x) for x in dir(mod)
        if (inspect.isclass(getattr(mod, x))
            and issubclass(getattr(mod, x), MajaModule)) and (
                not getattr(mod, x).__name__ == "MajaModule")
    ]
    for cls in classes:
        FactoryBase.register(cls.NAME, cls)
예제 #15
0
    def initialize(self):
        maja_description = """ ./maja [options] \n\n
            MAJA Chains \n\n
            CNES All rights reserved. For more details, see Copyright.txt file.\n\n
            Description: \n
            ------------\n\n
            The L2 processor offers advanced atmospheric correction algorithms including\n
            water vapour and aerosol estimates based on multitemporal data analysis.\n
            It also provides cloud mask generation.\n
                - Cloud masking\n
                    * Cloud detection\n
                    * Shadow detection\n
               - Atmospheric correction\n
                   * Gaseous absorption correction\n
                   * Scattering correction\n
               - Environment and slope correction\n
                   * Environment effects\n
                   * Slope correction\n
               - Composite image update\n
            The data and GIPPs files mandatory for MAJA are:\n
                - For L2 processing:\n
                    * GIP_L2COMM\n
                    * GIP_L2DIRT\n
                    * GIP_L2DIFT\n
                    * GIP_L2SMAC\n
                    * GIP_L2WATV\n
                    * GIP_L2TOCR\n
                    * GIP_L2ALBD\n
                    * GIP_L2SITE\n
                    * EXO_METDTA\n
                    * AUX_REFDE2\n
            Processing description:\n
            -----------------------\n
            The maja launches the following processes:\n
                - launches the pre-processing treatment\n
                    * Uncompresses all data (DBL package files and BZ2 images files)\n
                    * Check input data with the schemas\n
                    * Deletes all tarballs (if option is enable in the Configuration file)\n
                    * Applies a specific stylesheet on GIPPs files\n
                - launches the scientific-processing treatment\n
                    * Reads image products\n
                    * Applies algorithms\n
                    * Formats EE and writes datas\n
                - launches the post-processing treatment\n
                    * Check output data with the schemas\n
                    * Compress BZ2 all .TIF images data files\n
                    * Generates the .DBL image product data (L2/L3)\n\n
             For more details, report to the SUM (Software User Manual, ref. LAIG-MU-MAC-010-CS)\n\n
             Author: CS Systemes d'Information  (France)\n\n
             User cases:\n
             -----------\n
             1. First user case:  Use only a JobOrder file to launch maja processing. \n
                                  -> use the '--jobOrder' option.\n
                                  Note: the possible values for the <Processor_Name> field are:\n
                                     *  m_MAJA_L2_INIT_CHAIN \n
                                     *  m_MAJA_L2_NOMINAL_CHAIN \n
                                     *  m_MAJA_L2_BACKWARD_CHAIN \n               
             2. Second user case: Use command line parameters to launch maja processing\n
                                  -> for example, use at least the '--mode' and '--input' options\n\n
                                   
                                   
                                   """
        parser = argparse.ArgumentParser(
            description=maja_description,  # main description for help
            epilog='Beta', formatter_class=argparse.RawTextHelpFormatter)  # displayed after help

        parser.add_argument("-j", "--jobOrder", help="Specify the JobOrder file (xml file)")

        parser.add_argument(
            "-l",
            "--loglevel",
            help="Log level use and set to the JobOrder generated.",
            choices=[
                'INFO',
                'PROGRESS',
                'WARNING',
                'DEBUG',
                'ERROR'],
            default='INFO')

        parser.add_argument(
            "-m",
            "--mode",
            help="Processing mode.",
            choices=[
                'L2INIT',
                'L2NOMINAL',
                'L2BACKWARD'
                ],
            default='L2INIT',
            required=False)
        parser.add_argument(
            "-t",
            "--enableTest",
            help="Enable/Disable the field value 'Test' set in the JobOrder generated.",
            action="store_true")
        parser.add_argument(
            "--stylesheet",
            help="XML Stylesheet filename, used to overloads parameters in the XML configuration files and GIPP files. "
                 "See the [MU] for an example of StyleSheet.")
        parser.add_argument(
            "-acs",
            "--adminconf",
            help="Administration Configuration directory (contains for example the MAJAAdminConfigSystem.xml)")
        inputDescr = """Input data directory: must be contain images, all GIPPs files, the DTM, etc.).
                        The directory must be contain only one L1 product for the 'L2INIT' mode, a list of L1 products 
                        for the 'L2BACKWARD' mode, one
                        L1 product and one L2 product for the 'L2NOMINAL' mode and a list of L2 products 
                        """
        parser.add_argument("-i", "--input",
                            help=inputDescr,
                            required=False)
        parser.add_argument(
            "-o",
            "--output",
            help="Output data directory (product directory). Default value: '.'",
            required=False)
        parser.add_argument(
            "-w",
            "--workingdir",
            help="Working directory (working 'temporary' directory). Default value: the '--output parameter value'",
            required=False)

        plugin_choices = "Available plugins : "
        creators = FactoryBase.get_registered("PluginBase")
        for crea in creators:
            plugin_choices = plugin_choices + crea().PluginName + " , "
        parser.add_argument(
            "-p",
            "--plugin",
            help="Output plugin to use to write L2 product. "+plugin_choices)
        parser.add_argument(
            "-ucs",
            "--conf",
            help="User Configuration directory (contains for example MAJAUserConfigSystem.xml)")

        parser.add_argument(
            "--NbThreads",
            type=int,
            help="UserConfigSystem overloads value for the parameter 'NbThreads'")
        parser.add_argument(
            "--CheckXMLFilesWithSchema",
            help="UserConfigSystem overloads value for the parameter 'CheckXMLFilesWithSchema'",
            action="store_true")
        parser.add_argument(
            "--CleanInputZipFiles",
            help="UserConfigSystem overloads value for the parameter 'CleanInputZipFiles'",
            action="store_true")
        parser.add_argument(
            "--CleanFiles",
            help="UserConfigSystem overloads value for the parameter 'CleanFiles'",
            action="store_true")
        parser.add_argument(
            "--ZipFiles",
            help="UserConfigSystem overloads value for the parameter 'ZipFiles'",
            action="store_true")
        parser.add_argument(
            "--EnableCleaningCachingDirectoryBeforeProcessing",
            help="UserConfigSystem overloads value for the parameter 'EnableCleaningCachingDirectoryBeforeProcessing'",
            action="store_true")
        parser.add_argument(
            "--EnableCleaningCachingDirectoryAfterProcessing",
            help="UserConfigSystem overloads value for the parameter 'EnableCleaningCachingDirectoryAfterProcessing'",
            action="store_true")
        parser.add_argument(
            "--EnableCleaningTemporaryDirectory",
            help="UserConfigSystem overloads value for the parameter 'EnableCleaningTemporaryDirectory'",
            action="store_true")
        parser.add_argument(
            "--TileId",
            help="Set the Tile id of the Sentinel2 L1 product (Only necessary for SENTINEL2 plug-in and only for "
                 "the L1C product with PSD version < PSD 14)",
            required=False)
        parser.add_argument(
            "--perfos-log",
            help="Enable performance measurement in log",
            action="store_true")
        parser.add_argument(
            "--perfos-report",
            help="Enable synthesize performance measurement in log and xml file",
            action="store_true")
        parser.add_argument(
            "-v",
            "--version",
            help="Display version information and exit",
            action="store_true"
        )

        args = parser.parse_args()

        if args.version :
            LOGGER.info("Maja Software Version: "+version.MAJA_VERSION)
            exit(0)

        # Set the log level
        self._logLevel = args.loglevel
        os.environ["MAJA_LOGGER_LEVEL"] = args.loglevel
        if args.loglevel == "INFO":
            LOGGER.setLevel(logging.INFO)
        elif args.loglevel == "PROGRESS":
            LOGGER.setLevel(logging.PROGRESS)
        elif args.loglevel == "WARNING":
            LOGGER.setLevel(logging.WARNING)
        elif args.loglevel == "DEBUG":
            LOGGER.setLevel(logging.DEBUG)
            os.environ["OTB_LOGGER_LEVEL"] = "DEBUG"
        elif args.loglevel == "ERROR":
            LOGGER.setLevel(logging.ERROR)

        LOGGER.info("Logger in %s mode ( %s )", args.loglevel, LOGGER.getEffectiveLevel())

        if args.output is not None:
            self._outputDirectory = args.output + os.path.sep
        else:
            raise MajaDataException("Output option -o/--output must be specified")
        LOGGER.info("Output Directory : %s ", self._outputDirectory)

        if not os.path.exists(self._outputDirectory):
            LOGGER.debug("OUTPUT_DIR must be created in %s", self._outputDirectory)
            file_utils.create_directory(self._outputDirectory)

        if args.input is not None:
            self._inputDirectory = args.input + os.path.sep
        else:
            raise MajaDataException("Input option -i/--input must be specified")
        LOGGER.info("Input Directory : %s ", self._inputDirectory)

        if args.workingdir is not None:
            self._workingDirectory = args.workingdir
        else:
            self._workingDirectory = os.path.join(self._outputDirectory, ".maja-working-directory")
        LOGGER.info("Working Directory : %s ", self._workingDirectory)
        self._directory_manager = DirectoryManager(self._workingDirectory)

        if not os.path.exists(self._workingDirectory):
            LOGGER.debug("WORKING_DIR must be created in %s", self._workingDirectory)
            file_utils.create_directory(self._workingDirectory)

        if args.plugin is not None:
            self._output_Plugin = args.plugin

        if args.TileId is not None:
            self._tile_id = args.TileId

        if os.getenv("MAJA_INSTALL_DIR") is None :
            raise MajaProcessingException("MAJA_INSTALL_DIR is not Set")

        if args.stylesheet is not None:
            self._stylesheet = args.stylesheet

        # User config
        if args.conf is not None:
            self._userconf_directory = args.conf
        self.luserConfigSystemFileName = os.path.join(self._userconf_directory, "MAJAUserConfigSystem.xml")
        if not os.path.exists(self.luserConfigSystemFileName):
            raise MajaDataException(
                "The User configuration system file <" +
                self.luserConfigSystemFileName +
                "> doesn't exist!")
        # Load the file
        LOGGER.info("Using "+self.luserConfigSystemFileName+" as userConfig file")
        self._userConfigSystemFileName = file_utils.copy_file_to_directory(self.luserConfigSystemFileName, self._workingDirectory,
                                                                notestmode=True)
        if self._stylesheet is not None:
            if not os.path.exists(self._stylesheet):
                raise MajaDataException(str(self._stylesheet) + " doesn't exist !!!!")
            translate_xsl(self._userConfigSystemFileName, self._stylesheet)
        self._userConf = user_conf.parse(self._userConfigSystemFileName, True)
        # overload values
        if args.CheckXMLFilesWithSchema:
            self._validate_schemas = True
        else:
            self._validate_schemas = self._userConf.get_Processing().get_CheckXMLFilesWithSchema()
        if args.CleanFiles:
            self._userConf.get_Processing().get_PostProcessing().set_CleanFiles(True)
        if args.ZipFiles:
            self._userConf.get_Processing().get_PostProcessing().set_ZipFiles(True)
        if args.CleanInputZipFiles:
            self._userConf.get_Processing().get_PreProcessing().set_CleanInputZipFiles(True)
        if args.EnableCleaningTemporaryDirectory:
            self._userConf.get_Computing().set_EnableCleaningTemporaryDirectory(True)
        if args.NbThreads is not None:
            self._nbThreads = args.NbThreads
        else:
            self._nbThreads = self._userConf.get_Computing().get_NbThreads()

        # Admin config
        if args.adminconf is not None:
            self._adminconf_directory = args.adminconf
        luseradminsystemfilename = os.path.join(self._adminconf_directory, "MAJAAdminConfigSystem.xml")
        if not os.path.exists(luseradminsystemfilename):
            raise MajaDataException("The Admin configuration system file <" + luseradminsystemfilename + "> doesn't exist!")
        self._adminConfigSystemFileName = file_utils.copy_file_to_directory(
            luseradminsystemfilename, self._workingDirectory, notestmode=True)
        if self._stylesheet is not None:
            translate_xsl(self._adminConfigSystemFileName, self._stylesheet)
        # Load the file
        self._adminConf = admin_conf.parse(self._adminConfigSystemFileName, True)

        if args.mode is not None:
            lProcessorName = args.mode
        else:
            raise MajaDataException("Mode must be specified : -m/--mode")

        self._processorName = AppHandler.MAJA_L2_NOMINAL_CHAIN
        if lProcessorName == AppHandler.L2INIT:
            self._processorName = AppHandler.MAJA_L2_INIT_CHAIN
        elif lProcessorName == AppHandler.L2NOMINAL:
            self._processorName = AppHandler.MAJA_L2_NOMINAL_CHAIN
        elif lProcessorName == AppHandler.L2BACKWARD:
            self._processorName = AppHandler.MAJA_L2_BACKWARD_CHAIN
        else:
            raise MajaDataException("Unknown mode in parameters")

        LOGGER.info("Processor is %s", self._processorName)
        LOGGER.progress("Starting " + self._processorName)

        LOGGER.info("Number of theads %i", self._nbThreads)
예제 #16
0
def test(argv):
    l1_input_dir = argv[1]
    l2_input_dir = argv[2]
    outdir = argv[3]
    l_cloudrate_value = int(argv[5])
    l_snowrate_value = int(argv[6])

    register_all()
    app_handler = AppHandler()
    app_handler._workingDirectory = outdir
    app_handler._inputDirectory = l1_input_dir
    app_handler._nbThreads = int(argv[4])

    global_output_dict = {}

    test_maja_l2_writer_setup.set_input_l2_writer(l2_input_dir, global_output_dict)


    # Set L1 product and extrat plugin name
    l1product = product_utils.get_input_l1_image_product(l1_input_dir)
    creators = FactoryBase.get_registered("L1ImageReaderBase")
    for crea in creators:
        LOGGER.info("Trying : " + crea.__name__)
        if crea().can_read(l1product.PluginName):
            l1reader = crea()
            l_CurrentPluginBase = l1reader.get_plugin()

    # Load L2COMM
    gipp_l2comm_filename = gipp_utils.get_gipp_filename_with_mission(l1_input_dir, "GIP_L2COMM",
                                                                     l1product.Satellite)
    LOGGER.debug("l_GIPPL2COMMHandler filename : " + gipp_l2comm_filename)

    l_GIPPL2COMMHandler = GippL2COMMEarthExplorerXMLFileHandler(gipp_l2comm_filename)

    # Load DTM
    dem_filename = gipp_utils.get_gipp_filename_with_mission(l1_input_dir, "AUX_REFDE2",
                                                             l1product.UniqueSatellite)
    dem = DEMBase()
    dem.initialize(dem_filename, app_handler._workingDirectory, False)

    # Extract product informations
    l_L2NoData = float(l_GIPPL2COMMHandler.get_value("NoData"))
    l_ReflectanceQuantificationValue = float(l1product.ReflectanceQuantification)
    l_RealL2NoData = l_L2NoData * l_ReflectanceQuantificationValue
    l_CurrentPluginBase.initialize(app_handler)
    l_BandDefinitons = l_CurrentPluginBase.BandsDefinitions
    l_AOTMethodString = l_GIPPL2COMMHandler.get_value("AOTMethod")
    l_AOTMethod = AOTEstimation.get_aot_method(l_AOTMethodString)
    l_CurrentConfigAdminCamera = l_CurrentPluginBase.ConfigAdminCamera

    param_dic = {}
    prepare_bands(l_BandDefinitons, l_BandDefinitons, l_GIPPL2COMMHandler, l_AOTMethod,
                                   l_CurrentConfigAdminCamera, True, False,
                                   param_dic)
    l_EnvCorOption = l_GIPPL2COMMHandler.get_value("EnvCorrOption")

    # Set L2 image Writer
    l2_image_writer = L2ImageWriterProvider.create(l1product.PluginName)
    l2_image_writer.set_dtm(dem)
    l2_image_writer.set_current_plugin_base(l_CurrentPluginBase)
    l2_image_writer.set_copy_private_from_l2_input_to_l2_output(False)
    l2_image_writer.set_write_l2_products(True)
    l2_image_writer.set_output_directory(app_handler._workingDirectory)
    l2_image_writer.set_l2_image_file_reader(None)
    l2_image_writer.set_l1_image_informations_provider(l1product)
    l2_image_writer.set_real_l2_nodata(l_RealL2NoData)

    l2_image_writer.set_reflectance_quantification_value(l1product.ReflectanceQuantification)
    l2_image_writer.set_aot_quantification_value(l_GIPPL2COMMHandler.get_value_f("AOTQuantificationValue"))
    l2_image_writer.set_vap_quantification_value(l_GIPPL2COMMHandler.get_value_f("VAPQuantificationValue"))
    l2_image_writer.set_vap_nodata_value(l_GIPPL2COMMHandler.get_value_f("VAPNodataValue"))
    l2_image_writer.set_aot_nodata_value(l_GIPPL2COMMHandler.get_value_f("AOTNodataValue"))
    l2_image_writer.set_quicklook_min_refl_redband(l_GIPPL2COMMHandler.get_value("QuicklookMinReflRedBand"))
    l2_image_writer.set_quicklook_min_refl_greenband(
        l_GIPPL2COMMHandler.get_value("QuicklookMinReflGreenBand"))
    l2_image_writer.set_quicklook_min_refl_blueband(l_GIPPL2COMMHandler.get_value("QuicklookMinReflBlueBand"))
    l2_image_writer.set_quicklook_max_refl_redband(l_GIPPL2COMMHandler.get_value("QuicklookMaxReflRedBand"))
    l2_image_writer.set_quicklook_max_refl_greenband(
        l_GIPPL2COMMHandler.get_value("QuicklookMaxReflGreenBand"))
    l2_image_writer.set_quicklook_max_refl_blueband(l_GIPPL2COMMHandler.get_value("QuicklookMaxReflBlueBand"))
    l2_image_writer.set_quicklook_red_band_code(l_GIPPL2COMMHandler.get_value("QuicklookRedBandCode"))
    l2_image_writer.set_quicklook_green_band_code(l_GIPPL2COMMHandler.get_value("QuicklookGreenBandCode"))
    l2_image_writer.set_quicklook_blue_band_code(l_GIPPL2COMMHandler.get_value("QuicklookBlueBandCode"))

    l2_image_writer.set_projection_ref(l1product.ProjectionRef)
    l2_image_writer.set_write_public_product(True)
    l2_image_writer.set_env_cor_option(l_EnvCorOption)
    l2_image_writer.set_sre_image_list(global_output_dict["SRE_List"])
    l2_image_writer.set_fre_image_list(global_output_dict["FRE_List"])
    l2_image_writer.set_aot_image_list(global_output_dict["L2AOT_List"])
    l2_image_writer.set_tao_image_list(global_output_dict["L2TAO_List"])
    l2_image_writer.set_vap_image_list(global_output_dict["L2VAP_List"])
    l2_image_writer.set_iwc_image_list(global_output_dict["L2IWC_List"])
    l2_image_writer.set_hid_image(global_output_dict["dtm_hid"])
    l2_image_writer.set_shd_image(global_output_dict["dtm_shd"])
    l2_image_writer.set_sat_image_list(global_output_dict["L2SAT_List"])
    l2_image_writer.set_pix_image_list(global_output_dict["L2PIX_List"])
    l2_image_writer.set_edg_image_list(global_output_dict["L2EDG_List"])
    l2_image_writer.set_stl_image_list(global_output_dict["L2STL_List"])
    l2_image_writer.set_tgs_image_list(global_output_dict["L2TGS_List"])

    if global_output_dict["L2DFP_List"]:
        l2_image_writer.set_dfp_image_list(global_output_dict["L2DFP_List"])

    if global_output_dict["snow"]:
        l2_image_writer.set_snw_image(global_output_dict["snow"])



    if global_output_dict["cla"]:
        l2_image_writer.set_cla_image(global_output_dict["cla"])


    l2_image_writer.set_rta_image(global_output_dict["rta_composite"])
    l2_image_writer.set_rtc_image(global_output_dict["rtc_composite"])
    l2_image_writer.set_rcr_image(global_output_dict["rcr_composite"])
    l2_image_writer.set_sto_image(global_output_dict["sto_composite"])

    l2_image_writer.set_pxd_image(global_output_dict["pxd_composite"])
    l2_image_writer.set_ndt_image(global_output_dict["ndt_composite"])

    l2_image_writer.set_cld_image(global_output_dict["CLD_List"])
    l2_image_writer.set_l2_cld_image_list(global_output_dict["L2CLD_List"])

    l2_image_writer.set_was_image(global_output_dict["was"])
    l2_image_writer.set_pwa_image(global_output_dict["pwa"])
    l2_image_writer.set_twa_image(global_output_dict["twa"])



    if global_output_dict["ltc"]:
        l_write_ltc = True
        l2_image_writer.set_write_ltc(l_write_ltc)
        LOGGER.debug(global_output_dict["ltc"])
        l2_image_writer.set_ltc_image(global_output_dict["ltc"])
    else:
        l_write_ltc = False
        l2_image_writer.set_write_ltc(l_write_ltc)


    l2_image_writer.initialize_product()
    l2_image_writer.write(app_handler._workingDirectory)

    # Set L2 Header
    l_L2HeaderFileWriter = L2HeaderWriterProvider.create(l1product.PluginName,
                                                         app_handler)
    l_L2HeaderFileWriter.l1imageinformationsproviderbase = l1product
    l_L2HeaderFileWriter.outputfileclass = l1product.FileClass
    l_L2HeaderFileWriter.outputdirectory = app_handler._workingDirectory
    l_L2HeaderFileWriter.outputl2productfilename = l2_image_writer.get_global_product_filename()
    l_L2HeaderFileWriter.outputl2privateimagefilenamesprovider = l2_image_writer.get_private_filenames_provider()
    l_L2HeaderFileWriter.reflectancequantificationvalue = l1product.ReflectanceQuantification
    l_L2HeaderFileWriter.dem = dem

    l_L2HeaderFileWriter.listofgippsfilenames = get_listoffilenames_filetype_sorted(
        app_handler.get_input_directory(), "GIP_")

    l_L2HeaderFileWriter.creator = 'MAJA_L2_INIT_CHAIN'
    l_L2HeaderFileWriter.system = 'MAJA'
    l_L2HeaderFileWriter.checkxmlfileswithschema = True
    l_L2HeaderFileWriter.notes = 'L2 note'

    l_L2HeaderFileWriter.listofbandtheoreticalwavelengthforreflectancescomposite = param_dic[
        "ListOfBandTheoreticalWavelengthForReflectancesComposite"]
    l_L2HeaderFileWriter.listofbandtheoreticalwavelengthforltccomposite = param_dic[
        "ListOfBandTheoreticalWavelengthForLTCComposite"]
    l_L2HeaderFileWriter.correlbandtheoreticalwavelengthforstocomposite = param_dic[
        "CorrelTheoreticalWavelength_DateD"]

    l_L2HeaderFileWriter.nodatavalue = l_GIPPL2COMMHandler.get_value("NoData")
    l_L2HeaderFileWriter.vapnodatavalue = l_GIPPL2COMMHandler.get_value("VAPNodataValue")
    l_L2HeaderFileWriter.vapquantificationvalue = l_GIPPL2COMMHandler.get_value("VAPQuantificationValue")
    l_L2HeaderFileWriter.aotnodatavalue = l_GIPPL2COMMHandler.get_value("AOTNodataValue")
    l_L2HeaderFileWriter.aotquantificationvalue = l_GIPPL2COMMHandler.get_value("AOTQuantificationValue")

    l_L2HeaderFileWriter.quicklookredbandcode = l_GIPPL2COMMHandler.get_value("QuicklookRedBandCode")
    l_L2HeaderFileWriter.quicklookgreenbandcode = l_GIPPL2COMMHandler.get_value("QuicklookGreenBandCode")
    l_L2HeaderFileWriter.quicklookbluebandcode = l_GIPPL2COMMHandler.get_value("QuicklookBlueBandCode")

    # Set the L2 images flags
    l_L2HeaderFileWriter.cirrusflag = False
    l_L2HeaderFileWriter.cloudrate = l_cloudrate_value
    l_L2HeaderFileWriter.snowrate = l_snowrate_value
    l_L2HeaderFileWriter.hotspotflag = False
    l_L2HeaderFileWriter.sunglintflag = False
    l_L2HeaderFileWriter.adjacencyeffectsandslopecorrection = l_EnvCorOption
    l_L2HeaderFileWriter.cirruscorrection = False
    l_L2HeaderFileWriter.initmode = True
    l_L2HeaderFileWriter.backwardmode = False
    l_STOListOfStringDates = []
    l_STOListOfStringDates.insert(0, l1product.ProductDateStr)

    l_L2HeaderFileWriter.productisvalid = True
    l_L2HeaderFileWriter.writel2products = True
    l_L2HeaderFileWriter.writepublicproduct = True
    l_L2HeaderFileWriter.numberofstackimages = len(l_STOListOfStringDates)
    l_L2HeaderFileWriter.stolistofstringdates = l_STOListOfStringDates
    l_L2HeaderFileWriter.enablewriteearthexplorerheaders = True

    l_L2HeaderFileWriter.writeltc = l_write_ltc
    l_L2HeaderFileWriter.ignorecurrentltc = False

    l_L2HeaderFileWriter.camsstatus = CAMSStatus.ACTIVATED_NOAVAILABLEDATA

    LOGGER.info("Writing L2 EarthExplorer headers files into the output L2 product")
    l_L2HeaderFileWriter.write()

    # Set the L2 header filename and the PMC report filename
    m_HDRFileNameOfProductImage = l2_image_writer.get_global_product_filename()
    m_ProductionReportFilename = l2_image_writer.get_production_report_filename()

    LOGGER.debug(
        "HDRFileNameOfProductImage: <" + m_HDRFileNameOfProductImage + ">")
    LOGGER.debug(
        "ProductionReportFilename:  <" + m_ProductionReportFilename + ">")

    LOGGER.debug("THREADS = ")

    LOGGER.debug(app_handler._nbThreads)
예제 #17
0
def register_all():
    FactoryBase.register("L1ImageInformationsBase",
                         MajaLandsat8L1ImageInformations)
    FactoryBase.register("PluginBase", MajaLandsat8Plugin)
    FactoryBase.register("L1ImageReaderBase", Landsat8L1ImageFileReader)
예제 #18
0
def register_all():
    FactoryBase.register("L1ImageInformationsBase",
                         MajaSentinel2L1ImageInformations)
    FactoryBase.register("L1ImageReaderBase", Sentinel2L1ImageFileReader)
    FactoryBase.register("PluginBase", MajaSentinel2Plugin)
    FactoryBase.register("L2ImageWriterBase", MajaSentinel2L2ImageWriter)
    FactoryBase.register("L2ImageReaderBase", MajaSentinel2L2ImageReader)
    FactoryBase.register("L2HeaderWriterBase", MajaSentinel2L2HeaderWriter)