def run_processing(self): """ Process SAS_L2_HR_LakeTile """ logger = logging.getLogger(self.__class__.__name__) logger.sigmsg("") logger.sigmsg("**********************") logger.sigmsg("***** PROCESSING *****") logger.sigmsg("**********************") logger.sigmsg("") timer_proc = my_timer.Timer() timer_proc.start() try: # Processing only if PixC pixels are selected if self.obj_pixc.nb_selected != 0: # 2 - F2-F3-F3b = Identify all separate entities in the water mask logger.info( "1 - Identifying all separate entities in the water mask..." ) self.obj_pixc.compute_separate_entities() logger.info("" + timer_proc.info(0)) logger.info("") # 3 - F4 = Retrieve pixels corresponding to lakes and unknown entirely inside the tile logger.info( "2 - Getting pixels corresponding to lakes and unknown entirely inside the tile..." ) self.obj_pixc.compute_obj_inside_tile() logger.info("" + timer_proc.info(0)) logger.info("") # 4 - F5 = Retrieve pixels indices and associated label of objects at the top/bottom edge of the tile logger.info( "3 - Getting pixels corresponding to objects at the top/bottom edge of the tile..." ) self.obj_pixc.compute_edge_indices_and_label() logger.info("" + timer_proc.info(0)) logger.info("") # 5 - F6 = Fill lake product logger.info("4 - Filling LakeTile product...") self.obj_lake.compute_lake_products( self.obj_pixc.labels_inside) logger.info("" + timer_proc.info(0)) logger.info("") else: logger.info( "NO selected PixC => empty lake tile product generated") logger.info("") except: message = "Something wrong happened in run_processing" raise service_error.SASLakeTileError(message, logger)
def run_processing(self): """ Process SAS_L2_HR_LakeTile """ logger = logging.getLogger(self.__class__.__name__) logger.sigmsg("") logger.sigmsg("**********************") logger.sigmsg("***** PROCESSING *****") logger.sigmsg("**********************") logger.sigmsg("") timer_proc = my_timer.Timer() timer_proc.start() try : if self.obj_pixc_sp.pixc_edge_l.nb_pixels > 0: logger.info("***** Processing Left Swath ******") # 3.1.1 - Gather pixels by entities for all the tiles of this swath logger.info("1 - Relabeling edge entities ...") self.obj_pixc_sp.pixc_edge_l.swath_global_relabeling() # 3.1.2 - Compute lake products logger.info("2 - Filling LakeTile product...") self.obj_lake_l.compute_lake_products(np.unique(self.obj_pixc_sp.pixc_edge_l.labels)) else: logger.info("No pixel to process") if self.obj_pixc_sp.pixc_edge_r.nb_pixels > 0: logger.info("***** Processing Right Swath ******") # 3.1.1 - Gather pixels by entities for all the tiles of this swath logger.info("1 - Relabeling edge entities ...") self.obj_pixc_sp.pixc_edge_r.swath_global_relabeling() # 3.1.2 - Compute lake products logger.info("2 - Filling LakeTile product...") self.obj_lake_r.compute_lake_products(np.unique(self.obj_pixc_sp.pixc_edge_r.labels)) else: logger.info("No pixel to process") except: message = "Something wrong happened in run_processing" raise service_error.SASLakeSpError(message, logger)
def run_processing(self): """ Process SAS_L2_HR_LakeTile for each input tile """ print("") print("") print("[multiLakeTileProcessing] PROCESSING...") print("") print("") timer_proc = my_timer.Timer() timer_proc.start() if self.nb_input != 0: for indf in range(self.nb_input): # Deal with all selected files print( "****************************************************************************************************************" ) print("***** Dealing with tile %d / %d = %s *****" % (indf + 1, self.nb_input, self.list_pixc[indf])) print( "****************************************************************************************************************" ) print("") print("") # 1 - Initialization cmd_file = self.create_cmd_file(indf) my_lake_tile = pge_lake_tile.PGELakeTile(cmd_file) # 2 - Run my_lake_tile.start() # 3 - Stop my_lake_tile.stop() print("") print(timer.stop()) print("") print("") print( "****************************************************************************************************************" ) print("") print("")
def run_processing(self): """ Process SAS_L2_HR_LakeTile for each input tile """ print("") print("") print("[multiLakeSPProcessing] PROCESSING...") print("") print("") timer_proc = my_timer.Timer() timer_proc.start() for (cycle_num, pass_num) in self.cycle_pass_set: # Deal with all selected files print( "****************************************************************************************************************" ) print("***** Dealing with cycle %s and pass %s *****" % (cycle_num, pass_num)) print( "****************************************************************************************************************" ) print("") print("") # 1 - Initialization cmd_file = self.create_cmd_file(cycle_num, pass_num) my_lake_tile = pge_lake_sp.PGELakeSP(cmd_file) # 2 - Run my_lake_tile.start() # 3 - Stop my_lake_tile.stop() print("") print(timer.stop()) print("") print("") print( "****************************************************************************************************************" ) print("") print("")
# 0 - Parse inline parameters parser = argparse.ArgumentParser(description="Compute SWOT LakeSP product from LakeTile products corresponding to a specific (cycle, pass). \ If indir_or_param_file is a parameter file (*.cfg), all input parameters are only read in the parameter file.") parser.add_argument("indir_or_param_file", help="LakeTile directory or parameter file (*.cfg)") parser.add_argument("output_dir", help="output directory", nargs='?') parser.add_argument("cycle_num", help="cycle number", type=int, nargs='?') parser.add_argument("pass_num", help="pass number", type=int, nargs='?') parser.add_argument("-shp", help="convert output NetCDF file as shapefile", action="store_true") parser.add_argument("-l", "--logfile", help="write prints to a logfile", action="store_true") # To print logs on screen (=False, default) or in a logfile (=True) parser.add_argument("-v", "--verbose", help="verbose level", choices=["DEBUG", "INFO"], default="INFO") # Verbose level args = parser.parse_args() print("===== lakeSPProcessing = BEGIN =====") print("") timer = my_timer.Timer() timer.start() # 1 - Working variables # 1.1 - Init variables paramFile = None # Parameter file full path laketile_dir = None # Input directory, containing LakeTile products output_dir = None # Output directory cycle_num = None # Cycle number pass_num = None # Pass number shp_option = False # To also produce PIXCVec file as shapefile (=True); else=False (default) # 1.2 - Read values according to indir_or_param_file values if os.path.isdir(args.indir_or_param_file): # Read inline parameters location = "inline command"
def run_processing(self): """ Process SAS_L2_HR_LakeSP for each (cycle, pass) pair """ my_api.printInfo("") my_api.printInfo("") my_api.printInfo("[multiLakeSPProcessing] PROCESSING...") my_api.printInfo("") my_api.printInfo("") timer_proc = my_timer.Timer() timer_proc.start() if len(self.list_pass) != 0: for cur_cycle, cur_pass in zip( self.list_cycle, self.list_pass): # Deal with all selected pairs my_api.printInfo( "*******************************************************************" ) my_api.printInfo( "***** Dealing with cycle %03d and pass %03d *****" % (cur_cycle, cur_pass)) if my_api.GEN_ENV != 2: print() print("> Dealing with cycle %03d and pass %03d" % (cur_cycle, cur_pass)) my_api.printInfo( "*******************************************************************" ) my_api.printInfo("") my_api.printInfo("") # 1 - Initialization myLakeSP = pge_lake_sp.Processing( self.lake_tile_dir, self.output_dir, cur_cycle, cur_pass, IN_shp_option=self.flag_prod_shp) my_api.printInfo(timer.info(0)) # 2 - Run pre-processing myLakeSP.run_preprocessing() my_api.printInfo(timer.info(0)) # 3 - Run processing myLakeSP.run_processing() my_api.printInfo(timer.info(0)) # 4 - Run post-processing myLakeSP.run_postprocessing() my_api.printInfo(timer.info(0)) my_api.printInfo("") my_api.printInfo(timer.stop()) my_api.printInfo("") my_api.printInfo("") my_api.printInfo( "*******************************************************************" ) my_api.printInfo("") my_api.printInfo("")
def __init__(self, cmd_file): """ Constructor of PGELakeTile :param cmdFile: command file full path :type cmdFile: string """ # 0 - Init timer self.timer = my_timer.Timer() self.timer.start() # 1 - Load command file self.cmd_file = cmd_file my_tools.testFile(cmd_file, IN_extent=".cfg") # Test existance and extension my_params = self._read_cmd_file() # Read parameters self.pixc_file = my_params["pixc_file"] self.pixc_vec_river_file = my_params["pixc_vec_river_file"] self.output_dir = my_params["output_dir"] # 2 - Load parameter file # 2.1 - Read value from command file file_config = my_params["param_file"] # 2.2 - Test existence if not os.path.exists(file_config): raise service_error.DirFileError(file_config) # 2.3 - Load parameters self.cfg = service_config_file.ServiceConfigFile(file_config) # 3 - Put command parameter inside cfg self._put_cmd_value(my_params) # 4 - Initiate logging service service_logger.ServiceLogger() logger = logging.getLogger(self.__class__.__name__) # 5 - Print info logger.info("======================================") logger.info("===== lakeTileProcessing = BEGIN =====") logger.info("======================================") message = "> Command file: " + str(self.cmd_file) logger.info(message) message = "> " + str(self.cfg) logger.info(message) logger.info("") # 6 - Test input parameters logger.info(">> Test input parameters") self._check_config_parameters() logger.info("") # 7 - Update global variables # TODO replace all global variables by call to service_config_file my_var.tmpGetConfigFromServiceConfigFile() # 8 - Form processing metadata dictionary self.proc_metadata = {} self.proc_metadata["xref_static_lake_db_file"] = my_var.LAKE_DB self.proc_metadata["xref_input_l2_hr_pixc_file"] = self.pixc_file self.proc_metadata[ "xref_input_l2_hr_pixc_vec_river_file"] = self.pixc_vec_river_file self.proc_metadata["xref_l2_hr_lake_tile_param_file"] = file_config logger.info("") logger.info("")
def __init__(self, cmd_file): """ Constructor of PGELakeTile :param cmdFile: command file full path :type cmdFile: string """ # 0 - Init timer self.timer = my_timer.Timer() self.timer.start() # 1 - Load command file self.cmd_file = cmd_file my_tools.test_file(cmd_file, in_extent=".cfg") # Test existance and extension my_params = self._read_cmd_file() # Read parameters self.pixc_file = my_params["pixc_file"] self.pixc_vec_river_file = my_params["pixc_vec_river_file"] self.output_dir = my_params["output_dir"] # 2 - Load parameter file # 2.1 - Read value from command file file_config = my_params["param_file"] # 2.2 - Test existence if not os.path.exists(file_config): raise service_error.DirFileError(file_config) # 2.3 - Load parameters self.cfg = service_config_file.ServiceConfigFile(file_config) # 3 - Put command parameter inside cfg self._put_cmd_value(my_params) # 4 - Init data object self.obj_pixc_vec = None self.obj_pixc = None self.obj_lake_db = None self.obj_lake = None self.lake_tile_filenames = None self.flag_prod_shp = self.cfg.getboolean("OPTIONS", "Produce shp") # 4 - Initiate logging service service_logger.ServiceLogger() logger = logging.getLogger(self.__class__.__name__) # 5 - Print info logger.sigmsg("======================================") logger.sigmsg("===== lakeTileProcessing = BEGIN =====") logger.sigmsg("======================================") message = "> Command file: " + str(self.cmd_file) logger.info(message) message = "> " + str(self.cfg) logger.info(message) logger.info("") # 6 - Test input parameters logger.info(">> Test input parameters") self._check_config_parameters() logger.info("") # 7 - Form processing metadata dictionary self.proc_metadata = {} if self.cfg.get("DATABASES", "LAKE_DB") is not None: self.proc_metadata["xref_static_lake_db_file"] = self.cfg.get( "DATABASES", "LAKE_DB") else: self.proc_metadata["xref_static_lake_db_file"] = "" self.proc_metadata["xref_input_l2_hr_pixc_file"] = self.pixc_file self.proc_metadata[ "xref_input_l2_hr_pixc_vec_river_file"] = self.pixc_vec_river_file self.proc_metadata["xref_l2_hr_lake_tile_param_file"] = file_config logger.info("") logger.info("")
def __init__(self, cmd_file): """ Constructor of PGELakeSP :param cmdFile: command file full path :type cmdFile: string """ # 0 - Init timer self.timer = my_timer.Timer() self.timer.start() # 1 - Load command file self.cmd_file = cmd_file my_tools.test_file(cmd_file, in_extent=".cfg") # Test existance and extension my_params = self._read_cmd_file() # Read parameters self.laketile_shp_dir = my_params["laketile_shp_directory"] self.laketile_edge_dir = my_params["laketile_edge_directory"] self.laketile_pixcvec_dir = my_params["laketile_pixcvec_directory"] self.output_dir = my_params["output_dir"] self.cycle_num = my_params["cycle_num"] self.pass_num = my_params["pass_num"] self.continent_list = set() # 2 - Load parameter file # 2.1 - Read value from command file self.file_config = my_params["param_file"] # 2.2 - Test existence if not os.path.exists(self.file_config): raise service_error.DirFileError(self.file_config) # 2.3 - Load parameters self.cfg = service_config_file.ServiceConfigFile(self.file_config) # 3 - Put command parameter inside cfg self._put_cmd_value(my_params) # 4 - Init data dict. Each key / value will be continent_code : object self.obj_pixc_sp = {} self.obj_pixcvec_sp = {} self.obj_lake_db = {} self.obj_lake_r = {} self.obj_lake_l = {} self.lake_sp_filenames = {} self.laketile_shp_path_dict = {} self.flag_prod_shp = self.cfg.getboolean("OPTIONS", "Produce shp") # 5 - Initiate logging service service_logger.ServiceLogger() logger = logging.getLogger(self.__class__.__name__) # 6 - Print info logger.sigmsg("======================================") logger.sigmsg("===== lakeSPProcessing = BEGIN =====") logger.sigmsg("======================================") message = "> Command file: " + str(self.cmd_file) logger.info(message) message = "> " + str(self.cfg) logger.info(message) logger.info("") # 7 - Test input parameters logger.info(">> Test input parameters") self._check_config_parameters() logger.info("") # 8 - Form processing metadata dictionary self.proc_metadata = {} logger.info("") logger.info("")