def compute_origin(in_origin, in_spacing, out_spacing, mode): """ :param in_origin: VNSOriginType :param in_spacing: VNSSpacingType :param out_spacing: VNSSpacingType :param mode: ResamplerHelper :return: """ outOrigin = None factor = None # -------------------------------------------------------------------------------------- # Resampling factor in line and column factor[0] = float(in_spacing[0]) / float(out_spacing[0]) factor[1] = float(in_spacing[1]) / float(out_spacing[1]) # TODO: # LOGGER.debug("Resampling CheckComputeOrigin - pixel mode: %s (with CENTERED="<<vns::ResamplerHelper::RB_MODE_CENTERED_PIXEL<<" and UPPER_LEFT_CORNER="<<vns::ResamplerHelper::RB_MODE_UPPER_LEFT_CORNER_PIXEL<<") ", mode) # LOGGER.debug(" - Input image origin: ["<<inOrigin[0]<<";"<<inOrigin[1]<<"] ") # LOGGER.debug(" - spacing: ["<<inSpacing[0]<<";"<<inSpacing[1]<<"] ") # LOGGER.debug(" - Output image spacing: ["<<outSpacing[0]<<";"<<outSpacing[1]<<"] ") # LOGGER.debug(" - Factor: ["<<factor[0]<<";"<<factor[1]<<"] ") # Check the sign of the input and output spacing if ((in_spacing[0] > 0) and (out_spacing[0] < 0)) or ((in_spacing[0] < 0) and (out_spacing[0] > 0)) \ or ((in_spacing[1] > 0) and (out_spacing[1] < 0)) or ((in_spacing[1] < 0) and (out_spacing[1] > 0)): raise MajaBusinessException( "For resampling, input and output spacing must have the same sign for each dimension!" ) # -------------------------------------------------------------------------------------- # Two convention are used to resample images depending on the satellite if mode == "RB_MODE_CENTERED_PIXEL": # In centered case, origin does not move outOrigin = in_origin # -------------------------------------------------------------------------------------- elif mode == "RB_MODE_UPPER_LEFT_CORNER_PIXEL": # In this case, the origin has to be shifted to preserve # footprint: # Formule CNES (J.Michel) et validee sur papier par CS outOrigin[0] = in_origin[0] - (factor[0] - 1) * in_spacing[0] / (2 * factor[0]) outOrigin[1] = in_origin[1] - (factor[1] - 1) * in_spacing[1] / (2 * factor[1]) # -------------------------------------------------------------------------------------- elif mode == "NOT_MODE_INITIALIZED": # -------------------------------------------------------------------------------------- pass else: raise MajaBusinessException("Unknown ResamplerHelper mode.") LOGGER.debug(" - Output image origin: [%s;%s]", outOrigin[0], outOrigin[1]) return outOrigin
def write_images(img_list, img_filenames): # TODO : Remove fixed streaming lines if len(img_list) != len(img_filenames): raise MajaBusinessException( "Not the same number of image and filename given to write_images") tmp_img_list_clean = [] tmp_filename_list_clean = [] for f in range(len(img_list)): if type(img_list[f]).__name__ != "str": tmp_img_list_clean.append(img_list[f]) tmp_filename_list_clean.append(img_filenames[f]) else: LOGGER.debug("source : " + img_list[f] + " , dest : " + img_filenames[f]) try: if not os.path.exists( img_filenames[f]) or not os.path.samefile( img_list[f], img_filenames[f]): shutil.copyfile(img_list[f], img_filenames[f]) except IOError as err: raise MajaIOError(err) if len(tmp_img_list_clean) == 0: return parameters = { "il": tmp_img_list_clean, "filenames": tmp_filename_list_clean } app = OtbAppHandler("ImageListWriter", parameters) del app
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 MajaBusinessException("No input L2 product available") return product_list
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 MajaBusinessException( "No factory to generate L2ImageWriter for " + plugin_name)
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(product_filename, app_handler, enable_reading_public): 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) return l2reader raise MajaBusinessException("No factory to handle " + product_filename)
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 MajaBusinessException("No factory to generate L2HeaderWriter for " + plugin_name)
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)